1 /*************************************************************************
2 /* CharArrayReaderTest.java -- Test CharArrayReaders's of course
4 /* Copyright (c) 1998 Free Software Foundation, Inc.
5 /* Written by Aaron M. Renn (arenn@urbanophile.com)
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 /*************************************************************************/
24 public class CharArrayReaderTest
extends CharArrayReader
28 CharArrayReaderTest(char[] b
)
36 System
.out
.println("Starting test of CharArrayReader.");
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];
57 boolean passed
= true;
59 if (car
.markedPos
!= read_buf
.length
)
62 System
.out
.println("The mark variable is wrong. Expected " +
63 read_buf
.length
+ " and got " + car
.markedPos
);
66 if (car
.pos
!= (read_buf
.length
* 2))
69 System
.out
.println("The pos variable is wrong. Expected 24 and got " +
72 if (car
.count
!= str_chars
.length
)
75 System
.out
.println("The count variable is wrong. Expected " +
76 str_chars
.length
+ " and got " + car
.pos
);
78 if (car
.buf
!= str_chars
)
81 System
.out
.println("The buf variable is not correct");
85 System
.out
.println("PASSED: Protected Variables Test");
87 System
.out
.println("FAILED: Protected Variables Test");
91 System
.out
.println("FAILED: Protected Variables Test: " + e
);
94 System
.out
.println("Test 2: Simple Read Test");
96 car
= new CharArrayReaderTest(str_chars
);
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
;
108 if (total_read
== str
.length())
109 System
.out
.println("PASSED: Simple Read Test");
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;
129 System
.out
.println("ready() reported false and should have " +
133 if (car
.skip(5) != 5)
136 System
.out
.println("skip() didn't work");
139 if (!car
.markSupported())
142 System
.out
.println("markSupported() should have returned true but returned false");
146 int pos_save
= car
.pos
;
149 if (car
.pos
!= pos_save
)
152 System
.out
.println("mark/reset failed to work");
156 System
.out
.println("PASSED: mark/reset/available/skip test");
158 System
.out
.println("FAILED: mark/reset/available/skip test");
162 System
.out
.println("FAILED: mark/reset/available/skip test: " + e
);
165 System
.out
.println("Finished CharArrayReader test");