You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestUnicode.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hpsf.basic;
  16. import static org.junit.jupiter.api.Assertions.assertEquals;
  17. import static org.junit.jupiter.api.Assertions.assertTrue;
  18. import java.io.ByteArrayInputStream;
  19. import java.io.File;
  20. import java.io.IOException;
  21. import org.apache.poi.POIDataSamples;
  22. import org.apache.poi.hpsf.DocumentSummaryInformation;
  23. import org.apache.poi.hpsf.HPSFException;
  24. import org.apache.poi.hpsf.PropertySet;
  25. import org.apache.poi.hpsf.PropertySetFactory;
  26. import org.apache.poi.hpsf.Section;
  27. import org.apache.poi.hpsf.SummaryInformation;
  28. import org.apache.poi.util.CodePageUtil;
  29. import org.junit.jupiter.api.Test;
  30. /**
  31. * Tests whether Unicode string can be read from a DocumentSummaryInformation.
  32. */
  33. class TestUnicode {
  34. private static final POIDataSamples samples = POIDataSamples.getHPSFInstance();
  35. /**
  36. * Tests the {@link PropertySet} methods. The test file has two
  37. * property set: the first one is a {@link SummaryInformation},
  38. * the second one is a {@link DocumentSummaryInformation}.
  39. *
  40. * @throws IOException if an I/O exception occurs
  41. * @throws HPSFException if an HPSF exception occurs
  42. */
  43. @Test
  44. void testPropertySetMethods() throws IOException, HPSFException {
  45. final String POI_FS = "TestUnicode.xls";
  46. final String[] POI_FILES = { DocumentSummaryInformation.DEFAULT_STREAM_NAME };
  47. File data = samples.getFile(POI_FS);
  48. POIFile poiFile = Util.readPOIFiles(data, POI_FILES).get(0);
  49. byte[] b = poiFile.getBytes();
  50. PropertySet ps = PropertySetFactory.create(new ByteArrayInputStream(b));
  51. assertTrue(ps.isDocumentSummaryInformation());
  52. assertEquals(2, ps.getSectionCount());
  53. Section s = ps.getSections().get(1);
  54. assertEquals(CodePageUtil.CP_UTF16, s.getProperty(1));
  55. assertEquals(-96070278, s.getProperty(2));
  56. assertEquals("MCon_Info zu Office bei Schreiner", s.getProperty(3));
  57. assertEquals("petrovitsch@schreiner-online.de", s.getProperty(4));
  58. assertEquals("Petrovitsch, Wilhelm", s.getProperty(5));
  59. }
  60. }