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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/*************************************************************************
2
/* PushbackReaderTest.java -- Tests PushbackReader's of course
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 PushbackReaderTest extends PushbackReader
25
{
26
 
27
public
28
PushbackReaderTest(Reader r, int size)
29
{
30
  super(r, size);
31
}
32
 
33
public static void
34
main(String[] argv)
35
{
36
  System.out.println("Started test of PushbackReader");
37
 
38
  String str = "I used to idolize my older cousin Kurt.  I wanted to be\n" +
39
    "just like him when I was a kid.  (Now we are as different as night\n" +
40
    "and day - but still like each other).  One thing he did for a while\n" +
41
    "was set traps for foxes thinking he would make money off sellnig furs.\n" +
42
    "Now I never saw a fox in all my years of Southern Indiana.  That\n" +
43
    "didn't deter us.  One time we went out in the middle of winter to\n" +
44
    "check our traps.  It was freezing and I stepped onto a frozen over\n" +
45
    "stream. The ice broke and I got my foot soak.  Despite the fact that\n" +
46
    "it made me look like a girl, I turned around and went straight home.\n" +
47
    "Good thing too since I couldn't even feel my foot by the time I got\n" +
48
    "there.\n";
49
 
50
  System.out.println("Test 1: Basic Unread Tests");
51
  try
52
    {
53
      PushbackReaderTest prt = new PushbackReaderTest(
54
        new StringReader(str), 15);
55
 
56
      char[] read_buf1 = new char[12];
57
      char[] read_buf2 = new char[12];
58
 
59
      boolean passed = true;
60
 
61
      prt.read(read_buf1);
62
      prt.unread(read_buf1);
63
      prt.read(read_buf2);
64
 
65
      for (int i = 0; i < read_buf1.length; i++)
66
        {
67
          if (read_buf1[i] != read_buf2[i])
68
            passed = false;
69
        }
70
 
71
      prt.unread(read_buf2, 1, read_buf2.length - 1);
72
      prt.unread(read_buf2[0]);
73
 
74
      int chars_read, total_read = 0;
75
      while ((chars_read = prt.read(read_buf1)) != -1)
76
        {
77
          System.out.print(new String(read_buf1, 0, chars_read));
78
          total_read += chars_read;
79
        }
80
 
81
      if (total_read != str.length())
82
        passed = false;
83
 
84
      if (passed)
85
        System.out.println("PASSED: Basic Unread Tests");
86
      else
87
        System.out.println("FAILED: Basic Unread Tests");
88
    }
89
  catch(IOException e)
90
    {
91
      System.out.println("FAILED: Basic Unread Tests: " + e);
92
    }
93
 
94
  System.out.println("Test 3: Buffer Overflow Test");
95
  try
96
    {
97
      PushbackReaderTest prt = new PushbackReaderTest(
98
        new StringReader(str), 10);
99
 
100
      char[] read_buf = new char[12];
101
 
102
      prt.read(read_buf);
103
      prt.unread(read_buf);
104
      System.out.println("FAILED: Buffer Overflow Test");
105
    }
106
  catch(IOException e)
107
    {
108
      System.out.println("PASSED: Buffer Overflow Test: " + e);
109
    }
110
 
111
  System.out.println("Finished tests of PushbackReader");
112
} // main
113
 
114
} // class PushbackReaderTest
115
 

powered by: WebSVN 2.1.0

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