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