KickJava   Java API By Example, From Geeks To Geeks.

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


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 TestEscherBlipRecord extends TestCase
25 {
26     private String JavaDoc dataStr;
27     private byte[] data;
28
29     protected void setUp() throws Exception JavaDoc
30     {
31         dataStr = "2C 15 18 F0 34 00 00 00 01 01 01 01 01 01 01 01 " +
32                         "01 01 01 01 01 01 01 01 06 00 00 00 03 00 00 00 " +
33                         "01 00 00 00 04 00 00 00 02 00 00 00 0A 00 00 00 " +
34                         "0B 00 00 00 05 00 00 00 08 07 01 02";
35         data = HexRead.readFromString(dataStr);
36     }
37
38     public void testSerialize() throws Exception JavaDoc
39     {
40         EscherBlipRecord r = new EscherBlipRecord();
41         r.setBoundaryLeft(1);
42         r.setBoundaryHeight(2);
43         r.setBoundaryTop(3);
44         r.setBoundaryWidth(4);
45         r.setCacheOfSavedSize(5);
46         r.setCacheOfSize(6);
47         r.setFilter((byte)7);
48         r.setCompressionFlag((byte)8);
49         r.setSecondaryUID(new byte[] { (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01,
50                                        (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01,
51                                        (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01,
52                                        (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, });
53         r.setWidth(10);
54         r.setHeight(11);
55         r.setRecordId(EscherBlipRecord.RECORD_ID_START);
56         r.setOptions((short)5420);
57         r.setData(new byte[] { (byte)0x01, (byte)0x02 } );
58
59         byte[] buf = new byte[r.getRecordSize()];
60         r.serialize(0, buf, new NullEscherSerializationListener() );
61
62         assertEquals("[2C, 15, 18, F0, 26, 00, 00, 00, " +
63                 "01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, " +
64                 "06, 00, 00, 00, " + // field_2_cacheOfSize
65
"03, 00, 00, 00, " + // field_3_boundaryTop
66
"01, 00, 00, 00, " + // field_4_boundaryLeft
67
"04, 00, 00, 00, " + // field_5_boundaryWidth
68
"02, 00, 00, 00, " + // field_6_boundaryHeight
69
"0A, 00, 00, 00, " + // field_7_x
70
"0B, 00, 00, 00, " + // field_8_y
71
"05, 00, 00, 00, " + // field_9_cacheOfSavedSize
72
"08, " + // field_10_compressionFlag
73
"07, " + // field_11_filter
74
"01, 02, ]", // field_12_data
75
HexDump.toHex(buf));
76         assertEquals(60, r.getRecordSize() );
77
78     }
79
80     public void testFillFields() throws Exception JavaDoc
81     {
82         EscherBlipRecord r = new EscherBlipRecord();
83         r.fillFields( data, 0, new DefaultEscherRecordFactory());
84
85         assertEquals( EscherBlipRecord.RECORD_ID_START, r.getRecordId() );
86         assertEquals( 1, r.getBoundaryLeft() );
87         assertEquals( 2, r.getBoundaryHeight() );
88         assertEquals( 3, r.getBoundaryTop() );
89         assertEquals( 4, r.getBoundaryWidth() );
90         assertEquals( 5, r.getCacheOfSavedSize() );
91         assertEquals( 6, r.getCacheOfSize() );
92         assertEquals( 7, r.getFilter() );
93         assertEquals( 8, r.getCompressionFlag() );
94         assertEquals( "[01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, ]", HexDump.toHex(r.getSecondaryUID() ) );
95         assertEquals( 10, r.getWidth() );
96         assertEquals( 11, r.getHeight() );
97         assertEquals( (short)5420, r.getOptions() );
98         assertEquals( "[01, 02, ]", HexDump.toHex( r.getData() ) );
99     }
100
101     public void testToString() throws Exception JavaDoc
102     {
103         EscherBlipRecord r = new EscherBlipRecord();
104         r.fillFields( data, 0, new DefaultEscherRecordFactory() );
105
106         String JavaDoc nl = System.getProperty("line.separator");
107
108         assertEquals( "org.apache.poi.ddf.EscherBlipRecord:" + nl +
109                 " RecordId: 0xF018" + nl +
110                 " Options: 0x152C" + nl +
111                 " Secondary UID: [01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, ]" + nl +
112                 " CacheOfSize: 6" + nl +
113                 " BoundaryTop: 3" + nl +
114                 " BoundaryLeft: 1" + nl +
115                 " BoundaryWidth: 4" + nl +
116                 " BoundaryHeight: 2" + nl +
117                 " X: 10" + nl +
118                 " Y: 11" + nl +
119                 " CacheOfSavedSize: 5" + nl +
120                 " CompressionFlag: 8" + nl +
121                 " Filter: 7" + nl +
122                 " Data:" + nl +
123                 "00000000 01 02 .." + nl
124                 , r.toString() );
125     }
126
127 }
128
Popular Tags