diff options
author | Nick Burch <nick@apache.org> | 2015-05-11 15:20:42 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2015-05-11 15:20:42 +0000 |
commit | de97868d2fc75855befb3653684dd1edfe02c82d (patch) | |
tree | 5dc56533afd3ccc7fa0b5d625e2154993ccdc045 /src/testcases/org | |
parent | 3e2fa9befaa8e4312abdef743cef9ece92ae8f9d (diff) | |
download | poi-de97868d2fc75855befb3653684dd1edfe02c82d.tar.gz poi-de97868d2fc75855befb3653684dd1edfe02c82d.zip |
More NPOIFS ministore tests
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1678767 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org')
-rw-r--r-- | src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSMiniStore.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSMiniStore.java b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSMiniStore.java index c875c52997..0445422907 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSMiniStore.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSMiniStore.java @@ -17,6 +17,7 @@ package org.apache.poi.poifs.filesystem; +import java.io.ByteArrayInputStream; import java.nio.ByteBuffer; import java.util.Iterator; @@ -332,4 +333,51 @@ public final class TestNPOIFSMiniStore extends TestCase { fs.close(); } + + public void testCreateMiniStoreFirst() throws Exception { + NPOIFSFileSystem fs = new NPOIFSFileSystem(); + NPOIFSMiniStore ministore = fs.getMiniStore(); + + // 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)); + // Ministore has no blocks, so can't iterate until used + try { + ministore.getNextBlock(0); + } catch (IndexOutOfBoundsException e) {} + + // Write a very small new document, will populate the ministore for us + byte[] data = new byte[8]; + for (int i=0; i<data.length; i++) { + data[i] = (byte)(i+42); + } + fs.getRoot().createDocument("mini", new ByteArrayInputStream(data)); + + // Should now have a mini-fat and a mini-stream + assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(0)); + assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(1)); + assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2)); + assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3)); + assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4)); + assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(0)); + assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(1)); + + // Re-fetch the mini store, and add it a second time + ministore = fs.getMiniStore(); + fs.getRoot().createDocument("mini2", new ByteArrayInputStream(data)); + + // Main unchanged, ministore has a second + assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(0)); + assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(1)); + assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2)); + assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3)); + assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4)); + assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(0)); + assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(1)); + assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(2)); + + // Done + fs.close(); + } } |