|
4 | 4 | import malva.TestCase;
|
5 | 5 |
|
6 | 6 | 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 | + |
7 | 77 | public static void testIsLoopback() throws Exception {
|
8 | 78 | assertTrue (InetAddress.getByName("127.0.0.1").isLoopbackAddress());
|
9 | 79 | assertFalse(InetAddress.getByName("192.168.0.1").isLoopbackAddress());
|
10 | 80 | }
|
11 | 81 |
|
| 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 | + |
12 | 122 | 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(); |
13 | 135 | testIsLoopback();
|
| 136 | + testIsLoopbackAddress(); |
| 137 | + testIsMCGlobal(); |
| 138 | + testIsMCLinkLocal(); |
| 139 | + testIsMCNodeLocal(); |
| 140 | + testIsMCOrgLocal(); |
| 141 | + testIsMCSiteLocal(); |
| 142 | + testIsMulticastAddress(); |
| 143 | + testIsReachable(); |
| 144 | + testIsSiteLocalAddress(); |
| 145 | + //testToString(); |
14 | 146 | }
|
15 | 147 | }
|
0 commit comments