summaryrefslogtreecommitdiffstats
path: root/luni/src
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2009-09-01 19:38:28 -0700
committerLorenzo Colitti <lorenzo@google.com>2009-09-01 19:53:55 -0700
commita236145abdd13e2ccda79cc2ab81d61300910e70 (patch)
tree79cd00fab4b245900fdab4f6c8dfe266a0939fa3 /luni/src
parent051128862ae7c5c031b8ddb763848ed264a63746 (diff)
downloadlibcore-a236145abdd13e2ccda79cc2ab81d61300910e70.zip
libcore-a236145abdd13e2ccda79cc2ab81d61300910e70.tar.gz
libcore-a236145abdd13e2ccda79cc2ab81d61300910e70.tar.bz2
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. Change-Id: I4c093ccc268c91fc256b4ba76e1243de2d27670d
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);
}
/**