11 # use Test::NoWarnings, if available
14 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
16 plan tests => 694 + $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 ;
57 foreach my $fb ( qw( file filehandle buffer ) )
60 foreach my $i (1 .. @buffers) {
62 title "Testing $CompressClass with $i streams to $fb";
64 my @buffs = @buffers[0..$i -1] ;
66 if ($CompressClass eq 'IO::Compress::Gzip') {
69 Comment => "this is a comment",
70 ExtraField => ["so" => "me extra"],
75 my $lex = new LexFile my $name ;
80 $output = \$compressed;
82 elsif ($fb eq 'filehandle')
84 $output = new IO::File ">$name" ;
91 my $x = new $CompressClass($output, AutoClose => 1, %headers);
92 isa_ok $x, $CompressClass, ' $x' ;
94 foreach my $buffer (@buffs) {
95 ok $x->write($buffer), " Write OK" ;
96 # this will add an extra "empty" stream
97 ok $x->newStream(), " newStream OK" ;
99 ok $x->close, " Close ok" ;
101 #hexDump($compressed) ;
103 foreach my $unc ($UncompressClass, 'IO::Uncompress::AnyUncompress') {
104 title " Testing $CompressClass with $unc and $i streams, from $fb";
106 if ($fb eq 'filehandle')
108 $cc = new IO::File "<$name" ;
110 my @opts = $unc ne $UncompressClass
113 my $gz = new $unc($cc,
121 isa_ok $gz, $UncompressClass, ' $gz' ;
124 1 while $gz->read($un) > 0 ;
125 #print "[[$un]]\n" while $gz->read($un) > 0 ;
126 ok ! $gz->error(), " ! error()"
127 or diag "Error is " . $gz->error() ;
128 ok $gz->eof(), " eof()";
129 ok $gz->close(), " close() ok"
130 or diag "errno $!\n" ;
132 is $gz->streamCount(), $i +1, " streamCount ok"
133 or diag "Stream count is " . $gz->streamCount();
134 ok $un eq join('', @buffs), " expected output" ;
138 foreach my $unc ($UncompressClass, 'IO::Uncompress::AnyUncompress') {
139 title " Testing $CompressClass with $unc nextStream and $i streams, from $fb";
141 if ($fb eq 'filehandle')
143 $cc = new IO::File "<$name" ;
145 my @opts = $unc ne $UncompressClass
148 my $gz = new $unc($cc,
156 isa_ok $gz, $UncompressClass, ' $gz' ;
158 for my $stream (1 .. $i)
160 my $buff = $buffs[$stream-1];
161 my @lines = split("\n", $buff);
166 while ($_ = $gz->getline()) {
169 is $., $lines, " \$. is $lines";
171 ok ! $gz->error(), " ! error()"
172 or diag "Error is " . $gz->error() ;
173 ok $gz->eof(), " eof()";
174 is $gz->streamCount(), $stream, " streamCount is $stream"
175 or diag "Stream count is " . $gz->streamCount();
176 ok $un eq $buff, " expected output" ;
177 #is $gz->tell(), length $buff, " tell is ok";
178 is $gz->nextStream(), 1, " nextStream ok";
179 is $gz->tell(), 0, " tell is 0";
180 is $., 0, ' $. is 0';
185 #1 while $gz->read($un) > 0 ;
186 is $., 0, " \$. is 0";
188 #print "[[$un]]\n" while $gz->read($un) > 0 ;
189 ok ! $gz->error(), " ! error()"
190 or diag "Error is " . $gz->error() ;
191 ok $gz->eof(), " eof()";
192 is $gz->streamCount(), $i+1, " streamCount is ok"
193 or diag "Stream count is " . $gz->streamCount();
194 ok $un eq "", " expected output" ;
195 is $gz->tell(), 0, " tell is 0";
198 is $gz->nextStream(), 0, " nextStream ok";
199 ok $gz->eof(), " eof()";
200 ok $gz->close(), " close() ok"
201 or diag "errno $!\n" ;
203 is $gz->streamCount(), $i +1, " streamCount ok"
204 or diag "Stream count is " . $gz->streamCount();
213 # corrupt one of the streams - all previous should be ok
215 # check that "tell" works ok