Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / test / java.io / LineNumberReaderTest.java
blob1a20b70f5218fca432e42bffa11e27b00a0d3ae3
1 /*************************************************************************
2 /* LineNumberReaderTest.java -- Tests LineNumberReader's
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 LineNumberReaderTest
27 public static void
28 main(String[] argv)
30 System.out.println("Started test of LineNumberReader");
32 try
34 System.out.println("Test 1: First test series");
36 boolean passed = true;
38 String str = "In 6th grade I had a crush on this girl named Leanne\n" +
39 "Dean. I thought she was pretty hot. I saw her at my ten year\n" +
40 "high school reunion. I still think she's pretty hot. (She's\n" +
41 "married to my brother's college roommate).\n";
43 StringReader sbr = new StringReader(str);
44 LineNumberReader lnr = new LineNumberReader(sbr);
46 lnr.setLineNumber(2);
48 char[] buf = new char[32];
49 int chars_read;
50 while ((chars_read = lnr.read(buf)) != -1)
52 str = new String(buf, 0, chars_read);
53 if (str.indexOf("\r") != -1)
55 passed = false;
56 System.out.println("\nFound an unexpected \\r\n");
59 System.out.print(str);
62 if (lnr.getLineNumber() != 6)
64 passed = false;
65 System.out.println("Line number was wrong. Expected 6 but got " +
66 lnr.getLineNumber());
69 if (passed)
70 System.out.println("PASSED: First test series");
71 else
72 System.out.println("FAILED: First test series");
74 catch(IOException e)
76 System.out.println("FAILED: First test series: " + e);
79 try
81 System.out.println("Test 2: Second test series");
83 boolean passed = true;
85 String str = "Exiting off the expressway in Chicago is not an easy\n" +
86 "thing to do. For example, at Fullerton you have to run a\n" +
87 "gauntlet of people selling flowers, begging for money, or trying\n" +
88 "to 'clean' your windshield for tips.";
90 StringReader sbr = new StringReader(str);
91 LineNumberReader lnr = new LineNumberReader(sbr);
93 char[] buf = new char[32];
94 int chars_read;
95 while ((chars_read = lnr.read(buf)) != -1)
96 System.out.print(new String(buf, 0, chars_read));
97 System.out.println("");
99 if (lnr.getLineNumber() != 3)
101 passed = false;
102 System.out.println("\nLine number was wrong. Expected 3 but got " +
103 lnr.getLineNumber());
106 if (passed)
107 System.out.println("PASSED: Second test series");
108 else
109 System.out.println("FAILED: Second test series");
111 catch(IOException e)
113 System.out.println("FAILED: Second test series: " + e);
116 System.out.println("Finished test of LineNumberReader");
119 } // class LineNumberReaderTest