11 # use Test::NoWarnings, if available
14 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
16 plan tests => 49 + $extra ;
21 my $CompressClass = identify();
22 my $UncompressClass = getInverse($CompressClass);
23 my $Error = getErrorRef($CompressClass);
24 my $UnError = getErrorRef($UncompressClass);
26 use Compress::Raw::Zlib;
27 use IO::Handle qw(SEEK_SET SEEK_CUR SEEK_END);
31 my $filename = shift ;
35 my $fil = new $UncompressClass $filename,
41 $data = $init if defined $init ;
42 1 while $fil->read($data) > 0;
51 title "Testing $CompressClass Errors";
57 title "Testing $UncompressClass Errors";
62 title "Testing $CompressClass and $UncompressClass";
68 my $lex = new LexFile my $name ;
77 ok $x = new $CompressClass $name ;
79 ok $x->write($hello), "write" ;
80 ok $x->flush(Z_FINISH), "flush";
81 ok $x->close, "close" ;
86 ok my $x = new $UncompressClass $name, -Append => 1 ;
89 1 while ($len = $x->read($uncomp)) > 0 ;
91 is $len, 0, "read returned 0";
99 if ($CompressClass ne 'RawDeflate')
102 #========================================
107 ok $x = new $CompressClass(\$buffer) ;
116 ok $x = new $UncompressClass(\$buffer, Append => 1) ;
118 1 while $x->read($uncomp) > 0 ;
124 ok $buffer eq $keep ;
130 title "inflateSync on plain file";
132 my $hello = "I am a HAL 9000 computer" x 2001 ;
134 my $k = new $UncompressClass(\$hello, Transparent => 1);
137 # Skip to the flush point -- no-op for plain file
138 my $status = $k->inflateSync();
140 or diag $k->error() ;
143 is $k->read($rest, length($hello)), length($hello)
144 or diag $k->error() ;
151 title "$CompressClass: inflateSync for real";
153 # create a deflate stream with flush points
155 my $hello = "I am a HAL 9000 computer" x 2001 ;
156 my $goodbye = "Will I dream?" x 2010;
157 my ($x, $err, $answer, $X, $Z, $status);
160 ok ($x = new $CompressClass(\$Answer));
163 is $x->write($hello), length($hello);
165 # create a flush point
166 ok $x->flush(Z_FULL_FLUSH) ;
168 is $x->write($goodbye), length($goodbye);
173 $k = new $UncompressClass(\$Answer, BlockSize => 1);
177 is $k->read($initial, 1), 1 ;
178 is $initial, substr($hello, 0, 1);
180 # Skip to the flush point
181 $status = $k->inflateSync();
182 is $status, 1, " inflateSync returned 1"
183 or diag $k->error() ;
186 is $k->read($rest, length($hello) + length($goodbye)),
188 or diag $k->error() ;
189 ok $rest eq $goodbye, " got expected output" ;
195 title "$CompressClass: inflateSync no FLUSH point";
197 # create a deflate stream with flush points
199 my $hello = "I am a HAL 9000 computer" x 2001 ;
200 my ($x, $err, $answer, $X, $Z, $status);
203 ok ($x = new $CompressClass(\$Answer));
206 is $x->write($hello), length($hello);
210 my $k = new $UncompressClass(\$Answer, BlockSize => 1);
214 is $k->read($initial, 1), 1 ;
215 is $initial, substr($hello, 0, 1);
217 # Skip to the flush point
218 $status = $k->inflateSync();
220 or diag $k->error() ;
223 is $k->inflateSync(), 0 ;