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 TestEscherChildAnchorRecord extends TestCase {
25: public void testSerialize() throws Exception {
26: EscherChildAnchorRecord r = createRecord();
27:
28: byte[] data = new byte[8 + 16];
29: int bytesWritten = r.serialize(0, data,
30: new NullEscherSerializationListener());
31: assertEquals(24, bytesWritten);
32: assertEquals("[01, 00, " + "0F, F0, " + "10, 00, 00, 00, "
33: + "01, 00, 00, 00, " + "02, 00, 00, 00, "
34: + "03, 00, 00, 00, " + "04, 00, 00, 00, ]", HexDump
35: .toHex(data));
36: }
37:
38: public void testFillFields() throws Exception {
39: String hexData = "01 00 " + "0F F0 " + "10 00 00 00 "
40: + "01 00 00 00 " + "02 00 00 00 " + "03 00 00 00 "
41: + "04 00 00 00 ";
42:
43: byte[] data = HexRead.readFromString(hexData);
44: EscherChildAnchorRecord r = new EscherChildAnchorRecord();
45: int bytesWritten = r.fillFields(data,
46: new DefaultEscherRecordFactory());
47:
48: assertEquals(24, bytesWritten);
49: assertEquals(1, r.getDx1());
50: assertEquals(2, r.getDy1());
51: assertEquals(3, r.getDx2());
52: assertEquals(4, r.getDy2());
53: assertEquals((short) 0x0001, r.getOptions());
54: }
55:
56: public void testToString() throws Exception {
57: String nl = System.getProperty("line.separator");
58:
59: String expected = "org.apache.poi.ddf.EscherChildAnchorRecord:"
60: + nl + " RecordId: 0xF00F" + nl + " Options: 0x0001"
61: + nl + " X1: 1" + nl + " Y1: 2" + nl + " X2: 3" + nl
62: + " Y2: 4" + nl;
63: assertEquals(expected, createRecord().toString());
64: }
65:
66: private EscherChildAnchorRecord createRecord() {
67: EscherChildAnchorRecord r = new EscherChildAnchorRecord();
68: r.setRecordId(EscherChildAnchorRecord.RECORD_ID);
69: r.setOptions((short) 0x0001);
70: r.setDx1(1);
71: r.setDy1(2);
72: r.setDx2(3);
73: r.setDy2(4);
74: return r;
75: }
76:
77: }
|