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 TestEscherClientAnchorRecord extends TestCase {
025: public void testSerialize() throws Exception {
026: EscherClientAnchorRecord r = createRecord();
027:
028: byte[] data = new byte[8 + 18 + 2];
029: int bytesWritten = r.serialize(0, data,
030: new NullEscherSerializationListener());
031: assertEquals(28, bytesWritten);
032: assertEquals("[01, 00, " + "10, F0, " + "14, 00, 00, 00, "
033: + "4D, 00, 37, 00, 21, 00, 58, 00, "
034: + "0B, 00, 2C, 00, 16, 00, 63, 00, " + "42, 00, "
035: + "FF, DD, ]", HexDump.toHex(data));
036: }
037:
038: public void testFillFields() throws Exception {
039: String hexData = "01 00 " + "10 F0 " + "14 00 00 00 "
040: + "4D 00 37 00 21 00 58 00 "
041: + "0B 00 2C 00 16 00 63 00 " + "42 00 " + "FF DD";
042: byte[] data = HexRead.readFromString(hexData);
043: EscherClientAnchorRecord r = new EscherClientAnchorRecord();
044: int bytesWritten = r.fillFields(data,
045: new DefaultEscherRecordFactory());
046:
047: assertEquals(28, bytesWritten);
048: assertEquals((short) 55, r.getCol1());
049: assertEquals((short) 44, r.getCol2());
050: assertEquals((short) 33, r.getDx1());
051: assertEquals((short) 22, r.getDx2());
052: assertEquals((short) 11, r.getDy1());
053: assertEquals((short) 66, r.getDy2());
054: assertEquals((short) 77, r.getFlag());
055: assertEquals((short) 88, r.getRow1());
056: assertEquals((short) 99, r.getRow2());
057: assertEquals((short) 0x0001, r.getOptions());
058: assertEquals((byte) 0xFF, r.getRemainingData()[0]);
059: assertEquals((byte) 0xDD, r.getRemainingData()[1]);
060: }
061:
062: public void testToString() throws Exception {
063: String nl = System.getProperty("line.separator");
064:
065: String expected = "org.apache.poi.ddf.EscherClientAnchorRecord:"
066: + nl
067: + " RecordId: 0xF010"
068: + nl
069: + " Options: 0x0001"
070: + nl
071: + " Flag: 77"
072: + nl
073: + " Col1: 55"
074: + nl
075: + " DX1: 33"
076: + nl
077: + " Row1: 88"
078: + nl
079: + " DY1: 11"
080: + nl
081: + " Col2: 44"
082: + nl
083: + " DX2: 22"
084: + nl
085: + " Row2: 99"
086: + nl
087: + " DY2: 66"
088: + nl
089: + " Extra Data:"
090: + nl
091: + "00000000 FF DD .."
092: + nl;
093: assertEquals(expected, createRecord().toString());
094: }
095:
096: private EscherClientAnchorRecord createRecord() {
097: EscherClientAnchorRecord r = new EscherClientAnchorRecord();
098: r.setCol1((short) 55);
099: r.setCol2((short) 44);
100: r.setDx1((short) 33);
101: r.setDx2((short) 22);
102: r.setDy1((short) 11);
103: r.setDy2((short) 66);
104: r.setFlag((short) 77);
105: r.setRow1((short) 88);
106: r.setRow2((short) 99);
107: r.setOptions((short) 0x0001);
108: r.setRemainingData(new byte[] { (byte) 0xFF, (byte) 0xDD });
109: return r;
110: }
111:
112: }
|