You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by re...@apache.org on 2009/04/20 11:41:43 UTC
svn commit: r766631 - in
/harmony/enhanced/classlib/trunk/modules/luni/src/test/api:
common/org/apache/harmony/luni/tests/java/net/
unix/org/apache/harmony/luni/tests/java/io/
windows/org/apache/harmony/luni/tests/java/io/
Author: regisxu
Date: Mon Apr 20 09:41:42 2009
New Revision: 766631
URL: http://svn.apache.org/viewvc?rev=766631&view=rev
Log:
Move platform specific tests in SocketTest.test_getInputStream() to platform test folders
Added:
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/io/UnixSocketTest.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/io/WinSocketTest.java
Modified:
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java?rev=766631&r1=766630&r2=766631&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java Mon Apr 20 09:41:42 2009
@@ -819,83 +819,6 @@
is.close();
client.close();
server.close();
-
- // Simple read/write test over the IO streams
- final ServerSocket pingServer = new ServerSocket(0);
- Runnable runnable = new Runnable() {
- public void run() {
- try {
- Socket worker = pingServer.accept();
- pingServer.close();
- InputStream in = worker.getInputStream();
- in.read();
- OutputStream out = worker.getOutputStream();
- out.write(new byte[42]);
- worker.close();
- } catch (IOException e) {
- fail(e.getMessage());
- }
- }
- };
- Thread thread = new Thread(runnable, "Socket.getInputStream");
- thread.start();
-
- Socket pingClient = new Socket(InetAddress.getLocalHost(), pingServer
- .getLocalPort());
-
- // Busy wait until the client is connected.
- int c = 0;
- while (!pingClient.isConnected()) {
- try {
- Thread.sleep(200);
- } catch (InterruptedException e) {
- }
- if (++c > 4) {
- fail("thread is not alive");
- }
- }
-
- // Write some data to the server to provoke it
- OutputStream out = pingClient.getOutputStream();
- out.write(new byte[256]);
-
- InputStream in = pingClient.getInputStream();
- in.read(new byte[42]);
- if (isUnix()) {
- try {
- in.read();
- fail("Should throw SocketException");
- } catch (SocketException e) {
- // expected
- }
- } else {
- // Check EOF
- assertEquals(-1, in.read());
- }
-
- in.close();
-
- if (isUnix()) {
- try {
- in.read();
- fail("Should throw SocketException");
- } catch (SocketException e) {
- // expected
- }
- try {
- in.read(new byte[5]);
- fail("Should throw SocketException");
- } catch (SocketException e) {
- // expected
- }
- } else {
- // No exception when reading a closed stream
- assertEquals(-1, in.read());
- assertEquals(-1, in.read(new byte[5]));
- }
-
- pingClient.close();
- pingServer.close();
}
private boolean isUnix() {
Added: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/io/UnixSocketTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/io/UnixSocketTest.java?rev=766631&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/io/UnixSocketTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/io/UnixSocketTest.java Mon Apr 20 09:41:42 2009
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.luni.tests.java.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketException;
+
+import junit.framework.TestCase;
+
+public class UnixSocketTest extends TestCase {
+
+ /**
+ * @tests java.net.Socket#getInputStream()
+ */
+ public void test_getInputStream() throws IOException {
+ // Simple read/write test over the IO streams
+ final ServerSocket pingServer = new ServerSocket(0);
+ Runnable runnable = new Runnable() {
+ public void run() {
+ try {
+ Socket worker = pingServer.accept();
+ pingServer.close();
+ InputStream in = worker.getInputStream();
+ in.read();
+ OutputStream out = worker.getOutputStream();
+ out.write(new byte[42]);
+ worker.close();
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ }
+ };
+ Thread thread = new Thread(runnable, "UnixSocket.getInputStream");
+ thread.start();
+
+ Socket pingClient = new Socket(InetAddress.getLocalHost(), pingServer
+ .getLocalPort());
+
+ // Busy wait until the client is connected.
+ int c = 0;
+ while (!pingClient.isConnected()) {
+ try {
+ Thread.sleep(200);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ if (++c > 4) {
+ fail("thread is not alive");
+ }
+ }
+
+ // Write some data to the server to provoke it
+ OutputStream out = pingClient.getOutputStream();
+ out.write(new byte[256]);
+
+ InputStream in = pingClient.getInputStream();
+ in.read(new byte[42]);
+ try {
+ in.read();
+ fail("Should throw SocketException");
+ } catch (SocketException e) {
+ // expected
+ }
+ in.close();
+
+ try {
+ in.read();
+ fail("Should throw SocketException");
+ } catch (SocketException e) {
+ // expected
+ }
+ try {
+ in.read(new byte[5]);
+ fail("Should throw SocketException");
+ } catch (SocketException e) {
+ // expected
+ }
+
+ pingClient.close();
+ pingServer.close();
+ }
+
+}
Added: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/io/WinSocketTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/io/WinSocketTest.java?rev=766631&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/io/WinSocketTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/io/WinSocketTest.java Mon Apr 20 09:41:42 2009
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.luni.tests.java.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+import junit.framework.TestCase;
+
+public class WinSocketTest extends TestCase {
+
+ /**
+ * @tests java.net.Socket#getInputStream()
+ */
+ public void test_getInputStream() throws IOException {
+ // Simple read/write test over the IO streams
+ final ServerSocket pingServer = new ServerSocket(0);
+ Runnable runnable = new Runnable() {
+ public void run() {
+ try {
+ Socket worker = pingServer.accept();
+ pingServer.close();
+ InputStream in = worker.getInputStream();
+ in.read();
+ OutputStream out = worker.getOutputStream();
+ out.write(new byte[42]);
+ worker.close();
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ }
+ };
+ Thread thread = new Thread(runnable, "WinSocket.getInputStream");
+ thread.start();
+
+ Socket pingClient = new Socket(InetAddress.getLocalHost(), pingServer
+ .getLocalPort());
+
+ // Busy wait until the client is connected.
+ int c = 0;
+ while (!pingClient.isConnected()) {
+ try {
+ Thread.sleep(200);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ if (++c > 4) {
+ fail("thread is not alive");
+ }
+ }
+
+ // Write some data to the server to provoke it
+ OutputStream out = pingClient.getOutputStream();
+ out.write(new byte[256]);
+
+ InputStream in = pingClient.getInputStream();
+ in.read(new byte[42]);
+
+ // Check EOF
+ assertEquals(-1, in.read());
+
+ in.close();
+
+ // No exception when reading a closed stream
+ assertEquals(-1, in.read());
+ assertEquals(-1, in.read(new byte[5]));
+
+ pingClient.close();
+ pingServer.close();
+ }
+}