From e191e05045b990625a144bf5ff9c088051260a42 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 26 May 2015 13:41:29 +0000 Subject: More 0 byte stream tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1681754 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/poifs/property/DirectoryProperty.java | 11 +++++-- .../apache/poi/poifs/property/RootProperty.java | 2 -- .../poi/poifs/filesystem/TestNPOIFSFileSystem.java | 32 +++++++++++++++++++++ test-data/poifs/only-zero-byte-streams.ole2 | Bin 0 -> 1536 bytes 4 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 test-data/poifs/only-zero-byte-streams.ole2 diff --git a/src/java/org/apache/poi/poifs/property/DirectoryProperty.java b/src/java/org/apache/poi/poifs/property/DirectoryProperty.java index a73221af24..d86e73ada1 100644 --- a/src/java/org/apache/poi/poifs/property/DirectoryProperty.java +++ b/src/java/org/apache/poi/poifs/property/DirectoryProperty.java @@ -28,10 +28,8 @@ import java.util.Set; /** * Directory property - * - * @author Marc Johnson (mjohnson at apache dot org) */ -public class DirectoryProperty extends Property implements Parent { // TODO - fix instantiable superclass +public class DirectoryProperty extends Property implements Parent, Iterable { // TODO - fix instantiable superclass /** List of Property instances */ private List _children; @@ -241,6 +239,13 @@ public class DirectoryProperty extends Property implements Parent { // TODO - fi { return _children.iterator(); } + /** + * Get an iterator over the children of this Parent, alias for + * {@link #getChildren()} which supports foreach use + */ + public Iterator iterator() { + return getChildren(); + } /** * Add a new child to the collection of children diff --git a/src/java/org/apache/poi/poifs/property/RootProperty.java b/src/java/org/apache/poi/poifs/property/RootProperty.java index b934a2601b..5a8f3d52ef 100644 --- a/src/java/org/apache/poi/poifs/property/RootProperty.java +++ b/src/java/org/apache/poi/poifs/property/RootProperty.java @@ -22,8 +22,6 @@ import org.apache.poi.poifs.storage.SmallDocumentBlock; /** * Root property - * - * @author Marc Johnson (mjohnson at apache dot org) */ public final class RootProperty extends DirectoryProperty { private static final String NAME = "Root Entry"; diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java index 1444374833..69c6cacf68 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java @@ -21,6 +21,7 @@ import static org.hamcrest.core.IsCollectionContaining.hasItem; import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; @@ -41,6 +42,7 @@ import org.apache.poi.poifs.property.Property; import org.apache.poi.poifs.property.RootProperty; import org.apache.poi.poifs.storage.HeaderBlock; import org.apache.poi.util.IOUtils; +import org.junit.Ignore; import org.junit.Test; /** @@ -1306,6 +1308,36 @@ public final class TestNPOIFSFileSystem { assertContentsMatches(main4106, normDoc); } + @Test + public void readZeroLengthEntries() throws Exception { + NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.getFile("only-zero-byte-streams.ole2")); + DirectoryNode testDir = fs.getRoot(); + assertEquals(3, testDir.getEntryCount()); + DocumentEntry entry; + + entry = (DocumentEntry)testDir.getEntry("test-zero-1"); + assertNotNull(entry); + assertEquals(0, entry.getSize()); + + entry = (DocumentEntry)testDir.getEntry("test-zero-2"); + assertNotNull(entry); + assertEquals(0, entry.getSize()); + + entry = (DocumentEntry)testDir.getEntry("test-zero-3"); + assertNotNull(entry); + assertEquals(0, entry.getSize()); + + // Check properties, all have zero length, no blocks + NPropertyTable props = fs._get_property_table(); + assertEquals(POIFSConstants.END_OF_CHAIN, props.getRoot().getStartBlock()); + for (Property prop : props.getRoot()) { + assertEquals("test-zero-", prop.getName().substring(0, 10)); + assertEquals(POIFSConstants.END_OF_CHAIN, prop.getStartBlock()); + } + } + + // 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(); diff --git a/test-data/poifs/only-zero-byte-streams.ole2 b/test-data/poifs/only-zero-byte-streams.ole2 new file mode 100644 index 0000000000..c1b8429878 Binary files /dev/null and b/test-data/poifs/only-zero-byte-streams.ole2 differ -- cgit v1.2.3