Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / test / java.io / PushbackReaderTest.java
blob3378306234b435870da3b62bcc53366bc80151ee
1 /*************************************************************************
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.
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.
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 /*************************************************************************/
22 import java.io.*;
24 public class PushbackReaderTest extends PushbackReader
27 public
28 PushbackReaderTest(Reader r, int size)
30 super(r, size);
33 public static void
34 main(String[] argv)
36 System.out.println("Started test of PushbackReader");
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";
50 System.out.println("Test 1: Basic Unread Tests");
51 try
53 PushbackReaderTest prt = new PushbackReaderTest(
54 new StringReader(str), 15);
56 char[] read_buf1 = new char[12];
57 char[] read_buf2 = new char[12];
59 boolean passed = true;
61 prt.read(read_buf1);
62 prt.unread(read_buf1);
63 prt.read(read_buf2);
65 for (int i = 0; i < read_buf1.length; i++)
67 if (read_buf1[i] != read_buf2[i])
68 passed = false;
71 prt.unread(read_buf2, 1, read_buf2.length - 1);
72 prt.unread(read_buf2[0]);
74 int chars_read, total_read = 0;
75 while ((chars_read = prt.read(read_buf1)) != -1)
77 System.out.print(new String(read_buf1, 0, chars_read));
78 total_read += chars_read;
81 if (total_read != str.length())
82 passed = false;
84 if (passed)
85 System.out.println("PASSED: Basic Unread Tests");
86 else
87 System.out.println("FAILED: Basic Unread Tests");
89 catch(IOException e)
91 System.out.println("FAILED: Basic Unread Tests: " + e);
94 System.out.println("Test 3: Buffer Overflow Test");
95 try
97 PushbackReaderTest prt = new PushbackReaderTest(
98 new StringReader(str), 10);
100 char[] read_buf = new char[12];
102 prt.read(read_buf);
103 prt.unread(read_buf);
104 System.out.println("FAILED: Buffer Overflow Test");
106 catch(IOException e)
108 System.out.println("PASSED: Buffer Overflow Test: " + e);
111 System.out.println("Finished tests of PushbackReader");
112 } // main
114 } // class PushbackReaderTest