tests/libjava-mauve/src/gnu/testlet/java/util/zip/GZIPInputStream/basic.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 // Tags: JDK1.1
       
     2 
       
     3 // Copyright (C) 1999 Cygnus Solutions
       
     4 
       
     5 // This file is part of Mauve.
       
     6 
       
     7 // Mauve is free software; you can redistribute it and/or modify
       
     8 // it under the terms of the GNU General Public License as published by
       
     9 // the Free Software Foundation; either version 2, or (at your option)
       
    10 // any later version.
       
    11 
       
    12 // Mauve is distributed in the hope that it will be useful,
       
    13 // but 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 Mauve; see the file COPYING.  If not, write to
       
    19 // the Free Software Foundation, 59 Temple Place - Suite 330,
       
    20 // Boston, MA 02111-1307, USA.  */
       
    21 
       
    22 package gnu.testlet.java.util.zip.GZIPInputStream;
       
    23 
       
    24 import gnu.testlet.Testlet;
       
    25 import gnu.testlet.TestHarness;
       
    26 import java.util.zip.*;
       
    27 import java.io.*;
       
    28 
       
    29 public class basic implements Testlet
       
    30 {
       
    31   private String readall (InputStream in)
       
    32   {
       
    33     StringBuffer sb = new StringBuffer ();
       
    34     byte[] buf = new byte[512];
       
    35     int n;
       
    36     try
       
    37       {
       
    38 	while ((n = in.read(buf)) > 0)
       
    39 	  sb.append(new String (buf, 0, n, "8859_1"));
       
    40       }
       
    41     catch (IOException _)
       
    42       {
       
    43       }
       
    44     return sb.toString ();
       
    45   }
       
    46 
       
    47   public void test (TestHarness harness)
       
    48   {
       
    49     // First read the uncompressed file.
       
    50     harness.checkPoint ("reading gzip file");
       
    51 
       
    52     String plain = "";
       
    53     GZIPInputStream gzin;
       
    54     InputStream is = null;
       
    55     try
       
    56       {
       
    57 	is = harness.getResourceStream ("gnu#testlet#java#util#zip#GZIPInputStream#reference.data");
       
    58 	plain = readall (is);
       
    59 
       
    60 	gzin = new GZIPInputStream (harness.getResourceStream ("gnu#testlet#java#util#zip#GZIPInputStream#reference.gz"));
       
    61 	String uncompressed = readall (gzin);
       
    62 
       
    63 	harness.check (plain, uncompressed);
       
    64       }
       
    65     catch (gnu.testlet.ResourceNotFoundException _1)
       
    66       {
       
    67 	harness.check (false);
       
    68       }
       
    69     catch (IOException _2)
       
    70       {
       
    71 	harness.check (false);
       
    72       }
       
    73 
       
    74     // Now compress some data into a buffer and then re-read it.
       
    75     harness.checkPoint ("compressing and re-reading");
       
    76     if (is == null)
       
    77       harness.check (false);
       
    78     else
       
    79       {
       
    80 	try
       
    81 	  {
       
    82 	    ByteArrayOutputStream bout = new ByteArrayOutputStream ();
       
    83 	    GZIPOutputStream gzout = new GZIPOutputStream (bout);
       
    84 	    gzout.write (plain.getBytes ("8859_1"));
       
    85 	    gzout.close ();
       
    86 	    gzin = new GZIPInputStream (new ByteArrayInputStream (bout.toByteArray()));
       
    87 	    String full = readall (gzin);
       
    88 
       
    89 	    harness.check (plain, full);
       
    90 	  }
       
    91 	catch (UnsupportedEncodingException _1)
       
    92 	  {
       
    93 	    harness.check (false);
       
    94 	  }
       
    95 	catch (IOException _2)
       
    96 	  {
       
    97 	    harness.check (false);
       
    98 	  }
       
    99       }
       
   100   }
       
   101 }