KickJava   Java API By Example, From Geeks To Geeks.

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


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
19
20 package org.apache.poi.hssf.record;
21
22
23 import junit.framework.TestCase;
24
25 /**
26  * Tests the serialization and deserialization of the SupBook record
27  * class works correctly.
28  *
29  * @author Andrew C. Oliver (acoliver at apache dot org)
30  */

31 public class TestSupBookRecord
32         extends TestCase
33 {
34     /**
35      * This contains a fake data section of a SubBookRecord
36      */

37     byte[] data = new byte[] {
38         (byte)0x04,(byte)0x00,(byte)0x01,(byte)0x04
39     };
40
41     public TestSupBookRecord(String JavaDoc name)
42     {
43         super(name);
44     }
45
46     /**
47      * tests that we can load the record
48      */

49     public void testLoad()
50             throws Exception JavaDoc
51     {
52
53         SupBookRecord record = new SupBookRecord((short)0x01AE, (short)data.length, data);
54         assertEquals( 0x401, record.getFlag()); //expected flag
55
assertEquals( 0x4, record.getNumberOfSheets() ); //expected # of sheets
56

57         assertEquals( 8, record.getRecordSize() ); //sid+size+data
58

59         record.validateSid((short)0x01AE);
60     }
61     
62     
63     /**
64      * Tests that we can store the record
65      *
66      */

67     public void testStore()
68     {
69         SupBookRecord record = new SupBookRecord();
70         record.setFlag( (short) 0x401 );
71         record.setNumberOfSheets( (short)0x4 );
72         
73
74
75         byte [] recordBytes = record.serialize();
76         assertEquals(recordBytes.length - 4, data.length);
77         for (int i = 0; i < data.length; i++)
78             assertEquals("At offset " + i, data[i], recordBytes[i+4]);
79     }
80     
81     public static void main(String JavaDoc [] args) {
82         System.out
83         .println("Testing org.apache.poi.hssf.record.SupBookRecord");
84         junit.textui.TestRunner.run(TestSupBookRecord.class);
85     }
86     
87
88 }
89
Popular Tags