FileDocCategorySizeDatePackage
TestUnknownEscherRecord.javaAPI DocApache Poi 3.0.14841Mon Jan 01 12:39:46 GMT 2007org.apache.poi.ddf

TestUnknownEscherRecord

public class TestUnknownEscherRecord extends TestCase

Fields Summary
Constructors Summary
Methods Summary
public voidtestFillFields()

        String testData =
                "0F 02 " + // options
                "11 F1 " + // record id
                "00 00 00 00";      // remaining bytes

        UnknownEscherRecord r = new UnknownEscherRecord();
        EscherRecordFactory factory = new DefaultEscherRecordFactory();
        r.fillFields( HexRead.readFromString( testData ), factory );

        assertEquals( 0x020F, r.getOptions() );
        assertEquals( (short) 0xF111, r.getRecordId() );
        assertTrue( r.isContainerRecord() );
        assertEquals( 8, r.getRecordSize() );
        assertEquals( 0, r.getChildRecords().size() );
        assertEquals( 0, r.getData().length );

        testData =
                "00 02 " + // options
                "11 F1 " + // record id
                "04 00 00 00 " + // remaining bytes
                "01 02 03 04";

        r = new UnknownEscherRecord();
        r.fillFields( HexRead.readFromString( testData ), factory );

        assertEquals( 0x0200, r.getOptions() );
        assertEquals( (short) 0xF111, r.getRecordId() );
        assertEquals( 12, r.getRecordSize() );
        assertFalse( r.isContainerRecord() );
        assertEquals( 0, r.getChildRecords().size() );
        assertEquals( 4, r.getData().length );
        assertEquals( 1, r.getData()[0] );
        assertEquals( 2, r.getData()[1] );
        assertEquals( 3, r.getData()[2] );
        assertEquals( 4, r.getData()[3] );

        testData =
                "0F 02 " + // options
                "11 F1 " + // record id
                "08 00 00 00 " + // remaining bytes
                "00 02 " + // options
                "FF FF " + // record id
                "00 00 00 00";      // remaining bytes

        r = new UnknownEscherRecord();
        r.fillFields( HexRead.readFromString( testData ), factory );

        assertEquals( 0x020F, r.getOptions() );
        assertEquals( (short) 0xF111, r.getRecordId() );
        assertEquals( 8, r.getRecordSize() );
        assertTrue( r.isContainerRecord() );
        assertEquals( 1, r.getChildRecords().size() );
        assertEquals( (short) 0xFFFF, r.getChild( 0 ).getRecordId() );

    
public voidtestSerialize()

        UnknownEscherRecord r = new UnknownEscherRecord();
        r.setOptions( (short) 0x1234 );
        r.setRecordId( (short) 0xF112 );
        byte[] data = new byte[8];
        r.serialize( 0, data, new NullEscherSerializationListener() );

        assertEquals( "[34, 12, 12, F1, 00, 00, 00, 00, ]", HexDump.toHex( data ) );

        EscherRecord childRecord = new UnknownEscherRecord();
        childRecord.setOptions( (short) 0x9999 );
        childRecord.setRecordId( (short) 0xFF01 );
        r.addChildRecord( childRecord );
        r.setOptions( (short) 0x123F );
        data = new byte[16];
        r.serialize( 0, data, new NullEscherSerializationListener() );

        assertEquals( "[3F, 12, 12, F1, 08, 00, 00, 00, 99, 99, 01, FF, 00, 00, 00, 00, ]", HexDump.toHex( data ) );
    
public voidtestToString()

        UnknownEscherRecord r = new UnknownEscherRecord();
        r.setOptions( (short) 0x1234 );
        r.setRecordId( (short) 0xF112 );
        byte[] data = new byte[8];
        r.serialize( 0, data, new NullEscherSerializationListener() );

        String nl = System.getProperty("line.separator");
        assertEquals( "org.apache.poi.ddf.UnknownEscherRecord:" + nl +
                "  isContainer: false" + nl +
                "  options: 0x1234" + nl +
                "  recordId: 0xF112" + nl +
                "  numchildren: 0" + nl
                , r.toString() );