1 // Tags: JDK1.1 |
|
2 |
|
3 /* Copyright (C) 1999 Cygnus Solutions |
|
4 |
|
5 This file is part of Mauve. |
|
6 |
|
7 Mauve is free software; you can redistribute it and/or modify |
|
8 it under the terms of the GNU General Public License as published by |
|
9 the Free Software Foundation; either version 2, or (at your option) |
|
10 any later version. |
|
11 |
|
12 Mauve is distributed in the hope that it will be useful, |
|
13 but 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 Mauve; see the file COPYING. If not, write to |
|
19 the Free Software Foundation, 59 Temple Place - Suite 330, |
|
20 Boston, MA 02111-1307, USA. */ |
|
21 |
|
22 package gnu.testlet.java.io.DataInputStream; |
|
23 import gnu.testlet.Testlet; |
|
24 import gnu.testlet.TestHarness; |
|
25 import java.io.*; |
|
26 |
|
27 public class readLine implements Testlet |
|
28 { |
|
29 private static void check(TestHarness harness, String input, String[] expected, int separator) |
|
30 { |
|
31 DataInputStream din = |
|
32 new DataInputStream(new ByteArrayInputStream(input.getBytes())); |
|
33 for (int i = 0; i < expected.length; i++) |
|
34 { |
|
35 try |
|
36 { |
|
37 harness.check(din.readLine(), expected[i]); |
|
38 if (separator != -1) |
|
39 harness.check(din.read() == separator, "missing separator in: " + input); |
|
40 } |
|
41 catch(Exception x) |
|
42 { |
|
43 harness.fail("unexpected exception " + x); |
|
44 } |
|
45 } |
|
46 try |
|
47 { |
|
48 harness.check(din.readLine(), null); |
|
49 } |
|
50 catch(Exception x) |
|
51 { |
|
52 harness.fail("unexpected exception " + x); |
|
53 } |
|
54 } |
|
55 |
|
56 public void test (TestHarness harness) |
|
57 { |
|
58 check(harness, "", new String[] {}, -1); |
|
59 check(harness, "\n", new String[] { "" }, -1); |
|
60 check(harness, "\r", new String[] { "" }, -1); |
|
61 check(harness, "\r\n", new String[] { "" }, -1); |
|
62 check(harness, "\n\r", new String[] { "", "" }, -1); |
|
63 check(harness, "\r\nfoo", new String[] { "", "foo" }, -1); |
|
64 check(harness, "foo\r\nbar", new String[] { "foo", "bar" }, -1); |
|
65 check(harness, "foo\rbar", new String[] { "foo", "bar" }, -1); |
|
66 check(harness, "foo\nbar", new String[] { "foo", "bar" }, -1); |
|
67 check(harness, "foo\r\n:bar\n:", new String[] { "foo", "bar" }, ':'); |
|
68 check(harness, "foo\r\n:bar\r:", new String[] { "foo", "bar" }, ':'); |
|
69 check(harness, "foo\r\n:bar\r\n:", new String[] { "foo", "bar" }, ':'); |
|
70 } |
|
71 } |
|