Skip to content

Commit 46f88c0

Browse files
reynderspenberg
authored andcommitted
Full implementation of InetAddressTest
Signed-off-by: Joonas Reynders <joonas.reynders@iki.fi> Signed-off-by: Pekka Enberg <penberg@kernel.org>
1 parent 08fb7a4 commit 46f88c0

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

src/malva/java/net/InetAddressTest.java

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,144 @@
44
import malva.TestCase;
55

66
public class InetAddressTest extends TestCase {
7+
8+
public static void testEquals() throws Exception {
9+
assertTrue(InetAddress.getLocalHost().equals(InetAddress.getLocalHost()));
10+
assertFalse(InetAddress.getLocalHost().equals(null));
11+
}
12+
13+
public static void testGetAddress() throws Exception {
14+
assertNotNull(InetAddress.getLocalHost().getAddress());
15+
}
16+
17+
public static void testGetAllByName() throws Exception {
18+
assertThrows(new Block() {
19+
@Override public void run() throws Throwable {
20+
InetAddress.getAllByName("non_existent");
21+
}
22+
}, java.net.UnknownHostException.class);
23+
24+
assertTrue(InetAddress.getAllByName(null)[0].isLoopbackAddress());
25+
}
26+
27+
public static void testGetByAddress() throws Exception {
28+
assertTrue(InetAddress.getByAddress(InetAddress.getLocalHost().getAddress()).equals(InetAddress.getLocalHost()));
29+
InetAddress.getByAddress("anyhost", new byte[] {0, 0, 0, 0});
30+
31+
assertThrows(new Block() {
32+
@Override public void run() throws Throwable {
33+
InetAddress.getByAddress(new byte[] {0, 0, 0});
34+
}
35+
}, java.net.UnknownHostException.class);
36+
}
37+
38+
public static void testGetByName() throws Exception {
39+
assertThrows(new Block() {
40+
@Override public void run() throws Throwable {
41+
InetAddress.getByName("unknown");
42+
}
43+
}, java.net.UnknownHostException.class);
44+
45+
assertTrue(InetAddress.getByName(null).isLoopbackAddress());
46+
}
47+
48+
public static void testGetCanonicalHostName() throws Exception {
49+
// Just check that call does not fail
50+
InetAddress.getLocalHost().getCanonicalHostName();
51+
}
52+
53+
public static void testGetHostAddress() throws Exception {
54+
assertEquals("0.0.0.0", InetAddress.getByAddress(new byte[]{0, 0, 0, 0}).getHostAddress());
55+
}
56+
57+
public static void testGetHostName() throws Exception {
58+
assertEquals("testhost", InetAddress.getByAddress("testhost", new byte[] {0, 0, 0, 0}).getHostName());
59+
}
60+
61+
public static void testGetLocalHost() throws Exception {
62+
// Just test that the call does not fail
63+
InetAddress.getLocalHost();
64+
}
65+
66+
public static void testHashCode() {
67+
}
68+
69+
public static void testIsAnyLocalAddress() throws Exception {
70+
assertFalse(InetAddress.getLocalHost().isAnyLocalAddress());
71+
}
72+
73+
public static void testIsLinkLocalAddress() throws Exception {
74+
assertFalse(InetAddress.getLocalHost().isLinkLocalAddress());
75+
}
76+
777
public static void testIsLoopback() throws Exception {
878
assertTrue (InetAddress.getByName("127.0.0.1").isLoopbackAddress());
979
assertFalse(InetAddress.getByName("192.168.0.1").isLoopbackAddress());
1080
}
1181

82+
public static void testIsLoopbackAddress() throws Exception {
83+
assertFalse(InetAddress.getLocalHost().isLoopbackAddress());
84+
}
85+
86+
public static void testIsMCGlobal() throws Exception {
87+
assertFalse(InetAddress.getLocalHost().isMCGlobal());
88+
}
89+
90+
public static void testIsMCLinkLocal() throws Exception {
91+
assertFalse(InetAddress.getLocalHost().isMCLinkLocal());
92+
}
93+
94+
public static void testIsMCNodeLocal() throws Exception {
95+
assertFalse(InetAddress.getLocalHost().isMCNodeLocal());
96+
}
97+
98+
99+
public static void testIsMCOrgLocal() throws Exception {
100+
assertFalse(InetAddress.getLocalHost().isMCOrgLocal());
101+
}
102+
103+
public static void testIsMCSiteLocal() throws Exception {
104+
assertFalse(InetAddress.getLocalHost().isMCSiteLocal());
105+
}
106+
107+
public static void testIsMulticastAddress() throws Exception {
108+
assertFalse(InetAddress.getLocalHost().isMulticastAddress());
109+
}
110+
111+
public static void testIsReachable() throws Exception {
112+
assertTrue(InetAddress.getLocalHost().isReachable(100));
113+
}
114+
115+
public static void testIsSiteLocalAddress() throws Exception {
116+
assertTrue(InetAddress.getLocalHost().isSiteLocalAddress());
117+
}
118+
119+
public void testToString() {
120+
}
121+
12122
public static void main(String[] args) throws Exception {
123+
testEquals();
124+
testGetAddress();
125+
testGetAllByName();
126+
testGetByAddress();
127+
testGetByName();
128+
testGetCanonicalHostName();
129+
testGetHostAddress();
130+
testGetHostName();
131+
testGetLocalHost();
132+
//testHashCode();
133+
testIsAnyLocalAddress();
134+
testIsLinkLocalAddress();
13135
testIsLoopback();
136+
testIsLoopbackAddress();
137+
testIsMCGlobal();
138+
testIsMCLinkLocal();
139+
testIsMCNodeLocal();
140+
testIsMCOrgLocal();
141+
testIsMCSiteLocal();
142+
testIsMulticastAddress();
143+
testIsReachable();
144+
testIsSiteLocalAddress();
145+
//testToString();
14146
}
15147
}

0 commit comments

Comments
 (0)