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 2011/01/01 07:49:54 UTC

svn commit: r1054199 - in /poi/trunk/src: java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java

Author: nick
Date: Sat Jan  1 06:49:53 2011
New Revision: 1054199

URL: http://svn.apache.org/viewvc?rev=1054199&view=rev
Log:
More NPOIFS tests

Modified:
    poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java
    poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java

Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java?rev=1054199&r1=1054198&r2=1054199&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java Sat Jan  1 06:49:53 2011
@@ -484,7 +484,7 @@ public class NPOIFSFileSystem extends Bl
              // Oh joy, we need a new XBAT too...
              xbat = createBAT(offset+1, false);
              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
              offset++;

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=1054199&r1=1054198&r2=1054199&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 Sat Jan  1 06:49:53 2011
@@ -348,6 +348,7 @@ public final class TestNPOIFSFileSystem 
     */
    public void testGetFreeBlockWithNoneSpare() throws Exception {
       NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
+      int free;
 
       // We have one BAT at block 99
       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(99));
@@ -382,19 +383,67 @@ public final class TestNPOIFSFileSystem 
       
       
       // 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
-      // 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
-      // TODO
+      // Fill the XBAT, which means filling 127 BATs
+      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
-      // 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
-      // Ensure it's correct
+      // TODO
+      
+      // Check the header is correct
+      // TODO
+      
+      // Now check the filesystem sees it correct too
       // TODO
    }
    
@@ -471,5 +520,23 @@ public final class TestNPOIFSFileSystem 
       }
    }
    
+   /**
+    * 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
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org