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 TestEscherDggRecord extends TestCase 25 { 26 public void testSerialize() throws Exception 27 { 28 EscherDggRecord r = createRecord(); 29 30 byte[] data = new byte[32]; 31 int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() ); 32 assertEquals( 32, bytesWritten ); 33 assertEquals( "[00, 00, " + 34 "06, F0, " + 35 "18, 00, 00, 00, " + 36 "02, 04, 00, 00, " + 37 "02, 00, 00, 00, " + 38 "02, 00, 00, 00, " + 39 "01, 00, 00, 00, " + 40 "01, 00, 00, 00, 02, 00, 00, 00, ]", 41 HexDump.toHex( data ) ); 42 } 43 44 public void testFillFields() throws Exception 45 { 46 String hexData = "00 00 " + 47 "06 F0 " + 48 "18 00 00 00 " + 49 "02 04 00 00 " + 50 "02 00 00 00 " + 51 "02 00 00 00 " + 52 "01 00 00 00 " + 53 "01 00 00 00 02 00 00 00"; 54 byte[] data = HexRead.readFromString( hexData ); 55 EscherDggRecord r = new EscherDggRecord(); 56 int bytesWritten = r.fillFields( data, new DefaultEscherRecordFactory() ); 57 58 assertEquals( 32, bytesWritten ); 59 assertEquals( 0x402, r.getShapeIdMax() ); 60 assertEquals( 0x02, r.getNumIdClusters() ); 61 assertEquals( 0x02, r.getNumShapesSaved() ); 62 assertEquals( 0x01, r.getDrawingsSaved() ); 63 assertEquals( 1, r.getFileIdClusters().length ); 64 assertEquals( 0x01, r.getFileIdClusters()[0].getDrawingGroupId()); 65 assertEquals( 0x02, r.getFileIdClusters()[0].getNumShapeIdsUsed()); 66 } 67 68 public void testToString() throws Exception 69 { 70 String nl = System.getProperty("line.separator"); 71 72 String expected = "org.apache.poi.ddf.EscherDggRecord:" + nl + 73 " RecordId: 0xF006" + nl + 74 " Options: 0x0000" + nl + 75 " ShapeIdMax: 1026" + nl + 76 " NumIdClusters: 2" + nl + 77 " NumShapesSaved: 2" + nl + 78 " DrawingsSaved: 1" + nl + 79 " DrawingGroupId1: 1" + nl + 80 " NumShapeIdsUsed1: 2" + nl; 81 assertEquals( expected, createRecord().toString() ); 82 } 83 84 private EscherDggRecord createRecord() 85 { 86 EscherDggRecord r = new EscherDggRecord(); 87 r.setOptions( (short) 0x0000 ); 88 r.setRecordId( EscherDggRecord.RECORD_ID ); 89 r.setShapeIdMax( 0x402 ); 90 r.setNumShapesSaved( 0x02 ); 91 r.setDrawingsSaved( 0x01 ); 92 r.setFileIdClusters(new EscherDggRecord.FileIdCluster[] { 93 new EscherDggRecord.FileIdCluster( 1, 2 ) 94 }); 95 return r; 96 } 97 98 public void testGetRecordSize() throws Exception 99 { 100 EscherDggRecord r = new EscherDggRecord(); 101 r.setFileIdClusters(new EscherDggRecord.FileIdCluster[] { new EscherDggRecord.FileIdCluster(0,0) } ); 102 assertEquals(32,r.getRecordSize()); 103 104 } 105 106 } 107 | Popular Tags |