diff options
author | Narayan Kamath <narayan@google.com> | 2014-12-08 10:12:52 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-12-08 10:12:52 +0000 |
commit | 6d24bc8cf5bade9450ebd715e60d80f788726571 (patch) | |
tree | 639c869895a88c588f732da2b8c3b537ad22143c /harmony-tests/src/test | |
parent | 6d65c2cb18ac0de361ee433739f354a2a63ec943 (diff) | |
parent | a951e74897193848ee88ed1c5b0a1d536f403d70 (diff) | |
download | libcore-6d24bc8cf5bade9450ebd715e60d80f788726571.zip libcore-6d24bc8cf5bade9450ebd715e60d80f788726571.tar.gz libcore-6d24bc8cf5bade9450ebd715e60d80f788726571.tar.bz2 |
am a951e748: Fix failing socket tests.
* commit 'a951e74897193848ee88ed1c5b0a1d536f403d70':
Fix failing socket tests.
Diffstat (limited to 'harmony-tests/src/test')
5 files changed, 33 insertions, 49 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/InetAddressTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/InetAddressTest.java index 959f83c..42f88c1 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/InetAddressTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/InetAddressTest.java @@ -24,31 +24,25 @@ import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.UnknownHostException; -import java.security.Permission; import java.util.ArrayList; import java.util.Enumeration; import org.apache.harmony.testframework.serialization.SerializationTest; import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert; -import tests.support.Support_Configuration; public class InetAddressTest extends junit.framework.TestCase { /** * java.net.InetAddress#getByName(String) */ - public void test_getByNameUnknownHostException() { + public void test_getByName_exceptionContainsUsefulMessage() { // Related to HARMONY-5784 - - // loop a few times to flex the negative cache paths - for (int i = 0; i < 5; i++) { - try { - InetAddress.getByName("unknown.unknown.bad"); - fail("An UnknownHostException should have been thrown"); - } catch (UnknownHostException e) { - assertTrue(e.getMessage().contains("unknown.unknown.bad")); - } + try { + InetAddress.getByName("1.2.3.4hello"); + fail(); + } catch (UnknownHostException e) { + assertTrue(e.getMessage().contains("1.2.3.4hello")); } } diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/SocketTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/SocketTest.java index 18d2cb2..4df92e2 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/SocketTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/SocketTest.java @@ -274,7 +274,7 @@ public class SocketTest extends junit.framework.TestCase { public void test_connect_unknownhost() throws Exception { Socket socket = new Socket(); try { - socket.connect(new InetSocketAddress("unknownhost.invalid", 12345)); + socket.connect(new InetSocketAddress("1.2.3.4hello", 12345)); fail(); } catch (UnknownHostException expected) { } diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/SocketFactoryTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/SocketFactoryTest.java index e939a9b..d566ee3 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/SocketFactoryTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/SocketFactoryTest.java @@ -65,7 +65,7 @@ public class SocketFactoryTest extends TestCase { assertTrue("Failed to create socket", s.getPort() == sport); try { - sf.createSocket("bla-bla", sport); + sf.createSocket("1.2.3.4hello", sport); fail("UnknownHostException wasn't thrown"); } catch (UnknownHostException expected) { } @@ -180,7 +180,7 @@ public class SocketFactoryTest extends TestCase { assertTrue("1: Failed to create socket", s.getPort() == sport); try { - sf.createSocket("bla-bla", sport, InetAddress.getLocalHost(), 0); + sf.createSocket("1.2.3.4hello", sport, InetAddress.getLocalHost(), 0); fail("UnknownHostException wasn't thrown"); } catch (UnknownHostException expected) { } diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketFactoryTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketFactoryTest.java index 0d91116..e890032 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketFactoryTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketFactoryTest.java @@ -61,52 +61,42 @@ public class SSLSocketFactoryTest extends TestCase { /** * javax.net.ssl.SSLSocketFactory#createSocket(Socket s, String host, int port, boolean autoClose) */ - public void test_createSocket() { + public void test_createSocket() throws Exception { SSLSocketFactory sf = (SSLSocketFactory)SSLSocketFactory.getDefault(); int sport = startServer("test_createSocket()"); int[] invalid = { Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE }; - try { - Socket st = new Socket("localhost", sport); - Socket s = sf.createSocket(st, "localhost", sport, false); - assertFalse(s.isClosed()); - } catch (Exception ex) { - fail("Unexpected exception " + ex); - } - try { - Socket st = new Socket("localhost", sport); - Socket s = sf.createSocket(st, "localhost", sport, true); - s.close(); - assertTrue(st.isClosed()); - } catch (Exception ex) { - fail("Unexpected exception " + ex); - } + + + Socket st = new Socket("localhost", sport); + Socket s = sf.createSocket(st, "localhost", sport, false); + assertFalse(s.isClosed()); + + st = new Socket("localhost", sport); + s = sf.createSocket(st, "localhost", sport, true); + s.close(); + assertTrue(st.isClosed()); + try { sf.createSocket(null, "localhost", sport, true); - fail("IOException wasn't thrown"); - } catch (IOException ioe) { - // expected - } catch (NullPointerException e) { - // expected + fail(); + } catch (NullPointerException expected) { } + for (int i = 0; i < invalid.length; i++) { try { - Socket s = sf.createSocket(new Socket(), "localhost", 1080, false); - fail("IOException wasn't thrown"); - } catch (IOException ioe) { - // expected + s = sf.createSocket(new Socket(), "localhost", 1080, false); + fail(); + } catch (IOException expected) { } } try { - Socket st = new Socket("bla-bla", sport); - Socket s = sf.createSocket(st, "bla-bla", sport, false); - fail("UnknownHostException wasn't thrown: " + "bla-bla"); - } catch (UnknownHostException uhe) { - // expected - } catch (Exception e) { - fail(e + " was thrown instead of UnknownHostException"); + st = new Socket("1.2.3.4hello", sport); + s = sf.createSocket(st, "1.2.3.4hello", sport, false); + fail(); + } catch (UnknownHostException expected) { } } diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java index b4cbde2..950d534 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java @@ -158,7 +158,7 @@ public class SSLSocketTest extends TestCase { } try { - getSSLSocket("bla-bla", sport); + getSSLSocket("1.2.3.4hello", sport); fail(); } catch (UnknownHostException expected) { } @@ -199,7 +199,7 @@ public class SSLSocketTest extends TestCase { } try { - getSSLSocket("bla-bla", sport, InetAddress.getLocalHost(), 0); + getSSLSocket("1.2.3.4hello", sport, InetAddress.getLocalHost(), 0); fail(); } catch (UnknownHostException expected) { } |