IPAddressTest.java
1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package org.onlab.packet;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import org.junit.Test;
import org.onlab.packet.IPAddress.Version;
import com.google.common.testing.EqualsTester;
public class IPAddressTest {
private static final byte [] BYTES1 = new byte [] {0x0, 0x0, 0x0, 0xa};
private static final byte [] BYTES2 = new byte [] {0x0, 0x0, 0x0, 0xb};
private static final int INTVAL1 = 10;
private static final int INTVAL2 = 12;
private static final String STRVAL = "0.0.0.11";
@Test
public void testEquality() {
IPAddress ip1 = IPAddress.valueOf(BYTES1);
IPAddress ip2 = IPAddress.valueOf(BYTES2);
IPAddress ip3 = IPAddress.valueOf(INTVAL1);
IPAddress ip4 = IPAddress.valueOf(INTVAL2);
IPAddress ip5 = IPAddress.valueOf(STRVAL);
new EqualsTester().addEqualityGroup(ip1, ip3)
.addEqualityGroup(ip2, ip5)
.addEqualityGroup(ip4)
.testEquals();
}
@Test
public void basics() {
IPAddress ip4 = IPAddress.valueOf(BYTES1);
assertEquals("incorrect IP Version", Version.INET, ip4.version());
assertEquals("faulty toOctets()", Arrays.equals(
new byte [] {0x0, 0x0, 0x0, 0xa}, ip4.toOctets()), true);
assertEquals("faulty toInt()", INTVAL1, ip4.toInt());
assertEquals("faulty toString()", "0.0.0.10", ip4.toString());
}
}