KickJava   Java API By Example, From Geeks To Geeks.

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


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

33 public class TestValueRangeRecord
34         extends TestCase
35 {
36     byte[] data = new byte[] {
37         (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, // min axis value
38
(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, // max axis value
39
(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, // major increment
40
(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, // minor increment
41
(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, // cross over
42
(byte)0x1F,(byte)0x01 // options
43
};
44
45     public TestValueRangeRecord(String JavaDoc name)
46     {
47         super(name);
48     }
49
50     public void testLoad()
51             throws Exception JavaDoc
52     {
53
54         ValueRangeRecord record = new ValueRangeRecord((short)0x101f, (short)data.length, data);
55         assertEquals( 0.0, record.getMinimumAxisValue(), 0.001);
56         assertEquals( 0.0, record.getMaximumAxisValue(), 0.001);
57         assertEquals( 0.0, record.getMajorIncrement(), 0.001);
58         assertEquals( 0.0, record.getMinorIncrement(), 0.001);
59         assertEquals( 0.0, record.getCategoryAxisCross(), 0.001);
60         assertEquals( 0x011f, record.getOptions());
61         assertEquals( true, record.isAutomaticMinimum() );
62         assertEquals( true, record.isAutomaticMaximum() );
63         assertEquals( true, record.isAutomaticMajor() );
64         assertEquals( true, record.isAutomaticMinor() );
65         assertEquals( true, record.isAutomaticCategoryCrossing() );
66         assertEquals( false, record.isLogarithmicScale() );
67         assertEquals( false, record.isValuesInReverse() );
68         assertEquals( false, record.isCrossCategoryAxisAtMaximum() );
69         assertEquals( true, record.isReserved() );
70
71         assertEquals( 42+4, record.getRecordSize() );
72
73         record.validateSid((short)0x101f);
74     }
75
76     public void testStore()
77     {
78         ValueRangeRecord record = new ValueRangeRecord();
79         record.setMinimumAxisValue( 0 );
80         record.setMaximumAxisValue( 0 );
81         record.setMajorIncrement( 0 );
82         record.setMinorIncrement( 0 );
83         record.setCategoryAxisCross( 0 );
84         record.setAutomaticMinimum( true );
85         record.setAutomaticMaximum( true );
86         record.setAutomaticMajor( true );
87         record.setAutomaticMinor( true );
88         record.setAutomaticCategoryCrossing( true );
89         record.setLogarithmicScale( false );
90         record.setValuesInReverse( false );
91         record.setCrossCategoryAxisAtMaximum( false );
92         record.setReserved( true );
93
94         byte [] recordBytes = record.serialize();
95         assertEquals(recordBytes.length - 4, data.length);
96         for (int i = 0; i < data.length; i++)
97             assertEquals("At offset " + i, data[i], recordBytes[i+4]);
98     }
99 }
100
Popular Tags