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: package org.apache.poi.hdgf.pointers;
018:
019: import junit.framework.TestCase;
020:
021: /**
022: * Tests for the pointer factory, and the pointers themselves
023: */
024: public class TestPointerFactory extends TestCase {
025: // Type: 16 Addr: 0143aff4 Offset: 80 Len: 54 Format: 46 From: 8a94
026: private static byte[] vp6_a = new byte[] { 22, 0, 0, 0, -12, -81,
027: 67, 1, -128, 0, 0, 0, 84, 0, 0, 0, 70, 0 };
028: // Type: 17 Addr: 014fd84c Offset: d4 Len: 20 Format: 54 From: 8a94
029: private static byte[] vp6_b = new byte[] { 23, 0, 0, 0, 76, -40,
030: 79, 1, -44, 0, 0, 0, 32, 0, 0, 0, 84, 0 };
031: // Type: 17 Addr: 014fd8bc Offset: f8 Len: 20 Format: 54 From: 8a94
032: private static byte[] vp6_c = new byte[] { 23, 0, 0, 0, -68, -40,
033: 79, 1, -8, 0, 0, 0, 32, 0, 0, 0, 84, 0 };
034: // Type: ff Addr: 014fffac Offset: 0 Len: 0 Format: 60 From: 8a94
035: private static byte[] vp6_d = new byte[] { -1, 0, 0, 0, -84, -1,
036: 79, 1, 0, 0, 0, 0, 0, 0, 0, 0, 96, 0 };
037:
038: public void testCreateV4() throws Exception {
039: PointerFactory pf = new PointerFactory(4);
040: try {
041: pf.createPointer(new byte[] {}, 0);
042: fail();
043: } catch (IllegalArgumentException e) {
044: // As expected
045: }
046: }
047:
048: public void testCreateV5() throws Exception {
049: PointerFactory pf = new PointerFactory(5);
050: try {
051: pf.createPointer(new byte[] {}, 0);
052: fail();
053: } catch (RuntimeException e) {
054: // Still to do
055: assertEquals("TODO", e.getMessage());
056: }
057: }
058:
059: public void testCreateV6() throws Exception {
060: PointerFactory pf = new PointerFactory(6);
061:
062: Pointer a = pf.createPointer(vp6_a, 0);
063: assertEquals(0x16, a.getType());
064: assertEquals(0x0143aff4, a.getAddress());
065: assertEquals(0x80, a.getOffset());
066: assertEquals(0x54, a.getLength());
067: assertEquals(0x46, a.getFormat());
068:
069: assertTrue(a.destinationCompressed());
070: assertTrue(a.destinationHasStrings());
071: assertFalse(a.destinationHasChunks());
072: assertFalse(a.destinationHasPointers());
073:
074: assertEquals(18, a.getSizeInBytes());
075:
076: Pointer b = pf.createPointer(vp6_b, 0);
077: assertEquals(0x17, b.getType());
078: assertEquals(0x014fd84c, b.getAddress());
079: assertEquals(0xd4, b.getOffset());
080: assertEquals(0x20, b.getLength());
081: assertEquals(0x54, b.getFormat());
082:
083: assertFalse(b.destinationCompressed());
084: assertFalse(b.destinationHasStrings());
085: assertFalse(b.destinationHasChunks());
086: assertTrue(b.destinationHasPointers());
087:
088: Pointer c = pf.createPointer(vp6_c, 0);
089: assertEquals(0x17, c.getType());
090: assertEquals(0x014fd8bc, c.getAddress());
091: assertEquals(0xf8, c.getOffset());
092: assertEquals(0x20, c.getLength());
093: assertEquals(0x54, c.getFormat());
094:
095: assertFalse(c.destinationCompressed());
096: assertFalse(c.destinationHasStrings());
097: assertFalse(c.destinationHasChunks());
098: assertTrue(c.destinationHasPointers());
099:
100: // Type: ff Addr: 014fffac Offset: 0 Len: 0 Format: 60 From: 8a94
101: Pointer d = pf.createPointer(vp6_d, 0);
102: assertEquals(0xff, d.getType());
103: assertEquals(0x014fffac, d.getAddress());
104: assertEquals(0x00, d.getOffset());
105: assertEquals(0x00, d.getLength());
106: assertEquals(0x60, d.getFormat());
107:
108: assertFalse(d.destinationCompressed());
109: assertFalse(d.destinationHasStrings());
110: assertFalse(d.destinationHasChunks());
111: assertFalse(d.destinationHasPointers());
112: }
113:
114: public void testCreateV6FromMid() throws Exception {
115: PointerFactory pf = new PointerFactory(11);
116:
117: // Create a from part way down the byte stream
118: byte[] bytes = new byte[28];
119: System.arraycopy(vp6_b, 0, bytes, 0, 10);
120: System.arraycopy(vp6_a, 0, bytes, 10, 18);
121:
122: Pointer a = pf.createPointer(bytes, 10);
123: assertEquals(0x16, a.getType());
124: assertEquals(0x0143aff4, a.getAddress());
125: assertEquals(0x80, a.getOffset());
126: assertEquals(0x54, a.getLength());
127: assertEquals(0x46, a.getFormat());
128:
129: assertTrue(a.destinationCompressed());
130: assertTrue(a.destinationHasStrings());
131: assertFalse(a.destinationHasChunks());
132: assertFalse(a.destinationHasPointers());
133: }
134: }
|