diff options
Diffstat (limited to 'luni/src/test/java/libcore/java/net/InetSocketAddressTest.java')
-rw-r--r-- | luni/src/test/java/libcore/java/net/InetSocketAddressTest.java | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/luni/src/test/java/libcore/java/net/InetSocketAddressTest.java b/luni/src/test/java/libcore/java/net/InetSocketAddressTest.java index 3bca8dc..d97c48a 100644 --- a/luni/src/test/java/libcore/java/net/InetSocketAddressTest.java +++ b/luni/src/test/java/libcore/java/net/InetSocketAddressTest.java @@ -63,7 +63,7 @@ public class InetSocketAddressTest extends TestCase { } InetSocketAddress isa = new InetSocketAddress((InetAddress)null, 80); - assertEquals("0.0.0.0", isa.getHostName()); + assertEquals("::", isa.getHostName()); try { new InetSocketAddress(InetAddress.getByName("localhost"), 65536); @@ -80,7 +80,7 @@ public class InetSocketAddressTest extends TestCase { public void test_ConstructorI() { InetSocketAddress isa = new InetSocketAddress(65535); - assertEquals("0.0.0.0", isa.getHostName()); + assertEquals("::", isa.getHostName()); assertEquals(65535, isa.getPort()); try { @@ -150,6 +150,20 @@ public class InetSocketAddressTest extends TestCase { assertTrue(hasHostname.isUnresolved()); assertEquals("some host", hasHostname.getHostString()); assertEquals("some host", hasHostname.getHostName()); + + InetSocketAddress hasHostnameAndAddress = new InetSocketAddress( + InetAddress.getByAddress("some host", new byte[] { 127, 0, 0, 1 }), + 1234); + assertFalse(hasHostnameAndAddress.isUnresolved()); + assertEquals("some host", hasHostnameAndAddress.getHostString()); + assertEquals("some host", hasHostnameAndAddress.getHostName()); + + // Using a host name that is actually an IP. + InetSocketAddress hostnameIsIp = InetSocketAddress.createUnresolved("127.0.0.1", 1234); + assertTrue(hostnameIsIp.isUnresolved()); + assertEquals("127.0.0.1", hostnameIsIp.getHostString()); + assertEquals("127.0.0.1", hostnameIsIp.getHostName()); + // When we don't have a hostname, whether or not we do the reverse lookup is the difference // between getHostString and getHostName... InetAddress address = InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }); @@ -157,4 +171,18 @@ public class InetSocketAddressTest extends TestCase { assertEquals("127.0.0.1", noHostname.getHostString()); assertEquals("localhost", noHostname.getHostName()); } + + public void test_getHostString_cachingBehavior() throws Exception { + InetAddress inetAddress = InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }); + InetSocketAddress socketAddress = new InetSocketAddress(inetAddress, 1234); + assertEquals("127.0.0.1", socketAddress.getHostString()); + assertEquals("localhost", socketAddress.getHostName()); + assertEquals("localhost", socketAddress.getHostString()); + + inetAddress = InetAddress.getByName("127.0.0.1"); + socketAddress = new InetSocketAddress(inetAddress, 1234); + assertEquals("127.0.0.1", socketAddress.getHostString()); + assertEquals("localhost", socketAddress.getHostName()); + assertEquals("localhost", socketAddress.getHostString()); + } } |