From 216343d32d2a9835f9af0402a3e2940fbf7de554 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 24 Apr 2014 20:23:43 +0000 Subject: [PATCH] Add TODOs for the next set of NPOIFS write tests we need git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1589868 13f79535-47bb-0310-9956-ffa450edef68 --- .../filesystem/TestNPOIFSFileSystem.java | 72 +++++++++++++++---- 1 file changed, 58 insertions(+), 14 deletions(-) diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java index 8e4391378a..b23feb29d1 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java @@ -46,6 +46,18 @@ import org.junit.Test; */ public final class TestNPOIFSFileSystem { private static final POIDataSamples _inst = POIDataSamples.getPOIFSInstance(); + + /** + * Returns test files with 512 byte and 4k block sizes, loaded + * both from InputStreams and Files + */ + protected NPOIFSFileSystem[] get512and4kFileAndInput() throws Exception { + NPOIFSFileSystem fsA = new NPOIFSFileSystem(_inst.getFile("BlockSize512.zvi")); + NPOIFSFileSystem fsB = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi")); + NPOIFSFileSystem fsC = new NPOIFSFileSystem(_inst.getFile("BlockSize4096.zvi")); + NPOIFSFileSystem fsD = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi")); + return new NPOIFSFileSystem[] {fsA,fsB,fsC,fsD}; + } protected static void assertBATCount(NPOIFSFileSystem fs, int expectedBAT, int expectedXBAT) throws IOException { int foundBAT = 0; @@ -515,7 +527,14 @@ public final class TestNPOIFSFileSystem { // Check that it is seen correctly fs = new NPOIFSFileSystem(new ByteArrayInputStream(baos.toByteArray())); assertBATCount(fs, 237, 2); - // TODO Do some more checks + + assertEquals(false, fs.getBATBlockAndIndex(236*128-1).getBlock().hasFreeSectors()); + assertEquals(true, fs.getBATBlockAndIndex(237*128-1).getBlock().hasFreeSectors()); + try { + assertEquals(false, fs.getBATBlockAndIndex(237*128).getBlock().hasFreeSectors()); + fail("Should only be 237 BATs"); + } catch(IndexOutOfBoundsException e) {} + // All done fs.close(); @@ -527,11 +546,7 @@ public final class TestNPOIFSFileSystem { */ @Test public void listEntries() throws Exception { - NPOIFSFileSystem fsA = new NPOIFSFileSystem(_inst.getFile("BlockSize512.zvi")); - NPOIFSFileSystem fsB = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi")); - NPOIFSFileSystem fsC = new NPOIFSFileSystem(_inst.getFile("BlockSize4096.zvi")); - NPOIFSFileSystem fsD = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi")); - for(NPOIFSFileSystem fs : new NPOIFSFileSystem[] {fsA,fsB,fsC,fsD}) { + for(NPOIFSFileSystem fs : get512and4kFileAndInput()) { DirectoryEntry root = fs.getRoot(); assertEquals(5, root.getEntryCount()); @@ -568,11 +583,7 @@ public final class TestNPOIFSFileSystem { */ @Test public void getDocumentEntry() throws Exception { - NPOIFSFileSystem fsA = new NPOIFSFileSystem(_inst.getFile("BlockSize512.zvi")); - NPOIFSFileSystem fsB = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi")); - NPOIFSFileSystem fsC = new NPOIFSFileSystem(_inst.getFile("BlockSize4096.zvi")); - NPOIFSFileSystem fsD = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi")); - for(NPOIFSFileSystem fs : new NPOIFSFileSystem[] {fsA,fsB,fsC,fsD}) { + for(NPOIFSFileSystem fs : get512and4kFileAndInput()) { DirectoryEntry root = fs.getRoot(); Entry si = root.getEntry("\u0005SummaryInformation"); @@ -583,6 +594,7 @@ public final class TestNPOIFSFileSystem { NDocumentInputStream inp = new NDocumentInputStream(doc); byte[] contents = new byte[doc.getSize()]; assertEquals(doc.getSize(), inp.read(contents)); + inp.close(); // Now try to build the property set inp = new NDocumentInputStream(doc); @@ -605,8 +617,40 @@ public final class TestNPOIFSFileSystem { */ @Test public void readWriteRead() throws Exception { - // TODO - // TODO + for(NPOIFSFileSystem fs : get512and4kFileAndInput()) { + // Check we can find the entries we expect + // TODO Add check + + // Write out, re-load + // TODO Add check + + // Check they're still there + // TODO Add check + + // Check the first few and last few bytes of a few + // TODO Add check + + // Add a test mini stream + // TODO Add check + + // Write out, re-load + // TODO Add check + + // Check old and new are there + // TODO Add check + + // Add a full stream, delete a full stream + // TODO Add check + + // Write out, re-load + // TODO Add check + + // Check it's all there + // TODO Add check + + // All done + fs.close(); + } } /** @@ -667,5 +711,5 @@ public final class TestNPOIFSFileSystem { assertThat(wbDataExp, equalTo(wbDataAct)); } - // TODO Directory/Document write tests + // TODO Directory/Document create/write/read/delete/change tests } -- 2.39.5