11 # use Test::NoWarnings, if available
14 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
16 plan tests => 2374 + $extra;
22 my $CompressClass = identify();
23 my $UncompressClass = getInverse($CompressClass);
24 my $Error = getErrorRef($CompressClass);
25 my $UnError = getErrorRef($UncompressClass);
30 some more stuff on this line
37 my ($info, $compressed) = mkComplete($CompressClass, $hello);
39 my $header_size = $info->{HeaderLength};
40 my $trailer_size = $info->{TrailerLength};
41 my $fingerprint_size = $info->{FingerprintLength};
42 ok 1, "Compressed size is " . length($compressed) ;
43 ok 1, "Fingerprint size is $fingerprint_size" ;
44 ok 1, "Header size is $header_size" ;
45 ok 1, "Trailer size is $trailer_size" ;
47 for my $trans ( 0 .. 1)
49 title "Truncating $CompressClass, Transparent $trans";
52 foreach my $i (1 .. $fingerprint_size-1)
54 my $lex = new LexFile my $name ;
56 title "Fingerprint Truncation - length $i";
58 my $part = substr($compressed, 0, $i);
59 writeFile($name, $part);
61 my $gz = new $UncompressClass $name,
62 -BlockSize => $blocksize,
63 -Transparent => $trans;
68 ok $gz->read($buff) == length($part) ;
80 # Any header corruption past the fingerprint is considered catastrophic
81 # so even if Transparent is set, it should still fail
83 foreach my $i ($fingerprint_size .. $header_size -1)
85 my $lex = new LexFile my $name ;
87 title "Header Truncation - length $i";
89 my $part = substr($compressed, 0, $i);
90 writeFile($name, $part);
91 ok ! defined new $UncompressClass $name,
92 -BlockSize => $blocksize,
93 -Transparent => $trans;
98 foreach my $i ($header_size .. length($compressed) - 1 - $trailer_size)
100 my $lex = new LexFile my $name ;
102 title "Compressed Data Truncation - length $i";
104 my $part = substr($compressed, 0, $i);
105 writeFile($name, $part);
106 ok my $gz = new $UncompressClass $name,
107 -BlockSize => $blocksize,
108 -Transparent => $trans;
111 $status = $gz->read($un) while $status >= 0 ;
118 # RawDeflate does not have a trailer
119 next if $CompressClass eq 'IO::Compress::RawDeflate' ;
121 title "Compressed Trailer Truncation";
122 foreach my $i (length($compressed) - $trailer_size .. length($compressed) -1 )
124 foreach my $lax (0, 1)
126 my $lex = new LexFile my $name ;
128 ok 1, "Length $i, Lax $lax" ;
129 my $part = substr($compressed, 0, $i);
130 writeFile($name, $part);
131 ok my $gz = new $UncompressClass $name,
132 -BlockSize => $blocksize,
135 -Transparent => $trans;
138 $status = $gz->read($un) while $status > 0 ;
144 or diag "Status $status Error is " . $gz->error() ;
146 or diag "Status $status Error is " . $gz->error() ;
152 or diag "Status $status Error is " . $gz->error() ;
154 or diag "Status $status Error is " . $gz->error() ;
169 foreach my $CompressClass ( 'IO::Compress::RawDeflate')
171 my $UncompressClass = getInverse($CompressClass);
172 my $Error = getErrorRef($UncompressClass);
175 ok( my $x = new IO::Compress::RawDeflate \$compressed);
176 ok $x->write($hello) ;
180 my $cc = $compressed ;
183 ok($gz = new $UncompressClass(\$cc,
187 ok $gz->read($un) > 0 ;
191 for my $trans (0 .. 1)
193 title "Testing $CompressClass, Transparent = $trans";
195 my $info = $gz->getHeaderInfo() ;
196 my $header_size = $info->{HeaderLength};
197 my $trailer_size = $info->{TrailerLength};
198 ok 1, "Compressed size is " . length($compressed) ;
199 ok 1, "Header size is $header_size" ;
200 ok 1, "Trailer size is $trailer_size" ;
203 title "Compressed Data Truncation";
204 foreach my $i (0 .. $blocksize)
207 my $lex = new LexFile my $name ;
210 my $part = substr($compressed, 0, $i);
211 writeFile($name, $part);
212 my $gz = new $UncompressClass $name,
213 -BlockSize => $blocksize,
214 -Transparent => $trans;
219 is $gz->read($buff), length $part ;
229 foreach my $i ($blocksize+1 .. length($compressed)-1)
232 my $lex = new LexFile my $name ;
235 my $part = substr($compressed, 0, $i);
236 writeFile($name, $part);
237 ok my $gz = new $UncompressClass $name,
238 -BlockSize => $blocksize,
239 -Transparent => $trans;
242 $status = $gz->read($un) while $status >= 0 ;