Fix Compress::Zlib test boilerplate
[p5sagit/p5-mst-13.2.git] / ext / Compress / Zlib / t / 12any.t
1 BEGIN {
2     if ($ENV{PERL_CORE}) {
3         chdir 't' if -d 't';
4         @INC = '../lib';
5     }
6 }
7
8 use lib 't';
9  
10 use strict;
11 use warnings;
12 use bytes;
13
14 use Test::More ;
15 use ZlibTestUtils;
16
17 BEGIN {
18     # use Test::NoWarnings, if available
19     my $extra = 0 ;
20     $extra = 1
21         if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };
22
23     plan tests => 63 + $extra ;
24
25     use_ok('Compress::Zlib', 2) ;
26
27     use_ok('IO::Compress::Gzip', qw($GzipError)) ;
28     use_ok('IO::Uncompress::Gunzip', qw($GunzipError)) ;
29
30     use_ok('IO::Compress::Deflate', qw($DeflateError)) ;
31     use_ok('IO::Uncompress::Inflate', qw($InflateError)) ;
32
33     use_ok('IO::Compress::RawDeflate', qw($RawDeflateError)) ;
34     use_ok('IO::Uncompress::RawInflate', qw($RawInflateError)) ;
35     use_ok('IO::Uncompress::AnyInflate', qw($AnyInflateError)) ;
36 }
37
38 foreach my $Class ( map { "IO::Compress::$_" } qw( Gzip Deflate RawDeflate) )
39 {
40     
41     for my $trans ( 0, 1 )
42     {
43         title "AnyInflate(Transparent => $trans) with $Class" ;
44         my $string = <<EOM;
45 some text
46 EOM
47
48         my $buffer ;
49         my $x = new $Class(\$buffer) ;
50         ok $x, "  create $Class object" ;
51         ok $x->write($string), "  write to object" ;
52         ok $x->close, "  close ok" ;
53
54         my $unc = new IO::Uncompress::AnyInflate \$buffer, Transparent => $trans  ;
55
56         ok $unc, "  Created AnyInflate object" ;
57         my $uncomp ;
58         ok $unc->read($uncomp) > 0 
59             or print "# $IO::Uncompress::AnyInflate::AnyInflateError\n";
60         ok $unc->eof(), "  at eof" ;
61         #ok $unc->type eq $Type;
62
63         is $uncomp, $string, "  expected output" ;
64     }
65
66 }
67
68 {
69     title "AnyInflate with Non-compressed data" ;
70
71     my $string = <<EOM;
72 This is not compressed data
73 EOM
74
75     my $buffer = $string ;
76
77     my $unc ;
78     my $keep = $buffer ;
79     $unc = new IO::Uncompress::AnyInflate \$buffer, -Transparent => 0 ;
80     ok ! $unc,"  no AnyInflate object when -Transparent => 0" ;
81     is $buffer, $keep ;
82
83     $buffer = $keep ;
84     $unc = new IO::Uncompress::AnyInflate \$buffer, -Transparent => 1 ;
85     ok $unc, "  AnyInflate object when -Transparent => 1"  ;
86
87     my $uncomp ;
88     ok $unc->read($uncomp) > 0 ;
89     ok $unc->eof() ;
90     #ok $unc->type eq $Type;
91
92     is $uncomp, $string ;
93 }