tests/libjava-mauve/src/gnu/testlet/java/io/DataOutputStream/writeUTF.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 // Tags: JDK1.0
       
     2 
       
     3 // Copyright (C) 2002 Free Software Foundation, Inc.
       
     4 // Written by Mark Wielaard
       
     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 package gnu.testlet.java.io.DataOutputStream;
       
    24 
       
    25 import gnu.testlet.Testlet;
       
    26 import gnu.testlet.TestHarness;
       
    27 
       
    28 import java.io.*;
       
    29 
       
    30 public class writeUTF implements Testlet
       
    31 {
       
    32   TestHarness harness;
       
    33 
       
    34   public void test (TestHarness harness)
       
    35   {
       
    36     this.harness = harness;
       
    37    
       
    38     try
       
    39       {
       
    40 	ByteArrayOutputStream baos = new ByteArrayOutputStream();
       
    41 	DataOutputStream dos = new DataOutputStream(baos);
       
    42 	dos.writeUTF("\u0000"
       
    43 		     + "\u0001\u0002\u007e\u007f"
       
    44 		     + "\u0080\u0081\u07fe\u07ff"
       
    45 		     + "\u0800\u0801\ufffe\uffff");
       
    46 	dos.close();
       
    47 	byte[] bs = baos.toByteArray();
       
    48 	byte[] encoded = {(byte)0x00, (byte)0x1a, // size (26)
       
    49 			  (byte)0xc0, (byte)0x80, // \u0000
       
    50 			  (byte)0x01, // \u0001
       
    51 			  (byte)0x02, // \u0002
       
    52 			  (byte)0x7e, // \u007e
       
    53 			  (byte)0x7f, // \u007f
       
    54 			  (byte)0xc2, (byte)0x80, // \u0080
       
    55 			  (byte)0xc2, (byte)0x81, // \u0081
       
    56 			  (byte)0xdf, (byte)0xbe, // \u07fe
       
    57 			  (byte)0xdf, (byte)0xbf, // \u07ff
       
    58 			  (byte)0xe0, (byte)0xa0, (byte)0x80,  // \u0800
       
    59 			  (byte)0xe0, (byte)0xa0, (byte)0x81,  // \u0801
       
    60 			  (byte)0xef, (byte)0xbf, (byte)0xbe,  // \ufffe
       
    61 			  (byte)0xef, (byte)0xbf, (byte)0xbf}; // \uffff
       
    62 	checkArrayEquals(bs, encoded);
       
    63       }
       
    64     catch (IOException ioe)
       
    65       {
       
    66 	harness.fail("Unexpected IOException: " + ioe);
       
    67       }
       
    68   }
       
    69   
       
    70   private void checkArrayEquals(byte[] b1, byte[] b2)
       
    71   {
       
    72     int length = b1.length;
       
    73     if (length != b2.length)
       
    74       {
       
    75 	harness.debug("b1.length=" + length
       
    76 		      + ", but b2.length=" + b2.length);
       
    77 	harness.fail("arrays same");
       
    78 	return;
       
    79       }
       
    80 
       
    81     for (int i = 0; i < length; i++)
       
    82       if (b1[i] != b2[i])
       
    83 	{
       
    84 	  harness.debug("b1[" + i + "] = " + b1[i]
       
    85 			+ ", but b2[" + i + "] = " + b2[i]);
       
    86 	  harness.fail("arrays not equal");
       
    87 	  return;
       
    88 	}
       
    89 
       
    90     harness.check(true, "arrays same");
       
    91   }
       
    92 }