1 2 17 18 package org.apache.poi.ddf; 19 20 import junit.framework.TestCase; 21 import org.apache.poi.util.HexRead; 22 import org.apache.poi.util.HexDump; 23 24 public class TestEscherContainerRecord extends TestCase 25 { 26 public void testFillFields() throws Exception 27 { 28 EscherRecordFactory f = new DefaultEscherRecordFactory(); 29 byte[] data = HexRead.readFromString( "0F 02 11 F1 00 00 00 00" ); 30 EscherRecord r = f.createRecord( data, 0 ); 31 r.fillFields( data, 0, f ); 32 assertTrue( r instanceof EscherContainerRecord ); 33 assertEquals( (short) 0x020F, r.getOptions() ); 34 assertEquals( (short) 0xF111, r.getRecordId() ); 35 36 data = HexRead.readFromString( "0F 02 11 F1 08 00 00 00" + 37 " 02 00 22 F2 00 00 00 00" ); 38 r = f.createRecord( data, 0 ); 39 r.fillFields( data, 0, f ); 40 EscherRecord c = r.getChild( 0 ); 41 assertFalse( c instanceof EscherContainerRecord ); 42 assertEquals( (short) 0x0002, c.getOptions() ); 43 assertEquals( (short) 0xF222, c.getRecordId() ); 44 } 45 46 public void testSerialize() throws Exception 47 { 48 UnknownEscherRecord r = new UnknownEscherRecord(); 49 r.setOptions( (short) 0x123F ); 50 r.setRecordId( (short) 0xF112 ); 51 byte[] data = new byte[8]; 52 r.serialize( 0, data, new NullEscherSerializationListener() ); 53 54 assertEquals( "[3F, 12, 12, F1, 00, 00, 00, 00, ]", HexDump.toHex( data ) ); 55 56 EscherRecord childRecord = new UnknownEscherRecord(); 57 childRecord.setOptions( (short) 0x9999 ); 58 childRecord.setRecordId( (short) 0xFF01 ); 59 r.addChildRecord( childRecord ); 60 data = new byte[16]; 61 r.serialize( 0, data, new NullEscherSerializationListener() ); 62 63 assertEquals( "[3F, 12, 12, F1, 08, 00, 00, 00, 99, 99, 01, FF, 00, 00, 00, 00, ]", HexDump.toHex( data ) ); 64 65 } 66 67 public void testToString() throws Exception 68 { 69 EscherContainerRecord r = new EscherContainerRecord(); 70 r.setRecordId( EscherContainerRecord.SP_CONTAINER ); 71 r.setOptions( (short) 0x000F ); 72 String nl = System.getProperty( "line.separator" ); 73 assertEquals( "org.apache.poi.ddf.EscherContainerRecord (SpContainer):" + nl + 74 " isContainer: true" + nl + 75 " options: 0x000F" + nl + 76 " recordId: 0xF004" + nl + 77 " numchildren: 0" + nl 78 , r.toString() ); 79 80 EscherOptRecord r2 = new EscherOptRecord(); 81 r2.setOptions( (short) 0x9876 ); 82 r2.setRecordId( EscherOptRecord.RECORD_ID ); 83 84 r.addChildRecord( r2 ); 85 String expected = "org.apache.poi.ddf.EscherContainerRecord (SpContainer):" + nl + 86 " isContainer: true" + nl + 87 " options: 0x000F" + nl + 88 " recordId: 0xF004" + nl + 89 " numchildren: 1" + nl + 90 " children: " + nl + 91 "org.apache.poi.ddf.EscherOptRecord:" + nl + 92 " isContainer: false" + nl + 93 " options: 0x0003" + nl + 94 " recordId: 0xF00B" + nl + 95 " numchildren: 0" + nl + 96 " properties:" + nl; 97 assertEquals( expected, r.toString() ); 98 99 } 100 101 public void testGetRecordSize() throws Exception 102 { 103 EscherContainerRecord r = new EscherContainerRecord(); 104 r.addChildRecord(new EscherRecord() 105 { 106 public int fillFields( byte[] data, int offset, EscherRecordFactory recordFactory ) { return 0; } 107 public int serialize( int offset, byte[] data, EscherSerializationListener listener ) { return 0; } 108 public int getRecordSize() { return 10; } 109 public String getRecordName() { return ""; } 110 } ); 111 112 assertEquals(18, r.getRecordSize()); 113 } 114 115 } 116 | Popular Tags |