1 2 17 18 package org.apache.poi.ddf; 19 20 import junit.framework.TestCase; 21 import org.apache.poi.util.HexRead; 22 import org.apache.poi.util.HexDump; 23 24 import java.io.IOException ; 25 26 public class TestEscherOptRecord extends TestCase 27 { 28 29 public void testFillFields() throws Exception 30 { 31 checkFillFieldsSimple(); 32 checkFillFieldsComplex(); 33 } 34 35 private void checkFillFieldsComplex() throws IOException 36 { 37 String dataStr = "33 00 " + 38 "0B F0 " + 39 "14 00 00 00 " + 40 "BF 00 01 00 00 00 " + 41 "01 80 02 00 00 00 " + 42 "BF 00 01 00 00 00 " + 43 "01 02"; 44 45 EscherOptRecord r = new EscherOptRecord(); 46 r.fillFields( HexRead.readFromString( dataStr ), new DefaultEscherRecordFactory() ); 47 assertEquals( (short) 0x0033, r.getOptions() ); 48 assertEquals( (short) 0xF00B, r.getRecordId() ); 49 assertEquals( 3, r.getEscherProperties().size() ); 50 EscherBoolProperty prop1 = new EscherBoolProperty( EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 1 ); 51 EscherComplexProperty prop2 = new EscherComplexProperty( (short) 1, false, new byte[] { 0x01, 0x02 } ); 52 EscherBoolProperty prop3 = new EscherBoolProperty( EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 1 ); 53 assertEquals( prop1, r.getEscherProperty( 0 ) ); 54 assertEquals( prop2, r.getEscherProperty( 1 ) ); 55 assertEquals( prop3, r.getEscherProperty( 2 ) ); 56 57 } 58 59 private void checkFillFieldsSimple() 60 throws IOException 61 { 62 String dataStr = "33 00 " + "0B F0 " + "12 00 00 00 " + "BF 00 08 00 08 00 " + 66 "81 01 09 00 00 08 " + 67 "C0 01 40 00 00 08"; 68 69 EscherOptRecord r = new EscherOptRecord(); 70 r.fillFields( HexRead.readFromString( dataStr ), new DefaultEscherRecordFactory() ); 71 assertEquals( (short) 0x0033, r.getOptions() ); 72 assertEquals( (short) 0xF00B, r.getRecordId() ); 73 assertEquals( 3, r.getEscherProperties().size() ); 74 EscherBoolProperty prop1 = new EscherBoolProperty( EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 524296 ); 75 EscherRGBProperty prop2 = new EscherRGBProperty( EscherProperties.FILL__FILLCOLOR, 0x08000009 ); 76 EscherRGBProperty prop3 = new EscherRGBProperty( EscherProperties.LINESTYLE__COLOR, 0x08000040 ); 77 assertEquals( prop1, r.getEscherProperty( 0 ) ); 78 assertEquals( prop2, r.getEscherProperty( 1 ) ); 79 assertEquals( prop3, r.getEscherProperty( 2 ) ); 80 } 81 82 public void testSerialize() throws Exception 83 { 84 checkSerializeSimple(); 85 checkSerializeComplex(); 86 } 87 88 private void checkSerializeComplex() 89 { 90 EscherOptRecord r = new EscherOptRecord(); 92 r.setOptions( (short) 0x0033 ); 93 r.setRecordId( (short) 0xF00B ); 94 EscherBoolProperty prop1 = new EscherBoolProperty( EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 1 ); 95 EscherComplexProperty prop2 = new EscherComplexProperty( (short) 1, false, new byte[] { 0x01, 0x02 } ); 96 EscherBoolProperty prop3 = new EscherBoolProperty( EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 1 ); 97 r.addEscherProperty( prop1 ); 98 r.addEscherProperty( prop2 ); 99 r.addEscherProperty( prop3 ); 100 101 byte[] data = new byte[28]; 102 int bytesWritten = r.serialize(0, data, new NullEscherSerializationListener() ); 103 assertEquals( 28, bytesWritten ); 104 String dataStr = "[33, 00, " + 105 "0B, F0, " + 106 "14, 00, 00, 00, " + 107 "BF, 00, 01, 00, 00, 00, " + 108 "01, 80, 02, 00, 00, 00, " + 109 "BF, 00, 01, 00, 00, 00, " + 110 "01, 02, ]"; 111 assertEquals( dataStr, HexDump.toHex(data) ); 112 113 } 114 115 private void checkSerializeSimple() 116 { 117 EscherOptRecord r = new EscherOptRecord(); 118 r.setOptions( (short) 0x0033 ); 119 r.setRecordId( (short) 0xF00B ); 120 EscherBoolProperty prop1 = new EscherBoolProperty( EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 1 ); 121 EscherRGBProperty prop2 = new EscherRGBProperty( EscherProperties.FILL__FILLCOLOR, 0x08000009 ); 122 EscherRGBProperty prop3 = new EscherRGBProperty( EscherProperties.LINESTYLE__COLOR, 0x08000040 ); 123 r.addEscherProperty( prop1 ); 124 r.addEscherProperty( prop2 ); 125 r.addEscherProperty( prop3 ); 126 127 byte[] data = new byte[26]; 128 int bytesWritten = r.serialize(0, data, new NullEscherSerializationListener() ); 129 String dataStr = "[33, 00, " + 130 "0B, F0, " + 131 "12, 00, 00, 00, " + 132 "BF, 00, 01, 00, 00, 00, " + 133 "81, 01, 09, 00, 00, 08, " + 134 "C0, 01, 40, 00, 00, 08, ]"; 135 assertEquals( dataStr, HexDump.toHex(data) ); 136 assertEquals( 26, bytesWritten ); 137 } 138 139 public void testToString() throws Exception 140 { 141 String nl = System.getProperty("line.separator"); 142 EscherOptRecord r = new EscherOptRecord(); 143 r.setOptions((short)0x000F); 144 r.setRecordId(EscherOptRecord.RECORD_ID); 145 EscherProperty prop1 = new EscherBoolProperty((short)1, 1); 146 r.addEscherProperty(prop1); 147 String expected = "org.apache.poi.ddf.EscherOptRecord:" + nl + 148 " isContainer: true" + nl + 149 " options: 0x0013" + nl + 150 " recordId: 0x" + HexDump.toHex(EscherOptRecord.RECORD_ID) + nl + 151 " numchildren: 0" + nl + 152 " properties:" + nl + 153 " propNum: 1, propName: unknown, complex: false, blipId: false, value: 1 (0x00000001)" + nl; 154 assertEquals( expected, r.toString()); 155 } 156 157 } 158 | Popular Tags |