diff options
author | Nick Burch <nick@apache.org> | 2014-04-25 10:57:15 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2014-04-25 10:57:15 +0000 |
commit | 4cbedafcaf9800696e485fa9cbe12f3023d92912 (patch) | |
tree | 4929745525bee7dd8fe88bb33a4355bba7bc851d /src/testcases/org/apache/poi/poifs | |
parent | 75826dcd7509cf8d2e017f8acf47e682fedf51d3 (diff) | |
download | poi-4cbedafcaf9800696e485fa9cbe12f3023d92912.tar.gz poi-4cbedafcaf9800696e485fa9cbe12f3023d92912.zip |
More npoifs write tests, some disabled as failing
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1589987 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/poifs')
-rw-r--r-- | src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java | 77 |
1 files changed, 74 insertions, 3 deletions
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java index cd0598be30..3ff82785a6 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java @@ -852,20 +852,91 @@ if (1==0) { @Test public void addBeforeWrite() throws Exception { NPOIFSFileSystem fs = new NPOIFSFileSystem(); + NDocumentInputStream inp; // Initially has BAT + Properties but nothing else assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(0)); assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(1)); assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(2)); + DirectoryEntry parentDir = fs.createDirectory("Parent Directory"); + DirectoryEntry testDir = parentDir.createDirectory("Test Directory"); + + // Add to the mini stream - // TODO + byte[] mini = new byte[] { 0, 1, 2, 3, 4 }; + testDir.createDocument("Mini", new ByteArrayInputStream(mini)); // Add to the main stream - // TODO + byte[] main4096 = new byte[4096]; + main4096[0] = -10; + main4096[4095] = -11; + testDir.createDocument("Normal4096", new ByteArrayInputStream(main4096)); + + + // Check the mini stream was added, then the main stream + assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(0)); + assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(1)); + assertEquals(3, fs.getNextBlock(2)); + assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3)); + assertEquals(5, fs.getNextBlock(4)); + assertEquals(6, fs.getNextBlock(5)); + assertEquals(7, fs.getNextBlock(6)); + assertEquals(8, fs.getNextBlock(7)); + assertEquals(9, fs.getNextBlock(8)); + assertEquals(10, fs.getNextBlock(9)); + assertEquals(11, fs.getNextBlock(10)); + assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(11)); + assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(12)); + // Write, read, check - // TODO + fs = writeOutAndReadBack(fs); + + // Check it was unchanged + // TODO Fix this +if (1==0) { + assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(0)); + assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(1)); + assertEquals(3, fs.getNextBlock(2)); + assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3)); + assertEquals(5, fs.getNextBlock(4)); + assertEquals(6, fs.getNextBlock(5)); + assertEquals(7, fs.getNextBlock(6)); + assertEquals(8, fs.getNextBlock(7)); + assertEquals(9, fs.getNextBlock(8)); + assertEquals(10, fs.getNextBlock(9)); + assertEquals(11, fs.getNextBlock(10)); + assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(11)); + assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(12)); +} + + // Check the data + DirectoryEntry fsRoot = fs.getRoot(); + assertEquals(1, fsRoot.getEntryCount()); + + parentDir = (DirectoryEntry)fsRoot.getEntry("Parent Directory"); + assertEquals(1, parentDir.getEntryCount()); + + testDir = (DirectoryEntry)parentDir.getEntry("Test Directory"); + assertEquals(2, testDir.getEntryCount()); + + // TODO Fix mini stream reading +if(1==0){ + DocumentEntry miniDoc = (DocumentEntry)testDir.getEntry("Mini"); + inp = new NDocumentInputStream(miniDoc); + byte[] miniRead = new byte[miniDoc.getSize()]; + assertEquals(miniDoc.getSize(), inp.read(miniRead)); + assertThat(mini, equalTo(miniRead)); + inp.close(); +} + + DocumentEntry normDoc = (DocumentEntry)testDir.getEntry("Normal4096"); + inp = new NDocumentInputStream(normDoc); + byte[] normRead = new byte[normDoc.getSize()]; + assertEquals(normDoc.getSize(), inp.read(normRead)); + assertThat(main4096, equalTo(normRead)); + inp.close(); } /** |