poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1721900 - /poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java
Date Mon, 28 Dec 2015 12:10:12 GMT
Author: onealj
Date: Mon Dec 28 12:10:12 2015
New Revision: 1721900

URL: http://svn.apache.org/viewvc?rev=1721900&view=rev
Log:
bug 58775: add unit test to test for non-built-in data formats

Modified:
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java?rev=1721900&r1=1721899&r2=1721900&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java Mon Dec 28
12:10:12 2015
@@ -19,6 +19,8 @@ package org.apache.poi.ss.usermodel;
 
 import junit.framework.TestCase;
 
+import java.io.IOException;
+
 import org.apache.poi.ss.ITestDataProvider;
 
 /**
@@ -32,6 +34,11 @@ public abstract class BaseTestDataFormat
     protected BaseTestDataFormat(ITestDataProvider testDataProvider) {
         _testDataProvider = testDataProvider;
     }
+    
+    public void assertNotBuiltInFormat(String customFmt) {
+        //check it is not in built-in formats
+        assertEquals(-1, BuiltinFormats.getBuiltinFormat(customFmt));
+    }
 
     public final void testBuiltinFormats() {
         Workbook wb = _testDataProvider.createWorkbook();
@@ -53,7 +60,7 @@ public abstract class BaseTestDataFormat
         //create a custom data format
         String customFmt = "#0.00 AM/PM";
         //check it is not in built-in formats
-        assertEquals(-1, BuiltinFormats.getBuiltinFormat(customFmt));
+        assertNotBuiltInFormat(customFmt);
         int customIdx = df.getFormat(customFmt);
         //The first user-defined format starts at 164.
         assertTrue(customIdx >= BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX);
@@ -88,6 +95,27 @@ public abstract class BaseTestDataFormat
         assertEquals(poundFmt, dataFormat.getFormat(poundFmtIdx));
     }
     
+    public void testReadbackFormat() throws IOException {
+        readbackFormat("built-in format", "0.00");
+        readbackFormat("overridden built-in format", poundFmt);
+        
+        String customFormat = "#0.00 AM/PM";
+        assertNotBuiltInFormat(customFormat);
+        readbackFormat("custom format", customFormat);
+    }
+    
+    private void readbackFormat(String msg, String fmt) throws IOException {
+        Workbook wb = _testDataProvider.createWorkbook();
+        try {
+            DataFormat dataFormat = wb.createDataFormat();
+            short fmtIdx = dataFormat.getFormat(fmt);
+            String readbackFmt = dataFormat.getFormat(fmtIdx);
+            assertEquals(msg, fmt, readbackFmt);
+        } finally {
+            wb.close();
+        }
+    }
+    
     public abstract void test58532();
     public void doTest58532Core(Workbook wb) {
         Sheet s = wb.getSheetAt(0);



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


Mime
View raw message