harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghar...@apache.org
Subject svn commit: r413627 - in /incubator/harmony/enhanced/classlib/trunk/modules/nio/src: main/java/org/apache/harmony/nio/internal/ test/java/org/apache/harmony/tests/java/nio/channels/
Date Mon, 12 Jun 2006 10:31:48 GMT
Author: gharley
Date: Mon Jun 12 03:31:47 2006
New Revision: 413627

URL: http://svn.apache.org/viewvc?rev=413627&view=rev
Log:
HARMONY 41 : java.nio.channels.spi and java.nio.channels.Channels, Pipe, Selector have not
been implemented (partie trois)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/PipeImpl.java
  (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/PipeTest.java
  (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SinkChannelTest.java
  (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SourceChannelTest.java
  (with props)
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorProviderImpl.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/AllTests.java

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/PipeImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/PipeImpl.java?rev=413627&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/PipeImpl.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/PipeImpl.java
Mon Jun 12 03:31:47 2006
@@ -0,0 +1,193 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * 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 org.apache.harmony.nio.internal;
+
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.Pipe;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.spi.SelectorProvider;
+
+import org.apache.harmony.luni.platform.FileDescriptorHandler;
+
+/*
+ * default implemetation of Pipe
+ * 
+ */
+
+final class PipeImpl extends Pipe {
+
+    private SinkChannelImpl sink;
+
+    private SourceChannelImpl source;
+
+    private int serverPort;
+
+    public PipeImpl() throws IOException {
+        super();
+        try {
+            sink = new SinkChannelImpl(SelectorProvider.provider());
+            source = new SourceChannelImpl(SelectorProvider.provider());
+            sink.finishConnect();
+            source.accept();
+            source.closeServer();
+        } catch(IOException ioe){
+            reset();
+            throw ioe;
+        } catch(RuntimeException e){
+            reset();
+            throw e;
+        }
+    }
+    
+    private void reset(){
+        if(sink != null){
+            try {
+                sink.close();
+            } catch (Exception e) {
+            }
+        }
+        if(source != null){
+            try {
+                source.closeServer();
+            } catch (Exception e) {
+            }
+            try {
+                source.close();
+            } catch (Exception e) {
+            }
+        }
+    }
+
+    /*
+     * @see java.nio.channels.Pipe#sink()
+     */
+    public SinkChannel sink() {
+        return sink;
+    }
+
+    /*
+     * @see java.nio.channels.Pipe#source()
+     */
+    public SourceChannel source() {
+        return source;
+    }
+
+    /*
+     * default implemetation of SourceChannel
+     */
+    private class SourceChannelImpl extends Pipe.SourceChannel implements
+            FileDescriptorHandler {
+
+        private SocketChannelImpl sourceSocket;
+
+        private ServerSocketChannel sourceServer;
+
+        /*
+         * constructor
+         */
+        protected SourceChannelImpl(SelectorProvider provider)
+                throws IOException {
+            super(provider);
+            sourceServer = provider.openServerSocketChannel();
+            sourceServer.socket().bind(
+                    new InetSocketAddress(InetAddress.getLocalHost(), 0));
+            serverPort = sourceServer.socket().getLocalPort();
+        }
+
+        void closeServer() throws IOException {
+            sourceServer.close();
+        }
+
+        void accept() throws IOException {
+            sourceSocket = (SocketChannelImpl) sourceServer.accept();
+        }
+
+        protected void implCloseSelectableChannel() throws IOException {
+            sourceSocket.close();
+        }
+
+        protected void implConfigureBlocking(boolean blockingMode)
+                throws IOException {
+            sourceSocket.configureBlocking(blockingMode);
+        }
+
+        public int read(ByteBuffer buffer) throws IOException {
+            return sourceSocket.read(buffer);
+        }
+
+        public long read(ByteBuffer[] buffers) throws IOException {
+            return read(buffers, 0, buffers.length);
+        }
+
+        public long read(ByteBuffer[] buffers, int offset, int length)
+                throws IOException {
+            return sourceSocket.read(buffers, offset, length);
+        }
+
+        public FileDescriptor getFD() {
+            return sourceSocket.getFD();
+        }
+    }
+
+    /*
+     * default implemetation of SinkChannel
+     */
+    private class SinkChannelImpl extends Pipe.SinkChannel implements
+            FileDescriptorHandler {
+
+        private SocketChannelImpl sinkSocket;
+
+        protected SinkChannelImpl(SelectorProvider provider) throws IOException {
+            super(provider);
+            sinkSocket = (SocketChannelImpl) provider.openSocketChannel();
+        }
+
+        public boolean finishConnect() throws IOException {
+            return sinkSocket.connect(new InetSocketAddress(InetAddress
+                    .getLocalHost(), serverPort));
+        }
+
+        protected void implCloseSelectableChannel() throws IOException {
+            sinkSocket.close();
+        }
+
+        protected void implConfigureBlocking(boolean blockingMode)
+                throws IOException {
+            sinkSocket.configureBlocking(blockingMode);
+        }
+
+        public int write(ByteBuffer buffer) throws IOException {
+            return sinkSocket.write(buffer);
+        }
+
+        public long write(ByteBuffer[] buffers) throws IOException {
+            return write(buffers, 0, buffers.length);
+        }
+
+        public long write(ByteBuffer[] buffers, int offset, int length)
+                throws IOException {
+            return sinkSocket.write(buffers, offset, length);
+        }
+
+        public FileDescriptor getFD() {
+            return sinkSocket.getFD();
+        }
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/PipeImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorProviderImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorProviderImpl.java?rev=413627&r1=413626&r2=413627&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorProviderImpl.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/org/apache/harmony/nio/internal/SelectorProviderImpl.java
Mon Jun 12 03:31:47 2006
@@ -49,9 +49,7 @@
 	 * @see java.nio.channels.spi.SelectorProvider#openPipe()
 	 */
 	public Pipe openPipe() throws IOException {
-//	    return new PipeImpl();
-		//FIXME: waiting for JIRA-41
-		return null;
+	    return new PipeImpl();
 	}
 
 	/*

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/AllTests.java?rev=413627&r1=413626&r2=413627&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/AllTests.java
Mon Jun 12 03:31:47 2006
@@ -20,18 +20,21 @@
 
 public class AllTests {
 
-	public static Test suite() {
-		TestSuite suite = new TestSuite(
-				"Test for org.apache.harmony.tests.java.nio.channels");
-		//$JUnit-BEGIN$
-		suite.addTestSuite(ServerSocketChannelTest.class);
-		suite.addTestSuite(SocketChannelTest.class);
-		suite.addTestSuite(FileChannelTest.class);
-		suite.addTestSuite(FileChannelLockingTest.class);
-		suite.addTestSuite(DatagramChannelTest.class);
+    public static Test suite() {
+        TestSuite suite = new TestSuite(
+                "Test for org.apache.harmony.tests.java.nio.channels");
+        //$JUnit-BEGIN$
+        suite.addTestSuite(FileChannelLockingTest.class);
+        suite.addTestSuite(FileChannelTest.class);
+        suite.addTestSuite(SinkChannelTest.class);
+        suite.addTestSuite(DatagramChannelTest.class);
+        suite.addTestSuite(PipeTest.class);
         suite.addTestSuite(ChannelsTest.class);
-		//$JUnit-END$
-		return suite;
-	}
+        suite.addTestSuite(ServerSocketChannelTest.class);
+        suite.addTestSuite(SocketChannelTest.class);
+        suite.addTestSuite(SourceChannelTest.class);
+        //$JUnit-END$
+        return suite;
+    }
 
 }

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/PipeTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/PipeTest.java?rev=413627&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/PipeTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/PipeTest.java
Mon Jun 12 03:31:47 2006
@@ -0,0 +1,56 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * 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 org.apache.harmony.tests.java.nio.channels;
+
+import java.io.IOException;
+import java.nio.channels.Pipe;
+import java.nio.channels.Pipe.SinkChannel;
+import java.nio.channels.Pipe.SourceChannel;
+
+import junit.framework.TestCase;
+
+/*
+ * Tests for Pipe and its default implementation
+ */
+public class PipeTest extends TestCase {
+	
+	/**
+	 * @tests java.nio.channels.Pipe#open()
+	 */
+	public void test_open() throws IOException{
+		Pipe pipe = Pipe.open();
+		assertNotNull(pipe);
+	}
+	
+	/**
+	 * @tests java.nio.channels.Pipe#sink()
+	 */
+	public void test_sink() throws IOException {
+		Pipe pipe = Pipe.open();
+		SinkChannel sink = pipe.sink();
+		assertTrue(sink.isBlocking());
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe#source()
+	 */
+	public void test_source() throws IOException {
+		Pipe pipe = Pipe.open();
+		SourceChannel source = pipe.source();
+		assertTrue(source.isBlocking());
+	}
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/PipeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SinkChannelTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SinkChannelTest.java?rev=413627&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SinkChannelTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SinkChannelTest.java
Mon Jun 12 03:31:47 2006
@@ -0,0 +1,528 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * 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 org.apache.harmony.tests.java.nio.channels;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.Pipe;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.SocketChannel;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for Pipe.SinkChannel class
+ */
+public class SinkChannelTest extends TestCase {
+
+	private static final int BUFFER_SIZE = 5;
+
+	private static final String ISO8859_1 = "ISO8859-1";
+
+	private Pipe pipe;
+
+	private Pipe.SinkChannel sink;
+
+	private Pipe.SourceChannel source;
+
+	private ByteBuffer buffer;
+
+	private ByteBuffer positionedBuffer;
+
+	protected void setUp() throws Exception {
+		super.setUp();
+		pipe = Pipe.open();
+		sink = pipe.sink();
+		source = pipe.source();
+		buffer = ByteBuffer.wrap("bytes".getBytes(ISO8859_1));
+		positionedBuffer = ByteBuffer.wrap("12345bytes".getBytes(ISO8859_1));
+		positionedBuffer.position(BUFFER_SIZE);
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SinkChannel#validOps()
+	 */
+	public void test_validOps() {
+		assertEquals(SelectionKey.OP_WRITE, sink.validOps());
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer)
+	 */
+	public void test_write_LByteBuffer() throws IOException {
+		ByteBuffer[] bufArray = { buffer, positionedBuffer };
+		boolean[] sinkBlockingMode = { true, true, false, false };
+		boolean[] sourceBlockingMode = { true, false, true, false };
+		int oldPosition;
+		int currentPosition;
+		for (int i = 0; i < sinkBlockingMode.length; ++i) {
+			sink.configureBlocking(sinkBlockingMode[i]);
+			source.configureBlocking(sourceBlockingMode[i]);
+			// if sink and source both are blocking mode, source only needs read
+			// once to get what sink write.
+			boolean isBlocking = sinkBlockingMode[i] && sourceBlockingMode[i];
+			for (ByteBuffer buf : bufArray) {
+				buf.mark();
+				oldPosition = buf.position();
+				sink.write(buf);
+				ByteBuffer readBuf = ByteBuffer.allocate(BUFFER_SIZE);
+				int totalCount = 0;
+				do {
+					int count = source.read(readBuf);
+					if (count > 0) {
+						totalCount += count;
+					}
+				} while (totalCount != BUFFER_SIZE && !isBlocking);
+				currentPosition = buf.position();
+				assertEquals(BUFFER_SIZE, currentPosition - oldPosition);
+				assertEquals("bytes", new String(readBuf.array(), ISO8859_1));
+				buf.reset();
+			}
+		}
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer)
+	 */
+	public void test_write_LByteBuffer_mutliThread() throws IOException,
+	        InterruptedException {
+		final int THREAD_NUM = 20;
+		Thread[] thread = new Thread[THREAD_NUM];
+		for (int i = 0; i < THREAD_NUM; i++) {
+			thread[i] = new Thread() {
+				public void run() {
+					try {
+						sink
+						        .write(ByteBuffer.wrap("bytes"
+						                .getBytes(ISO8859_1)));
+					} catch (IOException e) {
+						// ignore
+					}
+				}
+			};
+		}
+		for (int i = 0; i < THREAD_NUM; i++) {
+			thread[i].start();
+		}
+		for (int i = 0; i < THREAD_NUM; i++) {
+			thread[i].join();
+		}
+		ByteBuffer readBuf = ByteBuffer.allocate(THREAD_NUM * BUFFER_SIZE);
+		source.read(readBuf);
+		StringBuffer buf = new StringBuffer();
+		for (int i = 0; i < THREAD_NUM; i++) {
+			buf.append("bytes");
+		}
+		String readString = buf.toString();
+		assertEquals(readString, new String(readBuf.array(), ISO8859_1));
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer)
+	 */
+	public void test_write_LByteBuffer_Exception() throws IOException {
+		// write null ByteBuffer
+		ByteBuffer nullBuf = null;
+		try {
+			sink.write(nullBuf);
+			fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer)
+	 */
+	public void test_write_LByteBuffer_SourceClosed() throws IOException {
+		source.close();
+		int written = sink.write(buffer);
+		assertEquals(BUFFER_SIZE, written);
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer)
+	 */
+	public void test_write_LByteBuffer_SinkClosed() throws IOException {
+		sink.close();
+		try {
+			sink.write(buffer);
+			fail("should throw ClosedChannelException");
+		} catch (ClosedChannelException e) {
+			// expected
+		}
+
+		// write null ByteBuffer
+		ByteBuffer nullBuf = null;
+		try {
+			sink.write(nullBuf);
+			fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer[])
+	 */
+	public void test_write_$LByteBuffer() throws IOException {
+		ByteBuffer[] bufArray = { buffer, positionedBuffer };
+		boolean[] sinkBlockingMode = { true, true, false, false };
+		boolean[] sourceBlockingMode = { true, false, true, false };
+		for (int i = 0; i < sinkBlockingMode.length; ++i) {
+			sink.configureBlocking(sinkBlockingMode[i]);
+			source.configureBlocking(sourceBlockingMode[i]);
+			buffer.position(0);
+			positionedBuffer.position(BUFFER_SIZE);
+			sink.write(bufArray);
+			// if sink and source both are blocking mode, source only needs read
+			// once to get what sink write.
+			boolean isBlocking = sinkBlockingMode[i] && sourceBlockingMode[i];
+			for (int j = 0; j < bufArray.length; ++j) {
+				ByteBuffer readBuf = ByteBuffer.allocate(BUFFER_SIZE);
+				int totalCount = 0;
+				do {
+					int count = source.read(readBuf);
+					if (count < 0) {
+						break;
+					}
+					totalCount += count;
+				} while (totalCount != BUFFER_SIZE && !isBlocking);
+				assertEquals("bytes", new String(readBuf.array(), ISO8859_1));
+			}
+			assertEquals(BUFFER_SIZE, buffer.position());
+			assertEquals(10, positionedBuffer.position());
+		}
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer[])
+	 */
+	public void test_write_$LByteBuffer_Exception() throws IOException {
+		// write null ByteBuffer[]
+		ByteBuffer[] nullBufArrayRef = null;
+		try {
+			sink.write(nullBufArrayRef);
+			fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+
+		// write ByteBuffer[] contains null element
+		ByteBuffer nullBuf = null;
+		ByteBuffer[] nullBufArray = { buffer, nullBuf };
+		try {
+			sink.write(nullBufArray);
+			fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer[])
+	 */
+	public void test_write_$LByteBuffer_SourceClosed() throws IOException {
+		ByteBuffer[] bufArray = { buffer };
+		source.close();
+		long written = sink.write(bufArray);
+		assertEquals(BUFFER_SIZE, written);
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer[])
+	 */
+	public void test_write_$LByteBuffer_SinkClosed() throws IOException {
+		ByteBuffer[] bufArray = { buffer };
+		sink.close();
+		try {
+			sink.write(bufArray);
+			fail("should throw ClosedChannelException");
+		} catch (ClosedChannelException e) {
+			// expected
+		}
+
+		ByteBuffer[] nullBufArrayRef = null;
+		try {
+			sink.write(nullBufArrayRef);
+			fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+
+		ByteBuffer nullBuf = null;
+		ByteBuffer[] nullBufArray = { nullBuf };
+		// write ByteBuffer[] contains null element
+		try {
+			sink.write(nullBufArray);
+			fail("should throw ClosedChannelException");
+		} catch (ClosedChannelException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer[], int, int)
+	 */
+	public void test_write_$LByteBufferII() throws IOException {
+		ByteBuffer[] bufArray = { buffer, positionedBuffer };
+		boolean[] sinkBlockingMode = { true, true, false, false };
+		boolean[] sourceBlockingMode = { true, false, true, false };
+		for (int i = 0; i < sinkBlockingMode.length; ++i) {
+			sink.configureBlocking(sinkBlockingMode[i]);
+			source.configureBlocking(sourceBlockingMode[i]);
+			positionedBuffer.position(BUFFER_SIZE);
+			sink.write(bufArray, 1, 1);
+			// if sink and source both are blocking mode, source only needs read
+			// once to get what sink write.
+			boolean isBlocking = sinkBlockingMode[i] && sourceBlockingMode[i];
+			ByteBuffer readBuf = ByteBuffer.allocate(BUFFER_SIZE);
+			int totalCount = 0;
+			do {
+				int count = source.read(readBuf);
+				if (count < 0) {
+					break;
+				}
+				totalCount += count;
+			} while (totalCount != BUFFER_SIZE && !isBlocking);
+			assertEquals("bytes", new String(readBuf.array(), ISO8859_1));
+			assertEquals(10, positionedBuffer.position());
+		}
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer[], int, int)
+	 */
+	public void test_write_$LByteBufferII_Exception() throws IOException {
+		// write null ByteBuffer[]
+		ByteBuffer[] nullBufArrayRef = null;
+		try {
+			sink.write(nullBufArrayRef, 0, 1);
+			fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+
+		try {
+			sink.write(nullBufArrayRef, 0, -1);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		// write ByteBuffer[] contains null element
+		ByteBuffer nullBuf = null;
+		ByteBuffer[] nullBufArray = { nullBuf };
+		try {
+			sink.write(nullBufArray, 0, 1);
+			fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+
+		try {
+			sink.write(nullBufArray, 0, -1);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		ByteBuffer[] bufArray = { buffer, nullBuf };
+		try {
+			sink.write(bufArray, 0, -1);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		try {
+			sink.write(bufArray, -1, 0);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		try {
+			sink.write(bufArray, -1, 1);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		try {
+			sink.write(bufArray, 0, 3);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		try {
+			sink.write(bufArray, 0, 2);
+			fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer[], int, int)
+	 */
+	public void test_write_$LByteBufferII_SourceClosed() throws IOException {
+		ByteBuffer[] bufArray = { buffer };
+		source.close();
+		long written = sink.write(bufArray, 0, 1);
+		assertEquals(BUFFER_SIZE, written);
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer[], int, int)
+	 */
+	public void test_write_$LByteBufferII_SinkClosed() throws IOException {
+		ByteBuffer[] bufArray = { buffer };
+		sink.close();
+		try {
+			sink.write(bufArray, 0, 1);
+			fail("should throw ClosedChannelException");
+		} catch (ClosedChannelException e) {
+			// expected
+		}
+
+		// write null ByteBuffer[]
+		ByteBuffer[] nullBufArrayRef = null;
+		try {
+			sink.write(nullBufArrayRef, 0, 1);
+			fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+		// illegal array index
+		try {
+			sink.write(nullBufArrayRef, 0, -1);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		// write ByteBuffer[] contains null element
+		ByteBuffer nullBuf = null;
+		ByteBuffer[] nullBufArray = { nullBuf };
+		try {
+			sink.write(nullBufArray, 0, 1);
+			fail("should throw ClosedChannelException");
+		} catch (ClosedChannelException e) {
+			// expected
+		}
+		// illegal array index
+		try {
+			sink.write(nullBufArray, 0, -1);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		ByteBuffer[] bufArray2 = { buffer, nullBuf };
+		// illegal array index
+		try {
+			sink.write(bufArray2, 0, -1);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		try {
+			sink.write(bufArray2, -1, 0);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		try {
+			sink.write(bufArray2, -1, 1);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		try {
+			sink.write(bufArray2, 0, 3);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		try {
+			sink.write(bufArray2, 0, 2);
+			fail("should throw ClosedChannelException");
+		} catch (ClosedChannelException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SinkChannel#close()
+	 */
+	public void test_close() throws IOException {
+		sink.close();
+		assertFalse(sink.isOpen());
+	}
+    
+    public void test_socketChannel_read_close() throws Exception {
+        ServerSocketChannel ssc = ServerSocketChannel.open();
+        ssc.socket().bind(new InetSocketAddress(InetAddress.getLocalHost(),49999));
+        SocketChannel sc = SocketChannel.open();
+        ByteBuffer buf = null;  
+        try{
+            sc.write(buf);
+            fail("should throw NPE");
+        }catch (NullPointerException e){
+            // expected
+        }
+        sc.connect(new InetSocketAddress(InetAddress.getLocalHost(),49999));
+        SocketChannel sock = ssc.accept();              
+        ssc.close();
+        sc.close();
+        try{
+            sc.write(buf);
+            fail("should throw NPE");
+        }catch (NullPointerException e){
+            // expected
+        }
+        sock.close();
+    }
+
+    public void test_socketChannel_read_write() throws Exception {
+        ServerSocketChannel ssc = ServerSocketChannel.open();
+        ssc.socket().bind(new InetSocketAddress(InetAddress.getLocalHost(),49999));
+        SocketChannel sc = SocketChannel.open();
+        sc.connect(new InetSocketAddress(InetAddress.getLocalHost(),49999));
+        SocketChannel sock = ssc.accept();
+        ByteBuffer[] buf = {ByteBuffer.allocate(10),null};                
+        try{
+            sc.write(buf,0,2);
+            fail("should throw NPE");
+        }catch (NullPointerException e){
+            // expected
+        }
+        ssc.close();
+        sc.close();
+        ByteBuffer target = ByteBuffer.allocate(10);
+        assertEquals(-1, sock.read(target));
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SinkChannelTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SourceChannelTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SourceChannelTest.java?rev=413627&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SourceChannelTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SourceChannelTest.java
Mon Jun 12 03:31:47 2006
@@ -0,0 +1,505 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * 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 org.apache.harmony.tests.java.nio.channels;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.Pipe;
+import java.nio.channels.SelectionKey;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for java.nio.channels.Pipe.SourceChannel
+ */
+public class SourceChannelTest extends TestCase {
+
+	private static final int BUFFER_SIZE = 5;
+
+	private static final String ISO8859_1 = "ISO8859-1";
+
+	private Pipe pipe;
+
+	private Pipe.SinkChannel sink;
+
+	private Pipe.SourceChannel source;
+
+	private ByteBuffer buffer;
+
+	private ByteBuffer positionedBuffer;
+
+	protected void setUp() throws Exception {
+		super.setUp();
+		pipe = Pipe.open();
+		sink = pipe.sink();
+		source = pipe.source();
+		buffer = ByteBuffer.wrap("bytes".getBytes(ISO8859_1));
+		positionedBuffer = ByteBuffer.wrap("12345bytes".getBytes(ISO8859_1));
+		positionedBuffer.position(BUFFER_SIZE);
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SourceChannel#validOps()
+	 */
+	public void test_validOps() {
+		assertEquals(SelectionKey.OP_READ, source.validOps());
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
+	 */
+	public void test_read_LByteBuffer_DataAvailable() throws IOException {
+		// if anything can read, read method will not block
+		sink.write(ByteBuffer.allocate(1));
+		int count = source.read(ByteBuffer.allocate(10));
+		assertEquals(1, count);
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
+	 */
+	public void test_read_LByteBuffer_Exception() throws IOException {
+		ByteBuffer nullBuf = null;
+		try {
+			source.read(nullBuf);
+            fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
+	 */
+	public void test_read_LByteBuffer_SinkClosed() throws IOException {
+		ByteBuffer readBuf = ByteBuffer.allocate(BUFFER_SIZE);
+		sink.write(buffer);
+		sink.close();
+		long count = source.read(readBuf);
+		assertEquals(BUFFER_SIZE, count);
+		// readBuf is full, read 0 byte expected
+		count = source.read(readBuf);
+		assertEquals(0, count);
+		// readBuf is not null, -1 is expected
+		readBuf.position(0);
+		count = source.read(readBuf);
+		assertEquals(-1, count);
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
+	 */
+	public void test_read_LByteBuffer_SourceClosed() throws IOException {
+		ByteBuffer readBuf = ByteBuffer.allocate(BUFFER_SIZE);
+		source.close();
+		try {
+			source.read(readBuf);
+            fail("should throw ClosedChannelException");
+		} catch (ClosedChannelException e) {
+			// expected
+		}
+		readBuf.position(BUFFER_SIZE);
+		try {
+			// readBuf is full
+			source.read(readBuf);
+            fail("should throw ClosedChannelException");
+		} catch (ClosedChannelException e) {
+			// expected
+		}
+
+		ByteBuffer nullBuf = null;
+		try {
+			source.read(nullBuf);
+            fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+        
+        ByteBuffer[] bufArray = null; 
+        try {
+            source.read(bufArray);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        
+        ByteBuffer[] nullBufArray = {nullBuf}; 
+        try {
+            source.read(nullBufArray);
+            fail("should throw ClosedChannelException");
+        } catch (ClosedChannelException e) {
+            // expected
+        }
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer[])
+	 */
+	public void test_read_$LByteBuffer() throws IOException {
+		ByteBuffer[] bufArray = { buffer, positionedBuffer };
+		boolean[] sinkBlockingMode = { true, true, false, false };
+		boolean[] sourceBlockingMode = { true, false, true, false };
+		for (int i = 0; i < sinkBlockingMode.length; ++i) {
+			sink.configureBlocking(sinkBlockingMode[i]);
+			source.configureBlocking(sourceBlockingMode[i]);
+
+			buffer.position(0);
+			positionedBuffer.position(BUFFER_SIZE);
+			long writeCount = sink.write(bufArray);
+			assertEquals(10, writeCount);
+			// if sink and source both are blocking mode, source only needs read
+			// once to get what sink write.
+			boolean isBlocking = sinkBlockingMode[i] && sourceBlockingMode[i];
+			ByteBuffer[] readBufArray = { ByteBuffer.allocate(BUFFER_SIZE),
+			        ByteBuffer.allocate(BUFFER_SIZE) };
+			long totalCount = 0;
+			do {
+				long count = source.read(readBufArray);
+				if (count < 0) {
+					break;
+				}
+				totalCount += count;
+			} while (totalCount != 10 && !isBlocking);
+
+			// assert read result
+			for (ByteBuffer readBuf : readBufArray) {
+				// RI may fail because of its bug implementation
+				assertEquals(BUFFER_SIZE, readBuf.position());
+				assertEquals("bytes", new String(readBuf.array(), ISO8859_1));
+			}
+		}
+	}
+	
+	/**
+	 * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
+	 */
+	public void test_read_$LByteBuffer_Exception() throws IOException {
+		ByteBuffer[] nullBufArrayRef = null;
+		try {
+			source.read(nullBufArrayRef);
+			fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+
+		// ByteBuffer array contains null element
+		ByteBuffer nullBuf = null;
+		ByteBuffer[] nullBufArray1 = { nullBuf };
+		try {
+			source.read(nullBufArray1);
+			fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+
+		ByteBuffer[] nullBufArray2 = { buffer, nullBuf };
+		try {
+			source.read(nullBufArray2);
+			fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
+	 */
+	public void test_read_$LByteBuffer_SinkClosed() throws IOException {
+		ByteBuffer readBuf = ByteBuffer.allocate(BUFFER_SIZE);
+		ByteBuffer[] readBufArray = { readBuf };
+		sink.write(buffer);
+		sink.close();
+		long count = source.read(readBufArray);
+		assertEquals(BUFFER_SIZE, count);
+		// readBuf is full, read 0 byte expected
+		count = source.read(readBufArray);
+		assertEquals(0, count);
+		// readBuf is not null, -1 is expected
+		readBuf.position(0);
+        assertTrue(readBuf.hasRemaining());
+		count = source.read(readBufArray);
+		assertEquals(-1, count);
+	}
+    
+	/**
+	 * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
+	 */
+	public void test_read_$LByteBuffer_SourceClosed() throws IOException {
+		ByteBuffer readBuf = ByteBuffer.allocate(BUFFER_SIZE);
+		ByteBuffer[] readBufArray = { readBuf };
+		source.close();
+		try {
+			source.read(readBufArray);
+            fail("should throw ClosedChannelException");
+		} catch (ClosedChannelException e) {
+			// expected
+		}
+		readBuf.position(BUFFER_SIZE);
+		try {
+			// readBuf is full
+			source.read(readBufArray);
+            fail("should throw ClosedChannelException");
+		} catch (ClosedChannelException e) {
+			// expected
+		}
+
+		ByteBuffer[] nullBufArrayRef = null;
+		try {
+			source.read(nullBufArrayRef);
+			fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+
+		// ByteBuffer array contains null element
+		ByteBuffer nullBuf = null;
+		ByteBuffer[] nullBufArray1 = { nullBuf };
+		try {
+			source.read(nullBufArray1);
+			fail("should throw ClosedChannelException");
+		} catch (ClosedChannelException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer[], int, int)
+	 */
+	public void test_read_$LByteBufferII() throws IOException {
+		ByteBuffer[] bufArray = { buffer, positionedBuffer };
+		boolean[] sinkBlockingMode = { true, true, false, false };
+		boolean[] sourceBlockingMode = { true, false, true, false };
+		for (int i = 0; i < sinkBlockingMode.length; ++i) {
+			sink.configureBlocking(sinkBlockingMode[i]);
+			source.configureBlocking(sourceBlockingMode[i]);
+
+			buffer.position(0);
+			positionedBuffer.position(BUFFER_SIZE);
+			sink.write(bufArray);
+			// begin to read
+			// if sink and source both are blocking mode, source only needs read
+			// once to get what sink write.
+			boolean isBlocking = sinkBlockingMode[i] && sourceBlockingMode[i];
+			ByteBuffer[] readBufArray = { ByteBuffer.allocate(BUFFER_SIZE),
+			        ByteBuffer.allocate(BUFFER_SIZE) };
+			long totalCount = 0;
+			do {
+				long count = source.read(readBufArray, 0, 2);
+				if (count < 0) {
+					break;
+				}
+				totalCount += count;
+			} while (totalCount != 10 && !isBlocking);
+
+			// assert read result
+			for (ByteBuffer readBuf : readBufArray) {
+				// RI may fail because of its bug implementation
+				assertEquals(BUFFER_SIZE, readBuf.position());
+				assertEquals("bytes", new String(readBuf.array(), ISO8859_1));
+			}
+		}
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
+	 */
+	public void test_read_$LByteBufferII_Exception() throws IOException {
+
+		ByteBuffer[] nullBufArrayRef = null;
+		try {
+			source.read(nullBufArrayRef, 0, 1);
+			fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+
+		try {
+			source.read(nullBufArrayRef, 0, -1);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		// ByteBuffer array contains null element
+		ByteBuffer nullBuf = null;
+		ByteBuffer[] nullBufArray1 = { nullBuf };
+		try {
+			source.read(nullBufArray1, 0, 1);
+			fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+		try {
+			source.read(nullBufArray1, 0, -1);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+		try {
+			source.read(nullBufArray1, -1, 0);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+		try {
+			source.read(nullBufArray1, -1, 1);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		ByteBuffer[] nullBufArray2 = { buffer, nullBuf };
+
+		try {
+			source.read(nullBufArray1, 1, -1);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		try {
+			source.read(nullBufArray2, 0, 3);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		try {
+			source.read(nullBufArray2, 0, 2);
+			fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
+	 */
+	public void test_read_$LByteBufferII_SinkClosed() throws IOException {
+		ByteBuffer readBuf = ByteBuffer.allocate(BUFFER_SIZE);
+		ByteBuffer[] readBufArray = { readBuf };
+		sink.write(buffer);
+		sink.close();
+		long count = source.read(readBufArray, 0, 1);
+		assertEquals(BUFFER_SIZE, count);
+		// readBuf is full, read 0 byte expected
+		count = source.read(readBufArray);
+		assertEquals(0, count);
+		// readBuf is not null, -1 is expected
+		readBuf.position(0);
+		count = source.read(readBufArray, 0, 1);
+		assertEquals(-1, count);
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
+	 */
+	public void test_read_$LByteBufferII_SourceClosed() throws IOException {
+		ByteBuffer readBuf = ByteBuffer.allocate(BUFFER_SIZE);
+		ByteBuffer[] readBufArray = { readBuf };
+		source.close();
+		try {
+			source.read(readBufArray, 0, 1);
+			fail("should throw ClosedChannelException");
+		} catch (ClosedChannelException e) {
+			// expected
+		}
+		readBuf.position(BUFFER_SIZE);
+		try {
+			// readBuf is full
+			source.read(readBufArray, 0, 1);
+			fail("should throw ClosedChannelException");
+		} catch (ClosedChannelException e) {
+			// expected
+		}
+
+		ByteBuffer[] nullBufArrayRef = null;
+		try {
+			source.read(nullBufArrayRef, 0, 1);
+			fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			// expected
+		}
+
+		try {
+			source.read(nullBufArrayRef, 0, -1);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		// ByteBuffer array contains null element
+		ByteBuffer nullBuf = null;
+		ByteBuffer[] nullBufArray1 = { nullBuf };
+		try {
+			source.read(nullBufArray1, 0, 1);
+			fail("should throw ClosedChannelException");
+		} catch (ClosedChannelException e) {
+			// expected
+		}
+		try {
+			source.read(nullBufArray1, 0, -1);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+		try {
+			source.read(nullBufArray1, -1, 0);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+		try {
+			source.read(nullBufArray1, -1, 1);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		ByteBuffer[] nullBufArray2 = { buffer, nullBuf };
+
+		try {
+			source.read(nullBufArray1, 1, -1);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		try {
+			source.read(nullBufArray2, 0, 3);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			// expected
+		}
+
+		try {
+			source.read(nullBufArray2, 0, 2);
+			fail("should throw ClosedChannelException");
+		} catch (ClosedChannelException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.nio.channels.Pipe.SourceChannel#close()
+	 */
+	public void test_close() throws IOException {
+		sink.close();
+		assertFalse(sink.isOpen());
+	}
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/org/apache/harmony/tests/java/nio/channels/SourceChannelTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message