KickJava   Java API By Example, From Geeks To Geeks.

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


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 TestEscherChildAnchorRecord extends TestCase
25 {
26     public void testSerialize() throws Exception JavaDoc
27     {
28         EscherChildAnchorRecord r = createRecord();
29
30         byte[] data = new byte[8 + 16];
31         int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() );
32         assertEquals( 24, bytesWritten );
33         assertEquals( "[01, 00, " +
34                 "0F, F0, " +
35                 "10, 00, 00, 00, " +
36                 "01, 00, 00, 00, " +
37                 "02, 00, 00, 00, " +
38                 "03, 00, 00, 00, " +
39                 "04, 00, 00, 00, ]", HexDump.toHex( data ) );
40     }
41
42     public void testFillFields() throws Exception JavaDoc
43     {
44         String JavaDoc hexData = "01 00 " +
45                 "0F F0 " +
46                 "10 00 00 00 " +
47                 "01 00 00 00 " +
48                 "02 00 00 00 " +
49                 "03 00 00 00 " +
50                 "04 00 00 00 ";
51
52         byte[] data = HexRead.readFromString( hexData );
53         EscherChildAnchorRecord r = new EscherChildAnchorRecord();
54         int bytesWritten = r.fillFields( data, new DefaultEscherRecordFactory() );
55
56         assertEquals( 24, bytesWritten );
57         assertEquals( 1, r.getDx1() );
58         assertEquals( 2, r.getDy1() );
59         assertEquals( 3, r.getDx2() );
60         assertEquals( 4, r.getDy2() );
61         assertEquals( (short) 0x0001, r.getOptions() );
62     }
63
64     public void testToString() throws Exception JavaDoc
65     {
66         String JavaDoc nl = System.getProperty( "line.separator" );
67
68         String JavaDoc expected = "org.apache.poi.ddf.EscherChildAnchorRecord:" + nl +
69                 " RecordId: 0xF00F" + nl +
70                 " Options: 0x0001" + nl +
71                 " X1: 1" + nl +
72                 " Y1: 2" + nl +
73                 " X2: 3" + nl +
74                 " Y2: 4" + nl;
75         assertEquals( expected, createRecord().toString() );
76     }
77
78     private EscherChildAnchorRecord createRecord()
79     {
80         EscherChildAnchorRecord r = new EscherChildAnchorRecord();
81         r.setRecordId( EscherChildAnchorRecord.RECORD_ID );
82         r.setOptions( (short) 0x0001 );
83         r.setDx1( 1 );
84         r.setDy1( 2 );
85         r.setDx2( 3 );
86         r.setDy2( 4 );
87         return r;
88     }
89
90 }
91
Popular Tags