1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.compress.archivers.zip;
20
21 import junit.framework.TestCase;
22
23
24
25
26
27 public class ZipLongTest extends TestCase {
28
29 public ZipLongTest(String name) {
30 super(name);
31 }
32
33
34
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
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
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(0x1234)));
72 }
73
74
75
76
77 public void testSign() {
78 ZipLong zl = new ZipLong(new byte[] {(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF});
79 assertEquals(0x00000000FFFFFFFFl, zl.getValue());
80 }
81
82 public void testClone() {
83 ZipLong s1 = new ZipLong(42);
84 ZipLong s2 = (ZipLong) s1.clone();
85 assertNotSame(s1, s2);
86 assertEquals(s1, s2);
87 assertEquals(s1.getValue(), s2.getValue());
88 }
89 }