1*b39c5158SmillertBEGIN { 2*b39c5158Smillert if ($ENV{PERL_CORE}) { 3*b39c5158Smillert chdir 't' if -d 't'; 4*b39c5158Smillert @INC = ("../lib", "lib/compress"); 5*b39c5158Smillert } 6*b39c5158Smillert} 7*b39c5158Smillert 8*b39c5158Smillertuse lib qw(t t/compress); 9*b39c5158Smillertuse strict; 10*b39c5158Smillertuse warnings; 11*b39c5158Smillertuse bytes; 12*b39c5158Smillert 13*b39c5158Smillertuse Test::More ; 14*b39c5158Smillertuse CompTestUtils; 15*b39c5158Smillert 16*b39c5158SmillertBEGIN 17*b39c5158Smillert{ 18*b39c5158Smillert # use Test::NoWarnings, if available 19*b39c5158Smillert my $extra = 0 ; 20*b39c5158Smillert $extra = 1 21*b39c5158Smillert if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; 22*b39c5158Smillert 23*b39c5158Smillert plan tests => 88 + $extra ; 24*b39c5158Smillert 25*b39c5158Smillert use_ok('Compress::Raw::Bzip2') ; 26*b39c5158Smillert} 27*b39c5158Smillert 28*b39c5158Smillert 29*b39c5158Smillert 30*b39c5158Smillertmy $hello = "I am a HAL 9000 computer" x 2001; 31*b39c5158Smillertmy $tmp = $hello ; 32*b39c5158Smillert 33*b39c5158Smillertmy ($err, $x, $X, $status); 34*b39c5158Smillert 35*b39c5158Smillertok( ($x, $err) = new Compress::Raw::Bzip2 (1)); 36*b39c5158Smillertok $x ; 37*b39c5158Smillertcmp_ok $err, '==', BZ_OK, " status is BZ_OK" ; 38*b39c5158Smillert 39*b39c5158Smillertmy $out ; 40*b39c5158Smillert$status = $x->bzdeflate($tmp, $out) ; 41*b39c5158Smillertcmp_ok $status, '==', BZ_RUN_OK, " status is BZ_RUN_OK" ; 42*b39c5158Smillert 43*b39c5158Smillertcmp_ok $x->bzclose($out), '==', BZ_STREAM_END, " bzflush returned BZ_STREAM_END" ; 44*b39c5158Smillert 45*b39c5158Smillert{ 46*b39c5158Smillert my $t = $out; 47*b39c5158Smillert my $b = new Compress::Raw::Bunzip2(0,0); 48*b39c5158Smillert 49*b39c5158Smillert my $GOT; 50*b39c5158Smillert my $status = $b->bzinflate($t, $GOT) ; 51*b39c5158Smillert cmp_ok $status, "==", BZ_STREAM_END; 52*b39c5158Smillert ok $GOT eq $hello; 53*b39c5158Smillert 54*b39c5158Smillert} 55*b39c5158Smillert 56*b39c5158Smillertsub getOut { my $x = ''; return \$x } 57*b39c5158Smillert 58*b39c5158Smillertfor my $bufsize (1, 2, 3, 13, 4096, 1024*10) 59*b39c5158Smillert{ 60*b39c5158Smillert print "#\n#Bufsize $bufsize\n#\n"; 61*b39c5158Smillert $tmp = $out; 62*b39c5158Smillert 63*b39c5158Smillert my $k; 64*b39c5158Smillert ok(($k, $err) = new Compress::Raw::Bunzip2( 1,1,0,0,1 65*b39c5158Smillert #AppendOutput => 1, 66*b39c5158Smillert #LimitOutput => 1, 67*b39c5158Smillert #Bufsize => $bufsize 68*b39c5158Smillert )); 69*b39c5158Smillert ok $k ; 70*b39c5158Smillert cmp_ok $err, '==', BZ_OK, " status is BZ_OK" ; 71*b39c5158Smillert 72*b39c5158Smillert is $k->total_in_lo32(), 0, " total_in_lo32 == 0" ; 73*b39c5158Smillert is $k->total_out_lo32(), 0, " total_out_lo32 == 0" ; 74*b39c5158Smillert my $GOT = getOut(); 75*b39c5158Smillert my $prev; 76*b39c5158Smillert my $deltaOK = 1; 77*b39c5158Smillert my $looped = 0; 78*b39c5158Smillert while (length $tmp) 79*b39c5158Smillert { 80*b39c5158Smillert ++ $looped; 81*b39c5158Smillert my $prev = length $GOT; 82*b39c5158Smillert $status = $k->bzinflate($tmp, $GOT) ; 83*b39c5158Smillert last if $status != BZ_OK; 84*b39c5158Smillert $deltaOK = 0 if length($GOT) - $prev > $bufsize; 85*b39c5158Smillert } 86*b39c5158Smillert 87*b39c5158Smillert ok $deltaOK, " Output Delta never > $bufsize"; 88*b39c5158Smillert cmp_ok $looped, '>=', 1, " looped $looped"; 89*b39c5158Smillert is length($tmp), 0, " length of input buffer is zero"; 90*b39c5158Smillert 91*b39c5158Smillert cmp_ok $status, "==", BZ_STREAM_END, " status is BZ_STREAM_END" ; 92*b39c5158Smillert ok $$GOT eq $hello, " got expected output" ; 93*b39c5158Smillert is $k->total_in_lo32(), length $out, " length total_in_lo32 ok" ; 94*b39c5158Smillert is $k->total_out_lo32(), length $hello, " length total_out_lo32 ok " . $k->total_out_lo32() ; 95*b39c5158Smillert} 96*b39c5158Smillert 97*b39c5158Smillertsub getit 98*b39c5158Smillert{ 99*b39c5158Smillert my $obj = shift ; 100*b39c5158Smillert my $input = shift; 101*b39c5158Smillert 102*b39c5158Smillert my $data ; 103*b39c5158Smillert 1 while $obj->bzinflate($input, $data) != BZ_STREAM_END ; 104*b39c5158Smillert return \$data ; 105*b39c5158Smillert} 106*b39c5158Smillert 107*b39c5158Smillert{ 108*b39c5158Smillert title "regression test"; 109*b39c5158Smillert 110*b39c5158Smillert my ($err, $x, $X, $status); 111*b39c5158Smillert 112*b39c5158Smillert ok( ($x, $err) = new Compress::Raw::Bzip2 (1)); 113*b39c5158Smillert ok $x ; 114*b39c5158Smillert cmp_ok $err, '==', BZ_OK, " status is BZ_OK" ; 115*b39c5158Smillert 116*b39c5158Smillert my $line1 = ("abcdefghijklmnopq" x 1000) . "\n" ; 117*b39c5158Smillert my $line2 = "second line\n" ; 118*b39c5158Smillert my $text = $line1 . $line2 ; 119*b39c5158Smillert my $tmp = $text; 120*b39c5158Smillert 121*b39c5158Smillert my $out ; 122*b39c5158Smillert $status = $x->bzdeflate($tmp, $out) ; 123*b39c5158Smillert cmp_ok $status, '==', BZ_RUN_OK, " status is BZ_RUN_OK" ; 124*b39c5158Smillert 125*b39c5158Smillert cmp_ok $x->bzclose($out), '==', BZ_STREAM_END, " bzclose returned BZ_STREAM_END" ; 126*b39c5158Smillert 127*b39c5158Smillert my $k; 128*b39c5158Smillert ok(($k, $err) = new Compress::Raw::Bunzip2( 1,1,0,0,1 129*b39c5158Smillert #AppendOutput => 1, 130*b39c5158Smillert #LimitOutput => 1 131*b39c5158Smillert )); 132*b39c5158Smillert 133*b39c5158Smillert 134*b39c5158Smillert my $c = getit($k, $out); 135*b39c5158Smillert is $$c, $text; 136*b39c5158Smillert 137*b39c5158Smillert 138*b39c5158Smillert} 139