KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.poi.hssf.record;
19
20
21 import junit.framework.TestCase;
22
23 /**
24  * Tests the serialization and deserialization of the FontBasisRecord
25  * class works correctly. Test data taken directly from a real
26  * Excel file.
27  *
28
29  * @author Glen Stampoultzis (glens at apache.org)
30  */

31 public class TestFontBasisRecord
32         extends TestCase
33 {
34     byte[] data = new byte[] {
35         (byte)0x28,(byte)0x1A, // x basis
36
(byte)0x9C,(byte)0x0F, // y basis
37
(byte)0xC8,(byte)0x00, // height basis
38
(byte)0x00,(byte)0x00, // scale
39
(byte)0x05,(byte)0x00 // index to font table
40
};
41
42     public TestFontBasisRecord(String JavaDoc name)
43     {
44         super(name);
45     }
46
47     public void testLoad()
48             throws Exception JavaDoc
49     {
50
51         FontBasisRecord record = new FontBasisRecord((short)0x1060, (short)data.length, data);
52         assertEquals( 0x1a28, record.getXBasis());
53         assertEquals( 0x0f9c, record.getYBasis());
54         assertEquals( 0xc8, record.getHeightBasis());
55         assertEquals( 0x00, record.getScale());
56         assertEquals( 0x05, record.getIndexToFontTable());
57
58
59         assertEquals( 14, record.getRecordSize() );
60
61         record.validateSid((short)0x1060);
62     }
63
64     public void testStore()
65     {
66         FontBasisRecord record = new FontBasisRecord();
67         record.setXBasis( (short)0x1a28 );
68         record.setYBasis( (short)0x0f9c );
69         record.setHeightBasis( (short)0xc8 );
70         record.setScale( (short)0x00 );
71         record.setIndexToFontTable( (short)0x05 );
72
73         byte [] recordBytes = record.serialize();
74         assertEquals(recordBytes.length - 4, data.length);
75         for (int i = 0; i < data.length; i++)
76             assertEquals("At offset " + i, data[i], recordBytes[i+4]);
77     }
78 }
79
Popular Tags