1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.compress.archivers.zip;
19
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21 import static org.junit.jupiter.api.Assertions.assertNotEquals;
22 import static org.junit.jupiter.api.Assertions.assertNotSame;
23
24 import org.junit.jupiter.api.Test;
25
26
27
28
29 public class ZipLongTest {
30
31 @Test
32 public void testClone() {
33 final ZipLong s1 = new ZipLong(42);
34 final ZipLong s2 = (ZipLong) s1.clone();
35 assertNotSame(s1, s2);
36 assertEquals(s1, s2);
37 assertEquals(s1.getValue(), s2.getValue());
38 }
39
40
41
42
43 @Test
44 public void testEquals() {
45 final ZipLong zl = new ZipLong(0x12345678);
46 final ZipLong zl2 = new ZipLong(0x12345678);
47 final ZipLong zl3 = new ZipLong(0x87654321);
48
49 assertEquals(zl, zl, "reflexive");
50
51 assertEquals(zl, zl2, "works");
52 assertNotEquals(zl, zl3, "works, part two");
53
54 assertEquals(zl2, zl, "symmetric");
55
56 assertNotEquals(null, zl, "null handling");
57 assertNotEquals(zl, Integer.valueOf(0x1234), "non ZipLong handling");
58 }
59
60
61
62
63 @Test
64 public void testFromBytes() {
65 final byte[] val = { 0x78, 0x56, 0x34, 0x12 };
66 final ZipLong zl = new ZipLong(val);
67 assertEquals(0x12345678, zl.getValue(), "value from bytes");
68 }
69
70
71
72
73 @Test
74 public void testPut() {
75 final byte[] arr = new byte[5];
76 ZipLong.putLong(0x12345678, arr, 1);
77 assertEquals(0x78, arr[1], "first byte getBytes");
78 assertEquals(0x56, arr[2], "second byte getBytes");
79 assertEquals(0x34, arr[3], "third byte getBytes");
80 assertEquals(0x12, arr[4], "fourth byte getBytes");
81 }
82
83
84
85
86 @Test
87 public void testSign() {
88 ZipLong zl = new ZipLong(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF });
89 assertEquals(0x00000000FFFFFFFFL, zl.getValue());
90 assertEquals(-1, zl.getIntValue());
91
92 zl = new ZipLong(0xFFFF_FFFFL);
93 assertEquals(0x00000000FFFFFFFFL, zl.getValue());
94 zl = new ZipLong(0xFFFF_FFFF);
95 assertEquals(0xFFFF_FFFF_FFFF_FFFFL, zl.getValue());
96
97 }
98
99
100
101
102 @Test
103 public void testToBytes() {
104 final ZipLong zl = new ZipLong(0x12345678);
105 final byte[] result = zl.getBytes();
106 assertEquals(4, result.length, "length getBytes");
107 assertEquals(0x78, result[0], "first byte getBytes");
108 assertEquals(0x56, result[1], "second byte getBytes");
109 assertEquals(0x34, result[2], "third byte getBytes");
110 assertEquals(0x12, result[3], "fourth byte getBytes");
111 }
112 }