001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.ddf;
019:
020: import junit.framework.TestCase;
021: import org.apache.poi.util.HexRead;
022: import org.apache.poi.util.HexDump;
023:
024: public class TestUnknownEscherRecord extends TestCase {
025: public void testFillFields() throws Exception {
026: String testData = "0F 02 " + // options
027: "11 F1 " + // record id
028: "00 00 00 00"; // remaining bytes
029:
030: UnknownEscherRecord r = new UnknownEscherRecord();
031: EscherRecordFactory factory = new DefaultEscherRecordFactory();
032: r.fillFields(HexRead.readFromString(testData), factory);
033:
034: assertEquals(0x020F, r.getOptions());
035: assertEquals((short) 0xF111, r.getRecordId());
036: assertTrue(r.isContainerRecord());
037: assertEquals(8, r.getRecordSize());
038: assertEquals(0, r.getChildRecords().size());
039: assertEquals(0, r.getData().length);
040:
041: testData = "00 02 " + // options
042: "11 F1 " + // record id
043: "04 00 00 00 " + // remaining bytes
044: "01 02 03 04";
045:
046: r = new UnknownEscherRecord();
047: r.fillFields(HexRead.readFromString(testData), factory);
048:
049: assertEquals(0x0200, r.getOptions());
050: assertEquals((short) 0xF111, r.getRecordId());
051: assertEquals(12, r.getRecordSize());
052: assertFalse(r.isContainerRecord());
053: assertEquals(0, r.getChildRecords().size());
054: assertEquals(4, r.getData().length);
055: assertEquals(1, r.getData()[0]);
056: assertEquals(2, r.getData()[1]);
057: assertEquals(3, r.getData()[2]);
058: assertEquals(4, r.getData()[3]);
059:
060: testData = "0F 02 " + // options
061: "11 F1 " + // record id
062: "08 00 00 00 " + // remaining bytes
063: "00 02 " + // options
064: "FF FF " + // record id
065: "00 00 00 00"; // remaining bytes
066:
067: r = new UnknownEscherRecord();
068: r.fillFields(HexRead.readFromString(testData), factory);
069:
070: assertEquals(0x020F, r.getOptions());
071: assertEquals((short) 0xF111, r.getRecordId());
072: assertEquals(8, r.getRecordSize());
073: assertTrue(r.isContainerRecord());
074: assertEquals(1, r.getChildRecords().size());
075: assertEquals((short) 0xFFFF, r.getChild(0).getRecordId());
076:
077: }
078:
079: public void testSerialize() throws Exception {
080: UnknownEscherRecord r = new UnknownEscherRecord();
081: r.setOptions((short) 0x1234);
082: r.setRecordId((short) 0xF112);
083: byte[] data = new byte[8];
084: r.serialize(0, data, new NullEscherSerializationListener());
085:
086: assertEquals("[34, 12, 12, F1, 00, 00, 00, 00, ]", HexDump
087: .toHex(data));
088:
089: EscherRecord childRecord = new UnknownEscherRecord();
090: childRecord.setOptions((short) 0x9999);
091: childRecord.setRecordId((short) 0xFF01);
092: r.addChildRecord(childRecord);
093: r.setOptions((short) 0x123F);
094: data = new byte[16];
095: r.serialize(0, data, new NullEscherSerializationListener());
096:
097: assertEquals(
098: "[3F, 12, 12, F1, 08, 00, 00, 00, 99, 99, 01, FF, 00, 00, 00, 00, ]",
099: HexDump.toHex(data));
100: }
101:
102: public void testToString() throws Exception {
103: UnknownEscherRecord r = new UnknownEscherRecord();
104: r.setOptions((short) 0x1234);
105: r.setRecordId((short) 0xF112);
106: byte[] data = new byte[8];
107: r.serialize(0, data, new NullEscherSerializationListener());
108:
109: String nl = System.getProperty("line.separator");
110: assertEquals("org.apache.poi.ddf.UnknownEscherRecord:" + nl
111: + " isContainer: false" + nl + " options: 0x1234"
112: + nl + " recordId: 0xF112" + nl + " numchildren: 0"
113: + nl, r.toString());
114: }
115:
116: }
|