KickJava   Java API By Example, From Geeks To Geeks.

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


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

32 public class TestTextRecord
33         extends TestCase
34 {
35     byte[] data = new byte[] {
36         (byte)0x02, // horiz align
37
(byte)0x02, // vert align
38
(byte)0x01,(byte)0x00, // display mode
39
(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, // rgb color
40
(byte)0xD6,(byte)0xFF,(byte)0xFF,(byte)0xFF, // x
41
(byte)0xC4,(byte)0xFF,(byte)0xFF,(byte)0xFF, // y
42
(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, // width
43
(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, // height
44
(byte)0xB1,(byte)0x00, // options 1
45
(byte)0x4D,(byte)0x00, // index of color value
46
(byte)0x50,(byte)0x2B, // options 2 -- strange upper bits supposed to be 0'd
47
(byte)0x00,(byte)0x00 // text rotation
48
};
49
50     public TestTextRecord(String JavaDoc name)
51     {
52         super(name);
53     }
54
55     public void testLoad()
56             throws Exception JavaDoc
57     {
58
59         TextRecord record = new TextRecord((short)0x1025, (short)data.length, data);
60         assertEquals( TextRecord.HORIZONTAL_ALIGNMENT_CENTER, record.getHorizontalAlignment());
61         assertEquals( TextRecord.VERTICAL_ALIGNMENT_CENTER, record.getVerticalAlignment());
62         assertEquals( TextRecord.DISPLAY_MODE_TRANSPARENT, record.getDisplayMode());
63         assertEquals( 0, record.getRgbColor());
64         assertEquals( -42, record.getX());
65         assertEquals( -60, record.getY());
66         assertEquals( 0, record.getWidth());
67         assertEquals( 0, record.getHeight());
68         assertEquals( 177, record.getOptions1());
69         assertEquals( true, record.isAutoColor() );
70         assertEquals( false, record.isShowKey() );
71         assertEquals( false, record.isShowValue() );
72         assertEquals( false, record.isVertical() );
73         assertEquals( true, record.isAutoGeneratedText() );
74         assertEquals( true, record.isGenerated() );
75         assertEquals( false, record.isAutoLabelDeleted() );
76         assertEquals( true, record.isAutoBackground() );
77         assertEquals( TextRecord.ROTATION_NONE, record.getRotation() );
78         assertEquals( false, record.isShowCategoryLabelAsPercentage() );
79         assertEquals( false, record.isShowValueAsPercentage() );
80         assertEquals( false, record.isShowBubbleSizes() );
81         assertEquals( false, record.isShowLabel() );
82         assertEquals( 77, record.getIndexOfColorValue());
83         assertEquals( 11088, record.getOptions2());
84         assertEquals( 0, record.getDataLabelPlacement() );
85         assertEquals( 0, record.getTextRotation());
86
87
88         assertEquals( 36, record.getRecordSize() );
89
90         record.validateSid((short)0x1025);
91
92     }
93
94     public void testStore()
95     {
96         TextRecord record = new TextRecord();
97         record.setHorizontalAlignment( TextRecord.HORIZONTAL_ALIGNMENT_CENTER );
98         record.setVerticalAlignment( TextRecord.VERTICAL_ALIGNMENT_CENTER );
99         record.setDisplayMode( TextRecord.DISPLAY_MODE_TRANSPARENT );
100         record.setRgbColor( 0 );
101         record.setX( -42 );
102         record.setY( -60 );
103         record.setWidth( 0 );
104         record.setHeight( 0 );
105         record.setAutoColor( true );
106         record.setShowKey( false );
107         record.setShowValue( false );
108         record.setVertical( false );
109         record.setAutoGeneratedText( true );
110         record.setGenerated( true );
111         record.setAutoLabelDeleted( false );
112         record.setAutoBackground( true );
113         record.setRotation( TextRecord.ROTATION_NONE );
114         record.setShowCategoryLabelAsPercentage( false );
115         record.setShowValueAsPercentage( false );
116         record.setShowBubbleSizes( false );
117         record.setShowLabel( false );
118         record.setIndexOfColorValue( (short)77 );
119         record.setOptions2( (short)0x2b50 );
120 // record.setDataLabelPlacement( (short)0x2b50 );
121
record.setTextRotation( (short)0 );
122
123
124         byte [] recordBytes = record.serialize();
125         assertEquals(recordBytes.length - 4, data.length);
126         for (int i = 0; i < data.length; i++)
127             assertEquals("At offset " + i, data[i], recordBytes[i+4]);
128     }
129 }
130
Popular Tags