poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1847069 [2/2] - in /poi/branches/hemf: ./ jenkins/ sonar/ sonar/examples/ sonar/excelant/ sonar/main/ sonar/ooxml-schema-encryption/ sonar/ooxml-schema-security/ sonar/ooxml-schema/ sonar/ooxml/ sonar/scratchpad/ src/examples/src/org/apach...
Date Tue, 20 Nov 2018 22:24:26 GMT
Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/sl/TestOleShape.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/sl/TestOleShape.java?rev=1847069&r1=1847068&r2=1847069&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/sl/TestOleShape.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/sl/TestOleShape.java Tue Nov 20 22:24:26 2018
@@ -35,13 +35,14 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.util.Arrays;
 import java.util.Collection;
 
 import org.apache.poi.POIDataSamples;
-import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.POIDocument;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hwpf.HWPFDocument;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.poifs.storage.RawDataUtil;
 import org.apache.poi.sl.usermodel.ObjectMetaData;
@@ -124,7 +125,7 @@ public class TestOleShape {
     }
     
     @Test
-    public void embedData() throws IOException, InvalidFormatException {
+    public void embedData() throws IOException, InvalidFormatException, ReflectiveOperationException {
         final ByteArrayInputStream pptBytes;
         try (SlideShow<?,?> ppt = createSlideShow()) {
             final PictureData picData = ppt.addPicture(pictureFile,  PictureType.EMF);
@@ -146,12 +147,12 @@ public class TestOleShape {
         }
     }
     
-    private SlideShow<?,?> createSlideShow() {
+    private SlideShow<?,?> createSlideShow() throws ReflectiveOperationException {
         if (api == Api.XSLF) {
             return new XMLSlideShow();
         } else {
             assumeFalse(xslfOnly());
-            return new HSLFSlideShow();
+            return (SlideShow<?,?>)Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow").newInstance();
         }
     }
 
@@ -186,7 +187,7 @@ public class TestOleShape {
         }
     }
     
-    private void validateOleData(final InputStream in) throws IOException, InvalidFormatException {
+    private void validateOleData(final InputStream in) throws IOException, InvalidFormatException, ReflectiveOperationException {
         switch (app) {
         case EXCEL_V8:
         case EXCEL_V12:
@@ -195,8 +196,11 @@ public class TestOleShape {
             }
             break;
         case WORD_V8:
-            try (HWPFDocument doc = new HWPFDocument(in)) {
-                assertEquals("This is a simple file created with Word 97-SR2.\r", doc.getDocumentText());
+            Class<? extends POIDocument> clazz = (Class<? extends POIDocument>)Class.forName("org.apache.poi.hwpf.HWPFDocument");
+            Constructor<? extends POIDocument> con = clazz.getDeclaredConstructor(InputStream.class);
+            Method m = clazz.getMethod("getDocumentText");
+            try (POIDocument doc = con.newInstance(in)) {
+                assertEquals("This is a simple file created with Word 97-SR2.\r", m.invoke(doc));
             }
             break;
         case WORD_V12:

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/sl/TestSlide.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/sl/TestSlide.java?rev=1847069&r1=1847068&r2=1847069&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/sl/TestSlide.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/sl/TestSlide.java Tue Nov 20 22:24:26 2018
@@ -29,7 +29,6 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.poi.hslf.usermodel.HSLFSlideShow;
 import org.apache.poi.sl.usermodel.SlideShow;
 import org.apache.poi.sl.usermodel.SlideShowFactory;
 import org.apache.poi.xslf.usermodel.XMLSlideShow;
@@ -38,9 +37,9 @@ import org.junit.Test;
 public class TestSlide {
 
     @Test
-    public void hideHSLF() throws IOException {
+    public void hideHSLF() throws IOException, ReflectiveOperationException {
         assumeFalse(xslfOnly());
-        SlideShow<?,?> ppt1 = new HSLFSlideShow();
+        SlideShow<?,?> ppt1 = (SlideShow<?,?>)Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow").newInstance();
         hideSlide(ppt1);
         ppt1.close();
     }

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/sl/TestTable.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/sl/TestTable.java?rev=1847069&r1=1847068&r2=1847069&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/sl/TestTable.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/sl/TestTable.java Tue Nov 20 22:24:26 2018
@@ -34,7 +34,6 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.poi.hslf.usermodel.HSLFSlideShow;
 import org.apache.poi.sl.usermodel.Slide;
 import org.apache.poi.sl.usermodel.SlideShow;
 import org.apache.poi.sl.usermodel.SlideShowFactory;
@@ -96,9 +95,9 @@ public class TestTable {
     }
 
     @Test
-    public void directionHSLF() throws IOException {
+    public void directionHSLF() throws IOException, ReflectiveOperationException {
         assumeFalse(xslfOnly());
-        SlideShow<?,?> ppt1 = new HSLFSlideShow();
+        SlideShow<?,?> ppt1 = (SlideShow<?,?>)Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow").newInstance();
         testTextDirection(ppt1);
         ppt1.close();
     }

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ss/format/TestCellFormatPart.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ss/format/TestCellFormatPart.java?rev=1847069&r1=1847068&r2=1847069&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ss/format/TestCellFormatPart.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ss/format/TestCellFormatPart.java Tue Nov 20 22:24:26 2018
@@ -17,12 +17,15 @@
 package org.apache.poi.ss.format;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 import java.util.Locale;
 import java.util.TimeZone;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.poi.hssf.util.HSSFColor;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.util.LocaleUtil;
 import org.apache.poi.xssf.XSSFITestDataProvider;
@@ -38,7 +41,7 @@ public class TestCellFormatPart extends
     @BeforeClass
     public static void setLocale() {
         userLocale = LocaleUtil.getUserLocale();
-        LocaleUtil.setUserLocale(Locale.ROOT);
+        LocaleUtil.setUserLocale(Locale.UK);
     }
     
     @AfterClass
@@ -153,6 +156,19 @@ public class TestCellFormatPart extends
         });
     }
 
+    @Test
+    public void testNamedColors() {
+        assertTrue(CellFormatPart.NAMED_COLORS.size() >= HSSFColor.HSSFColorPredefined.values().length);
+        assertNotNull(CellFormatPart.NAMED_COLORS.get("GREEN"));
+        assertNotNull(CellFormatPart.NAMED_COLORS.get("Green"));
+        assertNotNull(CellFormatPart.NAMED_COLORS.get("RED"));
+        assertNotNull(CellFormatPart.NAMED_COLORS.get("Red"));
+        assertNotNull(CellFormatPart.NAMED_COLORS.get("BLUE"));
+        assertNotNull(CellFormatPart.NAMED_COLORS.get("Blue"));
+        assertNotNull(CellFormatPart.NAMED_COLORS.get("YELLOW"));
+        assertNotNull(CellFormatPart.NAMED_COLORS.get("Yellow"));
+    }
+
     private double extractNumber(String str) {
         Matcher m = NUMBER_EXTRACT_FMT.matcher(str);
         if (!m.find())

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ss/usermodel/TestEmbedOLEPackage.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ss/usermodel/TestEmbedOLEPackage.java?rev=1847069&r1=1847068&r2=1847069&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ss/usermodel/TestEmbedOLEPackage.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ss/usermodel/TestEmbedOLEPackage.java Tue Nov 20 22:24:26 2018
@@ -17,10 +17,11 @@
 
 package org.apache.poi.ss.usermodel;
 
+import static org.apache.poi.sl.SLCommonUtils.xslfOnly;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
+import static org.junit.Assume.assumeFalse;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -48,7 +49,7 @@ public class TestEmbedOLEPackage {
     private static byte[] samplePPT, samplePPTX, samplePNG;
     
     @BeforeClass
-    public static void init() throws IOException {
+    public static void init() throws IOException, ReflectiveOperationException {
         samplePPT = getSamplePPT(false);
         samplePPTX = getSamplePPT(true);
         samplePNG = POIDataSamples.getSpreadSheetInstance().readFile("logoKarmokar4.png");
@@ -68,11 +69,7 @@ public class TestEmbedOLEPackage {
 
     @Test
     public void embedHSSF() throws IOException {
-        try {
-            Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow");
-        } catch (Exception e) {
-            assumeTrue(false);
-        }
+        assumeFalse(xslfOnly());
 
         Workbook wb1 = new HSSFWorkbook();
         addEmbeddedObjects(wb1);
@@ -124,8 +121,9 @@ public class TestEmbedOLEPackage {
         pat2.createObjectData(anchor2, oleIdx2, picIdx);
     }
     
-    static byte[] getSamplePPT(boolean ooxml) throws IOException {
-        SlideShow<?,?> ppt = (ooxml) ? new XMLSlideShow() : new org.apache.poi.hslf.usermodel.HSLFSlideShow();
+    static byte[] getSamplePPT(boolean ooxml) throws IOException, ReflectiveOperationException {
+        SlideShow<?,?> ppt = (ooxml) ? new XMLSlideShow()
+            : (SlideShow<?,?>)Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow").newInstance();
         Slide<?,?> slide = ppt.createSlide();
 
         AutoShape<?,?> sh1 = slide.createAutoShape();

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java?rev=1847069&r1=1847068&r2=1847069&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java Tue Nov 20 22:24:26 2018
@@ -17,12 +17,7 @@
 package org.apache.poi.xslf;
 
 import static org.apache.poi.POITestCase.assertContains;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
 
 import java.awt.Color;
 import java.awt.Dimension;
@@ -94,6 +89,25 @@ public class TestXSLFBugs {
     private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
 
     @Test
+    public void bug62929() throws Exception {
+        try(XMLSlideShow ss1 = XSLFTestDataSamples.openSampleDocument("missing-blip-fill.pptx")) {
+            assertEquals(1, ss1.getSlides().size());
+
+            XSLFSlide slide = ss1.getSlides().get(0);
+
+            assertEquals(slide.getShapes().size(), 1);
+
+            XSLFPictureShape picture = (XSLFPictureShape)slide.getShapes().get(0);
+
+            assertEquals(picture.getShapeId(), 662);
+            assertFalse(picture.isExternalLinkedPicture());
+            assertNull(picture.getPictureData());
+            assertNull(picture.getPictureLink());
+            assertNull(picture.getClipping());
+        }
+    }
+
+    @Test
     public void bug62736() throws Exception {
         XMLSlideShow ss1 = XSLFTestDataSamples.openSampleDocument("bug62736.pptx");
 

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextShape.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextShape.java?rev=1847069&r1=1847068&r2=1847069&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextShape.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextShape.java Tue Nov 20 22:24:26 2018
@@ -17,6 +17,7 @@
 package org.apache.poi.xslf.usermodel;
 
 import static org.apache.poi.sl.TestCommonSL.sameColor;
+import static org.apache.poi.xslf.usermodel.TestXSLFSimpleShape.getSpPr;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -24,7 +25,6 @@ import static org.junit.Assert.assertNul
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assume.assumeFalse;
-import static org.apache.poi.xslf.usermodel.TestXSLFSimpleShape.getSpPr;
 
 import java.awt.Color;
 import java.io.File;
@@ -33,8 +33,8 @@ import java.util.List;
 import java.util.stream.Collectors;
 
 import org.apache.poi.POIDataSamples;
-import org.apache.poi.hslf.usermodel.HSLFTextShape;
 import org.apache.poi.sl.usermodel.Placeholder;
+import org.apache.poi.sl.usermodel.Shape;
 import org.apache.poi.sl.usermodel.SlideShow;
 import org.apache.poi.sl.usermodel.SlideShowFactory;
 import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
@@ -950,12 +950,12 @@ public class TestXSLFTextShape {
     }
     
     @Test
-    public void metroBlob() throws IOException {
+    public void metroBlob() throws IOException, ReflectiveOperationException {
         assumeFalse(xslfOnly);
         File f = POIDataSamples.getSlideShowInstance().getFile("bug52297.ppt");
         SlideShow<?,?> ppt = SlideShowFactory.create(f);
-        HSLFTextShape sh = (HSLFTextShape)ppt.getSlides().get(1).getShapes().get(3);
-        XSLFAutoShape xsh = (XSLFAutoShape)sh.getMetroShape();
+        Shape<?, ?> sh = ppt.getSlides().get(1).getShapes().get(3);
+        XSLFAutoShape xsh = (XSLFAutoShape)sh.getClass().getMethod("getMetroShape").invoke(sh);
         String textExp = " ___ ___ ___ ________ __  _______ ___  ___________  __________ __ _____ ___ ___ ___ _______ ____ ______ ___________  _____________ ___ _______ ______  ____ ______ __ ___________  __________ ___ _________  _____ ________ __________  ___ _______ __________ ";
         String textAct = xsh.getText();
         ppt.close();

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java?rev=1847069&r1=1847068&r2=1847069&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java Tue Nov 20 22:24:26 2018
@@ -21,7 +21,10 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
+import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.util.Date;
 
 import org.apache.poi.ss.ITestDataProvider;
 import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
@@ -34,6 +37,9 @@ import org.apache.poi.ss.usermodel.Workb
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.xssf.SXSSFITestDataProvider;
 import org.apache.poi.xssf.XSSFITestDataProvider;
+import org.apache.poi.xssf.streaming.SXSSFCell;
+import org.apache.poi.xssf.streaming.SXSSFRow;
+import org.apache.poi.xssf.streaming.SXSSFSheet;
 import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -166,4 +172,45 @@ public final class TestSXSSFBugs extends
         CellRangeAddress range = new CellRangeAddress(rowIndex, rowIndex, colIndex, colIndex);
         sheet.setArrayFormula(col1Value, range);
     }
+
+    @Test
+    @Ignore("takes too long for the normal test run")
+    public void test62872() throws Exception {
+        final int COLUMN_COUNT = 300;
+        final int ROW_COUNT = 600000;
+        final int TEN_MINUTES = 1000*60*10;
+
+        SXSSFWorkbook workbook = new SXSSFWorkbook(100);
+        workbook.setCompressTempFiles(true);
+        SXSSFSheet sheet = workbook.createSheet("RawData");
+
+        SXSSFRow row = sheet.createRow(0);
+        SXSSFCell cell;
+
+        for (int i = 1; i <= COLUMN_COUNT; i++) {
+            cell = row.createCell(i - 1);
+            cell.setCellValue("Column " + i);
+        }
+
+        for (int i = 1; i < ROW_COUNT; i++) {
+            row = sheet.createRow(i);
+            for (int j = 1; j <= COLUMN_COUNT; j++) {
+                cell = row.createCell(j - 1);
+
+                //make some noise
+                cell.setCellValue(new Date(i*TEN_MINUTES+(j*TEN_MINUTES)/COLUMN_COUNT));
+            }
+            i++;
+            // if (i % 1000 == 0)
+            // logger.info("Created Row " + i);
+        }
+
+        try (FileOutputStream out = new FileOutputStream(File.createTempFile("test62872", ".xlsx"))) {
+            workbook.write(out);
+            workbook.dispose();
+            workbook.close();
+            out.flush();
+        }
+        // logger.info("File written!");
+    }
 }

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java?rev=1847069&r1=1847068&r2=1847069&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java Tue Nov 20 22:24:26 2018
@@ -55,10 +55,7 @@ import org.apache.poi.ss.usermodel.Index
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.util.CellAddress;
-import org.apache.poi.ss.util.CellRangeAddress;
-import org.apache.poi.ss.util.CellReference;
-import org.apache.poi.ss.util.CellUtil;
+import org.apache.poi.ss.util.*;
 import org.apache.poi.util.LocaleUtil;
 import org.apache.poi.xssf.XSSFITestDataProvider;
 import org.apache.poi.xssf.XSSFTestDataSamples;
@@ -1993,12 +1990,11 @@ public final class TestXSSFSheet extends
 
     @Test
     public void testGetHeaderFooterProperties() throws IOException {
-         XSSFWorkbook wb = new XSSFWorkbook();
-         XSSFSheet sh = wb.createSheet();
-
-         XSSFHeaderFooterProperties hfProp = sh.getHeaderFooterProperties();
-         assertNotNull(hfProp);
+        try (XSSFWorkbook wb = new XSSFWorkbook()) {
+            XSSFSheet sh = wb.createSheet();
 
-         wb.close();
+            XSSFHeaderFooterProperties hfProp = sh.getHeaderFooterProperties();
+            assertNotNull(hfProp);
+        }
     }
 }

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java?rev=1847069&r1=1847068&r2=1847069&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java Tue Nov 20 22:24:26 2018
@@ -348,15 +348,47 @@ public final class TestXSSFTable {
         
         IOUtils.closeQuietly(wb);
     }
-    
+
+    @Test
+    public void testCreateTableIds() throws IOException {
+        try (XSSFWorkbook wb = new XSSFWorkbook()) {
+            XSSFSheet sheet = wb.createSheet();
+
+            AreaReference reference1 = wb.getCreationHelper().createAreaReference(
+                    new CellReference(0, 0), new CellReference(2, 2));
+
+            XSSFTable table1 = sheet.createTable(reference1);
+            assertEquals("A1:C3", table1.getCTTable().getRef());
+
+            assertEquals(1, table1.getCTTable().getTableColumns().getTableColumnArray(0).getId());
+            assertEquals(2, table1.getCTTable().getTableColumns().getTableColumnArray(1).getId());
+            assertEquals(3, table1.getCTTable().getTableColumns().getTableColumnArray(2).getId());
+
+            assertEquals(1, table1.getCTTable().getId());
+
+            AreaReference reference2 = wb.getCreationHelper().createAreaReference(
+                    new CellReference(10, 10), new CellReference(12, 12));
+
+            XSSFTable table2 = sheet.createTable(reference2);
+            assertEquals("K11:M13", table2.getCTTable().getRef());
+
+            // these IDs duplicate those from table1 and may be cause of https://bz.apache.org/bugzilla/show_bug.cgi?id=62906
+            assertEquals(1, table2.getCTTable().getTableColumns().getTableColumnArray(0).getId());
+            assertEquals(2, table2.getCTTable().getTableColumns().getTableColumnArray(1).getId());
+            assertEquals(3, table2.getCTTable().getTableColumns().getTableColumnArray(2).getId());
+
+            assertEquals(2, table2.getCTTable().getId());
+        }
+    }
+
     @Test
     public void testSetArea() throws IOException {
-        XSSFWorkbook wb = new XSSFWorkbook();
+        try (XSSFWorkbook wb = new XSSFWorkbook()) {
             XSSFSheet sh = wb.createSheet();
-            
+
             AreaReference tableArea = new AreaReference("B10:D12", wb.getSpreadsheetVersion());
             XSSFTable table = sh.createTable(tableArea);
-            
+
             assertEquals(3, table.getColumnCount());
             assertEquals(3, table.getRowCount());
 
@@ -366,11 +398,11 @@ public final class TestXSSFTable {
 
             assertEquals(3, table.getColumnCount());
             assertEquals(3, table.getRowCount());
- 
+
             // increase size by 1 row and 1 column
             AreaReference tableArea3 = new AreaReference("B11:E14", wb.getSpreadsheetVersion());
             table.setArea(tableArea3);
-            
+
             assertEquals(4, table.getColumnCount());
             assertEquals(4, table.getRowCount());
 
@@ -380,43 +412,41 @@ public final class TestXSSFTable {
 
             assertEquals(2, table.getColumnCount());
             assertEquals(2, table.getRowCount());
-            
-            IOUtils.closeQuietly(wb);
+        }
     }
     
     @Test
-    public void testCreateColumn() {
-        XSSFWorkbook wb = new XSSFWorkbook();
-        XSSFSheet sh = wb.createSheet();
-        
-        AreaReference tableArea = new AreaReference("A2:A3", wb.getSpreadsheetVersion());
-        XSSFTable table = sh.createTable(tableArea);
+    public void testCreateColumn() throws IOException {
+        try (XSSFWorkbook wb = new XSSFWorkbook()) {
+            XSSFSheet sh = wb.createSheet();
 
-        assertEquals(1, table.getColumnCount());
-        assertEquals(2, table.getRowCount());
+            AreaReference tableArea = new AreaReference("A2:A3", wb.getSpreadsheetVersion());
+            XSSFTable table = sh.createTable(tableArea);
 
-        // add columns
-        XSSFTableColumn c1 = table.getColumns().get(0);
-        XSSFTableColumn cB = table.createColumn("Column B");
-        XSSFTableColumn cD = table.createColumn("Column D");
-        XSSFTableColumn cC = table.createColumn("Column C", 2); // add between B and D
-        table.updateReferences();
-        table.updateHeaders();
-
-        assertEquals(4, table.getColumnCount());
-        assertEquals(2, table.getRowCount());
-
-        // column IDs start at 1, and increase in the order columns are added (see bug #62740)
-        assertEquals("Column c ID", 1, c1.getId());
-        assertTrue("Column B ID", c1.getId() < cB.getId());
-        assertTrue("Column D ID", cB.getId() < cD.getId());
-        assertTrue("Column C ID", cD.getId() < cC.getId());
-        assertEquals("Column 1", table.getColumns().get(0).getName()); // generated name
-        assertEquals("Column B", table.getColumns().get(1).getName());
-        assertEquals("Column C", table.getColumns().get(2).getName());
-        assertEquals("Column D", table.getColumns().get(3).getName());
+            assertEquals(1, table.getColumnCount());
+            assertEquals(2, table.getRowCount());
 
-        IOUtils.closeQuietly(wb);
+            // add columns
+            XSSFTableColumn c1 = table.getColumns().get(0);
+            XSSFTableColumn cB = table.createColumn("Column B");
+            XSSFTableColumn cD = table.createColumn("Column D");
+            XSSFTableColumn cC = table.createColumn("Column C", 2); // add between B and D
+            table.updateReferences();
+            table.updateHeaders();
+
+            assertEquals(4, table.getColumnCount());
+            assertEquals(2, table.getRowCount());
+
+            // column IDs start at 1, and increase in the order columns are added (see bug #62740)
+            assertEquals("Column c ID", 1, c1.getId());
+            assertTrue("Column B ID", c1.getId() < cB.getId());
+            assertTrue("Column D ID", cB.getId() < cD.getId());
+            assertTrue("Column C ID", cD.getId() < cC.getId());
+            assertEquals("Column 1", table.getColumns().get(0).getName()); // generated name
+            assertEquals("Column B", table.getColumns().get(1).getName());
+            assertEquals("Column C", table.getColumns().get(2).getName());
+            assertEquals("Column D", table.getColumns().get(3).getName());
+        }
     }
 
     @Test(expected = IllegalArgumentException.class)

Modified: poi/branches/hemf/src/scratchpad/src/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/scratchpad/src/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java?rev=1847069&r1=1847068&r2=1847069&view=diff
==============================================================================
--- poi/branches/hemf/src/scratchpad/src/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java (original)
+++ poi/branches/hemf/src/scratchpad/src/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java Tue Nov 20 22:24:26 2018
@@ -32,6 +32,7 @@ import org.apache.poi.hslf.usermodel.HSL
 import org.apache.poi.hsmf.MAPIMessage;
 import org.apache.poi.hsmf.datatypes.AttachmentChunks;
 import org.apache.poi.hsmf.extractor.OutlookTextExtactor;
+import org.apache.poi.hssf.extractor.ExcelExtractor;
 import org.apache.poi.hwpf.OldWordFileFormatException;
 import org.apache.poi.hwpf.extractor.Word6Extractor;
 import org.apache.poi.hwpf.extractor.WordExtractor;
@@ -40,6 +41,8 @@ import org.apache.poi.poifs.filesystem.D
 import org.apache.poi.poifs.filesystem.Entry;
 import org.apache.poi.sl.extractor.SlideShowExtractor;
 import org.apache.poi.sl.usermodel.SlideShowFactory;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
 
 /**
  * Scratchpad-specific logic for {@link OLE2ExtractorFactory} and
@@ -50,6 +53,8 @@ import org.apache.poi.sl.usermodel.Slide
  */
 @SuppressWarnings("WeakerAccess")
 public class OLE2ScratchpadExtractorFactory {
+    private static final POILogger logger = POILogFactory.getLogger(OLE2ScratchpadExtractorFactory.class);
+
     /**
      * Look for certain entries in the stream, to figure it
      * out what format is desired
@@ -125,7 +130,16 @@ public class OLE2ScratchpadExtractorFact
             throw new IllegalStateException("The extractor didn't know which POIFS it came from!");
         }
 
-        if (ext instanceof WordExtractor) {
+        if (ext instanceof ExcelExtractor) {
+            // These are in MBD... under the root
+            Iterator<Entry> it = root.getEntries();
+            while (it.hasNext()) {
+                Entry entry = it.next();
+                if (entry.getName().startsWith("MBD")) {
+                    dirs.add(entry);
+                }
+            }
+        } else if (ext instanceof WordExtractor) {
             // These are in ObjectPool -> _... under the root
             try {
                 DirectoryEntry op = (DirectoryEntry)
@@ -138,6 +152,7 @@ public class OLE2ScratchpadExtractorFact
                     }
                 }
             } catch(FileNotFoundException e) {
+                logger.log(POILogger.INFO, "Ignoring FileNotFoundException while extracting Word document", e.getLocalizedMessage());
                 // ignored here
             }
             //} else if(ext instanceof PowerPointExtractor) {

Modified: poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/record/Notes.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/record/Notes.java?rev=1847069&r1=1847068&r2=1847069&view=diff
==============================================================================
--- poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/record/Notes.java (original)
+++ poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/record/Notes.java Tue Nov 20 22:24:26 2018
@@ -63,7 +63,6 @@ public final class Notes extends SheetCo
 		for(int i=0; i<_children.length; i++) {
 			if(_children[i] instanceof NotesAtom) {
 				notesAtom = (NotesAtom)_children[i];
-				//System.out.println("Found notes for sheet " + notesAtom.getSlideID());
 			}
 			if(_children[i] instanceof PPDrawing) {
 				ppDrawing = (PPDrawing)_children[i];

Modified: poi/branches/hemf/src/scratchpad/testcases/org/apache/poi/hmef/TestAttachments.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/scratchpad/testcases/org/apache/poi/hmef/TestAttachments.java?rev=1847069&r1=1847068&r2=1847069&view=diff
==============================================================================
--- poi/branches/hemf/src/scratchpad/testcases/org/apache/poi/hmef/TestAttachments.java (original)
+++ poi/branches/hemf/src/scratchpad/testcases/org/apache/poi/hmef/TestAttachments.java Tue Nov 20 22:24:26 2018
@@ -18,6 +18,7 @@
 package org.apache.poi.hmef;
 
 import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import java.util.List;
 import java.util.Locale;
 
@@ -83,9 +84,7 @@ public final class TestAttachments exten
       List<Attachment> attachments = quick.getAttachments();
       
       // Pick a predictable date format + timezone
-      DateFormat fmt = DateFormat.getDateTimeInstance(
-            DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK
-      );
+      DateFormat fmt = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss", Locale.UK);
       fmt.setTimeZone(LocaleUtil.TIMEZONE_UTC);
       
       // They should all have the same date on them

Modified: poi/branches/hemf/src/scratchpad/testcases/org/apache/poi/hmef/attribute/TestMAPIAttributes.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/scratchpad/testcases/org/apache/poi/hmef/attribute/TestMAPIAttributes.java?rev=1847069&r1=1847068&r2=1847069&view=diff
==============================================================================
--- poi/branches/hemf/src/scratchpad/testcases/org/apache/poi/hmef/attribute/TestMAPIAttributes.java (original)
+++ poi/branches/hemf/src/scratchpad/testcases/org/apache/poi/hmef/attribute/TestMAPIAttributes.java Tue Nov 20 22:24:26 2018
@@ -20,6 +20,7 @@ package org.apache.poi.hmef.attribute;
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import java.util.Locale;
 
 import org.apache.poi.POIDataSamples;
@@ -159,9 +160,7 @@ protected void tearDown() throws Excepti
       assertEquals(MAPIDateAttribute.class, attr.getClass());
       
       MAPIDateAttribute date = (MAPIDateAttribute)attr;
-      DateFormat fmt = DateFormat.getDateTimeInstance(
-            DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK
-      );
+      DateFormat fmt = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss", Locale.UK);
       fmt.setTimeZone(LocaleUtil.TIMEZONE_UTC);
       assertEquals("15-Dec-2010 14:46:31", fmt.format(date.getDate()));
       

Modified: poi/branches/hemf/src/scratchpad/testcases/org/apache/poi/hmef/attribute/TestTNEFAttributes.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/scratchpad/testcases/org/apache/poi/hmef/attribute/TestTNEFAttributes.java?rev=1847069&r1=1847068&r2=1847069&view=diff
==============================================================================
--- poi/branches/hemf/src/scratchpad/testcases/org/apache/poi/hmef/attribute/TestTNEFAttributes.java (original)
+++ poi/branches/hemf/src/scratchpad/testcases/org/apache/poi/hmef/attribute/TestTNEFAttributes.java Tue Nov 20 22:24:26 2018
@@ -19,6 +19,7 @@ package org.apache.poi.hmef.attribute;
 
 import java.io.ByteArrayInputStream;
 import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import java.util.Locale;
 
 import org.apache.poi.POIDataSamples;
@@ -159,9 +160,7 @@ public final class TestTNEFAttributes ex
       // Ask for it as a Java date, and have it converted
       // Pick a predictable format + location + timezone
       TNEFDateAttribute date = (TNEFDateAttribute)attr;
-      DateFormat fmt = DateFormat.getDateTimeInstance(
-            DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK
-      );
+      DateFormat fmt = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss", Locale.UK);
       fmt.setTimeZone(LocaleUtil.TIMEZONE_UTC);
       assertEquals("28-Apr-2010 12:40:56", fmt.format(date.getDate()));
 	}

Modified: poi/branches/hemf/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java?rev=1847069&r1=1847068&r2=1847069&view=diff
==============================================================================
--- poi/branches/hemf/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java (original)
+++ poi/branches/hemf/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java Tue Nov 20 22:24:26 2018
@@ -30,6 +30,12 @@ import org.apache.poi.POIDataSamples;
 import org.apache.poi.hslf.HSLFTestDataSamples;
 import org.apache.poi.hslf.usermodel.HSLFSlide;
 import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
+import org.apache.poi.sl.usermodel.Shape;
+import org.apache.poi.sl.usermodel.Slide;
+import org.apache.poi.sl.usermodel.SlideShow;
+import org.apache.poi.sl.usermodel.TextParagraph;
+import org.apache.poi.sl.usermodel.TextShape;
 import org.junit.Test;
 
 /**
@@ -228,4 +234,45 @@ public final class TestHeadersFooters
         ppt2.close();
         ppt1.close();
     }
+    @Test
+    public void bug58144a() throws IOException {
+        try (InputStream is = _slTests.openResourceAsStream("bug58144-headers-footers-2003.ppt");
+             SlideShow<?,?> ppt = new HSLFSlideShow(is)) {
+            HSLFSlide sl = (HSLFSlide) ppt.getSlides().get(0);
+            HeadersFooters hfs = sl.getHeadersFooters();
+            assertNull(hfs.getHeaderText());
+            assertEquals("Confidential", hfs.getFooterText());
+            List<List<HSLFTextParagraph>> llp = sl.getTextParagraphs();
+            assertEquals("Test", HSLFTextParagraph.getText(llp.get(0)));
+            assertFalse(llp.get(0).get(0).isHeaderOrFooter());
+        }
+    }
+
+    @Test
+    public void bug58144b() throws IOException {
+        try (InputStream is = _slTests.openResourceAsStream("bug58144-headers-footers-2007.ppt");
+             SlideShow<?,?> ppt = new HSLFSlideShow(is)) {
+            Slide<?, ?> sl = ppt.getSlides().get(0);
+            HeadersFooters hfs2 = ((HSLFSlide) sl).getHeadersFooters();
+            assertNull(hfs2.getHeaderText());
+            assertEquals("Slide footer", hfs2.getFooterText());
+
+            testSlideShow(ppt);
+        }
+    }
+
+    // copied from org.apache.poi.sl.TestHeadersFooters because of scratchpad.ignore option
+    private void testSlideShow(SlideShow<?,?> ppt) {
+        Slide<?,?> sl =  ppt.getSlides().get(0);
+
+        List<? extends Shape<?,?>> shapes = sl.getShapes();
+        TextShape<?,?> ts0 = (TextShape<?,?>)shapes.get(0);
+        assertEquals("Test file", ts0.getText());
+        TextShape<?,?> ts1 = (TextShape<?,?>)shapes.get(1);
+        assertEquals("Has some text in the headers and footers", ts1.getText());
+        TextShape<?,?> ts2 = (TextShape<?,?>)shapes.get(2);
+        assertEquals("Slide footer", ts2.getText());
+        List<? extends TextParagraph<?,?,?>> ltp = ts2.getTextParagraphs();
+        assertTrue(ltp.get(0).isHeaderOrFooter());
+    }
 }

Modified: poi/branches/hemf/src/testcases/org/apache/poi/POIDataSamples.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/testcases/org/apache/poi/POIDataSamples.java?rev=1847069&r1=1847068&r2=1847069&view=diff
==============================================================================
--- poi/branches/hemf/src/testcases/org/apache/poi/POIDataSamples.java (original)
+++ poi/branches/hemf/src/testcases/org/apache/poi/POIDataSamples.java Tue Nov 20 22:24:26 2018
@@ -206,7 +206,7 @@ public final class POIDataSamples {
         }
         File dataDir = new File(dataDirName, _moduleDir);
         if (!dataDir.exists()) {
-            throw new RuntimeException("Data dir '" + _moduleDir + "' does not exist");
+            throw new RuntimeException("Data dir '" + dataDir + "' does not exist");
         }
         // convert to canonical file, to make any subsequent error messages
         // clearer.

Modified: poi/branches/hemf/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java?rev=1847069&r1=1847068&r2=1847069&view=diff
==============================================================================
--- poi/branches/hemf/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java (original)
+++ poi/branches/hemf/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java Tue Nov 20 22:24:26 2018
@@ -19,6 +19,7 @@ package org.apache.poi.hssf.usermodel;
 
 import java.awt.image.BufferedImage;
 import java.io.ByteArrayInputStream;
+import java.io.File;
 import java.io.IOException;
 import java.util.List;
 
@@ -27,6 +28,7 @@ import javax.imageio.ImageIO;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.junit.BeforeClass;
 
 /**
  * Test <code>HSSFPictureData</code>.
@@ -36,7 +38,19 @@ import org.apache.poi.hssf.HSSFTestDataS
  * @author Trejkaz (trejkaz at trypticon dot org)
  */
 public final class TestHSSFPictureData extends TestCase{
-
+    @BeforeClass
+    public static void setUpClass() {
+        final String tmpDirProperty = System.getProperty("java.io.tmpdir");
+        if(tmpDirProperty == null || "".equals(tmpDirProperty)) {
+            return;
+        }
+        // ensure that temp-dir exists because ImageIO requires it
+        final File tmpDir = new File(tmpDirProperty);
+        if(!tmpDir.exists() && !tmpDir.mkdirs()) {
+            throw new IllegalStateException("Could not create temporary directory " + tmpDirProperty + ", full path " + tmpDir.getAbsolutePath());
+        }
+        ImageIO.setCacheDirectory(tmpDir);
+    }
 
 	public void testPictures() throws IOException {
         HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithImages.xls");
@@ -64,8 +78,8 @@ public final class TestHSSFPictureData e
                 assertEquals(300, png.getHeight());
                 assertEquals(HSSFWorkbook.PICTURE_TYPE_PNG, pict.getFormat());
                 assertEquals("image/png", pict.getMimeType());
-            } else {
-                //TODO: test code for PICT, WMF and EMF
+            /*} else {
+                //TODO: test code for PICT, WMF and EMF*/
             }
         }
     }
@@ -93,7 +107,7 @@ public final class TestHSSFPictureData e
         assertEquals("image/png", pict.getMimeType());
     }
 
-    public void testNotNullPictures() throws IOException {
+    public void testNotNullPictures() {
 
         HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SheetWithDrawing.xls");
 
@@ -103,5 +117,4 @@ public final class TestHSSFPictureData e
             assertNotNull(pict);
         }
     }
-
 }

Modified: poi/branches/hemf/src/testcases/org/apache/poi/ss/usermodel/TestExcelStyleDateFormatter.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/testcases/org/apache/poi/ss/usermodel/TestExcelStyleDateFormatter.java?rev=1847069&r1=1847068&r2=1847069&view=diff
==============================================================================
--- poi/branches/hemf/src/testcases/org/apache/poi/ss/usermodel/TestExcelStyleDateFormatter.java (original)
+++ poi/branches/hemf/src/testcases/org/apache/poi/ss/usermodel/TestExcelStyleDateFormatter.java Tue Nov 20 22:24:26 2018
@@ -18,124 +18,122 @@
 package org.apache.poi.ss.usermodel;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 import java.text.DateFormatSymbols;
 import java.text.FieldPosition;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Arrays;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import org.apache.poi.util.LocaleUtil;
 import org.junit.Test;
 
 public class TestExcelStyleDateFormatter {
     private static final String EXCEL_DATE_FORMAT = "MMMMM";
+    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT);
+    private final int jreVersion;
+
+    public TestExcelStyleDateFormatter() {
+        jreVersion = Integer.parseInt(System.getProperty("java.version")
+            .replace("1.8", "8").replaceAll("(\\d+).*", "$1"));
+    }
 
     /**
      * [Bug 60369] Month format 'MMMMM' issue with TEXT-formula and Java 8
      */
     @Test
-    public void test60369() throws ParseException {
-        Map<Locale, List<String>> testMap = initializeLocales();
+    public void test60369() {
+        Map<Locale, String> testMap = initializeLocales();
 
         // We have to set up dates as well.
-        SimpleDateFormat testDateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.ROOT);
-        List<Date> testDates = Arrays.asList(
-                testDateFormat.parse("12.01.1980"),
-                testDateFormat.parse("11.02.1995"),
-                testDateFormat.parse("10.03.2045"),
-                testDateFormat.parse("09.04.2016"),
-                testDateFormat.parse("08.05.2017"),
-                testDateFormat.parse("07.06.1945"),
-                testDateFormat.parse("06.07.1998"),
-                testDateFormat.parse("05.08.2099"),
-                testDateFormat.parse("04.09.1988"),
-                testDateFormat.parse("03.10.2023"),
-                testDateFormat.parse("02.11.1978"),
-                testDateFormat.parse("01.12.1890"));
+        List<Date> testDates = Stream.of("1980-01-12", "1995-02-11", "2045-03-10", "2016-04-09", "2017-05-08",
+            "1945-06-07", "1998-07-06", "2099-08-05", "1988-09-04", "2023-10-03", "1978-11-02", "1890-12-01")
+            .map(this::parseDate).collect(Collectors.toList());
 
         // Let's iterate over the test setup.
-        for (Locale locale : testMap.keySet()) {
-            ExcelStyleDateFormatter formatter = new ExcelStyleDateFormatter(EXCEL_DATE_FORMAT, new DateFormatSymbols(locale));
-            for (int i = 0; i < testDates.size(); i++) {
-                // Call the method to be tested!
-                String result =
-                        formatter.format(testDates.get(i),
-                                new StringBuffer(),
-                                new FieldPosition(java.text.DateFormat.MONTH_FIELD)).toString();
-                //System.err.println(result +  " - " + getUnicode(result.charAt(0)));
-                assertEquals("Failed for locale " + locale + ", provider: " + System.getProperty("java.locale.providers") +
-                        " and date " + testDates.get(i) + ", having: " + result,
-                        getUnicode(testMap.get(locale).get(i).charAt(0)), getUnicode(result.charAt(0)));
+        final String provider = System.getProperty("java.locale.providers");
+        final FieldPosition fp = new FieldPosition(java.text.DateFormat.MONTH_FIELD);
+        final ExcelStyleDateFormatter formatter = new ExcelStyleDateFormatter(EXCEL_DATE_FORMAT);
+        final StringBuffer sb = new StringBuffer();
+
+        for (Map.Entry<Locale,String> me : testMap.entrySet()) {
+            final Locale locale = me.getKey();
+            final String expected = me.getValue();
+            formatter.setDateFormatSymbols(DateFormatSymbols.getInstance(locale));
+            int month = 0;
+            for (Date d : testDates) {
+                sb.setLength(0);
+                String result = formatter.format(d, sb, fp).toString();
+                String msg = "Failed testDates for locale " + locale + ", provider: " + provider +
+                        " and date " + d + ", having: " + result;
+
+                int actIdx = localeIndex(locale);
+
+                assertNotNull(msg, result);
+                assertTrue(msg, result.length() > actIdx);
+                assertEquals(msg, expected.charAt(month), result.charAt(actIdx));
+                month++;
             }
         }
     }
 
-    private Map<Locale, List<String>> initializeLocales() {
-        // Setting up the locale to be tested together with a list of asserted unicode-formatted results and put them in a map.
-        Locale germanLocale = Locale.GERMAN;
-        List<String> germanResultList = Arrays.asList("\u004a", "\u0046", "\u004d", "\u0041", "\u004d",
-                "\u004a", "\u004a", "\u0041", "\u0053", "\u004f", "\u004e", "\u0044");
-
-        Locale russianLocale = new Locale("ru", "RU");
-        List<String> russianResultList = Arrays.asList("\u044f", "\u0444", "\u043c", "\u0430", "\u043c",
-                "\u0438", "\u0438", "\u0430", "\u0441", "\u043e", "\u043d", "\u0434");
-
-        Locale austrianLocale = new Locale("de", "AT");
-        List<String> austrianResultList = Arrays.asList("\u004a", "\u0046", "\u004d", "\u0041", "\u004d",
-                "\u004a", "\u004a", "\u0041", "\u0053", "\u004f", "\u004e", "\u0044");
-
-        Locale englishLocale = Locale.UK;
-        List<String> englishResultList = Arrays.asList("\u004a", "\u0046", "\u004d", "\u0041", "\u004d",
-                "\u004a", "\u004a", "\u0041", "\u0053", "\u004f", "\u004e", "\u0044");
-
-        Locale frenchLocale = Locale.FRENCH;
-        List<String> frenchResultList = Arrays.asList("\u006a", "\u0066", "\u006d", "\u0061", "\u006d",
-                "\u006a", "\u006a", "\u0061", "\u0073", "\u006f", "\u006e", "\u0064");
-
-        Locale chineseLocale = Locale.CHINESE;
-        List<String> chineseResultList = Arrays.asList("\u4e00", "\u4e8c", "\u4e09", "\u56db", "\u4e94",
-                "\u516d", "\u4e03", "\u516b", "\u4e5d", "\u5341", "\u5341", "\u5341");
-
-        Locale turkishLocale = new Locale("tr", "TR");
-        List<String> turkishResultList = Arrays.asList("\u004f", "\u015e", "\u004d", "\u004e", "\u004d",
-                "\u0048", "\u0054", "\u0041", "\u0045", "\u0045", "\u004b", "\u0041");
-
-        Locale hungarianLocale = new Locale("hu", "HU");
-        List<String> hungarianResultList = Arrays.asList("\u006a", "\u0066", "\u006d", "\u00e1", "\u006d",
-                "\u006a", "\u006a", "\u0061", "\u0073", "\u006f", "\u006e", "\u0064");
-
-        Locale indianLocale = new Locale("en", "IN");
-        List<String> indianResultList = Arrays.asList("\u004a", "\u0046", "\u004d", "\u0041", "\u004d",
-                "\u004a", "\u004a", "\u0041", "\u0053", "\u004f", "\u004e", "\u0044");
-
-        Locale indonesianLocale = new Locale("in", "ID");
-        List<String> indonesianResultList = Arrays.asList("\u004a", "\u0046", "\u004d", "\u0041", "\u004d",
-                "\u004a", "\u004a", "\u0041", "\u0053", "\u004f", "\u004e", "\u0044");
-
-
-        Map<Locale, List<String>> testMap = new HashMap<>();
-        testMap.put(germanLocale,        germanResultList);
-        testMap.put(russianLocale,        russianResultList);
-        testMap.put(austrianLocale,        austrianResultList);
-        testMap.put(englishLocale,        englishResultList);
-        testMap.put(frenchLocale,        frenchResultList);
-        testMap.put(chineseLocale,        chineseResultList);
-        testMap.put(turkishLocale,        turkishResultList);
-        testMap.put(hungarianLocale,    hungarianResultList);
-        testMap.put(indianLocale,        indianResultList);
-        testMap.put(indonesianLocale,    indonesianResultList);
+    /**
+     * Depending on the JRE version, the provider setting and the locale, a different result
+     * is expected and selected via an index
+     */
+    private int localeIndex(Locale locale) {
+        final String provider = System.getProperty("java.locale.providers");
+        return jreVersion < 12 ||
+            !locale.equals (Locale.CHINESE) ||
+            (provider != null && provider.startsWith("JRE"))
+            ? 0 : 1;
+    }
 
-        return testMap;
+    private Date parseDate(String dateStr) {
+        try {
+            return DATE_FORMAT.parse(dateStr);
+        } catch (ParseException e) {
+            return new Date(0);
+        }
     }
 
-    private String getUnicode(char c) {
-        return "\\u" + Integer.toHexString(c | 0x10000).substring(1);
+    /**
+     * Setting up the locale to be tested together with a list of asserted
+     * unicode-formatted results and put them in a map.
+     */
+    private Map<Locale, String> initializeLocales() {
+        Map<Locale, String> testMap = new HashMap<>();
+
+        testMap.put(Locale.GERMAN, "JFMAMJJASOND");
+        testMap.put(new Locale("de", "AT"), "JFMAMJJASOND");
+        testMap.put(Locale.UK, "JFMAMJJASOND");
+        testMap.put(new Locale("en", "IN"), "JFMAMJJASOND");
+        testMap.put(new Locale("in", "ID"), "JFMAMJJASOND");
+        testMap.put(Locale.FRENCH, "jfmamjjasond");
+
+        testMap.put(new Locale("ru", "RU"),
+            "\u044f\u0444\u043c\u0430\u043c\u0438\u0438\u0430\u0441\u043e\u043d\u0434");
+
+        testMap.put(Locale.CHINESE, new String[]{
+            "\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341\u5341\u5341",
+            "123456789111"
+        }[localeIndex(Locale.CHINESE)]);
+
+        testMap.put(new Locale("tr", "TR"),
+            "\u004f\u015e\u004d\u004e\u004d\u0048\u0054\u0041\u0045\u0045\u004b\u0041");
+
+        testMap.put(new Locale("hu", "HU"),
+            "\u006a\u0066\u006d\u00e1\u006d\u006a\u006a\u0061\u0073\u006f\u006e\u0064");
+
+        return testMap;
     }
 
     @Test
@@ -150,7 +148,7 @@ public class TestExcelStyleDateFormatter
         try {
             LocaleUtil.setUserLocale(Locale.GERMAN);
             String dateStr = new ExcelStyleDateFormatter(EXCEL_DATE_FORMAT).format(
-                    new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT).parse("2016-03-26"));
+                    DATE_FORMAT.parse("2016-03-26"));
             assertEquals("M", dateStr);
         } finally {
             LocaleUtil.setUserLocale(before);
@@ -160,7 +158,7 @@ public class TestExcelStyleDateFormatter
     @Test
     public void testWithPattern() throws ParseException {
         String dateStr = new ExcelStyleDateFormatter("yyyy|" + EXCEL_DATE_FORMAT + "|").format(
-                new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT).parse("2016-03-26"));
+                DATE_FORMAT.parse("2016-03-26"));
         assertEquals("2016|M|", dateStr);
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message