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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/*************************************************************************
2
/* StringWriterTest.java -- Test StringWriter
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 StringWriter. This is just a rehash of the
26
  * BufferedCharWriterTest using a StringWriter instead of a
27
  * CharArrayWriter underneath.
28
  *
29
  * @version 0.0
30
  *
31
  * @author Aaron M. Renn (arenn@urbanophile.com)
32
  */
33
public class StringWriterTest
34
{
35
 
36
public static void
37
main(String argv[])
38
{
39
  System.out.println("Started test of StringWriter");
40
 
41
  try
42
    {
43
      System.out.println("Test 1: Write Tests");
44
 
45
      StringWriter sw = new StringWriter(24);
46
      BufferedWriter bw = new BufferedWriter(sw, 12);
47
 
48
      String str = "There are a ton of great places to see live, original\n" +
49
        "music in Chicago.  Places like Lounge Ax, Schuba's, the Empty\n" +
50
        "Bottle, and even the dreaded Metro with their sometimes asshole\n" +
51
        "bouncers.\n";
52
 
53
      boolean passed = true;
54
 
55
      char[] buf = new char[str.length()];
56
      str.getChars(0, str.length(), buf, 0);
57
 
58
      bw.write(buf, 0, 5);
59
      if (sw.toString().length() != 0)
60
        {
61
          passed = false;
62
          System.out.println("StringWriter has too many bytes #1");
63
        }
64
      bw.write(buf, 5, 8);
65
      bw.write(buf, 13, 12);
66
      bw.write(buf[25]);
67
      bw.write(buf, 26, buf.length - 26);
68
      bw.close();
69
 
70
      String str2 = sw.toString();
71
      if (!str.equals(str2))
72
        {
73
          passed = false;
74
          System.out.println("Unexpected string: " + str2);
75
        }
76
 
77
      if (passed)
78
        System.out.println("PASSED: Write Tests");
79
      else
80
        System.out.println("FAILED: Write Tests");
81
    }
82
  catch(IOException e)
83
    {
84
      System.out.println("FAILED: Write Tests: " + e);
85
    }
86
 
87
  System.out.println("Finished test of BufferedOutputStream and ByteArrayOutputStream");
88
}
89
 
90
} // class BufferedByteOutputStreamTest
91
 

powered by: WebSVN 2.1.0

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