tests/libjava-mauve/src/gnu/testlet/java/io/PushbackReader/Unread.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 /*************************************************************************
       
     2 /* Unread.java - Test basic unread functionality of PushbackReader
       
     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.PushbackReader;
       
    25 
       
    26 import gnu.testlet.Testlet;
       
    27 import gnu.testlet.TestHarness;
       
    28 import java.io.*;
       
    29 
       
    30 public class Unread implements Testlet
       
    31 {
       
    32 
       
    33 public void
       
    34 test(TestHarness harness)
       
    35 {
       
    36   String str = "I used to idolize my older cousin Kurt.  I wanted to be\n" +
       
    37     "just like him when I was a kid.  (Now we are as different as night\n" +
       
    38     "and day - but still like each other).  One thing he did for a while\n" +
       
    39     "was set traps for foxes thinking he would make money off selling furs.\n" +
       
    40     "Now I never saw a fox in all my years of Southern Indiana.  That\n" +
       
    41     "didn't deter us.  One time we went out in the middle of winter to\n" +
       
    42     "check our traps.  It was freezing and I stepped onto a frozen over\n" +
       
    43     "stream. The ice broke and I got my foot soaked.  Despite the fact that\n" +
       
    44     "it made me look like a girl, I turned around and went straight home.\n" +
       
    45     "Good thing too since I couldn't even feel my foot by the time I got\n" +
       
    46     "there.\n";
       
    47 
       
    48   try
       
    49     {
       
    50       PushbackReader prt = new PushbackReader(
       
    51         new StringReader(str), 15);
       
    52 
       
    53       char[] read_buf1 = new char[12]; 
       
    54       char[] read_buf2 = new char[12]; 
       
    55       
       
    56       boolean passed = true;
       
    57 
       
    58 	  harness.check(prt.ready(), "ready()");
       
    59 	  harness.check(!prt.markSupported(), "markSupported()");
       
    60 
       
    61       prt.read(read_buf1); 
       
    62       prt.unread(read_buf1);
       
    63       prt.read(read_buf2);
       
    64       
       
    65       for (int i = 0; i < read_buf1.length; i++)
       
    66         {
       
    67           if (read_buf1[i] != read_buf2[i])
       
    68             throw new IOException("Re-reading bytes gave different results");
       
    69         }
       
    70 
       
    71       prt.unread(read_buf2, 1, read_buf2.length - 1);      
       
    72       prt.unread(read_buf2[0]);
       
    73 
       
    74       int chars_read, total_read = 0;
       
    75       while ((chars_read = prt.read(read_buf1)) != -1)
       
    76         {
       
    77           harness.debug(new String(read_buf1, 0, chars_read), false);
       
    78           total_read += chars_read;
       
    79         }
       
    80 
       
    81       harness.check(total_read, str.length(), "total_read == str.length()");
       
    82 
       
    83 	  prt.close();
       
    84 	  harness.check(true, "close()");
       
    85     }
       
    86   catch(IOException e)
       
    87     {
       
    88       harness.debug(e);
       
    89       harness.check(false);
       
    90     }
       
    91 } 
       
    92 
       
    93 } // class Unread
       
    94