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 TestEscherBlipRecord extends TestCase 25 { 26 private String dataStr; 27 private byte[] data; 28 29 protected void setUp() throws Exception 30 { 31 dataStr = "2C 15 18 F0 34 00 00 00 01 01 01 01 01 01 01 01 " + 32 "01 01 01 01 01 01 01 01 06 00 00 00 03 00 00 00 " + 33 "01 00 00 00 04 00 00 00 02 00 00 00 0A 00 00 00 " + 34 "0B 00 00 00 05 00 00 00 08 07 01 02"; 35 data = HexRead.readFromString(dataStr); 36 } 37 38 public void testSerialize() throws Exception 39 { 40 EscherBlipRecord r = new EscherBlipRecord(); 41 r.setBoundaryLeft(1); 42 r.setBoundaryHeight(2); 43 r.setBoundaryTop(3); 44 r.setBoundaryWidth(4); 45 r.setCacheOfSavedSize(5); 46 r.setCacheOfSize(6); 47 r.setFilter((byte)7); 48 r.setCompressionFlag((byte)8); 49 r.setSecondaryUID(new byte[] { (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, 50 (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, 51 (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, 52 (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, }); 53 r.setWidth(10); 54 r.setHeight(11); 55 r.setRecordId(EscherBlipRecord.RECORD_ID_START); 56 r.setOptions((short)5420); 57 r.setData(new byte[] { (byte)0x01, (byte)0x02 } ); 58 59 byte[] buf = new byte[r.getRecordSize()]; 60 r.serialize(0, buf, new NullEscherSerializationListener() ); 61 62 assertEquals("[2C, 15, 18, F0, 26, 00, 00, 00, " + 63 "01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, " + 64 "06, 00, 00, 00, " + "03, 00, 00, 00, " + "01, 00, 00, 00, " + "04, 00, 00, 00, " + "02, 00, 00, 00, " + "0A, 00, 00, 00, " + "0B, 00, 00, 00, " + "05, 00, 00, 00, " + "08, " + "07, " + "01, 02, ]", HexDump.toHex(buf)); 76 assertEquals(60, r.getRecordSize() ); 77 78 } 79 80 public void testFillFields() throws Exception 81 { 82 EscherBlipRecord r = new EscherBlipRecord(); 83 r.fillFields( data, 0, new DefaultEscherRecordFactory()); 84 85 assertEquals( EscherBlipRecord.RECORD_ID_START, r.getRecordId() ); 86 assertEquals( 1, r.getBoundaryLeft() ); 87 assertEquals( 2, r.getBoundaryHeight() ); 88 assertEquals( 3, r.getBoundaryTop() ); 89 assertEquals( 4, r.getBoundaryWidth() ); 90 assertEquals( 5, r.getCacheOfSavedSize() ); 91 assertEquals( 6, r.getCacheOfSize() ); 92 assertEquals( 7, r.getFilter() ); 93 assertEquals( 8, r.getCompressionFlag() ); 94 assertEquals( "[01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, ]", HexDump.toHex(r.getSecondaryUID() ) ); 95 assertEquals( 10, r.getWidth() ); 96 assertEquals( 11, r.getHeight() ); 97 assertEquals( (short)5420, r.getOptions() ); 98 assertEquals( "[01, 02, ]", HexDump.toHex( r.getData() ) ); 99 } 100 101 public void testToString() throws Exception 102 { 103 EscherBlipRecord r = new EscherBlipRecord(); 104 r.fillFields( data, 0, new DefaultEscherRecordFactory() ); 105 106 String nl = System.getProperty("line.separator"); 107 108 assertEquals( "org.apache.poi.ddf.EscherBlipRecord:" + nl + 109 " RecordId: 0xF018" + nl + 110 " Options: 0x152C" + nl + 111 " Secondary UID: [01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, ]" + nl + 112 " CacheOfSize: 6" + nl + 113 " BoundaryTop: 3" + nl + 114 " BoundaryLeft: 1" + nl + 115 " BoundaryWidth: 4" + nl + 116 " BoundaryHeight: 2" + nl + 117 " X: 10" + nl + 118 " Y: 11" + nl + 119 " CacheOfSavedSize: 5" + nl + 120 " CompressionFlag: 8" + nl + 121 " Filter: 7" + nl + 122 " Data:" + nl + 123 "00000000 01 02 .." + nl 124 , r.toString() ); 125 } 126 127 } 128 | Popular Tags |