Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / test / java.io / CharArrayReaderTest.java
blob8b652b8062d821410a108a6712e0d418f31b31cd
1 /*************************************************************************
2 /* CharArrayReaderTest.java -- Test CharArrayReaders'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 CharArrayReaderTest extends CharArrayReader
27 public
28 CharArrayReaderTest(char[] b)
30 super(b);
33 public static void
34 main(String[] argv)
36 System.out.println("Starting test of CharArrayReader.");
37 System.out.flush();
39 String str = "In junior high, I did a lot writing. I wrote a science\n" +
40 "fiction novel length story that was called 'The Destruction of\n" +
41 "Planet Earth'. All the characters in the story were my friends \n" +
42 "from school because I couldn't think up any cool names.";
44 char[] str_chars = new char[str.length()];
45 str.getChars(0, str.length(), str_chars, 0);
47 System.out.println("Test 1: Protected Variables");
49 CharArrayReaderTest car = new CharArrayReaderTest(str_chars);
50 char[] read_buf = new char[12];
52 try
54 car.read(read_buf);
55 car.mark(0);
57 boolean passed = true;
59 if (car.markedPos != read_buf.length)
61 passed = false;
62 System.out.println("The mark variable is wrong. Expected " +
63 read_buf.length + " and got " + car.markedPos);
65 car.read(read_buf);
66 if (car.pos != (read_buf.length * 2))
68 passed = false;
69 System.out.println("The pos variable is wrong. Expected 24 and got " +
70 car.pos);
72 if (car.count != str_chars.length)
74 passed = false;
75 System.out.println("The count variable is wrong. Expected " +
76 str_chars.length + " and got " + car.pos);
78 if (car.buf != str_chars)
80 passed = false;
81 System.out.println("The buf variable is not correct");
84 if (passed)
85 System.out.println("PASSED: Protected Variables Test");
86 else
87 System.out.println("FAILED: Protected Variables Test");
89 catch (IOException e)
91 System.out.println("FAILED: Protected Variables Test: " + e);
94 System.out.println("Test 2: Simple Read Test");
96 car = new CharArrayReaderTest(str_chars);
98 try
100 int chars_read, total_read = 0;
101 while ((chars_read = car.read(read_buf, 0, read_buf.length)) != -1)
103 System.out.print(new String(read_buf, 0, chars_read));
104 total_read += chars_read;
107 car.close();
108 if (total_read == str.length())
109 System.out.println("PASSED: Simple Read Test");
110 else
111 System.out.println("FAILED: Simple Read Test");
113 catch (IOException e)
115 System.out.println("FAILED: Simple Read Test: " + e);
118 System.out.println("Test 3: mark/reset/available/skip test");
119 car = new CharArrayReaderTest(str_chars);
123 boolean passed = true;
125 car.read(read_buf);
126 if (!car.ready())
128 passed = false;
129 System.out.println("ready() reported false and should have " +
130 "reported true.");
133 if (car.skip(5) != 5)
135 passed = false;
136 System.out.println("skip() didn't work");
139 if (!car.markSupported())
141 passed = false;
142 System.out.println("markSupported() should have returned true but returned false");
145 car.mark(0);
146 int pos_save = car.pos;
147 car.read();
148 car.reset();
149 if (car.pos != pos_save)
151 passed = false;
152 System.out.println("mark/reset failed to work");
155 if (passed)
156 System.out.println("PASSED: mark/reset/available/skip test");
157 else
158 System.out.println("FAILED: mark/reset/available/skip test");
160 catch(IOException e)
162 System.out.println("FAILED: mark/reset/available/skip test: " + e);
165 System.out.println("Finished CharArrayReader test");