01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
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: public void testSerialize() throws Exception {
26: EscherSpgrRecord r = createRecord();
27:
28: byte[] data = new byte[24];
29: int bytesWritten = r.serialize(0, data,
30: new NullEscherSerializationListener());
31: assertEquals(24, bytesWritten);
32: assertEquals("[10, 00, " + "09, F0, " + "10, 00, 00, 00, "
33: + "01, 00, 00, 00, " + // x
34: "02, 00, 00, 00, " + // y
35: "03, 00, 00, 00, " + // width
36: "04, 00, 00, 00, ]", // height
37: HexDump.toHex(data));
38: }
39:
40: public void testFillFields() throws Exception {
41: String hexData = "10 00 " + "09 F0 " + "10 00 00 00 "
42: + "01 00 00 00 " + "02 00 00 00 " + "03 00 00 00 "
43: + "04 00 00 00 ";
44: byte[] data = HexRead.readFromString(hexData);
45: EscherSpgrRecord r = new EscherSpgrRecord();
46: int bytesWritten = r.fillFields(data,
47: new DefaultEscherRecordFactory());
48:
49: assertEquals(24, bytesWritten);
50: assertEquals(1, r.getRectX1());
51: assertEquals(2, r.getRectY1());
52: assertEquals(3, r.getRectX2());
53: assertEquals(4, r.getRectY2());
54: }
55:
56: public void testToString() throws Exception {
57: String nl = System.getProperty("line.separator");
58:
59: String expected = "org.apache.poi.ddf.EscherSpgrRecord:" + nl
60: + " RecordId: 0xF009" + nl + " Options: 0x0010" + nl
61: + " RectX: 1" + nl + " RectY: 2" + nl
62: + " RectWidth: 3" + nl + " RectHeight: 4" + nl;
63: ;
64: assertEquals(expected, createRecord().toString());
65: }
66:
67: private EscherSpgrRecord createRecord() {
68: EscherSpgrRecord r = new EscherSpgrRecord();
69: r.setOptions((short) 0x0010);
70: r.setRecordId(EscherSpgrRecord.RECORD_ID);
71: r.setRectX1(1);
72: r.setRectY1(2);
73: r.setRectX2(3);
74: r.setRectY2(4);
75: return r;
76: }
77:
78: }
|