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.ZipLong.
25: *
26: */
27: public class ZipLongTest extends TestCase {
28:
29: public ZipLongTest(String name) {
30: super (name);
31: }
32:
33: /**
34: * Test conversion to bytes.
35: */
36: public void testToBytes() {
37: ZipLong zl = new ZipLong(0x12345678);
38: byte[] result = zl.getBytes();
39: assertEquals("length getBytes", 4, result.length);
40: assertEquals("first byte getBytes", 0x78, result[0]);
41: assertEquals("second byte getBytes", 0x56, result[1]);
42: assertEquals("third byte getBytes", 0x34, result[2]);
43: assertEquals("fourth byte getBytes", 0x12, result[3]);
44: }
45:
46: /**
47: * Test conversion from bytes.
48: */
49: public void testFromBytes() {
50: byte[] val = new byte[] { 0x78, 0x56, 0x34, 0x12 };
51: ZipLong zl = new ZipLong(val);
52: assertEquals("value from bytes", 0x12345678, zl.getValue());
53: }
54:
55: /**
56: * Test the contract of the equals method.
57: */
58: public void testEquals() {
59: ZipLong zl = new ZipLong(0x12345678);
60: ZipLong zl2 = new ZipLong(0x12345678);
61: ZipLong zl3 = new ZipLong(0x87654321);
62:
63: assertTrue("reflexive", zl.equals(zl));
64:
65: assertTrue("works", zl.equals(zl2));
66: assertTrue("works, part two", !zl.equals(zl3));
67:
68: assertTrue("symmetric", zl2.equals(zl));
69:
70: assertTrue("null handling", !zl.equals(null));
71: assertTrue("non ZipLong handling", !zl.equals(new Integer(
72: 0x1234)));
73: }
74:
75: /**
76: * Test sign handling.
77: */
78: public void testSign() {
79: ZipLong zl = new ZipLong(new byte[] { (byte) 0xFF, (byte) 0xFF,
80: (byte) 0xFF, (byte) 0xFF });
81: assertEquals(0x00000000FFFFFFFFl, zl.getValue());
82: }
83:
84: }
|