FileDocCategorySizeDatePackage
TestObjRecord.javaAPI DocApache Poi 3.0.13744Sun Mar 11 12:59:26 GMT 2007org.apache.poi.hssf.record

TestObjRecord

public class TestObjRecord extends TestCase
Tests the serialization and deserialization of the ObjRecord class works correctly. Test data taken directly from a real Excel file.
author
Yegor Kozlov

Fields Summary
public static byte[]
recdata
OBJ record data containing two sub-records. The data taken directly from a real Excel file. [OBJ] [ftCmo] [ftEnd]
Constructors Summary
Methods Summary
public voidtestConstruct()

        ObjRecord record = new ObjRecord();
        CommonObjectDataSubRecord ftCmo = new CommonObjectDataSubRecord();
        ftCmo.setObjectType( CommonObjectDataSubRecord.OBJECT_TYPE_COMMENT);
        ftCmo.setObjectId( (short) 1024 );
        ftCmo.setLocked( true );
        ftCmo.setPrintable( true );
        ftCmo.setAutofill( true );
        ftCmo.setAutoline( true );
        record.addSubRecord(ftCmo);
        EndSubRecord ftEnd = new EndSubRecord();
        record.addSubRecord(ftEnd);

        //serialize and read again
        byte [] recordBytes = record.serialize();
        //cut off the record header
        byte [] bytes = new byte[recordBytes.length-4];
        System.arraycopy(recordBytes, 4, bytes, 0, bytes.length);

        record = new ObjRecord(new TestcaseRecordInputStream(ObjRecord.sid, (short)bytes.length, bytes));
        List subrecords = record.getSubRecords();
        assertEquals( 2, subrecords.size() );
        assertTrue( subrecords.get(0) instanceof CommonObjectDataSubRecord);
        assertTrue( subrecords.get(1) instanceof EndSubRecord );
    
public voidtestLoad()



         
        ObjRecord record = new ObjRecord(new TestcaseRecordInputStream(ObjRecord.sid, (short)recdata.length, recdata));

        assertEquals( recdata.length, record.getRecordSize() - 4);

        List subrecords = record.getSubRecords();
        assertEquals( 2, subrecords.size() );
        assertTrue( subrecords.get(0) instanceof CommonObjectDataSubRecord);
        assertTrue( subrecords.get(1) instanceof EndSubRecord );

    
public voidtestStore()

        ObjRecord record = new ObjRecord(new TestcaseRecordInputStream(ObjRecord.sid, (short)recdata.length, recdata));

        byte [] recordBytes = record.serialize();
        assertEquals(recdata.length, recordBytes.length - 4);
        byte[] subData = new byte[recordBytes.length - 4];
        System.arraycopy(recordBytes, 4, subData, 0, subData.length);
        assertTrue(Arrays.equals(recdata, subData));