11 # use Test::NoWarnings, if available
14 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
16 plan tests => 2374 + $extra;
18 use_ok('Compress::Zlib', 2) ;
20 use_ok('IO::Compress::Gzip', qw($GzipError)) ;
21 use_ok('IO::Uncompress::Gunzip', qw($GunzipError)) ;
23 use_ok('IO::Compress::Deflate', qw($DeflateError)) ;
24 use_ok('IO::Uncompress::Inflate', qw($InflateError)) ;
26 use_ok('IO::Compress::RawDeflate', qw($RawDeflateError)) ;
27 use_ok('IO::Uncompress::RawInflate', qw($RawInflateError)) ;
35 some more stuff on this line
42 foreach my $CompressClass ('IO::Compress::Gzip', 'IO::Compress::Deflate')
44 my $UncompressClass = getInverse($CompressClass);
50 if ($CompressClass eq 'IO::Compress::Gzip') {
51 ok( my $x = new IO::Compress::Gzip \$compressed,
53 -Comment => "a comment",
54 -ExtraField => ['ab' => "extra"],
56 ok $x->write($hello) ;
60 ok($gz = new IO::Uncompress::Gunzip \$cc,
62 or diag "$GunzipError";
64 ok $gz->read($un) > 0 ;
69 ok( my $x = new $CompressClass(\$compressed));
70 ok $x->write($hello) ;
74 ok($gz = new $UncompressClass(\$cc,
76 or diag "$GunzipError";
78 ok $gz->read($un) > 0 ;
84 for my $trans ( 0 .. 1)
86 title "Testing $CompressClass, Transparent $trans";
88 my $info = $gz->getHeaderInfo() ;
89 my $header_size = $info->{HeaderLength};
90 my $trailer_size = $info->{TrailerLength};
91 ok 1, "Compressed size is " . length($compressed) ;
92 ok 1, "Header size is $header_size" ;
93 ok 1, "Trailer size is $trailer_size" ;
95 title "Fingerprint Truncation";
98 my $name = "test.gz" ;
100 my $lex = new LexFile $name ;
103 my $part = substr($compressed, 0, $i);
104 writeFile($name, $part);
106 my $gz = new $UncompressClass $name,
107 -BlockSize => $blocksize,
108 -Transparent => $trans;
113 ok $gz->read($buff) == length($part) ;
124 title "Header Truncation";
126 # Any header corruption past the fingerprint is considered catastrophic
127 # so even if Transparent is set, it should still fail
129 foreach my $i (2 .. $header_size -1)
131 my $name = "test.gz" ;
133 my $lex = new LexFile $name ;
136 my $part = substr($compressed, 0, $i);
137 writeFile($name, $part);
138 ok ! defined new $UncompressClass $name,
139 -BlockSize => $blocksize,
140 -Transparent => $trans;
144 title "Compressed Data Truncation";
145 foreach my $i ($header_size .. length($compressed) - 1 - $trailer_size)
148 my $name = "test.gz" ;
150 my $lex = new LexFile $name ;
153 my $part = substr($compressed, 0, $i);
154 writeFile($name, $part);
155 ok my $gz = new $UncompressClass $name,
156 -BlockSize => $blocksize,
157 -Transparent => $trans;
160 $status = $gz->read($un) while $status >= 0 ;
167 # RawDeflate does not have a trailer
168 next if $CompressClass eq 'IO::Compress::RawDeflate' ;
170 title "Compressed Trailer Truncation";
171 foreach my $i (length($compressed) - $trailer_size .. length($compressed) -1 )
173 foreach my $lax (0, 1)
175 my $name = "test.gz" ;
177 my $lex = new LexFile $name ;
179 ok 1, "Length $i, Lax $lax" ;
180 my $part = substr($compressed, 0, $i);
181 writeFile($name, $part);
182 ok my $gz = new $UncompressClass $name,
183 -BlockSize => $blocksize,
186 -Transparent => $trans;
189 $status = $gz->read($un) while $status > 0 ;
195 or diag "Status $status Error is " . $gz->error() ;
197 or diag "Status $status Error is " . $gz->error() ;
203 or diag "Status $status Error is " . $gz->error() ;
205 or diag "Status $status Error is " . $gz->error() ;
216 foreach my $CompressClass ( 'IO::Compress::RawDeflate')
218 my $UncompressClass = getInverse($CompressClass);
219 my $Error = getErrorRef($UncompressClass);
222 ok( my $x = new IO::Compress::RawDeflate \$compressed);
223 ok $x->write($hello) ;
227 my $cc = $compressed ;
230 ok($gz = new $UncompressClass(\$cc,
234 ok $gz->read($un) > 0 ;
238 for my $trans (0 .. 1)
240 title "Testing $CompressClass, Transparent = $trans";
242 my $info = $gz->getHeaderInfo() ;
243 my $header_size = $info->{HeaderLength};
244 my $trailer_size = $info->{TrailerLength};
245 ok 1, "Compressed size is " . length($compressed) ;
246 ok 1, "Header size is $header_size" ;
247 ok 1, "Trailer size is $trailer_size" ;
250 title "Compressed Data Truncation";
251 foreach my $i (0 .. $blocksize)
254 my $name = "test.gz" ;
256 my $lex = new LexFile $name ;
259 my $part = substr($compressed, 0, $i);
260 writeFile($name, $part);
261 my $gz = new $UncompressClass $name,
262 -BlockSize => $blocksize,
263 -Transparent => $trans;
268 ok $gz->read($buff) == length $part ;
278 foreach my $i ($blocksize+1 .. length($compressed)-1)
281 my $name = "test.gz" ;
283 my $lex = new LexFile $name ;
286 my $part = substr($compressed, 0, $i);
287 writeFile($name, $part);
288 ok my $gz = new $UncompressClass $name,
289 -BlockSize => $blocksize,
290 -Transparent => $trans;
293 $status = $gz->read($un) while $status >= 0 ;