]> source.dussan.org Git - poi.git/commitdiff
More tests for bug #45365, but still not able to reproduce it
authorNick Burch <nick@apache.org>
Tue, 5 Aug 2008 22:29:20 +0000 (22:29 +0000)
committerNick Burch <nick@apache.org>
Tue, 5 Aug 2008 22:29:20 +0000 (22:29 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@682999 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/eventusermodel/FormatTrackingHSSFListener.java
src/testcases/org/apache/poi/hssf/data/45365-2.xls [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/eventusermodel/TestFormatTrackingHSSFListener.java

index 355a9b71f034f210e519b165f63fa9ba3af3b6f4..ff34958e6e405414da78f2f50ad92a803e87a24d 100644 (file)
 ==================================================================== */
 package org.apache.poi.hssf.eventusermodel;
 
-import java.text.DateFormat;
-import java.text.DecimalFormat;
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
@@ -33,7 +29,6 @@ import org.apache.poi.hssf.record.NumberRecord;
 import org.apache.poi.hssf.record.Record;
 import org.apache.poi.hssf.usermodel.HSSFDataFormat;
 import org.apache.poi.hssf.usermodel.HSSFDataFormatter;
-import org.apache.poi.hssf.usermodel.HSSFDateUtil;
 
 /**
  * A proxy HSSFListener that keeps track of the document
@@ -50,6 +45,13 @@ public class FormatTrackingHSSFListener implements HSSFListener {
                this.childListener = childListener;
        }
        
+       protected int getNumberOfCustomFormats() {
+               return customFormatRecords.size();
+       }
+       protected int getNumberOfExtendedFormats() {
+               return xfRecords.size();
+       }
+       
        /**
         * Process this record ourselves, and then
         *  pass it on to our child listener
diff --git a/src/testcases/org/apache/poi/hssf/data/45365-2.xls b/src/testcases/org/apache/poi/hssf/data/45365-2.xls
new file mode 100644 (file)
index 0000000..b5e66c1
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/45365-2.xls differ
index 60f5d2ca72d7c227cbff61d48d21d7587526ffca..0c28c484129fc8de0d5286222536a123c16172bd 100644 (file)
@@ -62,31 +62,45 @@ public final class TestFormatTrackingHSSFListener extends TestCase {
        
        /**
         * Ensure that all number and formula records can be
-        *  turned into strings without problems
+        *  turned into strings without problems.
+        * For now, we're just looking to get text back, no
+        *  exceptions thrown, but in future we might also
+        *  want to check the exact strings!
         */
        public void testTurnToString() throws Exception {
-               processFile("45365.xls");
-               
-               for(int i=0; i<mockListen._records.size(); i++) {
-                       Record r = (Record)mockListen._records.get(i);
-                       CellValueRecordInterface cvr = null;
+               String[] files = new String[] { 
+                               "45365.xls", "45365-2.xls", "MissingBits.xls" 
+               };
+               for(int k=0; k<files.length; k++) {
+                       processFile(files[k]);
                        
-                       if(r instanceof NumberRecord) {
-                               cvr = (CellValueRecordInterface)r;
-                       }
-                       if(r instanceof FormulaRecord) {
-                               cvr = (CellValueRecordInterface)r;
-                       }
+                       // Check we found our formats
+                       assertTrue(listener.getNumberOfCustomFormats() > 5);
+                       assertTrue(listener.getNumberOfExtendedFormats() > 5);
                        
-                       if(cvr != null) {
-                               // Should always give us a string 
-                               String s = listener.formatNumberDateCell(cvr);
-                               assertNotNull(s);
-                               assertTrue(s.length() > 0);
+                       // Now check we can turn all the numeric
+                       //  cells into strings without error
+                       for(int i=0; i<mockListen._records.size(); i++) {
+                               Record r = (Record)mockListen._records.get(i);
+                               CellValueRecordInterface cvr = null;
+                               
+                               if(r instanceof NumberRecord) {
+                                       cvr = (CellValueRecordInterface)r;
+                               }
+                               if(r instanceof FormulaRecord) {
+                                       cvr = (CellValueRecordInterface)r;
+                               }
+                               
+                               if(cvr != null) {
+                                       // Should always give us a string 
+                                       String s = listener.formatNumberDateCell(cvr);
+                                       assertNotNull(s);
+                                       assertTrue(s.length() > 0);
+                               }
                        }
+                       
+                       // TODO - test some specific format strings
                }
-               
-               // TODO - test some specific format strings
        }
        
        private static final class MockHSSFListener implements HSSFListener {