summaryrefslogtreecommitdiffstats
path: root/luni/src/test/java/tests/api
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2012-07-19 18:20:19 -0700
committerElliott Hughes <enh@google.com>2012-07-19 18:20:19 -0700
commit514d3165e7a487224c1a20f1a55e8011eaf3e037 (patch)
tree8d3d79729b0baac9c3b86ed15739d7183da9539f /luni/src/test/java/tests/api
parent518cfbc45544a7c99eb8a85e67003b8f7a413a76 (diff)
downloadlibcore-514d3165e7a487224c1a20f1a55e8011eaf3e037.zip
libcore-514d3165e7a487224c1a20f1a55e8011eaf3e037.tar.gz
libcore-514d3165e7a487224c1a20f1a55e8011eaf3e037.tar.bz2
Second chunk of Support_PortManager removal.
Bug: 2441548 Change-Id: Id5fb5785259700db637c17522c105e6b0bb6b89f
Diffstat (limited to 'luni/src/test/java/tests/api')
-rw-r--r--luni/src/test/java/tests/api/javax/net/ServerSocketFactoryTest.java139
-rw-r--r--luni/src/test/java/tests/api/javax/net/SocketFactoryTest.java230
2 files changed, 97 insertions, 272 deletions
diff --git a/luni/src/test/java/tests/api/javax/net/ServerSocketFactoryTest.java b/luni/src/test/java/tests/api/javax/net/ServerSocketFactoryTest.java
index 053200f..34d7aed 100644
--- a/luni/src/test/java/tests/api/javax/net/ServerSocketFactoryTest.java
+++ b/luni/src/test/java/tests/api/javax/net/ServerSocketFactoryTest.java
@@ -30,158 +30,77 @@ import javax.net.ServerSocketFactory;
import junit.framework.TestCase;
-import tests.support.Support_PortManager;
-
-
-/**
- * Tests for <code>ServerSocketFactory</code> class constructors and methods.
- */
public class ServerSocketFactoryTest extends TestCase {
- /**
- * javax.net.SocketFactory#SocketFactory()
- */
public void test_Constructor() {
- try {
- ServerSocketFactory sf = new MyServerSocketFactory();
- } catch (Exception e) {
- fail("Unexpected exception " + e.toString());
- }
+ ServerSocketFactory sf = new MyServerSocketFactory();
}
- /**
- * javax.net.ServerSocketFactory#createServerSocket()
- */
- public final void test_createServerSocket_01() {
+ public final void test_createServerSocket() throws Exception {
ServerSocketFactory sf = ServerSocketFactory.getDefault();
- try {
- ServerSocket ss = sf.createServerSocket();
- assertNotNull(ss);
- } catch (SocketException e) {
- } catch (Exception e) {
- fail(e.toString());
- }
+ ServerSocket ss = sf.createServerSocket();
+ assertNotNull(ss);
+ ss.close();
}
- /**
- * javax.net.ServerSocketFactory#createServerSocket(int port)
- */
- public final void test_createServerSocket_02() {
+ public final void test_createServerSocket_I() throws Exception {
ServerSocketFactory sf = ServerSocketFactory.getDefault();
- int portNumber = Support_PortManager.getNextPort();
-
- try {
- ServerSocket ss = sf.createServerSocket(portNumber);
- assertNotNull(ss);
- } catch (Exception ex) {
- fail("Unexpected exception: " + ex);
- }
+ ServerSocket ss = sf.createServerSocket(0);
+ assertNotNull(ss);
try {
- sf.createServerSocket(portNumber);
+ sf.createServerSocket(ss.getLocalPort());
fail("IOException wasn't thrown");
- } catch (IOException ioe) {
- //expected
- } catch (Exception ex) {
- fail(ex + " was thrown instead of IOException");
+ } catch (IOException expected) {
}
+ ss.close();
+
try {
sf.createServerSocket(-1);
fail("IllegalArgumentException wasn't thrown");
- } catch (IllegalArgumentException ioe) {
- //expected
- } catch (Exception ex) {
- fail(ex + " was thrown instead of IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
}
}
- /**
- * javax.net.ServerSocketFactory#createServerSocket(int port, int backlog)
- */
- public final void test_createServerSocket_03() {
+ public final void test_createServerSocket_II() throws Exception {
ServerSocketFactory sf = ServerSocketFactory.getDefault();
- int portNumber = Support_PortManager.getNextPort();
-
- try {
- ServerSocket ss = sf.createServerSocket(portNumber, 0);
- assertNotNull(ss);
- } catch (Exception ex) {
- fail("Unexpected exception: " + ex);
- }
+ ServerSocket ss = sf.createServerSocket(0, 0);
+ assertNotNull(ss);
try {
- sf.createServerSocket(portNumber, 0);
+ sf.createServerSocket(ss.getLocalPort(), 0);
fail("IOException wasn't thrown");
- } catch (IOException ioe) {
- //expected
- } catch (Exception ex) {
- fail(ex + " was thrown instead of IOException");
+ } catch (IOException expected) {
}
+ ss.close();
+
try {
sf.createServerSocket(65536, 0);
fail("IllegalArgumentException wasn't thrown");
- } catch (IllegalArgumentException ioe) {
- //expected
- } catch (Exception ex) {
- fail(ex + " was thrown instead of IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
}
}
- /**
- * javax.net.ServerSocketFactory#createServerSocket(int port, int backlog, InetAddress ifAddress)
- */
- public final void test_createServerSocket_04() {
+ public final void test_createServerSocket_IIInetAddress() throws Exception {
ServerSocketFactory sf = ServerSocketFactory.getDefault();
- int portNumber = Support_PortManager.getNextPort();
- try {
- ServerSocket ss = sf.createServerSocket(portNumber, 0, InetAddress.getLocalHost());
- assertNotNull(ss);
- } catch (Exception ex) {
- fail("Unexpected exception: " + ex);
- }
+ ServerSocket ss = sf.createServerSocket(0, 0, InetAddress.getLocalHost());
+ assertNotNull(ss);
try {
- sf.createServerSocket(portNumber, 0, InetAddress.getLocalHost());
+ sf.createServerSocket(ss.getLocalPort(), 0, InetAddress.getLocalHost());
fail("IOException wasn't thrown");
- } catch (IOException ioe) {
- //expected
- } catch (Exception ex) {
- fail(ex + " was thrown instead of IOException");
+ } catch (IOException expected) {
}
+ ss.close();
+
try {
sf.createServerSocket(Integer.MAX_VALUE, 0, InetAddress.getLocalHost());
fail("IllegalArgumentException wasn't thrown");
- } catch (IllegalArgumentException ioe) {
- //expected
- } catch (Exception ex) {
- fail(ex + " was thrown instead of IllegalArgumentException");
- }
- }
-
- /**
- * javax.net.ServerSocketFactory#getDefault()
- */
- public final void test_getDefault() {
- ServerSocketFactory sf = ServerSocketFactory.getDefault();
- ServerSocket s;
- try {
- s = sf.createServerSocket(0);
- s.close();
- } catch (IOException e) {
- }
- try {
- s = sf.createServerSocket(0, 50);
- s.close();
- } catch (IOException e) {
- }
- try {
- s = sf.createServerSocket(0, 50, InetAddress.getLocalHost());
- s.close();
- } catch (IOException e) {
+ } catch (IllegalArgumentException expected) {
}
}
}
diff --git a/luni/src/test/java/tests/api/javax/net/SocketFactoryTest.java b/luni/src/test/java/tests/api/javax/net/SocketFactoryTest.java
index 2250602..e939a9b 100644
--- a/luni/src/test/java/tests/api/javax/net/SocketFactoryTest.java
+++ b/luni/src/test/java/tests/api/javax/net/SocketFactoryTest.java
@@ -33,200 +33,135 @@ import javax.net.SocketFactory;
import junit.framework.TestCase;
-import tests.support.Support_PortManager;
-
-
-/**
- * Tests for <code>SocketFactory</code> class methods.
- */
public class SocketFactoryTest extends TestCase {
- /**
- * javax.net.SocketFactory#SocketFactory()
- */
- public void test_Constructor() {
- try {
- MySocketFactory sf = new MySocketFactory();
- } catch (Exception e) {
- fail("Unexpected exception " + e.toString());
- }
+ public void test_Constructor() throws Exception {
+ new MySocketFactory();
}
- /**
- * javax.net.SocketFactory#createSocket()
- */
- public final void test_createSocket_01() {
+ public final void test_createSocket() throws Exception {
SocketFactory sf = SocketFactory.getDefault();
- try {
- Socket s = sf.createSocket();
- assertNotNull(s);
- assertEquals(-1, s.getLocalPort());
- assertEquals(0, s.getPort());
- } catch (Exception e) {
- fail("Unexpected exception: " + e);
- }
+ Socket s = sf.createSocket();
+ assertNotNull(s);
+ assertEquals(-1, s.getLocalPort());
+ assertEquals(0, s.getPort());
MySocketFactory msf = new MySocketFactory();
try {
msf.createSocket();
fail("No expected SocketException");
- } catch (SocketException e) {
- } catch (IOException e) {
- fail(e.toString());
+ } catch (SocketException expected) {
}
}
- /**
- * javax.net.SocketFactory#createSocket(String host, int port)
- */
- public final void test_createSocket_02() {
+ public final void test_createSocket_StringI() throws Exception {
SocketFactory sf = SocketFactory.getDefault();
- int portNumber = Support_PortManager.getNextPort();
- int sport = startServer("Cons String,I");
+ int sport = new ServerSocket(0).getLocalPort();
int[] invalidPorts = {Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE};
- try {
- Socket s = sf.createSocket(InetAddress.getLocalHost().getHostName(), sport);
- assertNotNull(s);
- assertTrue("Failed to create socket", s.getPort() == sport);
- } catch (Exception e) {
- fail("Unexpected exception: " + e);
- }
+ Socket s = sf.createSocket(InetAddress.getLocalHost().getHostName(), sport);
+ assertNotNull(s);
+ assertTrue("Failed to create socket", s.getPort() == sport);
try {
- Socket s = sf.createSocket("bla-bla", sport);
+ sf.createSocket("bla-bla", sport);
fail("UnknownHostException wasn't thrown");
- } catch (UnknownHostException uhe) {
- //expected
- } catch (Exception e) {
- fail(e + " was thrown instead of UnknownHostException");
+ } catch (UnknownHostException expected) {
}
for (int i = 0; i < invalidPorts.length; i++) {
try {
- Socket s = sf.createSocket(InetAddress.getLocalHost().getHostName(), invalidPorts[i]);
+ sf.createSocket(InetAddress.getLocalHost().getHostName(), invalidPorts[i]);
fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
- } catch (IllegalArgumentException iae) {
- //expected
- } catch (Exception e) {
- fail(e + " was thrown instead of IllegalArgumentException for " + invalidPorts[i]);
+ } catch (IllegalArgumentException expected) {
}
}
try {
- Socket s = sf.createSocket(InetAddress.getLocalHost().getHostName(), portNumber);
+ sf.createSocket(InetAddress.getLocalHost().getHostName(), s.getLocalPort());
fail("IOException wasn't thrown");
- } catch (IOException ioe) {
- //expected
+ } catch (IOException expected) {
}
SocketFactory f = SocketFactory.getDefault();
try {
- Socket s = f.createSocket("localhost", 8082);
+ f.createSocket(InetAddress.getLocalHost().getHostName(), 8082);
fail("IOException wasn't thrown ...");
- } catch (IOException e) {
+ } catch (IOException expected) {
}
}
- /**
- * javax.net.SocketFactory#createSocket(InetAddress host, int port)
- */
- public final void test_createSocket_03() {
+ public final void test_createSocket_InetAddressI() throws Exception {
SocketFactory sf = SocketFactory.getDefault();
- int portNumber = Support_PortManager.getNextPort();
- int sport = startServer("Cons InetAddress,I");
+ int sport = new ServerSocket(0).getLocalPort();
int[] invalidPorts = {Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE};
- try {
- Socket s = sf.createSocket(InetAddress.getLocalHost(), sport);
- assertNotNull(s);
- assertTrue("Failed to create socket", s.getPort() == sport);
- } catch (Exception e) {
- fail("Unexpected exception: " + e);
- }
+ Socket s = sf.createSocket(InetAddress.getLocalHost(), sport);
+ assertNotNull(s);
+ assertTrue("Failed to create socket", s.getPort() == sport);
for (int i = 0; i < invalidPorts.length; i++) {
try {
- Socket s = sf.createSocket(InetAddress.getLocalHost(), invalidPorts[i]);
+ sf.createSocket(InetAddress.getLocalHost(), invalidPorts[i]);
fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
- } catch (IllegalArgumentException iae) {
- //expected
- } catch (Exception e) {
- fail(e + " was thrown instead of IllegalArgumentException for " + invalidPorts[i]);
+ } catch (IllegalArgumentException expected) {
}
}
try {
- Socket s = sf.createSocket(InetAddress.getLocalHost(), portNumber);
+ sf.createSocket(InetAddress.getLocalHost(), s.getLocalPort());
fail("IOException wasn't thrown");
- } catch (IOException ioe) {
- //expected
+ } catch (IOException expected) {
}
SocketFactory f = SocketFactory.getDefault();
try {
- Socket s = f.createSocket(InetAddress.getLocalHost(), 8081);
+ f.createSocket(InetAddress.getLocalHost(), 8081);
fail("IOException wasn't thrown ...");
- } catch (IOException e) {
+ } catch (IOException expected) {
}
}
- /**
- * javax.net.SocketFactory#createSocket(InetAddress address, int port,
- * InetAddress localAddress, int localPort)
- */
- public final void test_createSocket_04() {
+ public final void test_createSocket_InetAddressIInetAddressI() throws Exception {
SocketFactory sf = SocketFactory.getDefault();
- int portNumber = Support_PortManager.getNextPort();
- int sport = startServer("Cons InetAddress,I,InetAddress,I");
+ int sport = new ServerSocket(0).getLocalPort();
int[] invalidPorts = {Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE};
- try {
- Socket s = sf.createSocket(InetAddress.getLocalHost(), sport,
- InetAddress.getLocalHost(), portNumber);
- assertNotNull(s);
- assertTrue("1: Failed to create socket", s.getPort() == sport);
- assertTrue("2: Failed to create socket", s.getLocalPort() == portNumber);
- } catch (Exception e) {
- fail("Unexpected exception: " + e);
- }
+ Socket s = sf.createSocket(InetAddress.getLocalHost(), sport,
+ InetAddress.getLocalHost(), 0);
+ assertNotNull(s);
+ assertTrue("1: Failed to create socket", s.getPort() == sport);
+ int portNumber = s.getLocalPort();
for (int i = 0; i < invalidPorts.length; i++) {
try {
- Socket s = sf.createSocket(InetAddress.getLocalHost(), invalidPorts[i],
- InetAddress.getLocalHost(), portNumber);
+ sf.createSocket(InetAddress.getLocalHost(), invalidPorts[i],
+ InetAddress.getLocalHost(), portNumber);
fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
- } catch (IllegalArgumentException iae) {
- //expected
- } catch (Exception e) {
- fail(e + " was thrown instead of IllegalArgumentException for " + invalidPorts[i]);
+ } catch (IllegalArgumentException expected) {
}
try {
- Socket s = sf.createSocket(InetAddress.getLocalHost(), sport,
- InetAddress.getLocalHost(), invalidPorts[i]);
+ sf.createSocket(InetAddress.getLocalHost(), sport,
+ InetAddress.getLocalHost(), invalidPorts[i]);
fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
- } catch (IllegalArgumentException iae) {
- //expected
- } catch (Exception e) {
- fail(e + " was thrown instead of IllegalArgumentException for " + invalidPorts[i]);
+ } catch (IllegalArgumentException expected) {
}
}
try {
- Socket s = sf.createSocket(InetAddress.getLocalHost(), sport,
- InetAddress.getLocalHost(), portNumber);
+ sf.createSocket(InetAddress.getLocalHost(), sport,
+ InetAddress.getLocalHost(), portNumber);
fail("IOException wasn't thrown");
- } catch (IOException ioe) {
- //expected
+ } catch (IOException expected) {
}
SocketFactory f = SocketFactory.getDefault();
try {
- Socket s = f.createSocket(InetAddress.getLocalHost(), 8081, InetAddress.getLocalHost(), 8082);
+ f.createSocket(InetAddress.getLocalHost(), 8081, InetAddress.getLocalHost(), 8082);
fail("IOException wasn't thrown ...");
- } catch (IOException e) {
+ } catch (IOException expected) {
}
}
@@ -234,59 +169,41 @@ public class SocketFactoryTest extends TestCase {
* javax.net.SocketFactory#createSocket(String host, int port,
* InetAddress localHost, int localPort)
*/
- public final void test_createSocket_05() {
+ public final void test_createSocket_05() throws Exception {
SocketFactory sf = SocketFactory.getDefault();
- int portNumber = Support_PortManager.getNextPort();
- int sport = startServer("Cons String,I,InetAddress,I");
+ int sport = new ServerSocket(0).getLocalPort();
int[] invalidPorts = {Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE};
- try {
- Socket s = sf.createSocket(InetAddress.getLocalHost().getHostName(), sport,
- InetAddress.getLocalHost(), portNumber);
- assertNotNull(s);
- assertTrue("1: Failed to create socket", s.getPort() == sport);
- assertTrue("2: Failed to create socket", s.getLocalPort() == portNumber);
- } catch (Exception e) {
- fail("Unexpected exception: " + e);
- }
+ Socket s = sf.createSocket(InetAddress.getLocalHost().getHostName(), sport,
+ InetAddress.getLocalHost(), 0);
+ assertNotNull(s);
+ assertTrue("1: Failed to create socket", s.getPort() == sport);
- portNumber = Support_PortManager.getNextPort();
try {
- Socket s = sf.createSocket("bla-bla", sport, InetAddress.getLocalHost(), portNumber);
+ sf.createSocket("bla-bla", sport, InetAddress.getLocalHost(), 0);
fail("UnknownHostException wasn't thrown");
- } catch (UnknownHostException uhe) {
- //expected
- } catch (Exception e) {
- fail(e + " was thrown instead of UnknownHostException");
+ } catch (UnknownHostException expected) {
}
for (int i = 0; i < invalidPorts.length; i++) {
- portNumber = Support_PortManager.getNextPort();
try {
- Socket s = sf.createSocket(InetAddress.getLocalHost().getHostName(), invalidPorts[i],
- InetAddress.getLocalHost(), portNumber);
+ sf.createSocket(InetAddress.getLocalHost().getHostName(), invalidPorts[i],
+ InetAddress.getLocalHost(), 0);
fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
- } catch (IllegalArgumentException iae) {
- //expected
- } catch (Exception e) {
- fail(e + " was thrown instead of IllegalArgumentException for " + invalidPorts[i]);
+ } catch (IllegalArgumentException expected) {
}
try {
- Socket s = sf.createSocket(InetAddress.getLocalHost().getHostName(), sport,
- InetAddress.getLocalHost(), invalidPorts[i]);
+ sf.createSocket(InetAddress.getLocalHost().getHostName(), sport,
+ InetAddress.getLocalHost(), invalidPorts[i]);
fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
- } catch (IllegalArgumentException iae) {
- //expected
- } catch (Exception e) {
- fail(e + " was thrown instead of IllegalArgumentException for " + invalidPorts[i]);
+ } catch (IllegalArgumentException expected) {
}
}
- SocketFactory f = SocketFactory.getDefault();
try {
- Socket s = f.createSocket("localhost", 8081, InetAddress.getLocalHost(), 8082);
+ sf.createSocket(InetAddress.getLocalHost().getHostName(), 8081, InetAddress.getLocalHost(), 8082);
fail("IOException wasn't thrown ...");
- } catch (IOException e) {
+ } catch (IOException expected) {
}
}
@@ -297,12 +214,12 @@ public class SocketFactoryTest extends TestCase {
SocketFactory sf = SocketFactory.getDefault();
Socket s;
try {
- s = sf.createSocket("localhost", 8082);
+ s = sf.createSocket(InetAddress.getLocalHost().getHostName(), 8082);
s.close();
} catch (IOException e) {
}
try {
- s = sf.createSocket("localhost", 8081, InetAddress.getLocalHost(), 8082);
+ s = sf.createSocket(InetAddress.getLocalHost().getHostName(), 8081, InetAddress.getLocalHost(), 8082);
s.close();
} catch (IOException e) {
}
@@ -317,17 +234,6 @@ public class SocketFactoryTest extends TestCase {
} catch (IOException e) {
}
}
-
- protected int startServer(String name) {
- int portNumber = Support_PortManager.getNextPort();
- ServerSocket ss = null;
- try {
- ss = new ServerSocket(portNumber);
- } catch (IOException e) {
- fail(name + ": " + e);
- }
- return ss.getLocalPort();
- }
}
class MySocketFactory extends SocketFactory {