1BEGIN { 2 if ($ENV{PERL_CORE}) { 3 chdir 't' if -d 't'; 4 @INC = ("../lib", "lib/compress"); 5 } 6} 7 8use lib qw(t t/compress); 9use strict; 10use warnings; 11use bytes; 12 13use Test::More ; 14use CompTestUtils; 15 16BEGIN 17{ 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 => 288 + $extra ; 24 25 use_ok('Compress::Raw::Zlib', 2) ; 26} 27 28 29my $hello = <<EOM ; 30hello world 31this is a test 32EOM 33 34my $len = length $hello ; 35 36# Check zlib_version and ZLIB_VERSION are the same. 37is Compress::Raw::Zlib::zlib_version, ZLIB_VERSION ; 38 39 40for my $i (1 .. 13) 41{ 42 43 print "#\n#Length $i\n#\n"; 44 45 my $hello = "I am a HAL 9000 computer" x 2001; 46 my $tmp = $hello ; 47 48 my @hello = (); 49 push @hello, $1 50 while $tmp =~ s/^(.{$i})//; 51 push @hello, $tmp if length $tmp ; 52 53 my ($err, $x, $X, $status); 54 55 ok( ($x, $err) = new Compress::Raw::Zlib::Deflate (-AppendOutput => 1)); 56 ok $x ; 57 cmp_ok $err, '==', Z_OK, " status is Z_OK" ; 58 59 ok ! defined $x->msg(), " no msg" ; 60 is $x->total_in(), 0, " total_in == 0" ; 61 is $x->total_out(), 0, " total_out == 0" ; 62 63 my $out ; 64 foreach (@hello) 65 { 66 $status = $x->deflate($_, $out) ; 67 last unless $status == Z_OK ; 68 69 } 70 cmp_ok $status, '==', Z_OK, " status is Z_OK" ; 71 72 cmp_ok $x->flush($out), '==', Z_OK, " flush returned Z_OK" ; 73 74 ok ! defined $x->msg(), " no msg" ; 75 is $x->total_in(), length $hello, " length total_in" ; 76 is $x->total_out(), length $out, " length total_out" ; 77 78 my @Answer = (); 79 $tmp = $out; 80 push @Answer, $1 while $tmp =~ s/^(.{$i})//; 81 push @Answer, $tmp if length $tmp ; 82 83 my $k; 84 ok(($k, $err) = new Compress::Raw::Zlib::Inflate( -AppendOutput => 1)); 85 ok $k ; 86 cmp_ok $err, '==', Z_OK, " status is Z_OK" ; 87 88 ok ! defined $k->msg(), " no msg" ; 89 is $k->total_in(), 0, " total_in == 0" ; 90 is $k->total_out(), 0, " total_out == 0" ; 91 my $GOT = ''; 92 my $Z; 93 $Z = 1 ;#x 2000 ; 94 foreach (@Answer) 95 { 96 $status = $k->inflate($_, $GOT) ; 97 last if $status == Z_STREAM_END or $status != Z_OK ; 98 99 } 100 101 cmp_ok $status, '==', Z_STREAM_END, " status is Z_STREAM_END" ; 102 is $GOT, $hello, " got expected output" ; 103 ok ! defined $k->msg(), " no msg" ; 104 is $k->total_in(), length $out, " length total_in ok" ; 105 is $k->total_out(), length $hello, " length total_out ok" ; 106 107} 108