tests/libjava-mauve/src/gnu/testlet/java/io/OutputStreamWriter/jdk11.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 // Test for OutputStreamWriter methods
       
     2 
       
     3 // Written by Daryl Lee (dol@sources.redhat.com)
       
     4 // Elaboration of except.java  by paul@dawa.demon.co.uk
       
     5 
       
     6 // This file is part of Mauve.
       
     7 
       
     8 // Mauve is free software; you can redistribute it and/or modify
       
     9 // it under the terms of the GNU General Public License as published by
       
    10 // the Free Software Foundation; either version 2, or (at your option)
       
    11 // any later version.
       
    12 
       
    13 // Mauve is distributed in the hope that it will be useful,
       
    14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16 // GNU General Public License for more details.
       
    17 
       
    18 // You should have received a copy of the GNU General Public License
       
    19 // along with Mauve; see the file COPYING.  If not, write to
       
    20 // the Free Software Foundation, 59 Temple Place - Suite 330,
       
    21 // Boston, MA 02111-1307, USA.
       
    22 
       
    23 // Tags: JDK1.1
       
    24 
       
    25 package gnu.testlet.java.io.OutputStreamWriter;
       
    26 
       
    27 import gnu.testlet.Testlet;
       
    28 import gnu.testlet.TestHarness;
       
    29 import java.io.OutputStreamWriter;
       
    30 import java.io.ByteArrayOutputStream;
       
    31 import java.io.IOException;
       
    32 
       
    33 public class jdk11 implements Testlet
       
    34 {
       
    35   public void test (TestHarness harness)
       
    36   {
       
    37     try
       
    38       {
       
    39 		String tstr = "ABCDEFGH";
       
    40 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
       
    41 		OutputStreamWriter osw = new OutputStreamWriter (baos);  //Default encoding
       
    42 		harness.check(true, "OutputStreamWriter(writer)");
       
    43 		harness.check(osw.getEncoding() != null,
       
    44 				"non-null getEncoding");
       
    45 
       
    46 		osw.write(tstr.charAt(0));					// 'A'
       
    47 		harness.check(true,"write(int)");
       
    48 		osw.write("ABCDE", 1, 3);					// 'ABCD'
       
    49 		harness.check(true,"write(string, off, len)");
       
    50 		char[] cbuf = new char[8];
       
    51 		tstr.getChars(4, 8, cbuf, 0);
       
    52 		osw.write(cbuf, 0, 4);						// 'ABCDEFGH'
       
    53 		harness.check(true,"write(char[], off, len)");
       
    54 		osw.flush();
       
    55 		harness.check(true, "flush()");
       
    56 		harness.check(baos.toString(), tstr, "Wrote all characters okay");	
       
    57 		osw.close ();
       
    58 		harness.check(osw.getEncoding(), null,
       
    59 				"null encoding after close");
       
    60 		ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
       
    61 		// ISO-8859-1 is a required encoding and this is the 
       
    62                 // "preferred" name, latin1 is a legal alias
       
    63                 // see also http://www.iana.org/assignments/character-sets
       
    64 		OutputStreamWriter osw2 = new OutputStreamWriter(baos2, "ISO-8859-1");
       
    65 		// Note that for java.io the canonical name as returned by
       
    66 		// getEncoding() must be the "historical" name. ISO8859_1.
       
    67 		harness.check(osw2.getEncoding(), "ISO8859_1", "OutputStreamWriter(writer, encoding)");
       
    68 		osw2.close ();
       
    69 		osw2 = new OutputStreamWriter(baos2, "latin1");
       
    70 		harness.check(osw2.getEncoding(), "ISO8859_1", "OutputStreamWriter(writer, encoding) // alias");
       
    71 		osw2.close ();
       
    72 
       
    73       }
       
    74     catch (IOException e)
       
    75       {
       
    76 		harness.check(false, "IOException unexpected");
       
    77       }
       
    78   }
       
    79 }