diff --git a/luni/src/test/java/libcore/java/net/OldDatagramSocketTest.java b/luni/src/test/java/libcore/java/net/OldDatagramSocketTest.java index 0a27fc79e773c70be79bf8c2762d341fdfeb4d08..666a5032339baca68f3897dd7cde389df6602631 100644 --- a/luni/src/test/java/libcore/java/net/OldDatagramSocketTest.java +++ b/luni/src/test/java/libcore/java/net/OldDatagramSocketTest.java @@ -769,18 +769,24 @@ public class OldDatagramSocketTest extends junit.framework./*Socket*/TestCase { } } - public void test_getSoTimeout() throws Exception { - // Test for method int java.net.DatagramSocket.getSoTimeout() - int portNumber = Support_PortManager.getNextPortForUDP(); - ds = new java.net.DatagramSocket(portNumber); - ds.setSoTimeout(100); - assertEquals("Returned incorrect timeout", 100, ds.getSoTimeout()); - ds.close(); + public void test_getSoTimeout_setSoTimeout() throws Exception { + // TODO: a useful test would check that setSoTimeout actually causes timeouts! + DatagramSocket s = new DatagramSocket(); + s.setSoTimeout(1500); + int ms = s.getSoTimeout(); + if (ms < 1500-10 || ms > 1500+10) { + fail("suspicious timeout: " + ms); + } + s.close(); try { - ds.getSoTimeout(); + s.getSoTimeout(); fail("SocketException was not thrown."); - } catch(SocketException se) { - //expected + } catch (SocketException expected) { + } + try { + s.setSoTimeout(1000); + fail("SocketException was not thrown."); + } catch (SocketException expected) { } } @@ -1133,21 +1139,6 @@ public class OldDatagramSocketTest extends junit.framework./*Socket*/TestCase { } } - public void test_setSoTimeoutI() throws Exception { - // Test for method void java.net.DatagramSocket.setSoTimeout(int) - int portNumber = Support_PortManager.getNextPortForUDP(); - ds = new java.net.DatagramSocket(portNumber); - ds.setSoTimeout(5000); - assertTrue("Set incorrect timeout", ds.getSoTimeout() >= 5000); - ds.close(); - try { - ds.setSoTimeout(100); - fail("SocketException was not thrown."); - } catch(SocketException se) { - //expected - } - } - public void test_ConstructorLjava_net_DatagramSocketImpl() { class testDatagramSocket extends DatagramSocket { public testDatagramSocket(DatagramSocketImpl impl){ diff --git a/luni/src/test/java/libcore/java/net/OldServerSocketTest.java b/luni/src/test/java/libcore/java/net/OldServerSocketTest.java index af47a5aa91bfb606ad8e95b481f3adec5be05b75..cf3548910913b06deec11f084eeae35522f697eb 100644 --- a/luni/src/test/java/libcore/java/net/OldServerSocketTest.java +++ b/luni/src/test/java/libcore/java/net/OldServerSocketTest.java @@ -242,25 +242,24 @@ public class OldServerSocketTest extends OldSocketTestCase { } } - public void test_getSoTimeout() throws IOException { - ServerSocket newSocket = new ServerSocket(); - newSocket.close(); + public void test_getSoTimeout_setSoTimeout() throws Exception { + // TODO: a useful test would check that setSoTimeout actually causes timeouts! + ServerSocket s = new ServerSocket(); + s.setSoTimeout(1500); + int ms = s.getSoTimeout(); + if (ms < 1500-10 || ms > 1500+10) { + fail("suspicious timeout: " + ms); + } + s.close(); try { - newSocket.setSoTimeout(100); + s.getSoTimeout(); fail("SocketException was not thrown."); - } catch(SocketException e) { - //expected + } catch (SocketException expected) { } - } - - public void test_setSoTimeoutI() throws IOException { - ServerSocket newSocket = new ServerSocket(); - newSocket.close(); try { - newSocket.setSoTimeout(100); + s.setSoTimeout(1000); fail("SocketException was not thrown."); - } catch(SocketException se) { - //expected + } catch (SocketException expected) { } } diff --git a/luni/src/test/java/libcore/java/net/OldSocketTest.java b/luni/src/test/java/libcore/java/net/OldSocketTest.java index 42f7b78160aa3c3f46ccdaae4f3e29f6312072d9..fda95579525437f7f91086e8b76e9772bba4b193 100644 --- a/luni/src/test/java/libcore/java/net/OldSocketTest.java +++ b/luni/src/test/java/libcore/java/net/OldSocketTest.java @@ -405,30 +405,24 @@ public class OldSocketTest extends OldSocketTestCase { } } - public void test_getSoTimeout() { - // Test for method int java.net.Socket.getSoTimeout() - int sport = startServer("SServer getSoTimeout"); - try { - s = new Socket(InetAddress.getLocalHost(), sport); - s.setSoTimeout(100); - assertEquals("Returned incorrect sotimeout", 100, s.getSoTimeout()); - ensureExceptionThrownIfOptionIsUnsupportedOnOS(SO_TIMEOUT); - } catch (Exception e) { - handleException(e, SO_TIMEOUT); + public void test_getSoTimeout_setSoTimeout() throws Exception { + // TODO: a useful test would check that setSoTimeout actually causes timeouts! + Socket s = new Socket(); + s.setSoTimeout(1500); + int ms = s.getSoTimeout(); + if (ms < 1500-10 || ms > 1500+10) { + fail("suspicious timeout: " + ms); } - + s.close(); try { - int portNumber = Support_PortManager.getNextPort(); - s = new Socket(InetAddress.getLocalHost(), sport, null, portNumber); - s.close(); - try { - s.getSoTimeout(); - fail("SocketException was not thrown."); - } catch(SocketException ioe) { - //expected - } - } catch(Exception e) { - fail("Unexpected exception was thrown: " + e.toString()); + s.getSoTimeout(); + fail("SocketException was not thrown."); + } catch (SocketException expected) { + } + try { + s.setSoTimeout(1000); + fail("SocketException was not thrown."); + } catch (SocketException expected) { } } @@ -586,31 +580,6 @@ public class OldSocketTest extends OldSocketTestCase { } } - public void test_setSoTimeoutI() { - // Test for method void java.net.Socket.setSoTimeout(int) - try { - int sport = startServer("SServer seSoTimeoutI"); - int portNumber = Support_PortManager.getNextPort(); - s = new Socket(InetAddress.getLocalHost(), sport, null, portNumber); - s.setSoTimeout(100); - assertEquals("Set incorrect sotimeout", 100, s.getSoTimeout()); - ensureExceptionThrownIfOptionIsUnsupportedOnOS(SO_TIMEOUT); - } catch (Exception e) { - handleException(e, SO_TIMEOUT); - } - - try { - Socket theSocket = new Socket(); - theSocket.close(); - theSocket.setSoTimeout(1); - fail("SocketException was not thrown."); - } catch(SocketException ioe) { - //expected - } catch(IOException ioe) { - fail("IOException was thrown."); - } - } - public void test_setTcpNoDelayZ() { // Test for method void java.net.Socket.setTcpNoDelay(boolean) try { @@ -1233,9 +1202,9 @@ public class OldSocketTest extends OldSocketTestCase { socket.connect( new InetSocketAddress(InetAddress.getLocalHost(), Support_PortManager.getNextPort())); fail("IllegalBlockingModeException was not thrown."); - } catch(IllegalBlockingModeException ibme) { - //expected + } catch (IllegalBlockingModeException expected) { } + socket.close(); } public void test_connectLjava_net_SocketAddressI() throws Exception { @@ -1532,17 +1501,14 @@ public class OldSocketTest extends OldSocketTestCase { // now try to set options while we are connecting theSocket = new Socket(); - SocketConnector connector = new SocketConnector(5000, theSocket, - nonReachableAddress); + SocketConnector connector = new SocketConnector(5000, theSocket, nonReachableAddress); connector.start(); - theSocket.setSoTimeout(100); + theSocket.setSoTimeout(1000); Thread.sleep(10); - assertEquals("Socket option not set during connect: 10 ", 100, - theSocket.getSoTimeout()); + assertEquals("Socket option not set during connect: 10 ", 1000, theSocket.getSoTimeout()); Thread.sleep(50); - theSocket.setSoTimeout(200); - assertEquals("Socket option not set during connect: 50 ", 200, - theSocket.getSoTimeout()); + theSocket.setSoTimeout(2000); + assertEquals("Socket option not set during connect: 50 ", 2000, theSocket.getSoTimeout()); Thread.sleep(5000); theSocket.close(); @@ -1554,9 +1520,9 @@ public class OldSocketTest extends OldSocketTestCase { socket.connect( new InetSocketAddress(InetAddress.getLocalHost(), Support_PortManager.getNextPort()), port); fail("IllegalBlockingModeException was not thrown."); - } catch(IllegalBlockingModeException ibme) { - //expected + } catch (IllegalBlockingModeException expected) { } + channel.close(); } public void test_isInputShutdown() throws IOException {