KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > ddf > TestEscherDggRecord


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        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 {
26     public void testSerialize() throws Exception JavaDoc
27     {
28         EscherDggRecord r = createRecord();
29
30         byte[] data = new byte[32];
31         int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() );
32         assertEquals( 32, bytesWritten );
33         assertEquals( "[00, 00, " +
34                 "06, F0, " +
35                 "18, 00, 00, 00, " +
36                 "02, 04, 00, 00, " +
37                 "02, 00, 00, 00, " +
38                 "02, 00, 00, 00, " +
39                 "01, 00, 00, 00, " +
40                 "01, 00, 00, 00, 02, 00, 00, 00, ]",
41                 HexDump.toHex( data ) );
42     }
43
44     public void testFillFields() throws Exception JavaDoc
45     {
46         String JavaDoc hexData = "00 00 " +
47                 "06 F0 " +
48                 "18 00 00 00 " +
49                 "02 04 00 00 " +
50                 "02 00 00 00 " +
51                 "02 00 00 00 " +
52                 "01 00 00 00 " +
53                 "01 00 00 00 02 00 00 00";
54         byte[] data = HexRead.readFromString( hexData );
55         EscherDggRecord r = new EscherDggRecord();
56         int bytesWritten = r.fillFields( data, new DefaultEscherRecordFactory() );
57
58         assertEquals( 32, bytesWritten );
59         assertEquals( 0x402, r.getShapeIdMax() );
60         assertEquals( 0x02, r.getNumIdClusters() );
61         assertEquals( 0x02, r.getNumShapesSaved() );
62         assertEquals( 0x01, r.getDrawingsSaved() );
63         assertEquals( 1, r.getFileIdClusters().length );
64         assertEquals( 0x01, r.getFileIdClusters()[0].getDrawingGroupId());
65         assertEquals( 0x02, r.getFileIdClusters()[0].getNumShapeIdsUsed());
66     }
67
68     public void testToString() throws Exception JavaDoc
69     {
70         String JavaDoc nl = System.getProperty("line.separator");
71
72         String JavaDoc expected = "org.apache.poi.ddf.EscherDggRecord:" + nl +
73                 " RecordId: 0xF006" + nl +
74                 " Options: 0x0000" + nl +
75                 " ShapeIdMax: 1026" + nl +
76                 " NumIdClusters: 2" + nl +
77                 " NumShapesSaved: 2" + nl +
78                 " DrawingsSaved: 1" + nl +
79                 " DrawingGroupId1: 1" + nl +
80                 " NumShapeIdsUsed1: 2" + nl;
81         assertEquals( expected, createRecord().toString() );
82     }
83
84     private EscherDggRecord createRecord()
85     {
86         EscherDggRecord r = new EscherDggRecord();
87         r.setOptions( (short) 0x0000 );
88         r.setRecordId( EscherDggRecord.RECORD_ID );
89         r.setShapeIdMax( 0x402 );
90         r.setNumShapesSaved( 0x02 );
91         r.setDrawingsSaved( 0x01 );
92         r.setFileIdClusters(new EscherDggRecord.FileIdCluster[] {
93             new EscherDggRecord.FileIdCluster( 1, 2 )
94         });
95         return r;
96     }
97
98     public void testGetRecordSize() throws Exception JavaDoc
99     {
100         EscherDggRecord r = new EscherDggRecord();
101         r.setFileIdClusters(new EscherDggRecord.FileIdCluster[] { new EscherDggRecord.FileIdCluster(0,0) } );
102         assertEquals(32,r.getRecordSize());
103
104     }
105
106 }
107
Popular Tags