11 # use Test::NoWarnings, if available
14 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
16 plan tests => 1324 + $extra ;
18 use_ok('IO::Uncompress::AnyUncompress', qw($AnyUncompressError)) ;
25 my $CompressClass = identify();
26 my $UncompressClass = getInverse($CompressClass);
27 my $Error = getErrorRef($CompressClass);
28 my $UnError = getErrorRef($UncompressClass);
34 push @buffers, <<EOM ;
37 some more stuff on this line
41 push @buffers, <<EOM ;
46 push @buffers, <<EOM ;
50 my $b0length = length $buffers[0];
51 my $bufcount = @buffers;
60 foreach my $fb ( qw( file filehandle buffer ) )
63 foreach my $i (1 .. @buffers) {
65 title "Testing $CompressClass with $i streams to $fb";
67 my @buffs = @buffers[0..$i -1] ;
69 if ($CompressClass eq 'IO::Compress::Gzip') {
72 Comment => "this is a comment",
73 ExtraField => ["so" => "me extra"],
78 my $lex = new LexFile my $name ;
83 $output = \$compressed;
85 elsif ($fb eq 'filehandle')
87 $output = new IO::File ">$name" ;
94 my $x = new $CompressClass($output, AutoClose => 1, %headers);
95 isa_ok $x, $CompressClass, ' $x' ;
97 foreach my $buffer (@buffs) {
98 ok $x->write($buffer), " Write OK" ;
99 # this will add an extra "empty" stream
100 ok $x->newStream(), " newStream OK" ;
102 ok $x->close, " Close ok" ;
104 #hexDump($compressed) ;
106 foreach my $unc ($UncompressClass, 'IO::Uncompress::AnyUncompress') {
107 title " Testing $CompressClass with $unc and $i streams, from $fb";
109 if ($fb eq 'filehandle')
111 $cc = new IO::File "<$name" ;
113 my @opts = $unc ne $UncompressClass
116 my $gz = new $unc($cc,
124 isa_ok $gz, $UncompressClass, ' $gz' ;
127 1 while $gz->read($un) > 0 ;
128 #print "[[$un]]\n" while $gz->read($un) > 0 ;
129 ok ! $gz->error(), " ! error()"
130 or diag "Error is " . $gz->error() ;
131 ok $gz->eof(), " eof()";
132 ok $gz->close(), " close() ok"
133 or diag "errno $!\n" ;
135 is $gz->streamCount(), $i +1, " streamCount ok " . ($i +1)
136 or diag "Stream count is " . $gz->streamCount();
137 ok $un eq join('', @buffs), " expected output" ;
141 foreach my $unc ($UncompressClass, 'IO::Uncompress::AnyUncompress') {
142 foreach my $blk (1, 20, $b0length - 1, $b0length, $b0length +1) {
143 title " Testing $CompressClass with $unc, BlockSize $blk and $i streams, from $fb";
145 if ($fb eq 'filehandle')
147 $cc = new IO::File "<$name" ;
149 my @opts = $unc ne $UncompressClass
152 my $gz = new $unc($cc,
160 isa_ok $gz, $UncompressClass, ' $gz' ;
164 # Want the first read to be in the middle of a stream
165 # and the second to cross a stream boundary
166 $b = 1000 while $gz->read($un, $b) > 0 ;
167 #print "[[$un]]\n" while $gz->read($un) > 0 ;
168 ok ! $gz->error(), " ! error()"
169 or diag "Error is " . $gz->error() ;
170 ok $gz->eof(), " eof()";
171 ok $gz->close(), " close() ok"
172 or diag "errno $!\n" ;
174 is $gz->streamCount(), $i +1, " streamCount ok " . ($i +1)
175 or diag "Stream count is " . $gz->streamCount();
176 ok $un eq join('', @buffs), " expected output" ;
181 foreach my $unc ($UncompressClass, 'IO::Uncompress::AnyUncompress') {
182 title " Testing $CompressClass with $unc nextStream and $i streams, from $fb";
184 if ($fb eq 'filehandle')
186 $cc = new IO::File "<$name" ;
188 my @opts = $unc ne $UncompressClass
191 my $gz = new $unc($cc,
199 isa_ok $gz, $UncompressClass, ' $gz' ;
201 for my $stream (1 .. $i)
203 my $buff = $buffs[$stream-1];
204 my @lines = split("\n", $buff);
209 while ($_ = $gz->getline()) {
212 is $., $lines, " \$. is $lines";
214 ok ! $gz->error(), " ! error()"
215 or diag "Error is " . $gz->error() ;
216 ok $gz->eof(), " eof()";
217 is $gz->streamCount(), $stream, " streamCount is $stream"
218 or diag "Stream count is " . $gz->streamCount();
219 ok $un eq $buff, " expected output" ;
220 #is $gz->tell(), length $buff, " tell is ok";
221 is $gz->nextStream(), 1, " nextStream ok";
222 is $gz->tell(), 0, " tell is 0";
223 is $., 0, ' $. is 0';
228 #1 while $gz->read($un) > 0 ;
229 is $., 0, " \$. is 0";
231 #print "[[$un]]\n" while $gz->read($un) > 0 ;
232 ok ! $gz->error(), " ! error()"
233 or diag "Error is " . $gz->error() ;
234 ok $gz->eof(), " eof()";
235 is $gz->streamCount(), $i+1, " streamCount is ok"
236 or diag "Stream count is " . $gz->streamCount();
237 ok $un eq "", " expected output" ;
238 is $gz->tell(), 0, " tell is 0";
241 is $gz->nextStream(), 0, " nextStream ok"
242 or diag $gz->error() ;
243 ok $gz->eof(), " eof()";
244 ok $gz->close(), " close() ok"
245 or diag "errno $!\n" ;
247 is $gz->streamCount(), $i +1, " streamCount ok"
248 or diag "Stream count is " . $gz->streamCount();
257 # corrupt one of the streams - all previous should be ok
259 # check that "tell" works ok