More NPOIFS tests
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1054199 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2d583f4e3f
commit
bfd6fb0e2b
@ -484,7 +484,7 @@ public class NPOIFSFileSystem extends BlockStore
|
|||||||
// Oh joy, we need a new XBAT too...
|
// Oh joy, we need a new XBAT too...
|
||||||
xbat = createBAT(offset+1, false);
|
xbat = createBAT(offset+1, false);
|
||||||
xbat.setValueAt(0, offset);
|
xbat.setValueAt(0, offset);
|
||||||
bat.setValueAt(offset+1, POIFSConstants.DIFAT_SECTOR_BLOCK);
|
bat.setValueAt(1, POIFSConstants.DIFAT_SECTOR_BLOCK);
|
||||||
|
|
||||||
// Will go one place higher as XBAT added in
|
// Will go one place higher as XBAT added in
|
||||||
offset++;
|
offset++;
|
||||||
|
@ -348,6 +348,7 @@ public final class TestNPOIFSFileSystem extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testGetFreeBlockWithNoneSpare() throws Exception {
|
public void testGetFreeBlockWithNoneSpare() throws Exception {
|
||||||
NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
|
NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
|
||||||
|
int free;
|
||||||
|
|
||||||
// We have one BAT at block 99
|
// We have one BAT at block 99
|
||||||
assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99));
|
assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99));
|
||||||
@ -382,19 +383,67 @@ public final class TestNPOIFSFileSystem extends TestCase {
|
|||||||
|
|
||||||
|
|
||||||
// Fill up to hold 109 BAT blocks
|
// Fill up to hold 109 BAT blocks
|
||||||
// TODO
|
for(int i=0; i<109; i++) {
|
||||||
|
fs.getFreeBlock();
|
||||||
|
int startOffset = i*128;
|
||||||
|
while( fs.getBATBlockAndIndex(startOffset).getBlock().hasFreeSectors() ) {
|
||||||
|
free = fs.getFreeBlock();
|
||||||
|
fs.setNextBlock(free, POIFSConstants.END_OF_CHAIN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(false, fs.getBATBlockAndIndex(109*128-1).getBlock().hasFreeSectors());
|
||||||
|
try {
|
||||||
|
assertEquals(false, fs.getBATBlockAndIndex(109*128).getBlock().hasFreeSectors());
|
||||||
|
fail("Should only be 109 BATs");
|
||||||
|
} catch(IndexOutOfBoundsException e) {}
|
||||||
|
|
||||||
|
|
||||||
// Ask for another, will get our first XBAT
|
// Ask for another, will get our first XBAT
|
||||||
// TODO
|
free = fs.getFreeBlock();
|
||||||
|
assertEquals(false, fs.getBATBlockAndIndex(109*128-1).getBlock().hasFreeSectors());
|
||||||
|
assertEquals(true, fs.getBATBlockAndIndex(110*128-1).getBlock().hasFreeSectors());
|
||||||
|
try {
|
||||||
|
assertEquals(false, fs.getBATBlockAndIndex(110*128).getBlock().hasFreeSectors());
|
||||||
|
fail("Should only be 110 BATs");
|
||||||
|
} catch(IndexOutOfBoundsException e) {}
|
||||||
|
|
||||||
|
|
||||||
// Fill the XBAT
|
// Fill the XBAT, which means filling 127 BATs
|
||||||
// TODO
|
for(int i=109; i<109+127; i++) {
|
||||||
|
fs.getFreeBlock();
|
||||||
|
int startOffset = i*128;
|
||||||
|
while( fs.getBATBlockAndIndex(startOffset).getBlock().hasFreeSectors() ) {
|
||||||
|
free = fs.getFreeBlock();
|
||||||
|
fs.setNextBlock(free, POIFSConstants.END_OF_CHAIN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should now have 109+127 = 236 BATs
|
||||||
|
assertEquals(false, fs.getBATBlockAndIndex(236*128-1).getBlock().hasFreeSectors());
|
||||||
|
try {
|
||||||
|
assertEquals(false, fs.getBATBlockAndIndex(236*128).getBlock().hasFreeSectors());
|
||||||
|
fail("Should only be 236 BATs");
|
||||||
|
} catch(IndexOutOfBoundsException e) {}
|
||||||
|
|
||||||
|
|
||||||
// Ask for another, will get our 2nd XBAT
|
// Ask for another, will get our 2nd XBAT
|
||||||
// TODO
|
free = fs.getFreeBlock();
|
||||||
|
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) {}
|
||||||
|
|
||||||
|
|
||||||
// Write it out and read it back in again
|
// Write it out and read it back in again
|
||||||
// Ensure it's correct
|
// TODO
|
||||||
|
|
||||||
|
// Check the header is correct
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
// Now check the filesystem sees it correct too
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,5 +520,23 @@ public final class TestNPOIFSFileSystem extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read a file, write it and read it again.
|
||||||
|
* Then, alter+add some streams, write and read
|
||||||
|
*/
|
||||||
|
public void testReadWriteRead() throws Exception {
|
||||||
|
// TODO
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new file, write it and read it again
|
||||||
|
* Then, add some streams, write and read
|
||||||
|
*/
|
||||||
|
public void testCreateWriteRead() throws Exception {
|
||||||
|
// TODO
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
// TODO Directory/Document write tests
|
// TODO Directory/Document write tests
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user