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 TestEscherSplitMenuColorsRecord extends TestCase {
25: public void testSerialize() throws Exception {
26: EscherSplitMenuColorsRecord r = createRecord();
27:
28: byte[] data = new byte[24];
29: int bytesWritten = r.serialize(0, data,
30: new NullEscherSerializationListener());
31: assertEquals(24, bytesWritten);
32: assertEquals("[40, 00, " + "1E, F1, " + "10, 00, 00, 00, "
33: + "02, 04, 00, 00, " + "02, 00, 00, 00, "
34: + "02, 00, 00, 00, " + "01, 00, 00, 00, ]", HexDump
35: .toHex(data));
36: }
37:
38: public void testFillFields() throws Exception {
39: String hexData = "40 00 " + "1E F1 " + "10 00 00 00 "
40: + "02 04 00 00 " + "02 00 00 00 " + "02 00 00 00 "
41: + "01 00 00 00 ";
42: byte[] data = HexRead.readFromString(hexData);
43: EscherSplitMenuColorsRecord r = new EscherSplitMenuColorsRecord();
44: int bytesWritten = r.fillFields(data,
45: new DefaultEscherRecordFactory());
46:
47: assertEquals(24, bytesWritten);
48: assertEquals(0x0402, r.getColor1());
49: assertEquals(0x02, r.getColor2());
50: assertEquals(0x02, r.getColor3());
51: assertEquals(0x01, r.getColor4());
52: }
53:
54: public void testToString() throws Exception {
55: String nl = System.getProperty("line.separator");
56:
57: String expected = "org.apache.poi.ddf.EscherSplitMenuColorsRecord:"
58: + nl
59: + " RecordId: 0xF11E"
60: + nl
61: + " Options: 0x0040"
62: + nl
63: + " Color1: 0x00000402"
64: + nl
65: + " Color2: 0x00000002"
66: + nl
67: + " Color3: 0x00000002"
68: + nl + " Color4: 0x00000001" + nl + "";
69: assertEquals(expected, createRecord().toString());
70: }
71:
72: private EscherSplitMenuColorsRecord createRecord() {
73: EscherSplitMenuColorsRecord r = new EscherSplitMenuColorsRecord();
74: r.setOptions((short) 0x0040);
75: r.setRecordId(EscherSplitMenuColorsRecord.RECORD_ID);
76: r.setColor1(0x402);
77: r.setColor2(0x2);
78: r.setColor3(0x2);
79: r.setColor4(0x1);
80: return r;
81: }
82:
83: }
|