KickJava   Java API By Example, From Geeks To Geeks.

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


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 TestEscherDgRecord extends TestCase
25 {
26     public void testSerialize() throws Exception JavaDoc
27     {
28         EscherDgRecord r = createRecord();
29
30         byte[] data = new byte[16];
31         int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() );
32         assertEquals( 16, bytesWritten );
33         assertEquals( "[10, 00, " +
34                 "08, F0, " +
35                 "08, 00, 00, 00, " +
36                 "02, 00, 00, 00, " + // num shapes in drawing
37
"01, 04, 00, 00, ]", // The last MSOSPID given to an SP in this DG
38
HexDump.toHex( data ) );
39     }
40
41     public void testFillFields() throws Exception JavaDoc
42     {
43         String JavaDoc hexData = "10 00 " +
44                 "08 F0 " +
45                 "08 00 00 00 " +
46                 "02 00 00 00 " +
47                 "01 04 00 00 ";
48         byte[] data = HexRead.readFromString( hexData );
49         EscherDgRecord r = new EscherDgRecord();
50         int bytesWritten = r.fillFields( data, new DefaultEscherRecordFactory() );
51
52         assertEquals( 16, bytesWritten );
53         assertEquals( 2, r.getNumShapes() );
54         assertEquals( 1025, r.getLastMSOSPID() );
55     }
56
57     public void testToString() throws Exception JavaDoc
58     {
59         String JavaDoc nl = System.getProperty("line.separator");
60
61         String JavaDoc expected = "org.apache.poi.ddf.EscherDgRecord:" + nl +
62                 " RecordId: 0xF008" + nl +
63                 " Options: 0x0010" + nl +
64                 " NumShapes: 2" + nl +
65                 " LastMSOSPID: 1025" + nl;
66         assertEquals( expected, createRecord().toString() );
67     }
68
69     private EscherDgRecord createRecord()
70     {
71         EscherDgRecord r = new EscherDgRecord();
72         r.setOptions( (short) 0x0010 );
73         r.setRecordId( EscherDgRecord.RECORD_ID );
74         r.setNumShapes(2);
75         r.setLastMSOSPID(1025);
76         return r;
77     }
78
79 }
80
Popular Tags