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: package org.apache.poi.hssf.model;
18:
19: import junit.framework.TestCase;
20: import org.apache.poi.ddf.EscherDggRecord;
21: import org.apache.poi.ddf.EscherDgRecord;
22:
23: public class TestDrawingManager2 extends TestCase {
24: private DrawingManager2 drawingManager2;
25: private EscherDggRecord dgg;
26:
27: protected void setUp() throws Exception {
28: super .setUp();
29: dgg = new EscherDggRecord();
30: dgg.setFileIdClusters(new EscherDggRecord.FileIdCluster[0]);
31: drawingManager2 = new DrawingManager2(dgg);
32: }
33:
34: public void testCreateDgRecord() throws Exception {
35: EscherDgRecord dgRecord1 = drawingManager2.createDgRecord();
36: assertEquals(1, dgRecord1.getDrawingGroupId());
37: assertEquals(-1, dgRecord1.getLastMSOSPID());
38:
39: EscherDgRecord dgRecord2 = drawingManager2.createDgRecord();
40: assertEquals(2, dgRecord2.getDrawingGroupId());
41: assertEquals(-1, dgRecord2.getLastMSOSPID());
42:
43: assertEquals(2, dgg.getDrawingsSaved());
44: assertEquals(2, dgg.getFileIdClusters().length);
45: assertEquals(3, dgg.getNumIdClusters());
46: assertEquals(0, dgg.getNumShapesSaved());
47: }
48:
49: public void testAllocateShapeId() throws Exception {
50: EscherDgRecord dgRecord1 = drawingManager2.createDgRecord();
51: EscherDgRecord dgRecord2 = drawingManager2.createDgRecord();
52:
53: assertEquals(1024, drawingManager2.allocateShapeId((short) 1));
54: assertEquals(1024, dgRecord1.getLastMSOSPID());
55: assertEquals(1025, dgg.getShapeIdMax());
56: assertEquals(1025, drawingManager2.allocateShapeId((short) 1));
57: assertEquals(1025, dgRecord1.getLastMSOSPID());
58: assertEquals(1026, dgg.getShapeIdMax());
59: assertEquals(1026, drawingManager2.allocateShapeId((short) 1));
60: assertEquals(1026, dgRecord1.getLastMSOSPID());
61: assertEquals(1027, dgg.getShapeIdMax());
62: assertEquals(2048, drawingManager2.allocateShapeId((short) 2));
63: assertEquals(2048, dgRecord2.getLastMSOSPID());
64: assertEquals(2049, dgg.getShapeIdMax());
65:
66: for (int i = 0; i < 1021; i++) {
67: drawingManager2.allocateShapeId((short) 1);
68: assertEquals(2049, dgg.getShapeIdMax());
69: }
70: assertEquals(3072, drawingManager2.allocateShapeId((short) 1));
71: assertEquals(3073, dgg.getShapeIdMax());
72:
73: assertEquals(2, dgg.getDrawingsSaved());
74: assertEquals(4, dgg.getNumIdClusters());
75: assertEquals(1026, dgg.getNumShapesSaved());
76: }
77: }
|