01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: 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 TestEscherSpRecord extends TestCase {
25: public void testSerialize() throws Exception {
26: EscherSpRecord r = createRecord();
27:
28: byte[] data = new byte[16];
29: int bytesWritten = r.serialize(0, data,
30: new NullEscherSerializationListener());
31: assertEquals(16, bytesWritten);
32: assertEquals("[02, 00, " + "0A, F0, " + "08, 00, 00, 00, "
33: + "00, 04, 00, 00, " + "05, 00, 00, 00, ]", HexDump
34: .toHex(data));
35: }
36:
37: public void testFillFields() throws Exception {
38: String hexData = "02 00 " + "0A F0 " + "08 00 00 00 "
39: + "00 04 00 00 " + "05 00 00 00 ";
40: byte[] data = HexRead.readFromString(hexData);
41: EscherSpRecord r = new EscherSpRecord();
42: int bytesWritten = r.fillFields(data,
43: new DefaultEscherRecordFactory());
44:
45: assertEquals(16, bytesWritten);
46: assertEquals(0x0400, r.getShapeId());
47: assertEquals(0x05, r.getFlags());
48: }
49:
50: public void testToString() throws Exception {
51: String nl = System.getProperty("line.separator");
52:
53: String expected = "org.apache.poi.ddf.EscherSpRecord:" + nl
54: + " RecordId: 0xF00A" + nl + " Options: 0x0002" + nl
55: + " ShapeId: 1024" + nl
56: + " Flags: GROUP|PATRIARCH (0x00000005)" + nl;
57: assertEquals(expected, createRecord().toString());
58: }
59:
60: private EscherSpRecord createRecord() {
61: EscherSpRecord r = new EscherSpRecord();
62: r.setOptions((short) 0x0002);
63: r.setRecordId(EscherSpRecord.RECORD_ID);
64: r.setShapeId(0x0400);
65: r.setFlags(0x05);
66: return r;
67: }
68:
69: }
|