am f27b4193: am 2add675f: Merge "Mapped IPv4 address test fix"
* commit 'f27b4193e37af4dbe983618f5a07473b7d70ccee':
Mapped IPv4 address test fix
diff --git a/luni/src/test/java/libcore/java/net/InetAddressTest.java b/luni/src/test/java/libcore/java/net/InetAddressTest.java
index edca1a6..c7617ab 100644
--- a/luni/src/test/java/libcore/java/net/InetAddressTest.java
+++ b/luni/src/test/java/libcore/java/net/InetAddressTest.java
@@ -77,6 +77,8 @@
assertEquals("/1.2.3.4", InetAddress.parseNumericAddress("1.2.3.4").toString());
// Regular IPv6.
assertEquals("/2001:4860:800d::68", InetAddress.parseNumericAddress("2001:4860:800d::68").toString());
+ // Mapped IPv4
+ assertEquals("/127.0.0.1", InetAddress.parseNumericAddress("::ffff:127.0.0.1").toString());
// Optional square brackets around IPv6 addresses, including mapped IPv4.
assertEquals("/2001:4860:800d::68", InetAddress.parseNumericAddress("[2001:4860:800d::68]").toString());
assertEquals("/127.0.0.1", InetAddress.parseNumericAddress("[::ffff:127.0.0.1]").toString());
@@ -101,9 +103,22 @@
}
public void test_isNumeric() throws Exception {
+ // IPv4
assertTrue(InetAddress.isNumeric("1.2.3.4"));
assertTrue(InetAddress.isNumeric("127.0.0.1"));
+ // IPv6
+ assertTrue(InetAddress.isNumeric("::1"));
+ assertTrue(InetAddress.isNumeric("2001:4860:800d::68"));
+
+ // Mapped IPv4
+ assertTrue(InetAddress.isNumeric("::ffff:127.0.0.1"));
+
+ // Optional square brackets around IPv6 addresses, including mapped IPv4.
+ assertTrue(InetAddress.isNumeric("[2001:4860:800d::68]"));
+ assertTrue(InetAddress.isNumeric("[::ffff:127.0.0.1]"));
+
+ // Negative test
assertFalse(InetAddress.isNumeric("example.com"));
for (String invalid : INVALID_IPv4_NUMERIC_ADDRESSES) {
@@ -113,6 +128,7 @@
public void test_isLinkLocalAddress() throws Exception {
assertFalse(InetAddress.getByName("127.0.0.1").isLinkLocalAddress());
+ assertFalse(InetAddress.getByName("::ffff:127.0.0.1").isLinkLocalAddress());
assertTrue(InetAddress.getByName("169.254.1.2").isLinkLocalAddress());
assertFalse(InetAddress.getByName("fec0::").isLinkLocalAddress());
@@ -195,6 +211,9 @@
assertEquals("127.0.0.1", Inet4Address.LOOPBACK.getHostAddress());
+ // IPv4 mapped address
+ assertEquals("127.0.0.1", InetAddress.getByName("::ffff:127.0.0.1").getHostAddress());
+
InetAddress aAddr = InetAddress.getByName("224.0.0.0");
assertEquals("224.0.0.0", aAddr.getHostAddress());
diff --git a/luni/src/test/java/libcore/java/security/cert/SubjectAlternativeNameTest.java b/luni/src/test/java/libcore/java/security/cert/SubjectAlternativeNameTest.java
index 88d5011..1b440c1 100644
--- a/luni/src/test/java/libcore/java/security/cert/SubjectAlternativeNameTest.java
+++ b/luni/src/test/java/libcore/java/security/cert/SubjectAlternativeNameTest.java
@@ -38,7 +38,9 @@
public void testFormatIpv4MappedAddress() throws Exception {
byte[] mappedAddress = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 127, 0, 0, 1 };
- assertEquals("127.0.0.1", formatIpAddress(mappedAddress));
+ String decoded = formatIpAddress(mappedAddress);
+ assertTrue(decoded,
+ decoded.equals("127.0.0.1") || decoded.equalsIgnoreCase("::ffff:127.0.0.1"));
}
public void testFormatIpv6Address() throws Exception {