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 TestEscherSpgrRecord extends TestCase 25 { 26 public void testSerialize() throws Exception 27 { 28 EscherSpgrRecord r = createRecord(); 29 30 byte[] data = new byte[24]; 31 int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() ); 32 assertEquals( 24, bytesWritten ); 33 assertEquals( "[10, 00, " + 34 "09, F0, " + 35 "10, 00, 00, 00, " + 36 "01, 00, 00, 00, " + "02, 00, 00, 00, " + "03, 00, 00, 00, " + "04, 00, 00, 00, ]", HexDump.toHex( data ) ); 41 } 42 43 public void testFillFields() throws Exception 44 { 45 String hexData = "10 00 " + 46 "09 F0 " + 47 "10 00 00 00 " + 48 "01 00 00 00 " + 49 "02 00 00 00 " + 50 "03 00 00 00 " + 51 "04 00 00 00 "; 52 byte[] data = HexRead.readFromString( hexData ); 53 EscherSpgrRecord r = new EscherSpgrRecord(); 54 int bytesWritten = r.fillFields( data, new DefaultEscherRecordFactory() ); 55 56 assertEquals( 24, bytesWritten ); 57 assertEquals( 1, r.getRectX1() ); 58 assertEquals( 2, r.getRectY1() ); 59 assertEquals( 3, r.getRectX2() ); 60 assertEquals( 4, r.getRectY2() ); 61 } 62 63 public void testToString() throws Exception 64 { 65 String nl = System.getProperty("line.separator"); 66 67 String expected = "org.apache.poi.ddf.EscherSpgrRecord:" + nl + 68 " RecordId: 0xF009" + nl + 69 " Options: 0x0010" + nl + 70 " RectX: 1" + nl + 71 " RectY: 2" + nl + 72 " RectWidth: 3" + nl + 73 " RectHeight: 4" + nl; 74 ; 75 assertEquals( expected, createRecord().toString() ); 76 } 77 78 private EscherSpgrRecord createRecord() 79 { 80 EscherSpgrRecord r = new EscherSpgrRecord(); 81 r.setOptions( (short) 0x0010 ); 82 r.setRecordId( EscherSpgrRecord.RECORD_ID ); 83 r.setRectX1(1); 84 r.setRectY1(2); 85 r.setRectX2(3); 86 r.setRectY2(4); 87 return r; 88 } 89 90 } 91 | Popular Tags |