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 TestEscherSpRecord extends TestCase 25 { 26 public void testSerialize() throws Exception 27 { 28 EscherSpRecord r = createRecord(); 29 30 byte[] data = new byte[16]; 31 int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() ); 32 assertEquals( 16, bytesWritten ); 33 assertEquals( "[02, 00, " + 34 "0A, F0, " + 35 "08, 00, 00, 00, " + 36 "00, 04, 00, 00, " + 37 "05, 00, 00, 00, ]", 38 HexDump.toHex( data ) ); 39 } 40 41 public void testFillFields() throws Exception 42 { 43 String hexData = "02 00 " + 44 "0A F0 " + 45 "08 00 00 00 " + 46 "00 04 00 00 " + 47 "05 00 00 00 "; 48 byte[] data = HexRead.readFromString( hexData ); 49 EscherSpRecord r = new EscherSpRecord(); 50 int bytesWritten = r.fillFields( data, new DefaultEscherRecordFactory() ); 51 52 assertEquals( 16, bytesWritten ); 53 assertEquals( 0x0400, r.getShapeId() ); 54 assertEquals( 0x05, r.getFlags() ); 55 } 56 57 public void testToString() throws Exception 58 { 59 String nl = System.getProperty("line.separator"); 60 61 String expected = "org.apache.poi.ddf.EscherSpRecord:" + nl + 62 " RecordId: 0xF00A" + nl + 63 " Options: 0x0002" + nl + 64 " ShapeId: 1024" + nl + 65 " Flags: GROUP|PATRIARCH (0x00000005)" + nl; 66 assertEquals( expected, createRecord().toString() ); 67 } 68 69 private EscherSpRecord createRecord() 70 { 71 EscherSpRecord r = new EscherSpRecord(); 72 r.setOptions( (short) 0x0002 ); 73 r.setRecordId( EscherSpRecord.RECORD_ID ); 74 r.setShapeId(0x0400); 75 r.setFlags(0x05); 76 return r; 77 } 78 79 } 80 | Popular Tags |