summaryrefslogtreecommitdiffstats
path: root/luni/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'luni/src/test')
-rw-r--r--luni/src/test/java/java/nio/channels/AllTests.java30
-rw-r--r--luni/src/test/java/java/nio/channels/DatagramChannelTest.java44
-rw-r--r--luni/src/test/java/java/nio/channels/FileChannelTest.java50
-rw-r--r--luni/src/test/java/java/nio/channels/SocketChannelTest.java44
-rw-r--r--luni/src/test/java/tests/AllTests.java1
5 files changed, 169 insertions, 0 deletions
diff --git a/luni/src/test/java/java/nio/channels/AllTests.java b/luni/src/test/java/java/nio/channels/AllTests.java
new file mode 100644
index 0000000..0b89f37
--- /dev/null
+++ b/luni/src/test/java/java/nio/channels/AllTests.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed 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 java.nio.channels;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+ public static final Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTestSuite(java.nio.channels.DatagramChannelTest.class);
+ suite.addTestSuite(java.nio.channels.FileChannelTest.class);
+ suite.addTestSuite(java.nio.channels.SocketChannelTest.class);
+ return suite;
+ }
+}
diff --git a/luni/src/test/java/java/nio/channels/DatagramChannelTest.java b/luni/src/test/java/java/nio/channels/DatagramChannelTest.java
new file mode 100644
index 0000000..c3a537e
--- /dev/null
+++ b/luni/src/test/java/java/nio/channels/DatagramChannelTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed 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 java.nio.channels;
+
+import java.net.DatagramSocket;
+import java.nio.ByteBuffer;
+
+public class DatagramChannelTest extends junit.framework.TestCase {
+ public void test_read_intoReadOnlyByteArrays() throws Exception {
+ ByteBuffer readOnly = ByteBuffer.allocate(1).asReadOnlyBuffer();
+ DatagramSocket ds = new DatagramSocket(0);
+ DatagramChannel dc = DatagramChannel.open();
+ dc.connect(ds.getLocalSocketAddress());
+ try {
+ dc.read(readOnly);
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+ try {
+ dc.read(new ByteBuffer[] { readOnly });
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+ try {
+ dc.read(new ByteBuffer[] { readOnly }, 0, 1);
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+}
diff --git a/luni/src/test/java/java/nio/channels/FileChannelTest.java b/luni/src/test/java/java/nio/channels/FileChannelTest.java
new file mode 100644
index 0000000..92b3f25
--- /dev/null
+++ b/luni/src/test/java/java/nio/channels/FileChannelTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed 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 java.nio.channels;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.nio.ByteBuffer;
+
+public class FileChannelTest extends junit.framework.TestCase {
+ public void test_read_intoReadOnlyByteArrays() throws Exception {
+ ByteBuffer readOnly = ByteBuffer.allocate(1).asReadOnlyBuffer();
+ File tmp = File.createTempFile("empty", "tmp");
+ tmp.deleteOnExit();
+ FileChannel fc = new FileInputStream(tmp).getChannel();
+ try {
+ fc.read(readOnly);
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+ try {
+ fc.read(new ByteBuffer[] { readOnly });
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+ try {
+ fc.read(new ByteBuffer[] { readOnly }, 0, 1);
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+ try {
+ fc.read(readOnly, 0L);
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+}
diff --git a/luni/src/test/java/java/nio/channels/SocketChannelTest.java b/luni/src/test/java/java/nio/channels/SocketChannelTest.java
new file mode 100644
index 0000000..71b4c81
--- /dev/null
+++ b/luni/src/test/java/java/nio/channels/SocketChannelTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed 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 java.nio.channels;
+
+import java.net.ServerSocket;
+import java.nio.ByteBuffer;
+
+public class SocketChannelTest extends junit.framework.TestCase {
+ public void test_read_intoReadOnlyByteArrays() throws Exception {
+ ByteBuffer readOnly = ByteBuffer.allocate(1).asReadOnlyBuffer();
+ ServerSocket ss = new ServerSocket(0);
+ ss.setReuseAddress(true);
+ SocketChannel sc = SocketChannel.open(ss.getLocalSocketAddress());
+ try {
+ sc.read(readOnly);
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+ try {
+ sc.read(new ByteBuffer[] { readOnly });
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+ try {
+ sc.read(new ByteBuffer[] { readOnly }, 0, 1);
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+}
diff --git a/luni/src/test/java/tests/AllTests.java b/luni/src/test/java/tests/AllTests.java
index 4b3a484..035a2f5 100644
--- a/luni/src/test/java/tests/AllTests.java
+++ b/luni/src/test/java/tests/AllTests.java
@@ -61,6 +61,7 @@ public class AllTests
suite.addTest(java.lang.AllTests.suite());
suite.addTest(java.lang.reflect.AllTests.suite());
suite.addTest(java.net.AllTests.suite());
+ suite.addTest(java.nio.channels.AllTests.suite());
suite.addTest(java.nio.charset.AllTests.suite());
suite.addTest(java.text.AllTests.suite());
suite.addTest(java.util.AllTests.suite());