1 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 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 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 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 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 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 |