You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2010/12/28 05:43:20 UTC
svn commit: r1053250 - in
/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem:
TestNPOIFSFileSystem.java TestNPOIFSStream.java
Author: nick
Date: Tue Dec 28 04:43:19 2010
New Revision: 1053250
URL: http://svn.apache.org/viewvc?rev=1053250&view=rev
Log:
More NPOIFSStream unit tests
Modified:
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSStream.java
Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java?rev=1053250&r1=1053249&r2=1053250&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java Tue Dec 28 04:43:19 2010
@@ -345,6 +345,9 @@ public final class TestNPOIFSFileSystem
*/
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++) {
Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSStream.java?rev=1053250&r1=1053249&r2=1053250&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSStream.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSStream.java Tue Dec 28 04:43:19 2010
@@ -510,9 +510,38 @@ public final class TestNPOIFSStream exte
* 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<data.length; i++) {
+ data[i] = (byte)(i%256);
+ }
+ NPOIFSStream stream = new NPOIFSStream(fs);
+ stream.updateContents(data);
+
+ // Check we got another BAT
+ assertEquals(false, fs.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
+ assertEquals(true, fs.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
+
+ // the BAT will be in the first spot of the new block
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(126));
+ assertEquals(129, fs.getNextBlock(127));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(128));
+ assertEquals(130, fs.getNextBlock(129));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(130));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(131));
}
/**
@@ -520,9 +549,52 @@ public final class TestNPOIFSStream exte
* more data than before, in a 4096 byte block file
*/
public void testWriteStream4096() throws Exception {
- NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
+ NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
- // TODO
+ // 0 -> 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<data.length; i++) {
+ data[i] = (byte)(i%256);
+ }
+ NPOIFSStream stream = new NPOIFSStream(fs, 0);
+ stream.updateContents(data);
+
+
+ // Check it
+ assertEquals(1, fs.getNextBlock(0));
+ assertEquals(2, fs.getNextBlock(1));
+ assertEquals(15, fs.getNextBlock(2)); // Jumps
+ assertEquals(4, fs.getNextBlock(3)); // Next stream
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(14));
+ assertEquals(16, fs.getNextBlock(15)); // Continues
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(16)); // Ends
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(17)); // Free
+
+ // Check the contents too
+ Iterator<ByteBuffer> 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<data.length; i++) {
+ byte exp = (byte)(i%256);
+ assertEquals(exp, data[i]);
+ }
+ count++;
+ }
+ assertEquals(5, count);
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org