KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > zip > ZipLongTest


1 /*
2  * Copyright 2001,2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 package org.apache.tools.zip;
19
20 import junit.framework.TestCase;
21
22 /**
23  * JUnit 3 testcases for org.apache.tools.zip.ZipLong.
24  *
25  */

26 public class ZipLongTest extends TestCase {
27
28     public ZipLongTest(String JavaDoc name) {
29         super(name);
30     }
31
32     /**
33      * Test conversion to bytes.
34      */

35     public void testToBytes() {
36         ZipLong zl = new ZipLong(0x12345678);
37         byte[] result = zl.getBytes();
38         assertEquals("length getBytes", 4, result.length);
39         assertEquals("first byte getBytes", 0x78, result[0]);
40         assertEquals("second byte getBytes", 0x56, result[1]);
41         assertEquals("third byte getBytes", 0x34, result[2]);
42         assertEquals("fourth byte getBytes", 0x12, result[3]);
43     }
44
45     /**
46      * Test conversion from bytes.
47      */

48     public void testFromBytes() {
49         byte[] val = new byte[] {0x78, 0x56, 0x34, 0x12};
50         ZipLong zl = new ZipLong(val);
51         assertEquals("value from bytes", 0x12345678, zl.getValue());
52     }
53
54     /**
55      * Test the contract of the equals method.
56      */

57     public void testEquals() {
58         ZipLong zl = new ZipLong(0x12345678);
59         ZipLong zl2 = new ZipLong(0x12345678);
60         ZipLong zl3 = new ZipLong(0x87654321);
61
62         assertTrue("reflexive", zl.equals(zl));
63
64         assertTrue("works", zl.equals(zl2));
65         assertTrue("works, part two", !zl.equals(zl3));
66
67         assertTrue("symmetric", zl2.equals(zl));
68
69         assertTrue("null handling", !zl.equals(null));
70         assertTrue("non ZipLong handling", !zl.equals(new Integer JavaDoc(0x1234)));
71     }
72
73     /**
74      * Test sign handling.
75      */

76     public void testSign() {
77         ZipLong zl = new ZipLong(new byte[] {(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF});
78         assertEquals(0x00000000FFFFFFFFl, zl.getValue());
79     }
80
81 }
82
Popular Tags