FileDocCategorySizeDatePackage
TestRawDataBlock.javaAPI DocApache Poi 3.0.13528Mon Jan 01 12:39:44 GMT 2007org.apache.poi.poifs.storage

TestRawDataBlock

public class TestRawDataBlock extends TestCase
Class to test RawDataBlock functionality
author
Marc Johnson

Fields Summary
Constructors Summary
public TestRawDataBlock(String name)
Constructor TestRawDataBlock

param
name

        super(name);
    
Methods Summary
public static voidmain(java.lang.String[] ignored_args)
main method to run the unit tests

param
ignored_args

        System.out
            .println("Testing org.apache.poi.poifs.storage.RawDataBlock");
        junit.textui.TestRunner.run(TestRawDataBlock.class);
    
public voidtestEmptyConstructor()
Test creating an empty RawDataBlock

exception
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
        }
    
public voidtestNormalConstructor()
Test creating a normal RawDataBlock

exception
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 ]);
        }
    
public voidtestShortConstructor()
Test creating a short RawDataBlock

        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;

            try
            {
                block = new RawDataBlock(new ByteArrayInputStream(data));
                fail("Should have thrown IOException creating short block");
            }
            catch (IOException ignored)
            {

                // as expected
            }
        }