You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/05/22 20:56:49 UTC
svn commit: r1890120 [27/43] - in /poi/trunk/poi/src:
main/java/org/apache/poi/ main/java/org/apache/poi/ddf/
main/java/org/apache/poi/extractor/ main/java/org/apache/poi/hpsf/
main/java/org/apache/poi/hssf/ main/java/org/apache/poi/hssf/dev/
main/java...
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestMetaDataIPI.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestMetaDataIPI.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestMetaDataIPI.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestMetaDataIPI.java Sat May 22 20:56:44 2021
@@ -47,475 +47,475 @@ import org.junit.jupiter.api.Test;
*/
final class TestMetaDataIPI {
- private POIFSFileSystem poifs ;
- private DocumentSummaryInformation dsi;
- private SummaryInformation si;
-
- @AfterEach
- void tearDown() throws Exception {
- poifs.close();
- }
-
- /**
- * Setup is used to get the document ready. Gets the DocumentSummaryInformation and the
- * SummaryInformation to reasonable values
- */
- @BeforeEach
+ private POIFSFileSystem poifs ;
+ private DocumentSummaryInformation dsi;
+ private SummaryInformation si;
+
+ @AfterEach
+ void tearDown() throws Exception {
+ poifs.close();
+ }
+
+ /**
+ * Setup is used to get the document ready. Gets the DocumentSummaryInformation and the
+ * SummaryInformation to reasonable values
+ */
+ @BeforeEach
void setUp() throws Exception {
poifs = new POIFSFileSystem();
dsi = PropertySetFactory.newDocumentSummaryInformation();
si = PropertySetFactory.newSummaryInformation();
dsi.write(poifs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
si.write(poifs.getRoot(), SummaryInformation.DEFAULT_STREAM_NAME);
- }
+ }
+
+ /**
+ * Sets the most important information in DocumentSummaryInformation and Summary Information and rereads it
+ */
+ @Test
+ void testOne() throws Exception {
- /**
- * Sets the most important information in DocumentSummaryInformation and Summary Information and rereads it
- */
- @Test
- void testOne() throws Exception {
-
- // DocumentSummaryInformation
- dsi.setCompany("xxxCompanyxxx");
- dsi.setManager("xxxManagerxxx");
- dsi.setCategory("xxxCategoryxxx");
-
- // SummaryInformation
- si.setTitle("xxxTitlexxx");
- si.setAuthor("xxxAuthorxxx");
- si.setComments("xxxCommentsxxx");
- si.setKeywords("xxxKeyWordsxxx");
- si.setSubject("xxxSubjectxxx");
-
- // Custom Properties (in DocumentSummaryInformation
- CustomProperties customProperties = dsi.getCustomProperties();
- if (customProperties == null) {
- customProperties = new CustomProperties();
- }
-
- /* Insert some custom properties into the container. */
- customProperties.put("Key1", "Value1");
- customProperties.put("Schl\u00fcssel2", "Wert2");
- customProperties.put("Sample Integer", 12345);
- customProperties.put("Sample Boolean", true);
- Date date = new Date();
- customProperties.put("Sample Date", date);
- customProperties.put("Sample Double", -1.0001);
- customProperties.put("Sample Negative Integer", -100000);
-
- dsi.setCustomProperties(customProperties);
-
- // start reading
- closeAndReOpen();
-
- // testing
- assertNotNull(dsi);
- assertNotNull(si);
-
- assertEquals("xxxCategoryxxx", dsi.getCategory(), "Category");
- assertEquals("xxxCompanyxxx", dsi.getCompany(), "Company");
- assertEquals("xxxManagerxxx", dsi.getManager(), "Manager");
-
- assertEquals("xxxAuthorxxx", si.getAuthor());
- assertEquals("xxxTitlexxx", si.getTitle());
- assertEquals("xxxCommentsxxx", si.getComments());
- assertEquals("xxxKeyWordsxxx", si.getKeywords());
- assertEquals("xxxSubjectxxx", si.getSubject());
-
- /*
- * Read the custom properties. If there are no custom properties yet,
- * the application has to create a new CustomProperties object. It will
- * serve as a container for custom properties.
- */
- customProperties = dsi.getCustomProperties();
- assertNotNull(customProperties);
-
- /* Insert some custom properties into the container. */
- String a1 = (String) customProperties.get("Key1");
- assertEquals("Value1", a1, "Key1");
- String a2 = (String) customProperties.get("Schl\u00fcssel2");
- assertEquals("Wert2", a2, "Schl\u00fcssel2");
- Integer a3 = (Integer) customProperties.get("Sample Integer");
- assertEquals(12345, (int)a3, "Sample Number");
- Boolean a4 = (Boolean) customProperties.get("Sample Boolean");
- assertTrue(a4, "Sample Boolean");
- Date a5 = (Date) customProperties.get("Sample Date");
- assertEquals(date, a5, "Custom Date:");
-
- Double a6 = (Double) customProperties.get("Sample Double");
- assertEquals(-1.0001, a6, 0, "Custom Float");
-
- Integer a7 = (Integer) customProperties.get("Sample Negative Integer");
- assertEquals(-100000, (int)a7, "Neg");
- }
-
- /**
- * Test very long input in each of the fields (approx 30-60KB each)
- */
+ // DocumentSummaryInformation
+ dsi.setCompany("xxxCompanyxxx");
+ dsi.setManager("xxxManagerxxx");
+ dsi.setCategory("xxxCategoryxxx");
+
+ // SummaryInformation
+ si.setTitle("xxxTitlexxx");
+ si.setAuthor("xxxAuthorxxx");
+ si.setComments("xxxCommentsxxx");
+ si.setKeywords("xxxKeyWordsxxx");
+ si.setSubject("xxxSubjectxxx");
+
+ // Custom Properties (in DocumentSummaryInformation
+ CustomProperties customProperties = dsi.getCustomProperties();
+ if (customProperties == null) {
+ customProperties = new CustomProperties();
+ }
+
+ /* Insert some custom properties into the container. */
+ customProperties.put("Key1", "Value1");
+ customProperties.put("Schl\u00fcssel2", "Wert2");
+ customProperties.put("Sample Integer", 12345);
+ customProperties.put("Sample Boolean", true);
+ Date date = new Date();
+ customProperties.put("Sample Date", date);
+ customProperties.put("Sample Double", -1.0001);
+ customProperties.put("Sample Negative Integer", -100000);
+
+ dsi.setCustomProperties(customProperties);
+
+ // start reading
+ closeAndReOpen();
+
+ // testing
+ assertNotNull(dsi);
+ assertNotNull(si);
+
+ assertEquals("xxxCategoryxxx", dsi.getCategory(), "Category");
+ assertEquals("xxxCompanyxxx", dsi.getCompany(), "Company");
+ assertEquals("xxxManagerxxx", dsi.getManager(), "Manager");
+
+ assertEquals("xxxAuthorxxx", si.getAuthor());
+ assertEquals("xxxTitlexxx", si.getTitle());
+ assertEquals("xxxCommentsxxx", si.getComments());
+ assertEquals("xxxKeyWordsxxx", si.getKeywords());
+ assertEquals("xxxSubjectxxx", si.getSubject());
+
+ /*
+ * Read the custom properties. If there are no custom properties yet,
+ * the application has to create a new CustomProperties object. It will
+ * serve as a container for custom properties.
+ */
+ customProperties = dsi.getCustomProperties();
+ assertNotNull(customProperties);
+
+ /* Insert some custom properties into the container. */
+ String a1 = (String) customProperties.get("Key1");
+ assertEquals("Value1", a1, "Key1");
+ String a2 = (String) customProperties.get("Schl\u00fcssel2");
+ assertEquals("Wert2", a2, "Schl\u00fcssel2");
+ Integer a3 = (Integer) customProperties.get("Sample Integer");
+ assertEquals(12345, (int)a3, "Sample Number");
+ Boolean a4 = (Boolean) customProperties.get("Sample Boolean");
+ assertTrue(a4, "Sample Boolean");
+ Date a5 = (Date) customProperties.get("Sample Date");
+ assertEquals(date, a5, "Custom Date:");
+
+ Double a6 = (Double) customProperties.get("Sample Double");
+ assertEquals(-1.0001, a6, 0, "Custom Float");
+
+ Integer a7 = (Integer) customProperties.get("Sample Negative Integer");
+ assertEquals(-100000, (int)a7, "Neg");
+ }
+
+ /**
+ * Test very long input in each of the fields (approx 30-60KB each)
+ */
@Test
- void testTwo() throws Exception {
+ void testTwo() throws Exception {
+
+ String company = elongate("company");
+ String manager = elongate("manager");
+ String category = elongate("category");
+ String title = elongate("title");
+ String author = elongate("author");
+ String comments = elongate("comments");
+ String keywords = elongate("keywords");
+ String subject = elongate("subject");
+ String p1 = elongate("p1");
+ String p2 = elongate("p2");
+ String k1 = elongate("k1");
+ String k2 = elongate("k2");
+
+ dsi.setCompany(company);
+ dsi.setManager(manager);
+ dsi.setCategory(category);
+
+ si.setTitle(title);
+ si.setAuthor(author);
+ si.setComments(comments);
+ si.setKeywords(keywords);
+ si.setSubject(subject);
+ CustomProperties customProperties = dsi.getCustomProperties();
+ if (customProperties == null) {
+ customProperties = new CustomProperties();
+ }
+
+ /* Insert some custom properties into the container. */
+ customProperties.put(k1, p1);
+ customProperties.put(k2, p2);
+ customProperties.put("Sample Number", 12345);
+ customProperties.put("Sample Boolean", Boolean.TRUE);
+ Date date = new Date();
+ customProperties.put("Sample Date", date);
+
+ dsi.setCustomProperties(customProperties);
+
+ closeAndReOpen();
+
+ assertNotNull(dsi);
+ assertNotNull(si);
+ /*
+ * Change the category to "POI example". Any former category value will
+ * be lost. If there has been no category yet, it will be created.
+ */
+ assertEquals(category, dsi.getCategory(), "Category");
+ assertEquals(company, dsi.getCompany(), "Company");
+ assertEquals(manager, dsi.getManager(), "Manager");
+
+ assertEquals(author, si.getAuthor());
+ assertEquals(title, si.getTitle());
+ assertEquals(comments, si.getComments());
+ assertEquals(keywords, si.getKeywords());
+ assertEquals(subject, si.getSubject());
+
+ /*
+ * Read the custom properties. If there are no custom properties yet,
+ * the application has to create a new CustomProperties object. It will
+ * serve as a container for custom properties.
+ */
+ customProperties = dsi.getCustomProperties();
+ assertNotNull(customProperties);
+
+ /* Insert some custom properties into the container. */
+ String a1 = (String) customProperties.get(k1);
+ assertEquals(p1, a1, "Key1");
+ String a2 = (String) customProperties.get(k2);
+ assertEquals(p2, a2, "Schl\u00fcssel2");
+ Integer a3 = (Integer) customProperties.get("Sample Number");
+ assertEquals(12345, (int)a3, "Sample Number");
+ Boolean a4 = (Boolean) customProperties.get("Sample Boolean");
+ assertTrue(a4, "Sample Boolean");
+ Date a5 = (Date) customProperties.get("Sample Date");
+ assertEquals(date, a5, "Custom Date:");
+
+ }
- String company = elongate("company");
- String manager = elongate("manager");
- String category = elongate("category");
- String title = elongate("title");
- String author = elongate("author");
- String comments = elongate("comments");
- String keywords = elongate("keywords");
- String subject = elongate("subject");
- String p1 = elongate("p1");
- String p2 = elongate("p2");
- String k1 = elongate("k1");
- String k2 = elongate("k2");
-
- dsi.setCompany(company);
- dsi.setManager(manager);
- dsi.setCategory(category);
-
- si.setTitle(title);
- si.setAuthor(author);
- si.setComments(comments);
- si.setKeywords(keywords);
- si.setSubject(subject);
- CustomProperties customProperties = dsi.getCustomProperties();
- if (customProperties == null) {
- customProperties = new CustomProperties();
- }
-
- /* Insert some custom properties into the container. */
- customProperties.put(k1, p1);
- customProperties.put(k2, p2);
- customProperties.put("Sample Number", 12345);
- customProperties.put("Sample Boolean", Boolean.TRUE);
- Date date = new Date();
- customProperties.put("Sample Date", date);
-
- dsi.setCustomProperties(customProperties);
-
- closeAndReOpen();
-
- assertNotNull(dsi);
- assertNotNull(si);
- /*
- * Change the category to "POI example". Any former category value will
- * be lost. If there has been no category yet, it will be created.
- */
- assertEquals(category, dsi.getCategory(), "Category");
- assertEquals(company, dsi.getCompany(), "Company");
- assertEquals(manager, dsi.getManager(), "Manager");
-
- assertEquals(author, si.getAuthor());
- assertEquals(title, si.getTitle());
- assertEquals(comments, si.getComments());
- assertEquals(keywords, si.getKeywords());
- assertEquals(subject, si.getSubject());
-
- /*
- * Read the custom properties. If there are no custom properties yet,
- * the application has to create a new CustomProperties object. It will
- * serve as a container for custom properties.
- */
- customProperties = dsi.getCustomProperties();
- assertNotNull(customProperties);
-
- /* Insert some custom properties into the container. */
- String a1 = (String) customProperties.get(k1);
- assertEquals(p1, a1, "Key1");
- String a2 = (String) customProperties.get(k2);
- assertEquals(p2, a2, "Schl\u00fcssel2");
- Integer a3 = (Integer) customProperties.get("Sample Number");
- assertEquals(12345, (int)a3, "Sample Number");
- Boolean a4 = (Boolean) customProperties.get("Sample Boolean");
- assertTrue(a4, "Sample Boolean");
- Date a5 = (Date) customProperties.get("Sample Date");
- assertEquals(date, a5, "Custom Date:");
-
- }
-
-
- /**
- * Tests with strange characters in keys and data (Umlaute etc.)
- */
+
+ /**
+ * Tests with strange characters in keys and data (Umlaute etc.)
+ */
@Test
- void testThree() throws Exception {
+ void testThree() throws Exception {
+
+ String company = strangize("company");
+ String manager = strangize("manager");
+ String category = strangize("category");
+ String title = strangize("title");
+ String author = strangize("author");
+ String comments = strangize("comments");
+ String keywords = strangize("keywords");
+ String subject = strangize("subject");
+ String p1 = strangize("p1");
+ String p2 = strangize("p2");
+ String k1 = strangize("k1");
+ String k2 = strangize("k2");
+
+ dsi.setCompany(company);
+ dsi.setManager(manager);
+ dsi.setCategory(category);
+
+ si.setTitle(title);
+ si.setAuthor(author);
+ si.setComments(comments);
+ si.setKeywords(keywords);
+ si.setSubject(subject);
+ CustomProperties customProperties = dsi.getCustomProperties();
+ if (customProperties == null) {
+ customProperties = new CustomProperties();
+ }
+
+ /* Insert some custom properties into the container. */
+ customProperties.put(k1, p1);
+ customProperties.put(k2, p2);
+ customProperties.put("Sample Number", 12345);
+ customProperties.put("Sample Boolean", false);
+ Date date = new Date(0);
+ customProperties.put("Sample Date", date);
+
+ dsi.setCustomProperties(customProperties);
+
+ closeAndReOpen();
+
+ assertNotNull(dsi);
+ assertNotNull(si);
+ /*
+ * Change the category to "POI example". Any former category value will
+ * be lost. If there has been no category yet, it will be created.
+ */
+ assertEquals(category, dsi.getCategory(), "Category");
+ assertEquals(company, dsi.getCompany(), "Company");
+ assertEquals(manager, dsi.getManager(), "Manager");
+
+ assertEquals(author, si.getAuthor());
+ assertEquals(title, si.getTitle());
+ assertEquals(comments, si.getComments());
+ assertEquals(keywords, si.getKeywords());
+ assertEquals(subject, si.getSubject());
+
+ /*
+ * Read the custom properties. If there are no custom properties yet,
+ * the application has to create a new CustomProperties object. It will
+ * serve as a container for custom properties.
+ */
+ customProperties = dsi.getCustomProperties();
+ assertNotNull(customProperties);
+
+ /* Insert some custom properties into the container. */
+ // System.out.println(k1);
+ String a1 = (String) customProperties.get(k1);
+ assertEquals(p1, a1, "Key1");
+ String a2 = (String) customProperties.get(k2);
+ assertEquals(p2, a2, "Schl\u00fcssel2");
+ Integer a3 = (Integer) customProperties.get("Sample Number");
+ assertEquals(12345, (int)a3, "Sample Number");
+ Boolean a4 = (Boolean) customProperties.get("Sample Boolean");
+ assertFalse(a4, "Sample Boolean");
+ Date a5 = (Date) customProperties.get("Sample Date");
+ assertEquals(date, a5, "Custom Date:");
- String company = strangize("company");
- String manager = strangize("manager");
- String category = strangize("category");
- String title = strangize("title");
- String author = strangize("author");
- String comments = strangize("comments");
- String keywords = strangize("keywords");
- String subject = strangize("subject");
- String p1 = strangize("p1");
- String p2 = strangize("p2");
- String k1 = strangize("k1");
- String k2 = strangize("k2");
-
- dsi.setCompany(company);
- dsi.setManager(manager);
- dsi.setCategory(category);
-
- si.setTitle(title);
- si.setAuthor(author);
- si.setComments(comments);
- si.setKeywords(keywords);
- si.setSubject(subject);
- CustomProperties customProperties = dsi.getCustomProperties();
- if (customProperties == null) {
- customProperties = new CustomProperties();
- }
-
- /* Insert some custom properties into the container. */
- customProperties.put(k1, p1);
- customProperties.put(k2, p2);
- customProperties.put("Sample Number", 12345);
- customProperties.put("Sample Boolean", false);
- Date date = new Date(0);
- customProperties.put("Sample Date", date);
-
- dsi.setCustomProperties(customProperties);
-
- closeAndReOpen();
-
- assertNotNull(dsi);
- assertNotNull(si);
- /*
- * Change the category to "POI example". Any former category value will
- * be lost. If there has been no category yet, it will be created.
- */
- assertEquals(category, dsi.getCategory(), "Category");
- assertEquals(company, dsi.getCompany(), "Company");
- assertEquals(manager, dsi.getManager(), "Manager");
-
- assertEquals(author, si.getAuthor());
- assertEquals(title, si.getTitle());
- assertEquals(comments, si.getComments());
- assertEquals(keywords, si.getKeywords());
- assertEquals(subject, si.getSubject());
-
- /*
- * Read the custom properties. If there are no custom properties yet,
- * the application has to create a new CustomProperties object. It will
- * serve as a container for custom properties.
- */
- customProperties = dsi.getCustomProperties();
- assertNotNull(customProperties);
-
- /* Insert some custom properties into the container. */
- // System.out.println(k1);
- String a1 = (String) customProperties.get(k1);
- assertEquals(p1, a1, "Key1");
- String a2 = (String) customProperties.get(k2);
- assertEquals(p2, a2, "Schl\u00fcssel2");
- Integer a3 = (Integer) customProperties.get("Sample Number");
- assertEquals(12345, (int)a3, "Sample Number");
- Boolean a4 = (Boolean) customProperties.get("Sample Boolean");
- assertFalse(a4, "Sample Boolean");
- Date a5 = (Date) customProperties.get("Sample Date");
- assertEquals(date, a5, "Custom Date:");
-
- }
-
- /**
- * Iterative testing: writing, reading etc.
- */
+ }
+
+ /**
+ * Iterative testing: writing, reading etc.
+ */
@Test
- void testFour() throws Exception {
- for (int i = 1; i < 100; i++) {
+ void testFour() throws Exception {
+ for (int i = 1; i < 100; i++) {
testThree();
- closeAndReOpen();
- }
- }
+ closeAndReOpen();
+ }
+ }
/**
- * Unicode test
- */
+ * Unicode test
+ */
@Test
- void testUnicode() throws Exception {
- String company = strangizeU("company");
- String manager = strangizeU("manager");
- String category = strangizeU("category");
- String title = strangizeU("title");
- String author = strangizeU("author");
- String comments = strangizeU("comments");
- String keywords = strangizeU("keywords");
- String subject = strangizeU("subject");
- String p1 = strangizeU("p1");
- String p2 = strangizeU("p2");
- String k1 = strangizeU("k1");
- String k2 = strangizeU("k2");
-
- dsi.setCompany(company);
- dsi.setManager(manager);
- dsi.setCategory(category);
-
- si.setTitle(title);
- si.setAuthor(author);
- si.setComments(comments);
- si.setKeywords(keywords);
- si.setSubject(subject);
-
- CustomProperties customProperties = new CustomProperties();
- /* Insert some custom properties into the container. */
- customProperties.put(k1, p1);
- customProperties.put(k2, p2);
- customProperties.put("Sample Number", 12345);
- customProperties.put("Sample Boolean", true);
- Date date = new Date();
- customProperties.put("Sample Date", date);
-
- dsi.setCustomProperties(customProperties);
-
- closeAndReOpen();
-
- assertNotNull(dsi);
- assertNotNull(si);
- /*
- * Change the category to "POI example". Any former category value will
- * be lost. If there has been no category yet, it will be created.
- */
- assertEquals(category, dsi.getCategory(), "Category");
- assertEquals(company, dsi.getCompany(), "Company");
- assertEquals(manager, dsi.getManager(), "Manager");
-
- assertEquals(author, si.getAuthor());
- assertEquals(title, si.getTitle());
- assertEquals(comments, si.getComments());
- assertEquals(keywords, si.getKeywords());
- assertEquals(subject, si.getSubject());
-
- /*
- * Read the custom properties. If there are no custom properties yet,
- * the application has to create a new CustomProperties object. It will
- * serve as a container for custom properties.
- */
- customProperties = dsi.getCustomProperties();
- assertNotNull(customProperties);
-
- /* Insert some custom properties into the container. */
- // System.out.println(k1);
- String a1 = (String) customProperties.get(k1);
- assertEquals(p1, a1, "Key1");
- String a2 = (String) customProperties.get(k2);
- assertEquals(p2, a2, "Schl\u00fcssel2");
- Integer a3 = (Integer) customProperties.get("Sample Number");
- assertEquals(12345, (int)a3, "Sample Number");
- Boolean a4 = (Boolean) customProperties.get("Sample Boolean");
- assertTrue(a4, "Sample Boolean");
- Date a5 = (Date) customProperties.get("Sample Date");
- assertEquals(date, a5, "Custom Date:");
- }
-
-
- /**
- * Iterative testing of the unicode test
- *
- */
+ void testUnicode() throws Exception {
+ String company = strangizeU("company");
+ String manager = strangizeU("manager");
+ String category = strangizeU("category");
+ String title = strangizeU("title");
+ String author = strangizeU("author");
+ String comments = strangizeU("comments");
+ String keywords = strangizeU("keywords");
+ String subject = strangizeU("subject");
+ String p1 = strangizeU("p1");
+ String p2 = strangizeU("p2");
+ String k1 = strangizeU("k1");
+ String k2 = strangizeU("k2");
+
+ dsi.setCompany(company);
+ dsi.setManager(manager);
+ dsi.setCategory(category);
+
+ si.setTitle(title);
+ si.setAuthor(author);
+ si.setComments(comments);
+ si.setKeywords(keywords);
+ si.setSubject(subject);
+
+ CustomProperties customProperties = new CustomProperties();
+ /* Insert some custom properties into the container. */
+ customProperties.put(k1, p1);
+ customProperties.put(k2, p2);
+ customProperties.put("Sample Number", 12345);
+ customProperties.put("Sample Boolean", true);
+ Date date = new Date();
+ customProperties.put("Sample Date", date);
+
+ dsi.setCustomProperties(customProperties);
+
+ closeAndReOpen();
+
+ assertNotNull(dsi);
+ assertNotNull(si);
+ /*
+ * Change the category to "POI example". Any former category value will
+ * be lost. If there has been no category yet, it will be created.
+ */
+ assertEquals(category, dsi.getCategory(), "Category");
+ assertEquals(company, dsi.getCompany(), "Company");
+ assertEquals(manager, dsi.getManager(), "Manager");
+
+ assertEquals(author, si.getAuthor());
+ assertEquals(title, si.getTitle());
+ assertEquals(comments, si.getComments());
+ assertEquals(keywords, si.getKeywords());
+ assertEquals(subject, si.getSubject());
+
+ /*
+ * Read the custom properties. If there are no custom properties yet,
+ * the application has to create a new CustomProperties object. It will
+ * serve as a container for custom properties.
+ */
+ customProperties = dsi.getCustomProperties();
+ assertNotNull(customProperties);
+
+ /* Insert some custom properties into the container. */
+ // System.out.println(k1);
+ String a1 = (String) customProperties.get(k1);
+ assertEquals(p1, a1, "Key1");
+ String a2 = (String) customProperties.get(k2);
+ assertEquals(p2, a2, "Schl\u00fcssel2");
+ Integer a3 = (Integer) customProperties.get("Sample Number");
+ assertEquals(12345, (int)a3, "Sample Number");
+ Boolean a4 = (Boolean) customProperties.get("Sample Boolean");
+ assertTrue(a4, "Sample Boolean");
+ Date a5 = (Date) customProperties.get("Sample Date");
+ assertEquals(date, a5, "Custom Date:");
+ }
+
+
+ /**
+ * Iterative testing of the unicode test
+ *
+ */
@Test
- void testSix() throws Exception {
- for (int i = 1; i < 100; i++) {
+ void testSix() throws Exception {
+ for (int i = 1; i < 100; i++) {
testUnicode();
- closeAndReOpen();
- }
- }
+ closeAndReOpen();
+ }
+ }
- /**
- * Tests conversion in custom fields and errors
- */
+ /**
+ * Tests conversion in custom fields and errors
+ */
@Test
- void testConvAndExistence() throws Exception {
+ void testConvAndExistence() throws Exception {
- CustomProperties customProperties = dsi.getCustomProperties();
- if (customProperties == null) {
- customProperties = new CustomProperties();
- }
-
- /* Insert some custom properties into the container. */
- customProperties.put("int", 12345);
- customProperties.put("negint", -12345);
- customProperties.put("long", 12345L);
- customProperties.put("neglong", -12345L);
- customProperties.put("boolean", true);
- customProperties.put("string", "a String");
- // customProperties.put("float", new Float(12345.0)); is not valid
- // customProperties.put("negfloat", new Float(-12345.1)); is not valid
- customProperties.put("double", 12345.2);
- customProperties.put("negdouble", -12345.3);
- // customProperties.put("char", new Character('a')); is not valid
-
- Date date = new Date();
- customProperties.put("date", date);
-
- dsi.setCustomProperties(customProperties);
-
- closeAndReOpen();
-
- assertNotNull(dsi);
- assertNotNull(si);
- /*
- * Change the category to "POI example". Any former category value will
- * be lost. If there has been no category yet, it will be created.
- */
- assertNull(dsi.getCategory());
- assertNull(dsi.getCompany());
- assertNull(dsi.getManager());
-
- assertNull(si.getAuthor());
- assertNull(si.getTitle());
- assertNull(si.getComments());
- assertNull(si.getKeywords());
- assertNull(si.getSubject());
-
- /*
- * Read the custom properties. If there are no custom properties yet,
- * the application has to create a new CustomProperties object. It will
- * serve as a container for custom properties.
- */
- customProperties = dsi.getCustomProperties();
- assertNotNull(customProperties);
-
- /* Insert some custom properties into the container. */
-
- Integer a3 = (Integer) customProperties.get("int");
- assertEquals(12345, (int)a3, "int");
-
- a3 = (Integer) customProperties.get("negint");
- assertEquals(-12345, (int)a3, "negint");
-
- Long al = (Long) customProperties.get("neglong");
- assertEquals(-12345L, (long)al, "neglong");
-
- al = (Long) customProperties.get("long");
- assertEquals(12345L, (long)al, "long");
-
- Boolean a4 = (Boolean) customProperties.get("boolean");
- assertTrue(a4, "boolean");
-
- Date a5 = (Date) customProperties.get("date");
- assertEquals(date, a5, "Custom Date:");
-
- Double d = (Double) customProperties.get("double");
- assertEquals(12345.2, d, 0, "int");
-
- d = (Double) customProperties.get("negdouble");
- assertEquals(-12345.3, d, 0, "string");
-
- String s = (String) customProperties.get("string");
- assertEquals("a String", s, "string");
-
-
- assertTrue(customProperties.get("string") instanceof String);
- assertTrue(customProperties.get("boolean") instanceof Boolean);
- assertTrue(customProperties.get("int") instanceof Integer);
- assertTrue(customProperties.get("negint") instanceof Integer);
- assertTrue(customProperties.get("long") instanceof Long);
- assertTrue(customProperties.get("neglong") instanceof Long);
- assertTrue(customProperties.get("double") instanceof Double);
- assertTrue(customProperties.get("negdouble") instanceof Double);
- assertTrue(customProperties.get("date") instanceof Date);
- }
+ CustomProperties customProperties = dsi.getCustomProperties();
+ if (customProperties == null) {
+ customProperties = new CustomProperties();
+ }
+
+ /* Insert some custom properties into the container. */
+ customProperties.put("int", 12345);
+ customProperties.put("negint", -12345);
+ customProperties.put("long", 12345L);
+ customProperties.put("neglong", -12345L);
+ customProperties.put("boolean", true);
+ customProperties.put("string", "a String");
+ // customProperties.put("float", new Float(12345.0)); is not valid
+ // customProperties.put("negfloat", new Float(-12345.1)); is not valid
+ customProperties.put("double", 12345.2);
+ customProperties.put("negdouble", -12345.3);
+ // customProperties.put("char", new Character('a')); is not valid
+
+ Date date = new Date();
+ customProperties.put("date", date);
+
+ dsi.setCustomProperties(customProperties);
+
+ closeAndReOpen();
+
+ assertNotNull(dsi);
+ assertNotNull(si);
+ /*
+ * Change the category to "POI example". Any former category value will
+ * be lost. If there has been no category yet, it will be created.
+ */
+ assertNull(dsi.getCategory());
+ assertNull(dsi.getCompany());
+ assertNull(dsi.getManager());
+
+ assertNull(si.getAuthor());
+ assertNull(si.getTitle());
+ assertNull(si.getComments());
+ assertNull(si.getKeywords());
+ assertNull(si.getSubject());
+
+ /*
+ * Read the custom properties. If there are no custom properties yet,
+ * the application has to create a new CustomProperties object. It will
+ * serve as a container for custom properties.
+ */
+ customProperties = dsi.getCustomProperties();
+ assertNotNull(customProperties);
+
+ /* Insert some custom properties into the container. */
+
+ Integer a3 = (Integer) customProperties.get("int");
+ assertEquals(12345, (int)a3, "int");
+
+ a3 = (Integer) customProperties.get("negint");
+ assertEquals(-12345, (int)a3, "negint");
+
+ Long al = (Long) customProperties.get("neglong");
+ assertEquals(-12345L, (long)al, "neglong");
+
+ al = (Long) customProperties.get("long");
+ assertEquals(12345L, (long)al, "long");
+
+ Boolean a4 = (Boolean) customProperties.get("boolean");
+ assertTrue(a4, "boolean");
+
+ Date a5 = (Date) customProperties.get("date");
+ assertEquals(date, a5, "Custom Date:");
+
+ Double d = (Double) customProperties.get("double");
+ assertEquals(12345.2, d, 0, "int");
+
+ d = (Double) customProperties.get("negdouble");
+ assertEquals(-12345.3, d, 0, "string");
+
+ String s = (String) customProperties.get("string");
+ assertEquals("a String", s, "string");
+
+
+ assertTrue(customProperties.get("string") instanceof String);
+ assertTrue(customProperties.get("boolean") instanceof Boolean);
+ assertTrue(customProperties.get("int") instanceof Integer);
+ assertTrue(customProperties.get("negint") instanceof Integer);
+ assertTrue(customProperties.get("long") instanceof Long);
+ assertTrue(customProperties.get("neglong") instanceof Long);
+ assertTrue(customProperties.get("double") instanceof Double);
+ assertTrue(customProperties.get("negdouble") instanceof Double);
+ assertTrue(customProperties.get("date") instanceof Date);
+ }
/**
@@ -532,8 +532,8 @@ final class TestMetaDataIPI {
poifs.close();
try (InputStream is = bout.toInputStream()) {
- poifs = new POIFSFileSystem(is);
- }
+ poifs = new POIFSFileSystem(is);
+ }
/* Read the document summary information. */
DirectoryEntry dir = poifs.getRoot();
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/HSSFTestDataSamples.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/HSSFTestDataSamples.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/HSSFTestDataSamples.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/HSSFTestDataSamples.java Sat May 22 20:56:44 2021
@@ -30,38 +30,38 @@ import org.apache.poi.hssf.usermodel.HSS
*/
public final class HSSFTestDataSamples {
- private static final POIDataSamples _inst = POIDataSamples.getSpreadSheetInstance();
+ private static final POIDataSamples _inst = POIDataSamples.getSpreadSheetInstance();
- public static InputStream openSampleFileStream(String sampleFileName) {
- return _inst.openResourceAsStream(sampleFileName);
- }
- public static File getSampleFile(String sampleFileName) {
- return _inst.getFile(sampleFileName);
- }
- public static byte[] getTestDataFileContent(String fileName) {
- return _inst.readFile(fileName);
- }
+ public static InputStream openSampleFileStream(String sampleFileName) {
+ return _inst.openResourceAsStream(sampleFileName);
+ }
+ public static File getSampleFile(String sampleFileName) {
+ return _inst.getFile(sampleFileName);
+ }
+ public static byte[] getTestDataFileContent(String fileName) {
+ return _inst.readFile(fileName);
+ }
- public static HSSFWorkbook openSampleWorkbook(String sampleFileName) {
- try {
- return new HSSFWorkbook(_inst.openResourceAsStream(sampleFileName));
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- /**
- * Writes a spreadsheet to a {@code ByteArrayOutputStream} and reads it back
- * from a {@code ByteArrayInputStream}.<p>
- * Useful for verifying that the serialisation round trip
- */
- public static HSSFWorkbook writeOutAndReadBack(HSSFWorkbook original) {
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
- original.write(baos);
- try (InputStream is = baos.toInputStream()) {
- return new HSSFWorkbook(is);
- }
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
+ public static HSSFWorkbook openSampleWorkbook(String sampleFileName) {
+ try {
+ return new HSSFWorkbook(_inst.openResourceAsStream(sampleFileName));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ /**
+ * Writes a spreadsheet to a {@code ByteArrayOutputStream} and reads it back
+ * from a {@code ByteArrayInputStream}.<p>
+ * Useful for verifying that the serialisation round trip
+ */
+ public static HSSFWorkbook writeOutAndReadBack(HSSFWorkbook original) {
+ try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+ original.write(baos);
+ try (InputStream is = baos.toInputStream()) {
+ return new HSSFWorkbook(is);
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java Sat May 22 20:56:44 2021
@@ -90,14 +90,14 @@ public abstract class BaseTestIteratingX
@ParameterizedTest
@MethodSource("files")
- void testMain(File file, Class<? extends Throwable> t) throws Exception {
+ void testMain(File file, Class<? extends Throwable> t) throws Exception {
Executable ex = () -> runOneFile(file);
if (t == null) {
assertDoesNotThrow(ex);
} else {
assertThrows(t, ex);
}
- }
+ }
- abstract void runOneFile(File pFile) throws Exception;
+ abstract void runOneFile(File pFile) throws Exception;
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java Sat May 22 20:56:44 2021
@@ -42,10 +42,10 @@ class TestBiffDrawingToXml extends BaseT
return excludes;
}
- @Override
- void runOneFile(File pFile) throws Exception {
+ @Override
+ void runOneFile(File pFile) throws Exception {
try (InputStream wb = new FileInputStream(pFile)) {
BiffDrawingToXml.writeToFile(NULL_OUTPUT_STREAM, wb, false, new String[0]);
}
- }
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestEFBiffViewer.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestEFBiffViewer.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestEFBiffViewer.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestEFBiffViewer.java Sat May 22 20:56:44 2021
@@ -32,36 +32,36 @@ class TestEFBiffViewer extends BaseTestI
@Override
protected Map<String, Class<? extends Throwable>> getExcludes() {
Map<String, Class<? extends Throwable>> excludes = super.getExcludes();
- // unsupported crypto api header
+ // unsupported crypto api header
excludes.put("35897-type4.xls", EncryptedDocumentException.class);
excludes.put("51832.xls", EncryptedDocumentException.class);
excludes.put("xor-encryption-abc.xls", EncryptedDocumentException.class);
excludes.put("password.xls", EncryptedDocumentException.class);
- // HSSFWorkbook cannot open it as well
+ // HSSFWorkbook cannot open it as well
excludes.put("43493.xls", RecordInputStream.LeftoverDataException.class);
excludes.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
- // "Buffer overrun"
+ // "Buffer overrun"
excludes.put("XRefCalc.xls", RuntimeException.class);
return excludes;
}
- @Override
- void runOneFile(File fileIn) throws IOException {
- PrintStream save = System.out;
- try {
- // redirect standard out during the test to avoid spamming the console with output
- System.setOut(new NullPrintStream());
+ @Override
+ void runOneFile(File fileIn) throws IOException {
+ PrintStream save = System.out;
+ try {
+ // redirect standard out during the test to avoid spamming the console with output
+ System.setOut(new NullPrintStream());
- EFBiffViewer.main(new String[] { fileIn.getAbsolutePath() });
- } finally {
- System.setOut(save);
- }
- }
+ EFBiffViewer.main(new String[] { fileIn.getAbsolutePath() });
+ } finally {
+ System.setOut(save);
+ }
+ }
- //@Test
- void testFile() throws IOException {
- EFBiffViewer viewer = new EFBiffViewer();
- viewer.setFile(new File("test-data/spreadsheet/59074.xls").getAbsolutePath());
- viewer.run();
- }
+ //@Test
+ void testFile() throws IOException {
+ EFBiffViewer viewer = new EFBiffViewer();
+ viewer.setFile(new File("test-data/spreadsheet/59074.xls").getAbsolutePath());
+ viewer.run();
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestFormulaViewer.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestFormulaViewer.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestFormulaViewer.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestFormulaViewer.java Sat May 22 20:56:44 2021
@@ -43,26 +43,26 @@ class TestFormulaViewer extends BaseTest
}
@Override
- void runOneFile(File fileIn) throws Exception {
- PrintStream save = System.out;
- try {
- // redirect standard out during the test to avoid spamming the console with output
- System.setOut(new NullPrintStream());
+ void runOneFile(File fileIn) throws Exception {
+ PrintStream save = System.out;
+ try {
+ // redirect standard out during the test to avoid spamming the console with output
+ System.setOut(new NullPrintStream());
FormulaViewer viewer = new FormulaViewer();
viewer.setFile(fileIn.getAbsolutePath());
viewer.setList(true);
viewer.run();
- } catch (RuntimeException re) {
- String m = re.getMessage();
- if (m.startsWith("toFormulaString") || m.startsWith("3D references")) {
- // TODO: fix those cases, but ignore them for now ...
- assumeTrue(true);
- } else {
- throw re;
- }
- } finally {
- System.setOut(save);
- }
- }
+ } catch (RuntimeException re) {
+ String m = re.getMessage();
+ if (m.startsWith("toFormulaString") || m.startsWith("3D references")) {
+ // TODO: fix those cases, but ignore them for now ...
+ assumeTrue(true);
+ } else {
+ throw re;
+ }
+ } finally {
+ System.setOut(save);
+ }
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestReSave.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestReSave.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestReSave.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestReSave.java Sat May 22 20:56:44 2021
@@ -51,35 +51,35 @@ class TestReSave extends BaseTestIterati
return excludes;
}
- @Override
- void runOneFile(File fileIn) throws Exception {
- // avoid running on files leftover from previous failed runs
- if(fileIn.getName().endsWith("-saved.xls")) {
- return;
- }
-
- PrintStream save = System.out;
- try {
- // redirect standard out during the test to avoid spamming the console with output
- System.setOut(new NullPrintStream());
-
- File reSavedFile = new File(fileIn.getParentFile(), fileIn.getName().replace(".xls", "-saved.xls"));
- try {
- ReSave.main(new String[] { fileIn.getAbsolutePath() });
+ @Override
+ void runOneFile(File fileIn) throws Exception {
+ // avoid running on files leftover from previous failed runs
+ if(fileIn.getName().endsWith("-saved.xls")) {
+ return;
+ }
+
+ PrintStream save = System.out;
+ try {
+ // redirect standard out during the test to avoid spamming the console with output
+ System.setOut(new NullPrintStream());
+
+ File reSavedFile = new File(fileIn.getParentFile(), fileIn.getName().replace(".xls", "-saved.xls"));
+ try {
+ ReSave.main(new String[] { fileIn.getAbsolutePath() });
- // also try BiffViewer on the saved file
+ // also try BiffViewer on the saved file
new TestBiffViewer().runOneFile(reSavedFile);
- // had one case where the re-saved could not be re-saved!
- ReSave.main(new String[] { "-bos", reSavedFile.getAbsolutePath() });
- } finally {
- // clean up the re-saved file
- assertTrue(!reSavedFile.exists() || reSavedFile.delete());
- }
- } finally {
- System.setOut(save);
- }
- }
+ // had one case where the re-saved could not be re-saved!
+ ReSave.main(new String[] { "-bos", reSavedFile.getAbsolutePath() });
+ } finally {
+ // clean up the re-saved file
+ assertTrue(!reSavedFile.exists() || reSavedFile.delete());
+ }
+ } finally {
+ System.setOut(save);
+ }
+ }
@Disabled("Only used for local testing")
@Test
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java Sat May 22 20:56:44 2021
@@ -26,25 +26,25 @@ import org.junit.jupiter.api.parallel.Re
@ResourceLock(Resources.SYSTEM_OUT)
class TestRecordLister extends BaseTestIteratingXLS {
- @Override
- void runOneFile(File fileIn) throws IOException {
- PrintStream save = System.out;
- try {
- // redirect standard out during the test to avoid spamming the console with output
- System.setOut(new NullPrintStream());
+ @Override
+ void runOneFile(File fileIn) throws IOException {
+ PrintStream save = System.out;
+ try {
+ // redirect standard out during the test to avoid spamming the console with output
+ System.setOut(new NullPrintStream());
- RecordLister viewer = new RecordLister();
+ RecordLister viewer = new RecordLister();
viewer.setFile(fileIn.getAbsolutePath());
viewer.run();
- } finally {
- System.setOut(save);
- }
- }
+ } finally {
+ System.setOut(save);
+ }
+ }
- //@Test
- void testFile() throws IOException {
- RecordLister viewer = new RecordLister();
+ //@Test
+ void testFile() throws IOException {
+ RecordLister viewer = new RecordLister();
viewer.setFile(new File("test-data/spreadsheet/testEXCEL_95.xls").getAbsolutePath());
viewer.run();
- }
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestAbortableListener.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestAbortableListener.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestAbortableListener.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestAbortableListener.java Sat May 22 20:56:44 2021
@@ -38,71 +38,71 @@ import org.junit.jupiter.api.Test;
*/
final class TestAbortableListener {
- private POIFSFileSystem openSample() throws IOException {
- ByteArrayInputStream is = new ByteArrayInputStream(HSSFITestDataProvider.instance
- .getTestDataFileContent("SimpleWithColours.xls"));
- return new POIFSFileSystem(is);
- }
-
- @Test
- void testAbortingBasics() throws Exception {
- AbortableCountingListener l = new AbortableCountingListener(1000);
+ private POIFSFileSystem openSample() throws IOException {
+ ByteArrayInputStream is = new ByteArrayInputStream(HSSFITestDataProvider.instance
+ .getTestDataFileContent("SimpleWithColours.xls"));
+ return new POIFSFileSystem(is);
+ }
+
+ @Test
+ void testAbortingBasics() throws Exception {
+ AbortableCountingListener l = new AbortableCountingListener(1000);
- HSSFRequest req = new HSSFRequest();
- req.addListenerForAllRecords(l);
+ HSSFRequest req = new HSSFRequest();
+ req.addListenerForAllRecords(l);
- HSSFEventFactory f = new HSSFEventFactory();
+ HSSFEventFactory f = new HSSFEventFactory();
- assertEquals(0, l.countSeen);
+ assertEquals(0, l.countSeen);
assertNull(l.lastRecordSeen);
- POIFSFileSystem fs = openSample();
- short res = f.abortableProcessWorkbookEvents(req, fs);
+ POIFSFileSystem fs = openSample();
+ short res = f.abortableProcessWorkbookEvents(req, fs);
- assertEquals(0, res);
- assertEquals(175, l.countSeen);
- assertEquals(EOFRecord.sid, l.lastRecordSeen.getSid());
- }
+ assertEquals(0, res);
+ assertEquals(175, l.countSeen);
+ assertEquals(EOFRecord.sid, l.lastRecordSeen.getSid());
+ }
- @Test
- void testAbortStops() throws Exception {
- AbortableCountingListener l = new AbortableCountingListener(1);
+ @Test
+ void testAbortStops() throws Exception {
+ AbortableCountingListener l = new AbortableCountingListener(1);
- HSSFRequest req = new HSSFRequest();
- req.addListenerForAllRecords(l);
+ HSSFRequest req = new HSSFRequest();
+ req.addListenerForAllRecords(l);
- HSSFEventFactory f = new HSSFEventFactory();
+ HSSFEventFactory f = new HSSFEventFactory();
- assertEquals(0, l.countSeen);
+ assertEquals(0, l.countSeen);
assertNull(l.lastRecordSeen);
- POIFSFileSystem fs = openSample();
- short res = f.abortableProcessWorkbookEvents(req, fs);
+ POIFSFileSystem fs = openSample();
+ short res = f.abortableProcessWorkbookEvents(req, fs);
- assertEquals(1234, res);
- assertEquals(1, l.countSeen);
- assertEquals(BOFRecord.sid, l.lastRecordSeen.getSid());
- }
-
- private static final class AbortableCountingListener extends AbortableHSSFListener {
- private final int abortAfterIndex;
- public int countSeen;
- public Record lastRecordSeen;
-
- public AbortableCountingListener(int abortAfter) {
- abortAfterIndex = abortAfter;
- countSeen = 0;
- lastRecordSeen = null;
- }
- @Override
- public short abortableProcessRecord(org.apache.poi.hssf.record.Record record) {
- countSeen++;
- lastRecordSeen = record;
-
- if (countSeen == abortAfterIndex) {
- return 1234;
- }
- return 0;
- }
- }
+ assertEquals(1234, res);
+ assertEquals(1, l.countSeen);
+ assertEquals(BOFRecord.sid, l.lastRecordSeen.getSid());
+ }
+
+ private static final class AbortableCountingListener extends AbortableHSSFListener {
+ private final int abortAfterIndex;
+ public int countSeen;
+ public Record lastRecordSeen;
+
+ public AbortableCountingListener(int abortAfter) {
+ abortAfterIndex = abortAfter;
+ countSeen = 0;
+ lastRecordSeen = null;
+ }
+ @Override
+ public short abortableProcessRecord(org.apache.poi.hssf.record.Record record) {
+ countSeen++;
+ lastRecordSeen = record;
+
+ if (countSeen == abortAfterIndex) {
+ return 1234;
+ }
+ return 0;
+ }
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java Sat May 22 20:56:44 2021
@@ -68,7 +68,7 @@ final class TestEventRecordFactory {
assertEquals(rec.getSid(), BOFRecord.sid, "must be BOFRecord got SID=" + rec.getSid());
return true;
};
- EventRecordFactory factory = new EventRecordFactory(listener, new short[] {BOFRecord.sid});
+ EventRecordFactory factory = new EventRecordFactory(listener, new short[] {BOFRecord.sid});
BOFRecord bof = new BOFRecord();
bof.setBuild((short)0);
@@ -79,7 +79,7 @@ final class TestEventRecordFactory {
bof.setHistoryBitMask(BOFRecord.HISTORY_MASK);
EOFRecord eof = EOFRecord.instance;
- byte[] bytes = new byte[bof.getRecordSize() + eof.getRecordSize()];
+ byte[] bytes = new byte[bof.getRecordSize() + eof.getRecordSize()];
int offset = 0;
offset = bof.serialize(offset,bytes);
eof.serialize(offset,bytes);
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventusermodel/TestFormatTrackingHSSFListener.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventusermodel/TestFormatTrackingHSSFListener.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventusermodel/TestFormatTrackingHSSFListener.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventusermodel/TestFormatTrackingHSSFListener.java Sat May 22 20:56:44 2021
@@ -35,82 +35,82 @@ import org.junit.jupiter.api.Test;
* Tests for FormatTrackingHSSFListener
*/
final class TestFormatTrackingHSSFListener {
- private FormatTrackingHSSFListener listener;
- private MockHSSFListener mockListen;
+ private FormatTrackingHSSFListener listener;
+ private MockHSSFListener mockListen;
- private void processFile(String filename) throws Exception {
- HSSFRequest req = new HSSFRequest();
- mockListen = new MockHSSFListener();
- listener = new FormatTrackingHSSFListener(mockListen);
- req.addListenerForAllRecords(listener);
+ private void processFile(String filename) throws Exception {
+ HSSFRequest req = new HSSFRequest();
+ mockListen = new MockHSSFListener();
+ listener = new FormatTrackingHSSFListener(mockListen);
+ req.addListenerForAllRecords(listener);
File file = HSSFTestDataSamples.getSampleFile(filename);
- HSSFEventFactory factory = new HSSFEventFactory();
- POIFSFileSystem fs = new POIFSFileSystem(file);
- factory.processWorkbookEvents(req, fs);
- fs.close();
- }
-
- @Test
- void testFormats() throws Exception {
- processFile("MissingBits.xls");
-
- assertEquals("_(* #,##0_);_(* (#,##0);_(* \"-\"_);_(@_)", listener.getFormatString(41));
- assertEquals("_(\"$\"* #,##0_);_(\"$\"* (#,##0);_(\"$\"* \"-\"_);_(@_)", listener.getFormatString(42));
- assertEquals("_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)", listener.getFormatString(43));
- assertEquals("_(\"$\"* #,##0.00_);_(\"$\"* (#,##0.00);_(\"$\"* \"-\"??_);_(@_)", listener.getFormatString(44));
- }
-
- /**
- * Ensure that all number and formula records can be
- * turned into strings without problems.
- * For now, we're just looking to get text back, no
- * exceptions thrown, but in future we might also
- * want to check the exact strings!
- */
- @Test
- void testTurnToString() throws Exception {
- String[] files = new String[] {
- "45365.xls", "45365-2.xls", "MissingBits.xls"
- };
- for (String file : files) {
- processFile(file);
-
- // Check we found our formats
- assertTrue(listener.getNumberOfCustomFormats() > 5);
- assertTrue(listener.getNumberOfExtendedFormats() > 5);
-
- // Now check we can turn all the numeric
- // cells into strings without error
- for(org.apache.poi.hssf.record.Record r : mockListen._records) {
- CellValueRecordInterface cvr = null;
-
- if(r instanceof NumberRecord) {
- cvr = (CellValueRecordInterface)r;
- }
- if(r instanceof FormulaRecord) {
- cvr = (CellValueRecordInterface)r;
- }
-
- if(cvr != null) {
- // Should always give us a string
- String s = listener.formatNumberDateCell(cvr);
- assertNotNull(s);
- assertTrue(s.length() > 0);
- }
- }
-
- // TODO - test some specific format strings
- }
- }
-
- private static final class MockHSSFListener implements HSSFListener {
- public MockHSSFListener() {}
- private final List<org.apache.poi.hssf.record.Record> _records = new ArrayList<>();
+ HSSFEventFactory factory = new HSSFEventFactory();
+ POIFSFileSystem fs = new POIFSFileSystem(file);
+ factory.processWorkbookEvents(req, fs);
+ fs.close();
+ }
+
+ @Test
+ void testFormats() throws Exception {
+ processFile("MissingBits.xls");
+
+ assertEquals("_(* #,##0_);_(* (#,##0);_(* \"-\"_);_(@_)", listener.getFormatString(41));
+ assertEquals("_(\"$\"* #,##0_);_(\"$\"* (#,##0);_(\"$\"* \"-\"_);_(@_)", listener.getFormatString(42));
+ assertEquals("_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)", listener.getFormatString(43));
+ assertEquals("_(\"$\"* #,##0.00_);_(\"$\"* (#,##0.00);_(\"$\"* \"-\"??_);_(@_)", listener.getFormatString(44));
+ }
+
+ /**
+ * Ensure that all number and formula records can be
+ * turned into strings without problems.
+ * For now, we're just looking to get text back, no
+ * exceptions thrown, but in future we might also
+ * want to check the exact strings!
+ */
+ @Test
+ void testTurnToString() throws Exception {
+ String[] files = new String[] {
+ "45365.xls", "45365-2.xls", "MissingBits.xls"
+ };
+ for (String file : files) {
+ processFile(file);
+
+ // Check we found our formats
+ assertTrue(listener.getNumberOfCustomFormats() > 5);
+ assertTrue(listener.getNumberOfExtendedFormats() > 5);
+
+ // Now check we can turn all the numeric
+ // cells into strings without error
+ for(org.apache.poi.hssf.record.Record r : mockListen._records) {
+ CellValueRecordInterface cvr = null;
+
+ if(r instanceof NumberRecord) {
+ cvr = (CellValueRecordInterface)r;
+ }
+ if(r instanceof FormulaRecord) {
+ cvr = (CellValueRecordInterface)r;
+ }
+
+ if(cvr != null) {
+ // Should always give us a string
+ String s = listener.formatNumberDateCell(cvr);
+ assertNotNull(s);
+ assertTrue(s.length() > 0);
+ }
+ }
+
+ // TODO - test some specific format strings
+ }
+ }
+
+ private static final class MockHSSFListener implements HSSFListener {
+ public MockHSSFListener() {}
+ private final List<org.apache.poi.hssf.record.Record> _records = new ArrayList<>();
- @Override
+ @Override
public void processRecord(org.apache.poi.hssf.record.Record record) {
- _records.add(record);
- }
- }
+ _records.add(record);
+ }
+ }
}
\ No newline at end of file
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java Sat May 22 20:56:44 2021
@@ -47,180 +47,180 @@ import org.junit.jupiter.api.Test;
*/
final class TestMissingRecordAwareHSSFListener {
- private final List<org.apache.poi.hssf.record.Record> _records = new ArrayList<>();
+ private final List<org.apache.poi.hssf.record.Record> _records = new ArrayList<>();
- private void readRecords(String sampleFileName) throws IOException {
- _records.clear();
- HSSFRequest req = new HSSFRequest();
- req.addListenerForAllRecords(new MissingRecordAwareHSSFListener(_records::add));
-
- HSSFEventFactory factory = new HSSFEventFactory();
- try (InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
- POIFSFileSystem fs = new POIFSFileSystem(is)) {
- factory.processWorkbookEvents(req, fs);
- }
-
- assertTrue(_records.size() > 100);
- }
-
- @Test
- void testMissingRowRecords() throws IOException {
- readRecords("MissingBits.xls");
-
- // We have rows 0, 1, 2, 20 and 21
- int row0 = lastIndexOf(r -> r instanceof RowRecord && ((RowRecord)r).getRowNumber() == 0);
- assertTrue(row0 > -1);
-
- // Records: row 0: column 1, 2), then missing rows, rows 20,21,22 each 1 column
- String exp1 =
- "0:rr,1:rr,2:rr,3:mr,4:mr,5:mr,6:mr,7:mr,8:mr,9:mr,10:mr,11:mr,12:mr,13:mr,14:mr," +
- "15:mr,16:mr,17:mr,18:mr,19:mr,20:rr,21:rr,22:rr";
- String act1 = digest(row0, 22);
- assertEquals(exp1, act1);
-
-
- // Find the cell at 0,0
- int cell00 = lastIndexOf(r -> r instanceof LabelSSTRecord && ((LabelSSTRecord)r).getRow() == 0 && ((LabelSSTRecord)r).getColumn() == 0);
-
- String exp2 =
- "0:ls0lc0," +
- "1:nr0/11mc1mc2nr3/23lc3," +
- "2:nr0/45mc1mc2mc3mc4nr5/22lc5," +
- "3:lc,4:lc,5:lc,6:lc,7:lc,8:lc,9:lc,10:lc,11:lc,12:lc,13:lc,14:lc,15:lc,16:lc,17:lc,18:lc,19:lc," +
- "20:nr0/50nr1/51nr2/52nr3/53nr4/54lc4," +
- "21:ls0ls1mc2nr3/12mc4nr5/23nr6/42lc6," +
- "22:ls0mc1mc2ls3ls4mc5mc6mc7mc8mc9mc10ls11lc11";
- String act2 = digest(cell00, 57);
- assertEquals(exp2, act2);
- }
-
- // Make sure we don't put in any extra new lines that aren't already there
- @Test
- void testNoExtraNewLines() throws IOException {
- // Load a different file
- // This file has has something in lines 1-33
- readRecords("MRExtraLines.xls");
-
- int rowCount=0;
- for (org.apache.poi.hssf.record.Record rec : _records) {
- if (rec instanceof LastCellOfRowDummyRecord) {
- LastCellOfRowDummyRecord eor = (LastCellOfRowDummyRecord) rec;
- assertEquals(rowCount, eor.getRow());
- rowCount++;
- }
- }
- // Check we got the 33 rows
- assertEquals(33, rowCount);
- }
-
- /**
- * Make sure that the presence of shared formulas does not cause extra end-of-row records.
- */
- @Test
- void testEndOfRow_bug45672() throws IOException {
- readRecords("ex45672.xls");
- assertEquals(1, matches(r -> r instanceof SharedFormulaRecord));
- assertEquals(1, matches(r -> r instanceof LastCellOfRowDummyRecord));
- }
-
- /**
- * MulBlank records hold multiple blank cells.
- * Check that we don't have any MulBlankRecords, but do have lots of BlankRecords
- */
- @Test
- void testMulBlankHandling() throws IOException {
- readRecords("45672.xls");
- assertEquals(20, matches(r -> r instanceof BlankRecord));
- assertEquals(2, matches(r -> r instanceof LastCellOfRowDummyRecord));
- assertEquals(0, matches(r -> r instanceof MulBlankRecord));
- }
-
- @Test
- void testStringRecordHandling() throws IOException {
- readRecords("53588.xls");
- assertEquals(1, matches(r -> r instanceof MissingCellDummyRecord));
- assertEquals(1, matches(r -> r instanceof LastCellOfRowDummyRecord));
- }
-
- @Test
- void testFormulasWithStringResultsHandling() throws IOException {
- readRecords("53433.xls");
-
- String exp =
- "dr0:mr,1:mr,2:mr,3:rr,4:rr,5:rr,6:rr,7:rr,8:rr,9:rr,10:mr,11:mr,12:mr,13:mr,14:mr,15:rr,16:rr,17:mr,18:rr," +
- "0:lc,1:lc,2:lc,3:mc0ls1ls2ls3ls4lc4,4:mc0ls1cv2urnr3/12cv4urlc4," +
- "5:mc0cv1urnr2/23nr3/23cv4urlc4,6:mc0mc1nr2/25nr3/45nr4/32815lc4," +
- "7:mc0ls1cv2cv3urcv4lc4,8:mc0mc1mc2mc3cv4lc4,9:mc0mc1mc2ls3lc3," +
- "10:lc,11:lc,12:lc,13:lc,14:lc,15:mc0ls1lc1,16:mc0mc1mc2ls3lc3," +
- "17:lc,18:mc0mc1mc2mc3ls4lc4wr";
- String act = digest(95, 89);
- assertEquals(exp, act);
- }
-
- private int lastIndexOf(Predicate<org.apache.poi.hssf.record.Record> pre) {
- int found = -1;
- int i = 0;
- for (org.apache.poi.hssf.record.Record r : _records) {
- if (pre.test(r)) {
- found = i;
- }
- i++;
- }
- return found;
- }
-
- private String digest(int start, int len) {
- StringBuilder sb = new StringBuilder(len*10);
- int lastRow = -1;
- for (org.apache.poi.hssf.record.Record r : _records.subList(start, start+len+1)) {
- String dig = null;
- int row = -1;
- if (r instanceof RowRecord) {
- RowRecord rr = (RowRecord)r;
- row = rr.getRowNumber();
- dig = "rr";
- } else if (r instanceof MissingRowDummyRecord) {
- MissingRowDummyRecord mr = (MissingRowDummyRecord)r;
- row = mr.getRowNumber();
- dig = "mr";
- } else if (r instanceof MissingCellDummyRecord) {
- MissingCellDummyRecord mc = (MissingCellDummyRecord)r;
- row = mc.getRow();
- dig = "mc" + mc.getColumn();
- } else if (r instanceof LastCellOfRowDummyRecord) {
- LastCellOfRowDummyRecord lc = (LastCellOfRowDummyRecord)r;
- row = lc.getRow();
- dig = "lc" + (lc.getLastColumnNumber() > -1 ? lc.getLastColumnNumber() : "");
- } else if (r instanceof NumberRecord) {
- NumberRecord nr = (NumberRecord)r;
- row = nr.getRow();
- dig = "nr" + nr.getColumn() + "/" + (int)nr.getValue();
- } else if (r instanceof LabelSSTRecord) {
- LabelSSTRecord ls = (LabelSSTRecord) r;
- row = ls.getRow();
- dig = "ls" + ls.getColumn();
- } else if (r instanceof WindowTwoRecord) {
- dig = "wr";
- } else if (r instanceof DimensionsRecord) {
- dig = "dr";
- } else if (r instanceof CellValueRecordInterface) {
- CellValueRecordInterface cv = (CellValueRecordInterface) r;
- row = cv.getRow();
- dig = "cv" + cv.getColumn();
- } else {
- // unhandled record
- dig = "ur";
- }
- if (lastRow != row && row > -1) {
- sb.append((lastRow > -1 ? "," : "") + row + ":");
- lastRow = row;
- }
- sb.append(dig);
- }
- return sb.toString();
- }
-
- private long matches(Predicate<org.apache.poi.hssf.record.Record> r) {
- return _records.stream().filter(r).count();
- }
+ private void readRecords(String sampleFileName) throws IOException {
+ _records.clear();
+ HSSFRequest req = new HSSFRequest();
+ req.addListenerForAllRecords(new MissingRecordAwareHSSFListener(_records::add));
+
+ HSSFEventFactory factory = new HSSFEventFactory();
+ try (InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
+ POIFSFileSystem fs = new POIFSFileSystem(is)) {
+ factory.processWorkbookEvents(req, fs);
+ }
+
+ assertTrue(_records.size() > 100);
+ }
+
+ @Test
+ void testMissingRowRecords() throws IOException {
+ readRecords("MissingBits.xls");
+
+ // We have rows 0, 1, 2, 20 and 21
+ int row0 = lastIndexOf(r -> r instanceof RowRecord && ((RowRecord)r).getRowNumber() == 0);
+ assertTrue(row0 > -1);
+
+ // Records: row 0: column 1, 2), then missing rows, rows 20,21,22 each 1 column
+ String exp1 =
+ "0:rr,1:rr,2:rr,3:mr,4:mr,5:mr,6:mr,7:mr,8:mr,9:mr,10:mr,11:mr,12:mr,13:mr,14:mr," +
+ "15:mr,16:mr,17:mr,18:mr,19:mr,20:rr,21:rr,22:rr";
+ String act1 = digest(row0, 22);
+ assertEquals(exp1, act1);
+
+
+ // Find the cell at 0,0
+ int cell00 = lastIndexOf(r -> r instanceof LabelSSTRecord && ((LabelSSTRecord)r).getRow() == 0 && ((LabelSSTRecord)r).getColumn() == 0);
+
+ String exp2 =
+ "0:ls0lc0," +
+ "1:nr0/11mc1mc2nr3/23lc3," +
+ "2:nr0/45mc1mc2mc3mc4nr5/22lc5," +
+ "3:lc,4:lc,5:lc,6:lc,7:lc,8:lc,9:lc,10:lc,11:lc,12:lc,13:lc,14:lc,15:lc,16:lc,17:lc,18:lc,19:lc," +
+ "20:nr0/50nr1/51nr2/52nr3/53nr4/54lc4," +
+ "21:ls0ls1mc2nr3/12mc4nr5/23nr6/42lc6," +
+ "22:ls0mc1mc2ls3ls4mc5mc6mc7mc8mc9mc10ls11lc11";
+ String act2 = digest(cell00, 57);
+ assertEquals(exp2, act2);
+ }
+
+ // Make sure we don't put in any extra new lines that aren't already there
+ @Test
+ void testNoExtraNewLines() throws IOException {
+ // Load a different file
+ // This file has has something in lines 1-33
+ readRecords("MRExtraLines.xls");
+
+ int rowCount=0;
+ for (org.apache.poi.hssf.record.Record rec : _records) {
+ if (rec instanceof LastCellOfRowDummyRecord) {
+ LastCellOfRowDummyRecord eor = (LastCellOfRowDummyRecord) rec;
+ assertEquals(rowCount, eor.getRow());
+ rowCount++;
+ }
+ }
+ // Check we got the 33 rows
+ assertEquals(33, rowCount);
+ }
+
+ /**
+ * Make sure that the presence of shared formulas does not cause extra end-of-row records.
+ */
+ @Test
+ void testEndOfRow_bug45672() throws IOException {
+ readRecords("ex45672.xls");
+ assertEquals(1, matches(r -> r instanceof SharedFormulaRecord));
+ assertEquals(1, matches(r -> r instanceof LastCellOfRowDummyRecord));
+ }
+
+ /**
+ * MulBlank records hold multiple blank cells.
+ * Check that we don't have any MulBlankRecords, but do have lots of BlankRecords
+ */
+ @Test
+ void testMulBlankHandling() throws IOException {
+ readRecords("45672.xls");
+ assertEquals(20, matches(r -> r instanceof BlankRecord));
+ assertEquals(2, matches(r -> r instanceof LastCellOfRowDummyRecord));
+ assertEquals(0, matches(r -> r instanceof MulBlankRecord));
+ }
+
+ @Test
+ void testStringRecordHandling() throws IOException {
+ readRecords("53588.xls");
+ assertEquals(1, matches(r -> r instanceof MissingCellDummyRecord));
+ assertEquals(1, matches(r -> r instanceof LastCellOfRowDummyRecord));
+ }
+
+ @Test
+ void testFormulasWithStringResultsHandling() throws IOException {
+ readRecords("53433.xls");
+
+ String exp =
+ "dr0:mr,1:mr,2:mr,3:rr,4:rr,5:rr,6:rr,7:rr,8:rr,9:rr,10:mr,11:mr,12:mr,13:mr,14:mr,15:rr,16:rr,17:mr,18:rr," +
+ "0:lc,1:lc,2:lc,3:mc0ls1ls2ls3ls4lc4,4:mc0ls1cv2urnr3/12cv4urlc4," +
+ "5:mc0cv1urnr2/23nr3/23cv4urlc4,6:mc0mc1nr2/25nr3/45nr4/32815lc4," +
+ "7:mc0ls1cv2cv3urcv4lc4,8:mc0mc1mc2mc3cv4lc4,9:mc0mc1mc2ls3lc3," +
+ "10:lc,11:lc,12:lc,13:lc,14:lc,15:mc0ls1lc1,16:mc0mc1mc2ls3lc3," +
+ "17:lc,18:mc0mc1mc2mc3ls4lc4wr";
+ String act = digest(95, 89);
+ assertEquals(exp, act);
+ }
+
+ private int lastIndexOf(Predicate<org.apache.poi.hssf.record.Record> pre) {
+ int found = -1;
+ int i = 0;
+ for (org.apache.poi.hssf.record.Record r : _records) {
+ if (pre.test(r)) {
+ found = i;
+ }
+ i++;
+ }
+ return found;
+ }
+
+ private String digest(int start, int len) {
+ StringBuilder sb = new StringBuilder(len*10);
+ int lastRow = -1;
+ for (org.apache.poi.hssf.record.Record r : _records.subList(start, start+len+1)) {
+ String dig = null;
+ int row = -1;
+ if (r instanceof RowRecord) {
+ RowRecord rr = (RowRecord)r;
+ row = rr.getRowNumber();
+ dig = "rr";
+ } else if (r instanceof MissingRowDummyRecord) {
+ MissingRowDummyRecord mr = (MissingRowDummyRecord)r;
+ row = mr.getRowNumber();
+ dig = "mr";
+ } else if (r instanceof MissingCellDummyRecord) {
+ MissingCellDummyRecord mc = (MissingCellDummyRecord)r;
+ row = mc.getRow();
+ dig = "mc" + mc.getColumn();
+ } else if (r instanceof LastCellOfRowDummyRecord) {
+ LastCellOfRowDummyRecord lc = (LastCellOfRowDummyRecord)r;
+ row = lc.getRow();
+ dig = "lc" + (lc.getLastColumnNumber() > -1 ? lc.getLastColumnNumber() : "");
+ } else if (r instanceof NumberRecord) {
+ NumberRecord nr = (NumberRecord)r;
+ row = nr.getRow();
+ dig = "nr" + nr.getColumn() + "/" + (int)nr.getValue();
+ } else if (r instanceof LabelSSTRecord) {
+ LabelSSTRecord ls = (LabelSSTRecord) r;
+ row = ls.getRow();
+ dig = "ls" + ls.getColumn();
+ } else if (r instanceof WindowTwoRecord) {
+ dig = "wr";
+ } else if (r instanceof DimensionsRecord) {
+ dig = "dr";
+ } else if (r instanceof CellValueRecordInterface) {
+ CellValueRecordInterface cv = (CellValueRecordInterface) r;
+ row = cv.getRow();
+ dig = "cv" + cv.getColumn();
+ } else {
+ // unhandled record
+ dig = "ur";
+ }
+ if (lastRow != row && row > -1) {
+ sb.append((lastRow > -1 ? "," : "") + row + ":");
+ lastRow = row;
+ }
+ sb.append(dig);
+ }
+ return sb.toString();
+ }
+
+ private long matches(Predicate<org.apache.poi.hssf.record.Record> r) {
+ return _records.stream().filter(r).count();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org