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: public class TestEscherBlipWMFRecord extends TestCase {
025: private String dataStr;
026: private byte[] data;
027:
028: protected void setUp() throws Exception {
029: dataStr = "2C 15 18 F0 34 00 00 00 01 01 01 01 01 01 01 01 "
030: + "01 01 01 01 01 01 01 01 06 00 00 00 03 00 00 00 "
031: + "01 00 00 00 04 00 00 00 02 00 00 00 0A 00 00 00 "
032: + "0B 00 00 00 05 00 00 00 08 07 01 02";
033: data = HexRead.readFromString(dataStr);
034: }
035:
036: public void testSerialize() throws Exception {
037: EscherBlipWMFRecord r = new EscherBlipWMFRecord();
038: r.setBoundaryLeft(1);
039: r.setBoundaryHeight(2);
040: r.setBoundaryTop(3);
041: r.setBoundaryWidth(4);
042: r.setCacheOfSavedSize(5);
043: r.setCacheOfSize(6);
044: r.setFilter((byte) 7);
045: r.setCompressionFlag((byte) 8);
046: r.setSecondaryUID(new byte[] { (byte) 0x01, (byte) 0x01,
047: (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01,
048: (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01,
049: (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01,
050: (byte) 0x01, (byte) 0x01, });
051: r.setWidth(10);
052: r.setHeight(11);
053: r.setRecordId(EscherBlipWMFRecord.RECORD_ID_START);
054: r.setOptions((short) 5420);
055: r.setData(new byte[] { (byte) 0x01, (byte) 0x02 });
056:
057: byte[] buf = new byte[r.getRecordSize()];
058: r.serialize(0, buf, new NullEscherSerializationListener());
059:
060: assertEquals(
061: "[2C, 15, 18, F0, 26, 00, 00, 00, "
062: + "01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, "
063: + "06, 00, 00, 00, " + // field_2_cacheOfSize
064: "03, 00, 00, 00, " + // field_3_boundaryTop
065: "01, 00, 00, 00, " + // field_4_boundaryLeft
066: "04, 00, 00, 00, " + // field_5_boundaryWidth
067: "02, 00, 00, 00, " + // field_6_boundaryHeight
068: "0A, 00, 00, 00, " + // field_7_x
069: "0B, 00, 00, 00, " + // field_8_y
070: "05, 00, 00, 00, " + // field_9_cacheOfSavedSize
071: "08, " + // field_10_compressionFlag
072: "07, " + // field_11_filter
073: "01, 02, ]", // field_12_data
074: HexDump.toHex(buf));
075: assertEquals(60, r.getRecordSize());
076:
077: }
078:
079: public void testFillFields() throws Exception {
080: EscherBlipWMFRecord r = new EscherBlipWMFRecord();
081: r.fillFields(data, 0, new DefaultEscherRecordFactory());
082:
083: assertEquals(EscherBlipWMFRecord.RECORD_ID_START, r
084: .getRecordId());
085: assertEquals(1, r.getBoundaryLeft());
086: assertEquals(2, r.getBoundaryHeight());
087: assertEquals(3, r.getBoundaryTop());
088: assertEquals(4, r.getBoundaryWidth());
089: assertEquals(5, r.getCacheOfSavedSize());
090: assertEquals(6, r.getCacheOfSize());
091: assertEquals(7, r.getFilter());
092: assertEquals(8, r.getCompressionFlag());
093: assertEquals(
094: "[01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, ]",
095: HexDump.toHex(r.getSecondaryUID()));
096: assertEquals(10, r.getWidth());
097: assertEquals(11, r.getHeight());
098: assertEquals((short) 5420, r.getOptions());
099: assertEquals("[01, 02, ]", HexDump.toHex(r.getData()));
100: }
101:
102: public void testToString() throws Exception {
103: EscherBlipWMFRecord r = new EscherBlipWMFRecord();
104: r.fillFields(data, 0, new DefaultEscherRecordFactory());
105:
106: String nl = System.getProperty("line.separator");
107:
108: assertEquals(
109: "org.apache.poi.ddf.EscherBlipWMFRecord:"
110: + nl
111: + " RecordId: 0xF018"
112: + nl
113: + " Options: 0x152C"
114: + nl
115: + " Secondary UID: [01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, ]"
116: + nl
117: + " CacheOfSize: 6"
118: + nl
119: + " BoundaryTop: 3"
120: + nl
121: + " BoundaryLeft: 1"
122: + nl
123: + " BoundaryWidth: 4"
124: + nl
125: + " BoundaryHeight: 2"
126: + nl
127: + " X: 10"
128: + nl
129: + " Y: 11"
130: + nl
131: + " CacheOfSavedSize: 5"
132: + nl
133: + " CompressionFlag: 8"
134: + nl
135: + " Filter: 7"
136: + nl
137: + " Data:"
138: + nl
139: + "00000000 01 02 .."
140: + nl, r.toString());
141: }
142:
143: }
|