OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [test/] [java.io/] [UTF8EncodingTest.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/*************************************************************************
2
/* UTF8EncodingTest.java -- A quick test of the UTF8 encoding
3
/*
4
/* Copyright (c) 1998 Free Software Foundation, Inc.
5
/* Written by Aaron M. Renn (arenn@urbanophile.com)
6
/*
7
/* This program is free software; you can redistribute it and/or modify
8
/* it under the terms of the GNU General Public License as published
9
/* by the Free Software Foundation, either version 2 of the License, or
10
/* (at your option) any later version.
11
/*
12
/* This program is distributed in the hope that it will be useful, but
13
/* WITHOUT ANY WARRANTY; without even the implied warranty of
14
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
/* GNU General Public License for more details.
16
/*
17
/* You should have received a copy of the GNU General Public License
18
/* along with this program; if not, write to the Free Software Foundation
19
/* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
20
/*************************************************************************/
21
 
22
import java.io.*;
23
 
24
public class UTF8EncodingTest
25
{
26
 
27
public static void main(String[] argv)
28
{
29
  System.out.println("Started test of UTF8 encoding handling");
30
 
31
  String str1 = "This is the first line of text\n";
32
  String str2 = "This has some \u01FF\uA000\u6666\u0200 weird characters\n";
33
 
34
  System.out.println("Test 1: Write test");
35
  try
36
    {
37
      FileOutputStream fos = new FileOutputStream("utf8test.out");
38
      OutputStreamWriter osr = new OutputStreamWriter(fos, "UTF8");
39
      osr.write(str1);
40
      osr.write(str2);
41
      osr.close();
42
 
43
      System.out.println("PASSED: Write test (conditionally)");
44
    }
45
  catch(IOException e)
46
    {
47
      System.out.println("FAILED: Write Test: " + e);
48
    }
49
 
50
  System.out.println("Test 2: Read JDK file test");
51
  try
52
    {
53
      FileInputStream fis = new FileInputStream("utf8test-jdk.out");
54
      InputStreamReader isr = new InputStreamReader(fis, "UTF8");
55
      char[] buf = new char[255];
56
 
57
      int chars_read = isr.read(buf, 0, str1.length());
58
      String str3 = new String(buf, 0, chars_read);
59
 
60
      chars_read = isr.read(buf, 0, str2.length());
61
      String str4 = new String(buf, 0, chars_read);
62
 
63
      if (!str1.equals(str3) || !str2.equals(str4))
64
        System.out.println("FAILED: Read JDK file test");
65
      else
66
        System.out.println("PASSED: Read JDK file test");
67
    }
68
  catch(IOException e)
69
    {
70
      System.out.println("FAILED: Read JDK file test: " + e);
71
    }
72
 
73
  System.out.println("Test 3: Read classpath file test");
74
  try
75
    {
76
      FileInputStream fis = new FileInputStream("utf8test.out");
77
      InputStreamReader isr = new InputStreamReader(fis, "UTF8");
78
      char[] buf = new char[255];
79
 
80
      int chars_read = isr.read(buf, 0, str1.length());
81
      String str3 = new String(buf, 0, chars_read);
82
 
83
      chars_read = isr.read(buf, 0, str2.length());
84
      String str4 = new String(buf, 0, chars_read);
85
 
86
      if (!str1.equals(str3) || !str2.equals(str4))
87
        System.out.println("FAILED: Read classpath file test");
88
      else
89
        System.out.println("PASSED: Read classpath file test");
90
    }
91
  catch(IOException e)
92
    {
93
      System.out.println("FAILED: Read classpath file test: " + e);
94
    }
95
 
96
  System.out.println("Finished test of UTF8 encoding handling");
97
}
98
 
99
} // class UTF8EncodingTest
100
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.