]> source.dussan.org Git - poi.git/commitdiff
Add disabled test for bug #44898, and slightly improve a few poifs related error...
authorNick Burch <nick@apache.org>
Tue, 6 May 2008 22:51:28 +0000 (22:51 +0000)
committerNick Burch <nick@apache.org>
Tue, 6 May 2008 22:51:28 +0000 (22:51 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@653945 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/poifs/storage/BlockListImpl.java
src/java/org/apache/poi/poifs/storage/RawDataBlock.java
src/testcases/org/apache/poi/poifs/data/ShortLastBlock.qwp [new file with mode: 0644]
src/testcases/org/apache/poi/poifs/data/ShortLastBlock.wps [new file with mode: 0644]
src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java

index 07f690c6b858bbd28fbb39bd904c35c74c1bd3e0..7e44fda3f35b31978c07fae340256f7d130ec872 100644 (file)
@@ -102,7 +102,8 @@ class BlockListImpl
         catch (ArrayIndexOutOfBoundsException ignored)
         {
             throw new IOException("Cannot remove block[ " + index
-                                  + " ]; out of range");
+                                  + " ]; out of range[ 0 - " + 
+                                  (_blocks.length-1) + " ]");
         }
         return result;
     }
index 472fd8b8b59f31ceb5554ffbf06fac99b4de29a9..b4630a78b400ef9e46f5a57533102c1713cd0468 100644 (file)
@@ -81,8 +81,9 @@ public class RawDataBlock
             log.log(POILogger.ERROR,
                        "Unable to read entire block; " + count
                      + type + " read before EOF; expected "
-                     + blockSize + " bytes. Your document"
-                     + " has probably been truncated!"
+                     + blockSize + " bytes. Your document "
+                     + "was either written by software that "
+                     + "ignores the spec, or has been truncated!"
             );
         }
         else {
diff --git a/src/testcases/org/apache/poi/poifs/data/ShortLastBlock.qwp b/src/testcases/org/apache/poi/poifs/data/ShortLastBlock.qwp
new file mode 100644 (file)
index 0000000..b278d06
Binary files /dev/null and b/src/testcases/org/apache/poi/poifs/data/ShortLastBlock.qwp differ
diff --git a/src/testcases/org/apache/poi/poifs/data/ShortLastBlock.wps b/src/testcases/org/apache/poi/poifs/data/ShortLastBlock.wps
new file mode 100644 (file)
index 0000000..1b1a627
Binary files /dev/null and b/src/testcases/org/apache/poi/poifs/data/ShortLastBlock.wps differ
index d792dcf22756f831ff15d589e73d0093b3b88d16..1cde86918b9623a6105ff51ff1f187d69b96bc6a 100755 (executable)
@@ -17,6 +17,9 @@
 
 package org.apache.poi.poifs.filesystem;
 
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
@@ -115,6 +118,40 @@ public final class TestPOIFSFileSystem extends TestCase {
                assertTrue("input stream was not closed", testIS.isClosed()); // but still should close
                
        }
+       
+       /**
+        * Test for bug # 48898 - problem opening an OLE2
+        *  file where the last block is short (i.e. not a full
+        *  multiple of 512 bytes)
+        *  
+        * As yet, this problem remains. One school of thought is
+        *  not not issue an EOF when we discover the last block
+        *  is short, but this seems a bit wrong.
+        * The other is to fix the handling of the last block in
+        *  POIFS, since it seems to be slight wrong
+        */
+       public void DISABLEDtestShortLastBlock() throws Exception {
+               String[] files = new String[] {
+                       "ShortLastBlock.qwp", "ShortLastBlock.wps"      
+               };
+               String pdirname = System.getProperty("POIFS.testdata.path");
+
+               for(int i=0; i<files.length; i++) {
+                       File f = new File(pdirname, files[i]);
+                       assertTrue(f.exists());
+                       
+                       // Open the file up
+                       POIFSFileSystem fs = new POIFSFileSystem(
+                                       new FileInputStream(f)
+                       );
+                       
+                       // Write it into a temp output array
+                       ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                       fs.writeFilesystem(baos);
+                       
+                       // Check sizes
+               }
+       }
 
        private static InputStream openSampleStream(String sampleFileName) {
                return HSSFTestDataSamples.openSampleFileStream(sampleFileName);