poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1681762 - in /poi/trunk/src: java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java java/org/apache/poi/poifs/filesystem/NPOIFSStream.java testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java
Date Tue, 26 May 2015 13:56:40 GMT
Author: nick
Date: Tue May 26 13:56:40 2015
New Revision: 1681762

URL: http://svn.apache.org/r1681762
Log:
Fix testing for NPOIFS zero-length stream writing

Modified:
    poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java
    poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSStream.java
    poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java

Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java?rev=1681762&r1=1681761&r2=1681762&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java Tue May 26 13:56:40
2015
@@ -143,10 +143,6 @@ public final class NPOIFSDocument implem
            os.write(buf, 0, readBytes);
        }
        
-       // If this is an empty document, write a single byte
-       //  to force a block allocation for this document
-       if (length == 0) os.write(0);
-       
        // Tidy and return the length
        os.close();
        return length;

Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSStream.java?rev=1681762&r1=1681761&r2=1681762&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSStream.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSStream.java Tue May 26 13:56:40
2015
@@ -256,8 +256,10 @@ public class NPOIFSStream implements Ite
             NPOIFSStream toFree = new NPOIFSStream(blockStore, nextBlock);
             toFree.free(loopDetector);
             
-            // Mark the end of the stream
-            blockStore.setNextBlock(prevBlock, POIFSConstants.END_OF_CHAIN);
+            // Mark the end of the stream, if we have any data
+            if (prevBlock != POIFSConstants.END_OF_CHAIN) {
+                blockStore.setNextBlock(prevBlock, POIFSConstants.END_OF_CHAIN);
+            }
         }
    }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java?rev=1681762&r1=1681761&r2=1681762&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java Tue
May 26 13:56:40 2015
@@ -1336,8 +1336,6 @@ public final class TestNPOIFSFileSystem
        }
    }
    
-   // TODO Should these have a mini-sbat entry or not?
-   // TODO Is the reading of zero-length properties exactly correct?
    @Test
    public void writeZeroLengthEntries() throws Exception {
        NPOIFSFileSystem fs = new NPOIFSFileSystem();
@@ -1378,6 +1376,37 @@ public final class TestNPOIFSFileSystem
        emptyDoc = (DocumentEntry)testDir.getEntry("empty-3");
        assertContentsMatches(empty, emptyDoc);
        
+       // Look at the properties entry, and check the empty ones
+       //  have zero size and no start block
+       NPropertyTable props = fs._get_property_table();
+       Iterator<Property> propsIt = props.getRoot().getChildren();
+       
+       Property prop = propsIt.next();
+       assertEquals("Mini2", prop.getName());
+       assertEquals(0, prop.getStartBlock());
+       assertEquals(7, prop.getSize());
+       
+       prop = propsIt.next();
+       assertEquals("Normal4106", prop.getName());
+       assertEquals(4, prop.getStartBlock()); // BAT, Props, SBAT, MIni
+       assertEquals(4106, prop.getSize());
+       
+       prop = propsIt.next();
+       assertEquals("empty-1", prop.getName());
+       assertEquals(POIFSConstants.END_OF_CHAIN, prop.getStartBlock());
+       assertEquals(0, prop.getSize());
+       
+       prop = propsIt.next();
+       assertEquals("empty-2", prop.getName());
+       assertEquals(POIFSConstants.END_OF_CHAIN, prop.getStartBlock());
+       assertEquals(0, prop.getSize());
+       
+       prop = propsIt.next();
+       assertEquals("empty-3", prop.getName());
+       assertEquals(POIFSConstants.END_OF_CHAIN, prop.getStartBlock());
+       assertEquals(0, prop.getSize());
+       
+       
        // Save and re-check
        fs = writeOutAndReadBack(fs);
        testDir = fs.getRoot();



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


Mime
View raw message