KickJava   Java API By Example, From Geeks To Geeks.

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


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 AxisOptionsRecord
27  * class works correctly. Test data taken directly from a real
28  * Excel file.
29  *
30
31  * @author Andrew C. Oliver(acoliver at apache.org)
32  */

33 public class TestAxisOptionsRecord
34         extends TestCase
35 {
36     byte[] data = new byte[] {
37         (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x01,
38         (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x01,(byte)0x00,
39         (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
40         (byte)0x00,(byte)0xEF,(byte)0x00
41     };
42
43     public TestAxisOptionsRecord(String JavaDoc name)
44     {
45         super(name);
46     }
47
48     public void testLoad()
49             throws Exception JavaDoc
50     {
51         AxisOptionsRecord record = new AxisOptionsRecord((short)0x1062, (short)data.length, data);
52         assertEquals( 0, record.getMinimumCategory());
53         assertEquals( 0, record.getMaximumCategory());
54         assertEquals( 1, record.getMajorUnitValue());
55         assertEquals( 0, record.getMajorUnit());
56         assertEquals( 1, record.getMinorUnitValue());
57         assertEquals( 0, record.getMinorUnit());
58         assertEquals( 0, record.getBaseUnit());
59         assertEquals( 0, record.getCrossingPoint());
60         assertEquals( 239, record.getOptions());
61         assertEquals( true, record.isDefaultMinimum() );
62         assertEquals( true, record.isDefaultMaximum() );
63         assertEquals( true, record.isDefaultMajor() );
64         assertEquals( true, record.isDefaultMinorUnit() );
65         assertEquals( false, record.isIsDate() );
66         assertEquals( true, record.isDefaultBase() );
67         assertEquals( true, record.isDefaultCross() );
68         assertEquals( true, record.isDefaultDateSettings() );
69
70
71         assertEquals( 22, record.getRecordSize() );
72
73         record.validateSid((short)0x1062);
74     }
75
76     public void testStore()
77     {
78         AxisOptionsRecord record = new AxisOptionsRecord();
79         record.setMinimumCategory( (short)0 );
80         record.setMaximumCategory( (short)0 );
81         record.setMajorUnitValue( (short)1 );
82         record.setMajorUnit( (short)0 );
83         record.setMinorUnitValue( (short)1 );
84         record.setMinorUnit( (short)0 );
85         record.setBaseUnit( (short)0 );
86         record.setCrossingPoint( (short)0 );
87         record.setOptions( (short)239 );
88         record.setDefaultMinimum( true );
89         record.setDefaultMaximum( true );
90         record.setDefaultMajor( true );
91         record.setDefaultMinorUnit( true );
92         record.setIsDate( false );
93         record.setDefaultBase( true );
94         record.setDefaultCross( true );
95         record.setDefaultDateSettings( true );
96
97
98         byte [] recordBytes = record.serialize();
99         assertEquals(recordBytes.length - 4, data.length);
100         for (int i = 0; i < data.length; i++)
101             assertEquals("At offset " + i, data[i], recordBytes[i+4]);
102     }
103
104     /**
105      * The main program for the TestAxisOptionsRecord class
106      *
107      *@param args The command line arguments
108      */

109     public static void main(String JavaDoc[] args) {
110         System.out.println("Testing org.apache.poi.hssf.record.AxisOptionsRecord");
111         junit.textui.TestRunner.run(TestAxisOptionsRecord.class);
112     }
113 }
114
Popular Tags