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 TestEscherDgRecord extends TestCase {
25: public void testSerialize() throws Exception {
26: EscherDgRecord r = createRecord();
27:
28: byte[] data = new byte[16];
29: int bytesWritten = r.serialize(0, data,
30: new NullEscherSerializationListener());
31: assertEquals(16, bytesWritten);
32: assertEquals("[10, 00, " + "08, F0, " + "08, 00, 00, 00, "
33: + "02, 00, 00, 00, " + // num shapes in drawing
34: "01, 04, 00, 00, ]", // The last MSOSPID given to an SP in this DG
35: HexDump.toHex(data));
36: }
37:
38: public void testFillFields() throws Exception {
39: String hexData = "10 00 " + "08 F0 " + "08 00 00 00 "
40: + "02 00 00 00 " + "01 04 00 00 ";
41: byte[] data = HexRead.readFromString(hexData);
42: EscherDgRecord r = new EscherDgRecord();
43: int bytesWritten = r.fillFields(data,
44: new DefaultEscherRecordFactory());
45:
46: assertEquals(16, bytesWritten);
47: assertEquals(2, r.getNumShapes());
48: assertEquals(1025, r.getLastMSOSPID());
49: }
50:
51: public void testToString() throws Exception {
52: String nl = System.getProperty("line.separator");
53:
54: String expected = "org.apache.poi.ddf.EscherDgRecord:" + nl
55: + " RecordId: 0xF008" + nl + " Options: 0x0010" + nl
56: + " NumShapes: 2" + nl + " LastMSOSPID: 1025" + nl;
57: assertEquals(expected, createRecord().toString());
58: }
59:
60: private EscherDgRecord createRecord() {
61: EscherDgRecord r = new EscherDgRecord();
62: r.setOptions((short) 0x0010);
63: r.setRecordId(EscherDgRecord.RECORD_ID);
64: r.setNumShapes(2);
65: r.setLastMSOSPID(1025);
66: return r;
67: }
68:
69: }
|