diff options
author | Elliott Hughes <enh@google.com> | 2014-06-17 14:47:50 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2014-06-17 14:47:50 -0700 |
commit | 6188cc840d4987d2445740ce8a13dd335b6c6f73 (patch) | |
tree | 94bc23d983f20338a7ec1debc16ccfc250ad0488 /harmony-tests | |
parent | aaddf1a8047e874ebba53b3b19d781d4a269423f (diff) | |
parent | 63744c884dd4b4f4307f2b021fb894af164972af (diff) | |
download | libcore-6188cc840d4987d2445740ce8a13dd335b6c6f73.zip libcore-6188cc840d4987d2445740ce8a13dd335b6c6f73.tar.gz libcore-6188cc840d4987d2445740ce8a13dd335b6c6f73.tar.bz2 |
resolved conflicts for merge of 63744c88 to master
Change-Id: I2dbbda225d0fbe61da34f93abbb466ed490ba405
Diffstat (limited to 'harmony-tests')
6 files changed, 115 insertions, 197 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/HttpCookieTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/HttpCookieTest.java index 306e697..d1cf18f 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/HttpCookieTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/HttpCookieTest.java @@ -234,16 +234,6 @@ public class HttpCookieTest extends TestCase { assertFalse(cookie.getSecure()); } - public void test_Is_SetHttpOnly() { - HttpCookie cookie = new HttpCookie("testName", "value"); - assertFalse(cookie.isHttpOnly()); - - cookie.setHttpOnly(true); - assertTrue(cookie.isHttpOnly()); - cookie.setHttpOnly(false); - assertFalse(cookie.isHttpOnly()); - } - /** * java.net.HttpCookie#getPath(), setPath(String) * @since 1.6 @@ -817,24 +807,20 @@ public class HttpCookieTest extends TestCase { // Default is !httpOnly. List<HttpCookie> list = HttpCookie.parse("Set-Cookie: SID=31d4d96e407aad42"); HttpCookie cookie = list.get(0); - assertFalse(cookie.isHttpOnly()); // Well formed, simple. list = HttpCookie.parse("Set-Cookie: SID=31d4d96e407aad42; HttpOnly"); cookie = list.get(0); - assertTrue(cookie.isHttpOnly()); // Well formed, other attributes present. list = HttpCookie.parse("Set-Cookie: SID=31d4d96e407aad42; Path=/; Secure; HttpOnly"); cookie = list.get(0); - assertTrue(cookie.isHttpOnly()); assertTrue(cookie.getSecure()); assertEquals("/", cookie.getPath()); // Mangled spacing, casing and attributes that have an (ignored) value. list = HttpCookie.parse("Set-Cookie:SID=31d4d96e407aad42;Path=/;secure=false;httponly=false"); cookie = list.get(0); - assertTrue(cookie.isHttpOnly()); assertTrue(cookie.getSecure()); assertEquals("/", cookie.getPath()); } diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java index 731e907..4469e01 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/DatagramChannelTest.java @@ -25,7 +25,6 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; import java.net.SocketException; import java.nio.ByteBuffer; -import java.nio.channels.AlreadyBoundException; import java.nio.channels.AsynchronousCloseException; import java.nio.channels.ClosedChannelException; import java.nio.channels.DatagramChannel; @@ -72,11 +71,11 @@ public class DatagramChannelTest extends TestCase { channel1 = DatagramChannel.open(); channel2 = DatagramChannel.open(); - channel1.bind(new InetSocketAddress(Inet6Address.LOOPBACK, 0)); - channel2.bind(new InetSocketAddress(Inet6Address.LOOPBACK, 0)); + channel1.socket().bind(new InetSocketAddress(Inet6Address.LOOPBACK, 0)); + channel2.socket().bind(new InetSocketAddress(Inet6Address.LOOPBACK, 0)); - channel1Address = (InetSocketAddress) channel1.getLocalAddress(); - channel2Address = (InetSocketAddress) channel2.getLocalAddress(); + channel1Address = (InetSocketAddress) channel1.socket().getLocalSocketAddress(); + channel2Address = (InetSocketAddress) channel2.socket().getLocalSocketAddress(); this.datagramSocket1 = new DatagramSocket(0, Inet6Address.LOOPBACK); this.datagramSocket2 = new DatagramSocket(0, Inet6Address.LOOPBACK); @@ -1943,7 +1942,7 @@ public class DatagramChannelTest extends TestCase { sourceArray[i] = (byte) i; } - this.channel1.connect(channel1.getLocalAddress()); + this.channel1.connect(channel1.socket().getLocalSocketAddress()); this.channel2.connect(datagramSocket1Address); // the different addr // write @@ -1973,7 +1972,7 @@ public class DatagramChannelTest extends TestCase { assertEquals(CAPACITY_NORMAL, dc.write(sourceBuf)); // Connect channel2 after data has been written. - channel2.connect(dc.getLocalAddress()); + channel2.connect(dc.socket().getLocalSocketAddress()); // read ByteBuffer targetBuf = ByteBuffer.wrap(targetArray); @@ -2165,7 +2164,7 @@ public class DatagramChannelTest extends TestCase { assertEquals(CAPACITY_NORMAL, dc.write(sourceBuf)); // Connect channel2 after data has been written. - channel2.connect(dc.getLocalAddress()); + channel2.connect(dc.socket().getLocalSocketAddress()); // read ByteBuffer targetBuf = ByteBuffer.wrap(targetArray); @@ -2383,8 +2382,8 @@ public class DatagramChannelTest extends TestCase { public void test_bounded_harmony6493() throws IOException { DatagramChannel server = DatagramChannel.open(); InetSocketAddress addr = new InetSocketAddress("localhost", 0); - server.bind(addr); - SocketAddress boundedAddress = server.getLocalAddress(); + server.socket().bind(addr); + SocketAddress boundedAddress = server.socket().getLocalSocketAddress(); DatagramChannel client = DatagramChannel.open(); ByteBuffer sent = ByteBuffer.allocate(1024); @@ -2400,11 +2399,11 @@ public class DatagramChannelTest extends TestCase { public void test_bind_null() throws Exception { DatagramChannel dc = DatagramChannel.open(); try { - assertNull(dc.getLocalAddress()); + assertNull(dc.socket().getLocalSocketAddress()); - dc.bind(null); + dc.socket().bind(null); - InetSocketAddress localAddress = (InetSocketAddress) dc.getLocalAddress(); + InetSocketAddress localAddress = (InetSocketAddress) dc.socket().getLocalSocketAddress(); assertTrue(localAddress.getAddress().isAnyLocalAddress()); assertTrue(localAddress.getPort() > 0); } finally { @@ -2416,7 +2415,7 @@ public class DatagramChannelTest extends TestCase { DatagramChannel dc = DatagramChannel.open(); try { // Bind to a local address that is in use - dc.bind(channel1Address); + dc.socket().bind(channel1Address); fail(); } catch (IOException expected) { } finally { @@ -2429,38 +2428,25 @@ public class DatagramChannelTest extends TestCase { dc.close(); try { - dc.bind(null); + dc.socket().bind(null); fail(); - } catch (ClosedChannelException expected) { - } finally { - dc.close(); - } - } - - public void test_bind_twice() throws Exception { - DatagramChannel dc = DatagramChannel.open(); - dc.bind(null); - - try { - dc.bind(null); - fail(); - } catch (AlreadyBoundException expected) { + } catch (IOException expected) { } finally { dc.close(); } } public void test_bind_explicitPort() throws Exception { - InetSocketAddress address = (InetSocketAddress) channel1.getLocalAddress(); + InetSocketAddress address = (InetSocketAddress) channel1.socket().getLocalSocketAddress(); assertTrue(address.getPort() > 0); DatagramChannel dc = DatagramChannel.open(); // Allow the socket to bind to a port we know is already in use. dc.socket().setReuseAddress(true); InetSocketAddress bindAddress = new InetSocketAddress("localhost", address.getPort()); - dc.bind(bindAddress); + dc.socket().bind(bindAddress); - InetSocketAddress boundAddress = (InetSocketAddress) dc.getLocalAddress(); + InetSocketAddress boundAddress = (InetSocketAddress) dc.socket().getLocalSocketAddress(); assertEquals(bindAddress.getHostName(), boundAddress.getHostName()); assertEquals(bindAddress.getPort(), boundAddress.getPort()); @@ -2471,16 +2457,16 @@ public class DatagramChannelTest extends TestCase { /** Checks that the SocketChannel and associated Socket agree on the socket state. */ public void test_bind_socketSync() throws IOException { DatagramChannel dc = DatagramChannel.open(); - assertNull(dc.getLocalAddress()); + assertNull(dc.socket().getLocalSocketAddress()); DatagramSocket socket = dc.socket(); assertNull(socket.getLocalSocketAddress()); assertFalse(socket.isBound()); InetSocketAddress bindAddr = new InetSocketAddress("localhost", 0); - dc.bind(bindAddr); + dc.socket().bind(bindAddr); - InetSocketAddress actualAddr = (InetSocketAddress) dc.getLocalAddress(); + InetSocketAddress actualAddr = (InetSocketAddress) dc.socket().getLocalSocketAddress(); assertEquals(actualAddr, socket.getLocalSocketAddress()); assertEquals(bindAddr.getHostName(), actualAddr.getHostName()); assertTrue(socket.isBound()); @@ -2499,14 +2485,14 @@ public class DatagramChannelTest extends TestCase { */ public void test_bind_socketSyncAfterBind() throws IOException { DatagramChannel dc = DatagramChannel.open(); - assertNull(dc.getLocalAddress()); + assertNull(dc.socket().getLocalSocketAddress()); InetSocketAddress bindAddr = new InetSocketAddress("localhost", 0); - dc.bind(bindAddr); + dc.socket().bind(bindAddr); // Socket creation after bind(). DatagramSocket socket = dc.socket(); - InetSocketAddress actualAddr = (InetSocketAddress) dc.getLocalAddress(); + InetSocketAddress actualAddr = (InetSocketAddress) dc.socket().getLocalSocketAddress(); assertEquals(actualAddr, socket.getLocalSocketAddress()); assertEquals(bindAddr.getHostName(), actualAddr.getHostName()); assertTrue(socket.isBound()); @@ -2521,21 +2507,17 @@ public class DatagramChannelTest extends TestCase { public void test_getLocalSocketAddress_afterClose() throws IOException { DatagramChannel dc = DatagramChannel.open(); - assertNull(dc.getLocalAddress()); + assertNull(dc.socket().getLocalSocketAddress()); InetSocketAddress bindAddr = new InetSocketAddress("localhost", 0); - dc.bind(bindAddr); + dc.socket().bind(bindAddr); - assertNotNull(dc.getLocalAddress()); + assertNotNull(dc.socket().getLocalSocketAddress()); dc.close(); assertFalse(dc.isOpen()); - try { - dc.getLocalAddress(); - fail(); - } catch (ClosedChannelException expected) { - } + dc.socket().getLocalSocketAddress(); } } diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/FileChannelTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/FileChannelTest.java index ccf5a14..990badc 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/FileChannelTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/FileChannelTest.java @@ -786,7 +786,6 @@ public class FileChannelTest extends TestCase { // shared lock, but it works on Windows & Linux. assertTrue(fileLock.isShared()); assertSame(readOnlyFileChannel, fileLock.channel()); - assertSame(readOnlyFileChannel, fileLock.acquiredBy()); assertEquals(POSITION, fileLock.position()); assertEquals(SIZE, fileLock.size()); } @@ -801,7 +800,6 @@ public class FileChannelTest extends TestCase { assertTrue(fileLock.isValid()); assertFalse(fileLock.isShared()); assertSame(writeOnlyFileChannel, fileLock.channel()); - assertSame(writeOnlyFileChannel, fileLock.acquiredBy()); assertEquals(POSITION, fileLock.position()); assertEquals(SIZE, fileLock.size()); } @@ -818,7 +816,6 @@ public class FileChannelTest extends TestCase { assertEquals(POSITION, fileLock.position()); assertEquals(SIZE, fileLock.size()); assertSame(readOnlyFileChannel, fileLock.channel()); - assertSame(readOnlyFileChannel, fileLock.acquiredBy()); } /** @@ -997,7 +994,6 @@ public class FileChannelTest extends TestCase { // shared lock, but it works on Windows & Linux. assertTrue(fileLock.isShared()); assertSame(readOnlyFileChannel, fileLock.channel()); - assertSame(readOnlyFileChannel, fileLock.acquiredBy()); assertEquals(POSITION, fileLock.position()); assertEquals(SIZE, fileLock.size()); } @@ -1012,7 +1008,6 @@ public class FileChannelTest extends TestCase { assertTrue(fileLock.isValid()); assertFalse(fileLock.isShared()); assertSame(writeOnlyFileChannel, fileLock.channel()); - assertSame(writeOnlyFileChannel, fileLock.acquiredBy()); assertEquals(POSITION, fileLock.position()); assertEquals(SIZE, fileLock.size()); } @@ -1029,7 +1024,6 @@ public class FileChannelTest extends TestCase { assertEquals(POSITION, fileLock.position()); assertEquals(SIZE, fileLock.size()); assertSame(readOnlyFileChannel, fileLock.channel()); - assertSame(readOnlyFileChannel, fileLock.acquiredBy()); } /** diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/FileLockTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/FileLockTest.java index c4d372b..7e3b671 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/FileLockTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/FileLockTest.java @@ -75,7 +75,6 @@ public class FileLockTest extends TestCase { public void test_Constructor_Ljava_nio_channels_FileChannelJJZ() { FileLock fileLock1 = new MockFileLock(null, 0, 0, false); assertNull(fileLock1.channel()); - assertNull(fileLock1.acquiredBy()); try { new MockFileLock(readWriteChannel, -1, 0, false); @@ -108,15 +107,6 @@ public class FileLockTest extends TestCase { } /** - * @tests java.nio.channels.FileLock#acquiredBy() - */ - public void test_acquiredBy() { - assertSame(readWriteChannel, mockLock.acquiredBy()); - FileLock lock = new MockFileLock(null, 0, 10, true); - assertNull(lock.acquiredBy()); - } - - /** * @tests java.nio.channels.FileLock#position() */ public void test_position() { diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/ServerSocketChannelTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/ServerSocketChannelTest.java index b417adc..c1d592a 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/ServerSocketChannelTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/ServerSocketChannelTest.java @@ -24,7 +24,6 @@ import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; import java.nio.ByteBuffer; -import java.nio.channels.AlreadyBoundException; import java.nio.channels.AsynchronousCloseException; import java.nio.channels.ClosedChannelException; import java.nio.channels.IllegalBlockingModeException; @@ -115,11 +114,11 @@ public class ServerSocketChannelTest extends TestCase { public void test_bind_null() throws Exception { ServerSocketChannel ssc = ServerSocketChannel.open(); try { - assertNull(ssc.getLocalAddress()); + assertNull(ssc.socket().getLocalSocketAddress()); - ssc.bind(null); + ssc.socket().bind(null); - InetSocketAddress localAddress = (InetSocketAddress) ssc.getLocalAddress(); + InetSocketAddress localAddress = (InetSocketAddress) ssc.socket().getLocalSocketAddress(); assertTrue(localAddress.getAddress().isAnyLocalAddress()); assertTrue(localAddress.getPort() > 0); } finally { @@ -129,12 +128,12 @@ public class ServerSocketChannelTest extends TestCase { public void test_bind_failure() throws Exception { ServerSocketChannel portHog = ServerSocketChannel.open(); - portHog.bind(null); + portHog.socket().bind(null); ServerSocketChannel ssc = ServerSocketChannel.open(); try { // Bind to a local address that is in use - ssc.bind(portHog.getLocalAddress()); + ssc.socket().bind(portHog.socket().getLocalSocketAddress()); fail(); } catch (IOException expected) { } finally { @@ -148,22 +147,9 @@ public class ServerSocketChannelTest extends TestCase { ssc.close(); try { - ssc.bind(null); + ssc.socket().bind(null); fail(); - } catch (ClosedChannelException expected) { - } finally { - ssc.close(); - } - } - - public void test_bind_twice() throws Exception { - ServerSocketChannel ssc = ServerSocketChannel.open(); - ssc.bind(null); - - try { - ssc.bind(null); - fail(); - } catch (AlreadyBoundException expected) { + } catch (IOException expected) { } finally { ssc.close(); } @@ -172,9 +158,9 @@ public class ServerSocketChannelTest extends TestCase { public void test_bind_explicitPort() throws Exception { ServerSocketChannel portPickingChannel = ServerSocketChannel.open(); // Have the OS find a free port. - portPickingChannel.bind(null); + portPickingChannel.socket().bind(null); - InetSocketAddress address = (InetSocketAddress) portPickingChannel.getLocalAddress(); + InetSocketAddress address = (InetSocketAddress) portPickingChannel.socket().getLocalSocketAddress(); assertTrue(address.getPort() > 0); portPickingChannel.close(); @@ -182,9 +168,9 @@ public class ServerSocketChannelTest extends TestCase { // close() and bind(). ServerSocketChannel ssc = ServerSocketChannel.open(); InetSocketAddress bindAddress = new InetSocketAddress("localhost", address.getPort()); - ssc.bind(bindAddress); + ssc.socket().bind(bindAddress); - InetSocketAddress boundAddress = (InetSocketAddress) ssc.getLocalAddress(); + InetSocketAddress boundAddress = (InetSocketAddress) ssc.socket().getLocalSocketAddress(); assertEquals(bindAddress.getHostName(), boundAddress.getHostName()); assertEquals(bindAddress.getPort(), boundAddress.getPort()); @@ -193,16 +179,16 @@ public class ServerSocketChannelTest extends TestCase { public void test_bind_socketSync() throws IOException { ServerSocketChannel ssc = ServerSocketChannel.open(); - assertNull(ssc.getLocalAddress()); + assertNull(ssc.socket().getLocalSocketAddress()); ServerSocket socket = ssc.socket(); assertNull(socket.getLocalSocketAddress()); assertFalse(socket.isBound()); InetSocketAddress bindAddr = new InetSocketAddress("localhost", 0); - ssc.bind(bindAddr); + ssc.socket().bind(bindAddr); - InetSocketAddress actualAddr = (InetSocketAddress) ssc.getLocalAddress(); + InetSocketAddress actualAddr = (InetSocketAddress) ssc.socket().getLocalSocketAddress(); assertEquals(actualAddr, socket.getLocalSocketAddress()); assertEquals(bindAddr.getHostName(), actualAddr.getHostName()); assertTrue(socket.isBound()); @@ -216,14 +202,14 @@ public class ServerSocketChannelTest extends TestCase { public void test_bind_socketSyncAfterBind() throws IOException { ServerSocketChannel ssc = ServerSocketChannel.open(); - assertNull(ssc.getLocalAddress()); + assertNull(ssc.socket().getLocalSocketAddress()); InetSocketAddress bindAddr = new InetSocketAddress("localhost", 0); - ssc.bind(bindAddr); + ssc.socket().bind(bindAddr); // Socket creation after bind(). ServerSocket socket = ssc.socket(); - InetSocketAddress actualAddr = (InetSocketAddress) ssc.getLocalAddress(); + InetSocketAddress actualAddr = (InetSocketAddress) ssc.socket().getLocalSocketAddress(); assertEquals(actualAddr, socket.getLocalSocketAddress()); assertEquals(bindAddr.getHostName(), actualAddr.getHostName()); assertTrue(socket.isBound()); @@ -241,22 +227,18 @@ public class ServerSocketChannelTest extends TestCase { public void test_getLocalSocketAddress_afterClose() throws IOException { ServerSocketChannel ssc = ServerSocketChannel.open(); - assertNull(ssc.getLocalAddress()); + assertNull(ssc.socket().getLocalSocketAddress()); InetSocketAddress bindAddr = new InetSocketAddress("localhost", 0); - ssc.bind(bindAddr); + ssc.socket().bind(bindAddr); - assertNotNull(ssc.getLocalAddress()); + assertNotNull(ssc.socket().getLocalSocketAddress()); ssc.close(); assertFalse(ssc.isOpen()); - try { - ssc.getLocalAddress(); - fail(); - } catch (ClosedChannelException expected) { - } + ssc.socket().getLocalSocketAddress(); } // ------------------------------------------------------------------- @@ -387,7 +369,7 @@ public class ServerSocketChannelTest extends TestCase { public void testAccept_Block_NoConnect() throws IOException { assertTrue(this.serverChannel.isBlocking()); - serverChannel.bind(null); + serverChannel.socket().bind(null); // blocking mode , will block and wait for ever... // so must close the server channel with another thread. new Thread() { @@ -410,7 +392,7 @@ public class ServerSocketChannelTest extends TestCase { } public void testAccept_NonBlock_NoConnect() throws IOException { - this.serverChannel.bind(null); + this.serverChannel.socket().bind(null); this.serverChannel.configureBlocking(false); // non-blocking mode , will immediately return assertNull(this.serverChannel.accept()); @@ -420,13 +402,13 @@ public class ServerSocketChannelTest extends TestCase { * @tests ServerSocketChannel#accept().socket() */ public void test_read_Blocking_RealData() throws IOException { - serverChannel.bind(null); + serverChannel.socket().bind(null); ByteBuffer buf = ByteBuffer.allocate(CAPACITY_NORMAL); for (int i = 0; i < CAPACITY_NORMAL; i++) { buf.put((byte) i); } - clientChannel.connect(serverChannel.getLocalAddress()); + clientChannel.connect(serverChannel.socket().getLocalSocketAddress()); Socket serverSocket = serverChannel.accept().socket(); InputStream in = serverSocket.getInputStream(); buf.flip(); @@ -459,13 +441,13 @@ public class ServerSocketChannelTest extends TestCase { */ public void test_read_NonBlocking_RealData() throws Exception { serverChannel.configureBlocking(false); - serverChannel.bind(null); + serverChannel.socket().bind(null); ByteBuffer buf = ByteBuffer.allocate(CAPACITY_NORMAL); for (int i = 0; i < CAPACITY_NORMAL; i++) { buf.put((byte) i); } buf.flip(); - clientChannel.connect(serverChannel.getLocalAddress()); + clientChannel.connect(serverChannel.socket().getLocalSocketAddress()); Socket serverSocket = serverChannel.accept().socket(); InputStream in = serverSocket.getInputStream(); clientChannel.write(buf); @@ -478,13 +460,13 @@ public class ServerSocketChannelTest extends TestCase { */ public void test_write_Blocking_RealData() throws IOException { assertTrue(serverChannel.isBlocking()); - serverChannel.bind(null); + serverChannel.socket().bind(null); byte[] writeContent = new byte[CAPACITY_NORMAL]; for (int i = 0; i < writeContent.length; i++) { writeContent[i] = (byte) i; } - clientChannel.connect(serverChannel.getLocalAddress()); + clientChannel.connect(serverChannel.socket().getLocalSocketAddress()); Socket socket = serverChannel.accept().socket(); OutputStream out = socket.getOutputStream(); out.write(writeContent); @@ -499,13 +481,13 @@ public class ServerSocketChannelTest extends TestCase { */ public void test_write_NonBlocking_RealData() throws Exception { serverChannel.configureBlocking(false); - serverChannel.bind(null); + serverChannel.socket().bind(null); byte[] writeContent = new byte[CAPACITY_NORMAL]; for (int i = 0; i < CAPACITY_NORMAL; i++) { writeContent[i] = (byte) i; } - clientChannel.connect(serverChannel.getLocalAddress()); + clientChannel.connect(serverChannel.socket().getLocalSocketAddress()); Socket clientSocket = serverChannel.accept().socket(); OutputStream out = clientSocket.getOutputStream(); out.write(writeContent); @@ -519,13 +501,13 @@ public class ServerSocketChannelTest extends TestCase { */ public void test_read_LByteBuffer_Blocking_ReadWriteRealLargeData() throws IOException, InterruptedException { - serverChannel.bind(null); + serverChannel.socket().bind(null); ByteBuffer buf = ByteBuffer.allocate(CAPACITY_64KB); for (int i = 0; i < CAPACITY_64KB; i++) { buf.put((byte) i); } buf.flip(); - clientChannel.connect(serverChannel.getLocalAddress()); + clientChannel.connect(serverChannel.socket().getLocalSocketAddress()); WriteChannelThread writeThread = new WriteChannelThread(clientChannel, buf); writeThread.start(); Socket socket = serverChannel.accept().socket(); @@ -564,13 +546,13 @@ public class ServerSocketChannelTest extends TestCase { public void test_read_LByteBuffer_NonBlocking_ReadWriteRealLargeData() throws Exception { serverChannel.configureBlocking(false); - serverChannel.bind(null); + serverChannel.socket().bind(null); ByteBuffer buf = ByteBuffer.allocate(CAPACITY_64KB); for (int i = 0; i < CAPACITY_64KB; i++) { buf.put((byte) i); } buf.flip(); - clientChannel.connect(serverChannel.getLocalAddress()); + clientChannel.connect(serverChannel.socket().getLocalSocketAddress()); WriteChannelThread writeThread = new WriteChannelThread(clientChannel, buf); writeThread.start(); Socket socket = serverChannel.accept().socket(); @@ -589,12 +571,12 @@ public class ServerSocketChannelTest extends TestCase { public void test_write_LByteBuffer_NonBlocking_ReadWriteRealLargeData() throws Exception { serverChannel.configureBlocking(false); - serverChannel.bind(null); + serverChannel.socket().bind(null); byte[] writeContent = new byte[CAPACITY_64KB]; for (int i = 0; i < writeContent.length; i++) { writeContent[i] = (byte) i; } - clientChannel.connect(serverChannel.getLocalAddress()); + clientChannel.connect(serverChannel.socket().getLocalSocketAddress()); Socket socket = serverChannel.accept().socket(); WriteSocketThread writeThread = new WriteSocketThread(socket, writeContent); writeThread.start(); @@ -632,12 +614,12 @@ public class ServerSocketChannelTest extends TestCase { */ public void test_write_LByteBuffer_Blocking_ReadWriteRealLargeData() throws Exception { - serverChannel.bind(null); + serverChannel.socket().bind(null); byte[] writeContent = new byte[CAPACITY_64KB]; for (int i = 0; i < writeContent.length; i++) { writeContent[i] = (byte) i; } - clientChannel.connect(serverChannel.getLocalAddress()); + clientChannel.connect(serverChannel.socket().getLocalSocketAddress()); Socket socket = serverChannel.accept().socket(); WriteSocketThread writeThread = new WriteSocketThread(socket, writeContent); writeThread.start(); @@ -679,7 +661,7 @@ public class ServerSocketChannelTest extends TestCase { final int SO_TIMEOUT = 10; ServerSocketChannel sc = ServerSocketChannel.open(); try { - sc.bind(null); + sc.socket().bind(null); sc.configureBlocking(false); ServerSocket ss = sc.socket(); ss.setSoTimeout(SO_TIMEOUT); @@ -740,7 +722,7 @@ public class ServerSocketChannelTest extends TestCase { public void test_socket_accept_Nonblocking_Bound() throws IOException { // regression test for Harmony-748 serverChannel.configureBlocking(false); - serverChannel.bind(null); + serverChannel.socket().bind(null); ServerSocket gotSocket = serverChannel.socket(); try { gotSocket.accept(); @@ -761,7 +743,7 @@ public class ServerSocketChannelTest extends TestCase { public void test_socket_accept_Blocking_Bound() throws IOException { // regression test for Harmony-748 serverChannel.configureBlocking(true); - serverChannel.bind(null); + serverChannel.socket().bind(null); serverChannel.close(); try { serverChannel.socket().accept(); @@ -773,8 +755,8 @@ public class ServerSocketChannelTest extends TestCase { * Regression test for HARMONY-4961 */ public void test_socket_getLocalPort() throws IOException { - serverChannel.bind(null); - clientChannel.connect(serverChannel.getLocalAddress()); + serverChannel.socket().bind(null); + clientChannel.connect(serverChannel.socket().getLocalSocketAddress()); SocketChannel myChannel = serverChannel.accept(); int port = myChannel.socket().getLocalPort(); assertEquals(serverChannel.socket().getLocalPort(), port); @@ -788,7 +770,7 @@ public class ServerSocketChannelTest extends TestCase { */ public void test_accept_configureBlocking() throws Exception { InetSocketAddress localAddr = new InetSocketAddress("localhost", 0); - serverChannel.bind(localAddr); + serverChannel.socket().bind(localAddr); // configure the channel non-blocking // when it is accepting in main thread diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/SocketChannelTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/SocketChannelTest.java index 52dff79..51a8cff 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/SocketChannelTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/SocketChannelTest.java @@ -30,7 +30,6 @@ import java.net.SocketAddress; import java.net.SocketException; import java.nio.Buffer; import java.nio.ByteBuffer; -import java.nio.channels.AlreadyBoundException; import java.nio.channels.AlreadyConnectedException; import java.nio.channels.ClosedChannelException; import java.nio.channels.ConnectionPendingException; @@ -155,21 +154,21 @@ public class SocketChannelTest extends TestCase { } public void testBind_Null() throws Exception { - assertNull(channel1.getLocalAddress()); + assertNull(channel1.socket().getLocalSocketAddress()); - channel1.bind(null); + channel1.socket().bind(null); - InetSocketAddress localAddress = (InetSocketAddress) channel1.getLocalAddress(); + InetSocketAddress localAddress = (InetSocketAddress) channel1.socket().getLocalSocketAddress(); assertTrue(localAddress.getAddress().isAnyLocalAddress()); assertTrue(localAddress.getPort() > 0); } public void testBind_Failure() throws Exception { - assertNull(channel1.getLocalAddress()); + assertNull(channel1.socket().getLocalSocketAddress()); try { // Bind to a local address that is in use - channel1.bind(localAddr1); + channel1.socket().bind(localAddr1); fail(); } catch (IOException expected) { } @@ -179,27 +178,17 @@ public class SocketChannelTest extends TestCase { channel1.close(); try { - channel1.bind(null); + channel1.socket().bind(null); fail(); - } catch (ClosedChannelException expected) { - } - } - - public void testBind_Twice() throws Exception { - channel1.bind(null); - - try { - channel1.bind(null); - fail(); - } catch (AlreadyBoundException expected) { + } catch (IOException expected) { } } public void testBind_explicitPort() throws Exception { ServerSocketChannel portPickingChannel = ServerSocketChannel.open(); // Have the OS find a free port. - portPickingChannel.bind(null); - InetSocketAddress address = (InetSocketAddress) portPickingChannel.getLocalAddress(); + portPickingChannel.socket().bind(null); + InetSocketAddress address = (InetSocketAddress) portPickingChannel.socket().getLocalSocketAddress(); assertTrue(address.getPort() > 0); portPickingChannel.close(); @@ -208,31 +197,27 @@ public class SocketChannelTest extends TestCase { InetSocketAddress bindAddress = new InetSocketAddress("localhost", address.getPort()); // Allow the socket to bind to a port we know is already in use. channel1.socket().setReuseAddress(true); - channel1.bind(bindAddress); + channel1.socket().bind(bindAddress); - InetSocketAddress boundAddress = (InetSocketAddress) channel1.getLocalAddress(); + InetSocketAddress boundAddress = (InetSocketAddress) channel1.socket().getLocalSocketAddress(); assertEquals(bindAddress.getHostName(), boundAddress.getHostName()); assertEquals(bindAddress.getPort(), boundAddress.getPort()); } public void test_getLocalSocketAddress_afterClose() throws IOException { SocketChannel sc = SocketChannel.open(); - assertNull(sc.getLocalAddress()); + assertNull(sc.socket().getLocalSocketAddress()); InetSocketAddress bindAddr = new InetSocketAddress("localhost", 0); - sc.bind(bindAddr); + sc.socket().bind(bindAddr); - assertNotNull(sc.getLocalAddress()); + assertNotNull(sc.socket().getLocalSocketAddress()); sc.close(); assertFalse(sc.isOpen()); - try { - sc.getLocalAddress(); - fail(); - } catch (ClosedChannelException expected) { - } + sc.socket().getLocalSocketAddress(); } /* @@ -479,11 +464,10 @@ public class SocketChannelTest extends TestCase { public void testSocket_getLocalAddress() throws Exception { Socket socket = channel1.socket(); - assertNotNull(socket.getLocalAddress()); channel1.connect(localAddr1); - assertNotNull(socket.getLocalAddress()); + assertNotNull(socket.getLocalSocketAddress()); } public void testSocket_getLocalSocketAddress() throws Exception { @@ -1882,7 +1866,7 @@ public class SocketChannelTest extends TestCase { ServerSocket serversocket = theServerChannel.socket(); serversocket.setReuseAddress(true); // Bind the socket - theServerChannel.bind(address); + theServerChannel.socket().bind(address); boolean doneNonBlockingConnect = false; // Loop so that we make sure we're definitely testing finishConnect() @@ -2203,7 +2187,7 @@ public class SocketChannelTest extends TestCase { ByteBuffer buffer = ByteBuffer.allocateDirect(128); ServerSocketChannel server = ServerSocketChannel.open(); - server.bind(new InetSocketAddress(InetAddress.getLocalHost(), 0), 5); + server.socket().bind(new InetSocketAddress(InetAddress.getLocalHost(), 0), 5); Socket client = new Socket(InetAddress.getLocalHost(), server.socket() .getLocalPort()); client.setTcpNoDelay(false); @@ -2821,9 +2805,9 @@ public class SocketChannelTest extends TestCase { */ public void test_writev() throws Exception { ServerSocketChannel ssc = ServerSocketChannel.open(); - ssc.bind(null); + ssc.socket().bind(null); SocketChannel sc = SocketChannel.open(); - sc.connect(ssc.getLocalAddress()); + sc.connect(ssc.socket().getLocalSocketAddress()); SocketChannel sock = ssc.accept(); ByteBuffer[] buf = { ByteBuffer.allocate(10), ByteBuffer.allocateDirect(20) }; @@ -2848,10 +2832,10 @@ public class SocketChannelTest extends TestCase { public void test_writev2() throws Exception { ServerSocketChannel ssc = ServerSocketChannel.open(); ssc.configureBlocking(false); - ssc.bind(null); + ssc.socket().bind(null); SocketChannel sc = SocketChannel.open(); sc.configureBlocking(false); - boolean connected = sc.connect(ssc.getLocalAddress()); + boolean connected = sc.connect(ssc.socket().getLocalSocketAddress()); SocketChannel sock = ssc.accept(); if (!connected) { sc.finishConnect(); @@ -2886,10 +2870,10 @@ public class SocketChannelTest extends TestCase { public void test_write$NonBlockingException() throws Exception { ServerSocketChannel ssc = ServerSocketChannel.open(); ssc.configureBlocking(false); - ssc.bind(null); + ssc.socket().bind(null); SocketChannel sc = SocketChannel.open(); sc.configureBlocking(false); - boolean connected = sc.connect(ssc.getLocalAddress()); + boolean connected = sc.connect(ssc.socket().getLocalSocketAddress()); SocketChannel sock = ssc.accept(); if (!connected) { sc.finishConnect(); @@ -2922,9 +2906,9 @@ public class SocketChannelTest extends TestCase { public void test_write$LByteBuffer2() throws IOException { // Set-up ServerSocketChannel server = ServerSocketChannel.open(); - server.bind(null); + server.socket().bind(null); SocketChannel client = SocketChannel.open(); - client.connect(server.getLocalAddress()); + client.connect(server.socket().getLocalSocketAddress()); SocketChannel worker = server.accept(); // Test overlapping buffers @@ -2954,9 +2938,9 @@ public class SocketChannelTest extends TestCase { public void test_write$LByteBuffer_buffers() throws IOException { // Set-up ServerSocketChannel server = ServerSocketChannel.open(); - server.bind(null); + server.socket().bind(null); SocketChannel client = SocketChannel.open(); - client.connect(server.getLocalAddress()); + client.connect(server.socket().getLocalSocketAddress()); SocketChannel worker = server.accept(); // A variety of buffer types to write @@ -2996,9 +2980,9 @@ public class SocketChannelTest extends TestCase { public void test_write$LByteBuffer_writes() throws IOException { // Set-up ServerSocketChannel server = ServerSocketChannel.open(); - server.bind(null); + server.socket().bind(null); SocketChannel client = SocketChannel.open(); - client.connect(server.getLocalAddress()); + client.connect(server.socket().getLocalSocketAddress()); SocketChannel worker = server.accept(); // Data to write @@ -3038,10 +3022,10 @@ public class SocketChannelTest extends TestCase { public void test_write$LByteBuffer_invalid() throws IOException { // Set-up ServerSocketChannel server = ServerSocketChannel.open(); - server.bind(null); + server.socket().bind(null); SocketChannel client = SocketChannel.open(); - client.connect(server.getLocalAddress()); + client.connect(server.socket().getLocalSocketAddress()); SocketChannel worker = server.accept(); @@ -3141,9 +3125,9 @@ public class SocketChannelTest extends TestCase { throws Exception { // regression 1 for HARMONY-549 ServerSocketChannel ssc = ServerSocketChannel.open(); - ssc.bind(null); + ssc.socket().bind(null); SocketChannel sc = SocketChannel.open(); - sc.connect(ssc.getLocalAddress()); + sc.connect(ssc.socket().getLocalSocketAddress()); ssc.accept().close(); ByteBuffer[] buf = { ByteBuffer.allocate(10) }; assertEquals(-1, sc.read(buf, 0, 1)); @@ -3157,9 +3141,9 @@ public class SocketChannelTest extends TestCase { public void test_socketChannel_write_ByteBufferII() throws Exception { // regression 2 for HARMONY-549 ServerSocketChannel ssc = ServerSocketChannel.open(); - ssc.bind(null); + ssc.socket().bind(null); SocketChannel sc = SocketChannel.open(); - sc.connect(ssc.getLocalAddress()); + sc.connect(ssc.socket().getLocalSocketAddress()); SocketChannel sock = ssc.accept(); ByteBuffer[] buf = { ByteBuffer.allocate(10), null }; try { @@ -3179,9 +3163,9 @@ public class SocketChannelTest extends TestCase { public void test_socketChannel_read_ByteBufferII_bufNULL() throws Exception { // regression 3 for HARMONY-549 ServerSocketChannel ssc = ServerSocketChannel.open(); - ssc.bind(null); + ssc.socket().bind(null); SocketChannel sc = SocketChannel.open(); - sc.connect(ssc.getLocalAddress()); + sc.connect(ssc.socket().getLocalSocketAddress()); ssc.accept(); ByteBuffer[] buf = new ByteBuffer[2]; buf[0] = ByteBuffer.allocate(1); @@ -3201,9 +3185,9 @@ public class SocketChannelTest extends TestCase { public void test_socketChannel_write_close() throws Exception { // regression 4 for HARMONY-549 ServerSocketChannel ssc = ServerSocketChannel.open(); - ssc.bind(null); + ssc.socket().bind(null); SocketChannel sc = SocketChannel.open(); - sc.connect(ssc.getLocalAddress()); + sc.connect(ssc.socket().getLocalSocketAddress()); SocketChannel sock = ssc.accept(); ByteBuffer buf = null; ssc.close(); @@ -3226,9 +3210,9 @@ public class SocketChannelTest extends TestCase { ByteBuffer readBuf = ByteBuffer.allocate(11); ByteBuffer buf = ByteBuffer.wrap(testStr.getBytes()); ServerSocketChannel ssc = ServerSocketChannel.open(); - ssc.bind(null); + ssc.socket().bind(null); SocketChannel sc = SocketChannel.open(); - sc.connect(ssc.getLocalAddress()); + sc.connect(ssc.socket().getLocalSocketAddress()); buf.position(2); ssc.accept().write(buf); assertEquals(9, sc.read(readBuf)); |