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.HexDump;
022: import org.apache.poi.util.HexRead;
023:
024: import java.io.IOException;
025:
026: public class TestEscherBSERecord extends TestCase {
027: public void testFillFields() throws Exception {
028: String data = "01 00 00 00 24 00 00 00 05 05 01 02 03 04 "
029: + " 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00 01 00 00 00 "
030: + " 00 00 02 00 00 00 03 00 00 00 04 05 06 07";
031: EscherBSERecord r = new EscherBSERecord();
032: int bytesWritten = r.fillFields(HexRead.readFromString(data),
033: 0, new DefaultEscherRecordFactory());
034: assertEquals(44, bytesWritten);
035: assertEquals((short) 0x0001, r.getOptions());
036: assertEquals(EscherBSERecord.BT_JPEG, r.getBlipTypeWin32());
037: assertEquals(EscherBSERecord.BT_JPEG, r.getBlipTypeMacOS());
038: assertEquals(
039: "[01, 02, 03, 04, 05, 06, 07, 08, 09, 0A, 0B, 0C, 0D, 0E, 0F, 00, ]",
040: HexDump.toHex(r.getUid()));
041: assertEquals((short) 1, r.getTag());
042: assertEquals(2, r.getRef());
043: assertEquals(3, r.getOffset());
044: assertEquals((byte) 4, r.getUsage());
045: assertEquals((byte) 5, r.getName());
046: assertEquals((byte) 6, r.getUnused2());
047: assertEquals((byte) 7, r.getUnused3());
048: assertEquals(0, r.getRemainingData().length);
049: }
050:
051: public void testSerialize() throws Exception {
052: EscherBSERecord r = createRecord();
053:
054: byte[] data = new byte[8 + 36];
055: int bytesWritten = r.serialize(0, data,
056: new NullEscherSerializationListener());
057: assertEquals(44, bytesWritten);
058: assertEquals(
059: "[01, 00, 00, 00, 24, 00, 00, 00, 05, 05, 01, 02, 03, 04, "
060: + "05, 06, 07, 08, 09, 0A, 0B, 0C, 0D, 0E, 0F, 00, 01, 00, 00, 00, "
061: + "00, 00, 02, 00, 00, 00, 03, 00, 00, 00, 04, 05, 06, 07, ]",
062: HexDump.toHex(data));
063:
064: }
065:
066: private EscherBSERecord createRecord() throws IOException {
067: EscherBSERecord r = new EscherBSERecord();
068: r.setOptions((short) 0x0001);
069: r.setBlipTypeWin32(EscherBSERecord.BT_JPEG);
070: r.setBlipTypeMacOS(EscherBSERecord.BT_JPEG);
071: r
072: .setUid(HexRead
073: .readFromString("01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00"));
074: r.setTag((short) 1);
075: r.setRef(2);
076: r.setOffset(3);
077: r.setUsage((byte) 4);
078: r.setName((byte) 5);
079: r.setUnused2((byte) 6);
080: r.setUnused3((byte) 7);
081: r.setRemainingData(new byte[0]);
082: return r;
083:
084: }
085:
086: public void testToString() throws Exception {
087: EscherBSERecord record = createRecord();
088: String nl = System.getProperty("line.separator");
089: assertEquals(
090: "org.apache.poi.ddf.EscherBSERecord:"
091: + nl
092: + " RecordId: 0xF007"
093: + nl
094: + " Options: 0x0001"
095: + nl
096: + " BlipTypeWin32: 5"
097: + nl
098: + " BlipTypeMacOS: 5"
099: + nl
100: + " SUID: [01, 02, 03, 04, 05, 06, 07, 08, 09, 0A, 0B, 0C, 0D, 0E, 0F, 00, ]"
101: + nl + " Tag: 1" + nl + " Size: 0" + nl
102: + " Ref: 2" + nl + " Offset: 3" + nl
103: + " Usage: 4" + nl + " Name: 5" + nl
104: + " Unused2: 6" + nl + " Unused3: 7" + nl
105: + " blipRecord: null" + nl + " Extra Data:"
106: + nl + "No Data" + nl, record.toString());
107: }
108:
109: }
|