KickJava   Java API By Example, From Geeks To Geeks.

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


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 TestEscherClientAnchorRecord extends TestCase
25 {
26     public void testSerialize() throws Exception JavaDoc
27     {
28         EscherClientAnchorRecord r = createRecord();
29
30         byte[] data = new byte[8 + 18 + 2];
31         int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() );
32         assertEquals( 28, bytesWritten );
33         assertEquals( "[01, 00, " +
34                 "10, F0, " +
35                 "14, 00, 00, 00, " +
36                 "4D, 00, 37, 00, 21, 00, 58, 00, " +
37                 "0B, 00, 2C, 00, 16, 00, 63, 00, " +
38                 "42, 00, " +
39                 "FF, DD, ]", HexDump.toHex( data ) );
40     }
41
42     public void testFillFields() throws Exception JavaDoc
43     {
44         String JavaDoc hexData = "01 00 " +
45                 "10 F0 " +
46                 "14 00 00 00 " +
47                 "4D 00 37 00 21 00 58 00 " +
48                 "0B 00 2C 00 16 00 63 00 " +
49                 "42 00 " +
50                 "FF DD";
51         byte[] data = HexRead.readFromString( hexData );
52         EscherClientAnchorRecord r = new EscherClientAnchorRecord();
53         int bytesWritten = r.fillFields( data, new DefaultEscherRecordFactory() );
54
55         assertEquals( 28, bytesWritten );
56         assertEquals( (short) 55, r.getCol1() );
57         assertEquals( (short) 44, r.getCol2() );
58         assertEquals( (short) 33, r.getDx1() );
59         assertEquals( (short) 22, r.getDx2() );
60         assertEquals( (short) 11, r.getDy1() );
61         assertEquals( (short) 66, r.getDy2() );
62         assertEquals( (short) 77, r.getFlag() );
63         assertEquals( (short) 88, r.getRow1() );
64         assertEquals( (short) 99, r.getRow2() );
65         assertEquals( (short) 0x0001, r.getOptions() );
66         assertEquals( (byte) 0xFF, r.getRemainingData()[0] );
67         assertEquals( (byte) 0xDD, r.getRemainingData()[1] );
68     }
69
70     public void testToString() throws Exception JavaDoc
71     {
72         String JavaDoc nl = System.getProperty("line.separator");
73
74         String JavaDoc expected = "org.apache.poi.ddf.EscherClientAnchorRecord:" + nl +
75                 " RecordId: 0xF010" + nl +
76                 " Options: 0x0001" + nl +
77                 " Flag: 77" + nl +
78                 " Col1: 55" + nl +
79                 " DX1: 33" + nl +
80                 " Row1: 88" + nl +
81                 " DY1: 11" + nl +
82                 " Col2: 44" + nl +
83                 " DX2: 22" + nl +
84                 " Row2: 99" + nl +
85                 " DY2: 66" + nl +
86                 " Extra Data:" + nl +
87                 "00000000 FF DD .." + nl;
88         assertEquals( expected, createRecord().toString() );
89     }
90
91     private EscherClientAnchorRecord createRecord()
92     {
93         EscherClientAnchorRecord r = new EscherClientAnchorRecord();
94         r.setCol1( (short) 55 );
95         r.setCol2( (short) 44 );
96         r.setDx1( (short) 33 );
97         r.setDx2( (short) 22 );
98         r.setDy1( (short) 11 );
99         r.setDy2( (short) 66 );
100         r.setFlag( (short) 77 );
101         r.setRow1( (short) 88 );
102         r.setRow2( (short) 99 );
103         r.setOptions( (short) 0x0001 );
104         r.setRemainingData( new byte[]{(byte) 0xFF, (byte) 0xDD} );
105         return r;
106     }
107
108 }
109
Popular Tags