From a236145abdd13e2ccda79cc2ab81d61300910e70 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Tue, 1 Sep 2009 19:38:28 -0700 Subject: 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 --- .../luni/tests/java/net/InetAddressTest.java | 27 ++++++++-------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'luni/src') 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); } /** -- cgit v1.1