1 /*************************************************************************
2 /* LineNumberReaderTest.java -- Tests LineNumberReader's
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 LineNumberReaderTest
30 System
.out
.println("Started test of LineNumberReader");
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
);
48 char[] buf
= new char[32];
50 while ((chars_read
= lnr
.read(buf
)) != -1)
52 str
= new String(buf
, 0, chars_read
);
53 if (str
.indexOf("\r") != -1)
56 System
.out
.println("\nFound an unexpected \\r\n");
59 System
.out
.print(str
);
62 if (lnr
.getLineNumber() != 6)
65 System
.out
.println("Line number was wrong. Expected 6 but got " +
70 System
.out
.println("PASSED: First test series");
72 System
.out
.println("FAILED: First test series");
76 System
.out
.println("FAILED: First test series: " + e
);
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];
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)
102 System
.out
.println("\nLine number was wrong. Expected 3 but got " +
103 lnr
.getLineNumber());
107 System
.out
.println("PASSED: Second test series");
109 System
.out
.println("FAILED: Second test series");
113 System
.out
.println("FAILED: Second test series: " + e
);
116 System
.out
.println("Finished test of LineNumberReader");
119 } // class LineNumberReaderTest