harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r386058 [10/49] - in /incubator/harmony/enhanced/classlib/trunk: make/ modules/archive/make/common/ modules/archive/src/test/java/tests/ modules/archive/src/test/java/tests/api/ modules/archive/src/test/java/tests/api/java/ modules/archive/...
Date Wed, 15 Mar 2006 11:47:39 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,364 @@
+/* Copyright 1998, 2005 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 tests.api.java.io;
+
+import java.io.IOException;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+
+public class PipedInputStreamTest extends junit.framework.TestCase {
+
+	static class PWriter implements Runnable {
+		PipedOutputStream pos;
+
+		public byte bytes[];
+
+		public void run() {
+			try {
+				pos.write(bytes);
+				synchronized (this) {
+					notify();
+				}
+			} catch (IOException e) {
+				e.printStackTrace(System.out);
+				System.out.println("Could not write bytes");
+			}
+		}
+
+		public PWriter(PipedOutputStream pout, int nbytes) {
+			pos = pout;
+			bytes = new byte[nbytes];
+			for (int i = 0; i < bytes.length; i++)
+				bytes[i] = (byte) (System.currentTimeMillis() % 9);
+		}
+	}
+
+	Thread t;
+
+	PWriter pw;
+
+	PipedInputStream pis;
+
+	PipedOutputStream pos;
+
+	/**
+	 * @tests java.io.PipedInputStream#PipedInputStream()
+	 */
+	public void test_Constructor() {
+		// Test for method java.io.PipedInputStream()
+		// Used in tests
+	}
+
+	/**
+	 * @tests java.io.PipedInputStream#PipedInputStream(java.io.PipedOutputStream)
+	 */
+	public void test_ConstructorLjava_io_PipedOutputStream() {
+		// Test for method java.io.PipedInputStream(java.io.PipedOutputStream)
+		try {
+			pis = new PipedInputStream(new PipedOutputStream());
+			pis.available();
+		} catch (Exception e) {
+			fail("Exception during constructor test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.PipedInputStream#available()
+	 */
+	public void test_available() {
+		// Test for method int java.io.PipedInputStream.available()
+		pis = new PipedInputStream();
+		pos = new PipedOutputStream();
+		try {
+			pis.connect(pos);
+			t = new Thread(pw = new PWriter(pos, 1000));
+			t.start();
+		} catch (IOException e) {
+			fail("Exception during available test: " + e.toString());
+		}
+		try {
+			synchronized (pw) {
+				pw.wait(10000);
+			}
+			assertTrue("Available returned incorrect number of bytes: "
+					+ pis.available(), pis.available() == 1000);
+		} catch (IOException e) {
+			fail("Exception getting available bytes : " + e.getMessage());
+		} catch (InterruptedException e) {
+			fail("InterruptedException getting available bytes : "
+					+ e.getMessage());
+		}
+
+		try {
+			PipedInputStream pin = new PipedInputStream();
+			PipedOutputStream pout = new PipedOutputStream(pin);
+			// We know the PipedInputStream buffer size is 1024.
+			// Writing another byte would cause the write to wait
+			// for a read before returning
+			for (int i = 0; i < 1024; i++)
+				pout.write(i);
+			assertTrue("Incorrect available count: " + pin.available(), pin
+					.available() == 1024);
+		} catch (IOException e) {
+			fail("Unexpected: " + e);
+		}
+	}
+
+	/**
+	 * @tests java.io.PipedInputStream#close()
+	 */
+	public void test_close() {
+		// Test for method void java.io.PipedInputStream.close()
+		pis = new PipedInputStream();
+		pos = new PipedOutputStream();
+		try {
+			pis.connect(pos);
+			pis.close();
+			pos.write((byte) 127);
+		} catch (IOException e) {
+			// The spec for PipedInput saya an exception should be thrown if
+			// a write is attempted to a closed input. The PipedOuput spec
+			// indicates that an exception should be thrown only when the
+			// piped input thread is terminated without closing
+			return;
+		}
+		fail("Failed to throw expected exception");
+	}
+
+	/**
+	 * @tests java.io.PipedInputStream#connect(java.io.PipedOutputStream)
+	 */
+	public void test_connectLjava_io_PipedOutputStream() {
+		// Test for method void
+		// java.io.PipedInputStream.connect(java.io.PipedOutputStream)
+		pis = new PipedInputStream();
+		pos = new PipedOutputStream();
+		try {
+			assertTrue("Non-conected pipe returned non-zero available bytes",
+					pis.available() == 0);
+		} catch (IOException e) {
+			fail("IOException getting avail bytes : " + e.getMessage());
+		}
+		try {
+			pis.connect(pos);
+			t = new Thread(pw = new PWriter(pos, 1000));
+			t.start();
+		} catch (IOException e) {
+			fail("Exception during connect test : " + e.getMessage());
+		}
+		try {
+			synchronized (pw) {
+				pw.wait(10000);
+			}
+			assertTrue("Available returned incorrect number of bytes: "
+					+ pis.available(), pis.available() == 1000);
+		} catch (IOException e) {
+			fail("Exception getting available bytes : " + e.getMessage());
+		} catch (InterruptedException e) {
+			fail("InterruptedException getting available bytes : "
+					+ e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.PipedInputStream#read()
+	 */
+	public void test_read() {
+		// Test for method int java.io.PipedInputStream.read()
+		pis = new PipedInputStream();
+		pos = new PipedOutputStream();
+		try {
+			pis.connect(pos);
+			t = new Thread(pw = new PWriter(pos, 1000));
+			t.start();
+		} catch (IOException e) {
+			fail("Exception during read test : " + e.getMessage());
+		}
+		try {
+			synchronized (pw) {
+				pw.wait(10000);
+			}
+			assertTrue("Available returned incorrect number of bytes: "
+					+ pis.available(), pis.available() == 1000);
+			assertTrue("read returned incorrect byte",
+					((byte) pis.read()) == pw.bytes[0]);
+		} catch (IOException e) {
+			fail("Exception reading byte : " + e.getMessage());
+		} catch (InterruptedException e) {
+			fail("InterruptedException getting available bytes : "
+					+ e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.PipedInputStream#read(byte[], int, int)
+	 */
+	public void test_read$BII() {
+		// Test for method int java.io.PipedInputStream.read(byte [], int, int)
+		pis = new PipedInputStream();
+		pos = new PipedOutputStream();
+		try {
+			pis.connect(pos);
+			t = new Thread(pw = new PWriter(pos, 1000));
+			t.start();
+		} catch (IOException e) {
+			fail("Exception during read test : " + e.getMessage());
+		}
+		try {
+			byte[] buf = new byte[400];
+			synchronized (pw) {
+				pw.wait(10000);
+			}
+			assertTrue("Available returned incorrect number of bytes: "
+					+ pis.available(), pis.available() == 1000);
+			pis.read(buf, 0, 400);
+			for (int i = 0; i < 400; i++)
+				assertTrue("read returned incorrect byte[]",
+						buf[i] == pw.bytes[i]);
+		} catch (IOException e) {
+			fail("Exception reading byte[] : " + e.getMessage());
+		} catch (InterruptedException e) {
+			fail("InterruptedException getting available bytes : "
+					+ e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.PipedInputStream#receive(int)
+	 */
+	public void test_receive() {
+		pis = new PipedInputStream();
+		pos = new PipedOutputStream();
+
+		// test if writer recognizes dead reader
+		try {
+			pis.connect(pos);
+			class WriteRunnable implements Runnable {
+				boolean pass = false;
+
+				boolean readerAlive = true;
+
+				public void run() {
+					try {
+						pos.write(1);
+						while (readerAlive)
+							;
+						try {
+							// should throw exception since reader thread
+							// is now dead
+							pos.write(1);
+						} catch (IOException e) {
+							pass = true;
+						}
+					} catch (IOException e) {
+					}
+				}
+			}
+			WriteRunnable writeRunnable = new WriteRunnable();
+			Thread writeThread = new Thread(writeRunnable);
+			class ReadRunnable implements Runnable {
+				boolean pass;
+
+				public void run() {
+					try {
+						int one = pis.read();
+						pass = true;
+					} catch (IOException e) {
+					}
+				}
+			}
+			;
+			ReadRunnable readRunnable = new ReadRunnable();
+			Thread readThread = new Thread(readRunnable);
+			writeThread.start();
+			readThread.start();
+			while (readThread.isAlive())
+				;
+			writeRunnable.readerAlive = false;
+			assertTrue("reader thread failed to read", readRunnable.pass);
+			while (writeThread.isAlive())
+				;
+			assertTrue("writer thread failed to recognize dead reader",
+					writeRunnable.pass);
+		} catch (IOException e) {
+			fail("Exception during receive test: " + e.toString());
+		}
+
+		// attempt to write to stream after writer closed
+		pis = new PipedInputStream();
+		pos = new PipedOutputStream();
+
+		try {
+			pis.connect(pos);
+			class MyRunnable implements Runnable {
+				boolean pass;
+
+				public void run() {
+					try {
+						pos.write(1);
+					} catch (IOException e) {
+						pass = true;
+					}
+				}
+			}
+			MyRunnable myRun = new MyRunnable();
+			synchronized (pis) {
+				t = new Thread(myRun);
+				// thread t will be blocked inside pos.write(1)
+				// when it tries to call the synchronized method pis.receive
+				// because we hold the monitor for object pis
+				t.start();
+				try {
+					// wait for thread t to get to the call to pis.receive
+					Thread.sleep(100);
+				} catch (InterruptedException e) {
+				}
+				// now we close
+				pos.close();
+			}
+			// we have exited the synchronized block, so now thread t will make
+			// a call to pis.receive AFTER the output stream was closed,
+			// in which case an IOException should be thrown
+			while (t.isAlive()) {
+				;
+			}
+			assertTrue(
+					"write failed to throw IOException on closed PipedOutputStream",
+					myRun.pass);
+		} catch (IOException e) {
+			fail("Exception during second part of receive test: "
+					+ e.toString());
+		}
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+		try {
+			if (t != null)
+				t.interrupt();
+		} catch (Exception e) {
+		}
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedOutputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedOutputStreamTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedOutputStreamTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedOutputStreamTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,202 @@
+/* Copyright 1998, 2005 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 tests.api.java.io;
+
+import java.io.IOException;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+
+public class PipedOutputStreamTest extends junit.framework.TestCase {
+
+	static class PReader implements Runnable {
+		PipedInputStream reader;
+
+		public PipedInputStream getReader() {
+			return reader;
+		}
+
+		public PReader(PipedOutputStream out) {
+			try {
+				reader = new PipedInputStream(out);
+			} catch (Exception e) {
+				System.out.println("Couldn't start reader");
+			}
+		}
+
+		public int available() {
+			try {
+				return reader.available();
+			} catch (Exception e) {
+				return -1;
+			}
+		}
+
+		public void run() {
+			try {
+				while (true) {
+					Thread.sleep(1000);
+					Thread.yield();
+				}
+			} catch (InterruptedException e) {
+			}
+		}
+
+		public String read(int nbytes) {
+			byte[] buf = new byte[nbytes];
+			try {
+				reader.read(buf, 0, nbytes);
+				return new String(buf);
+			} catch (IOException e) {
+				System.out.println("Exception reading info");
+				return "ERROR";
+			}
+		}
+	}
+
+	Thread rt;
+
+	PReader reader;
+
+	PipedOutputStream out;
+
+	/**
+	 * @tests java.io.PipedOutputStream#PipedOutputStream()
+	 */
+	public void test_Constructor() {
+		// Test for method java.io.PipedOutputStream()
+		// Used in tests
+	}
+
+	/**
+	 * @tests java.io.PipedOutputStream#PipedOutputStream(java.io.PipedInputStream)
+	 */
+	public void test_ConstructorLjava_io_PipedInputStream() {
+		// Test for method java.io.PipedOutputStream(java.io.PipedInputStream)
+
+		try {
+			out = new PipedOutputStream(new PipedInputStream());
+			out.write('b');
+		} catch (Exception e) {
+			fail("Exception during constructor test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.PipedOutputStream#close()
+	 */
+	public void test_close() {
+		// Test for method void java.io.PipedOutputStream.close()
+		try {
+			out = new PipedOutputStream();
+			rt = new Thread(reader = new PReader(out));
+			rt.start();
+			out.close();
+		} catch (IOException e) {
+			fail("Exception during close : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.PipedOutputStream#connect(java.io.PipedInputStream)
+	 */
+	public void test_connectLjava_io_PipedInputStream() {
+		// Test for method void
+		// java.io.PipedOutputStream.connect(java.io.PipedInputStream)
+		try {
+			out = new PipedOutputStream();
+			rt = new Thread(reader = new PReader(out));
+			rt.start();
+			out.connect(new PipedInputStream());
+		} catch (IOException e) {
+			// Correct
+			return;
+		}
+		fail(
+				"Failed to throw exception attemting connect on already connected stream");
+
+	}
+
+	/**
+	 * @tests java.io.PipedOutputStream#flush()
+	 */
+	public void test_flush() {
+		// Test for method void java.io.PipedOutputStream.flush()
+		try {
+			out = new PipedOutputStream();
+			rt = new Thread(reader = new PReader(out));
+			rt.start();
+			out.write("HelloWorld".getBytes(), 0, 10);
+			assertTrue("Bytes written before flush", reader.available() != 0);
+			out.flush();
+			assertTrue("Wrote incorrect bytes", reader.read(10).equals(
+					"HelloWorld"));
+		} catch (IOException e) {
+			fail("IOException during write test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.PipedOutputStream#write(byte[], int, int)
+	 */
+	public void test_write$BII() {
+		// Test for method void java.io.PipedOutputStream.write(byte [], int,
+		// int)
+		try {
+			out = new PipedOutputStream();
+			rt = new Thread(reader = new PReader(out));
+			rt.start();
+			out.write("HelloWorld".getBytes(), 0, 10);
+			out.flush();
+			assertTrue("Wrote incorrect bytes", reader.read(10).equals(
+					"HelloWorld"));
+		} catch (IOException e) {
+			fail("IOException during write test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.PipedOutputStream#write(int)
+	 */
+	public void test_writeI() {
+		// Test for method void java.io.PipedOutputStream.write(int)
+		try {
+			out = new PipedOutputStream();
+			rt = new Thread(reader = new PReader(out));
+			rt.start();
+			out.write('c');
+			out.flush();
+			assertTrue("Wrote incorrect byte", reader.read(1).equals("c"));
+		} catch (IOException e) {
+			fail("IOException during write test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+		if (rt != null)
+			rt.interrupt();
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedReaderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedReaderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedReaderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedReaderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,217 @@
+/* Copyright 1998, 2005 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 tests.api.java.io;
+
+import java.io.PipedReader;
+import java.io.PipedWriter;
+
+public class PipedReaderTest extends junit.framework.TestCase {
+
+	static class PWriter implements Runnable {
+		public PipedWriter pw;
+
+		public PWriter(PipedReader reader) {
+			try {
+				pw = new PipedWriter(reader);
+			} catch (Exception e) {
+				System.out.println("Couldn't create writer");
+			}
+		}
+
+		public PWriter() {
+			pw = new PipedWriter();
+		}
+
+		public void run() {
+			try {
+				char[] c = new char[11];
+				"Hello World".getChars(0, 11, c, 0);
+				pw.write(c);
+				Thread.sleep(10000);
+			} catch (InterruptedException e) {
+			} catch (Exception e) {
+				System.out.println("Exception occurred: " + e.toString());
+			}
+		}
+	}
+
+	PipedReader preader;
+
+	PWriter pwriter;
+
+	Thread t;
+
+	/**
+	 * @tests java.io.PipedReader#PipedReader()
+	 */
+	public void test_Constructor() {
+		// Test for method java.io.PipedReader()
+		// Used in test
+	}
+
+	/**
+	 * @tests java.io.PipedReader#PipedReader(java.io.PipedWriter)
+	 */
+	public void test_ConstructorLjava_io_PipedWriter() {
+		// Test for method java.io.PipedReader(java.io.PipedWriter)
+		try {
+			preader = new PipedReader(new PipedWriter());
+
+		} catch (Exception e) {
+			fail("Exception during constructor test: " + e.toString());
+		}
+	}
+
+	/**
+	 * @tests java.io.PipedReader#close()
+	 */
+	public void test_close() {
+		// Test for method void java.io.PipedReader.close()
+		char[] c = null;
+		try {
+			preader = new PipedReader();
+			t = new Thread(new PWriter(preader), "");
+			t.start();
+			Thread.sleep(500); // Allow writer to start
+			c = new char[11];
+			preader.read(c, 0, 11);
+			preader.close();
+		} catch (Exception e) {
+			fail("Exception during close test : " + e.getMessage());
+		}
+		assertTrue("Read incorrect chars", new String(c).equals("Hello World"));
+	}
+
+	/**
+	 * @tests java.io.PipedReader#connect(java.io.PipedWriter)
+	 */
+	public void test_connectLjava_io_PipedWriter() {
+		// Test for method void java.io.PipedReader.connect(java.io.PipedWriter)
+		char[] c = null;
+		try {
+			preader = new PipedReader();
+			t = new Thread(pwriter = new PWriter(), "");
+			preader.connect(pwriter.pw);
+			t.start();
+			Thread.sleep(500); // Allow writer to start
+			c = new char[11];
+			preader.read(c, 0, 11);
+		} catch (Exception e) {
+			fail("Exception during connect test : " + e.getMessage());
+		}
+		assertTrue("Read incorrect chars", new String(c).equals("Hello World"));
+		try {
+			preader.connect(pwriter.pw);
+		} catch (Exception e) {
+			// Correct
+			return;
+		}
+		fail(
+				"Failed to throw exception connecting to pre-connected reader");
+	}
+
+	/**
+	 * @tests java.io.PipedReader#read()
+	 */
+	public void test_read() {
+		// Test for method int java.io.PipedReader.read()
+		char[] c = null;
+		try {
+			preader = new PipedReader();
+			t = new Thread(new PWriter(preader), "");
+			t.start();
+			Thread.sleep(500); // Allow writer to start
+			c = new char[11];
+			for (int i = 0; i < c.length; i++)
+				c[i] = (char) preader.read();
+		} catch (Exception e) {
+			fail("Exception during read test : " + e.getMessage());
+		}
+		assertTrue("Read incorrect chars: " + new String(c), new String(c)
+				.equals("Hello World"));
+	}
+
+	/**
+	 * @tests java.io.PipedReader#read(char[], int, int)
+	 */
+	public void test_read$CII() {
+		// Test for method int java.io.PipedReader.read(char [], int, int)
+		char[] c = null;
+		try {
+			preader = new PipedReader();
+			t = new Thread(new PWriter(preader), "");
+			t.start();
+			Thread.sleep(500); // Allow writer to start
+			c = new char[11];
+			int n = 0;
+			int x = n;
+			while (x < 11) {
+				n = preader.read(c, x, 11 - x);
+				x = x + n;
+			}
+		} catch (Exception e) {
+			fail("Exception during read test : " + e.getMessage());
+		}
+		assertTrue("Read incorrect chars: " + new String(c), new String(c)
+				.equals("Hello World"));
+		try {
+			preader.close();
+			preader.read(c, 8, 7);
+		} catch (Exception e) {
+			// Correct
+			return;
+		}
+		fail("Failed to throw exception reading from closed reader");
+	}
+
+	/**
+	 * @tests java.io.PipedReader#ready()
+	 */
+	public void test_ready() {
+		// Test for method boolean java.io.PipedReader.ready()
+		char[] c = null;
+		try {
+			preader = new PipedReader();
+			t = new Thread(new PWriter(preader), "");
+			t.start();
+			Thread.sleep(500); // Allow writer to start
+			assertTrue("Reader should be ready", preader.ready());
+			c = new char[11];
+			for (int i = 0; i < c.length; i++)
+				c[i] = (char) preader.read();
+			assertTrue("Reader should not be ready after reading all chars",
+					!preader.ready());
+		} catch (Exception e) {
+			fail("Exception during read test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+		if (t != null)
+			t.interrupt();
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedWriterTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedWriterTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedWriterTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedWriterTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,232 @@
+/* Copyright 1998, 2005 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 tests.api.java.io;
+
+import java.io.IOException;
+import java.io.PipedReader;
+import java.io.PipedWriter;
+
+public class PipedWriterTest extends junit.framework.TestCase {
+
+	static class PReader implements Runnable {
+		public PipedReader pr;
+
+		public char[] buf = new char[10];
+
+		public PReader(PipedWriter pw) {
+			try {
+				pr = new PipedReader(pw);
+			} catch (IOException e) {
+				System.out.println("Exception setting up reader: "
+						+ e.toString());
+			}
+		}
+
+		public PReader(PipedReader pr) {
+			this.pr = pr;
+		}
+
+		public void run() {
+			try {
+				int r = 0;
+				for (int i = 0; i < buf.length; i++) {
+					r = pr.read();
+					if (r == -1)
+						break;
+					buf[i] = (char) r;
+				}
+			} catch (Exception e) {
+				System.out.println("Exception reading ("
+						+ Thread.currentThread().getName() + "): "
+						+ e.toString());
+			}
+		}
+	}
+
+	Thread rdrThread;
+
+	PReader reader;
+
+	PipedWriter pw;
+
+	/**
+	 * @tests java.io.PipedWriter#PipedWriter()
+	 */
+	public void test_Constructor() {
+		// Test for method java.io.PipedWriter()
+		// Used in tests
+	}
+
+	/**
+	 * @tests java.io.PipedWriter#PipedWriter(java.io.PipedReader)
+	 */
+	public void test_ConstructorLjava_io_PipedReader() {
+		// Test for method java.io.PipedWriter(java.io.PipedReader)
+		try {
+			char[] buf = new char[10];
+			"HelloWorld".getChars(0, 10, buf, 0);
+			PipedReader rd = new PipedReader();
+			pw = new PipedWriter(rd);
+			rdrThread = new Thread(reader = new PReader(rd),
+					"Constructor(Reader)");
+			rdrThread.start();
+			pw.write(buf);
+			pw.close();
+			rdrThread.join(500);
+		} catch (Exception e) {
+			fail("Exception during constructor test: " + e.toString());
+		}
+		assertTrue("Failed to construct writer", "HelloWorld"
+				.equals(new String(reader.buf)));
+	}
+
+	/**
+	 * @tests java.io.PipedWriter#close()
+	 */
+	public void test_close() {
+		// Test for method void java.io.PipedWriter.close()
+		char[] buf = new char[10];
+		try {
+			"HelloWorld".getChars(0, 10, buf, 0);
+			PipedReader rd = new PipedReader();
+			pw = new PipedWriter(rd);
+			reader = new PReader(rd);
+			pw.close();
+		} catch (Exception e) {
+			fail("Exception during close test : " + e.getMessage());
+		}
+		try {
+			pw.write(buf);
+		} catch (Exception e) {
+			// correct
+			return;
+		}
+		fail(
+				"Should have thrown exception when attempting to write to closed writer.");
+
+	}
+
+	/**
+	 * @tests java.io.PipedWriter#connect(java.io.PipedReader)
+	 */
+	public void test_connectLjava_io_PipedReader() {
+		// Test for method void java.io.PipedWriter.connect(java.io.PipedReader)
+		try {
+			char[] buf = new char[10];
+			"HelloWorld".getChars(0, 10, buf, 0);
+			PipedReader rd = new PipedReader();
+			pw = new PipedWriter();
+			pw.connect(rd);
+			rdrThread = new Thread(reader = new PReader(rd), "connect");
+			rdrThread.start();
+			pw.write(buf);
+			pw.close();
+			rdrThread.join(500);
+		} catch (Exception e) {
+			fail("Exception during write test : " + e.getMessage());
+		}
+		assertTrue("Failed to write correct chars", "HelloWorld"
+				.equals(new String(reader.buf)));
+	}
+
+	/**
+	 * @tests java.io.PipedWriter#flush()
+	 */
+	public void test_flush() {
+		// Test for method void java.io.PipedWriter.flush()
+		try {
+			char[] buf = new char[10];
+			"HelloWorld".getChars(0, 10, buf, 0);
+			pw = new PipedWriter();
+			rdrThread = new Thread(reader = new PReader(pw), "flush");
+			rdrThread.start();
+			pw.write(buf);
+			pw.flush();
+			rdrThread.join(700);
+		} catch (Exception e) {
+			fail("Exception during flush test : " + e.getMessage());
+		}
+		assertTrue("Failed to flush chars", "HelloWorld".equals(new String(
+				reader.buf)));
+	}
+
+	/**
+	 * @tests java.io.PipedWriter#write(char[], int, int)
+	 */
+	public void test_write$CII() {
+		// Test for method void java.io.PipedWriter.write(char [], int, int)
+		try {
+			char[] buf = new char[10];
+			"HelloWorld".getChars(0, 10, buf, 0);
+			pw = new PipedWriter();
+			rdrThread = new Thread(reader = new PReader(pw), "writeCII");
+			rdrThread.start();
+			pw.write(buf, 0, 10);
+			pw.close();
+			rdrThread.join(1000);
+		} catch (Exception e) {
+			fail("Exception during write test : " + e.getMessage());
+		}
+		assertTrue("Failed to write correct chars", "HelloWorld"
+				.equals(new String(reader.buf)));
+	}
+
+	/**
+	 * @tests java.io.PipedWriter#write(int)
+	 */
+	public void test_writeI() {
+		// Test for method void java.io.PipedWriter.write(int)
+		try {
+			pw = new PipedWriter();
+			rdrThread = new Thread(reader = new PReader(pw), "writeI");
+			rdrThread.start();
+			pw.write(1);
+			pw.write(2);
+			pw.write(3);
+			pw.close();
+			rdrThread.join(1000);
+		} catch (Exception e) {
+			fail("Exception during write test : " + e.getMessage());
+		}
+		assertTrue("Failed to write correct chars: " + (int) reader.buf[0]
+				+ " " + (int) reader.buf[1] + " " + (int) reader.buf[2],
+				reader.buf[0] == 1 && reader.buf[1] == 2 && reader.buf[2] == 3);
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+		try {
+			if (rdrThread != null)
+				rdrThread.interrupt();
+		} catch (Exception e) {
+		}
+		try {
+			if (pw != null)
+				pw.close();
+		} catch (Exception e) {
+		}
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintStreamTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintStreamTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintStreamTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,529 @@
+/* Copyright 1998, 2005 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 tests.api.java.io;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class PrintStreamTest extends junit.framework.TestCase {
+
+	java.io.ByteArrayOutputStream bos;
+
+	private java.io.PrintStream os;
+
+	java.io.ByteArrayInputStream bis;
+
+	byte[] ibuf = new byte[4096];
+
+	public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_Class
 NotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Obj
 ect\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketE
 xception\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
+
+	/**
+	 * @tests java.io.PrintStream#PrintStream(java.io.OutputStream)
+	 */
+	public void test_ConstructorLjava_io_OutputStream() {
+		// Test for method java.io.PrintStream(java.io.OutputStream)
+		try {
+			os = new java.io.PrintStream(bos);
+			os.print(2345.76834720202);
+		} catch (Exception e) {
+			fail("IOException during constructor test : " + e.getMessage());
+		} finally {
+			try {
+				os.close();
+			} catch (Exception e) {
+				fail("IOException during constructor test : " + e.getMessage());
+			}
+		}
+	}
+
+	/**
+	 * @tests java.io.PrintStream#PrintStream(java.io.OutputStream, boolean)
+	 */
+	public void test_ConstructorLjava_io_OutputStreamZ() {
+		// Test for method java.io.PrintStream(java.io.OutputStream, boolean)
+		try {
+			os = new java.io.PrintStream(bos);
+			os.println(2345.76834720202);
+			os.flush();
+			assertTrue("Bytes not written", bos.size() > 0);
+		} catch (Exception e) {
+			fail("Exception during constructor test : " + e.getMessage());
+		} finally {
+			try {
+				os.close();
+			} catch (Exception e) {
+				fail("Exception during constructor test : " + e.getMessage());
+			}
+		}
+	}
+
+	/**
+	 * @tests java.io.PrintStream#checkError()
+	 */
+	public void test_checkError() {
+		// Test for method boolean java.io.PrintStream.checkError()
+		try {
+			os = new java.io.PrintStream(new OutputStream() {
+				public void write(int b) throws IOException {
+					throw new IOException();
+				}
+
+				public void write(byte[] b, int o, int l)
+						throws java.io.IOException {
+					throw new java.io.IOException();
+				}
+			});
+			os.print(fileString.substring(0, 501));
+			assertTrue("Checkerror should return true", os.checkError() == true);
+		} catch (Exception e) {
+			fail("Exception raised : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.PrintStream#close()
+	 */
+	public void test_close() {
+		// Test for method void java.io.PrintStream.close()
+		try {
+			os = new java.io.PrintStream(bos);
+			os.close();
+		} catch (Exception e) {
+			fail("Close test raised exception : " + e.getMessage());
+		} finally {
+			try {
+				bos.close();
+			} catch (java.io.IOException e) {
+				fail("IOException during flush test : " + e.getMessage());
+			}
+		}
+	}
+
+	/**
+	 * @tests java.io.PrintStream#flush()
+	 */
+	public void test_flush() {
+		// Test for method void java.io.PrintStream.flush()
+		try {
+			os = new java.io.PrintStream(bos);
+			os.print(fileString.substring(0, 501));
+			os.flush();
+			assertTrue("Bytes not written after flush.", bos.size() == 501);
+			bos.close();
+		} catch (java.io.IOException e) {
+			fail("Flush test failed with IOException: " + e.toString());
+		} finally {
+			try {
+				os.close();
+				bos.close();
+			} catch (java.io.IOException e) {
+				fail("IOException during flush test: " + e.toString());
+			}
+		}
+	}
+
+	/**
+	 * @tests java.io.PrintStream#print(char[])
+	 */
+	public void test_print$C() {
+		// Test for method void java.io.PrintStream.print(char [])
+		int r = 0;
+		os = new java.io.PrintStream(bos, true);
+		try {
+			os.print((char[]) null);
+		} catch (NullPointerException ex) {
+			r = 1;
+		}
+		assertTrue(
+				"expected null Pointer Exception for print(char[]) not thrown",
+				r == 1);
+
+		os = new java.io.PrintStream(bos, true);
+		char[] sc = new char[4000];
+		fileString.getChars(0, fileString.length(), sc, 0);
+		os.print(sc);
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		os.close();
+		byte[] rbytes = new byte[4000];
+		bis.read(rbytes, 0, fileString.length());
+		assertTrue("Incorrect char[] written", new String(rbytes, 0, fileString
+				.length()).equals(fileString));
+	}
+
+	/**
+	 * @tests java.io.PrintStream#print(char)
+	 */
+	public void test_printC() {
+		// Test for method void java.io.PrintStream.print(char)
+		os = new java.io.PrintStream(bos, true);
+		os.print('t');
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		assertTrue("Incorrect char written", bis.read() == 't');
+	}
+
+	/**
+	 * @tests java.io.PrintStream#print(double)
+	 */
+	public void test_printD() {
+		// Test for method void java.io.PrintStream.print(double)
+		byte[] rbuf = new byte[100];
+		os = new java.io.PrintStream(bos, true);
+		os.print(2345.76834720202);
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		bis.read(rbuf, 0, 16);
+		assertTrue("Incorrect double written", new String(rbuf, 0, 16)
+				.equals("2345.76834720202"));
+	}
+
+	/**
+	 * @tests java.io.PrintStream#print(float)
+	 */
+	public void test_printF() {
+		// Test for method void java.io.PrintStream.print(float)
+		os = new java.io.PrintStream(bos, true);
+		byte rbuf[] = new byte[10];
+		os.print(29.08764f);
+		os.flush();
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		bis.read(rbuf, 0, 8);
+		assertTrue("Incorrect float written", new String(rbuf, 0, 8)
+				.equals("29.08764"));
+
+	}
+
+	/**
+	 * @tests java.io.PrintStream#print(int)
+	 */
+	public void test_printI() {
+		// Test for method void java.io.PrintStream.print(int)
+		os = new java.io.PrintStream(bos, true);
+		os.print(768347202);
+		byte[] rbuf = new byte[18];
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		bis.read(rbuf, 0, 9);
+		assertTrue("Incorrect int written", new String(rbuf, 0, 9)
+				.equals("768347202"));
+	}
+
+	/**
+	 * @tests java.io.PrintStream#print(long)
+	 */
+	public void test_printJ() {
+		// Test for method void java.io.PrintStream.print(long)
+		byte[] rbuf = new byte[100];
+		os = new java.io.PrintStream(bos, true);
+		os.print(9875645283333L);
+		os.close();
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		bis.read(rbuf, 0, 13);
+		assertTrue("Incorrect long written", new String(rbuf, 0, 13)
+				.equals("9875645283333"));
+	}
+
+	/**
+	 * @tests java.io.PrintStream#print(java.lang.Object)
+	 */
+	public void test_printLjava_lang_Object() {
+		// Test for method void java.io.PrintStream.print(java.lang.Object)
+		os = new java.io.PrintStream(bos, true);
+		os.print((Object) null);
+		os.flush();
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		byte[] nullbytes = new byte[4];
+		bis.read(nullbytes, 0, 4);
+		assertTrue("null should be written", new String(nullbytes, 0, 4)
+				.equals("null"));
+		try {
+			bis.close();
+			bos.close();
+			os.close();
+		} catch (java.io.IOException e) {
+			fail("Unexpectted IO exception : " + e.getMessage());
+		}
+		java.io.ByteArrayOutputStream bos1 = new java.io.ByteArrayOutputStream();
+		os = new java.io.PrintStream(bos1, true);
+		os.print(new java.util.Vector());
+		bis = new java.io.ByteArrayInputStream(bos1.toByteArray());
+		byte[] rbytes = new byte[2];
+		bis.read(rbytes, 0, 2);
+		assertTrue("Incorrect Object written", new String(rbytes, 0, 2)
+				.equals("[]"));
+	}
+
+	/**
+	 * @tests java.io.PrintStream#print(java.lang.String)
+	 */
+	public void test_printLjava_lang_String() {
+		// Test for method void java.io.PrintStream.print(java.lang.String)
+		os = new java.io.PrintStream(bos, true);
+		os.print((String) null);
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		byte[] nullbytes = new byte[4];
+		bis.read(nullbytes, 0, 4);
+		assertTrue("null should be written", new String(nullbytes, 0, 4)
+				.equals("null"));
+		try {
+			bis.close();
+			bos.close();
+			os.close();
+		} catch (java.io.IOException e) {
+			fail("Unexpected IO exception : " + e.getMessage());
+		}
+		java.io.ByteArrayOutputStream bos1 = new java.io.ByteArrayOutputStream();
+		os = new java.io.PrintStream(bos1, true);
+		os.print("Hello World");
+		bis = new java.io.ByteArrayInputStream(bos1.toByteArray());
+		byte rbytes[] = new byte[100];
+		bis.read(rbytes, 0, 11);
+		assertTrue("Incorrect string written", new String(rbytes, 0, 11)
+				.equals("Hello World"));
+	}
+
+	/**
+	 * @tests java.io.PrintStream#print(boolean)
+	 */
+	public void test_printZ() {
+		// Test for method void java.io.PrintStream.print(boolean)
+		java.io.DataInputStream dis = null;
+		os = new java.io.PrintStream(bos, true);
+		os.print(true);
+		dis = new java.io.DataInputStream(new java.io.ByteArrayInputStream(bos
+				.toByteArray()));
+		try {
+			assertTrue("Incorrect boolean written", dis.readBoolean() == true);
+		} catch (java.io.IOException e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.PrintStream#println()
+	 */
+	public void test_println() {
+		// Test for method void java.io.PrintStream.println()
+		char c;
+		os = new java.io.PrintStream(bos, true);
+		os.println("");
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		assertTrue("Newline not written", (c = (char) bis.read()) == '\r'
+				|| c == '\n');
+	}
+
+	/**
+	 * @tests java.io.PrintStream#println(char[])
+	 */
+	public void test_println$C() {
+		// Test for method void java.io.PrintStream.println(char [])
+		os = new java.io.PrintStream(bos, true);
+		char[] sc = new char[4000];
+		fileString.getChars(0, fileString.length(), sc, 0);
+		os.println(sc);
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		byte[] rbytes = new byte[4000];
+		bis.read(rbytes, 0, fileString.length());
+		assertTrue("Incorrect char[] written", new String(rbytes, 0, fileString
+				.length()).equals(fileString));
+		// In this particular test method, the end of data is not immediately
+		// followed by newLine separator in the reading buffer, instead its
+		// followed by zeros. The newline is written as the last entry
+		// in the inputStream buffer. Therefore, we must keep reading until we
+		// hit a new line.
+		int r;
+		boolean newline = false;
+		while ((r = bis.read()) != -1) {
+			if (r == '\r' || r == '\n')
+				newline = true;
+		}
+		assertTrue("Newline not written", newline);
+	}
+
+	/**
+	 * @tests java.io.PrintStream#println(char)
+	 */
+	public void test_printlnC() {
+		// Test for method void java.io.PrintStream.println(char)
+		int c;
+		os = new java.io.PrintStream(bos, true);
+		os.println('t');
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		assertTrue("Incorrect char written", bis.read() == 't');
+		assertTrue("Newline not written", (c = bis.read()) == '\r' || c == '\n');
+	}
+
+	/**
+	 * @tests java.io.PrintStream#println(double)
+	 */
+	public void test_printlnD() {
+		// Test for method void java.io.PrintStream.println(double)
+		int c;
+		os = new java.io.PrintStream(bos, true);
+		os.println(2345.76834720202);
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		byte[] rbuf = new byte[100];
+		bis.read(rbuf, 0, 16);
+		assertTrue("Incorrect double written", new String(rbuf, 0, 16)
+				.equals("2345.76834720202"));
+		assertTrue("Newline not written", (c = bis.read()) == '\r' || c == '\n');
+	}
+
+	/**
+	 * @tests java.io.PrintStream#println(float)
+	 */
+	public void test_printlnF() {
+		// Test for method void java.io.PrintStream.println(float)
+		int c;
+		byte[] rbuf = new byte[100];
+		os = new java.io.PrintStream(bos, true);
+		os.println(29.08764f);
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		bis.read(rbuf, 0, 8);
+		assertTrue("Incorrect float written", new String(rbuf, 0, 8)
+				.equals("29.08764"));
+		assertTrue("Newline not written", (c = bis.read()) == '\r' || c == '\n');
+	}
+
+	/**
+	 * @tests java.io.PrintStream#println(int)
+	 */
+	public void test_printlnI() {
+		// Test for method void java.io.PrintStream.println(int)
+		int c;
+		os = new java.io.PrintStream(bos, true);
+		os.println(768347202);
+		byte[] rbuf = new byte[100];
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		bis.read(rbuf, 0, 9);
+		assertTrue("Incorrect int written", new String(rbuf, 0, 9)
+				.equals("768347202"));
+		assertTrue("Newline not written", (c = bis.read()) == '\r' || c == '\n');
+	}
+
+	/**
+	 * @tests java.io.PrintStream#println(long)
+	 */
+	public void test_printlnJ() {
+		// Test for method void java.io.PrintStream.println(long)
+		int c;
+		os = new java.io.PrintStream(bos, true);
+		os.println(9875645283333L);
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		byte[] rbuf = new byte[100];
+		bis.read(rbuf, 0, 13);
+		assertTrue("Incorrect long written", new String(rbuf, 0, 13)
+				.equals("9875645283333"));
+		assertTrue("Newline not written", (c = bis.read()) == '\r' || c == '\n');
+	}
+
+	/**
+	 * @tests java.io.PrintStream#println(java.lang.Object)
+	 */
+	public void test_printlnLjava_lang_Object() {
+		// Test for method void java.io.PrintStream.println(java.lang.Object)
+		char c;
+		os = new java.io.PrintStream(bos, true);
+		os.println(new java.util.Vector());
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		byte[] rbytes = new byte[2];
+		bis.read(rbytes, 0, 2);
+		assertTrue("Incorrect Vector written", new String(rbytes, 0, 2)
+				.equals("[]"));
+		assertTrue("Newline not written", (c = (char) bis.read()) == '\r'
+				|| c == '\n');
+	}
+
+	/**
+	 * @tests java.io.PrintStream#println(java.lang.String)
+	 */
+	public void test_printlnLjava_lang_String() {
+		// Test for method void java.io.PrintStream.println(java.lang.String)
+		char c;
+		os = new java.io.PrintStream(bos, true);
+		os.println("Hello World");
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		byte rbytes[] = new byte[100];
+		bis.read(rbytes, 0, 11);
+		assertTrue("Incorrect string written", new String(rbytes, 0, 11)
+				.equals("Hello World"));
+		assertTrue("Newline not written", (c = (char) bis.read()) == '\r'
+				|| c == '\n');
+	}
+
+	/**
+	 * @tests java.io.PrintStream#println(boolean)
+	 */
+	public void test_printlnZ() {
+		// Test for method void java.io.PrintStream.println(boolean)
+		int c;
+		os = new java.io.PrintStream(bos, true);
+		os.println(true);
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		byte[] rbuf = new byte[100];
+		bis.read(rbuf, 0, 4);
+		assertTrue("Incorrect boolean written", new String(rbuf, 0, 4)
+				.equals("true"));
+		assertTrue("Newline not written", (c = bis.read()) == '\r' || c == '\n');
+	}
+
+	/**
+	 * @tests java.io.PrintStream#write(byte[], int, int)
+	 */
+	public void test_write$BII() {
+		// Test for method void java.io.PrintStream.write(byte [], int, int)
+		os = new java.io.PrintStream(bos, true);
+		os.write(fileString.getBytes(), 0, fileString.length());
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		byte rbytes[] = new byte[4000];
+		bis.read(rbytes, 0, fileString.length());
+		assertTrue("Incorrect bytes written", new String(rbytes, 0, fileString
+				.length()).equals(fileString));
+	}
+
+	/**
+	 * @tests java.io.PrintStream#write(int)
+	 */
+	public void test_writeI() {
+		// Test for method void java.io.PrintStream.write(int)
+		os = new java.io.PrintStream(bos, true);
+		os.write('t');
+		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
+		assertTrue("Incorrect char written", bis.read() == 't');
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+		try {
+			bos = new java.io.ByteArrayOutputStream();
+		} catch (Throwable e) {
+			fail("Exception during setup : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+
+		try {
+			os.close();
+			bis.close();
+		} catch (Throwable e) {
+		}
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintWriterTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintWriterTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintWriterTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintWriterTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,607 @@
+/* Copyright 1998, 2005 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 tests.api.java.io;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import tests.support.Support_StringReader;
+import tests.support.Support_StringWriter;
+
+public class PrintWriterTest extends junit.framework.TestCase {
+
+	static class Bogus {
+		public String toString() {
+			return "Bogus";
+		}
+	}
+
+	PrintWriter pw;
+
+	ByteArrayOutputStream bao;
+
+	ByteArrayInputStream bai;
+
+	BufferedReader br;
+
+	/**
+	 * @tests java.io.PrintWriter#PrintWriter(java.io.OutputStream)
+	 */
+	public void test_ConstructorLjava_io_OutputStream() {
+		// Test for method java.io.PrintWriter(java.io.OutputStream)
+		String s;
+		pw.println("Random Chars");
+		pw.write("Hello World");
+		pw.flush();
+		try {
+			br = new BufferedReader(new Support_StringReader(bao.toString()));
+			s = br.readLine();
+			assertTrue("Incorrect string written/read: " + s, s
+					.equals("Random Chars"));
+			s = br.readLine();
+			assertTrue("Incorrect string written/read: " + s, s
+					.equals("Hello World"));
+		} catch (IOException e) {
+			fail("IOException during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#PrintWriter(java.io.OutputStream, boolean)
+	 */
+	public void test_ConstructorLjava_io_OutputStreamZ() {
+		// Test for method java.io.PrintWriter(java.io.OutputStream, boolean)
+		String s;
+		pw = new PrintWriter(bao, true);
+		pw.println("Random Chars");
+		pw.write("Hello World");
+		try {
+			br = new BufferedReader(new Support_StringReader(bao.toString()));
+			s = br.readLine();
+			assertTrue("Incorrect string written/read: " + s, s
+					.equals("Random Chars"));
+			pw.flush();
+			br = new BufferedReader(new Support_StringReader(bao.toString()));
+			s = br.readLine();
+			assertTrue("Incorrect string written/read: " + s, s
+					.equals("Random Chars"));
+			s = br.readLine();
+			assertTrue("Incorrect string written/read: " + s, s
+					.equals("Hello World"));
+		} catch (IOException e) {
+			fail("IOException during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#PrintWriter(java.io.Writer)
+	 */
+	public void test_ConstructorLjava_io_Writer() {
+		// Test for method java.io.PrintWriter(java.io.Writer)
+		Support_StringWriter sw;
+		pw = new PrintWriter(sw = new Support_StringWriter());
+		pw.print("Hello");
+		pw.flush();
+		assertTrue("Failed to construct proper writer", sw.toString().equals(
+				"Hello"));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#PrintWriter(java.io.Writer, boolean)
+	 */
+	public void test_ConstructorLjava_io_WriterZ() {
+		// Test for method java.io.PrintWriter(java.io.Writer, boolean)
+		Support_StringWriter sw;
+		pw = new PrintWriter(sw = new Support_StringWriter(), true);
+		pw.print("Hello");
+		// Auto-flush should have happened
+		assertTrue("Failed to construct proper writer", sw.toString().equals(
+				"Hello"));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#checkError()
+	 */
+	public void test_checkError() {
+		// Test for method boolean java.io.PrintWriter.checkError()
+		pw.close();
+		pw.print(490000000000.08765);
+		assertTrue("Failed to return error", pw.checkError());
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#close()
+	 */
+	public void test_close() {
+		// Test for method void java.io.PrintWriter.close()
+		pw.close();
+		pw.println("l");
+		assertTrue("Write on closed stream failed to generate error", pw
+				.checkError());
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#flush()
+	 */
+	public void test_flush() {
+		// Test for method void java.io.PrintWriter.flush()
+		final double dub = 490000000000.08765;
+		pw.print(dub);
+		pw.flush();
+		assertTrue("Failed to flush", new String(bao.toByteArray())
+				.equals(String.valueOf(dub)));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#print(char[])
+	 */
+	public void test_print$C() {
+		// Test for method void java.io.PrintWriter.print(char [])
+		String s = null;
+		char[] schars = new char[11];
+		"Hello World".getChars(0, 11, schars, 0);
+		pw.print(schars);
+		pw.flush();
+		try {
+			br = new BufferedReader(new Support_StringReader(bao.toString()));
+			s = br.readLine();
+		} catch (IOException e) {
+			fail("IOException during test : " + e.getMessage());
+		}
+		assertTrue("Wrote incorrect char[] string: " + s, s
+				.equals("Hello World"));
+		int r = 0;
+		try {
+			pw.print((char[]) null);
+		} catch (NullPointerException e) {
+			r = 1;
+		}
+		assertTrue(
+				"null pointer exception for printing null char[] is not caught",
+				r == 1);
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#print(char)
+	 */
+	public void test_printC() {
+		// Test for method void java.io.PrintWriter.print(char)
+		pw.print('c');
+		pw.flush();
+		assertTrue("Wrote incorrect char string", new String(bao.toByteArray())
+				.equals("c"));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#print(double)
+	 */
+	public void test_printD() {
+		// Test for method void java.io.PrintWriter.print(double)
+		final double dub = 490000000000.08765;
+		pw.print(dub);
+		pw.flush();
+		assertTrue("Wrote incorrect double string", new String(bao
+				.toByteArray()).equals(String.valueOf(dub)));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#print(float)
+	 */
+	public void test_printF() {
+		// Test for method void java.io.PrintWriter.print(float)
+		final float flo = 49.08765f;
+		pw.print(flo);
+		pw.flush();
+		assertTrue("Wrote incorrect float string",
+				new String(bao.toByteArray()).equals(String.valueOf(flo)));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#print(int)
+	 */
+	public void test_printI() {
+		// Test for method void java.io.PrintWriter.print(int)
+		pw.print(4908765);
+		pw.flush();
+		assertTrue("Wrote incorrect int string", new String(bao.toByteArray())
+				.equals("4908765"));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#print(long)
+	 */
+	public void test_printJ() {
+		// Test for method void java.io.PrintWriter.print(long)
+		pw.print(49087650000L);
+		pw.flush();
+		assertTrue("Wrote incorrect long string", new String(bao.toByteArray())
+				.equals("49087650000"));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#print(java.lang.Object)
+	 */
+	public void test_printLjava_lang_Object() {
+		// Test for method void java.io.PrintWriter.print(java.lang.Object)
+		pw.print((Object) null);
+		pw.flush();
+		assertTrue("Did not write null", new String(bao.toByteArray())
+				.equals("null"));
+		bao.reset();
+
+		pw.print(new Bogus());
+		pw.flush();
+		assertTrue("Wrote in incorrect Object string", new String(bao
+				.toByteArray()).equals("Bogus"));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#print(java.lang.String)
+	 */
+	public void test_printLjava_lang_String() {
+		// Test for method void java.io.PrintWriter.print(java.lang.String)
+		pw.print((String) null);
+		pw.flush();
+		assertTrue("did not write null", new String(bao.toByteArray())
+				.equals("null"));
+		bao.reset();
+
+		pw.print("Hello World");
+		pw.flush();
+		assertTrue("Wrote incorrect  string", new String(bao.toByteArray())
+				.equals("Hello World"));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#print(boolean)
+	 */
+	public void test_printZ() {
+		// Test for method void java.io.PrintWriter.print(boolean)
+		pw.print(true);
+		pw.flush();
+		assertTrue("Wrote in incorrect boolean string", new String(bao
+				.toByteArray()).equals("true"));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#println()
+	 */
+	public void test_println() {
+		// Test for method void java.io.PrintWriter.println()
+		String s;
+		pw.println("Blarg");
+		pw.println();
+		pw.println("Bleep");
+		pw.flush();
+		try {
+			br = new BufferedReader(new Support_StringReader(bao.toString()));
+			s = br.readLine();
+			assertTrue("Wrote incorrect line: " + s, s.equals("Blarg"));
+			s = br.readLine();
+			assertTrue("Wrote incorrect line: " + s, s.equals(""));
+			s = br.readLine();
+			assertTrue("Wrote incorrect line: " + s, s.equals("Bleep"));
+		} catch (IOException e) {
+			fail("IOException during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#println(char[])
+	 */
+	public void test_println$C() {
+		// Test for method void java.io.PrintWriter.println(char [])
+		String s = null;
+		char[] schars = new char[11];
+		"Hello World".getChars(0, 11, schars, 0);
+		pw.println("Random Chars");
+		pw.println(schars);
+		pw.flush();
+		try {
+			br = new BufferedReader(new Support_StringReader(bao.toString()));
+			s = br.readLine();
+			s = br.readLine();
+		} catch (IOException e) {
+			fail("IOException during test : " + e.getMessage());
+		}
+		assertTrue("Wrote incorrect char[] string: " + s, s
+				.equals("Hello World"));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#println(char)
+	 */
+	public void test_printlnC() {
+		// Test for method void java.io.PrintWriter.println(char)
+		String s = null;
+		pw.println("Random Chars");
+		pw.println('c');
+		pw.flush();
+		try {
+			br = new BufferedReader(new Support_StringReader(bao.toString()));
+			s = br.readLine();
+			s = br.readLine();
+		} catch (IOException e) {
+			fail("IOException during test : " + e.getMessage());
+		}
+		assertTrue("Wrote incorrect char string: " + s, s.equals("c"));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#println(double)
+	 */
+	public void test_printlnD() {
+		// Test for method void java.io.PrintWriter.println(double)
+		String s = null;
+		final double dub = 4000000000000000.657483;
+		pw.println("Random Chars");
+		pw.println(dub);
+		pw.flush();
+		try {
+			br = new BufferedReader(new Support_StringReader(bao.toString()));
+			br.readLine();
+			s = br.readLine();
+		} catch (IOException e) {
+			fail("IOException during test : " + e.getMessage());
+		}
+		assertTrue("Wrote incorrect double string: " + s, s.equals(String
+				.valueOf(dub)));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#println(float)
+	 */
+	public void test_printlnF() {
+		// Test for method void java.io.PrintWriter.println(float)
+		String s;
+		final float flo = 40.4646464f;
+		pw.println("Random Chars");
+		pw.println(flo);
+		pw.flush();
+		try {
+			br = new BufferedReader(new Support_StringReader(bao.toString()));
+			br.readLine();
+			s = br.readLine();
+			assertTrue("Wrote incorrect float string: " + s + " wanted: "
+					+ String.valueOf(flo), s.equals(String.valueOf(flo)));
+		} catch (IOException e) {
+			fail("IOException during test : " + e.getMessage());
+		}
+
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#println(int)
+	 */
+	public void test_printlnI() {
+		// Test for method void java.io.PrintWriter.println(int)
+		String s = null;
+		pw.println("Random Chars");
+		pw.println(400000);
+		pw.flush();
+		try {
+			br = new BufferedReader(new Support_StringReader(bao.toString()));
+			br.readLine();
+			s = br.readLine();
+		} catch (IOException e) {
+			fail("IOException during test : " + e.getMessage());
+		}
+		assertTrue("Wrote incorrect int string: " + s, s.equals("400000"));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#println(long)
+	 */
+	public void test_printlnJ() {
+		// Test for method void java.io.PrintWriter.println(long)
+		String s = null;
+		pw.println("Random Chars");
+		pw.println(4000000000000L);
+		pw.flush();
+		try {
+			br = new BufferedReader(new Support_StringReader(bao.toString()));
+			br.readLine();
+			s = br.readLine();
+		} catch (IOException e) {
+			fail("IOException during test : " + e.getMessage());
+		}
+		assertTrue("Wrote incorrect long string: " + s, s
+				.equals("4000000000000"));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#println(java.lang.Object)
+	 */
+	public void test_printlnLjava_lang_Object() {
+		// Test for method void java.io.PrintWriter.println(java.lang.Object)
+		String s = null;
+		pw.println("Random Chars");
+		pw.println(new Bogus());
+		pw.flush();
+		try {
+			br = new BufferedReader(new Support_StringReader(bao.toString()));
+			br.readLine();
+			s = br.readLine();
+		} catch (IOException e) {
+			fail("IOException during test : " + e.getMessage());
+		}
+		assertTrue("Wrote incorrect Object string: " + s, s.equals("Bogus"));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#println(java.lang.String)
+	 */
+	public void test_printlnLjava_lang_String() {
+		// Test for method void java.io.PrintWriter.println(java.lang.String)
+		String s = null;
+		pw.println("Random Chars");
+		pw.println("Hello World");
+		pw.flush();
+		try {
+			br = new BufferedReader(new Support_StringReader(bao.toString()));
+			br.readLine();
+			s = br.readLine();
+		} catch (IOException e) {
+			fail("IOException during test : " + e.getMessage());
+		}
+		assertTrue("Wrote incorrect string: " + s, s.equals("Hello World"));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#println(boolean)
+	 */
+	public void test_printlnZ() {
+		// Test for method void java.io.PrintWriter.println(boolean)
+		String s = null;
+		pw.println("Random Chars");
+		pw.println(false);
+		pw.flush();
+		try {
+			br = new BufferedReader(new Support_StringReader(bao.toString()));
+			br.readLine();
+			s = br.readLine();
+		} catch (IOException e) {
+			fail("IOException during test : " + e.getMessage());
+		}
+		assertTrue("Wrote incorrect boolean string: " + s, s.equals("false"));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#write(char[])
+	 */
+	public void test_write$C() {
+		// Test for method void java.io.PrintWriter.write(char [])
+		String s = null;
+		char[] schars = new char[11];
+		"Hello World".getChars(0, 11, schars, 0);
+		pw.println("Random Chars");
+		pw.write(schars);
+		pw.flush();
+		try {
+			br = new BufferedReader(new Support_StringReader(bao.toString()));
+			br.readLine();
+			s = br.readLine();
+		} catch (IOException e) {
+			fail("IOException during test: " + e.getMessage());
+		}
+		assertTrue("Wrote incorrect char[] string: " + s, s
+				.equals("Hello World"));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#write(char[], int, int)
+	 */
+	public void test_write$CII() {
+		// Test for method void java.io.PrintWriter.write(char [], int, int)
+		String s = null;
+		char[] schars = new char[11];
+		"Hello World".getChars(0, 11, schars, 0);
+		pw.println("Random Chars");
+		pw.write(schars, 6, 5);
+		pw.flush();
+		try {
+			br = new BufferedReader(new Support_StringReader(bao.toString()));
+			br.readLine();
+			s = br.readLine();
+		} catch (IOException e) {
+			fail("IOException during test : " + e.getMessage());
+		}
+		assertTrue("Wrote incorrect char[] string: " + s, s.equals("World"));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#write(int)
+	 */
+	public void test_writeI() {
+		// Test for method void java.io.PrintWriter.write(int)
+		char[] cab = new char[3];
+		pw.write('a');
+		pw.write('b');
+		pw.write('c');
+		pw.flush();
+		bai = new ByteArrayInputStream(bao.toByteArray());
+		cab[0] = (char) bai.read();
+		cab[1] = (char) bai.read();
+		cab[2] = (char) bai.read();
+		assertTrue("Wrote incorrect ints", cab[0] == 'a' && cab[1] == 'b'
+				&& cab[2] == 'c');
+
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#write(java.lang.String)
+	 */
+	public void test_writeLjava_lang_String() {
+		// Test for method void java.io.PrintWriter.write(java.lang.String)
+		String s = null;
+		pw.println("Random Chars");
+		pw.write("Hello World");
+		pw.flush();
+		try {
+			br = new BufferedReader(new Support_StringReader(bao.toString()));
+			br.readLine();
+			s = br.readLine();
+		} catch (IOException e) {
+			fail("IOException during test : " + e.getMessage());
+		}
+		assertTrue("Wrote incorrect char[] string: " + s, s
+				.equals("Hello World"));
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#write(java.lang.String, int, int)
+	 */
+	public void test_writeLjava_lang_StringII() {
+		// Test for method void java.io.PrintWriter.write(java.lang.String, int,
+		// int)
+		String s = null;
+		pw.println("Random Chars");
+		pw.write("Hello World", 6, 5);
+		pw.flush();
+		try {
+			br = new BufferedReader(new Support_StringReader(bao.toString()));
+			br.readLine();
+			s = br.readLine();
+		} catch (IOException e) {
+			fail("IOException during test : " + e.getMessage());
+		}
+		assertTrue("Wrote incorrect char[] string: " + s, s.equals("World"));
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+		bao = new ByteArrayOutputStream();
+		pw = new PrintWriter(bao, false);
+
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+		try {
+			pw.close();
+		} catch (Exception e) {
+		}
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PushbackInputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PushbackInputStreamTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PushbackInputStreamTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PushbackInputStreamTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,213 @@
+/* Copyright 1998, 2005 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 tests.api.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.PushbackInputStream;
+
+public class PushbackInputStreamTest extends junit.framework.TestCase {
+
+	PushbackInputStream pis;
+
+	public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_la
 ng_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_
 lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net
 _SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
+
+	/**
+	 * @tests java.io.PushbackInputStream#PushbackInputStream(java.io.InputStream)
+	 */
+	public void test_ConstructorLjava_io_InputStream() {
+		// Test for method java.io.PushbackInputStream(java.io.InputStream)
+		try {
+			pis = new PushbackInputStream(new ByteArrayInputStream("Hello"
+					.getBytes()));
+			pis.unread("He".getBytes());
+		} catch (IOException e) {
+			// Correct
+			// Pushback buffer should be full
+			return;
+
+		}
+		fail("Failed to throw exception on unread when buffer full");
+	}
+
+	/**
+	 * @tests java.io.PushbackInputStream#PushbackInputStream(java.io.InputStream,
+	 *        int)
+	 */
+	public void test_ConstructorLjava_io_InputStreamI() {
+		// Test for method java.io.PushbackInputStream(java.io.InputStream, int)
+		try {
+			pis = new PushbackInputStream(new ByteArrayInputStream("Hello"
+					.getBytes()), 5);
+			pis.unread("Hellos".getBytes());
+		} catch (IOException e) {
+			// Correct
+			// Pushback buffer should be full
+			return;
+
+		}
+		fail("Failed to throw exception on unread when buffer full");
+	}
+
+	/**
+	 * @tests java.io.PushbackInputStream#available()
+	 */
+	public void test_available() {
+		// Test for method int java.io.PushbackInputStream.available()
+		try {
+			assertTrue("Available returned incorrect number of bytes", pis
+					.available() == fileString.getBytes().length);
+		} catch (IOException e) {
+			fail("Exception during avaialable test: " + e.toString());
+		}
+	}
+
+	/**
+	 * @tests java.io.PushbackInputStream#markSupported()
+	 */
+	public void test_markSupported() {
+		// Test for method boolean java.io.PushbackInputStream.markSupported()
+		assertTrue("markSupported returned true", !pis.markSupported());
+	}
+
+	/**
+	 * @tests java.io.PushbackInputStream#read()
+	 */
+	public void test_read() {
+		// Test for method int java.io.PushbackInputStream.read()
+		try {
+			assertTrue("Incorrect byte read", pis.read() == fileString
+					.getBytes()[0]);
+		} catch (IOException e) {
+			fail("Exception during read test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.PushbackInputStream#read(byte[], int, int)
+	 */
+	public void test_read$BII() {
+		// Test for method int java.io.PushbackInputStream.read(byte [], int,
+		// int)
+		try {
+			byte[] buf = new byte[100];
+			pis.read(buf, 0, buf.length);
+			assertTrue("Incorrect bytes read", new String(buf)
+					.equals(fileString.substring(0, 100)));
+		} catch (IOException e) {
+			fail("Exception during read test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.PushbackInputStream#skip(long)
+	 */
+	public void test_skipJ() {
+		// Test for method long java.io.PushbackInputStream.skip(long)
+		try {
+			byte[] buf = new byte[50];
+			pis.skip(50);
+			pis.read(buf, 0, buf.length);
+			assertTrue("a) Incorrect bytes read", new String(buf)
+					.equals(fileString.substring(50, 100)));
+			pis.unread(buf);
+			pis.skip(25);
+			byte[] buf2 = new byte[25];
+			pis.read(buf2, 0, buf2.length);
+			assertTrue("b) Incorrect bytes read", new String(buf2)
+					.equals(fileString.substring(75, 100)));
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.PushbackInputStream#unread(byte[])
+	 */
+	public void test_unread$B() {
+		// Test for method void java.io.PushbackInputStream.unread(byte [])
+		try {
+			byte[] buf = new byte[100];
+			pis.read(buf, 0, buf.length);
+			assertTrue("Incorrect bytes read", new String(buf)
+					.equals(fileString.substring(0, 100)));
+			pis.unread(buf);
+			pis.read(buf, 0, 50);
+			assertTrue("Failed to unread bytes", new String(buf, 0, 50)
+					.equals(fileString.substring(0, 50)));
+		} catch (IOException e) {
+			fail("IOException during unread test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.PushbackInputStream#unread(byte[], int, int)
+	 */
+	public void test_unread$BII() {
+		// Test for method void java.io.PushbackInputStream.unread(byte [], int,
+		// int)
+		try {
+			byte[] buf = new byte[100];
+			pis.read(buf, 0, buf.length);
+			assertTrue("Incorrect bytes read", new String(buf)
+					.equals(fileString.substring(0, 100)));
+			pis.unread(buf, 50, 50);
+			pis.read(buf, 0, 50);
+			assertTrue("Failed to unread bytes", new String(buf, 0, 50)
+					.equals(fileString.substring(50, 100)));
+		} catch (IOException e) {
+			fail("IOException during unread test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.PushbackInputStream#unread(int)
+	 */
+	public void test_unreadI() {
+		// Test for method void java.io.PushbackInputStream.unread(int)
+		try {
+			int x;
+			assertTrue("Incorrect byte read", (x = pis.read()) == fileString
+					.getBytes()[0]);
+			pis.unread(x);
+			assertTrue("Failed to unread", pis.read() == x);
+		} catch (IOException e) {
+			fail("IOException during read test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+
+		pis = new PushbackInputStream(new ByteArrayInputStream(fileString
+				.getBytes()), 65535);
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+		try {
+			pis.close();
+		} catch (IOException e) {
+			fail("IOException during tearDown : " + e.getMessage());
+		}
+	}
+}



Mime
View raw message