1 /************************************************************************* |
|
2 /* SimpleRead.java -- BufferedReader simple read test |
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA |
|
20 /*************************************************************************/ |
|
21 |
|
22 // Tags: JDK1.1 |
|
23 |
|
24 package gnu.testlet.java.io.BufferedReader; |
|
25 |
|
26 import gnu.testlet.Testlet; |
|
27 import gnu.testlet.TestHarness; |
|
28 import java.io.*; |
|
29 |
|
30 public class SimpleRead implements Testlet |
|
31 { |
|
32 |
|
33 public void |
|
34 test(TestHarness harness) |
|
35 { |
|
36 try |
|
37 { |
|
38 String str = "My 5th grade teacher was named Mr. Thompson. Terry\n" + |
|
39 "George Thompson to be precise. He had these sideburns like\n" + |
|
40 "Isaac Asimov's, only uglier. One time he had a contest and said\n" + |
|
41 "that if any kid who could lift 50lbs worth of weights on a barbell\n" + |
|
42 "all the way over their head, he would shave it off. Nobody could\n" + |
|
43 "though. One time I guess I made a comment about how stupid his\n" + |
|
44 "sideburns worked and he not only kicked me out of class, he called\n" + |
|
45 "my mother. Jerk.\n"; |
|
46 |
|
47 StringReader sr = new StringReader(str); |
|
48 BufferedReader br = new BufferedReader(sr, 15); |
|
49 |
|
50 char[] buf = new char[12]; |
|
51 int chars_read, total_read = 0; |
|
52 while((chars_read = br.read(buf)) != -1) |
|
53 { |
|
54 harness.debug(new String(buf, 0, chars_read), false); |
|
55 total_read += chars_read; |
|
56 } |
|
57 |
|
58 br.close(); |
|
59 harness.check(total_read, str.length(), "total_read"); |
|
60 } |
|
61 catch (IOException e) |
|
62 { |
|
63 harness.debug(e); |
|
64 harness.check(false); |
|
65 } |
|
66 } // main |
|
67 |
|
68 } // class SimpleRead |
|
69 |
|