From: Nick Burch Date: Mon, 27 Dec 2010 01:51:10 +0000 (+0000) Subject: More NPOIFS tests X-Git-Tag: REL_3_8_BETA1~73 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e511b3403762a5dc3c5af2bb34ef2cdf9ab713fb;p=poi.git More NPOIFS tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1052988 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java b/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java index 11f2ff5978..3caf3b8dd7 100644 --- a/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java +++ b/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java @@ -45,17 +45,13 @@ import org.apache.poi.poifs.nio.FileBackedDataSource; import org.apache.poi.poifs.property.DirectoryProperty; import org.apache.poi.poifs.property.NPropertyTable; import org.apache.poi.poifs.property.Property; -import org.apache.poi.poifs.property.PropertyTable; import org.apache.poi.poifs.storage.BATBlock; -import org.apache.poi.poifs.storage.BlockAllocationTableReader; import org.apache.poi.poifs.storage.BlockAllocationTableWriter; import org.apache.poi.poifs.storage.BlockList; import org.apache.poi.poifs.storage.BlockWritable; import org.apache.poi.poifs.storage.HeaderBlock; import org.apache.poi.poifs.storage.HeaderBlockConstants; import org.apache.poi.poifs.storage.HeaderBlockWriter; -import org.apache.poi.poifs.storage.RawDataBlockList; -import org.apache.poi.poifs.storage.SmallBlockTableReader; import org.apache.poi.poifs.storage.SmallBlockTableWriter; import org.apache.poi.poifs.storage.BATBlock.BATBlockAndIndex; import org.apache.poi.util.CloseIgnoringInputStream; @@ -415,6 +411,14 @@ public class NPOIFSFileSystem } /** + * For unit testing only! Returns the underlying + * properties table + */ + NPropertyTable _get_property_table() { + return _property_table; + } + + /** * Create a new document to be added to the root directory * * @param stream the InputStream from which the document's data diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java index afd2419951..bca205d844 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java @@ -18,11 +18,15 @@ package org.apache.poi.poifs.filesystem; import java.nio.ByteBuffer; +import java.util.Iterator; import junit.framework.TestCase; import org.apache.poi.POIDataSamples; import org.apache.poi.poifs.common.POIFSConstants; +import org.apache.poi.poifs.property.NPropertyTable; +import org.apache.poi.poifs.property.Property; +import org.apache.poi.poifs.property.RootProperty; /** * Tests for the new NIO POIFSFileSystem implementation @@ -69,7 +73,35 @@ public final class TestNPOIFSFileSystem extends TestCase { assertEquals(98, fs.getNextBlock(97)); assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(98)); + // Check the properties + NPropertyTable props = fs._get_property_table(); + assertEquals(90, props.getStartBlock()); + assertEquals(7, props.countBlocks()); + + // Root property tells us about the Mini Stream + RootProperty root = props.getRoot(); + assertEquals("Root Entry", root.getName()); + assertEquals(11564, root.getSize()); + assertEquals(0, root.getStartBlock()); + + // Check its children too + Property prop; + Iterator pi = root.getChildren(); + prop = pi.next(); + assertEquals("Thumbnail", prop.getName()); + prop = pi.next(); + assertEquals("\u0005DocumentSummaryInformation", prop.getName()); + prop = pi.next(); + assertEquals("\u0005SummaryInformation", prop.getName()); + prop = pi.next(); + assertEquals("Image", prop.getName()); + prop = pi.next(); + assertEquals("Tags", prop.getName()); + assertEquals(false, pi.hasNext()); + + + // Check the SBAT (Small Blocks FAT) was properly processed // TODO } @@ -91,8 +123,36 @@ public final class TestNPOIFSFileSystem extends TestCase { assertEquals(1, fs.getNextBlock(0)); assertEquals(2, fs.getNextBlock(1)); assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2)); + // Check the properties + NPropertyTable props = fs._get_property_table(); + assertEquals(12, props.getStartBlock()); + assertEquals(1, props.countBlocks()); + + // Root property tells us about the Mini Stream + RootProperty root = props.getRoot(); + assertEquals("Root Entry", root.getName()); + assertEquals(11564, root.getSize()); + assertEquals(0, root.getStartBlock()); + + // Check its children too + Property prop; + Iterator pi = root.getChildren(); + prop = pi.next(); + assertEquals("Thumbnail", prop.getName()); + prop = pi.next(); + assertEquals("\u0005DocumentSummaryInformation", prop.getName()); + prop = pi.next(); + assertEquals("\u0005SummaryInformation", prop.getName()); + prop = pi.next(); + assertEquals("Image", prop.getName()); + prop = pi.next(); + assertEquals("Tags", prop.getName()); + assertEquals(false, pi.hasNext()); + + + // Check the SBAT (Small Blocks FAT) was properly processed // TODO } } @@ -138,7 +198,21 @@ public final class TestNPOIFSFileSystem extends TestCase { } } - // TODO Check a few bits of a 4096 byte file + // Quick check on 4096 byte blocks too + fsA = new NPOIFSFileSystem(_inst.getFile("BlockSize4096.zvi")); + fsB = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi")); + for(NPOIFSFileSystem fs : new NPOIFSFileSystem[] {fsA,fsB}) { + // 0 -> 1 -> 2 -> end + assertEquals(1, fs.getNextBlock(0)); + assertEquals(2, fs.getNextBlock(1)); + assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2)); + + // 4 -> 11 then end + for(int i=4; i<11; i++) { + assertEquals(i+1, fs.getNextBlock(i)); + } + assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(11)); + } } /** @@ -176,7 +250,37 @@ public final class TestNPOIFSFileSystem extends TestCase { assertEquals((byte)0x00, b.get()); } - // TODO Check a few bits of a 4096 byte file + // Quick check on 4096 byte blocks too + fsA = new NPOIFSFileSystem(_inst.getFile("BlockSize4096.zvi")); + fsB = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi")); + for(NPOIFSFileSystem fs : new NPOIFSFileSystem[] {fsA,fsB}) { + ByteBuffer b; + + // The 0th block is the first data block + b = fs.getBlockAt(0); + assertEquals((byte)0x9e, b.get()); + assertEquals((byte)0x75, b.get()); + assertEquals((byte)0x97, b.get()); + assertEquals((byte)0xf6, b.get()); + + // And the next block + b = fs.getBlockAt(1); + assertEquals((byte)0x00, b.get()); + assertEquals((byte)0x00, b.get()); + assertEquals((byte)0x03, b.get()); + assertEquals((byte)0x00, b.get()); + + // The 14th block is the FAT + b = fs.getBlockAt(14); + assertEquals((byte)0x01, b.get()); + assertEquals((byte)0x00, b.get()); + assertEquals((byte)0x00, b.get()); + assertEquals((byte)0x00, b.get()); + assertEquals((byte)0x02, b.get()); + assertEquals((byte)0x00, b.get()); + assertEquals((byte)0x00, b.get()); + assertEquals((byte)0x00, b.get()); + } } /**