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 TestUnknownEscherRecord extends TestCase 25 { 26 public void testFillFields() throws Exception 27 { 28 String testData = 29 "0F 02 " + "11 F1 " + "00 00 00 00"; 33 UnknownEscherRecord r = new UnknownEscherRecord(); 34 EscherRecordFactory factory = new DefaultEscherRecordFactory(); 35 r.fillFields( HexRead.readFromString( testData ), factory ); 36 37 assertEquals( 0x020F, r.getOptions() ); 38 assertEquals( (short) 0xF111, r.getRecordId() ); 39 assertTrue( r.isContainerRecord() ); 40 assertEquals( 8, r.getRecordSize() ); 41 assertEquals( 0, r.getChildRecords().size() ); 42 assertEquals( 0, r.getData().length ); 43 44 testData = 45 "00 02 " + "11 F1 " + "04 00 00 00 " + "01 02 03 04"; 49 50 r = new UnknownEscherRecord(); 51 r.fillFields( HexRead.readFromString( testData ), factory ); 52 53 assertEquals( 0x0200, r.getOptions() ); 54 assertEquals( (short) 0xF111, r.getRecordId() ); 55 assertEquals( 12, r.getRecordSize() ); 56 assertFalse( r.isContainerRecord() ); 57 assertEquals( 0, r.getChildRecords().size() ); 58 assertEquals( 4, r.getData().length ); 59 assertEquals( 1, r.getData()[0] ); 60 assertEquals( 2, r.getData()[1] ); 61 assertEquals( 3, r.getData()[2] ); 62 assertEquals( 4, r.getData()[3] ); 63 64 testData = 65 "0F 02 " + "11 F1 " + "08 00 00 00 " + "00 02 " + "FF FF " + "00 00 00 00"; 72 r = new UnknownEscherRecord(); 73 r.fillFields( HexRead.readFromString( testData ), factory ); 74 75 assertEquals( 0x020F, r.getOptions() ); 76 assertEquals( (short) 0xF111, r.getRecordId() ); 77 assertEquals( 8, r.getRecordSize() ); 78 assertTrue( r.isContainerRecord() ); 79 assertEquals( 1, r.getChildRecords().size() ); 80 assertEquals( (short) 0xFFFF, r.getChild( 0 ).getRecordId() ); 81 82 } 83 84 public void testSerialize() throws Exception 85 { 86 UnknownEscherRecord r = new UnknownEscherRecord(); 87 r.setOptions( (short) 0x1234 ); 88 r.setRecordId( (short) 0xF112 ); 89 byte[] data = new byte[8]; 90 r.serialize( 0, data, new NullEscherSerializationListener() ); 91 92 assertEquals( "[34, 12, 12, F1, 00, 00, 00, 00, ]", HexDump.toHex( data ) ); 93 94 EscherRecord childRecord = new UnknownEscherRecord(); 95 childRecord.setOptions( (short) 0x9999 ); 96 childRecord.setRecordId( (short) 0xFF01 ); 97 r.addChildRecord( childRecord ); 98 r.setOptions( (short) 0x123F ); 99 data = new byte[16]; 100 r.serialize( 0, data, new NullEscherSerializationListener() ); 101 102 assertEquals( "[3F, 12, 12, F1, 08, 00, 00, 00, 99, 99, 01, FF, 00, 00, 00, 00, ]", HexDump.toHex( data ) ); 103 } 104 105 public void testToString() throws Exception 106 { 107 UnknownEscherRecord r = new UnknownEscherRecord(); 108 r.setOptions( (short) 0x1234 ); 109 r.setRecordId( (short) 0xF112 ); 110 byte[] data = new byte[8]; 111 r.serialize( 0, data, new NullEscherSerializationListener() ); 112 113 String nl = System.getProperty("line.separator"); 114 assertEquals( "org.apache.poi.ddf.UnknownEscherRecord:" + nl + 115 " isContainer: false" + nl + 116 " options: 0x1234" + nl + 117 " recordId: 0xF112" + nl + 118 " numchildren: 0" + nl 119 , r.toString() ); 120 } 121 122 123 } 124 | Popular Tags |