Add Java 6's PrintStream.clearError/PrintWriter.clearError methods.
Also bring back the latest harmony java6 branch tests.
Bug: 2497395
Change-Id: I242e9a7d0446b46faaa5b28e0348806e999d8fdf
diff --git a/luni/src/main/java/java/io/PrintStream.java b/luni/src/main/java/java/io/PrintStream.java
index 0f30147..a69deab 100644
--- a/luni/src/main/java/java/io/PrintStream.java
+++ b/luni/src/main/java/java/io/PrintStream.java
@@ -242,6 +242,15 @@
}
/**
+ * Sets the error state of the stream to false.
+ * @since 1.6
+ * @hide
+ */
+ protected void clearError() {
+ ioError = false;
+ }
+
+ /**
* Closes this print stream. Flushes this stream and then closes the target
* stream. If an I/O error occurs, this stream's error state is set to
* {@code true}.
@@ -643,7 +652,7 @@
}
/**
- * Sets the error flag of this print stream to {@code true}.
+ * Sets the error flag of this print stream to true.
*/
protected void setError() {
ioError = true;
diff --git a/luni/src/main/java/java/io/PrintWriter.java b/luni/src/main/java/java/io/PrintWriter.java
index 3b6bb9c..49a219d 100644
--- a/luni/src/main/java/java/io/PrintWriter.java
+++ b/luni/src/main/java/java/io/PrintWriter.java
@@ -249,6 +249,17 @@
}
/**
+ * Sets the error state of the stream to false.
+ * @since 1.6
+ * @hide
+ */
+ protected void clearError() {
+ synchronized (lock) {
+ ioError = false;
+ }
+ }
+
+ /**
* Closes this print writer. Flushes this writer and then closes the target.
* If an I/O error occurs, this writer's error flag is set to {@code true}.
*/
@@ -635,7 +646,7 @@
}
/**
- * Sets the error flag of this writer to {@code true}.
+ * Sets the error flag of this writer to true.
*/
protected void setError() {
synchronized (lock) {
diff --git a/luni/src/test/java/tests/api/java/io/PrintStreamTest.java b/luni/src/test/java/tests/api/java/io/PrintStreamTest.java
index fed1aed..f8f885b 100644
--- a/luni/src/test/java/tests/api/java/io/PrintStreamTest.java
+++ b/luni/src/test/java/tests/api/java/io/PrintStreamTest.java
@@ -19,6 +19,7 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.InputStreamReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileNotFoundException;
@@ -26,255 +27,99 @@
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
-import java.util.IllegalFormatException;
import java.util.Locale;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import tests.support.Support_Locale;
-
-@TestTargetClass(PrintStream.class)
public class PrintStreamTest extends junit.framework.TestCase {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] ibuf = new byte[4096];
private File testFile = null;
+
private String testFilePath = null;
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_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";
private static class MockPrintStream extends PrintStream {
- public MockPrintStream(String fileName) throws FileNotFoundException {
- super(fileName);
- }
-
- public MockPrintStream(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException {
- super(fileName, csn);
- }
-
- public MockPrintStream(OutputStream os) {
- super(os);
- }
+ public MockPrintStream(String fileName) throws FileNotFoundException {
+ super(fileName);
+ }
+
+ public MockPrintStream(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException {
+ super(fileName, csn);
+ }
+
+ public MockPrintStream(OutputStream os) {
+ super(os);
+ }
@Override
- public void setError() {
- super.setError();
+ public void clearError() {
+ super.clearError();
}
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PrintStream",
- args = {java.io.File.class}
- )
- public void test_Constructor_Ljava_io_File() throws IOException {
- PrintStream tobj;
-
- tobj = new PrintStream(testFile);
- assertNotNull(tobj);
- tobj.write(1);
- tobj.close();
- assertEquals("output file has wrong length", 1, testFile.length());
- tobj = new PrintStream(testFile);
- assertNotNull(tobj);
- tobj.close();
- assertEquals("output file should be empty", 0, testFile.length());
-
- File file = new File("/invalidDirectory/Dummy");
- try {
- tobj = new PrintStream(file);
- fail("FileNotFoundException not thrown.");
- } catch (FileNotFoundException e) {
- // expected
- }
+
+ @Override
+ public void setError() {
+ super.setError();
+ }
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PrintStream",
- args = {java.io.File.class, java.lang.String.class}
- )
- public void test_Constructor_Ljava_io_File_Ljava_lang_String() throws Exception {
- PrintStream tobj;
-
- tobj = new PrintStream(testFile, "utf-8");
- assertNotNull(tobj);
- tobj.write(1);
- tobj.close();
- assertEquals("output file has wrong length", 1, testFile.length());
- tobj = new PrintStream(testFile, "utf-8");
- assertNotNull(tobj);
- tobj.close();
- assertEquals("output file should be empty", 0, testFile.length());
-
- File file = new File("/invalidDirectory/Dummy");
- try {
- tobj = new PrintStream(file, "utf-8");
- fail("FileNotFoundException not thrown.");
- } catch (FileNotFoundException e) {
- // expected
- }
-
- try {
- tobj = new PrintStream(testFile, "invalidEncoding");
- fail("UnsupportedEncodingException not thrown.");
- } catch (UnsupportedEncodingException e) {
- // expected
- }
- }
-
/**
* @tests {@link java.io.PrintStream#PrintStream(String)}
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PrintStream",
- args = {java.lang.String.class}
- )
public void test_Constructor_Ljava_lang_String() throws IOException {
- PrintStream tobj;
-
- tobj = new PrintStream(testFilePath);
- assertNotNull(tobj);
- tobj.write(1);
- tobj.close();
- assertEquals("output file has wrong length", 1, testFile.length());
- tobj = new PrintStream(testFilePath);
- assertNotNull(tobj);
- tobj.close();
- assertEquals("output file should be empty", 0, testFile.length());
-
- try {
- tobj = new PrintStream("/invalidDirectory/Dummy");
- fail("FileNotFoundException not thrown.");
- } catch (FileNotFoundException e) {
- // expected
- }
- }
+ MockPrintStream os = new MockPrintStream(testFilePath);
+ assertNotNull(os);
+ os.close();
+ }
/**
* @tests {@link java.io.PrintStream#PrintStream(String, String)}
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PrintStream",
- args = {java.lang.String.class, java.lang.String.class}
- )
public void test_Constructor_Ljava_lang_String_Ljava_lang_String() throws Exception {
- PrintStream tobj;
-
- tobj = new PrintStream(testFilePath, "utf-8");
- assertNotNull(tobj);
- tobj.write(1);
- tobj.close();
- assertEquals("output file has wrong length", 1, testFile.length());
- tobj = new PrintStream(testFilePath, "utf-8");
- assertNotNull(tobj);
- tobj.close();
- assertEquals("output file should be empty", 0, testFile.length());
-
- try {
- tobj = new PrintStream("/invalidDirectory/", "utf-8");
- fail("FileNotFoundException not thrown.");
- } catch (FileNotFoundException e) {
- // expected
- }
-
- try {
- tobj = new PrintStream(testFilePath, "invalidEncoding");
- fail("UnsupportedEncodingException not thrown.");
- } catch (UnsupportedEncodingException e) {
- // expected
- }
+ MockPrintStream os = new MockPrintStream(testFilePath, "utf-8");
+ assertNotNull(os);
+ os.close();
}
/**
* @tests java.io.PrintStream#PrintStream(java.io.OutputStream)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PrintStream",
- args = {java.io.OutputStream.class}
- )
public void test_ConstructorLjava_io_OutputStream() throws Exception {
// Test for method java.io.PrintStream(java.io.OutputStream)
- PrintStream os = new PrintStream(baos);
+ PrintStream os = new PrintStream(bos);
os.print(2345.76834720202);
os.close();
// regression for HARMONY-1195
try {
- os = new PrintStream(baos, true, null);
+ os = new PrintStream(bos, true, null);
fail("Should throw NPE");
} catch (NullPointerException e) {}
}
/**
- * @throws FileNotFoundException
* @tests java.io.PrintStream#PrintStream(java.io.OutputStream, boolean)
*/
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Passing FALSE for autoFlush not tested.",
- method = "PrintStream",
- args = {java.io.OutputStream.class, boolean.class}
- )
- public void test_ConstructorLjava_io_OutputStreamZ() throws FileNotFoundException {
- PrintStream tobj;
-
- tobj = new PrintStream(baos, true);
- tobj.println(2345.76834720202);
- assertTrue("Bytes not written", baos.size() > 0);
- tobj.close();
-
-// tobj = new PrintStream(bos, false);
-// tobj.println(2345.76834720202);
-// assertEquals("Bytes should not be written, yet", 0, bos.size());
-// tobj.flush();
-// assertTrue("Bytes not written", bos.size() > 0);
-// tobj.close();
-
-// FileOutputStream fos = new FileOutputStream(testFile);
-//
-// tobj = new PrintStream(fos, true);
-// tobj.println(2345.76834720202);
-// assertTrue("Bytes not written", testFile.length() > 0);
-// tobj.close();
-//
-// tobj = new PrintStream(fos, false);
-// tobj.println(2345.76834720202);
-// assertTrue("Bytes not written", testFile.length() > 0);
-// tobj.close();
-//
+ public void test_ConstructorLjava_io_OutputStreamZ() {
+ // Test for method java.io.PrintStream(java.io.OutputStream, boolean)
+ PrintStream os = new PrintStream(bos);
+ os.println(2345.76834720202);
+ os.flush();
+ assertTrue("Bytes not written", bos.size() > 0);
+ os.close();
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PrintStream",
- args = {java.io.OutputStream.class, boolean.class, java.lang.String.class}
- )
- public void test_ConstructorLjava_io_OutputStream_Z_Ljava_lang_String() {
- PrintStream tobj;
-
- tobj = new PrintStream(baos, true);
- tobj.println(2345.76834720202);
- assertTrue("Bytes not written", baos.size() > 0);
- tobj.close();
-
+ /**
+ * @tests java.io.PrintStream#PrintStream(java.io.OutputStream, boolean, String)
+ */
+ public void test_ConstructorLjava_io_OutputStreamZLjava_lang_String() {
try {
- tobj = new PrintStream(baos, true, "invalidEncoding");
- fail("UnsupportedEncodingException not thrown.");
+ new PrintStream(new ByteArrayOutputStream(), false,
+ "%Illegal_name!");
+ fail("Expected UnsupportedEncodingException");
} catch (UnsupportedEncodingException e) {
// expected
}
@@ -283,12 +128,6 @@
/**
* @tests java.io.PrintStream#checkError()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "checkError",
- args = {}
- )
public void test_checkError() throws Exception {
// Test for method boolean java.io.PrintStream.checkError()
PrintStream os = new PrintStream(new OutputStream() {
@@ -307,77 +146,57 @@
}
/**
- * @tests java.io.PrintStream#setError()
+ * @tests {@link java.io.PrintStream#clearError()}
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setError",
- args = {}
- )
- public void test_setError() throws Exception {
- MockPrintStream os = new MockPrintStream(new ByteArrayOutputStream());
- assertFalse("Test 1: Error flag should not be set.", os.checkError());
+ public void test_clearError() throws FileNotFoundException {
+ MockPrintStream os = new MockPrintStream(testFilePath);
+ assertFalse(os.checkError());
os.setError();
- assertTrue("Test 2: Error flag should be set.", os.checkError());
+ assertTrue(os.checkError());
+ os.clearError();
+ assertFalse(os.checkError());
+ os.close();
}
/**
* @tests java.io.PrintStream#close()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "close",
- args = {}
- )
public void test_close() throws Exception {
// Test for method void java.io.PrintStream.close()
- PrintStream os = new PrintStream(baos);
+ PrintStream os = new PrintStream(bos);
os.close();
- baos.close();
+ bos.close();
}
/**
* @tests java.io.PrintStream#flush()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "flush",
- args = {}
- )
public void test_flush() throws Exception {
// Test for method void java.io.PrintStream.flush()
- PrintStream os = new PrintStream(baos);
+ PrintStream os = new PrintStream(bos);
os.print(fileString.substring(0, 501));
os.flush();
- assertEquals("Bytes not written after flush", 501, baos.size());
- baos.close();
+ assertEquals("Bytes not written after flush", 501, bos.size());
+ bos.close();
os.close();
}
/**
* @tests java.io.PrintStream#print(char[])
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "print",
- args = {char[].class}
- )
public void test_print$C() {
// Test for method void java.io.PrintStream.print(char [])
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
try {
os.print((char[]) null);
fail("NPE expected");
} catch (NullPointerException ok) {}
- os = new PrintStream(baos, true);
+ os = new PrintStream(bos, true);
char[] sc = new char[4000];
fileString.getChars(0, fileString.length(), sc, 0);
os.print(sc);
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
os.close();
byte[] rbytes = new byte[4000];
@@ -389,35 +208,24 @@
/**
* @tests java.io.PrintStream#print(char)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "print",
- args = {char.class}
- )
- public void test_printC() {
+ public void test_printC() throws Exception {
// Test for method void java.io.PrintStream.print(char)
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
os.print('t');
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
- assertEquals("Incorrect char written", 't', bis.read());
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ InputStreamReader isr = new InputStreamReader(bis);
+ assertEquals("Incorrect char written", 't', isr.read());
}
/**
* @tests java.io.PrintStream#print(double)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "print",
- args = {double.class}
- )
public void test_printD() {
// Test for method void java.io.PrintStream.print(double)
byte[] rbuf = new byte[100];
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
os.print(2345.76834720202);
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
bis.read(rbuf, 0, 16);
assertEquals("Incorrect double written", "2345.76834720202",
new String(rbuf, 0, 16));
@@ -426,19 +234,13 @@
/**
* @tests java.io.PrintStream#print(float)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "print",
- args = {float.class}
- )
public void test_printF() {
// Test for method void java.io.PrintStream.print(float)
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
byte rbuf[] = new byte[10];
os.print(29.08764f);
os.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
bis.read(rbuf, 0, 8);
assertEquals("Incorrect float written", "29.08764", new String(rbuf, 0,
8));
@@ -448,18 +250,12 @@
/**
* @tests java.io.PrintStream#print(int)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "print",
- args = {int.class}
- )
public void test_printI() {
// Test for method void java.io.PrintStream.print(int)
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
os.print(768347202);
byte[] rbuf = new byte[18];
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
bis.read(rbuf, 0, 9);
assertEquals("Incorrect int written", "768347202", new String(rbuf, 0,
9));
@@ -468,19 +264,13 @@
/**
* @tests java.io.PrintStream#print(long)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "print",
- args = {long.class}
- )
public void test_printJ() {
// Test for method void java.io.PrintStream.print(long)
byte[] rbuf = new byte[100];
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
os.print(9875645283333L);
os.close();
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
bis.read(rbuf, 0, 13);
assertEquals("Incorrect long written", "9875645283333", new String(
rbuf, 0, 13));
@@ -489,25 +279,19 @@
/**
* @tests java.io.PrintStream#print(java.lang.Object)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "print",
- args = {java.lang.Object.class}
- )
public void test_printLjava_lang_Object() throws Exception {
// Test for method void java.io.PrintStream.print(java.lang.Object)
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
os.print((Object) null);
os.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
byte[] nullbytes = new byte[4];
bis.read(nullbytes, 0, 4);
assertEquals("null should be written", "null", new String(nullbytes, 0,
4));
bis.close();
- baos.close();
+ bos.close();
os.close();
ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
@@ -522,24 +306,18 @@
/**
* @tests java.io.PrintStream#print(java.lang.String)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "print",
- args = {java.lang.String.class}
- )
public void test_printLjava_lang_String() throws Exception {
// Test for method void java.io.PrintStream.print(java.lang.String)
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
os.print((String) null);
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
byte[] nullbytes = new byte[4];
bis.read(nullbytes, 0, 4);
assertEquals("null should be written", "null", new String(nullbytes, 0,
4));
bis.close();
- baos.close();
+ bos.close();
os.close();
ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
@@ -555,17 +333,11 @@
/**
* @tests java.io.PrintStream#print(boolean)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "print",
- args = {boolean.class}
- )
public void test_printZ() throws Exception {
// Test for method void java.io.PrintStream.print(boolean)
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
os.print(true);
- DataInputStream dis = new DataInputStream(new ByteArrayInputStream(baos
+ DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bos
.toByteArray()));
assertTrue("Incorrect boolean written", dis.readBoolean());
@@ -574,38 +346,28 @@
/**
* @tests java.io.PrintStream#println()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {}
- )
- public void test_println() {
+ public void test_println() throws Exception {
// Test for method void java.io.PrintStream.println()
char c;
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
os.println("");
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
- assertTrue("Newline not written", (c = (char) bis.read()) == '\r'
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ InputStreamReader isr = new InputStreamReader(bis);
+ assertTrue("Newline not written", (c = (char) isr.read()) == '\r'
|| c == '\n');
}
/**
* @tests java.io.PrintStream#println(char[])
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {char[].class}
- )
- public void test_println$C() {
+ public void test_println$C() throws Exception {
// Test for method void java.io.PrintStream.println(char [])
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
char[] sc = new char[4000];
fileString.getChars(0, fileString.length(), sc, 0);
os.println(sc);
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ InputStreamReader isr = new InputStreamReader(bis);
byte[] rbytes = new byte[4000];
bis.read(rbytes, 0, fileString.length());
assertEquals("Incorrect char[] written", fileString, new String(rbytes,
@@ -618,7 +380,7 @@
// hit a new line.
int r;
boolean newline = false;
- while ((r = bis.read()) != -1) {
+ while ((r = isr.read()) != -1) {
if (r == '\r' || r == '\n')
newline = true;
}
@@ -628,244 +390,165 @@
/**
* @tests java.io.PrintStream#println(char)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {char.class}
- )
- public void test_printlnC() {
+ public void test_printlnC() throws Exception {
// Test for method void java.io.PrintStream.println(char)
int c;
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
os.println('t');
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
- assertEquals("Incorrect char written", 't', bis.read());
- assertTrue("Newline not written", (c = bis.read()) == '\r' || c == '\n');
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ InputStreamReader isr = new InputStreamReader(bis);
+ assertEquals("Incorrect char written", 't', isr.read());
+ assertTrue("Newline not written", (c = isr.read()) == '\r' || c == '\n');
}
/**
* @tests java.io.PrintStream#println(double)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {double.class}
- )
- public void test_printlnD() {
+ public void test_printlnD() throws Exception {
// Test for method void java.io.PrintStream.println(double)
int c;
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
os.println(2345.76834720202);
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ InputStreamReader isr = new InputStreamReader(bis);
byte[] rbuf = new byte[100];
bis.read(rbuf, 0, 16);
assertEquals("Incorrect double written", "2345.76834720202",
new String(rbuf, 0, 16));
- assertTrue("Newline not written", (c = bis.read()) == '\r' || c == '\n');
+ assertTrue("Newline not written", (c = isr.read()) == '\r' || c == '\n');
}
/**
* @tests java.io.PrintStream#println(float)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {float.class}
- )
- public void test_printlnF() {
+ public void test_printlnF() throws Exception {
// Test for method void java.io.PrintStream.println(float)
int c;
byte[] rbuf = new byte[100];
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
os.println(29.08764f);
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ InputStreamReader isr = new InputStreamReader(bis);
bis.read(rbuf, 0, 8);
assertEquals("Incorrect float written", "29.08764", new String(rbuf, 0,
8));
- assertTrue("Newline not written", (c = bis.read()) == '\r' || c == '\n');
+ assertTrue("Newline not written", (c = isr.read()) == '\r' || c == '\n');
}
/**
* @tests java.io.PrintStream#println(int)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {int.class}
- )
- public void test_printlnI() {
+ public void test_printlnI() throws Exception {
// Test for method void java.io.PrintStream.println(int)
int c;
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
os.println(768347202);
byte[] rbuf = new byte[100];
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ InputStreamReader isr = new InputStreamReader(bis);
bis.read(rbuf, 0, 9);
assertEquals("Incorrect int written", "768347202", new String(rbuf, 0,
9));
- assertTrue("Newline not written", (c = bis.read()) == '\r' || c == '\n');
+ assertTrue("Newline not written", (c = isr.read()) == '\r' || c == '\n');
}
/**
* @tests java.io.PrintStream#println(long)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {long.class}
- )
- public void test_printlnJ() {
+ public void test_printlnJ() throws Exception {
// Test for method void java.io.PrintStream.println(long)
int c;
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
os.println(9875645283333L);
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ InputStreamReader isr = new InputStreamReader(bis);
byte[] rbuf = new byte[100];
bis.read(rbuf, 0, 13);
assertEquals("Incorrect long written", "9875645283333", new String(
rbuf, 0, 13));
- assertTrue("Newline not written", (c = bis.read()) == '\r' || c == '\n');
+ assertTrue("Newline not written", (c = isr.read()) == '\r' || c == '\n');
}
/**
* @tests java.io.PrintStream#println(java.lang.Object)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {java.lang.Object.class}
- )
- public void test_printlnLjava_lang_Object() {
+ public void test_printlnLjava_lang_Object() throws Exception {
// Test for method void java.io.PrintStream.println(java.lang.Object)
char c;
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
os.println(new java.util.Vector());
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ InputStreamReader isr = new InputStreamReader(bis);
byte[] rbytes = new byte[2];
bis.read(rbytes, 0, 2);
assertEquals("Incorrect Vector written", "[]", new String(rbytes, 0, 2));
- assertTrue("Newline not written", (c = (char) bis.read()) == '\r'
+ assertTrue("Newline not written", (c = (char) isr.read()) == '\r'
|| c == '\n');
}
/**
* @tests java.io.PrintStream#println(java.lang.String)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {java.lang.String.class}
- )
- public void test_printlnLjava_lang_String() {
+ public void test_printlnLjava_lang_String() throws Exception {
// Test for method void java.io.PrintStream.println(java.lang.String)
char c;
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
os.println("Hello World");
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ InputStreamReader isr = new InputStreamReader(bis);
byte rbytes[] = new byte[100];
bis.read(rbytes, 0, 11);
assertEquals("Incorrect string written", "Hello World", new String(
rbytes, 0, 11));
- assertTrue("Newline not written", (c = (char) bis.read()) == '\r'
+ assertTrue("Newline not written", (c = (char) isr.read()) == '\r'
|| c == '\n');
}
/**
* @tests java.io.PrintStream#println(boolean)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {boolean.class}
- )
- public void test_printlnZ() {
+ public void test_printlnZ() throws Exception {
// Test for method void java.io.PrintStream.println(boolean)
int c;
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
os.println(true);
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ InputStreamReader isr = new InputStreamReader(bis);
byte[] rbuf = new byte[100];
bis.read(rbuf, 0, 4);
assertEquals("Incorrect boolean written", "true",
new String(rbuf, 0, 4));
- assertTrue("Newline not written", (c = bis.read()) == '\r' || c == '\n');
+ assertTrue("Newline not written", (c = isr.read()) == '\r' || c == '\n');
}
/**
* @tests java.io.PrintStream#write(byte[], int, int)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
public void test_write$BII() {
// Test for method void java.io.PrintStream.write(byte [], int, int)
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
os.write(fileString.getBytes(), 0, fileString.length());
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ ByteArrayInputStream bis = new 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));
-
- try {
- os.write(rbytes, -1, 1);
- fail("IndexOutOfBoundsException should have been thrown.");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- os.write(rbytes, 0, -1);
- fail("IndexOutOfBoundsException should have been thrown.");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- os.write(rbytes, 1, rbytes.length);
- fail("IndexOutOfBoundsException should have been thrown.");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
}
/**
* @tests java.io.PrintStream#write(int)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {int.class}
- )
public void test_writeI() {
// Test for method void java.io.PrintStream.write(int)
- PrintStream os = new PrintStream(baos, true);
+ PrintStream os = new PrintStream(bos, true);
os.write('t');
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
assertEquals("Incorrect char written", 't', bis.read());
}
/**
* @tests java.io.PrintStream#append(char)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {char.class}
- )
public void test_appendChar() throws IOException {
char testChar = ' ';
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -879,12 +562,6 @@
/**
* @tests java.io.PrintStream#append(CharSequence)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {java.lang.CharSequence.class}
- )
public void test_appendCharSequence() {
String testString = "My Test String";
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -898,12 +575,6 @@
/**
* @tests java.io.PrintStream#append(CharSequence, int, int)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {java.lang.CharSequence.class, int.class, int.class}
- )
public void test_appendCharSequenceIntInt() {
String testString = "My Test String";
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -911,269 +582,82 @@
printStream.append(testString, 1, 3);
printStream.flush();
assertEquals(testString.substring(1, 3), out.toString());
- try {
- printStream.append(testString, 4, 100);
- fail("IndexOutOfBoundsException not thrown");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- printStream.append(testString, 100, 1);
- fail("IndexOutOfBoundsException not thrown");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
printStream.close();
}
/**
* @tests java.io.PrintStream#format(java.lang.String, java.lang.Object...)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "format",
- args = {java.lang.String.class, java.lang.Object[].class}
- )
public void test_formatLjava_lang_String$Ljava_lang_Object() {
- PrintStream tobj;
-
- tobj = new PrintStream(baos, false);
- tobj.format("%s %s", "Hello", "World");
- tobj.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ PrintStream os = new PrintStream(bos, false);
+ os.format("%s %s", "Hello", "World");
+ os.flush();
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
byte[] rbytes = new byte[11];
bis.read(rbytes, 0, rbytes.length);
assertEquals("Wrote incorrect string", "Hello World",
new String(rbytes));
- baos.reset();
- tobj = new PrintStream(baos);
- tobj.format("%1$.3G, %1$.5f, 0%2$xx", 12345.678, 123456);
- tobj.flush();
- assertEquals("Wrong output!", "1.23E+04, 12345.67800, 01e240x", new String(baos.toByteArray()));
- tobj.close();
-
- baos.reset();
- tobj = new PrintStream(baos);
- try {
- tobj.format("%1$.3G, %1$x", 12345.678);
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
-
- try {
- tobj.format("%s %q", "Hello", "World");
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
-
- try {
- tobj.format("%s %s", "Hello");
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
}
/**
* @tests java.io.PrintStream#format(java.util.Locale, java.lang.String,
* java.lang.Object...)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "format",
- args = {java.util.Locale.class, java.lang.String.class, java.lang.Object[].class}
- )
public void test_formatLjava_util_Locale_Ljava_lang_String_$Ljava_lang_Object() {
- Locale[] requiredLocales = {Locale.US, Locale.GERMANY};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- PrintStream tobj;
-
- tobj = new PrintStream(baos, false);
- tobj.format(Locale.US, "%s %s", "Hello", "World");
- tobj.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ PrintStream os = new PrintStream(bos, false);
+ os.format(Locale.US, "%s %s", "Hello", "World");
+ os.flush();
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
byte[] rbytes = new byte[11];
bis.read(rbytes, 0, rbytes.length);
assertEquals("Wrote incorrect string", "Hello World",
new String(rbytes));
-
- baos.reset();
- tobj = new PrintStream(baos);
- tobj.format(Locale.GERMANY, "%1$.3G; %1$.5f; 0%2$xx", 12345.678, 123456);
- tobj.flush();
- assertEquals("Wrong output!", "1,23E+04; 12345,67800; 01e240x", new String(baos.toByteArray()));
- tobj.close();
-
- baos.reset();
- tobj = new PrintStream(baos);
- tobj.format(Locale.US, "%1$.3G, %1$.5f, 0%2$xx", 12345.678, 123456);
- tobj.flush();
- assertEquals("Wrong output!", "1.23E+04, 12345.67800, 01e240x", new String(baos.toByteArray()));
- tobj.close();
-
- baos.reset();
- tobj = new PrintStream(baos);
- try {
- tobj.format(Locale.US, "%1$.3G, %1$x", 12345.678);
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
-
- try {
- tobj.format(Locale.US, "%s %q", "Hello", "World");
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
-
- try {
- tobj.format(Locale.US, "%s %s", "Hello");
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
}
/**
* @tests java.io.PrintStream#printf(java.lang.String, java.lang.Object...)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "printf",
- args = {java.lang.String.class, java.lang.Object[].class}
- )
public void test_printfLjava_lang_String$Ljava_lang_Object() {
- PrintStream tobj;
-
- tobj = new PrintStream(baos, false);
- tobj.printf("%s %s", "Hello", "World");
- tobj.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ PrintStream os = new PrintStream(bos, false);
+ os.printf("%s %s", "Hello", "World");
+ os.flush();
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
byte[] rbytes = new byte[11];
bis.read(rbytes, 0, rbytes.length);
assertEquals("Wrote incorrect string", "Hello World",
new String(rbytes));
-
- baos.reset();
- tobj = new PrintStream(baos);
- tobj.printf("%1$.3G, %1$.5f, 0%2$xx", 12345.678, 123456);
- tobj.flush();
- assertEquals("Wrong output!", "1.23E+04, 12345.67800, 01e240x", new String(baos.toByteArray()));
- tobj.close();
-
- baos.reset();
- tobj = new PrintStream(baos);
- try {
- tobj.printf("%1$.3G, %1$x", 12345.678);
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
-
- try {
- tobj.printf("%s %q", "Hello", "World");
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
-
- try {
- tobj.printf("%s %s", "Hello");
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
}
/**
* @tests java.io.PrintStream#printf(java.util.Locale, java.lang.String,
* java.lang.Object...)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "printf",
- args = {java.util.Locale.class, java.lang.String.class, java.lang.Object[].class}
- )
public void test_printfLjava_util_Locale_Ljava_lang_String_$Ljava_lang_Object() {
- Locale[] requiredLocales = {Locale.US, Locale.GERMANY};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- PrintStream tobj;
-
- tobj = new PrintStream(baos, false);
- tobj.printf(Locale.US, "%s %s", "Hello", "World");
- tobj.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ PrintStream os = new PrintStream(bos, false);
+ os.printf(Locale.US, "%s %s", "Hello", "World");
+ os.flush();
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
byte[] rbytes = new byte[11];
bis.read(rbytes, 0, rbytes.length);
assertEquals("Wrote incorrect string", "Hello World",
new String(rbytes));
-
- baos.reset();
- tobj = new PrintStream(baos);
- tobj.printf(Locale.GERMANY, "%1$.3G; %1$.5f; 0%2$xx", 12345.678, 123456);
- tobj.flush();
- assertEquals("Wrong output!", "1,23E+04; 12345,67800; 01e240x", new String(baos.toByteArray()));
- tobj.close();
-
- baos.reset();
- tobj = new PrintStream(baos);
- tobj.printf(Locale.US, "%1$.3G, %1$.5f, 0%2$xx", 12345.678, 123456);
- tobj.flush();
- assertEquals("Wrong output!", "1.23E+04, 12345.67800, 01e240x", new String(baos.toByteArray()));
- tobj.close();
-
- baos.reset();
- tobj = new PrintStream(baos);
- try {
- tobj.printf(Locale.US, "%1$.3G, %1$x", 12345.678);
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
-
- try {
- tobj.printf(Locale.US, "%s %q", "Hello", "World");
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
-
- try {
- tobj.printf(Locale.US, "%s %s", "Hello");
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
}
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- testFile = File.createTempFile("test", null);
- testFilePath = testFile.getAbsolutePath();
- }
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ testFile = File.createTempFile("test", null);
+ testFilePath = testFile.getAbsolutePath();
+ }
- @Override
- protected void tearDown() throws Exception {
- testFile.delete();
- testFile = null;
- testFilePath = null;
- super.tearDown();
- }
+ @Override
+ protected void tearDown() throws Exception {
+ testFile.delete();
+ testFile = null;
+ testFilePath = null;
+ super.tearDown();
+ }
}
diff --git a/luni/src/test/java/tests/api/java/io/PrintWriterTest.java b/luni/src/test/java/tests/api/java/io/PrintWriterTest.java
index 59d83eb..0cf53a4 100644
--- a/luni/src/test/java/tests/api/java/io/PrintWriterTest.java
+++ b/luni/src/test/java/tests/api/java/io/PrintWriterTest.java
@@ -21,1287 +21,758 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
-import java.util.IllegalFormatException;
+import java.nio.charset.Charset;
import java.util.Locale;
-import tests.support.Support_Locale;
import tests.support.Support_StringReader;
import tests.support.Support_StringWriter;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-@TestTargetClass(PrintWriter.class)
public class PrintWriterTest extends junit.framework.TestCase {
- private static class MockPrintWriter extends PrintWriter {
+ static class Bogus {
+ public String toString() {
+ return "Bogus";
+ }
+ }
+
+ /**
+ * @since 1.6
+ */
+ static class MockPrintWriter extends PrintWriter {
- public MockPrintWriter(OutputStream os) {
- super(os);
+ public MockPrintWriter(OutputStream out, boolean autoflush) {
+ super(out, autoflush);
}
-
+
@Override
- public void setError() {
- super.setError();
+ public void clearError() {
+ super.clearError();
}
+
}
- static class Bogus {
- public String toString() {
- return "Bogus";
- }
- }
+ PrintWriter pw;
- private File testFile = null;
- private String testFilePath = null;
+ ByteArrayOutputStream bao;
- PrintWriter pw;
+ ByteArrayInputStream bai;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ BufferedReader br;
- ByteArrayInputStream bai;
+ /**
+ * @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());
+ }
+ }
- BufferedReader br;
+ /**
+ * @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.OutputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PrintWriter",
- args = {java.io.OutputStream.class}
- )
- public void test_ConstructorLjava_io_OutputStream() {
- // Test for method java.io.PrintWriter(java.io.OutputStream)
- String s;
- pw = new PrintWriter(baos);
- pw.println("Random Chars");
- pw.write("Hello World");
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(baos.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();
+ assertEquals("Failed to construct proper writer",
+ "Hello", sw.toString());
+ }
- /**
- * @tests java.io.PrintWriter#PrintWriter(java.io.OutputStream, boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PrintWriter",
- args = {java.io.OutputStream.class, boolean.class}
- )
- public void test_ConstructorLjava_io_OutputStreamZ() {
- // Test for method java.io.PrintWriter(java.io.OutputStream, boolean)
- String s;
- pw = new PrintWriter(baos, true);
- pw.println("Random Chars");
- pw.write("Hello World");
- try {
- br = new BufferedReader(new Support_StringReader(baos.toString()));
- s = br.readLine();
- assertTrue("Incorrect string written/read: " + s, s
- .equals("Random Chars"));
- pw.flush();
- br = new BufferedReader(new Support_StringReader(baos.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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PrintWriter",
- args = {java.io.Writer.class}
- )
- 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();
- assertEquals("Failed to construct proper writer",
- "Hello", sw.toString());
- }
-
- /**
- * @tests java.io.PrintWriter#PrintWriter(java.io.Writer, boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PrintWriter",
- args = {java.io.Writer.class, boolean.class}
- )
- 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
- assertEquals("Failed to construct proper writer",
- "Hello", sw.toString());
- }
+ /**
+ * @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
+ assertEquals("Failed to construct proper writer",
+ "Hello", sw.toString());
+ }
/**
* @tests java.io.PrintWriter#PrintWriter(java.io.File)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PrintWriter",
- args = {java.io.File.class}
- )
public void test_ConstructorLjava_io_File() throws Exception {
- PrintWriter tobj;
-
- tobj = new PrintWriter(testFile);
- tobj.write(1);
- tobj.close();
- assertEquals("output file has wrong length", 1, testFile.length());
- tobj = new PrintWriter(testFile);
- assertNotNull(tobj);
- tobj.close();
- assertEquals("output file should be empty", 0, testFile.length());
-
- File file = new File("/invalidDirectory/Dummy");
+ File file = File.createTempFile(getClass().getName(), null);
try {
- tobj = new PrintWriter(file);
- fail("FileNotFoundException not thrown.");
- } catch (FileNotFoundException e) {
- // expected
+ PrintWriter writer = new PrintWriter(file);
+ writer.close();
+ } finally {
+ file.delete();
}
}
/**
* @tests java.io.PrintWriter#PrintWriter(java.io.File, java.lang.String)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PrintWriter",
- args = {java.io.File.class, java.lang.String.class}
- )
public void test_ConstructorLjava_io_File_Ljava_lang_String() throws Exception {
- PrintWriter tobj;
-
- tobj = new PrintWriter(testFile, "utf-8");
- tobj.write(1);
- tobj.close();
- assertEquals("output file has wrong length", 1, testFile.length());
- tobj = new PrintWriter(testFile, "utf-8");
- assertNotNull(tobj);
- tobj.close();
- assertEquals("output file should be empty", 0, testFile.length());
-
- File file = new File("/invalidDirectory/Dummy");
+ File file = File.createTempFile(getClass().getName(), null);
try {
- tobj = new PrintWriter(file, "utf-8");
- fail("FileNotFoundException not thrown.");
- } catch (FileNotFoundException e) {
- // expected
- }
-
- try {
- tobj = new PrintWriter(testFile, "invalidEncoding");
- fail("UnsupportedEncodingException not thrown.");
- } catch (UnsupportedEncodingException e) {
- // expected
+ PrintWriter writer = new PrintWriter(file,
+ Charset.defaultCharset().name());
+ writer.close();
+ } finally {
+ file.delete();
}
}
/**
* @tests java.io.PrintWriter#PrintWriter(java.lang.String)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PrintWriter",
- args = {java.lang.String.class}
- )
public void test_ConstructorLjava_lang_String() throws Exception {
- PrintWriter tobj;
-
- tobj = new PrintWriter(testFilePath);
- assertNotNull(tobj);
- tobj.write(1);
- tobj.close();
- assertEquals("output file has wrong length", 1, testFile.length());
- tobj = new PrintWriter(testFilePath);
- assertNotNull(tobj);
- tobj.close();
- assertEquals("output file should be empty", 0, testFile.length());
-
+ File file = File.createTempFile(getClass().getName(), null);
try {
- tobj = new PrintWriter("/invalidDirectory/Dummy");
- fail("FileNotFoundException not thrown.");
- } catch (FileNotFoundException e) {
- // expected
+ PrintWriter writer = new PrintWriter(file.getPath());
+ writer.close();
+ } finally {
+ file.delete();
}
}
/**
* @tests java.io.PrintWriter#PrintWriter(java.lang.String, java.lang.String)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PrintWriter",
- args = {java.lang.String.class, java.lang.String.class}
- )
public void test_ConstructorLjava_lang_String_Ljava_lang_String() throws Exception {
- PrintWriter tobj;
-
- tobj = new PrintWriter(testFilePath, "utf-8");
- assertNotNull(tobj);
- tobj.write(1);
- tobj.close();
- assertEquals("output file has wrong length", 1, testFile.length());
- tobj = new PrintWriter(testFilePath, "utf-8");
- assertNotNull(tobj);
- tobj.close();
- assertEquals("output file should be empty", 0, testFile.length());
-
+ File file = File.createTempFile(getClass().getName(), null);
try {
- tobj = new PrintWriter("/invalidDirectory/", "utf-8");
- fail("FileNotFoundException not thrown.");
- } catch (FileNotFoundException e) {
- // expected
- }
-
- try {
- tobj = new PrintWriter(testFilePath, "invalidEncoding");
- fail("UnsupportedEncodingException not thrown.");
- } catch (UnsupportedEncodingException e) {
- // expected
+ PrintWriter writer = new PrintWriter(file.getPath(),
+ Charset.defaultCharset().name());
+ writer.close();
+ } finally {
+ file.delete();
}
}
- /**
- * @tests java.io.PrintWriter#checkError()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "checkError",
- args = {}
- )
- 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#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.PrintStream#setError()
+ * @tests java.io.PrintWriter#clearError()
+ * @since 1.6
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setError",
- args = {}
- )
- public void test_setError() throws Exception {
- MockPrintWriter os = new MockPrintWriter(new ByteArrayOutputStream());
- assertFalse("Test 1: Error flag should not be set.", os.checkError());
- os.setError();
- assertTrue("Test 2: Error flag should be set.", os.checkError());
+ public void test_clearError() {
+ // Test for method boolean java.io.PrintWriter.clearError()
+ MockPrintWriter mpw = new MockPrintWriter(new ByteArrayOutputStream(), false);
+ mpw.close();
+ mpw.print(490000000000.08765);
+ assertTrue("Failed to return error", mpw.checkError());
+ mpw.clearError();
+ assertFalse("Internal error state has not be cleared", mpw.checkError());
}
- /**
- * @tests java.io.PrintWriter#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "close",
- args = {}
- )
- 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#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()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "flush",
- args = {}
- )
- 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(baos.toByteArray())
- .equals(String.valueOf(dub)));
- }
+ /**
+ * @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[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "print",
- args = {char[].class}
- )
- 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(baos.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;
- }
- assertEquals("null pointer exception for printing null char[] is not caught",
- 1, r);
- }
+ /**
+ * @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;
+ }
+ assertEquals("null pointer exception for printing null char[] is not caught",
+ 1, r);
+ }
- /**
- * @tests java.io.PrintWriter#print(char)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "print",
- args = {char.class}
- )
- public void test_printC() {
- // Test for method void java.io.PrintWriter.print(char)
- pw.print('c');
- pw.flush();
- assertEquals("Wrote incorrect char string", "c", new String(baos.toByteArray())
- );
- }
+ /**
+ * @tests java.io.PrintWriter#print(char)
+ */
+ public void test_printC() {
+ // Test for method void java.io.PrintWriter.print(char)
+ pw.print('c');
+ pw.flush();
+ assertEquals("Wrote incorrect char string", "c", new String(bao.toByteArray())
+ );
+ }
- /**
- * @tests java.io.PrintWriter#print(double)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "print",
- args = {double.class}
- )
- 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(baos
- .toByteArray()).equals(String.valueOf(dub)));
- }
+ /**
+ * @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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "print",
- args = {float.class}
- )
- 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(baos.toByteArray()).equals(String.valueOf(flo)));
- }
+ /**
+ * @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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "print",
- args = {int.class}
- )
- public void test_printI() {
- // Test for method void java.io.PrintWriter.print(int)
- pw.print(4908765);
- pw.flush();
- assertEquals("Wrote incorrect int string", "4908765", new String(baos.toByteArray())
- );
- }
+ /**
+ * @tests java.io.PrintWriter#print(int)
+ */
+ public void test_printI() {
+ // Test for method void java.io.PrintWriter.print(int)
+ pw.print(4908765);
+ pw.flush();
+ assertEquals("Wrote incorrect int string", "4908765", new String(bao.toByteArray())
+ );
+ }
- /**
- * @tests java.io.PrintWriter#print(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "print",
- args = {long.class}
- )
- public void test_printJ() {
- // Test for method void java.io.PrintWriter.print(long)
- pw.print(49087650000L);
- pw.flush();
- assertEquals("Wrote incorrect long string", "49087650000", new String(baos.toByteArray())
- );
- }
+ /**
+ * @tests java.io.PrintWriter#print(long)
+ */
+ public void test_printJ() {
+ // Test for method void java.io.PrintWriter.print(long)
+ pw.print(49087650000L);
+ pw.flush();
+ assertEquals("Wrote incorrect long string", "49087650000", new String(bao.toByteArray())
+ );
+ }
- /**
- * @tests java.io.PrintWriter#print(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "print",
- args = {java.lang.Object.class}
- )
- public void test_printLjava_lang_Object() {
- // Test for method void java.io.PrintWriter.print(java.lang.Object)
- pw.print((Object) null);
- pw.flush();
- assertEquals("Did not write null", "null", new String(baos.toByteArray()));
- baos.reset();
+ /**
+ * @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();
+ assertEquals("Did not write null", "null", new String(bao.toByteArray())
+ );
+ bao.reset();
- pw.print(new Bogus());
- pw.flush();
- assertEquals("Wrote in incorrect Object string", "Bogus", new String(baos
- .toByteArray()));
- }
+ pw.print(new Bogus());
+ pw.flush();
+ assertEquals("Wrote in incorrect Object string", "Bogus", new String(bao
+ .toByteArray()));
+ }
- /**
- * @tests java.io.PrintWriter#print(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "print",
- args = {java.lang.String.class}
- )
- public void test_printLjava_lang_String() {
- // Test for method void java.io.PrintWriter.print(java.lang.String)
- pw.print((String) null);
- pw.flush();
- assertEquals("did not write null", "null", new String(baos.toByteArray()));
- baos.reset();
+ /**
+ * @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();
+ assertEquals("did not write null", "null", new String(bao.toByteArray())
+ );
+ bao.reset();
- pw.print("Hello World");
- pw.flush();
- assertEquals("Wrote incorrect string", "Hello World", new String(baos.toByteArray()));
- }
+ pw.print("Hello World");
+ pw.flush();
+ assertEquals("Wrote incorrect string", "Hello World", new String(bao.toByteArray())
+ );
+ }
- /**
- * @tests java.io.PrintWriter#print(boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "print",
- args = {boolean.class}
- )
- public void test_printZ() {
- // Test for method void java.io.PrintWriter.print(boolean)
- pw.print(true);
- pw.flush();
- assertEquals("Wrote in incorrect boolean string", "true", new String(baos
- .toByteArray()));
- }
+ /**
+ * @tests java.io.PrintWriter#print(boolean)
+ */
+ public void test_printZ() {
+ // Test for method void java.io.PrintWriter.print(boolean)
+ pw.print(true);
+ pw.flush();
+ assertEquals("Wrote in incorrect boolean string", "true", new String(bao
+ .toByteArray()));
+ }
- /**
- * @tests java.io.PrintWriter#println()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {}
- )
- 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(baos.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()
+ */
+ 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[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {char[].class}
- )
- 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(baos.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_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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {char.class}
- )
- 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(baos.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(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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {double.class}
- )
- 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(baos.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(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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {float.class}
- )
- 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(baos.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(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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {int.class}
- )
- 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(baos.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(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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {long.class}
- )
- 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(baos.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(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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {java.lang.Object.class}
- )
- 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(baos.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.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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {java.lang.String.class}
- )
- 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(baos.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(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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {boolean.class}
- )
- 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(baos.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#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[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class}
- )
- 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(baos.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[])
+ */
+ 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)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- 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(baos.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(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(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_write$CII_Exception() {
- // Test for method void java.io.PrintWriter.write(char [], int, int)
- char[] chars = new char[10];
- try {
- pw.write(chars, 0, -1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- pw.write(chars, -1, 1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- pw.write(chars, 10, 1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
+ /**
+ * @tests java.io.PrintWriter#write(int)
+ */
+ public void test_writeI() throws IOException {
+ // 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();
+ InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(bao.toByteArray()));
+ cab[0] = (char) isr.read();
+ cab[1] = (char) isr.read();
+ cab[2] = (char) isr.read();
+ assertTrue("Wrote incorrect ints", cab[0] == 'a' && cab[1] == 'b'
+ && cab[2] == 'c');
- /**
- * @tests java.io.PrintWriter#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {int.class}
- )
- 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(baos.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)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {java.lang.String.class}
- )
- 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(baos.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"));
+ }
+
+ /**
+ * @tests java.io.PrintWriter#append(char)
+ */
+ public void test_appendChar() {
+ char testChar = ' ';
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ PrintWriter printWriter = new PrintWriter(out);
+ printWriter.append(testChar);
+ printWriter.flush();
+ assertEquals(String.valueOf(testChar),out.toString());
+ printWriter.close();
+ }
+ /**
+ * @tests java.io.PrintWriter#append(CharSequence)
+ */
+ public void test_appendCharSequence() {
+
+ String testString = "My Test String";
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ PrintWriter printWriter = new PrintWriter(out);
+ printWriter.append(testString);
+ printWriter.flush();
+ assertEquals(testString, out.toString());
+ printWriter.close();
- /**
- * @tests java.io.PrintWriter#write(java.lang.String, int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {java.lang.String.class, int.class, int.class}
- )
- 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(baos.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#append(char)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {char.class}
- )
- public void test_appendChar() {
- char testChar = ' ';
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- PrintWriter printWriter = new PrintWriter(out);
- printWriter.append(testChar);
- printWriter.flush();
- assertEquals(String.valueOf(testChar),out.toString());
- printWriter.close();
- }
- /**
- * @tests java.io.PrintWriter#append(CharSequence)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {java.lang.CharSequence.class}
- )
- public void test_appendCharSequence() {
-
- String testString = "My Test String";
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- PrintWriter printWriter = new PrintWriter(out);
- printWriter.append(testString);
- printWriter.flush();
- assertEquals(testString, out.toString());
- printWriter.close();
+ }
- }
+ /**
+ * @tests java.io.PrintWriter#append(CharSequence, int, int)
+ */
+ public void test_appendCharSequenceIntInt() {
+ String testString = "My Test String";
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ PrintWriter printWriter = new PrintWriter(out);
+ printWriter.append(testString, 1, 3);
+ printWriter.flush();
+ assertEquals(testString.substring(1, 3), out.toString());
+ printWriter.close();
- /**
- * @tests java.io.PrintWriter#append(CharSequence, int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {java.lang.CharSequence.class, int.class, int.class}
- )
- public void test_appendCharSequenceIntInt() {
- String testString = "My Test String";
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- PrintWriter printWriter = new PrintWriter(out);
- printWriter.append(testString, 1, 3);
- printWriter.flush();
- assertEquals(testString.substring(1, 3), out.toString());
- try {
- printWriter.append(testString, 4, 100);
- fail("IndexOutOfBoundsException not thrown");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- printWriter.append(testString, 100, 1);
- fail("IndexOutOfBoundsException not thrown");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- printWriter.close();
- }
+ }
/**
* @tests java.io.PrintWriter#format(java.lang.String, java.lang.Object...)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "format",
- args = {java.lang.String.class, java.lang.Object[].class}
- )
public void test_formatLjava_lang_String$Ljava_lang_Object() {
- PrintWriter tobj;
-
- tobj = new PrintWriter(baos, false);
- tobj.format("%s %s", "Hello", "World");
- tobj.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
- byte[] rbytes = new byte[11];
- bis.read(rbytes, 0, rbytes.length);
- assertEquals("Wrote incorrect string", "Hello World",
- new String(rbytes));
-
- baos.reset();
- tobj = new PrintWriter(baos);
- tobj.format("%1$.3G, %1$.5f, 0%2$xx", 12345.678, 123456);
- tobj.flush();
- assertEquals("Wrong output!", "1.23E+04, 12345.67800, 01e240x", new String(baos.toByteArray()));
- tobj.close();
-
- baos.reset();
- tobj = new PrintWriter(baos);
- try {
- tobj.format("%1$.3G, %1$x", 12345.678);
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
-
- try {
- tobj.format("%s %q", "Hello", "World");
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
-
- try {
- tobj.format("%s %s", "Hello");
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
+ pw.format("%s %s", "Hello", "World");
+ pw.flush();
+ assertEquals("Wrote incorrect string", "Hello World",
+ new String(bao.toByteArray()));
}
/**
* @tests java.io.PrintWriter#format(java.util.Locale, java.lang.String, java.lang.Object...)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "format",
- args = {java.util.Locale.class, java.lang.String.class, java.lang.Object[].class}
- )
public void test_formatLjava_util_Locale_Ljava_lang_String_$Ljava_lang_Object() {
- Locale[] requiredLocales = {Locale.US, Locale.GERMANY};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- PrintWriter tobj;
-
- tobj = new PrintWriter(baos, false);
- tobj.format(Locale.US, "%s %s", "Hello", "World");
- tobj.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
- byte[] rbytes = new byte[11];
- bis.read(rbytes, 0, rbytes.length);
- assertEquals("Wrote incorrect string", "Hello World",
- new String(rbytes));
-
- baos.reset();
- tobj = new PrintWriter(baos);
- tobj.format(Locale.GERMANY, "%1$.3G; %1$.5f; 0%2$xx", 12345.678, 123456);
- tobj.flush();
- assertEquals("Wrong output!", "1,23E+04; 12345,67800; 01e240x", new String(baos.toByteArray()));
- tobj.close();
-
- baos.reset();
- tobj = new PrintWriter(baos);
- tobj.format(Locale.US, "%1$.3G, %1$.5f, 0%2$xx", 12345.678, 123456);
- tobj.flush();
- assertEquals("Wrong output!", "1.23E+04, 12345.67800, 01e240x", new String(baos.toByteArray()));
- tobj.close();
-
- baos.reset();
- tobj = new PrintWriter(baos);
- try {
- tobj.format(Locale.US, "%1$.3G, %1$x", 12345.678);
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
-
- try {
- tobj.format(Locale.US, "%s %q", "Hello", "World");
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
-
- try {
- tobj.format(Locale.US, "%s %s", "Hello");
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
+ pw.format(Locale.US, "%s %s", "Hello", "World");
+ pw.flush();
+ assertEquals("Wrote incorrect string", "Hello World",
+ new String(bao.toByteArray()));
}
/**
* @tests java.io.PrintWriter#printf(java.lang.String, java.lang.Object...)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "printf",
- args = {java.lang.String.class, java.lang.Object[].class}
- )
public void test_printfLjava_lang_String$Ljava_lang_Object() {
- PrintWriter tobj;
-
- tobj = new PrintWriter(baos, false);
- tobj.printf("%s %s", "Hello", "World");
- tobj.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
- byte[] rbytes = new byte[11];
- bis.read(rbytes, 0, rbytes.length);
- assertEquals("Wrote incorrect string", "Hello World",
- new String(rbytes));
-
- baos.reset();
- tobj = new PrintWriter(baos);
- tobj.printf("%1$.3G, %1$.5f, 0%2$xx", 12345.678, 123456);
- tobj.flush();
- assertEquals("Wrong output!", "1.23E+04, 12345.67800, 01e240x", new String(baos.toByteArray()));
- tobj.close();
-
- baos.reset();
- tobj = new PrintWriter(baos);
- try {
- tobj.printf("%1$.3G, %1$x", 12345.678);
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
-
- try {
- tobj.printf("%s %q", "Hello", "World");
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
-
- try {
- tobj.printf("%s %s", "Hello");
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
+ pw.printf("%s %s", "Hello", "World");
+ pw.flush();
+ assertEquals("Wrote incorrect string", "Hello World",
+ new String(bao.toByteArray()));
}
/**
* @tests java.io.PrintWriter#printf(java.util.Locale, java.lang.String, java.lang.Object...)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "printf",
- args = {java.util.Locale.class, java.lang.String.class, java.lang.Object[].class}
- )
public void test_printfLjava_util_Locale_Ljava_lang_String_$Ljava_lang_Object() {
- Locale[] requiredLocales = {Locale.US, Locale.GERMANY};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- PrintWriter tobj;
-
- tobj = new PrintWriter(baos, false);
- tobj.printf(Locale.US, "%s %s", "Hello", "World");
- tobj.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
- byte[] rbytes = new byte[11];
- bis.read(rbytes, 0, rbytes.length);
- assertEquals("Wrote incorrect string", "Hello World",
- new String(rbytes));
-
- baos.reset();
- tobj = new PrintWriter(baos);
- tobj.printf(Locale.GERMANY, "%1$.3G; %1$.5f; 0%2$xx", 12345.678, 123456);
- tobj.flush();
- assertEquals("Wrong output!", "1,23E+04; 12345,67800; 01e240x", new String(baos.toByteArray()));
- tobj.close();
-
- baos.reset();
- tobj = new PrintWriter(baos);
- tobj.printf(Locale.US, "%1$.3G, %1$.5f, 0%2$xx", 12345.678, 123456);
- tobj.flush();
- assertEquals("Wrong output!", "1.23E+04, 12345.67800, 01e240x", new String(baos.toByteArray()));
- tobj.close();
-
- baos.reset();
- tobj = new PrintWriter(baos);
- try {
- tobj.printf(Locale.US, "%1$.3G, %1$x", 12345.678);
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
-
- try {
- tobj.printf(Locale.US, "%s %q", "Hello", "World");
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
-
- try {
- tobj.printf(Locale.US, "%s %s", "Hello");
- fail("IllegalFormatException not thrown");
- } catch (IllegalFormatException e) {
- // expected
- }
+ pw.printf(Locale.US, "%s %s", "Hello", "World");
+ pw.flush();
+ assertEquals("Wrote incorrect string", "Hello World",
+ new String(bao.toByteArray()));
}
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- @Override
- protected void setUp() throws Exception {
- testFile = File.createTempFile("test", null);
- testFilePath = testFile.getAbsolutePath();
- pw = new PrintWriter(baos, false);
+ /**
+ * 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.
- */
- @Override
- protected void tearDown() throws Exception {
- testFile.delete();
- testFile = null;
- testFilePath = null;
- try {
- pw.close();
- } catch (Exception e) {
- }
- }
+ /**
+ * 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) {
+ }
+ }
}