poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1701688 [2/7] - in /poi/trunk: ./ src/java/org/apache/poi/hssf/eventusermodel/ src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/usermodel/ src/java/org/apache/poi/poifs/filesystem/ src/java/org/apache/poi/ss/format/ src/jav...
Date Mon, 07 Sep 2015 20:19:51 GMT
Modified: poi/trunk/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/facets/XAdESXLSignatureFacet.java Mon Sep  7 20:19:50 2015
@@ -39,6 +39,8 @@ import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collections;
 import java.util.List;
+import java.util.Locale;
+import java.util.TimeZone;
 import java.util.UUID;
 
 import javax.xml.crypto.MarshalException;
@@ -214,7 +216,7 @@ public class XAdESXLSignatureFacet exten
                 CRLIdentifierType crlIdentifier = crlRef.addNewCRLIdentifier();
                 String issuerName = crl.getIssuerDN().getName().replace(",", ", ");
                 crlIdentifier.setIssuer(issuerName);
-                Calendar cal = Calendar.getInstance();
+                Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Z"), Locale.ROOT);
                 cal.setTime(crl.getThisUpdate());
                 crlIdentifier.setIssueTime(cal);
                 crlIdentifier.setNumber(getCrlNumber(crl));
@@ -238,7 +240,7 @@ public class XAdESXLSignatureFacet exten
                     
                     BasicOCSPResp basicOcspResp = (BasicOCSPResp)ocspResp.getResponseObject();
                     
-                    Calendar cal = Calendar.getInstance();
+                    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Z"), Locale.ROOT);
                     cal.setTime(basicOcspResp.getProducedAt());
                     ocspIdentifier.setProducedAt(cal);
     

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java Mon Sep  7 20:19:50 2015
@@ -26,6 +26,7 @@ import java.awt.image.BufferedImage;
 import java.io.File;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 import javax.imageio.ImageIO;
@@ -155,7 +156,7 @@ public class PPTX2PNG {
                 // save the result
                 if (!"null".equals(format)) {
                     String outname = file.getName().replaceFirst(".pptx?", "");
-                    outname = String.format("%1$s-%2$04d.%3$s", outname, slideNo, format);
+                    outname = String.format(Locale.ROOT, "%1$s-%2$04d.%3$s", outname, slideNo, format);
                     File outfile = new File(outdir, outname);
                     ImageIO.write(img, format, outfile);
                 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java Mon Sep  7 20:19:50 2015
@@ -25,6 +25,7 @@ import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Vector;
 
@@ -314,7 +315,7 @@ public class XSSFExportToXml implements
     }
 
     private String getFormattedDate(XSSFCell cell) {
-        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT);
         return sdf.format(cell.getDateCellValue());
     }
 

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java Mon Sep  7 20:19:50 2015
@@ -35,6 +35,7 @@ import org.apache.poi.ss.usermodel.RichT
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellReference;
+import org.apache.poi.util.LocaleUtil;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 import org.apache.poi.xssf.usermodel.XSSFHyperlink;
@@ -653,7 +654,7 @@ public class SXSSFCell implements Cell {
                 return getCellFormula();
             case CELL_TYPE_NUMERIC:
                 if (DateUtil.isCellDateFormatted(this)) {
-                    DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
+                    DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", LocaleUtil.getUserLocale());
                     return sdf.format(getDateCellValue());
                 }
                 return getNumericCellValue() + "";

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java Mon Sep  7 20:19:50 2015
@@ -21,6 +21,7 @@ import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.Locale;
 
 import org.apache.poi.ss.SpreadsheetVersion;
 import org.apache.poi.ss.formula.FormulaParser;
@@ -840,7 +841,7 @@ public final class XSSFCell implements C
                 return getCellFormula();
             case CELL_TYPE_NUMERIC:
                 if (DateUtil.isCellDateFormatted(this)) {
-                    DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
+                    DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", Locale.ROOT);
                     return sdf.format(getDateCellValue());
                 }
                 return Double.toString(getNumericCellValue());

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java Mon Sep  7 20:19:50 2015
@@ -17,37 +17,49 @@
 
 package org.apache.poi;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import java.io.IOException;
 import java.util.Calendar;
 import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.Locale;
-import java.util.TimeZone;
-
-import junit.framework.TestCase;
 
 import org.apache.poi.POIXMLProperties.CoreProperties;
 import org.apache.poi.openxml4j.util.Nullable;
+import org.apache.poi.util.LocaleUtil;
 import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.poi.xwpf.XWPFTestDataSamples;
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
 
 /**
  * Test setting extended and custom OOXML properties
  */
-public final class TestPOIXMLProperties extends TestCase {
+public final class TestPOIXMLProperties {
+    private XWPFDocument sampleDoc;
 	private POIXMLProperties _props;
 	private CoreProperties _coreProperties;
 
+	@Before
 	public void setUp() throws IOException {
-		XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("documentProperties.docx");
+		sampleDoc = XWPFTestDataSamples.openSampleDocument("documentProperties.docx");
 		_props = sampleDoc.getProperties();
 		_coreProperties = _props.getCoreProperties();
 		assertNotNull(_props);
 	}
+	
+	@After
+	public void closeResources() throws Exception {
+	    sampleDoc.close();
+	}
 
-	public void testWorkbookExtendedProperties() {
+	@Test
+	public void testWorkbookExtendedProperties() throws Exception {
 		XSSFWorkbook workbook = new XSSFWorkbook();
 		POIXMLProperties props = workbook.getProperties();
 		assertNotNull(props);
@@ -71,7 +83,7 @@ public final class TestPOIXMLProperties
 
 		XSSFWorkbook newWorkbook =
 				XSSFTestDataSamples.writeOutAndReadBack(workbook);
-
+		workbook.close();
 		assertTrue(workbook != newWorkbook);
 
 
@@ -88,16 +100,19 @@ public final class TestPOIXMLProperties
 
 		assertEquals(application, newCtProps.getApplication());
 		assertEquals(appVersion, newCtProps.getAppVersion());
+		
+		newWorkbook.close();
 	}
 
 
     /**
      * Test usermodel API for setting custom properties
      */
-    public void testCustomProperties() {
-        POIXMLDocument wb = new XSSFWorkbook();
+	@Test
+	public void testCustomProperties() throws Exception {
+        POIXMLDocument wb1 = new XSSFWorkbook();
 
-        POIXMLProperties.CustomProperties customProps = wb.getProperties().getCustomProperties();
+        POIXMLProperties.CustomProperties customProps = wb1.getProperties().getCustomProperties();
         customProps.addProperty("test-1", "string val");
         customProps.addProperty("test-2", 1974);
         customProps.addProperty("test-3", 36.6);
@@ -110,9 +125,10 @@ public final class TestPOIXMLProperties
         }
         customProps.addProperty("test-4", true);
 
-        wb = XSSFTestDataSamples.writeOutAndReadBack((XSSFWorkbook)wb);
+        POIXMLDocument wb2 = XSSFTestDataSamples.writeOutAndReadBack((XSSFWorkbook)wb1);
+        wb1.close();
         org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperties ctProps =
-                wb.getProperties().getCustomProperties().getUnderlyingProperties();
+                wb2.getProperties().getCustomProperties().getUnderlyingProperties();
         assertEquals(4, ctProps.sizeOfPropertyArray());
         org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty p;
 
@@ -131,7 +147,7 @@ public final class TestPOIXMLProperties
         p = ctProps.getPropertyArray(2);
         assertEquals("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", p.getFmtid());
         assertEquals("test-3", p.getName());
-        assertEquals(36.6, p.getR8());
+        assertEquals(36.6, p.getR8(), 0);
         assertEquals(4, p.getPid());
 
         p = ctProps.getPropertyArray(3);
@@ -139,9 +155,12 @@ public final class TestPOIXMLProperties
         assertEquals("test-4", p.getName());
         assertEquals(true, p.getBool());
         assertEquals(5, p.getPid());
+        
+        wb2.close();
     }
 
-    public void testDocumentProperties() {
+	@Test
+	public void testDocumentProperties() {
 		String category = _coreProperties.getCategory();
 		assertEquals("test", category);
 		String contentStatus = "Draft";
@@ -158,21 +177,25 @@ public final class TestPOIXMLProperties
 		assertEquals("Hello World", title);
 	}
 
-    public void testTransitiveSetters() throws IOException {
+	@Test
+	public void testTransitiveSetters() throws IOException {
 		XWPFDocument doc = new XWPFDocument();
         CoreProperties cp = doc.getProperties().getCoreProperties();
 
-        Date dateCreated = new GregorianCalendar(2010, 6, 15, 10, 0, 0).getTime();
+
+        Date dateCreated = LocaleUtil.getLocaleCalendar(2010, 6, 15, 10, 0, 0).getTime();
         cp.setCreated(new Nullable<Date>(dateCreated));
         assertEquals(dateCreated.toString(), cp.getCreated().toString());
 
-        doc = XWPFTestDataSamples.writeOutAndReadBack(doc);
+        XWPFDocument doc2 = XWPFTestDataSamples.writeOutAndReadBack(doc);
+        doc.close();
         cp = doc.getProperties().getCoreProperties();
         Date dt3 = cp.getCreated();
         assertEquals(dateCreated.toString(), dt3.toString());
-
+        doc2.close();
     }
 
+	@Test
 	public void testGetSetRevision() {
 		String revision = _coreProperties.getRevision();
 		assertTrue("Revision number is 1", Integer.parseInt(revision) > 1);
@@ -183,7 +206,7 @@ public final class TestPOIXMLProperties
 	}
 	
 	public static boolean dateTimeEqualToUTCString(Date dateTime, String utcString) {
-		Calendar utcCalendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.UK);
+		Calendar utcCalendar = LocaleUtil.getLocaleCalendar(LocaleUtil.TIMEZONE_UTC);
         utcCalendar.setTimeInMillis(dateTime.getTime());
         String dateTimeUtcString = utcCalendar.get(Calendar.YEAR) + "-" + 
                zeroPad((utcCalendar.get(Calendar.MONTH)+1)) + "-" + 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java Mon Sep  7 20:19:50 2015
@@ -17,111 +17,97 @@
 
 package org.apache.poi.openxml4j.opc;
 
+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 java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.IOException;
 import java.io.InputStream;
 import java.text.ParsePosition;
 import java.text.SimpleDateFormat;
 import java.util.Date;
-import java.util.TimeZone;
-
-import junit.framework.TestCase;
+import java.util.Locale;
 
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
 import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
 import org.apache.poi.openxml4j.util.Nullable;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
+import org.apache.poi.util.LocaleUtil;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.junit.Test;
 import org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty;
 
-public final class TestPackageCoreProperties extends TestCase {
-    private static final POILogger logger = POILogFactory.getLogger(TestPackageCoreProperties.class);
-
+public final class TestPackageCoreProperties {
 	/**
 	 * Test package core properties getters.
 	 */
-	public void testGetProperties() {
-		try {
-			// Open the package
-			OPCPackage p = OPCPackage.open(OpenXML4JTestDataSamples.openSampleStream("TestPackageCoreProperiesGetters.docx"));
-			compareProperties(p);
-			p.revert();
-		} catch (OpenXML4JException e) {
-			logger.log(POILogger.DEBUG, e.getMessage());
-			throw new RuntimeException(e);
-		} catch (IOException e) {
-			throw new RuntimeException(e);
-		}
+    @Test
+	public void testGetProperties() throws Exception {
+		// Open the package
+		@SuppressWarnings("resource")
+        OPCPackage p = OPCPackage.open(OpenXML4JTestDataSamples.openSampleStream("TestPackageCoreProperiesGetters.docx"));
+		compareProperties(p);
+		p.revert();
 	}
 
 	/**
 	 * Test package core properties setters.
 	 */
-	public void testSetProperties() throws Exception {
+    @Test
+    public void testSetProperties() throws Exception {
 		String inputPath = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCoreProperiesSetters.docx");
 
 		File outputFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageCoreProperiesSettersOUTPUT.docx");
 
 		// Open package
-		OPCPackage p = OPCPackage.open(inputPath, PackageAccess.READ_WRITE);
-		try {
-    		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
-            df.setTimeZone(TimeZone.getTimeZone("UTC"));
-    		Date dateToInsert = df.parse("2007-05-12T08:00:00Z", new ParsePosition(
-    				0));
-    
-    		PackageProperties props = p.getPackageProperties();
-    		props.setCategoryProperty("MyCategory");
-    		props.setContentStatusProperty("MyContentStatus");
-    		props.setContentTypeProperty("MyContentType");
-    		props.setCreatedProperty(new Nullable<Date>(dateToInsert));
-    		props.setCreatorProperty("MyCreator");
-    		props.setDescriptionProperty("MyDescription");
-    		props.setIdentifierProperty("MyIdentifier");
-    		props.setKeywordsProperty("MyKeywords");
-    		props.setLanguageProperty("MyLanguage");
-    		props.setLastModifiedByProperty("Julien Chable");
-    		props.setLastPrintedProperty(new Nullable<Date>(dateToInsert));
-    		props.setModifiedProperty(new Nullable<Date>(dateToInsert));
-    		props.setRevisionProperty("2");
-    		props.setTitleProperty("MyTitle");
-    		props.setSubjectProperty("MySubject");
-    		props.setVersionProperty("2");
-    		// Save the package in the output directory
-    		p.save(outputFile);
-    
-    		// Open the newly created file to check core properties saved values.
-    		OPCPackage p2 = OPCPackage.open(outputFile.getAbsolutePath(), PackageAccess.READ);
-    		try {
-    		    compareProperties(p2);
-    		    p2.revert();
-    		} finally {
-    		    p2.close();
-    		}
-    		outputFile.delete();
-		} finally {
-            // use revert to not re-write the input file
-            p.revert();
-		}
+		@SuppressWarnings("resource")
+        OPCPackage p = OPCPackage.open(inputPath, PackageAccess.READ_WRITE);
+		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT);
+        df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
+		Date dateToInsert = df.parse("2007-05-12T08:00:00Z", new ParsePosition(0));
+
+		PackageProperties props = p.getPackageProperties();
+		props.setCategoryProperty("MyCategory");
+		props.setContentStatusProperty("MyContentStatus");
+		props.setContentTypeProperty("MyContentType");
+		props.setCreatedProperty(new Nullable<Date>(dateToInsert));
+		props.setCreatorProperty("MyCreator");
+		props.setDescriptionProperty("MyDescription");
+		props.setIdentifierProperty("MyIdentifier");
+		props.setKeywordsProperty("MyKeywords");
+		props.setLanguageProperty("MyLanguage");
+		props.setLastModifiedByProperty("Julien Chable");
+		props.setLastPrintedProperty(new Nullable<Date>(dateToInsert));
+		props.setModifiedProperty(new Nullable<Date>(dateToInsert));
+		props.setRevisionProperty("2");
+		props.setTitleProperty("MyTitle");
+		props.setSubjectProperty("MySubject");
+		props.setVersionProperty("2");
+		// Save the package in the output directory
+		p.save(outputFile);
+        p.revert();
+
+		// Open the newly created file to check core properties saved values.
+		@SuppressWarnings("resource")
+        OPCPackage p2 = OPCPackage.open(outputFile.getAbsolutePath(), PackageAccess.READ);
+	    compareProperties(p2);
+	    p2.revert();
+		outputFile.delete();
 	}
 
 	private void compareProperties(OPCPackage p) throws InvalidFormatException {
-		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
-		df.setTimeZone(TimeZone.getTimeZone("UTC"));
-		Date expectedDate = df.parse("2007-05-12T08:00:00Z", new ParsePosition(
-				0));
+		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT);
+		df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
+		Date expectedDate = df.parse("2007-05-12T08:00:00Z", new ParsePosition(0));
 
 		// Gets the core properties
 		PackageProperties props = p.getPackageProperties();
 		assertEquals("MyCategory", props.getCategoryProperty().getValue());
-		assertEquals("MyContentStatus", props.getContentStatusProperty()
-				.getValue());
+		assertEquals("MyContentStatus", props.getContentStatusProperty().getValue());
 		assertEquals("MyContentType", props.getContentTypeProperty().getValue());
 		assertEquals(expectedDate, props.getCreatedProperty().getValue());
 		assertEquals("MyCreator", props.getCreatorProperty().getValue());
@@ -129,8 +115,7 @@ public final class TestPackageCoreProper
 		assertEquals("MyIdentifier", props.getIdentifierProperty().getValue());
 		assertEquals("MyKeywords", props.getKeywordsProperty().getValue());
 		assertEquals("MyLanguage", props.getLanguageProperty().getValue());
-		assertEquals("Julien Chable", props.getLastModifiedByProperty()
-				.getValue());
+		assertEquals("Julien Chable", props.getLastModifiedByProperty().getValue());
 		assertEquals(expectedDate, props.getLastPrintedProperty().getValue());
 		assertEquals(expectedDate, props.getModifiedProperty().getValue());
 		assertEquals("2", props.getRevisionProperty().getValue());
@@ -139,9 +124,10 @@ public final class TestPackageCoreProper
 		assertEquals("2", props.getVersionProperty().getValue());
 	}
 
-    public void testCoreProperties_bug51374() throws Exception {
-        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
-        df.setTimeZone(TimeZone.getTimeZone("UTC"));
+	@Test
+	public void testCoreProperties_bug51374() throws Exception {
+        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT);
+        df.setTimeZone(LocaleUtil.TIMEZONE_UTC);
         String strDate = "2007-05-12T08:00:00Z";
         Date date = df.parse(strDate);
 
@@ -197,7 +183,8 @@ public final class TestPackageCoreProper
         pkg.close();
     }
 
-    public void testGetPropertiesLO() throws Exception {
+	@Test
+	public void testGetPropertiesLO() throws Exception {
         // Open the package
         OPCPackage pkg1 = OPCPackage.open(OpenXML4JTestDataSamples.openSampleStream("51444.xlsx"));
         PackageProperties props1 = pkg1.getPackageProperties();
@@ -206,13 +193,16 @@ public final class TestPackageCoreProper
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         pkg1.save(out);
         out.close();
+        pkg1.close();
 
         OPCPackage pkg2 = OPCPackage.open(new ByteArrayInputStream(out.toByteArray()));
         PackageProperties props2 = pkg2.getPackageProperties();
         props2.setTitleProperty("Bug 51444 fixed");
+        pkg2.close();
     }
 
-    public void testEntitiesInCoreProps_56164() throws Exception {
+	@Test
+	public void testEntitiesInCoreProps_56164() throws Exception {
         InputStream is = OpenXML4JTestDataSamples.openSampleStream("CorePropertiesHasEntities.ooxml");
         OPCPackage p = OPCPackage.open(is);
         is.close();
@@ -236,9 +226,12 @@ public final class TestPackageCoreProper
         
         // Check
         assertEquals("Stefan Kopf", props.getCreatorProperty().getValue());
+        
+        p.close();
     }
     
-    public void testListOfCustomProperties() throws Exception {
+	@Test
+	public void testListOfCustomProperties() throws Exception {
         File inp = POIDataSamples.getSpreadSheetInstance().getFile("ExcelWithAttachments.xlsm");
         OPCPackage pkg = OPCPackage.open(inp, PackageAccess.READ);
         XSSFWorkbook wb = new XSSFWorkbook(pkg);

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/format/TestCellFormatPart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/format/TestCellFormatPart.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/format/TestCellFormatPart.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/format/TestCellFormatPart.java Mon Sep  7 20:19:50 2015
@@ -16,14 +16,36 @@
 ==================================================================== */
 package org.apache.poi.ss.format;
 
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.xssf.XSSFITestDataProvider;
+import static org.junit.Assert.assertEquals;
 
+import java.util.Locale;
+import java.util.TimeZone;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.util.LocaleUtil;
+import org.apache.poi.xssf.XSSFITestDataProvider;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
 /** Test the individual CellFormatPart types. */
 public class TestCellFormatPart extends CellFormatTestBase {
+    
+    private static Locale userLocale;
+    
+    @BeforeClass
+    public static void setLocale() {
+        userLocale = LocaleUtil.getUserLocale();
+        LocaleUtil.setUserLocale(Locale.ROOT);
+    }
+    
+    @AfterClass
+    public static void unsetLocale() {
+        LocaleUtil.setUserLocale(userLocale);
+    }
+    
     private static final Pattern NUMBER_EXTRACT_FMT = Pattern.compile(
             "([-+]?[0-9]+)(\\.[0-9]+)?.*(?:(e).*?([+-]?[0-9]+))",
             Pattern.CASE_INSENSITIVE);
@@ -32,6 +54,7 @@ public class TestCellFormatPart extends
         super(XSSFITestDataProvider.instance);
     }
 
+    @Test
     public void testGeneralFormat() throws Exception {
         runFormatTests("GeneralFormatTests.xlsx", new CellValue() {
             public Object getValue(Cell cell) {
@@ -54,6 +77,7 @@ public class TestCellFormatPart extends
         });
     }
 
+    @Test
     public void testNumberApproxFormat() throws Exception {
         runFormatTests("NumberFormatApproxTests.xlsx", new CellValue() {
             public Object getValue(Cell cell) {
@@ -73,14 +97,22 @@ public class TestCellFormatPart extends
         });
     }
 
+    @Test
     public void testDateFormat() throws Exception {
-        runFormatTests("DateFormatTests.xlsx", new CellValue() {
-            public Object getValue(Cell cell) {
-                return cell.getDateCellValue();
-            }
-        });
+        TimeZone tz = LocaleUtil.getUserTimeZone();
+        LocaleUtil.setUserTimeZone(TimeZone.getTimeZone("CET"));
+        try {
+            runFormatTests("DateFormatTests.xlsx", new CellValue() {
+                public Object getValue(Cell cell) {
+                    return cell.getDateCellValue();
+                }
+            });
+        } finally {
+            LocaleUtil.setUserTimeZone(tz);
+        }
     }
 
+    @Test
     public void testElapsedFormat() throws Exception {
         runFormatTests("ElapsedFormatTests.xlsx", new CellValue() {
             public Object getValue(Cell cell) {
@@ -89,6 +121,7 @@ public class TestCellFormatPart extends
         });
     }
 
+    @Test
     public void testTextFormat() throws Exception {
         runFormatTests("TextFormatTests.xlsx", new CellValue() {
             public Object getValue(Cell cell) {
@@ -100,6 +133,7 @@ public class TestCellFormatPart extends
         });
     }
 
+    @Test
     public void testConditions() throws Exception {
         runFormatTests("FormatConditionTests.xlsx", new CellValue() {
             Object getValue(Cell cell) {

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java Mon Sep  7 20:19:50 2015
@@ -17,13 +17,13 @@
 
 package org.apache.poi.ss.usermodel;
 
+import static org.junit.Assert.assertEquals;
+
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.ss.ITestDataProvider;
-import org.apache.poi.ss.SpreadsheetVersion;
-import org.apache.poi.xssf.SXSSFITestDataProvider;
-import org.apache.poi.xssf.XSSFITestDataProvider;
 import org.apache.poi.xssf.streaming.SXSSFCell;
 import org.apache.poi.xssf.usermodel.XSSFCell;
+import org.junit.Test;
 
 /**
  * Class for combined testing of XML-specific functionality of 
@@ -37,6 +37,7 @@ public abstract class BaseTestXCell exte
         super(testDataProvider);
     }
 
+    @Test
     public void testXmlEncoding(){
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sh = wb.createSheet();

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java Mon Sep  7 20:19:50 2015
@@ -19,6 +19,8 @@
 
 package org.apache.poi.xssf.streaming;
 
+import static org.junit.Assert.assertEquals;
+
 import java.io.IOException;
 
 import javax.xml.namespace.QName;
@@ -30,6 +32,8 @@ import org.apache.poi.xssf.SXSSFITestDat
 import org.apache.poi.xssf.usermodel.XSSFCell;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.xmlbeans.XmlCursor;
+import org.junit.AfterClass;
+import org.junit.Test;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
 
 /**
@@ -42,11 +46,12 @@ public class TestSXSSFCell extends BaseT
         super(SXSSFITestDataProvider.instance);
     }
 
-    @Override
-    public void tearDown(){
+    @AfterClass
+    public static void tearDown(){
         SXSSFITestDataProvider.instance.cleanup();
     }
 
+    @Test
     public void testPreserveSpaces() throws IOException {
         String[] samplesWithSpaces = {
                 " POI",

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java Mon Sep  7 20:19:50 2015
@@ -17,14 +17,18 @@
 
 package org.apache.poi.xssf.usermodel;
 
-import java.io.InputStream;
-import java.io.PrintStream;
-
-import junit.framework.Assert;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.PackageAccess;
 import org.apache.poi.ss.formula.eval.TestFormulasFromSpreadsheet;
 import org.apache.poi.ss.formula.functions.TestMathX;
 import org.apache.poi.ss.usermodel.Cell;
@@ -32,7 +36,13 @@ import org.apache.poi.ss.usermodel.CellV
 import org.apache.poi.ss.usermodel.FormulaEvaluator;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.AfterClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
 
 /**
  * Performs much the same role as {@link TestFormulasFromSpreadsheet},
@@ -44,206 +54,127 @@ import org.apache.poi.openxml4j.opc.OPCP
  *  Excel 2007, and re-save it as FormulaEvalTestData_Copy.xlsx
  *  
  */
-public final class TestFormulaEvaluatorOnXSSF extends TestCase {
-	
-	private static final class Result {
-		public static final int SOME_EVALUATIONS_FAILED = -1;
-		public static final int ALL_EVALUATIONS_SUCCEEDED = +1;
-		public static final int NO_EVALUATIONS_FOUND = 0;
-	}
+@RunWith(Parameterized.class)
+public final class TestFormulaEvaluatorOnXSSF {
 
+    private static XSSFWorkbook workbook;
+    private static Sheet sheet;
+    private static FormulaEvaluator evaluator;
+    private static Locale userLocale;
+    
 	/** 
 	 * This class defines constants for navigating around the test data spreadsheet used for these tests.
 	 */
-	private static final class SS {
+	private static interface SS {
 		
 		/**
 		 * Name of the test spreadsheet (found in the standard test data folder)
 		 */
-		public final static String FILENAME = "FormulaEvalTestData_Copy.xlsx";
+		String FILENAME = "FormulaEvalTestData_Copy.xlsx";
         /**
          * Row (zero-based) in the test spreadsheet where the operator examples start.
          */
-        public static final int START_OPERATORS_ROW_INDEX = 22; // Row '23'
+        int START_OPERATORS_ROW_INDEX = 22; // Row '23'
         /**
          * Row (zero-based) in the test spreadsheet where the function examples start.
          */
-        public static final int START_FUNCTIONS_ROW_INDEX = 95; // Row '96'
+        int START_FUNCTIONS_ROW_INDEX = 95; // Row '96'
         /**
          * Index of the column that contains the function names
          */
-        public static final int COLUMN_INDEX_FUNCTION_NAME = 1; // Column 'B'
+        int COLUMN_INDEX_FUNCTION_NAME = 1; // Column 'B'
 
         /**
          * Used to indicate when there are no more functions left
          */
-        public static final String FUNCTION_NAMES_END_SENTINEL = "<END-OF-FUNCTIONS>";
+        String FUNCTION_NAMES_END_SENTINEL = "<END-OF-FUNCTIONS>";
 
         /**
          * Index of the column where the test values start (for each function)
          */
-        public static final short COLUMN_INDEX_FIRST_TEST_VALUE = 3; // Column 'D'
+        short COLUMN_INDEX_FIRST_TEST_VALUE = 3; // Column 'D'
 
         /**
          * Each function takes 4 rows in the test spreadsheet
          */
-        public static final int NUMBER_OF_ROWS_PER_FUNCTION = 4;
-	}
-
-	private XSSFWorkbook workbook;
-	private Sheet sheet;
-	// Note - multiple failures are aggregated before ending.  
-	// If one or more functions fail, a single AssertionFailedError is thrown at the end
-	private int _functionFailureCount;
-	private int _functionSuccessCount;
-	private int _evaluationFailureCount;
-	private int _evaluationSuccessCount;
-
-	private static final Cell getExpectedValueCell(Row row, short columnIndex) {
-		if (row == null) {
-			return null;
-		}
-		return row.getCell(columnIndex);
-	}
-
-
-	private static void confirmExpectedResult(String msg, Cell expected, CellValue actual) {
-		if (expected == null) {
-			throw new AssertionFailedError(msg + " - Bad setup data expected value is null");
-		}
-		if(actual == null) {
-			throw new AssertionFailedError(msg + " - actual value was null");
-		}
-		
-		switch (expected.getCellType()) {
-			case Cell.CELL_TYPE_BLANK:
-				assertEquals(msg, Cell.CELL_TYPE_BLANK, actual.getCellType());
-				break;
-			case Cell.CELL_TYPE_BOOLEAN:
-				assertEquals(msg, Cell.CELL_TYPE_BOOLEAN, actual.getCellType());
-				assertEquals(msg, expected.getBooleanCellValue(), actual.getBooleanValue());
-				break;
-			case Cell.CELL_TYPE_ERROR:
-				assertEquals(msg, Cell.CELL_TYPE_ERROR, actual.getCellType());
-				if(false) { // TODO: fix ~45 functions which are currently returning incorrect error values
-					assertEquals(msg, expected.getErrorCellValue(), actual.getErrorValue());
-				}
-				break;
-			case Cell.CELL_TYPE_FORMULA: // will never be used, since we will call method after formula evaluation
-				throw new AssertionFailedError("Cannot expect formula as result of formula evaluation: " + msg);
-			case Cell.CELL_TYPE_NUMERIC:
-				assertEquals(msg, Cell.CELL_TYPE_NUMERIC, actual.getCellType());
-				TestMathX.assertEquals(msg, expected.getNumericCellValue(), actual.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR);
-//				double delta = Math.abs(expected.getNumericCellValue()-actual.getNumberValue());
-//				double pctExpected = Math.abs(0.00001*expected.getNumericCellValue());
-//				assertTrue(msg, delta <= pctExpected);
-				break;
-			case Cell.CELL_TYPE_STRING:
-				assertEquals(msg, Cell.CELL_TYPE_STRING, actual.getCellType());
-				assertEquals(msg, expected.getRichStringCellValue().getString(), actual.getStringValue());
-				break;
-		}
-	}
-
-
-	protected void setUp() throws Exception {
-		if (workbook == null) {
-			InputStream is = HSSFTestDataSamples.openSampleFileStream(SS.FILENAME);
-			OPCPackage pkg = OPCPackage.open(is);
-			workbook = new XSSFWorkbook( pkg );
-			sheet = workbook.getSheetAt( 0 );
-		  }
-		_functionFailureCount = 0;
-		_functionSuccessCount = 0;
-		_evaluationFailureCount = 0;
-		_evaluationSuccessCount = 0;
-	}
-	
-	/**
-	 * Checks that we can actually open the file
-	 */
-	public void testOpen() {
-		assertNotNull(workbook);
-	}
-	
-	/**
-	 * Disabled for now, as many things seem to break
-	 *  for XSSF, which is a shame
-	 */
-	public void testFunctionsFromTestSpreadsheet() {
-		
-		processFunctionGroup(SS.START_OPERATORS_ROW_INDEX, null);
-		processFunctionGroup(SS.START_FUNCTIONS_ROW_INDEX, null);
-		// example for debugging individual functions/operators:
-//		processFunctionGroup(SS.START_OPERATORS_ROW_INDEX, "ConcatEval");
-//		processFunctionGroup(SS.START_FUNCTIONS_ROW_INDEX, "AVERAGE");
-		
-		// confirm results
-		String successMsg = "There were " 
-				+ _evaluationSuccessCount + " successful evaluation(s) and "
-				+ _functionSuccessCount + " function(s) without error";
- 		if(_functionFailureCount > 0) {
-			String msg = _functionFailureCount + " function(s) failed in "
-			+ _evaluationFailureCount + " evaluation(s).  " + successMsg;
-			throw new AssertionFailedError(msg);
-		}
- 		if(false) { // normally no output for successful tests
- 			System.out.println(getClass().getName() + ": " + successMsg);
- 		}
-	}
-
-	/**
-	 * @param startRowIndex row index in the spreadsheet where the first function/operator is found 
-	 * @param testFocusFunctionName name of a single function/operator to test alone. 
-	 * Typically pass <code>null</code> to test all functions
-	 */
-	private void processFunctionGroup(int startRowIndex, String testFocusFunctionName) {
- 
-		FormulaEvaluator evaluator = new XSSFFormulaEvaluator(workbook);
-
-		int rowIndex = startRowIndex;
-		while (true) {
-			Row r = sheet.getRow(rowIndex);
-			String targetFunctionName = getTargetFunctionName(r);
-			if(targetFunctionName == null) {
-				throw new AssertionFailedError("Test spreadsheet cell empty on row (" 
-						+ (rowIndex+1) + "). Expected function name or '"
-						+ SS.FUNCTION_NAMES_END_SENTINEL + "'");
-			}
-			if(targetFunctionName.equals(SS.FUNCTION_NAMES_END_SENTINEL)) {
-				// found end of functions list
-				break;
-			}
-			if(testFocusFunctionName == null || targetFunctionName.equalsIgnoreCase(testFocusFunctionName)) {
-				
-				// expected results are on the row below
-				Row expectedValuesRow = sheet.getRow(rowIndex + 1);
-				if(expectedValuesRow == null) {
-					int missingRowNum = rowIndex + 2; //+1 for 1-based, +1 for next row
-					throw new AssertionFailedError("Missing expected values row for function '" 
-							+ targetFunctionName + " (row " + missingRowNum + ")"); 
-				}
-				switch(processFunctionRow(evaluator, targetFunctionName, r, expectedValuesRow)) {
-					case Result.ALL_EVALUATIONS_SUCCEEDED: _functionSuccessCount++; break;
-					case Result.SOME_EVALUATIONS_FAILED: _functionFailureCount++; break;
-					default:
-						throw new RuntimeException("unexpected result");
-					case Result.NO_EVALUATIONS_FOUND: // do nothing
-				}
-			}
-			rowIndex += SS.NUMBER_OF_ROWS_PER_FUNCTION;
-		}
+        int NUMBER_OF_ROWS_PER_FUNCTION = 4;
 	}
 
-	/**
-	 * 
-	 * @return a constant from the local Result class denoting whether there were any evaluation
-	 * cases, and whether they all succeeded.
-	 */
-	private int processFunctionRow(FormulaEvaluator evaluator, String targetFunctionName, 
-			Row formulasRow, Row expectedValuesRow) {
-		
-		int result = Result.NO_EVALUATIONS_FOUND; // so far
+    @Parameter(value = 0)
+    public String targetFunctionName;
+    @Parameter(value = 1)
+    public int formulasRowIdx;
+    @Parameter(value = 2)
+    public int expectedValuesRowIdx;
+
+    @AfterClass
+    public static void closeResource() throws Exception {
+        LocaleUtil.setUserLocale(userLocale);
+        workbook.close();
+    }
+    
+    @Parameters(name="{0}")
+    public static Collection<Object[]> data() throws Exception {
+        // Function "Text" uses custom-formats which are locale specific
+        // can't set the locale on a per-testrun execution, as some settings have been
+        // already set, when we would try to change the locale by then
+        userLocale = LocaleUtil.getUserLocale();
+        LocaleUtil.setUserLocale(Locale.ROOT);
+
+        workbook = new XSSFWorkbook( OPCPackage.open(HSSFTestDataSamples.getSampleFile(SS.FILENAME), PackageAccess.READ) );
+        sheet = workbook.getSheetAt( 0 );
+        evaluator = new XSSFFormulaEvaluator(workbook);
+        
+        List<Object[]> data = new ArrayList<Object[]>();
+        
+        processFunctionGroup(data, SS.START_OPERATORS_ROW_INDEX, null);
+        processFunctionGroup(data, SS.START_FUNCTIONS_ROW_INDEX, null);
+        // example for debugging individual functions/operators:
+        // processFunctionGroup(data, SS.START_OPERATORS_ROW_INDEX, "ConcatEval");
+        // processFunctionGroup(data, SS.START_FUNCTIONS_ROW_INDEX, "Text");
+
+        return data;
+    }
+    
+    /**
+     * @param startRowIndex row index in the spreadsheet where the first function/operator is found 
+     * @param testFocusFunctionName name of a single function/operator to test alone. 
+     * Typically pass <code>null</code> to test all functions
+     */
+    private static void processFunctionGroup(List<Object[]> data, int startRowIndex, String testFocusFunctionName) {
+        for (int rowIndex = startRowIndex; true; rowIndex += SS.NUMBER_OF_ROWS_PER_FUNCTION) {
+            Row r = sheet.getRow(rowIndex);
+            String targetFunctionName = getTargetFunctionName(r);
+            if(targetFunctionName == null) {
+                fail("Test spreadsheet cell empty on row ("
+                    + (rowIndex+1) + "). Expected function name or '"
+                    + SS.FUNCTION_NAMES_END_SENTINEL + "'");
+            }
+            if(targetFunctionName.equals(SS.FUNCTION_NAMES_END_SENTINEL)) {
+                // found end of functions list
+                break;
+            }
+            if(testFocusFunctionName == null || targetFunctionName.equalsIgnoreCase(testFocusFunctionName)) {
+                
+                // expected results are on the row below
+                Row expectedValuesRow = sheet.getRow(rowIndex + 1);
+                if(expectedValuesRow == null) {
+                    int missingRowNum = rowIndex + 2; //+1 for 1-based, +1 for next row
+                    fail("Missing expected values row for function '" 
+                        + targetFunctionName + " (row " + missingRowNum + ")"); 
+                }
+                
+                data.add(new Object[]{targetFunctionName, rowIndex, rowIndex + 1});
+            }
+        }
+    }
+
+
+	@Test
+	public void processFunctionRow() {
+	    Row formulasRow = sheet.getRow(formulasRowIdx);
+	    Row expectedValuesRow = sheet.getRow(expectedValuesRowIdx);
+	    
 		short endcolnum = formulasRow.getLastCellNum();
 
 		// iterate across the row for all the evaluation cases
@@ -256,31 +187,44 @@ public final class TestFormulaEvaluatorO
 				continue;
 			}
 
-			CellValue actualValue;
-			try {
-				actualValue = evaluator.evaluate(c);
-			} catch (RuntimeException e) {
-				_evaluationFailureCount ++;
-				printShortStackTrace(System.err, e);
-				result = Result.SOME_EVALUATIONS_FAILED;
-				continue;
-			}
+			CellValue actValue = evaluator.evaluate(c);
+			Cell expValue = (expectedValuesRow == null) ? null : expectedValuesRow.getCell(colnum);
 
-			Cell expectedValueCell = getExpectedValueCell(expectedValuesRow, colnum);
-			try {
-				confirmExpectedResult("Function '" + targetFunctionName + "': Formula: " + c.getCellFormula() + " @ " + formulasRow.getRowNum() + ":" + colnum,
-						expectedValueCell, actualValue);
-				_evaluationSuccessCount ++;
-				if(result != Result.SOME_EVALUATIONS_FAILED) {
-					result = Result.ALL_EVALUATIONS_SUCCEEDED;
-				}
-			} catch (AssertionFailedError e) {
-				_evaluationFailureCount ++;
-				printShortStackTrace(System.err, e);
-				result = Result.SOME_EVALUATIONS_FAILED;
-			}
+			String msg = String.format(Locale.ROOT, "Function '%s': Formula: %s @ %d:%d"
+		        , targetFunctionName, c.getCellFormula(), formulasRow.getRowNum(), colnum);
+			
+			assertNotNull(msg + " - Bad setup data expected value is null", expValue);
+			assertNotNull(msg + " - actual value was null", actValue);
+	        
+	        switch (expValue.getCellType()) {
+	            case Cell.CELL_TYPE_BLANK:
+	                assertEquals(msg, Cell.CELL_TYPE_BLANK, actValue.getCellType());
+	                break;
+	            case Cell.CELL_TYPE_BOOLEAN:
+	                assertEquals(msg, Cell.CELL_TYPE_BOOLEAN, actValue.getCellType());
+	                assertEquals(msg, expValue.getBooleanCellValue(), actValue.getBooleanValue());
+	                break;
+	            case Cell.CELL_TYPE_ERROR:
+	                assertEquals(msg, Cell.CELL_TYPE_ERROR, actValue.getCellType());
+//	              if(false) { // TODO: fix ~45 functions which are currently returning incorrect error values
+//	                  assertEquals(msg, expValue.getErrorCellValue(), actValue.getErrorValue());
+//	              }
+	                break;
+	            case Cell.CELL_TYPE_FORMULA: // will never be used, since we will call method after formula evaluation
+	                fail("Cannot expect formula as result of formula evaluation: " + msg);
+	            case Cell.CELL_TYPE_NUMERIC:
+	                assertEquals(msg, Cell.CELL_TYPE_NUMERIC, actValue.getCellType());
+	                TestMathX.assertEquals(msg, expValue.getNumericCellValue(), actValue.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR);
+//	              double delta = Math.abs(expValue.getNumericCellValue()-actValue.getNumberValue());
+//	              double pctExpValue = Math.abs(0.00001*expValue.getNumericCellValue());
+//	              assertTrue(msg, delta <= pctExpValue);
+	                break;
+	            case Cell.CELL_TYPE_STRING:
+	                assertEquals(msg, Cell.CELL_TYPE_STRING, actValue.getCellType());
+	                assertEquals(msg, expValue.getRichStringCellValue().getString(), actValue.getStringValue());
+	                break;
+	        }
 		}
- 		return result;
 	}
 
 	/*
@@ -301,40 +245,6 @@ public final class TestFormulaEvaluatorO
 		return false;
 	}
 
-
-	/**
-	 * Useful to keep output concise when expecting many failures to be reported by this test case
-	 */
-	private static void printShortStackTrace(PrintStream ps, Throwable e) {
-		StackTraceElement[] stes = e.getStackTrace();
-		
-		int startIx = 0;
-		// skip any top frames inside junit.framework.Assert
-		while(startIx<stes.length) {
-			if(!stes[startIx].getClassName().equals(Assert.class.getName())) {
-				break;
-			}
-			startIx++;
-		}
-		// skip bottom frames (part of junit framework)
-		int endIx = startIx+1;
-		while(endIx < stes.length) {
-			if(stes[endIx].getClassName().equals(TestCase.class.getName())) {
-				break;
-			}
-			endIx++;
-		}
-		if(startIx >= endIx) {
-			// something went wrong. just print the whole stack trace
-			e.printStackTrace(ps);
-		}
-		endIx -= 4; // skip 4 frames of reflection invocation
-		ps.println(e.toString());
-		for(int i=startIx; i<endIx; i++) {
-			ps.println("\tat " + stes[i].toString());
-		}
-	}
-
 	/**
 	 * @return <code>null</code> if cell is missing, empty or blank
 	 */
@@ -355,7 +265,7 @@ public final class TestFormulaEvaluatorO
 			return cell.getRichStringCellValue().getString();
 		}
 		
-		throw new AssertionFailedError("Bad cell type for 'function name' column: ("
-				+ cell.getCellType() + ") row (" + (r.getRowNum() +1) + ")");
+		fail("Bad cell type for 'function name' column: ("+cell.getColumnIndex()+") row ("+(r.getRowNum()+1)+")");
+		return null;
 	}
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java Mon Sep  7 20:19:50 2015
@@ -17,6 +17,12 @@
 
 package org.apache.poi.xssf.usermodel;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
@@ -25,10 +31,6 @@ import java.io.OutputStream;
 import java.nio.charset.Charset;
 import java.util.Calendar;
 import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.Locale;
-
-import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.ss.usermodel.Cell;
@@ -42,6 +44,7 @@ import org.apache.poi.ss.usermodel.Workb
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellUtil;
 import org.apache.poi.ss.util.RegionUtil;
+import org.apache.poi.util.LocaleUtil;
 import org.apache.poi.xssf.SXSSFITestDataProvider;
 import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.streaming.SXSSFWorkbook;
@@ -57,7 +60,8 @@ import org.openxmlformats.schemas.spread
  * Bugzilla id's PLEASE MOVE tests from this class to TestBugs once the bugs are
  * fixed, so that they are then run automatically.
  */
-public final class TestUnfixedBugs extends TestCase {
+public final class TestUnfixedBugs {
+    @Test
     public void testBug54084Unicode() throws IOException {
         // sample XLSX with the same text-contents as the text-file above
         XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("54084 - Greek - beyond BMP.xlsx");
@@ -76,8 +80,14 @@ public final class TestUnfixedBugs exten
         verifyBug54084Unicode(wbWritten);
 
         // finally also write it out via the streaming interface and verify that we still can read it back in
-        Workbook wbStreamingWritten = SXSSFITestDataProvider.instance.writeOutAndReadBack(new SXSSFWorkbook(wb));
+        SXSSFWorkbook swb = new SXSSFWorkbook(wb);
+        Workbook wbStreamingWritten = SXSSFITestDataProvider.instance.writeOutAndReadBack(swb);
         verifyBug54084Unicode(wbStreamingWritten);
+
+        wbWritten.close();
+        swb.close();
+        wbStreamingWritten.close();
+        wb.close();
     }
 
     private void verifyBug54084Unicode(Workbook wb) {
@@ -95,7 +105,8 @@ public final class TestUnfixedBugs exten
         assertEquals("The data in the text-file should exactly match the data that we read from the workbook", testData, value);
     }
 
-    public void test54071() {
+    @Test
+    public void test54071() throws Exception {
         Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("54071.xlsx");
         Sheet sheet = workbook.getSheetAt(0);
         int rows = sheet.getPhysicalNumberOfRows();
@@ -120,8 +131,11 @@ public final class TestUnfixedBugs exten
                 }
             }
         }
+        
+        workbook.close();
     }
     
+    @Test
     public void test54071Simple() {
         double value1 = 41224.999988425923;
         double value2 = 41224.999988368058;
@@ -143,15 +157,13 @@ public final class TestUnfixedBugs exten
         // second to be different here!
         int startYear = 1900;
         int dayAdjust = -1; // Excel thinks 2/29/1900 is a valid date, which it isn't
-        Calendar calendar1 = new GregorianCalendar(Locale.ROOT);
-        calendar1.set(startYear,0, wholeDays1 + dayAdjust, 0, 0, 0);
+        Calendar calendar1 = LocaleUtil.getLocaleCalendar(startYear,0, wholeDays1 + dayAdjust);
         calendar1.set(Calendar.MILLISECOND, millisecondsInDay1);
       // this is the rounding part:
       calendar1.add(Calendar.MILLISECOND, 500);
       calendar1.clear(Calendar.MILLISECOND);
 
-        Calendar calendar2 = new GregorianCalendar(Locale.ROOT);
-        calendar2.set(startYear,0, wholeDays2 + dayAdjust, 0, 0, 0);
+        Calendar calendar2 = LocaleUtil.getLocaleCalendar(startYear,0, wholeDays2 + dayAdjust);
         calendar2.set(Calendar.MILLISECOND, millisecondsInDay2);
       // this is the rounding part:
       calendar2.add(Calendar.MILLISECOND, 500);
@@ -163,7 +175,8 @@ public final class TestUnfixedBugs exten
         assertEquals(DateUtil.getJavaDate(value1, false), DateUtil.getJavaDate(value2, false));
     }
 
-    public void test57236() {
+    @Test
+    public void test57236() throws Exception {
         // Having very small numbers leads to different formatting, Excel uses the scientific notation, but POI leads to "0"
         
         /*
@@ -189,10 +202,12 @@ public final class TestUnfixedBugs exten
                 }
             }
         }
+        wb.close();
     }
 
     // When this is fixed, the test case should go to BaseTestXCell with 
     // adjustments to use _testDataProvider to also verify this for XSSF
+    @Test
     public void testBug57294() throws IOException {
         Workbook wb = SXSSFITestDataProvider.instance.createWorkbook();
         
@@ -217,6 +232,8 @@ public final class TestUnfixedBugs exten
         assertEquals(0, strBack.getIndexOfFormattingRun(0));
         assertEquals(2, strBack.getIndexOfFormattingRun(1));
         assertEquals(4, strBack.getIndexOfFormattingRun(2));
+        
+        wbBack.close();
     }
 
    @Test



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


Mime
View raw message