poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r634318 - in /poi/trunk/src: documentation/content/xdocs/ java/org/apache/poi/poifs/storage/ testcases/org/apache/poi/poifs/storage/ testcases/org/apache/poi/util/
Date Thu, 06 Mar 2008 15:54:08 GMT
Author: nick
Date: Thu Mar  6 07:54:06 2008
New Revision: 634318

URL: http://svn.apache.org/viewvc?rev=634318&view=rev
Log:
Change the behaviour on short last blocks to be a warning not an exception, as some people
seem to have "real" valid files that trigger this. Fixed bug #28231

Added:
    poi/trunk/src/testcases/org/apache/poi/util/DummyPOILogger.java   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/changes.xml
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/poifs/storage/RawDataBlock.java
    poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java
    poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java

Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=634318&r1=634317&r2=634318&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Thu Mar  6 07:54:06 2008
@@ -36,6 +36,7 @@
 
 		<!-- Don't forget to update status.xml too! -->
         <release version="3.1-beta1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">28231 - For apparently truncated
files, which are somehow still valid, now issue a truncation warning but carry on, rather
than giving an exception as before</action>
            <action dev="POI-DEVELOPERS" type="fix">44504 - Added initial support for
recognising external functions like YEARFRAC and ISEVEN (using NameXPtg), via LinkTable support</action>
            <action dev="POI-DEVELOPERS" type="fix">44504 - Improvements to FormulaParser
- operators, precedence, error literals, quotes in string literals, range checking on IntPtg,
formulas with extra un-parsed stuff at the end, improved parse error handling</action>
            <action dev="POI-DEVELOPERS" type="fix">44504 - Fixed number conversion
inconsistencies in many functions, and improved RefEval</action>

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=634318&r1=634317&r2=634318&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Mar  6 07:54:06 2008
@@ -36,6 +36,9 @@
            <action dev="POI-DEVELOPERS" type="fix">44504 - Added initial support for
recognising external functions like YEARFRAC and ISEVEN (using NameXPtg), via LinkTable support</action>
            <action dev="POI-DEVELOPERS" type="fix">44504 - Improvements to FormulaParser
- operators, precedence, error literals, quotes in string literals, range checking on IntPtg,
formulas with extra un-parsed stuff at the end, improved parse error handling</action>
            <action dev="POI-DEVELOPERS" type="fix">44504 - Fixed number conversion
inconsistencies in many functions, and improved RefEval</action>
+           <action dev="POI-DEVELOPERS" type="fix">44504 - Added initial support for
recognising external functions like YEARFRAC and ISEVEN (using NameXPtg), via LinkTable support</action>
+           <action dev="POI-DEVELOPERS" type="fix">44504 - Improvements to FormulaParser
- operators, precedence, error literals, quotes in string literals, range checking on IntPtg,
formulas with extra un-parsed stuff at the end, improved parse error handling</action>
+           <action dev="POI-DEVELOPERS" type="fix">44504 - Fixed number conversion
inconsistencies in many functions, and improved RefEval</action>
            <action dev="POI-DEVELOPERS" type="fix">44508 - Fix formula evaluation with
evaluateInCell on boolean formulas</action>
            <action dev="POI-DEVELOPERS" type="fix">44510 - Fix how DVALRecord works
with dropdowns</action>
            <action dev="POI-DEVELOPERS" type="fix">44495 - Handle named cell ranges
in formulas that have lower case parts</action>

Modified: poi/trunk/src/java/org/apache/poi/poifs/storage/RawDataBlock.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/storage/RawDataBlock.java?rev=634318&r1=634317&r2=634318&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/storage/RawDataBlock.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/storage/RawDataBlock.java Thu Mar  6 07:54:06
2008
@@ -21,6 +21,8 @@
 
 import org.apache.poi.poifs.common.POIFSConstants;
 import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
 
 import java.io.*;
 
@@ -35,6 +37,7 @@
 {
     private byte[]  _data;
     private boolean _eof;
+    private static POILogger log = POILogFactory.getLogger(RawDataBlock.class);
 
     /**
      * Constructor RawDataBlock
@@ -75,9 +78,12 @@
             String type = " byte" + ((count == 1) ? ("")
                                                   : ("s"));
 
-            throw new IOException("Unable to read entire block; " + count
-                                  + type + " read before EOF; expected "
-                                  + blockSize + " bytes");
+            log.log(POILogger.ERROR,
+            		"Unable to read entire block; " + count
+                     + type + " read before EOF; expected "
+                     + blockSize + " bytes. Your document"
+                     + " has probably been truncated!"
+            );
         }
         else {
             _eof = false;

Modified: poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java?rev=634318&r1=634317&r2=634318&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java Thu Mar  6
07:54:06 2008
@@ -22,6 +22,9 @@
 import java.io.*;
 import java.util.Random;
 
+import org.apache.poi.util.DummyPOILogger;
+import org.apache.poi.util.POILogFactory;
+
 import junit.framework.*;
 
 /**
@@ -43,6 +46,13 @@
     public TestRawDataBlock(String name)
     {
         super(name);
+        
+        // We always want to use our own
+        //  logger
+        System.setProperty(
+        		"org.apache.poi.util.POILogger",
+        		"org.apache.poi.util.DummyPOILogger"
+        );
     }
 
     /**
@@ -99,11 +109,19 @@
 
     /**
      * Test creating a short RawDataBlock
+     * Will trigger a warning, but no longer an IOException,
+     *  as people seem to have "valid" truncated files
      */
-
-    public void testShortConstructor()
+    public void testShortConstructor() throws Exception
     {
-        for (int k = 1; k < 512; k++)
+        // Get the logger to be used
+        DummyPOILogger logger = (DummyPOILogger)POILogFactory.getLogger(
+        		RawDataBlock.class
+        );
+        assertEquals(0, logger.logged.size());
+        
+        // Test for various data sizes
+        for (int k = 1; k <= 512; k++)
         {
             byte[] data = new byte[ k ];
 
@@ -112,16 +130,33 @@
                 data[ j ] = ( byte ) j;
             }
             RawDataBlock block = null;
-
-            try
-            {
-                block = new RawDataBlock(new ByteArrayInputStream(data));
-                fail("Should have thrown IOException creating short block");
-            }
-            catch (IOException ignored)
-            {
-
-                // as expected
+            
+            logger.reset();
+            assertEquals(0, logger.logged.size());
+            
+            // Have it created
+            block = new RawDataBlock(new ByteArrayInputStream(data));
+            assertNotNull(block);
+            
+            // Check for the warning is there for <512
+            if(k < 512) {
+	            assertEquals(
+	            		"Warning on " + k + " byte short block",
+	            		1, logger.logged.size()
+	            );
+	
+	            // Build the expected warning message, and check
+	            String bts = k + " byte";
+	            if(k > 1) {
+	            	bts += "s";
+	            }
+	            
+	            assertEquals(
+	            		"7 - Unable to read entire block; "+bts+" read before EOF; expected 512 bytes.
Your document has probably been truncated!", 
+	            		(String)(logger.logged.get(0))
+	            );
+            } else {
+            	assertEquals(0, logger.logged.size());
             }
         }
     }
@@ -132,6 +167,13 @@
      *  incorrectly think that there's not enough data
      */
     public void testSlowInputStream() throws Exception {
+        // Get the logger to be used
+        DummyPOILogger logger = (DummyPOILogger)POILogFactory.getLogger(
+        		RawDataBlock.class
+        );
+        assertEquals(0, logger.logged.size());
+        
+        // Test for various ok data sizes
         for (int k = 1; k < 512; k++) {
             byte[] data = new byte[ 512 ];
             for (int j = 0; j < data.length; j++) {
@@ -153,14 +195,17 @@
                 data[j] = (byte) j;
             }
             
-            // Shouldn't complain, as there is enough data
-            try {
-	            RawDataBlock block = 
-	            	new RawDataBlock(new SlowInputStream(data, k));
-	            fail();
-            } catch(IOException e) {
-            	// as expected
-            }
+            logger.reset();
+            assertEquals(0, logger.logged.size());
+            
+            // Should complain, as there isn't enough data
+            RawDataBlock block = 
+            	new RawDataBlock(new SlowInputStream(data, k));
+            assertNotNull(block);
+            assertEquals(
+            		"Warning on " + k + " byte short block",
+            		1, logger.logged.size()
+            );
         }
     }
     

Modified: poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java?rev=634318&r1=634317&r2=634318&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java Thu Mar
 6 07:54:06 2008
@@ -21,6 +21,9 @@
 
 import java.io.*;
 
+import org.apache.poi.util.DummyPOILogger;
+import org.apache.poi.util.POILogFactory;
+
 import junit.framework.*;
 
 /**
@@ -42,6 +45,13 @@
     public TestRawDataBlockList(String name)
     {
         super(name);
+        
+        // We always want to use our own
+        //  logger
+        System.setProperty(
+        		"org.apache.poi.util.POILogger",
+        		"org.apache.poi.util.DummyPOILogger"
+        );
     }
 
     /**
@@ -78,8 +88,15 @@
      * Test creating a short RawDataBlockList
      */
 
-    public void testShortConstructor()
+    public void testShortConstructor() throws Exception
     {
+        // Get the logger to be used
+        DummyPOILogger logger = (DummyPOILogger)POILogFactory.getLogger(
+        		RawDataBlock.class
+        );
+        assertEquals(0, logger.logged.size());
+        
+        // Test for various short sizes
         for (int k = 2049; k < 2560; k++)
         {
             byte[] data = new byte[ k ];
@@ -88,16 +105,11 @@
             {
                 data[ j ] = ( byte ) j;
             }
-            try
-            {
-                new RawDataBlockList(new ByteArrayInputStream(data));
-                fail("Should have thrown IOException creating short block");
-            }
-            catch (IOException ignored)
-            {
 
-                // as expected
-            }
+            // Check we logged the error
+            logger.reset();
+            new RawDataBlockList(new ByteArrayInputStream(data));
+            assertEquals(1, logger.logged.size());
         }
     }
 

Added: poi/trunk/src/testcases/org/apache/poi/util/DummyPOILogger.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/util/DummyPOILogger.java?rev=634318&view=auto
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/util/DummyPOILogger.java (added)
+++ poi/trunk/src/testcases/org/apache/poi/util/DummyPOILogger.java Thu Mar  6 07:54:06 2008
@@ -0,0 +1,46 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * POILogger which logs into an ArrayList, so that 
+ *  tests can see what got logged
+ */
+public class DummyPOILogger extends POILogger {
+	public List logged = new ArrayList(); 
+
+	public void reset() {
+		logged = new ArrayList();
+	}
+	
+	public boolean check(int level) {
+		return true;
+	}
+
+	public void initialize(String cat) {}
+
+	public void log(int level, Object obj1) {
+		logged.add(new String(level + " - " + obj1));
+	}
+
+	public void log(int level, Object obj1, Throwable exception) {
+		logged.add(new String(level + " - " + obj1 + " - " + exception));
+	}
+}

Propchange: poi/trunk/src/testcases/org/apache/poi/util/DummyPOILogger.java
------------------------------------------------------------------------------
    svn:eol-style = native



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


Mime
View raw message