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:
19: package org.apache.tools.zip;
20:
21: import junit.framework.TestCase;
22:
23: /**
24: * JUnit 3 testcases for org.apache.tools.zip.ZipShort.
25: *
26: */
27: public class ZipShortTest extends TestCase {
28:
29: public ZipShortTest(String name) {
30: super (name);
31: }
32:
33: /**
34: * Test conversion to bytes.
35: */
36: public void testToBytes() {
37: ZipShort zs = new ZipShort(0x1234);
38: byte[] result = zs.getBytes();
39: assertEquals("length getBytes", 2, result.length);
40: assertEquals("first byte getBytes", 0x34, result[0]);
41: assertEquals("second byte getBytes", 0x12, result[1]);
42: }
43:
44: /**
45: * Test conversion from bytes.
46: */
47: public void testFromBytes() {
48: byte[] val = new byte[] { 0x34, 0x12 };
49: ZipShort zs = new ZipShort(val);
50: assertEquals("value from bytes", 0x1234, zs.getValue());
51: }
52:
53: /**
54: * Test the contract of the equals method.
55: */
56: public void testEquals() {
57: ZipShort zs = new ZipShort(0x1234);
58: ZipShort zs2 = new ZipShort(0x1234);
59: ZipShort zs3 = new ZipShort(0x5678);
60:
61: assertTrue("reflexive", zs.equals(zs));
62:
63: assertTrue("works", zs.equals(zs2));
64: assertTrue("works, part two", !zs.equals(zs3));
65:
66: assertTrue("symmetric", zs2.equals(zs));
67:
68: assertTrue("null handling", !zs.equals(null));
69: assertTrue("non ZipShort handling", !zs.equals(new Integer(
70: 0x1234)));
71: }
72:
73: /**
74: * Test sign handling.
75: */
76: public void testSign() {
77: ZipShort zs = new ZipShort(new byte[] { (byte) 0xFF,
78: (byte) 0xFF });
79: assertEquals(0x0000FFFF, zs.getValue());
80: }
81:
82: }
|