KickJava   Java API By Example, From Geeks To Geeks.

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


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.HexRead;
22 import org.apache.poi.util.HexDump;
23
24 public class TestEscherContainerRecord extends TestCase
25 {
26     public void testFillFields() throws Exception JavaDoc
27     {
28         EscherRecordFactory f = new DefaultEscherRecordFactory();
29         byte[] data = HexRead.readFromString( "0F 02 11 F1 00 00 00 00" );
30         EscherRecord r = f.createRecord( data, 0 );
31         r.fillFields( data, 0, f );
32         assertTrue( r instanceof EscherContainerRecord );
33         assertEquals( (short) 0x020F, r.getOptions() );
34         assertEquals( (short) 0xF111, r.getRecordId() );
35
36         data = HexRead.readFromString( "0F 02 11 F1 08 00 00 00" +
37                 " 02 00 22 F2 00 00 00 00" );
38         r = f.createRecord( data, 0 );
39         r.fillFields( data, 0, f );
40         EscherRecord c = r.getChild( 0 );
41         assertFalse( c instanceof EscherContainerRecord );
42         assertEquals( (short) 0x0002, c.getOptions() );
43         assertEquals( (short) 0xF222, c.getRecordId() );
44     }
45
46     public void testSerialize() throws Exception JavaDoc
47     {
48         UnknownEscherRecord r = new UnknownEscherRecord();
49         r.setOptions( (short) 0x123F );
50         r.setRecordId( (short) 0xF112 );
51         byte[] data = new byte[8];
52         r.serialize( 0, data, new NullEscherSerializationListener() );
53
54         assertEquals( "[3F, 12, 12, F1, 00, 00, 00, 00, ]", HexDump.toHex( data ) );
55
56         EscherRecord childRecord = new UnknownEscherRecord();
57         childRecord.setOptions( (short) 0x9999 );
58         childRecord.setRecordId( (short) 0xFF01 );
59         r.addChildRecord( childRecord );
60         data = new byte[16];
61         r.serialize( 0, data, new NullEscherSerializationListener() );
62
63         assertEquals( "[3F, 12, 12, F1, 08, 00, 00, 00, 99, 99, 01, FF, 00, 00, 00, 00, ]", HexDump.toHex( data ) );
64
65     }
66
67     public void testToString() throws Exception JavaDoc
68     {
69         EscherContainerRecord r = new EscherContainerRecord();
70         r.setRecordId( EscherContainerRecord.SP_CONTAINER );
71         r.setOptions( (short) 0x000F );
72         String JavaDoc nl = System.getProperty( "line.separator" );
73         assertEquals( "org.apache.poi.ddf.EscherContainerRecord (SpContainer):" + nl +
74                 " isContainer: true" + nl +
75                 " options: 0x000F" + nl +
76                 " recordId: 0xF004" + nl +
77                 " numchildren: 0" + nl
78                 , r.toString() );
79
80         EscherOptRecord r2 = new EscherOptRecord();
81         r2.setOptions( (short) 0x9876 );
82         r2.setRecordId( EscherOptRecord.RECORD_ID );
83
84         r.addChildRecord( r2 );
85         String JavaDoc expected = "org.apache.poi.ddf.EscherContainerRecord (SpContainer):" + nl +
86                         " isContainer: true" + nl +
87                         " options: 0x000F" + nl +
88                         " recordId: 0xF004" + nl +
89                         " numchildren: 1" + nl +
90                         " children: " + nl +
91                         "org.apache.poi.ddf.EscherOptRecord:" + nl +
92                         " isContainer: false" + nl +
93                         " options: 0x0003" + nl +
94                         " recordId: 0xF00B" + nl +
95                         " numchildren: 0" + nl +
96                         " properties:" + nl;
97         assertEquals( expected, r.toString() );
98
99     }
100
101     public void testGetRecordSize() throws Exception JavaDoc
102     {
103         EscherContainerRecord r = new EscherContainerRecord();
104         r.addChildRecord(new EscherRecord()
105         {
106             public int fillFields( byte[] data, int offset, EscherRecordFactory recordFactory ) { return 0; }
107             public int serialize( int offset, byte[] data, EscherSerializationListener listener ) { return 0; }
108             public int getRecordSize() { return 10; }
109             public String JavaDoc getRecordName() { return ""; }
110         } );
111
112         assertEquals(18, r.getRecordSize());
113     }
114
115 }
116
Popular Tags