harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r396774 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io: PipedInputStreamTest.java PipedReaderTest.java PipedWriterTest.java
Date Tue, 25 Apr 2006 05:51:34 GMT
Author: mloenko
Date: Mon Apr 24 22:51:32 2006
New Revision: 396774

URL: http://svn.apache.org/viewcvs?rev=396774&view=rev
Log:
making regression tests integrated with HARMONY-387 fix compliant to the conventions
making other tests in the modified files compliant to the conventions 

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedReaderTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedWriterTest.java

Modified: 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=396774&r1=396773&r2=396774&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java
Mon Apr 24 22:51:32 2006
@@ -64,69 +64,52 @@
 	/**
 	 * @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());
-		}
-	}
+	public void test_ConstructorLjava_io_PipedOutputStream() throws Exception {
+        // Test for method java.io.PipedInputStream(java.io.PipedOutputStream)
+        pis = new PipedInputStream(new PipedOutputStream());
+        pis.available();
+    }
 
 	/**
 	 * @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());
-		}
+	public void test_available() throws Exception {
+        // Test for method int java.io.PipedInputStream.available()
+        pis = new PipedInputStream();
+        pos = new PipedOutputStream();
+
+        pis.connect(pos);
+        t = new Thread(pw = new PWriter(pos, 1000));
+        t.start();
 
-		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);
-		}
-	}
+        synchronized (pw) {
+            pw.wait(10000);
+        }
+        assertTrue("Available returned incorrect number of bytes: "
+                + pis.available(), pis.available() == 1000);
+
+        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);
+        assertEquals("Incorrect available count", 1024 , pin.available());
+    }
 
 	/**
 	 * @tests java.io.PipedInputStream#close()
 	 */
-	public void test_close() {
+	public void test_close() throws IOException {
 		// Test for method void java.io.PipedInputStream.close()
 		pis = new PipedInputStream();
 		pos = new PipedOutputStream();
+        pis.connect(pos);
+        pis.close();
 		try {
-			pis.connect(pos);
-			pis.close();
 			pos.write((byte) 127);
+            fail("Failed to throw expected exception");
 		} 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
@@ -134,106 +117,74 @@
 			// 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());
-		}
-	}
+	public void test_connectLjava_io_PipedOutputStream() throws Exception {
+        // Test for method void
+        // java.io.PipedInputStream.connect(java.io.PipedOutputStream)
+        pis = new PipedInputStream();
+        pos = new PipedOutputStream();
+        assertEquals("Non-conected pipe returned non-zero available bytes", 0,
+                pis.available());
+
+        pis.connect(pos);
+        t = new Thread(pw = new PWriter(pos, 1000));
+        t.start();
+
+        synchronized (pw) {
+            pw.wait(10000);
+        }
+        assertEquals("Available returned incorrect number of bytes", 1000, pis
+                .available());
+    }
 
 	/**
 	 * @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());
-		}
-	}
+	public void test_read() throws Exception {
+        // Test for method int java.io.PipedInputStream.read()
+        pis = new PipedInputStream();
+        pos = new PipedOutputStream();
+
+        pis.connect(pos);
+        t = new Thread(pw = new PWriter(pos, 1000));
+        t.start();
+
+        synchronized (pw) {
+            pw.wait(10000);
+        }
+        assertEquals("Available returned incorrect number of bytes", 1000, pis
+                .available());
+        assertEquals("read returned incorrect byte", pw.bytes[0], (byte) pis
+                .read());
+    }
 
 	/**
 	 * @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());
-		}
-	}
+	public void test_read$BII() throws Exception {
+        // Test for method int java.io.PipedInputStream.read(byte [], int, int)
+        pis = new PipedInputStream();
+        pos = new PipedOutputStream();
+
+        pis.connect(pos);
+        t = new Thread(pw = new PWriter(pos, 1000));
+        t.start();
+
+        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++) {
+            assertEquals("read returned incorrect byte[]", pw.bytes[i], buf[i]);
+        }
+    }
 
     /**
      * @tests java.io.PipedInputStream#read(byte[], int, int)
@@ -254,7 +205,7 @@
     /**
      * @tests java.io.PipedInputStream#read(byte[], int, int)
      */
-    public void test_read$BII_3() {
+    public void test_read$BII_3() throws IOException {
         PipedInputStream obj = new PipedInputStream();
         try {
             obj.read(new byte[0], -1, 0);
@@ -262,15 +213,13 @@
         } catch (ArrayIndexOutOfBoundsException t) {
             fail("IndexOutOfBoundsException expected");
         } catch (IndexOutOfBoundsException t) {
-        } catch (IOException t) {
-            fail("Unexpected IOException: " + t.getMessage());
         }
     }
 
     /**
      * @tests java.io.PipedInputStream#read(byte[], int, int)
      */
-    public void test_read$BII_4() {
+    public void test_read$BII_4() throws IOException {
         PipedInputStream obj = new PipedInputStream();
         try {
             obj.read(new byte[0], -1, -1);
@@ -278,135 +227,119 @@
         } catch (ArrayIndexOutOfBoundsException t) {
             fail("IndexOutOfBoundsException expected");
         } catch (IndexOutOfBoundsException t) {
-        } catch (IOException t) {
-            fail("Unexpected IOException: " + t.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() {
-	}
+     * @tests java.io.PipedInputStream#receive(int)
+     */
+    public void test_receive() throws IOException {
+        pis = new PipedInputStream();
+        pos = new PipedOutputStream();
+
+        // test if writer recognizes dead reader
+        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);
+
+        // attempt to write to stream after writer closed
+        pis = new PipedInputStream();
+        pos = new PipedOutputStream();
+
+        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);
+    }
 
 	/**
 	 * Tears down the fixture, for example, close a network connection. This
 	 * method is called after a test is executed.
 	 */
-	protected void tearDown() {
+	protected void tearDown() throws Exception {
 		try {
-			if (t != null)
+			if (t != null) {
 				t.interrupt();
-		} catch (Exception e) {
+            }
+		} catch (Exception ignore) {
 		}
+        super.tearDown();
 	}
 }

Modified: 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=396774&r1=396773&r2=396774&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedReaderTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedReaderTest.java
Mon Apr 24 22:51:32 2006
@@ -56,127 +56,104 @@
 	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()
+     */
+    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#PipedReader(java.io.PipedWriter)
+     */
+    public void test_ConstructorLjava_io_PipedWriter() throws IOException {
+        // Test for method java.io.PipedReader(java.io.PipedWriter)
+        preader = new PipedReader(new PipedWriter());
+    }
 
-	/**
-	 * @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#close()
+     */
+    public void test_close() throws Exception {
+        // Test for method void java.io.PipedReader.close()
+        char[] c = null;
+        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();
+        assertEquals("Read incorrect chars", "Hello World", new String(c));
+    }
 
-	/**
-	 * @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#connect(java.io.PipedWriter)
+     */
+    public void test_connectLjava_io_PipedWriter() throws Exception {
+        // Test for method void java.io.PipedReader.connect(java.io.PipedWriter)
+        char[] c = null;
+
+        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);
+
+        assertEquals("Read incorrect chars", "Hello World", new String(c));
+        try {
+            preader.connect(pwriter.pw);
+            fail("Failed to throw exception connecting to pre-connected reader");
+        } catch (Exception e) {
+            // Correct
+        }
+    }
 
 	/**
 	 * @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"));
-	}
+	public void test_read() throws Exception {
+        // Test for method int java.io.PipedReader.read()
+        char[] c = null;
+        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();
+        }
+        assertEquals("Read incorrect chars", "Hello World", new String(c));
+    }
 
 	/**
 	 * @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");
-	}
+	public void test_read$CII() throws Exception {
+        // Test for method int java.io.PipedReader.read(char [], int, int)
+        char[] c = null;
+        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;
+        }
+        assertEquals("Read incorrect chars", "Hello World", new String(c));
+        try {
+            preader.close();
+            preader.read(c, 8, 7);
+            fail("Failed to throw exception reading from closed reader");
+        } catch (Exception e) {
+            // Correct
+        }
+    }
 
     /**
      * @tests java.io.PipedReader#read(char[], int, int)
@@ -199,7 +176,7 @@
     /**
      * @tests java.io.PipedReader#read(char[], int, int)
      */
-    public void test_read$CII_3() {
+    public void test_read$CII_3() throws IOException {
         PipedWriter pw = new PipedWriter();
         PipedReader obj = null;
         try {
@@ -209,15 +186,13 @@
         } catch (ArrayIndexOutOfBoundsException t) {
             fail("IndexOutOfBoundsException expected");
         } catch (IndexOutOfBoundsException t) {
-        } catch (IOException e) {
-            fail("Unexpected IOException: " + e.getMessage());
         }
     }
 
     /**
      * @tests java.io.PipedReader#read(char[], int, int)
      */
-    public void test_read$CII_4() {
+    public void test_read$CII_4() throws IOException {
         PipedWriter pw = new PipedWriter();
         PipedReader obj = null;
         try {
@@ -227,46 +202,35 @@
         } catch (ArrayIndexOutOfBoundsException t) {
             fail("IndexOutOfBoundsException expected");
         } catch (IndexOutOfBoundsException t) {
-        } catch (IOException e) {
-            fail("Unexpected IOException: " + e.getMessage());
         }
     }
 
     /**
 	 * @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() {
-	}
+	public void test_ready() throws Exception {
+        // Test for method boolean java.io.PipedReader.ready()
+        char[] c = null;
+        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();
+        assertFalse("Reader should not be ready after reading all chars",
+                preader.ready());
+    }
 
 	/**
 	 * 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)
+	protected void tearDown() throws Exception {
+		if (t != null) {
 			t.interrupt();
+        }
+        super.tearDown();
 	}
 }

Modified: 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=396774&r1=396773&r2=396774&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedWriterTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedWriterTest.java
Mon Apr 24 22:51:32 2006
@@ -71,122 +71,98 @@
 	}
 
 	/**
-	 * @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#PipedWriter(java.io.PipedReader)
+     */
+    public void test_ConstructorLjava_io_PipedReader() throws Exception {
+        // Test for method java.io.PipedWriter(java.io.PipedReader)
+        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);
+        assertEquals("Failed to construct writer", "HelloWorld", new String(
+                reader.buf));
+    }
+
+    /**
+     * @tests java.io.PipedWriter#close()
+     */
+    public void test_close() throws Exception {
+        // Test for method void java.io.PipedWriter.close()
+        char[] buf = new char[10];
+        "HelloWorld".getChars(0, 10, buf, 0);
+        PipedReader rd = new PipedReader();
+        pw = new PipedWriter(rd);
+        reader = new PReader(rd);
+        pw.close();
+        try {
+            pw.write(buf);
+            fail("Should have thrown exception when attempting to write to closed writer.");
+        } catch (Exception e) {
+            // correct
+        }
+    }
+
+    /**
+     * @tests java.io.PipedWriter#connect(java.io.PipedReader)
+     */
+    public void test_connectLjava_io_PipedReader() throws Exception {
+        // Test for method void java.io.PipedWriter.connect(java.io.PipedReader)
+        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);
+        assertEquals("Failed to write correct chars", "HelloWorld", new String(
+                reader.buf));
+    }
+
+    /**
+     * @tests java.io.PipedWriter#flush()
+     */
+    public void test_flush() throws Exception {
+        // Test for method void java.io.PipedWriter.flush()
+        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);
+        assertEquals("Failed to flush chars", "HelloWorld", new String(
+                reader.buf));
+    }
 
     /**
      * @tests java.io.PipedWriter#write(char[], int, int)
-     * Regression for HARMONY-387
+     */
+    public void test_write$CII() throws Exception {
+        // Test for method void java.io.PipedWriter.write(char [], int, int)
+        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);
+        assertEquals("Failed to write correct chars", "HelloWorld", new String(
+                reader.buf));
+    }
+
+    /**
+     * @tests java.io.PipedWriter#write(char[], int, int) Regression for
+     *        HARMONY-387
      */
     public void test_write$CII_2() throws IOException {
         PipedReader pr = new PipedReader();
@@ -205,7 +181,7 @@
     /**
      * @tests java.io.PipedWriter#write(char[], int, int)
      */
-    public void test_write$CII_3() {
+    public void test_write$CII_3() throws IOException {
         PipedReader pr = new PipedReader();
         PipedWriter obj = null;
         try {
@@ -214,16 +190,13 @@
             fail("IndexOutOfBoundsException expected");
         } catch (ArrayIndexOutOfBoundsException t) {
             fail("IndexOutOfBoundsException expected");
-        } catch (IndexOutOfBoundsException t) {
-        } catch (IOException e) {
-            fail("Unexpected IOException: " + e.getMessage());
-        }
+        } catch (IndexOutOfBoundsException t) {}
     }
 
     /**
      * @tests java.io.PipedWriter#write(char[], int, int)
      */
-    public void test_write$CII_4() {
+    public void test_write$CII_4() throws IOException {
         PipedReader pr = new PipedReader();
         PipedWriter obj = null;
         try {
@@ -232,16 +205,13 @@
             fail("IndexOutOfBoundsException expected");
         } catch (ArrayIndexOutOfBoundsException t) {
             fail("IndexOutOfBoundsException expected");
-        } catch (IndexOutOfBoundsException t) {
-        } catch (IOException e) {
-            fail("Unexpected IOException: " + e.getMessage());
-        }
+        } catch (IndexOutOfBoundsException t) {}
     }
 
     /**
      * @tests java.io.PipedWriter#write(char[], int, int)
      */
-    public void test_write$CII_5() {
+    public void test_write$CII_5() throws IOException {
         PipedReader pr = new PipedReader();
         PipedWriter obj = null;
         try {
@@ -250,16 +220,13 @@
             fail("NullPointerException expected");
         } catch (IndexOutOfBoundsException t) {
             fail("NullPointerException expected");
-        } catch (NullPointerException t) {
-        } catch (IOException e) {
-            fail("Unexpected IOException: " + e.getMessage());
-        }
+        } catch (NullPointerException t) {}
     }
 
     /**
      * @tests java.io.PipedWriter#write(char[], int, int)
      */
-    public void test_write$CII_6() {
+    public void test_write$CII_6() throws IOException {
         PipedReader pr = new PipedReader();
         PipedWriter obj = null;
         try {
@@ -268,55 +235,43 @@
             fail("NullPointerException expected");
         } catch (IndexOutOfBoundsException t) {
             fail("NullPointerException expected");
-        } catch (NullPointerException t) {
-        } catch (IOException e) {
-            fail("Unexpected IOException: " + e.getMessage());
-        }
+        } catch (NullPointerException t) {}
     }
 
     /**
-	 * @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) {
-		}
-	}
+     * @tests java.io.PipedWriter#write(int)
+     */
+    public void test_writeI() throws Exception {
+        // Test for method void java.io.PipedWriter.write(int)
+
+        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);
+        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);
+    }
+
+    /**
+     * Tears down the fixture, for example, close a network connection. This
+     * method is called after a test is executed.
+     */
+    protected void tearDown() throws Exception {
+        try {
+            if (rdrThread != null) {
+                rdrThread.interrupt();
+            }
+        } catch (Exception ignore) {}
+        try {
+            if (pw != null) {
+                pw.close();
+            }
+        } catch (Exception ignore) {}
+        super.tearDown();
+    }
 }



Mime
View raw message