KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > TestSubRecord


1 /* ====================================================================
2    Copyright 2002-2004 Apache Software Foundation
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 ==================================================================== */

16
17
18 package org.apache.poi.hssf.record;
19
20
21 import junit.framework.TestCase;
22
23 /**
24  * Tests Subrecord components of an OBJ record. Test data taken directly
25  * from a real Excel file.
26  *
27  * @author Michael Zalewski (zalewski@optonline.net)
28  */

29 public class TestSubRecord
30         extends TestCase
31 {
32     /*
33        The following is a dump of the OBJ record corresponding to an auto-filter
34        drop-down list. The 3rd subrecord beginning at offset 0x002e (type=0x0013)
35        does not conform to the documentation, because the length field is 0x1fee,
36        which is longer than the entire OBJ record.
37
38        00000000 15 00 12 00 14 00 01 00 01 21 00 00 00 00 3C 13 .........!....<. Type=0x15 Len=0x0012 ftCmo
39        00000010 F4 03 00 00 00 00
40                                   0C 00 14 00 00 00 00 00 00 00 ................ Type=0x0c Len=0x0014 ftSbs
41        00000020 00 00 00 00 01 00 08 00 00 00 10 00 00 00
42                                                           13 00 ................ Type=0x13 Len=0x1FEE ftLbsData
43        00000030 EE 1F 00 00 08 00 08 00 01 03 00 00 0A 00 14 00 ................
44        00000040 6C 00
45                       00 00 00 00 l..... Type=0x00 Len=0x0000 ftEnd
46     */

47
48     byte[] dataAutoFilter = new byte[]{
49         // ftCmo
50
(byte) 0x15, (byte) 0x00, (byte) 0x12, (byte) 0x00, (byte) 0x14, (byte) 0x00, (byte) 0x01, (byte) 0x00
51         , (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x21, (byte) 0x00, (byte) 0x00, (byte) 0x3c, (byte) 0x13
52         , (byte) 0xf4, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
53
54         // ftSbs (currently UnknownSubrecord)
55
, (byte) 0x0c, (byte) 0x00
56         , (byte) 0x14, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
57         , (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x08, (byte) 0x00
58         , (byte) 0x00, (byte) 0x00, (byte) 0x10, (byte) 0x00, (byte) 0x00, (byte) 0x00
59
60         // ftLbsData (currently UnknownSubrecord)
61
, (byte) 0x13, (byte) 0x00
62         , (byte) 0xee, (byte) 0x1f, (byte) 0x00, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x08, (byte) 0x00
63         , (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x0a, (byte) 0x00, (byte) 0x14, (byte) 0x00
64         , (byte) 0x6c, (byte) 0x00
65
66         // ftEnd
67
, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
68     };
69
70     public TestSubRecord( String JavaDoc name )
71     {
72         super( name );
73     }
74
75     public void testParseCmo()
76     {
77         Record r = SubRecord.createSubRecord( (short) 0x0015, (short) 0x0012, dataAutoFilter, 0x0000 );
78         assertEquals( "ftCmo is 22 bytes", 22, r.getRecordSize() );
79         assertEquals( "ftCmo is a CommonObjectDataSubRecord"
80                 , "org.apache.poi.hssf.record.CommonObjectDataSubRecord"
81                 , r.getClass().getName() );
82     }
83
84     public void testParseAutoFilterLbsData()
85     {
86         Record r = SubRecord.createSubRecord( (short) 0x0013, (short) 0x1fee, dataAutoFilter, 0x0032 );
87         assertEquals( "ftLbsData is 20 bytes", 20, r.getRecordSize() );
88     }
89
90     public void testParseEnd()
91     {
92         Record r = SubRecord.createSubRecord( (short) 0x0000, (short) 0x0000, dataAutoFilter, 0x0046 );
93         assertEquals( "ftEnd is 4 bytes", 4, r.getRecordSize() );
94         assertEquals( "ftEnd is a EndSubRecord"
95                 , "org.apache.poi.hssf.record.EndSubRecord"
96                 , r.getClass().getName() );
97     }
98 }
99
Popular Tags