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

TestEscherContainerRecord

public class TestEscherContainerRecord extends TestCase

Fields Summary
Constructors Summary
Methods Summary
public voidtestFillFields()

        EscherRecordFactory f = new DefaultEscherRecordFactory();
        byte[] data = HexRead.readFromString( "0F 02 11 F1 00 00 00 00" );
        EscherRecord r = f.createRecord( data, 0 );
        r.fillFields( data, 0, f );
        assertTrue( r instanceof EscherContainerRecord );
        assertEquals( (short) 0x020F, r.getOptions() );
        assertEquals( (short) 0xF111, r.getRecordId() );

        data = HexRead.readFromString( "0F 02 11 F1 08 00 00 00" +
                " 02 00 22 F2 00 00 00 00" );
        r = f.createRecord( data, 0 );
        r.fillFields( data, 0, f );
        EscherRecord c = r.getChild( 0 );
        assertFalse( c instanceof EscherContainerRecord );
        assertEquals( (short) 0x0002, c.getOptions() );
        assertEquals( (short) 0xF222, c.getRecordId() );
    
public voidtestGetRecordSize()

        EscherContainerRecord r = new EscherContainerRecord();
        r.addChildRecord(new EscherRecord()
        {
            public int fillFields( byte[] data, int offset, EscherRecordFactory recordFactory ) { return 0; }
            public int serialize( int offset, byte[] data, EscherSerializationListener listener ) { return 0; }
            public int getRecordSize() { return 10; }
            public String getRecordName() { return ""; }
        } );

        assertEquals(18, r.getRecordSize());
    
public voidtestSerialize()

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

        assertEquals( "[3F, 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 );
        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()

        EscherContainerRecord r = new EscherContainerRecord();
        r.setRecordId( EscherContainerRecord.SP_CONTAINER );
        r.setOptions( (short) 0x000F );
        String nl = System.getProperty( "line.separator" );
        assertEquals( "org.apache.poi.ddf.EscherContainerRecord (SpContainer):" + nl +
                "  isContainer: true" + nl +
                "  options: 0x000F" + nl +
                "  recordId: 0xF004" + nl +
                "  numchildren: 0" + nl
                , r.toString() );

        EscherOptRecord r2 = new EscherOptRecord();
        r2.setOptions( (short) 0x9876 );
        r2.setRecordId( EscherOptRecord.RECORD_ID );

        r.addChildRecord( r2 );
        String expected = "org.apache.poi.ddf.EscherContainerRecord (SpContainer):" + nl +
                        "  isContainer: true" + nl +
                        "  options: 0x000F" + nl +
                        "  recordId: 0xF004" + nl +
                        "  numchildren: 1" + nl +
                        "  children: " + nl +
                        "org.apache.poi.ddf.EscherOptRecord:" + nl +
                        "  isContainer: false" + nl +
                        "  options: 0x0003" + nl +
                        "  recordId: 0xF00B" + nl +
                        "  numchildren: 0" + nl +
                        "  properties:" + nl;
        assertEquals( expected, r.toString() );