From 4cbedafcaf9800696e485fa9cbe12f3023d92912 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Fri, 25 Apr 2014 10:57:15 +0000 Subject: [PATCH] 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 --- .../filesystem/TestNPOIFSFileSystem.java | 77 ++++++++++++++++++- 1 file 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(); } /** -- 2.39.5