KickJava   Java API By Example, From Geeks To Geeks.

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


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 TestUnknownEscherRecord extends TestCase
25 {
26     public void testFillFields() throws Exception JavaDoc
27     {
28         String JavaDoc testData =
29                 "0F 02 " + // options
30
"11 F1 " + // record id
31
"00 00 00 00"; // remaining bytes
32

33         UnknownEscherRecord r = new UnknownEscherRecord();
34         EscherRecordFactory factory = new DefaultEscherRecordFactory();
35         r.fillFields( HexRead.readFromString( testData ), factory );
36
37         assertEquals( 0x020F, r.getOptions() );
38         assertEquals( (short) 0xF111, r.getRecordId() );
39         assertTrue( r.isContainerRecord() );
40         assertEquals( 8, r.getRecordSize() );
41         assertEquals( 0, r.getChildRecords().size() );
42         assertEquals( 0, r.getData().length );
43
44         testData =
45                 "00 02 " + // options
46
"11 F1 " + // record id
47
"04 00 00 00 " + // remaining bytes
48
"01 02 03 04";
49
50         r = new UnknownEscherRecord();
51         r.fillFields( HexRead.readFromString( testData ), factory );
52
53         assertEquals( 0x0200, r.getOptions() );
54         assertEquals( (short) 0xF111, r.getRecordId() );
55         assertEquals( 12, r.getRecordSize() );
56         assertFalse( r.isContainerRecord() );
57         assertEquals( 0, r.getChildRecords().size() );
58         assertEquals( 4, r.getData().length );
59         assertEquals( 1, r.getData()[0] );
60         assertEquals( 2, r.getData()[1] );
61         assertEquals( 3, r.getData()[2] );
62         assertEquals( 4, r.getData()[3] );
63
64         testData =
65                 "0F 02 " + // options
66
"11 F1 " + // record id
67
"08 00 00 00 " + // remaining bytes
68
"00 02 " + // options
69
"FF FF " + // record id
70
"00 00 00 00"; // remaining bytes
71

72         r = new UnknownEscherRecord();
73         r.fillFields( HexRead.readFromString( testData ), factory );
74
75         assertEquals( 0x020F, r.getOptions() );
76         assertEquals( (short) 0xF111, r.getRecordId() );
77         assertEquals( 8, r.getRecordSize() );
78         assertTrue( r.isContainerRecord() );
79         assertEquals( 1, r.getChildRecords().size() );
80         assertEquals( (short) 0xFFFF, r.getChild( 0 ).getRecordId() );
81
82     }
83
84     public void testSerialize() throws Exception JavaDoc
85     {
86         UnknownEscherRecord r = new UnknownEscherRecord();
87         r.setOptions( (short) 0x1234 );
88         r.setRecordId( (short) 0xF112 );
89         byte[] data = new byte[8];
90         r.serialize( 0, data, new NullEscherSerializationListener() );
91
92         assertEquals( "[34, 12, 12, F1, 00, 00, 00, 00, ]", HexDump.toHex( data ) );
93
94         EscherRecord childRecord = new UnknownEscherRecord();
95         childRecord.setOptions( (short) 0x9999 );
96         childRecord.setRecordId( (short) 0xFF01 );
97         r.addChildRecord( childRecord );
98         r.setOptions( (short) 0x123F );
99         data = new byte[16];
100         r.serialize( 0, data, new NullEscherSerializationListener() );
101
102         assertEquals( "[3F, 12, 12, F1, 08, 00, 00, 00, 99, 99, 01, FF, 00, 00, 00, 00, ]", HexDump.toHex( data ) );
103     }
104
105     public void testToString() throws Exception JavaDoc
106     {
107         UnknownEscherRecord r = new UnknownEscherRecord();
108         r.setOptions( (short) 0x1234 );
109         r.setRecordId( (short) 0xF112 );
110         byte[] data = new byte[8];
111         r.serialize( 0, data, new NullEscherSerializationListener() );
112
113         String JavaDoc nl = System.getProperty("line.separator");
114         assertEquals( "org.apache.poi.ddf.UnknownEscherRecord:" + nl +
115                 " isContainer: false" + nl +
116                 " options: 0x1234" + nl +
117                 " recordId: 0xF112" + nl +
118                 " numchildren: 0" + nl
119                 , r.toString() );
120     }
121
122
123 }
124
Popular Tags