KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > TestEscherAggregate


1 /* ====================================================================
2    Copyright 2003-2004 Apache Software Foundation
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 ==================================================================== */

16
17 package org.apache.poi.hssf.record;
18
19 import junit.framework.TestCase;
20 import org.apache.poi.util.HexRead;
21 import org.apache.poi.util.HexDump;
22 import org.apache.poi.ddf.EscherContainerRecord;
23 import org.apache.poi.ddf.EscherSpRecord;
24 import org.apache.poi.ddf.EscherClientDataRecord;
25 import org.apache.poi.ddf.EscherDggRecord;
26 import org.apache.poi.hssf.model.DrawingManager;
27 import org.apache.poi.hssf.model.Sheet;
28
29 import java.util.ArrayList JavaDoc;
30 import java.util.List JavaDoc;
31
32 /**
33  * Tests the EscherAggregate class.
34  *
35  * @author Glen Stampoultzis (glens at apache.org)
36  */

37 public class TestEscherAggregate extends TestCase
38 {
39     /**
40      * Tests that the create aggregate method correctly rejoins escher records together.
41      *
42      * @throws Exception
43      */

44     public void testCreateAggregate() throws Exception JavaDoc
45     {
46         String JavaDoc msoDrawingRecord1 =
47                 "0F 00 02 F0 20 01 00 00 10 00 08 F0 08 00 00 00 \n" +
48                 "03 00 00 00 02 04 00 00 0F 00 03 F0 08 01 00 00 \n" +
49                 "0F 00 04 F0 28 00 00 00 01 00 09 F0 10 00 00 00 \n" +
50                 "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \n" +
51                 "02 00 0A F0 08 00 00 00 00 04 00 00 05 00 00 00 \n" +
52                 "0F 00 04 F0 64 00 00 00 42 01 0A F0 08 00 00 00 \n" +
53                 "01 04 00 00 00 0A 00 00 73 00 0B F0 2A 00 00 00 \n" +
54                 "BF 00 08 00 08 00 44 01 04 00 00 00 7F 01 00 00 \n" +
55                 "01 00 BF 01 00 00 11 00 C0 01 40 00 00 08 FF 01 \n" +
56                 "10 00 10 00 BF 03 00 00 08 00 00 00 10 F0 12 00 \n" +
57                 "00 00 00 00 01 00 54 00 05 00 45 00 01 00 88 03 \n" +
58                 "05 00 94 00 00 00 11 F0 00 00 00 00";
59
60         String JavaDoc msoDrawingRecord2 =
61                 "0F 00 04 F0 64 00 00 00 42 01 0A F0 08 00 00 00 " +
62                 "02 04 00 00 80 0A 00 00 73 00 0B F0 2A 00 00 00 " +
63                 "BF 00 08 00 08 00 44 01 04 00 00 00 7F 01 00 00 " +
64                 "01 00 BF 01 00 00 11 00 C0 01 40 00 00 08 FF 01 " +
65                 "10 00 10 00 BF 03 00 00 08 00 00 00 10 F0 12 00 " +
66                 "00 00 00 00 01 00 8D 03 05 00 E4 00 03 00 4D 03 " +
67                 "0B 00 0C 00 00 00 11 F0 00 00 00 00";
68
69         DrawingRecord d1 = new DrawingRecord();
70         d1.setData( HexRead.readFromString( msoDrawingRecord1 ) );
71
72         ObjRecord r1 = new ObjRecord();
73
74         DrawingRecord d2 = new DrawingRecord();
75         d2.setData( HexRead.readFromString( msoDrawingRecord2 ) );
76
77         ObjRecord r2 = new ObjRecord();
78
79         List JavaDoc records = new ArrayList JavaDoc();
80         records.add( d1 );
81         records.add( r1 );
82         records.add( d2 );
83         records.add( r2 );
84
85         DrawingManager drawingManager = new DrawingManager(new EscherDggRecord() );
86         EscherAggregate aggregate = EscherAggregate.createAggregate( records, 0, drawingManager );
87
88         assertEquals( 1, aggregate.getEscherRecords().size() );
89         assertEquals( (short) 0xF002, aggregate.getEscherRecord( 0 ).getRecordId() );
90         assertEquals( 2, aggregate.getEscherRecord( 0 ).getChildRecords().size() );
91
92 // System.out.println( "aggregate = " + aggregate );
93
}
94
95     public void testSerialize() throws Exception JavaDoc
96     {
97
98         EscherContainerRecord container1 = new EscherContainerRecord();
99         EscherContainerRecord spContainer1 = new EscherContainerRecord();
100         EscherContainerRecord spContainer2 = new EscherContainerRecord();
101         EscherContainerRecord spContainer3 = new EscherContainerRecord();
102         EscherSpRecord sp1 = new EscherSpRecord();
103         EscherSpRecord sp2 = new EscherSpRecord();
104         EscherSpRecord sp3 = new EscherSpRecord();
105         EscherClientDataRecord d2 = new EscherClientDataRecord();
106         EscherClientDataRecord d3 = new EscherClientDataRecord();
107
108         container1.setOptions( (short) 0x000F );
109         spContainer1.setOptions( (short) 0x000F );
110         spContainer1.setRecordId( EscherContainerRecord.SP_CONTAINER );
111         spContainer2.setOptions( (short) 0x000F );
112         spContainer2.setRecordId( EscherContainerRecord.SP_CONTAINER );
113         spContainer3.setOptions( (short) 0x000F );
114         spContainer3.setRecordId( EscherContainerRecord.SP_CONTAINER );
115         d2.setRecordId( EscherClientDataRecord.RECORD_ID );
116         d2.setRemainingData( new byte[0] );
117         d3.setRecordId( EscherClientDataRecord.RECORD_ID );
118         d3.setRemainingData( new byte[0] );
119         container1.addChildRecord( spContainer1 );
120         container1.addChildRecord( spContainer2 );
121         container1.addChildRecord( spContainer3 );
122         spContainer1.addChildRecord( sp1 );
123         spContainer2.addChildRecord( sp2 );
124         spContainer3.addChildRecord( sp3 );
125         spContainer2.addChildRecord( d2 );
126         spContainer3.addChildRecord( d3 );
127
128         EscherAggregate aggregate = new EscherAggregate(null);
129         aggregate.addEscherRecord( container1 );
130         aggregate.assoicateShapeToObjRecord( d2, new ObjRecord() );
131         aggregate.assoicateShapeToObjRecord( d3, new ObjRecord() );
132
133         byte[] data = new byte[112];
134         int bytesWritten = aggregate.serialize( 0, data );
135         assertEquals( 112, bytesWritten );
136         assertEquals( "[EC, 00, 40, 00, 0F, 00, 00, 00, 58, 00, 00, 00, 0F, 00, 04, F0, 10, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0F, 00, 04, F0, 18, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 11, F0, 00, 00, 00, 00, 5D, 00, 00, 00, EC, 00, 20, 00, 0F, 00, 04, F0, 18, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 11, F0, 00, 00, 00, 00, 5D, 00, 00, 00, ]",
137                 HexDump.toHex( data ) );
138     }
139
140 }
141
Popular Tags