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