KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.poi.hssf.record;
20
21 import junit.framework.TestCase;
22
23 /**
24  * Tests BoundSheetRecord.
25  *
26  * @see BoundSheetRecord
27  *
28  * @author Glen Stampoultzis (glens at apache.org)
29  */

30 public class TestBoundSheetRecord
31         extends TestCase
32 {
33     public TestBoundSheetRecord( String JavaDoc s )
34     {
35         super( s );
36     }
37
38     public void testRecordLength()
39             throws Exception JavaDoc
40     {
41         BoundSheetRecord record = new BoundSheetRecord();
42         record.setCompressedUnicodeFlag((byte)0x00);
43         record.setSheetname("Sheet1");
44         record.setSheetnameLength((byte)6);
45
46         assertEquals(" 2 + 2 + 4 + 2 + 1 + 1 + len(str)", 18, record.getRecordSize());
47     }
48
49     public void testWideRecordLength()
50             throws Exception JavaDoc
51     {
52         BoundSheetRecord record = new BoundSheetRecord();
53         record.setCompressedUnicodeFlag((byte)0x01);
54         record.setSheetname("Sheet1");
55         record.setSheetnameLength((byte)6);
56
57         assertEquals(" 2 + 2 + 4 + 2 + 1 + 1 + len(str) * 2", 24, record.getRecordSize());
58     }
59     
60     public void testName() {
61         BoundSheetRecord record = new BoundSheetRecord();
62         record.setSheetname("1234567890223456789032345678904");
63         assertTrue("Success", true);
64         try {
65             record.setSheetname("12345678902234567890323456789042");
66             assertTrue("Should have thrown IllegalArgumentException, but didnt", false);
67         } catch (IllegalArgumentException JavaDoc e) {
68             assertTrue("succefully threw exception",true);
69         }
70         
71         try {
72             record.setSheetname("s//*s");
73             assertTrue("Should have thrown IllegalArgumentException, but didnt", false);
74         } catch (IllegalArgumentException JavaDoc e) {
75             assertTrue("succefully threw exception",true);
76         }
77             
78     }
79
80 }
81
Popular Tags