diff options
author | Narayan Kamath <narayan@google.com> | 2014-12-05 10:21:31 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-12-05 10:21:31 +0000 |
commit | c04b43461b80ceb1ecd035d17b88ebd89fa82219 (patch) | |
tree | c36f5c52cec3bd61b5c7ea9187544c741befbbff /harmony-tests/src/test | |
parent | e2ffb329440774b5c30b1e30386b9b404aa4051e (diff) | |
parent | 89b456da4190576d2c89ad01bd5a7627b0676c2c (diff) | |
download | libcore-c04b43461b80ceb1ecd035d17b88ebd89fa82219.zip libcore-c04b43461b80ceb1ecd035d17b88ebd89fa82219.tar.gz libcore-c04b43461b80ceb1ecd035d17b88ebd89fa82219.tar.bz2 |
am 89b456da: Merge "Fix failing socket tests."
* commit '89b456da4190576d2c89ad01bd5a7627b0676c2c':
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 cfe0ad6..649be09 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 576a303..2f456e0 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 4907dfb..11e3142 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) { } |