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