4 @INC = ("../lib", "lib/compress");
13 # TODO -- split out & add zip/bzip2
19 # use Test::NoWarnings, if available
22 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
24 plan tests => 2374 + $extra;
26 use_ok('Compress::Zlib', 2) ;
28 use_ok('IO::Compress::Gzip', qw($GzipError)) ;
29 use_ok('IO::Uncompress::Gunzip', qw($GunzipError)) ;
31 use_ok('IO::Compress::Deflate', qw($DeflateError)) ;
32 use_ok('IO::Uncompress::Inflate', qw($InflateError)) ;
34 use_ok('IO::Compress::RawDeflate', qw($RawDeflateError)) ;
35 use_ok('IO::Uncompress::RawInflate', qw($RawInflateError)) ;
43 some more stuff on this line
50 foreach my $CompressClass ('IO::Compress::Gzip', 'IO::Compress::Deflate')
52 my $UncompressClass = getInverse($CompressClass);
58 if ($CompressClass eq 'IO::Compress::Gzip') {
59 ok( my $x = new IO::Compress::Gzip \$compressed,
61 -Comment => "a comment",
62 -ExtraField => ['ab' => "extra"],
64 ok $x->write($hello) ;
68 ok($gz = new IO::Uncompress::Gunzip \$cc,
70 or diag "$GunzipError";
72 ok $gz->read($un) > 0 ;
77 ok( my $x = new $CompressClass(\$compressed));
78 ok $x->write($hello) ;
82 ok($gz = new $UncompressClass(\$cc,
84 or diag "$GunzipError";
86 ok $gz->read($un) > 0 ;
92 for my $trans ( 0 .. 1)
94 title "Testing $CompressClass, Transparent $trans";
96 my $info = $gz->getHeaderInfo() ;
97 my $header_size = $info->{HeaderLength};
98 my $trailer_size = $info->{TrailerLength};
99 ok 1, "Compressed size is " . length($compressed) ;
100 ok 1, "Header size is $header_size" ;
101 ok 1, "Trailer size is $trailer_size" ;
103 title "Fingerprint Truncation";
106 my $lex = new LexFile my $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 $lex = new LexFile my $name ;
140 my $part = substr($compressed, 0, $i);
141 writeFile($name, $part);
142 ok ! defined new $UncompressClass $name,
143 -BlockSize => $blocksize,
144 -Transparent => $trans;
148 title "Compressed Data Truncation";
149 foreach my $i ($header_size .. length($compressed) - 1 - $trailer_size)
152 my $lex = new LexFile my $name ;
155 my $part = substr($compressed, 0, $i);
156 writeFile($name, $part);
157 ok my $gz = new $UncompressClass $name,
158 -BlockSize => $blocksize,
159 -Transparent => $trans;
162 $status = $gz->read($un) while $status >= 0 ;
169 # RawDeflate does not have a trailer
170 next if $CompressClass eq 'IO::Compress::RawDeflate' ;
172 title "Compressed Trailer Truncation";
173 foreach my $i (length($compressed) - $trailer_size .. length($compressed) -1 )
175 foreach my $lax (0, 1)
177 my $lex = new LexFile my $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 $lex = new LexFile my $name ;
257 my $part = substr($compressed, 0, $i);
258 writeFile($name, $part);
259 my $gz = new $UncompressClass $name,
260 -BlockSize => $blocksize,
261 -Transparent => $trans;
266 is $gz->read($buff), length $part ;
276 foreach my $i ($blocksize+1 .. length($compressed)-1)
279 my $lex = new LexFile my $name ;
282 my $part = substr($compressed, 0, $i);
283 writeFile($name, $part);
284 ok my $gz = new $UncompressClass $name,
285 -BlockSize => $blocksize,
286 -Transparent => $trans;
289 $status = $gz->read($un) while $status >= 0 ;