summaryrefslogtreecommitdiffstats
path: root/luni/src
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-09-04 10:48:43 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2009-09-04 10:48:43 -0700
commit8ae7a7764fcad09504673f1da328ebabdb3c62f1 (patch)
tree0995acea520f604e84d35969ace7a71abad076bf /luni/src
parent054a74b628697276d163568adcc02f719a8240f8 (diff)
parenta236145abdd13e2ccda79cc2ab81d61300910e70 (diff)
downloadlibcore-8ae7a7764fcad09504673f1da328ebabdb3c62f1.zip
libcore-8ae7a7764fcad09504673f1da328ebabdb3c62f1.tar.gz
libcore-8ae7a7764fcad09504673f1da328ebabdb3c62f1.tar.bz2
Merge change 23572 into eclair
* changes: Do not check hash codes against golden values. Instead, spot check that they differ for different addresses and obvious values (e.g., 0 or 1) that might be returned by buggy implementations.
Diffstat (limited to 'luni/src')
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetAddressTest.java27
1 files changed, 10 insertions, 17 deletions
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetAddressTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetAddressTest.java
index 5c8808c..6087a46 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetAddressTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetAddressTest.java
@@ -479,10 +479,6 @@ public class InetAddressTest extends junit.framework.TestCase {
}
}
- static final int TEST_IP_HASHCODE = 2130706433;
- static final int TEST_IP6_HASHCODE = -1022939537;
- static final int TEST_IP6_LO_HASHCODE = 1353309698;
-
/**
* @tests java.net.InetAddress#hashCode()
*/
@@ -492,28 +488,25 @@ public class InetAddressTest extends junit.framework.TestCase {
method = "hashCode",
args = {}
)
- void assertHashCode(String literal, int expectedHashCode) {
+ int getHashCode(String literal) {
InetAddress host = null;
try {
host = InetAddress.getByName(literal);
} catch(UnknownHostException e) {
fail("Exception during hashCode test : " + e.getMessage());
}
- int hashCode = host.hashCode();
- assertEquals("incorrect hashCode for " + host, expectedHashCode,
- hashCode);
+ return host.hashCode();
}
public void test_hashCode() {
- // Test for method int java.net.InetAddress.hashCode()
- // Create InetAddresses from string literals instead of from hostnames
- // because we are only testing hashCode, not getByName. That way the
- // test does not depend on name resolution and we can test many
- // different addresses, not just localhost.
- assertHashCode(Support_Configuration.InetTestIP, TEST_IP_HASHCODE);
- assertHashCode(Support_Configuration.InetTestIP6, TEST_IP6_HASHCODE);
- assertHashCode(Support_Configuration.InetTestIP6LO,
- TEST_IP6_LO_HASHCODE);
+ int hashCode = getHashCode(Support_Configuration.InetTestIP);
+ int ip6HashCode = getHashCode(Support_Configuration.InetTestIP6);
+ int ip6LOHashCode = getHashCode(Support_Configuration.InetTestIP6LO);
+ assertFalse("Hash collision", hashCode == ip6HashCode);
+ assertFalse("Hash collision", ip6HashCode == ip6LOHashCode);
+ assertFalse("Hash collision", hashCode == ip6LOHashCode);
+ assertFalse("Hash collision", ip6LOHashCode == 0);
+ assertFalse("Hash collision", ip6LOHashCode == 1);
}
/**