From 6f3d7d99e595e5f5533ed57729437099a2c449ad Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 28 Dec 2010 04:43:19 +0000 Subject: [PATCH] More NPOIFSStream unit tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1053250 13f79535-47bb-0310-9956-ffa450edef68 --- .../filesystem/TestNPOIFSFileSystem.java | 3 + .../poifs/filesystem/TestNPOIFSStream.java | 80 ++++++++++++++++++- 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java index 19305fa05b..09e6dd78cf 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java @@ -345,6 +345,9 @@ public final class TestNPOIFSFileSystem extends TestCase { */ public void testGetFreeBlockWithNoneSpare() throws Exception { NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi")); + + // We have one BAT at block 99 + assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99)); // We've spare ones from 100 to 128 for(int i=100; i<128; i++) { diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSStream.java b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSStream.java index 8705e7ac37..c8b38d99b8 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSStream.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSStream.java @@ -510,9 +510,38 @@ public final class TestNPOIFSStream extends TestCase { * to support this */ public void testWriteNewStreamExtraFATs() throws Exception { - NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.getFile("BlockSize512.zvi")); + NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi")); - // TODO + // Allocate almost all the blocks + assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99)); + assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(100)); + assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(127)); + for(int i=100; i<127; i++) { + fs.setNextBlock(i, POIFSConstants.END_OF_CHAIN); + } + assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(127)); + assertEquals(true, fs.getBATBlockAndIndex(0).getBlock().hasFreeSectors()); + + + // Write a 3 block stream + byte[] data = new byte[512*3]; + for(int i=0; i 1 -> 2 -> end + assertEquals(1, fs.getNextBlock(0)); + assertEquals(2, fs.getNextBlock(1)); + assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2)); + assertEquals(4, fs.getNextBlock(3)); + + // First free one is at 15 + assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(14)); + assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(15)); + + + // Write a 5 block file + byte[] data = new byte[4096*5]; + for(int i=0; i it = stream.getBlockIterator(); + int count = 0; + while(it.hasNext()) { + ByteBuffer b = it.next(); + data = new byte[512]; + b.get(data); + for(int i=0; i