KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.io.IOException JavaDoc;
25
26 public class TestEscherBSERecord extends TestCase
27 {
28     public void testFillFields() throws Exception JavaDoc
29     {
30         String JavaDoc data = "01 00 00 00 24 00 00 00 05 05 01 02 03 04 " +
31                 " 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00 01 00 00 00 " +
32                 " 00 00 02 00 00 00 03 00 00 00 04 05 06 07";
33         EscherBSERecord r = new EscherBSERecord();
34         int bytesWritten = r.fillFields( HexRead.readFromString( data ), 0, new DefaultEscherRecordFactory() );
35         assertEquals( 44, bytesWritten );
36         assertEquals( (short) 0x0001, r.getOptions() );
37         assertEquals( EscherBSERecord.BT_JPEG, r.getBlipTypeWin32() );
38         assertEquals( EscherBSERecord.BT_JPEG, r.getBlipTypeMacOS() );
39         assertEquals( "[01, 02, 03, 04, 05, 06, 07, 08, 09, 0A, 0B, 0C, 0D, 0E, 0F, 00, ]", HexDump.toHex( r.getUid() ) );
40         assertEquals( (short) 1, r.getTag() );
41         assertEquals( 2, r.getRef() );
42         assertEquals( 3, r.getOffset() );
43         assertEquals( (byte) 4, r.getUsage() );
44         assertEquals( (byte) 5, r.getName() );
45         assertEquals( (byte) 6, r.getUnused2() );
46         assertEquals( (byte) 7, r.getUnused3() );
47         assertEquals( 0, r.getRemainingData().length );
48     }
49
50     public void testSerialize() throws Exception JavaDoc
51     {
52         EscherBSERecord r = createRecord();
53
54         byte[] data = new byte[8 + 36];
55         int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() );
56         assertEquals( 44, bytesWritten );
57         assertEquals( "[01, 00, 00, 00, 24, 00, 00, 00, 05, 05, 01, 02, 03, 04, " +
58                 "05, 06, 07, 08, 09, 0A, 0B, 0C, 0D, 0E, 0F, 00, 01, 00, 00, 00, " +
59                 "00, 00, 02, 00, 00, 00, 03, 00, 00, 00, 04, 05, 06, 07, ]",
60                 HexDump.toHex( data ) );
61
62     }
63
64     private EscherBSERecord createRecord() throws IOException JavaDoc
65     {
66         EscherBSERecord r = new EscherBSERecord();
67         r.setOptions( (short) 0x0001 );
68         r.setBlipTypeWin32( EscherBSERecord.BT_JPEG );
69         r.setBlipTypeMacOS( EscherBSERecord.BT_JPEG );
70         r.setUid( HexRead.readFromString( "01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00" ) );
71         r.setTag( (short) 1 );
72         r.setRef( 2 );
73         r.setOffset( 3 );
74         r.setUsage( (byte) 4 );
75         r.setName( (byte) 5 );
76         r.setUnused2( (byte) 6 );
77         r.setUnused3( (byte) 7 );
78         r.setRemainingData( new byte[0] );
79         return r;
80
81     }
82
83     public void testToString() throws Exception JavaDoc
84     {
85         EscherBSERecord record = createRecord();
86         String JavaDoc nl = System.getProperty("line.separator");
87         assertEquals( "org.apache.poi.ddf.EscherBSERecord:" + nl +
88                 " RecordId: 0xF007" + nl +
89                 " Options: 0x0001" + nl +
90                 " BlipTypeWin32: 5" + nl +
91                 " BlipTypeMacOS: 5" + nl +
92                 " SUID: [01, 02, 03, 04, 05, 06, 07, 08, 09, 0A, 0B, 0C, 0D, 0E, 0F, 00, ]" + nl +
93                 " Tag: 1" + nl +
94                 " Size: 0" + nl +
95                 " Ref: 2" + nl +
96                 " Offset: 3" + nl +
97                 " Usage: 4" + nl +
98                 " Name: 5" + nl +
99                 " Unused2: 6" + nl +
100                 " Unused3: 7" + nl +
101                 " Extra Data:" + nl +
102                 "No Data", record.toString() );
103     }
104
105 }
106
Popular Tags