Initial load
diff --git a/test/java/io/PrintStream/CheckError.java b/test/java/io/PrintStream/CheckError.java
new file mode 100644
index 0000000..caa0809
--- /dev/null
+++ b/test/java/io/PrintStream/CheckError.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4213822
+ * @summary Test that checkError() returns a correct value
+ * when a PrintWriter is wrapped with another
+ * PrintWriter.
+ */
+
+import java.io.*;
+
+public class CheckError {
+
+ public static void main(String[] args) throws Exception {
+
+ File file = new File(System.getProperty("test.dir", "."),
+ "junkie.out");
+ file.deleteOnExit();
+
+ FileOutputStream fos = new FileOutputStream(file);
+ PrintStream pps = new PrintStream(
+ new PrintStream(fos));
+ boolean passTest1 = false;
+
+ fos.close();
+ pps.println("Hello World!");
+
+ if (pps.checkError()) {
+ System.out.println("Correct: An error occured in the" +
+ " underlying Stream");
+ passTest1 = true;
+ }
+ pps.close();
+
+ if (!passTest1) {
+ throw new Exception("CheckError() returned an incorrect value" +
+ " when the error has occured in the underlying Stream");
+ }
+ }
+}
diff --git a/test/java/io/PrintStream/ClearErrorStream.java b/test/java/io/PrintStream/ClearErrorStream.java
new file mode 100644
index 0000000..655bc75
--- /dev/null
+++ b/test/java/io/PrintStream/ClearErrorStream.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4491255
+ * @summary Test for a new protected method PrintStream.clearError()
+ * to reset the internal error state
+ */
+
+import java.io.*;
+
+public class ClearErrorStream extends PrintStream {
+
+ public ClearErrorStream(OutputStream out, boolean autoFlush) {
+ super(out, autoFlush);
+ }
+
+ public static void main(String[] args) throws Exception {
+
+ File f = new File(System.getProperty("test.dir", "."),
+ "print-stream.out");
+ f.deleteOnExit();
+
+ ClearErrorStream out = new ClearErrorStream(
+ new BufferedOutputStream(
+ new FileOutputStream(f)),
+ true);
+ out.println("Hello World!");
+ out.close();
+ out.println("Writing after close");
+
+ if (out.checkError()) {
+ System.out.println("An error occured");
+ out.clearError();
+
+ if (!out.checkError()) {
+ System.out.println("Error status cleared");
+ } else {
+ throw new Exception("Error Status unchanged");
+ }
+ }
+ else {
+ System.out.println(" No error occured");
+ }
+ }
+}
diff --git a/test/java/io/PrintStream/EncodingConstructor.java b/test/java/io/PrintStream/EncodingConstructor.java
new file mode 100644
index 0000000..fab64a6
--- /dev/null
+++ b/test/java/io/PrintStream/EncodingConstructor.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2000 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 4378278
+ * @summary java.io.PrintStream(..., String encoding) constructor
+ */
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+
+public class EncodingConstructor {
+
+ public static void main(String args[]) throws Exception {
+ ByteArrayOutputStream bo = new ByteArrayOutputStream();
+ PrintStream ps = new PrintStream(bo, false, "UTF-8");
+ String s = "xyzzy";
+ int n = s.length();
+ ps.print(s);
+ ps.close();
+ byte[] ba = bo.toByteArray();
+ if (ba.length != n)
+ throw new Exception("Length mismatch: " + n + " " + ba.length);
+ for (int i = 0; i < n; i++) {
+ if (ba[i] != (byte)s.charAt(i))
+ throw new Exception("Content mismatch: "
+ + i + " "
+ + Integer.toString(ba[i]) + " "
+ + Integer.toString(s.charAt(i)));
+ }
+ }
+
+}
diff --git a/test/java/io/PrintStream/NullConstructor.java b/test/java/io/PrintStream/NullConstructor.java
new file mode 100644
index 0000000..ec31b29
--- /dev/null
+++ b/test/java/io/PrintStream/NullConstructor.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 1998-2003 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ @bug 1265548
+ @summary PrintStream should not accept a null output stream in its
+ constructor
+*/
+
+import java.io.*;
+
+public class NullConstructor {
+
+ public static void main(String args[]) throws Exception {
+ try {
+ PrintStream ps = new PrintStream((OutputStream) null);
+ } catch (Exception e) {
+ return;
+ }
+ throw new Exception("PrintStream does not catch null constructor");
+ }
+}
diff --git a/test/java/io/PrintStream/OversynchronizedTest.java b/test/java/io/PrintStream/OversynchronizedTest.java
new file mode 100644
index 0000000..f7d0b3d
--- /dev/null
+++ b/test/java/io/PrintStream/OversynchronizedTest.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ @bug 4905777
+ @summary PrintStream.println(Object) oversynchronized, can deadlock
+*/
+
+import java.io.PrintStream;
+
+public class OversynchronizedTest extends Thread {
+ private static TestObj testObj = new TestObj("This is a test.");
+ private static int loopNum = 100;
+
+ public void run() {
+ for(int i=0; i<loopNum; i++) {
+ testObj.test();
+
+ //passing an object to System.out.println might cause deadlock
+ //if the object has a synchronized toString() method.
+ //using System.out.println(testObj.toString()) won't have a problem
+ System.out.println(testObj);
+ }
+ }
+
+ public static void main(String args[]) throws Exception {
+ // should no NullPointerException
+ System.out.println((Object)null);
+
+ // over synch test
+ int num = 5;
+
+ OversynchronizedTest[] t = new OversynchronizedTest[num];
+ for(int i=0; i<num; i++) {
+ t[i] = new OversynchronizedTest();
+ t[i].start();
+ }
+
+ for(int i=0; i <num; i++) {
+ t[i].join();
+ }
+
+ System.out.println("Test completed.");
+ }
+}
+
+class TestObj {
+ String mStr;
+
+ TestObj(String str) {
+ mStr = str;
+ }
+
+ synchronized void test() {
+ try {
+ long t = Math.round(Math.random()*10);
+ Thread.currentThread().sleep(t);
+ } catch (InterruptedException e) {
+ // jtreg timeout?
+ // Only jtreg will interrupt this thread so it knows what to do:
+ e.printStackTrace();
+ }
+
+ //the following line might cause hang if there is System.out.println(testObj)
+ //called by other threads.
+ System.out.println("In test().");
+ }
+
+ synchronized public String toString() {
+ System.out.println("Calling toString\n");
+ return mStr;
+ }
+}