tests/libjava-mauve/src/gnu/testlet/java/io/FilterReader/SimpleRead.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 /*************************************************************************
       
     2 /* SimpleRead.java -- FilterReader simple read test.
       
     3 /*
       
     4 /* Copyright (c) 1998 Free Software Foundation, Inc.
       
     5 /* Written by Daryl O. Lee (dolee@sources.redhat.com)
       
     6 /* Adapted from CharArrayReader tests by Aaron M. Renn (arenn@urbanophile.com)
       
     7 /*
       
     8 /* This program is free software; you can redistribute it and/or modify
       
     9 /* it under the terms of the GNU General Public License as published 
       
    10 /* by the Free Software Foundation, either version 2 of the License, or
       
    11 /* (at your option) any later version.
       
    12 /*
       
    13 /* This program is distributed in the hope that it will be useful, but
       
    14 /* WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16 /* GNU General Public License for more details.
       
    17 /*
       
    18 /* You should have received a copy of the GNU General Public License
       
    19 /* along with this program; if not, write to the Free Software Foundation
       
    20 /* Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307 USA
       
    21 /*************************************************************************/
       
    22 
       
    23 // Tags: JDK1.1
       
    24 
       
    25 package gnu.testlet.java.io.FilterReader;
       
    26 
       
    27 import gnu.testlet.Testlet;
       
    28 import gnu.testlet.TestHarness;
       
    29 import java.io.CharArrayReader;
       
    30 import java.io.Reader;
       
    31 import java.io.FilterReader;
       
    32 import java.io.IOException;
       
    33 
       
    34 public class SimpleRead extends FilterReader implements Testlet
       
    35 {
       
    36 
       
    37 public SimpleRead()
       
    38 {
       
    39   this(new CharArrayReader(new char[0]));
       
    40 }
       
    41 
       
    42 SimpleRead(CharArrayReader car)
       
    43 {
       
    44   super((Reader) car);
       
    45 }
       
    46 
       
    47 public void
       
    48 test(TestHarness harness)
       
    49 {
       
    50   String str = "In junior high, I did a lot writing.  I wrote a science\n" +
       
    51      "fiction novel length story that was called 'The Destruction of\n" +
       
    52      "Planet Earth'.  All the characters in the story were my friends \n" +
       
    53      "from school because I couldn't think up any cool names.\n";
       
    54 
       
    55   char[] str_chars = new char[str.length()];
       
    56   str.getChars(0, str.length(), str_chars, 0);
       
    57   char[] read_buf = new char[12];
       
    58 
       
    59   CharArrayReader car = new CharArrayReader(str_chars);
       
    60   SimpleRead fr = new SimpleRead(car);
       
    61 
       
    62   try
       
    63     {
       
    64 	  harness.check(fr.read(), 'I', "read()");
       
    65       int chars_read, total_read = 0;
       
    66       while ((chars_read = fr.read(read_buf, 0, read_buf.length)) != -1)
       
    67         {
       
    68           harness.debug(new String(read_buf, 0, chars_read), false);
       
    69           total_read += chars_read;
       
    70         }
       
    71 
       
    72       harness.check(total_read, str.length()-1, "read(buf,off,len)");  // -1 compensates for single read() earlier
       
    73     }
       
    74   catch (IOException e)
       
    75     {
       
    76       harness.debug(e);
       
    77       harness.check(false);
       
    78     }
       
    79 }
       
    80 
       
    81 } // SimpleRead
       
    82