tests/libjava-mauve/src/gnu/testlet/java/io/LineNumberReader/Test.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 /*************************************************************************
       
     2 /* Test.java -- Tests LineNumberReader
       
     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.LineNumberReader;
       
    25 
       
    26 import gnu.testlet.Testlet;
       
    27 import gnu.testlet.TestHarness;
       
    28 import java.io.*;
       
    29 
       
    30 public class Test implements Testlet
       
    31 {
       
    32 
       
    33 public void
       
    34 test(TestHarness harness)
       
    35 {
       
    36   try
       
    37     {
       
    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";
       
    42 
       
    43       StringReader sbr = new StringReader(str);
       
    44       LineNumberReader lnr = new LineNumberReader(sbr);
       
    45 
       
    46       lnr.setLineNumber(2);
       
    47 
       
    48       char[] buf = new char[32];
       
    49       int chars_read; 
       
    50       while ((chars_read = lnr.read(buf)) != -1)
       
    51         {
       
    52           str = new String(buf, 0, chars_read);
       
    53           if (str.indexOf("\r") != -1)
       
    54             {
       
    55               harness.debug("\nFound unexpected \\r");
       
    56               harness.check(false);
       
    57             } 
       
    58           harness.debug(str, false);
       
    59         }
       
    60 
       
    61       harness.check(lnr.getLineNumber(), 6, "getLineNumber - first series");
       
    62     }
       
    63   catch(IOException e)
       
    64     {
       
    65       harness.debug(e);
       
    66       harness.check(false);
       
    67     }
       
    68 
       
    69   try
       
    70     {
       
    71       String str = "Exiting off the expressway in Chicago is not an easy\n" +
       
    72         "thing to do.  For example, at Fullerton you have to run a\n" +
       
    73         "gauntlet of people selling flowers, begging for money, or trying\n" +
       
    74         "to 'clean' your windshield for tips.";
       
    75 
       
    76       StringReader sbr = new StringReader(str);
       
    77       LineNumberReader lnr = new LineNumberReader(sbr);
       
    78 
       
    79       char[] buf = new char[32];
       
    80       int chars_read; 
       
    81       while ((chars_read = lnr.read(buf)) != -1)
       
    82         harness.debug(new String(buf, 0, chars_read), false);
       
    83       harness.debug("");
       
    84 
       
    85       harness.check(lnr.getLineNumber(), 3, "getLineNumber - second test");
       
    86     }
       
    87   catch(IOException e)
       
    88     {
       
    89       harness.debug(e);
       
    90       harness.check(false);
       
    91 	}
       
    92 
       
    93    // test for mark, reset, skip, read(buf, off, len) and readLine
       
    94    try
       
    95     {
       
    96       String str = "Exiting off the expressway in Chicago is not an easy\n" +
       
    97         "thing to do.  For example, at Fullerton you have to run a\n" +
       
    98         "gauntlet of people selling flowers, begging for money, or trying\n" +
       
    99         "to 'clean' your windshield for tips.";
       
   100 
       
   101       StringReader sbr = new StringReader(str);
       
   102       LineNumberReader lnr = new LineNumberReader(sbr);
       
   103 
       
   104       char[] buf = new char[80];
       
   105       int chars_read; 
       
   106 	  String line = lnr.readLine();
       
   107 	  lnr.mark(80);
       
   108 	  lnr.skip(14);
       
   109 	  char[] buf2 = new char[3];
       
   110 	  lnr.read(buf2, 0, 3);
       
   111 	  String b2 = new String(buf2);
       
   112 	  harness.check(b2, "For", "skip(), read(buf, off, len)");
       
   113 	  lnr.reset();
       
   114 	  char[] buf3 = new char[5];
       
   115 	  lnr.read(buf3, 0, 5);
       
   116 	  String b3 = new String(buf3);
       
   117 	  harness.check(b3, "thing", "mark(), reset()");
       
   118     }
       
   119   catch(IOException e)
       
   120     {
       
   121       harness.debug(e);
       
   122       harness.check(false);
       
   123     }
       
   124 
       
   125   // Test for multiple \r or \n in a stream.
       
   126   try
       
   127     {
       
   128       String str = "One\r\r\r\rTwo\n\n\n\nThree\r\n\r\n\r\n";
       
   129       StringReader sbr = new StringReader(str);
       
   130       LineNumberReader lnr = new LineNumberReader(sbr);
       
   131 
       
   132       int c = lnr.read();
       
   133       while (c != -1)
       
   134 	{
       
   135 	  c = lnr.read();
       
   136 	}
       
   137       harness.check(lnr.getLineNumber(), 11, "One, Two, Three makes 11");
       
   138     }
       
   139   catch(IOException e)
       
   140     {
       
   141       harness.debug(e);
       
   142       harness.check(false, "One, Two, Three makes 11");
       
   143     }
       
   144 }
       
   145 
       
   146 } // class Test
       
   147