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