KickJava   Java API By Example, From Geeks To Geeks.

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


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 TickRecord
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 TestTickRecord
34         extends TestCase
35 {
36     byte[] data = new byte[] {
37     (byte)0x02, (byte)0x00, (byte)0x03, (byte)0x01,
38         (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
39         (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
40     (byte)0x00, (byte)0x00, (byte)0x00,
41     (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
42     (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x23, (byte)0x00,
43     (byte)0x4D, (byte)0x00, (byte)0x00, (byte)0x00
44     };
45
46     public TestTickRecord(String JavaDoc name)
47     {
48         super(name);
49     }
50
51     public void testLoad()
52             throws Exception JavaDoc
53     {
54         TickRecord record = new TickRecord((short)0x101e, (short)data.length, data);
55         assertEquals( (byte)2, record.getMajorTickType());
56         assertEquals( (byte)0, record.getMinorTickType());
57         assertEquals( (byte)3, record.getLabelPosition());
58         assertEquals( (short)1, record.getBackground());
59         assertEquals( 0, record.getLabelColorRgb());
60         assertEquals( (short)0, record.getZero1());
61         assertEquals( (short)0, record.getZero2());
62         assertEquals( (short)35, record.getOptions());
63         assertEquals( true, record.isAutoTextColor() );
64         assertEquals( true, record.isAutoTextBackground() );
65         assertEquals( (short)0x0, record.getRotation() );
66         assertEquals( true, record.isAutorotate() );
67         assertEquals( (short)77, record.getTickColor());
68         assertEquals( (short)0x0, record.getZero3());
69
70
71         assertEquals( 34, record.getRecordSize() );
72
73         record.validateSid((short)0x101e);
74     }
75
76     public void testStore()
77     {
78         TickRecord record = new TickRecord();
79         record.setMajorTickType( (byte)2 );
80         record.setMinorTickType( (byte)0 );
81         record.setLabelPosition( (byte)3 );
82         record.setBackground( (byte)1 );
83         record.setLabelColorRgb( 0 );
84         record.setZero1( (short)0 );
85         record.setZero2( (short)0 );
86         record.setOptions( (short)35 );
87         record.setAutoTextColor( true );
88         record.setAutoTextBackground( true );
89         record.setRotation( (short)0 );
90         record.setAutorotate( true );
91         record.setTickColor( (short)77 );
92         record.setZero3( (short)0 );
93
94
95         byte [] recordBytes = record.serialize();
96         assertEquals(recordBytes.length - 4, data.length);
97         for (int i = 0; i < data.length; i++)
98             assertEquals("At offset " + i, data[i], recordBytes[i+4]);
99     }
100     
101     
102     /**
103      * The main program for the TestTickRecord class
104      *
105      *@param args The command line arguments
106      */

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