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 TestEscherChildAnchorRecord extends TestCase 25 { 26 public void testSerialize() throws Exception 27 { 28 EscherChildAnchorRecord r = createRecord(); 29 30 byte[] data = new byte[8 + 16]; 31 int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() ); 32 assertEquals( 24, bytesWritten ); 33 assertEquals( "[01, 00, " + 34 "0F, F0, " + 35 "10, 00, 00, 00, " + 36 "01, 00, 00, 00, " + 37 "02, 00, 00, 00, " + 38 "03, 00, 00, 00, " + 39 "04, 00, 00, 00, ]", HexDump.toHex( data ) ); 40 } 41 42 public void testFillFields() throws Exception 43 { 44 String hexData = "01 00 " + 45 "0F F0 " + 46 "10 00 00 00 " + 47 "01 00 00 00 " + 48 "02 00 00 00 " + 49 "03 00 00 00 " + 50 "04 00 00 00 "; 51 52 byte[] data = HexRead.readFromString( hexData ); 53 EscherChildAnchorRecord r = new EscherChildAnchorRecord(); 54 int bytesWritten = r.fillFields( data, new DefaultEscherRecordFactory() ); 55 56 assertEquals( 24, bytesWritten ); 57 assertEquals( 1, r.getDx1() ); 58 assertEquals( 2, r.getDy1() ); 59 assertEquals( 3, r.getDx2() ); 60 assertEquals( 4, r.getDy2() ); 61 assertEquals( (short) 0x0001, r.getOptions() ); 62 } 63 64 public void testToString() throws Exception 65 { 66 String nl = System.getProperty( "line.separator" ); 67 68 String expected = "org.apache.poi.ddf.EscherChildAnchorRecord:" + nl + 69 " RecordId: 0xF00F" + nl + 70 " Options: 0x0001" + nl + 71 " X1: 1" + nl + 72 " Y1: 2" + nl + 73 " X2: 3" + nl + 74 " Y2: 4" + nl; 75 assertEquals( expected, createRecord().toString() ); 76 } 77 78 private EscherChildAnchorRecord createRecord() 79 { 80 EscherChildAnchorRecord r = new EscherChildAnchorRecord(); 81 r.setRecordId( EscherChildAnchorRecord.RECORD_ID ); 82 r.setOptions( (short) 0x0001 ); 83 r.setDx1( 1 ); 84 r.setDy1( 2 ); 85 r.setDx2( 3 ); 86 r.setDy2( 4 ); 87 return r; 88 } 89 90 } 91 | Popular Tags |