1 2 17 18 package org.apache.poi.ddf; 19 20 import junit.framework.TestCase; 21 import org.apache.poi.util.HexDump; 22 import org.apache.poi.util.HexRead; 23 24 public class TestEscherClientDataRecord extends TestCase 25 { 26 public void testSerialize() throws Exception 27 { 28 EscherClientDataRecord r = createRecord(); 29 30 byte[] data = new byte[8]; 31 int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() ); 32 assertEquals( 8, bytesWritten ); 33 assertEquals( "[02, 00, " + 34 "11, F0, " + 35 "00, 00, 00, 00, ]", 36 HexDump.toHex( data ) ); 37 } 38 39 public void testFillFields() throws Exception 40 { 41 String hexData = "02 00 " + 42 "11 F0 " + 43 "00 00 00 00 "; 44 byte[] data = HexRead.readFromString( hexData ); 45 EscherClientDataRecord r = new EscherClientDataRecord(); 46 int bytesWritten = r.fillFields( data, new DefaultEscherRecordFactory() ); 47 48 assertEquals( 8, bytesWritten ); 49 assertEquals( (short)0xF011, r.getRecordId() ); 50 assertEquals( "[]", HexDump.toHex(r.getRemainingData()) ); 51 } 52 53 public void testToString() throws Exception 54 { 55 String nl = System.getProperty("line.separator"); 56 57 String expected = "org.apache.poi.ddf.EscherClientDataRecord:" + nl + 58 " RecordId: 0xF011" + nl + 59 " Options: 0x0002" + nl + 60 " Extra Data:" + nl + 61 "No Data" ; 62 assertEquals( expected, createRecord().toString() ); 63 } 64 65 private EscherClientDataRecord createRecord() 66 { 67 EscherClientDataRecord r = new EscherClientDataRecord(); 68 r.setOptions( (short) 0x0002 ); 69 r.setRecordId( EscherClientDataRecord.RECORD_ID ); 70 r.setRemainingData( new byte[] {} ); 71 return r; 72 } 73 74 } 75 | Popular Tags |