KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > ddf > TestEscherSpgrRecord


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.ddf;
19
20 import junit.framework.TestCase;
21 import org.apache.poi.util.HexDump;
22 import org.apache.poi.util.HexRead;
23
24 public class TestEscherSpgrRecord extends TestCase
25 {
26     public void testSerialize() throws Exception JavaDoc
27     {
28         EscherSpgrRecord r = createRecord();
29
30         byte[] data = new byte[24];
31         int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() );
32         assertEquals( 24, bytesWritten );
33         assertEquals( "[10, 00, " +
34                 "09, F0, " +
35                 "10, 00, 00, 00, " +
36                 "01, 00, 00, 00, " + // x
37
"02, 00, 00, 00, " + // y
38
"03, 00, 00, 00, " + // width
39
"04, 00, 00, 00, ]", // height
40
HexDump.toHex( data ) );
41     }
42
43     public void testFillFields() throws Exception JavaDoc
44     {
45         String JavaDoc hexData = "10 00 " +
46                 "09 F0 " +
47                 "10 00 00 00 " +
48                 "01 00 00 00 " +
49                 "02 00 00 00 " +
50                 "03 00 00 00 " +
51                 "04 00 00 00 ";
52         byte[] data = HexRead.readFromString( hexData );
53         EscherSpgrRecord r = new EscherSpgrRecord();
54         int bytesWritten = r.fillFields( data, new DefaultEscherRecordFactory() );
55
56         assertEquals( 24, bytesWritten );
57         assertEquals( 1, r.getRectX1() );
58         assertEquals( 2, r.getRectY1() );
59         assertEquals( 3, r.getRectX2() );
60         assertEquals( 4, r.getRectY2() );
61     }
62
63     public void testToString() throws Exception JavaDoc
64     {
65         String JavaDoc nl = System.getProperty("line.separator");
66
67         String JavaDoc expected = "org.apache.poi.ddf.EscherSpgrRecord:" + nl +
68                 " RecordId: 0xF009" + nl +
69                 " Options: 0x0010" + nl +
70                 " RectX: 1" + nl +
71                 " RectY: 2" + nl +
72                 " RectWidth: 3" + nl +
73                 " RectHeight: 4" + nl;
74                 ;
75         assertEquals( expected, createRecord().toString() );
76     }
77
78     private EscherSpgrRecord createRecord()
79     {
80         EscherSpgrRecord r = new EscherSpgrRecord();
81         r.setOptions( (short) 0x0010 );
82         r.setRecordId( EscherSpgrRecord.RECORD_ID );
83         r.setRectX1(1);
84         r.setRectY1(2);
85         r.setRectX2(3);
86         r.setRectY2(4);
87         return r;
88     }
89
90 }
91
Popular Tags