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/] [BufferedCharWriterTest.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/*************************************************************************
2
/* BufferedCharWriterTest.java -- Test {Buffered,CharArray}Writer
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
/**
25
  * Class to test BufferedWriter and CharArrayWriter
26
  *
27
  * @version 0.0
28
  *
29
  * @author Aaron M. Renn (arenn@urbanophile.com)
30
  */
31
public class BufferedCharWriterTest
32
{
33
 
34
public static void
35
main(String argv[])
36
{
37
  System.out.println("Started test of BufferedWriter and CharArrayWriter");
38
 
39
  try
40
    {
41
      System.out.println("Test 1: Write Tests");
42
 
43
      CharArrayWriter caw = new CharArrayWriter(24);
44
      BufferedWriter bw = new BufferedWriter(caw, 12);
45
 
46
      String str = "I used to live right behind this super-cool bar in\n" +
47
        "Chicago called Lounge Ax.  They have the best music of pretty\n" +
48
        "much anyplace in town with a great atmosphere and $1 Huber\n" +
49
        "on tap.  I go to tons of shows there, even though I moved.\n";
50
 
51
      boolean passed = true;
52
 
53
      char[] buf = new char[str.length()];
54
      str.getChars(0, str.length(), buf, 0);
55
 
56
      bw.write(buf, 0, 5);
57
      if (caw.toCharArray().length != 0)
58
        {
59
          passed = false;
60
          System.out.println("CharArrayWriter has too many bytes #1");
61
        }
62
      bw.write(buf, 5, 8);
63
      bw.write(buf, 13, 12);
64
      bw.write(buf[25]);
65
      bw.write(buf, 26, buf.length - 26);
66
      bw.close();
67
 
68
      String str2 = new String(caw.toCharArray());
69
      if (!str.equals(str2))
70
        {
71
          passed = false;
72
          System.out.println("Unexpected string: " + str2);
73
        }
74
 
75
      if (passed)
76
        System.out.println("PASSED: Write Tests");
77
      else
78
        System.out.println("FAILED: Write Tests");
79
    }
80
  catch(IOException e)
81
    {
82
      System.out.println("FAILED: Write Tests: " + e);
83
    }
84
 
85
  System.out.println("Finished test of BufferedOutputStream and ByteArrayOutputStream");
86
}
87
 
88
} // class BufferedByteOutputStreamTest
89
 

powered by: WebSVN 2.1.0

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