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