source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/testcases/org/apache/tools/zip/ZipShortTest.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

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