KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > model > TestDrawingManager


1 /* ====================================================================
2    Copyright 2003-2004 Apache Software Foundation
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 ==================================================================== */

16 package org.apache.poi.hssf.model;
17
18 import junit.framework.TestCase;
19 import org.apache.poi.ddf.EscherDggRecord;
20 import org.apache.poi.ddf.EscherDgRecord;
21
22 public class TestDrawingManager extends TestCase
23 {
24     public void testFindFreeSPIDBlock() throws Exception JavaDoc
25     {
26         EscherDggRecord dgg = new EscherDggRecord();
27         DrawingManager dm = new DrawingManager( dgg );
28         dgg.setShapeIdMax( 1024 );
29         assertEquals( 2048, dm.findFreeSPIDBlock() );
30         dgg.setShapeIdMax( 1025 );
31         assertEquals( 2048, dm.findFreeSPIDBlock() );
32         dgg.setShapeIdMax( 2047 );
33         assertEquals( 2048, dm.findFreeSPIDBlock() );
34     }
35
36     public void testFindNewDrawingGroupId() throws Exception JavaDoc
37     {
38         EscherDggRecord dgg = new EscherDggRecord();
39         dgg.setDrawingsSaved( 1 );
40         dgg.setFileIdClusters( new EscherDggRecord.FileIdCluster[]{
41             new EscherDggRecord.FileIdCluster( 2, 10 )} );
42         DrawingManager dm = new DrawingManager( dgg );
43         assertEquals( 1, dm.findNewDrawingGroupId() );
44         dgg.setFileIdClusters( new EscherDggRecord.FileIdCluster[]{
45             new EscherDggRecord.FileIdCluster( 1, 10 ),
46             new EscherDggRecord.FileIdCluster( 2, 10 )} );
47         assertEquals( 3, dm.findNewDrawingGroupId() );
48     }
49
50     public void testDrawingGroupExists() throws Exception JavaDoc
51     {
52         EscherDggRecord dgg = new EscherDggRecord();
53         dgg.setDrawingsSaved( 1 );
54         dgg.setFileIdClusters( new EscherDggRecord.FileIdCluster[]{
55             new EscherDggRecord.FileIdCluster( 2, 10 )} );
56         DrawingManager dm = new DrawingManager( dgg );
57         assertFalse( dm.drawingGroupExists( (short) 1 ) );
58         assertTrue( dm.drawingGroupExists( (short) 2 ) );
59         assertFalse( dm.drawingGroupExists( (short) 3 ) );
60     }
61
62     public void testCreateDgRecord() throws Exception JavaDoc
63     {
64         EscherDggRecord dgg = new EscherDggRecord();
65         dgg.setDrawingsSaved( 0 );
66         dgg.setFileIdClusters( new EscherDggRecord.FileIdCluster[]{} );
67         DrawingManager dm = new DrawingManager( dgg );
68
69         EscherDgRecord dgRecord = dm.createDgRecord();
70         assertEquals( -1, dgRecord.getLastMSOSPID() );
71         assertEquals( 0, dgRecord.getNumShapes() );
72         assertEquals( 1, dm.getDgg().getDrawingsSaved() );
73         assertEquals( 1, dm.getDgg().getFileIdClusters().length );
74         assertEquals( 1, dm.getDgg().getFileIdClusters()[0].getDrawingGroupId() );
75         assertEquals( 0, dm.getDgg().getFileIdClusters()[0].getNumShapeIdsUsed() );
76     }
77
78     public void testAllocateShapeId() throws Exception JavaDoc
79     {
80         EscherDggRecord dgg = new EscherDggRecord();
81         dgg.setDrawingsSaved( 0 );
82         dgg.setFileIdClusters( new EscherDggRecord.FileIdCluster[]{} );
83         DrawingManager dm = new DrawingManager( dgg );
84
85         EscherDgRecord dg = dm.createDgRecord();
86         int shapeId = dm.allocateShapeId( dg.getDrawingGroupId() );
87         assertEquals( 1024, shapeId );
88         assertEquals( 1025, dgg.getShapeIdMax() );
89         assertEquals( 1, dgg.getDrawingsSaved() );
90         assertEquals( 1, dgg.getFileIdClusters()[0].getDrawingGroupId() );
91         assertEquals( 1, dgg.getFileIdClusters()[0].getNumShapeIdsUsed() );
92         assertEquals( 1024, dg.getLastMSOSPID() );
93         assertEquals( 1, dg.getNumShapes() );
94     }
95
96 }
97
Popular Tags