1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/*************************************************************************
/* Test.java -- Tests PrintWriter
/*
/* Copyright (c) 1998, 2003 Free Software Foundation, Inc.
/* Written by Daryl Lee (dolee@sources.redhat.com)
/*
/* This program is free software; you can redistribute it and/or modify
/* it under the terms of the GNU General Public License as published
/* by the Free Software Foundation, either version 2 of the License, or
/* (at your option) any later version.
/*
/* This program is distributed in the hope that it will be useful, but
/* WITHOUT ANY WARRANTY; without even the implied warranty of
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/* GNU General Public License for more details.
/*
/* You should have received a copy of the GNU General Public License
/* along with this program; if not, write to the Free Software Foundation
/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
/*************************************************************************/
// Tags: JDK1.1
package gnu.testlet.java.io.PrintWriter;
import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;
import java.io.PrintWriter;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.CharArrayWriter;
public class jdk11 extends PrintWriter implements Testlet
{
public jdk11()
{
this(new ByteArrayOutputStream());
}
jdk11(OutputStream os)
{
super(os);
}
public void print(int i, boolean err)
{
if (err)
{
this.setError();
}
}
public String toString()
{
return ("ObjectString");
}
public void
test(TestHarness harness)
{
// Test constructors first
ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
PrintWriter pw1 = new PrintWriter(baos1);
harness.check(pw1 != null, "PrintWriter(OutputStream)");
ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
PrintWriter pw2 = new PrintWriter(baos2, true);
harness.check(pw2 != null, "PrintWriter(OutputStream, boolean)");
CharArrayWriter caw1 = new CharArrayWriter();
PrintWriter pw3 = new PrintWriter(caw1);
harness.check(pw3 != null, "PrintWriter(Writer)");
CharArrayWriter caw2 = new CharArrayWriter();
PrintWriter pw4 = new PrintWriter(caw2);
harness.check(pw4 != null, "PrintWriter(Writer)");
// Now test the methods
pw1.print(true);
pw1.print(false);
pw1.print('X');
char[] ca = {'A', 'B', 'C'};
pw1.print(ca);
double x = 3.14;
pw1.print(x);
float y = (float) 1.414;
pw1.print(y);
int i = 37;
pw1.print(i);
long l = 65537L;
pw1.print(l);
pw1.print(new jdk11());
pw1.print("XYZ");
pw1.write(ca);
pw1.write(ca,0,2);
pw1.write('Q');
pw1.write("JKL");
pw1.write("MNOPQ", 1, 2);
pw1.println();
pw1.println(true);
pw1.println(false);
pw1.println('X');
pw1.println(ca);
pw1.println(x);
pw1.println(y);
pw1.println(i);
pw1.println(l);
pw1.println(new jdk11());
pw1.println("XYZ");
pw1.flush();
harness.check(true, "flush()");
pw1.close();
harness.check(true, "close()");
String tst = "truefalseXABC3.141.4143765537ObjectStringXYZABCABQJKLNO\n" +
"true\nfalse\nX\nABC\n3.14\n1.414\n37\n65537\nObjectString\nXYZ\n";
harness.check(baos1.toString(), tst, "All characters printed okay");
harness.debug("Final output:" + baos1.toString());
// Set up to test setError() and checkError()
ByteArrayOutputStream baos3 = new ByteArrayOutputStream();
jdk11 tpw = new jdk11(baos3);
harness.check(!tpw.checkError(), "checkError");
tpw.print(3, true); // forces call to setError
harness.check(tpw.checkError(), "setError");
// Check for (no) error after close
PrintWriter p = new PrintWriter(baos3);
p.close();
harness.check(!p.checkError(), "checkError() after close()");
}
} // class Test
|