17 # use Test::NoWarnings, if available
20 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
22 plan tests => 2374 + $extra;
24 use_ok('Compress::Zlib', 2) ;
26 use_ok('IO::Compress::Gzip', qw($GzipError)) ;
27 use_ok('IO::Uncompress::Gunzip', qw($GunzipError)) ;
29 use_ok('IO::Compress::Deflate', qw($DeflateError)) ;
30 use_ok('IO::Uncompress::Inflate', qw($InflateError)) ;
32 use_ok('IO::Compress::RawDeflate', qw($RawDeflateError)) ;
33 use_ok('IO::Uncompress::RawInflate', qw($RawInflateError)) ;
41 some more stuff on this line
48 foreach my $CompressClass ('IO::Compress::Gzip', 'IO::Compress::Deflate')
50 my $UncompressClass = getInverse($CompressClass);
56 if ($CompressClass eq 'IO::Compress::Gzip') {
57 ok( my $x = new IO::Compress::Gzip \$compressed,
59 -Comment => "a comment",
60 -ExtraField => ['ab' => "extra"],
62 ok $x->write($hello) ;
66 ok($gz = new IO::Uncompress::Gunzip \$cc,
68 or diag "$GunzipError";
70 ok $gz->read($un) > 0 ;
75 ok( my $x = new $CompressClass(\$compressed));
76 ok $x->write($hello) ;
80 ok($gz = new $UncompressClass(\$cc,
82 or diag "$GunzipError";
84 ok $gz->read($un) > 0 ;
90 for my $trans ( 0 .. 1)
92 title "Testing $CompressClass, Transparent $trans";
94 my $info = $gz->getHeaderInfo() ;
95 my $header_size = $info->{HeaderLength};
96 my $trailer_size = $info->{TrailerLength};
97 ok 1, "Compressed size is " . length($compressed) ;
98 ok 1, "Header size is $header_size" ;
99 ok 1, "Trailer size is $trailer_size" ;
101 title "Fingerprint Truncation";
104 my $name = "test.gz" ;
106 my $lex = new LexFile $name ;
109 my $part = substr($compressed, 0, $i);
110 writeFile($name, $part);
112 my $gz = new $UncompressClass $name,
113 -BlockSize => $blocksize,
114 -Transparent => $trans;
119 ok $gz->read($buff) == length($part) ;
130 title "Header Truncation";
132 # Any header corruption past the fingerprint is considered catastrophic
133 # so even if Transparent is set, it should still fail
135 foreach my $i (2 .. $header_size -1)
137 my $name = "test.gz" ;
139 my $lex = new LexFile $name ;
142 my $part = substr($compressed, 0, $i);
143 writeFile($name, $part);
144 ok ! defined new $UncompressClass $name,
145 -BlockSize => $blocksize,
146 -Transparent => $trans;
150 title "Compressed Data Truncation";
151 foreach my $i ($header_size .. length($compressed) - 1 - $trailer_size)
154 my $name = "test.gz" ;
156 my $lex = new LexFile $name ;
159 my $part = substr($compressed, 0, $i);
160 writeFile($name, $part);
161 ok my $gz = new $UncompressClass $name,
162 -BlockSize => $blocksize,
163 -Transparent => $trans;
166 $status = $gz->read($un) while $status >= 0 ;
173 # RawDeflate does not have a trailer
174 next if $CompressClass eq 'IO::Compress::RawDeflate' ;
176 title "Compressed Trailer Truncation";
177 foreach my $i (length($compressed) - $trailer_size .. length($compressed) -1 )
179 foreach my $lax (0, 1)
181 my $name = "test.gz" ;
183 my $lex = new LexFile $name ;
185 ok 1, "Length $i, Lax $lax" ;
186 my $part = substr($compressed, 0, $i);
187 writeFile($name, $part);
188 ok my $gz = new $UncompressClass $name,
189 -BlockSize => $blocksize,
192 -Transparent => $trans;
195 $status = $gz->read($un) while $status > 0 ;
201 or diag "Status $status Error is " . $gz->error() ;
203 or diag "Status $status Error is " . $gz->error() ;
209 or diag "Status $status Error is " . $gz->error() ;
211 or diag "Status $status Error is " . $gz->error() ;
222 foreach my $CompressClass ( 'IO::Compress::RawDeflate')
224 my $UncompressClass = getInverse($CompressClass);
225 my $Error = getErrorRef($UncompressClass);
228 ok( my $x = new IO::Compress::RawDeflate \$compressed);
229 ok $x->write($hello) ;
233 my $cc = $compressed ;
236 ok($gz = new $UncompressClass(\$cc,
240 ok $gz->read($un) > 0 ;
244 for my $trans (0 .. 1)
246 title "Testing $CompressClass, Transparent = $trans";
248 my $info = $gz->getHeaderInfo() ;
249 my $header_size = $info->{HeaderLength};
250 my $trailer_size = $info->{TrailerLength};
251 ok 1, "Compressed size is " . length($compressed) ;
252 ok 1, "Header size is $header_size" ;
253 ok 1, "Trailer size is $trailer_size" ;
256 title "Compressed Data Truncation";
257 foreach my $i (0 .. $blocksize)
260 my $name = "test.gz" ;
262 my $lex = new LexFile $name ;
265 my $part = substr($compressed, 0, $i);
266 writeFile($name, $part);
267 my $gz = new $UncompressClass $name,
268 -BlockSize => $blocksize,
269 -Transparent => $trans;
274 ok $gz->read($buff) == length $part ;
284 foreach my $i ($blocksize+1 .. length($compressed)-1)
287 my $name = "test.gz" ;
289 my $lex = new LexFile $name ;
292 my $part = substr($compressed, 0, $i);
293 writeFile($name, $part);
294 ok my $gz = new $UncompressClass $name,
295 -BlockSize => $blocksize,
296 -Transparent => $trans;
299 $status = $gz->read($un) while $status >= 0 ;