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