poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1053791 [15/18] - in /poi/branches/NIO_32_BRANCH: ./ src/contrib/src/org/apache/poi/contrib/poibrowser/ src/java/org/apache/poi/ src/java/org/apache/poi/hpsf/ src/java/org/apache/poi/hpsf/extractor/ src/java/org/apache/poi/hssf/record/ src...
Date Thu, 30 Dec 2010 02:35:11 GMT
Modified: poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestBlockAllocationTableWriter.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestBlockAllocationTableWriter.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestBlockAllocationTableWriter.java (original)
+++ poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestBlockAllocationTableWriter.java Thu Dec 30 02:35:06 2010
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,15 +14,14 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.poifs.storage;
 
-import java.io.*;
-
-import java.util.*;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
 
-import junit.framework.*;
+import junit.framework.TestCase;
 
 import org.apache.poi.poifs.common.POIFSConstants;
 import org.apache.poi.util.LittleEndian;
@@ -34,30 +32,11 @@ import org.apache.poi.util.LittleEndianC
  *
  * @author Marc Johnson
  */
+public final class TestBlockAllocationTableWriter extends TestCase {
 
-public class TestBlockAllocationTableWriter
-    extends TestCase
-{
-
-    /**
-     * Constructor TestBlockAllocationTableWriter
-     *
-     * @param name
-     */
-
-    public TestBlockAllocationTableWriter(String name)
-    {
-        super(name);
-    }
-
-    /**
-     * Test the allocateSpace method.
-     */
-
-    public void testAllocateSpace()
-    {
+    public void testAllocateSpace() {
         BlockAllocationTableWriter table         =
-            new BlockAllocationTableWriter();
+            new BlockAllocationTableWriter(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
         int[]                      blockSizes    =
         {
             0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
@@ -71,45 +50,37 @@ public class TestBlockAllocationTableWri
         }
     }
 
-    /**
-     * Test the createBlocks method
-     *
-     * @exception IOException
-     */
-
-    public void testCreateBlocks()
-        throws IOException
-    {
-        BlockAllocationTableWriter table = new BlockAllocationTableWriter();
+    public void testCreateBlocks() {
+        BlockAllocationTableWriter table = new BlockAllocationTableWriter(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
 
         table.allocateSpace(127);
         table.createBlocks();
         verifyBlocksCreated(table, 1);
-        table = new BlockAllocationTableWriter();
+        table = new BlockAllocationTableWriter(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
         table.allocateSpace(128);
         table.createBlocks();
         verifyBlocksCreated(table, 2);
-        table = new BlockAllocationTableWriter();
+        table = new BlockAllocationTableWriter(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
         table.allocateSpace(254);
         table.createBlocks();
         verifyBlocksCreated(table, 2);
-        table = new BlockAllocationTableWriter();
+        table = new BlockAllocationTableWriter(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
         table.allocateSpace(255);
         table.createBlocks();
         verifyBlocksCreated(table, 3);
-        table = new BlockAllocationTableWriter();
+        table = new BlockAllocationTableWriter(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
         table.allocateSpace(13843);
         table.createBlocks();
         verifyBlocksCreated(table, 109);
-        table = new BlockAllocationTableWriter();
+        table = new BlockAllocationTableWriter(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
         table.allocateSpace(13844);
         table.createBlocks();
         verifyBlocksCreated(table, 110);
-        table = new BlockAllocationTableWriter();
+        table = new BlockAllocationTableWriter(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
         table.allocateSpace(13969);
         table.createBlocks();
         verifyBlocksCreated(table, 110);
-        table = new BlockAllocationTableWriter();
+        table = new BlockAllocationTableWriter(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
         table.allocateSpace(13970);
         table.createBlocks();
         verifyBlocksCreated(table, 111);
@@ -117,14 +88,9 @@ public class TestBlockAllocationTableWri
 
     /**
      * Test content produced by BlockAllocationTableWriter
-     *
-     * @exception IOException
      */
-
-    public void testProduct()
-        throws IOException
-    {
-        BlockAllocationTableWriter table = new BlockAllocationTableWriter();
+    public void testProduct() throws IOException {
+        BlockAllocationTableWriter table = new BlockAllocationTableWriter(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
 
         for (int k = 1; k <= 22; k++)
         {
@@ -168,28 +134,16 @@ public class TestBlockAllocationTableWri
         }
     }
 
-    private void verifyBlocksCreated(BlockAllocationTableWriter table,
-                                     int count)
-        throws IOException
-    {
+    private static void verifyBlocksCreated(BlockAllocationTableWriter table, int count){
         ByteArrayOutputStream stream = new ByteArrayOutputStream();
 
-        table.writeBlocks(stream);
+        try {
+			table.writeBlocks(stream);
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
         byte[] output = stream.toByteArray();
 
         assertEquals(count * 512, output.length);
     }
-
-    /**
-     * main method to run the unit tests
-     *
-     * @param ignored_args
-     */
-
-    public static void main(String [] ignored_args)
-    {
-        System.out.println(
-            "Testing org.apache.poi.poifs.storage.BlockAllocationTableWriter");
-        junit.textui.TestRunner.run(TestBlockAllocationTableWriter.class);
-    }
 }

Modified: poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestBlockListImpl.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestBlockListImpl.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestBlockListImpl.java (original)
+++ poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestBlockListImpl.java Thu Dec 30 02:35:06 2010
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,16 +14,18 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.poifs.storage;
 
-import java.io.*;
-
-import java.util.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 
-import junit.framework.*;
+import junit.framework.TestCase;
 
+import org.apache.poi.poifs.common.POIFSConstants;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.LittleEndianConsts;
 
@@ -33,32 +34,18 @@ import org.apache.poi.util.LittleEndianC
  *
  * @author Marc Johnson
  */
-
-public class TestBlockListImpl
-    extends TestCase
-{
-
-    /**
-     * Constructor TestBlockListImpl
-     *
-     * @param name
-     */
-
-    public TestBlockListImpl(String name)
-    {
-        super(name);
+public final class TestBlockListImpl extends TestCase {
+    private static final class BlockListTestImpl extends BlockListImpl {
+        public BlockListTestImpl() {
+            // no extra initialisation
+        }
+    }
+    private static BlockListImpl create() {
+        return new BlockListTestImpl();
     }
 
-    /**
-     * test zap method
-     *
-     * @exception IOException
-     */
-
-    public void testZap()
-        throws IOException
-    {
-        BlockListImpl list = new BlockListImpl();
+    public void testZap() throws IOException {
+        BlockListImpl list = create();
 
         // verify that you can zap anything
         for (int j = -2; j < 10; j++)
@@ -92,16 +79,9 @@ public class TestBlockListImpl
         }
     }
 
-    /**
-     * test remove method
-     *
-     * @exception IOException
-     */
-
-    public void testRemove()
-        throws IOException
-    {
-        BlockListImpl  list   = new BlockListImpl();
+
+    public void testRemove() throws IOException {
+        BlockListImpl  list   = create();
         RawDataBlock[] blocks = new RawDataBlock[ 5 ];
         byte[]         data   = new byte[ 512 * 5 ];
 
@@ -159,22 +139,14 @@ public class TestBlockListImpl
         }
     }
 
-    /**
-     * test setBAT
-     *
-     * @exception IOException
-     */
-
-    public void testSetBAT()
-        throws IOException
-    {
-        BlockListImpl list = new BlockListImpl();
+    public void testSetBAT() throws IOException {
+        BlockListImpl list = create();
 
         list.setBAT(null);
-        list.setBAT(new BlockAllocationTableReader());
+        list.setBAT(new BlockAllocationTableReader(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS));
         try
         {
-            list.setBAT(new BlockAllocationTableReader());
+            list.setBAT(new BlockAllocationTableReader(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS));
             fail("second attempt should have failed");
         }
         catch (IOException ignored)
@@ -182,18 +154,10 @@ public class TestBlockListImpl
         }
     }
 
-    /**
-     * Test fetchBlocks
-     *
-     * @exception IOException
-     */
-
-    public void testFetchBlocks()
-        throws IOException
-    {
+    public void testFetchBlocks() throws IOException {
 
         // strategy:
-        // 
+        //
         // 1. set up a single BAT block from which to construct a
         // BAT. create nonsense blocks in the raw data block list
         // corresponding to the indices in the BAT block.
@@ -204,7 +168,7 @@ public class TestBlockListImpl
         // document, one that includes a reserved (BAT) block, one
         // that includes a reserved (XBAT) block, and one that
         // points off into space somewhere
-        BlockListImpl list       = new BlockListImpl();
+        BlockListImpl list       = create();
         List          raw_blocks = new ArrayList();
         byte[]        data       = new byte[ 512 ];
         int           offset     = 0;
@@ -270,7 +234,7 @@ public class TestBlockListImpl
             0
         };
         BlockAllocationTableReader table           =
-            new BlockAllocationTableReader(1, blocks, 0, -2, list);
+            new BlockAllocationTableReader(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, 1, blocks, 0, -2, list);
         int[]                      start_blocks    =
         {
             -2, 1, 2, 3, 5, 7, 9, 11, 12
@@ -285,7 +249,7 @@ public class TestBlockListImpl
             try
             {
                 ListManagedBlock[] dataBlocks =
-                    list.fetchBlocks(start_blocks[ j ]);
+                    list.fetchBlocks(start_blocks[ j ], -1);
 
                 if (expected_length[ j ] == -1)
                 {
@@ -310,17 +274,4 @@ public class TestBlockListImpl
             }
         }
     }
-
-    /**
-     * main method to run the unit tests
-     *
-     * @param ignored_args
-     */
-
-    public static void main(String [] ignored_args)
-    {
-        System.out
-            .println("Testing org.apache.poi.poifs.storage.BlockListImpl");
-        junit.textui.TestRunner.run(TestBlockListImpl.class);
-    }
 }

Modified: poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestDocumentBlock.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestDocumentBlock.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestDocumentBlock.java (original)
+++ poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestDocumentBlock.java Thu Dec 30 02:35:06 2010
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,25 +14,23 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.poifs.storage;
 
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 
-import java.util.*;
+import org.apache.poi.poifs.common.POIFSConstants;
 
-import junit.framework.*;
+import junit.framework.TestCase;
 
 /**
  * Class to test DocumentBlock functionality
  *
  * @author Marc Johnson
  */
-
-public class TestDocumentBlock
-    extends TestCase
-{
+public final class TestDocumentBlock extends TestCase {
     static final private byte[] _testdata;
 
     static
@@ -44,25 +41,10 @@ public class TestDocumentBlock
             _testdata[ j ] = ( byte ) j;
         }
     }
-    ;
-
-    /**
-     * Constructor TestDocumentBlock
-     *
-     * @param name
-     */
-
-    public TestDocumentBlock(String name)
-    {
-        super(name);
-    }
 
     /**
      * Test the writing DocumentBlock constructor.
-     *
-     * @exception IOException
      */
-
     public void testConstructor()
         throws IOException
     {
@@ -75,7 +57,7 @@ public class TestDocumentBlock
             byte[] data = new byte[ Math.min(_testdata.length - index, 512) ];
 
             System.arraycopy(_testdata, index, data, 0, data.length);
-            DocumentBlock block = new DocumentBlock(input);
+            DocumentBlock block = new DocumentBlock(input, POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
 
             verifyOutput(block, data);
             size += block.size();
@@ -88,46 +70,10 @@ public class TestDocumentBlock
         assertEquals(_testdata.length, size);
     }
 
-    /**
-     * test static read method
-     *
-     * @exception IOException
-     */
-
-    public void testRead()
-        throws IOException
-    {
-        DocumentBlock[]      blocks = new DocumentBlock[ 4 ];
-        ByteArrayInputStream input  = new ByteArrayInputStream(_testdata);
-
-        for (int j = 0; j < 4; j++)
-        {
-            blocks[ j ] = new DocumentBlock(input);
-        }
-        for (int j = 1; j <= 2000; j += 17)
-        {
-            byte[] buffer = new byte[ j ];
-            int    offset = 0;
-
-            for (int k = 0; k < (2000 / j); k++)
-            {
-                DocumentBlock.read(blocks, buffer, offset);
-                for (int n = 0; n < buffer.length; n++)
-                {
-                    assertEquals("checking byte " + (k * j) + n,
-                                 _testdata[ (k * j) + n ], buffer[ n ]);
-                }
-                offset += j;
-            }
-        }
-    }
 
     /**
      * Test 'reading' constructor
-     *
-     * @exception IOException
      */
-
     public void testReadingConstructor()
         throws IOException
     {
@@ -164,17 +110,4 @@ public class TestDocumentBlock
             assertEquals(( byte ) 0xFF, copy[ j ]);
         }
     }
-
-    /**
-     * main method to run the unit tests
-     *
-     * @param ignored_args
-     */
-
-    public static void main(String [] ignored_args)
-    {
-        System.out
-            .println("Testing org.apache.poi.poifs.storage.DocumentBlock");
-        junit.textui.TestRunner.run(TestDocumentBlock.class);
-    }
 }

Added: poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockReading.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockReading.java?rev=1053791&view=auto
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockReading.java (added)
+++ poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockReading.java Thu Dec 30 02:35:06 2010
@@ -0,0 +1,83 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.poifs.storage;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+/**
+ * Class to test HeaderBlockReader functionality
+ *
+ * @author Marc Johnson
+ */
+public final class TestHeaderBlockReading extends TestCase {
+
+	public void testConstructors() throws IOException {
+		String[] hexData = {
+			"D0 CF 11 E0 A1 B1 1A E1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3B 00 03 00 FE FF 09 00",
+			"06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FE FF FF FF 00 00 00 00 00 10 00 00 FE FF FF FF",
+			"01 00 00 00 FE FF FF FF 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+		};
+		byte[] content = RawDataUtil.decode(hexData);
+		HeaderBlock block = new HeaderBlock(new ByteArrayInputStream(content));
+
+		assertEquals(-2, block.getPropertyStart());
+
+		// verify we can't read a short block
+		byte[] shortblock = new byte[511];
+
+		System.arraycopy(content, 0, shortblock, 0, 511);
+		try {
+			block = new HeaderBlock(new ByteArrayInputStream(shortblock));
+			fail("Should have caught IOException reading a short block");
+		} catch (IOException ignored) {
+
+			// as expected
+		}
+
+		// try various forms of corruption
+		for (int index = 0; index < 8; index++) {
+			content[index] = (byte) (content[index] - 1);
+			try {
+				block = new HeaderBlock(new ByteArrayInputStream(content));
+				fail("Should have caught IOException corrupting byte " + index);
+			} catch (IOException ignored) {
+
+				// as expected
+			}
+
+			// restore byte value
+			content[index] = (byte) (content[index] + 1);
+		}
+	}
+}

Added: poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockWriting.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockWriting.java?rev=1053791&view=auto
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockWriting.java (added)
+++ poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockWriting.java Thu Dec 30 02:35:06 2010
@@ -0,0 +1,270 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.poifs.storage;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.poifs.common.POIFSConstants;
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianConsts;
+
+/**
+ * Class to test HeaderBlockWriter functionality
+ *
+ * @author Marc Johnson
+ */
+public final class TestHeaderBlockWriting extends TestCase {
+
+	private static void confirmEqual(String[] expectedDataHexDumpLines, byte[] actual) {
+		byte[] expected = RawDataUtil.decode(expectedDataHexDumpLines);
+
+		assertEquals(expected.length, actual.length);
+		for (int j = 0; j < expected.length; j++) {
+			assertEquals("testing byte " + j, expected[j], actual[j]);
+		}
+	}
+
+	/**
+	 * Test creating a HeaderBlockWriter
+	 */
+	public void testConstructors() throws IOException {
+		HeaderBlockWriter block = new HeaderBlockWriter(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
+		ByteArrayOutputStream output = new ByteArrayOutputStream(512);
+
+		block.writeBlocks(output);
+		byte[] copy = output.toByteArray();
+		String[] expected = {
+			"D0 CF 11 E0 A1 B1 1A E1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3B 00 03 00 FE FF 09 00",
+			"06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FE FF FF FF 00 00 00 00 00 10 00 00 FE FF FF FF",
+			"00 00 00 00 FE FF FF FF 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+		};
+
+		confirmEqual(expected, copy);
+
+		// verify we can read a 'good' HeaderBlockWriter (also test
+		// getPropertyStart)
+		block.setPropertyStart(0x87654321);
+		output = new ByteArrayOutputStream(512);
+		block.writeBlocks(output);
+		assertEquals(0x87654321, new HeaderBlock(
+		      new ByteArrayInputStream(output.toByteArray())).getPropertyStart());
+	}
+
+	/**
+	 * Test setting the SBAT start block
+	 */
+	public void testSetSBATStart() throws IOException {
+	   HeaderBlockWriter block = new HeaderBlockWriter(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
+
+		block.setSBATStart(0x01234567);
+		ByteArrayOutputStream output = new ByteArrayOutputStream(512);
+
+		block.writeBlocks(output);
+		byte[] copy = output.toByteArray();
+		String[] expected = {
+			"D0 CF 11 E0 A1 B1 1A E1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3B 00 03 00 FE FF 09 00",
+			"06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FE FF FF FF 00 00 00 00 00 10 00 00 67 45 23 01",
+			"00 00 00 00 FE FF FF FF 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+		};
+		confirmEqual(expected, copy);
+	}
+
+	/**
+	 * test setPropertyStart and getPropertyStart
+	 */
+	public void testSetPropertyStart() throws IOException {
+	   HeaderBlockWriter block = new HeaderBlockWriter(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
+
+		block.setPropertyStart(0x01234567);
+		ByteArrayOutputStream output = new ByteArrayOutputStream(512);
+
+		block.writeBlocks(output);
+		byte[] copy = output.toByteArray();
+		String[] expected = {
+			"D0 CF 11 E0 A1 B1 1A E1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3B 00 03 00 FE FF 09 00",
+			"06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 67 45 23 01 00 00 00 00 00 10 00 00 FE FF FF FF",
+			"00 00 00 00 FE FF FF FF 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+		};
+		confirmEqual(expected, copy);
+	}
+
+	/**
+	 * test setting the BAT blocks; also tests getBATCount, getBATArray,
+	 * getXBATCount
+	 */
+	public void testSetBATBlocks() throws IOException {
+
+		// first, a small set of blocks
+	   HeaderBlockWriter block = new HeaderBlockWriter(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
+		BATBlock[] xbats = block.setBATBlocks(5, 0x01234567);
+
+		assertEquals(0, xbats.length);
+		assertEquals(0, HeaderBlockWriter.calculateXBATStorageRequirements(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,5));
+		ByteArrayOutputStream output = new ByteArrayOutputStream(512);
+
+		block.writeBlocks(output);
+		byte[] copy = output.toByteArray();
+		String[] expected = {
+			"D0 CF 11 E0 A1 B1 1A E1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3B 00 03 00 FE FF 09 00",
+			"06 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 FE FF FF FF 00 00 00 00 00 10 00 00 FE FF FF FF",
+			"00 00 00 00 FE FF FF FF 00 00 00 00 67 45 23 01 68 45 23 01 69 45 23 01 6A 45 23 01 6B 45 23 01",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+			"FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF",
+		};
+
+		confirmEqual(expected, copy);
+
+		// second, a full set of blocks (109 blocks)
+		block = new HeaderBlockWriter(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
+		xbats = block.setBATBlocks(109, 0x01234567);
+		assertEquals(0, xbats.length);
+		assertEquals(0, HeaderBlockWriter.calculateXBATStorageRequirements(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,109));
+		output = new ByteArrayOutputStream(512);
+		block.writeBlocks(output);
+		copy = output.toByteArray();
+		String[] expected2 = {
+			"D0 CF 11 E0 A1 B1 1A E1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3B 00 03 00 FE FF 09 00",
+			"06 00 00 00 00 00 00 00 00 00 00 00 6D 00 00 00 FE FF FF FF 00 00 00 00 00 10 00 00 FE FF FF FF",
+			"00 00 00 00 FE FF FF FF 00 00 00 00 67 45 23 01 68 45 23 01 69 45 23 01 6A 45 23 01 6B 45 23 01",
+			"6C 45 23 01 6D 45 23 01 6E 45 23 01 6F 45 23 01 70 45 23 01 71 45 23 01 72 45 23 01 73 45 23 01",
+			"74 45 23 01 75 45 23 01 76 45 23 01 77 45 23 01 78 45 23 01 79 45 23 01 7A 45 23 01 7B 45 23 01",
+			"7C 45 23 01 7D 45 23 01 7E 45 23 01 7F 45 23 01 80 45 23 01 81 45 23 01 82 45 23 01 83 45 23 01",
+			"84 45 23 01 85 45 23 01 86 45 23 01 87 45 23 01 88 45 23 01 89 45 23 01 8A 45 23 01 8B 45 23 01",
+			"8C 45 23 01 8D 45 23 01 8E 45 23 01 8F 45 23 01 90 45 23 01 91 45 23 01 92 45 23 01 93 45 23 01",
+			"94 45 23 01 95 45 23 01 96 45 23 01 97 45 23 01 98 45 23 01 99 45 23 01 9A 45 23 01 9B 45 23 01",
+			"9C 45 23 01 9D 45 23 01 9E 45 23 01 9F 45 23 01 A0 45 23 01 A1 45 23 01 A2 45 23 01 A3 45 23 01",
+			"A4 45 23 01 A5 45 23 01 A6 45 23 01 A7 45 23 01 A8 45 23 01 A9 45 23 01 AA 45 23 01 AB 45 23 01",
+			"AC 45 23 01 AD 45 23 01 AE 45 23 01 AF 45 23 01 B0 45 23 01 B1 45 23 01 B2 45 23 01 B3 45 23 01",
+			"B4 45 23 01 B5 45 23 01 B6 45 23 01 B7 45 23 01 B8 45 23 01 B9 45 23 01 BA 45 23 01 BB 45 23 01",
+			"BC 45 23 01 BD 45 23 01 BE 45 23 01 BF 45 23 01 C0 45 23 01 C1 45 23 01 C2 45 23 01 C3 45 23 01",
+			"C4 45 23 01 C5 45 23 01 C6 45 23 01 C7 45 23 01 C8 45 23 01 C9 45 23 01 CA 45 23 01 CB 45 23 01",
+			"CC 45 23 01 CD 45 23 01 CE 45 23 01 CF 45 23 01 D0 45 23 01 D1 45 23 01 D2 45 23 01 D3 45 23 01",
+		};
+		confirmEqual(expected2, copy);
+
+		// finally, a really large set of blocks (256 blocks)
+		block = new HeaderBlockWriter(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
+		xbats = block.setBATBlocks(256, 0x01234567);
+		assertEquals(2, xbats.length);
+		assertEquals(2, HeaderBlockWriter.calculateXBATStorageRequirements(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,256));
+		output = new ByteArrayOutputStream(512);
+		block.writeBlocks(output);
+		copy = output.toByteArray();
+		String[] expected3 = {
+			"D0 CF 11 E0 A1 B1 1A E1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3B 00 03 00 FE FF 09 00",
+			"06 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 FE FF FF FF 00 00 00 00 00 10 00 00 FE FF FF FF",
+			"00 00 00 00 67 46 23 01 02 00 00 00 67 45 23 01 68 45 23 01 69 45 23 01 6A 45 23 01 6B 45 23 01",
+			"6C 45 23 01 6D 45 23 01 6E 45 23 01 6F 45 23 01 70 45 23 01 71 45 23 01 72 45 23 01 73 45 23 01",
+			"74 45 23 01 75 45 23 01 76 45 23 01 77 45 23 01 78 45 23 01 79 45 23 01 7A 45 23 01 7B 45 23 01",
+			"7C 45 23 01 7D 45 23 01 7E 45 23 01 7F 45 23 01 80 45 23 01 81 45 23 01 82 45 23 01 83 45 23 01",
+			"84 45 23 01 85 45 23 01 86 45 23 01 87 45 23 01 88 45 23 01 89 45 23 01 8A 45 23 01 8B 45 23 01",
+			"8C 45 23 01 8D 45 23 01 8E 45 23 01 8F 45 23 01 90 45 23 01 91 45 23 01 92 45 23 01 93 45 23 01",
+			"94 45 23 01 95 45 23 01 96 45 23 01 97 45 23 01 98 45 23 01 99 45 23 01 9A 45 23 01 9B 45 23 01",
+			"9C 45 23 01 9D 45 23 01 9E 45 23 01 9F 45 23 01 A0 45 23 01 A1 45 23 01 A2 45 23 01 A3 45 23 01",
+			"A4 45 23 01 A5 45 23 01 A6 45 23 01 A7 45 23 01 A8 45 23 01 A9 45 23 01 AA 45 23 01 AB 45 23 01",
+			"AC 45 23 01 AD 45 23 01 AE 45 23 01 AF 45 23 01 B0 45 23 01 B1 45 23 01 B2 45 23 01 B3 45 23 01",
+			"B4 45 23 01 B5 45 23 01 B6 45 23 01 B7 45 23 01 B8 45 23 01 B9 45 23 01 BA 45 23 01 BB 45 23 01",
+			"BC 45 23 01 BD 45 23 01 BE 45 23 01 BF 45 23 01 C0 45 23 01 C1 45 23 01 C2 45 23 01 C3 45 23 01",
+			"C4 45 23 01 C5 45 23 01 C6 45 23 01 C7 45 23 01 C8 45 23 01 C9 45 23 01 CA 45 23 01 CB 45 23 01",
+			"CC 45 23 01 CD 45 23 01 CE 45 23 01 CF 45 23 01 D0 45 23 01 D1 45 23 01 D2 45 23 01 D3 45 23 01",
+		};
+
+		confirmEqual(expected3, copy);
+
+		output = new ByteArrayOutputStream(1028);
+		xbats[0].writeBlocks(output);
+		xbats[1].writeBlocks(output);
+		copy = output.toByteArray();
+		int correct = 0x012345D4;
+		int offset = 0;
+		int k = 0;
+
+		for (; k < 127; k++) {
+			assertEquals("XBAT entry " + k, correct, LittleEndian.getInt(copy, offset));
+			correct++;
+			offset += LittleEndianConsts.INT_SIZE;
+		}
+		assertEquals("XBAT Chain", 0x01234567 + 257, LittleEndian.getInt(copy, offset));
+		offset += LittleEndianConsts.INT_SIZE;
+		k++;
+		for (; k < 148; k++) {
+			assertEquals("XBAT entry " + k, correct, LittleEndian.getInt(copy, offset));
+			correct++;
+			offset += LittleEndianConsts.INT_SIZE;
+		}
+		for (; k < 255; k++) {
+			assertEquals("XBAT entry " + k, -1, LittleEndian.getInt(copy, offset));
+			offset += LittleEndianConsts.INT_SIZE;
+		}
+		assertEquals("XBAT End of chain", -2, LittleEndian.getInt(copy, offset));
+	}
+}

Modified: poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestPropertyBlock.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestPropertyBlock.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestPropertyBlock.java (original)
+++ poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestPropertyBlock.java Thu Dec 30 02:35:06 2010
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,59 +14,37 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.poifs.storage;
 
-import java.io.*;
-
-import java.util.*;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
-import junit.framework.*;
+import org.apache.poi.poifs.common.POIFSConstants;
 
-import org.apache.poi.poifs.property.Property;
+import junit.framework.TestCase;
 
 /**
  * Class to test PropertyBlock functionality
  *
  * @author Marc Johnson
  */
+public final class TestPropertyBlock extends TestCase {
 
-public class TestPropertyBlock
-    extends TestCase
-{
-
-    /**
-     * Constructor TestPropertyBlock
-     *
-     * @param name
-     */
-
-    public TestPropertyBlock(String name)
-    {
-        super(name);
-    }
-
-    /**
-     * Test constructing PropertyBlocks
-     *
-     * @exception IOException
-     */
-
-    public void testCreatePropertyBlocks()
-        throws IOException
-    {
+    public void testCreatePropertyBlocks() {
 
         // test with 0 properties
         List            properties = new ArrayList();
         BlockWritable[] blocks     =
-            PropertyBlock.createPropertyBlockArray(properties);
+            PropertyBlock.createPropertyBlockArray(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,properties);
 
         assertEquals(0, blocks.length);
 
         // test with 1 property
         properties.add(new LocalProperty("Root Entry"));
-        blocks = PropertyBlock.createPropertyBlockArray(properties);
+        blocks = PropertyBlock.createPropertyBlockArray(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,properties);
         assertEquals(1, blocks.length);
         byte[] testblock = new byte[ 512 ];
 
@@ -91,7 +68,7 @@ public class TestPropertyBlock
         // test with 3 properties
         properties.add(new LocalProperty("workbook"));
         properties.add(new LocalProperty("summary"));
-        blocks = PropertyBlock.createPropertyBlockArray(properties);
+        blocks = PropertyBlock.createPropertyBlockArray(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,properties);
         assertEquals(1, blocks.length);
         testblock[ 0x0080 ] = ( byte ) 'w';
         testblock[ 0x0082 ] = ( byte ) 'o';
@@ -114,7 +91,7 @@ public class TestPropertyBlock
 
         // test with 4 properties
         properties.add(new LocalProperty("wintery"));
-        blocks = PropertyBlock.createPropertyBlockArray(properties);
+        blocks = PropertyBlock.createPropertyBlockArray(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,properties);
         assertEquals(1, blocks.length);
         testblock[ 0x0180 ] = ( byte ) 'w';
         testblock[ 0x0182 ] = ( byte ) 'i';
@@ -128,7 +105,7 @@ public class TestPropertyBlock
 
         // test with 5 properties
         properties.add(new LocalProperty("foo"));
-        blocks = PropertyBlock.createPropertyBlockArray(properties);
+        blocks = PropertyBlock.createPropertyBlockArray(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,properties);
         assertEquals(2, blocks.length);
         testblock = new byte[ 1024 ];
         for (int j = 0; j < 8; j++)
@@ -178,7 +155,7 @@ public class TestPropertyBlock
         verifyCorrect(blocks, testblock);
     }
 
-    private void setDefaultBlock(byte [] testblock, int j)
+    private static void setDefaultBlock(byte [] testblock, int j)
     {
         int base  = j * 128;
         int index = 0;
@@ -204,15 +181,16 @@ public class TestPropertyBlock
         }
     }
 
-    private void verifyCorrect(BlockWritable [] blocks, byte [] testblock)
-        throws IOException
-    {
+    private static void verifyCorrect(BlockWritable[] blocks, byte[] testblock) {
         ByteArrayOutputStream stream = new ByteArrayOutputStream(512
                                            * blocks.length);
 
-        for (int j = 0; j < blocks.length; j++)
-        {
-            blocks[ j ].writeBlocks(stream);
+        for (int j = 0; j < blocks.length; j++) {
+            try {
+				blocks[ j ].writeBlocks(stream);
+			} catch (IOException e) {
+				throw new RuntimeException(e);
+			}
         }
         byte[] output = stream.toByteArray();
 
@@ -223,17 +201,4 @@ public class TestPropertyBlock
                          output[ j ]);
         }
     }
-
-    /**
-     * main method to run the unit tests
-     *
-     * @param ignored_args
-     */
-
-    public static void main(String [] ignored_args)
-    {
-        System.out
-            .println("Testing org.apache.poi.poifs.storage.PropertyBlock");
-        junit.textui.TestRunner.run(TestPropertyBlock.class);
-    }
 }

Modified: poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java (original)
+++ poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java Thu Dec 30 02:35:06 2010
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,233 +14,212 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.poifs.storage;
 
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Field;
 import java.util.Random;
 
-import org.apache.poi.util.DummyPOILogger;
-import org.apache.poi.util.POILogFactory;
+import junit.framework.TestCase;
 
-import junit.framework.*;
+import org.apache.poi.util.DummyPOILogger;
 
 /**
  * Class to test RawDataBlock functionality
  *
  * @author Marc Johnson
  */
-
-public class TestRawDataBlock
-    extends TestCase
-{
+public final class TestRawDataBlock extends TestCase {
 	static {
-        // We always want to use our own
-        //  logger
-        System.setProperty(
-        		"org.apache.poi.util.POILogger",
-        		"org.apache.poi.util.DummyPOILogger"
-        );
+		// We always want to use our own
+		//  logger
+		System.setProperty(
+				"org.apache.poi.util.POILogger",
+				"org.apache.poi.util.DummyPOILogger"
+		);
+	}
+
+	/**
+	 * Test creating a normal RawDataBlock
+	 */
+	public void testNormalConstructor() throws IOException {
+		byte[] data = new byte[ 512 ];
+
+		for (int j = 0; j < 512; j++)
+		{
+			data[ j ] = ( byte ) j;
+		}
+		RawDataBlock block = new RawDataBlock(new ByteArrayInputStream(data));
+
+		assertTrue("Should not be at EOF", !block.eof());
+		byte[] out_data = block.getData();
+
+		assertEquals("Should be same length", data.length, out_data.length);
+		for (int j = 0; j < 512; j++)
+		{
+			assertEquals("Should be same value at offset " + j, data[ j ],
+						 out_data[ j ]);
+		}
+	}
+
+	/**
+	 * Test creating an empty RawDataBlock
+	 */
+	public void testEmptyConstructor() throws IOException {
+		byte[]	   data  = new byte[ 0 ];
+		RawDataBlock block = new RawDataBlock(new ByteArrayInputStream(data));
+
+		assertTrue("Should be at EOF", block.eof());
+		try
+		{
+			block.getData();
+		}
+		catch (IOException ignored)
+		{
+
+			// as expected
+		}
+	}
+
+	/**
+	 * Test creating a short RawDataBlock
+	 * Will trigger a warning, but no longer an IOException,
+	 *  as people seem to have "valid" truncated files
+	 */
+	public void testShortConstructor() throws Exception {
+		// Get the logger to be used
+		DummyPOILogger logger = new DummyPOILogger();
+		Field fld = RawDataBlock.class.getDeclaredField("log");
+		fld.setAccessible(true);
+		fld.set(null, logger);
+		assertEquals(0, logger.logged.size());
+
+		// Test for various data sizes
+		for (int k = 1; k <= 512; k++)
+		{
+			byte[] data = new byte[ k ];
+
+			for (int j = 0; j < k; j++)
+			{
+				data[ j ] = ( byte ) j;
+			}
+			RawDataBlock block = null;
+
+			logger.reset();
+			assertEquals(0, logger.logged.size());
+
+			// Have it created
+			block = new RawDataBlock(new ByteArrayInputStream(data));
+			assertNotNull(block);
+
+			// Check for the warning is there for <512
+			if(k < 512) {
+				assertEquals(
+						"Warning on " + k + " byte short block",
+						1, logger.logged.size()
+				);
+
+				// Build the expected warning message, and check
+				String bts = k + " byte";
+				if(k > 1) {
+					bts += "s";
+				}
+
+				assertEquals(
+						"7 - Unable to read entire block; "+bts+" read before EOF; expected 512 bytes. Your document was either written by software that ignores the spec, or has been truncated!",
+						(String)(logger.logged.get(0))
+				);
+			} else {
+				assertEquals(0, logger.logged.size());
+			}
+		}
 	}
 
-    /**
-     * Constructor TestRawDataBlock
-     *
-     * @param name
-     */
-    public TestRawDataBlock(String name)
-    {
-        super(name);
-    }
-
-    /**
-     * Test creating a normal RawDataBlock
-     *
-     * @exception IOException
-     */
-
-    public void testNormalConstructor()
-        throws IOException
-    {
-        byte[] data = new byte[ 512 ];
-
-        for (int j = 0; j < 512; j++)
-        {
-            data[ j ] = ( byte ) j;
-        }
-        RawDataBlock block = new RawDataBlock(new ByteArrayInputStream(data));
-
-        assertTrue("Should not be at EOF", !block.eof());
-        byte[] out_data = block.getData();
-
-        assertEquals("Should be same length", data.length, out_data.length);
-        for (int j = 0; j < 512; j++)
-        {
-            assertEquals("Should be same value at offset " + j, data[ j ],
-                         out_data[ j ]);
-        }
-    }
-
-    /**
-     * Test creating an empty RawDataBlock
-     *
-     * @exception IOException
-     */
-
-    public void testEmptyConstructor()
-        throws IOException
-    {
-        byte[]       data  = new byte[ 0 ];
-        RawDataBlock block = new RawDataBlock(new ByteArrayInputStream(data));
-
-        assertTrue("Should be at EOF", block.eof());
-        try
-        {
-            block.getData();
-        }
-        catch (IOException ignored)
-        {
-
-            // as expected
-        }
-    }
-
-    /**
-     * Test creating a short RawDataBlock
-     * Will trigger a warning, but no longer an IOException,
-     *  as people seem to have "valid" truncated files
-     */
-    public void testShortConstructor() throws Exception
-    {
-        // Get the logger to be used
-        DummyPOILogger logger = (DummyPOILogger)POILogFactory.getLogger(
-        		RawDataBlock.class
-        );
-        assertEquals(0, logger.logged.size());
-        
-        // Test for various data sizes
-        for (int k = 1; k <= 512; k++)
-        {
-            byte[] data = new byte[ k ];
-
-            for (int j = 0; j < k; j++)
-            {
-                data[ j ] = ( byte ) j;
-            }
-            RawDataBlock block = null;
-            
-            logger.reset();
-            assertEquals(0, logger.logged.size());
-            
-            // Have it created
-            block = new RawDataBlock(new ByteArrayInputStream(data));
-            assertNotNull(block);
-            
-            // Check for the warning is there for <512
-            if(k < 512) {
-	            assertEquals(
-	            		"Warning on " + k + " byte short block",
-	            		1, logger.logged.size()
-	            );
-	
-	            // Build the expected warning message, and check
-	            String bts = k + " byte";
-	            if(k > 1) {
-	            	bts += "s";
-	            }
-	            
-	            assertEquals(
-	            		"7 - Unable to read entire block; "+bts+" read before EOF; expected 512 bytes. Your document was either written by software that ignores the spec, or has been truncated!", 
-	            		(String)(logger.logged.get(0))
-	            );
-            } else {
-            	assertEquals(0, logger.logged.size());
-            }
-        }
-    }
-    
-    /**
-     * Tests that when using a slow input stream, which
-     *  won't return a full block at a time, we don't
-     *  incorrectly think that there's not enough data
-     */
-    public void testSlowInputStream() throws Exception {
-        // Get the logger to be used
-        DummyPOILogger logger = (DummyPOILogger)POILogFactory.getLogger(
-        		RawDataBlock.class
-        );
-        assertEquals(0, logger.logged.size());
-        
-        // Test for various ok data sizes
-        for (int k = 1; k < 512; k++) {
-            byte[] data = new byte[ 512 ];
-            for (int j = 0; j < data.length; j++) {
-                data[j] = (byte) j;
-            }
-            
-            // Shouldn't complain, as there is enough data,
-            //  even if it dribbles through
-            RawDataBlock block = 
-            	new RawDataBlock(new SlowInputStream(data, k));
-            assertFalse(block.eof());
-        }
-        
-        // But if there wasn't enough data available, will
-        //  complain
-        for (int k = 1; k < 512; k++) {
-            byte[] data = new byte[ 511 ];
-            for (int j = 0; j < data.length; j++) {
-                data[j] = (byte) j;
-            }
-            
-            logger.reset();
-            assertEquals(0, logger.logged.size());
-            
-            // Should complain, as there isn't enough data
-            RawDataBlock block = 
-            	new RawDataBlock(new SlowInputStream(data, k));
-            assertNotNull(block);
-            assertEquals(
-            		"Warning on " + k + " byte short block",
-            		1, logger.logged.size()
-            );
-        }
-    }
-    
-    /**
-     * An input stream which will return a maximum of
-     *  a given number of bytes to read, and often claims
-     *  not to have any data
-     */
-    public static class SlowInputStream extends InputStream {
-    	private Random rnd = new Random();
-    	private byte[] data;
-    	private int chunkSize;
-    	private int pos = 0;
-    	
-    	public SlowInputStream(byte[] data, int chunkSize) {
-    		this.chunkSize = chunkSize;
-    		this.data = data;
-    	}
-    	
-    	/**
-    	 * 75% of the time, claim there's no data available
-    	 */
-    	private boolean claimNoData() {
-    		if(rnd.nextFloat() < 0.25f) {
-    			return false;
-    		}
-    		return true;
-    	}
-    	
-		public int read() throws IOException {
+	/**
+	 * Tests that when using a slow input stream, which
+	 *  won't return a full block at a time, we don't
+	 *  incorrectly think that there's not enough data
+	 */
+	public void testSlowInputStream() throws Exception {
+		// Get the logger to be used
+		DummyPOILogger logger = new DummyPOILogger();
+		Field fld = RawDataBlock.class.getDeclaredField("log");
+		fld.setAccessible(true);
+		fld.set(null, logger);
+		assertEquals(0, logger.logged.size());
+
+		// Test for various ok data sizes
+		for (int k = 1; k < 512; k++) {
+			byte[] data = new byte[ 512 ];
+			for (int j = 0; j < data.length; j++) {
+				data[j] = (byte) j;
+			}
+
+			// Shouldn't complain, as there is enough data,
+			//  even if it dribbles through
+			RawDataBlock block =
+				new RawDataBlock(new SlowInputStream(data, k));
+			assertFalse(block.eof());
+		}
+
+		// But if there wasn't enough data available, will
+		//  complain
+		for (int k = 1; k < 512; k++) {
+			byte[] data = new byte[ 511 ];
+			for (int j = 0; j < data.length; j++) {
+				data[j] = (byte) j;
+			}
+
+			logger.reset();
+			assertEquals(0, logger.logged.size());
+
+			// Should complain, as there isn't enough data
+			RawDataBlock block =
+				new RawDataBlock(new SlowInputStream(data, k));
+			assertNotNull(block);
+			assertEquals(
+					"Warning on " + k + " byte short block",
+					1, logger.logged.size()
+			);
+		}
+	}
+
+	/**
+	 * An input stream which will return a maximum of
+	 *  a given number of bytes to read, and often claims
+	 *  not to have any data
+	 */
+	public static class SlowInputStream extends InputStream {
+		private Random rnd = new Random();
+		private byte[] data;
+		private int chunkSize;
+		private int pos = 0;
+
+		public SlowInputStream(byte[] data, int chunkSize) {
+			this.chunkSize = chunkSize;
+			this.data = data;
+		}
+
+		/**
+		 * 75% of the time, claim there's no data available
+		 */
+		private boolean claimNoData() {
+			if(rnd.nextFloat() < 0.25f) {
+				return false;
+			}
+			return true;
+		}
+
+		public int read() {
 			if(pos >= data.length) {
 				return -1;
 			}
 			int ret = data[pos];
 			pos++;
-			
+
 			if(ret < 0) ret += 256;
 			return ret;
 		}
@@ -251,7 +229,7 @@ public class TestRawDataBlock
 		 *  size, whichever is lower.
 		 * Quite often will simply claim to have no data
 		 */
-		public int read(byte[] b, int off, int len) throws IOException {
+		public int read(byte[] b, int off, int len) {
 			// Keep the length within the chunk size
 			if(len > chunkSize) {
 				len = chunkSize;
@@ -259,40 +237,26 @@ public class TestRawDataBlock
 			// Don't read off the end of the data
 			if(pos + len > data.length) {
 				len = data.length - pos;
-				
+
 				// Spot when we're out of data
 				if(len == 0) {
 					return -1;
 				}
 			}
-			
+
 			// 75% of the time, claim there's no data
 			if(claimNoData()) {
 				return 0;
 			}
-			
+
 			// Copy, and return what we read
 			System.arraycopy(data, pos, b, off, len);
 			pos += len;
 			return len;
 		}
 
-		public int read(byte[] b) throws IOException {
+		public int read(byte[] b) {
 			return read(b, 0, b.length);
 		}
-		
-    }
-
-    /**
-     * main method to run the unit tests
-     *
-     * @param ignored_args
-     */
-
-    public static void main(String [] ignored_args)
-    {
-        System.out
-            .println("Testing org.apache.poi.poifs.storage.RawDataBlock");
-        junit.textui.TestRunner.run(TestRawDataBlock.class);
-    }
+	}
 }

Modified: poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java
URL: http://svn.apache.org/viewvc/poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java?rev=1053791&r1=1053790&r2=1053791&view=diff
==============================================================================
--- poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java (original)
+++ poi/branches/NIO_32_BRANCH/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java Thu Dec 30 02:35:06 2010
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,27 +14,24 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.poifs.storage;
 
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.lang.reflect.Field;
+
+import junit.framework.TestCase;
 
 import org.apache.poi.poifs.common.POIFSConstants;
 import org.apache.poi.util.DummyPOILogger;
-import org.apache.poi.util.POILogFactory;
-
-import junit.framework.*;
 
 /**
  * Class to test RawDataBlockList functionality
  *
  * @author Marc Johnson
  */
-
-public class TestRawDataBlockList
-    extends TestCase
-{
+public final class TestRawDataBlockList extends TestCase {
 	static {
         // We always want to use our own
         //  logger
@@ -46,56 +42,36 @@ public class TestRawDataBlockList
 	}
 
     /**
-     * Constructor TestRawDataBlockList
-     *
-     * @param name
-     */
-    public TestRawDataBlockList(String name)
-    {
-        super(name);
-    }
-
-    /**
      * Test creating a normal RawDataBlockList
-     *
-     * @exception IOException
      */
-    public void testNormalConstructor()
-        throws IOException
-    {
+    public void testNormalConstructor() throws IOException {
         byte[] data = new byte[ 2560 ];
 
         for (int j = 0; j < 2560; j++)
         {
             data[ j ] = ( byte ) j;
         }
-        new RawDataBlockList(new ByteArrayInputStream(data), POIFSConstants.BIG_BLOCK_SIZE);
+        new RawDataBlockList(new ByteArrayInputStream(data), POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
     }
 
     /**
      * Test creating an empty RawDataBlockList
-     *
-     * @exception IOException
      */
-
-    public void testEmptyConstructor()
-        throws IOException
-    {
-        new RawDataBlockList(new ByteArrayInputStream(new byte[ 0 ]), POIFSConstants.BIG_BLOCK_SIZE);
+    public void testEmptyConstructor() throws IOException {
+        new RawDataBlockList(new ByteArrayInputStream(new byte[ 0 ]), POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
     }
 
     /**
      * Test creating a short RawDataBlockList
      */
-
-    public void testShortConstructor() throws Exception
-    {
+    public void testShortConstructor() throws Exception {
         // Get the logger to be used
-        DummyPOILogger logger = (DummyPOILogger)POILogFactory.getLogger(
-        		RawDataBlock.class
-        );
+        DummyPOILogger logger = new DummyPOILogger();
+        Field fld = RawDataBlock.class.getDeclaredField("log");
+        fld.setAccessible(true);
+        fld.set(null, logger);
         assertEquals(0, logger.logged.size());
-        
+
         // Test for various short sizes
         for (int k = 2049; k < 2560; k++)
         {
@@ -108,21 +84,8 @@ public class TestRawDataBlockList
 
             // Check we logged the error
             logger.reset();
-            new RawDataBlockList(new ByteArrayInputStream(data), POIFSConstants.BIG_BLOCK_SIZE);
+            new RawDataBlockList(new ByteArrayInputStream(data), POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
             assertEquals(1, logger.logged.size());
         }
     }
-
-    /**
-     * main method to run the unit tests
-     *
-     * @param ignored_args
-     */
-
-    public static void main(String [] ignored_args)
-    {
-        System.out
-            .println("Testing org.apache.poi.poifs.storage.RawDataBlockList");
-        junit.textui.TestRunner.run(TestRawDataBlockList.class);
-    }
 }



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


Mime
View raw message