1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
|
use lib 't';
use strict;
use warnings;
use bytes;
use Test::More ;
use CompTestUtils;
BEGIN {
# use Test::NoWarnings, if available
my $extra = 0 ;
$extra = 1
if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
plan tests => 1828 + $extra ;
use_ok('IO::Uncompress::AnyUncompress', qw($AnyUncompressError)) ;
}
sub run
{
my $CompressClass = identify();
my $UncompressClass = getInverse($CompressClass);
my $Error = getErrorRef($CompressClass);
my $UnError = getErrorRef($UncompressClass);
my @buffers ;
push @buffers, <<EOM ;
hello world
this is a test
some more stuff on this line
ad finally...
EOM
push @buffers, <<EOM ;
some more stuff
line 2
EOM
push @buffers, <<EOM ;
even more stuff
EOM
my $b0length = length $buffers[0];
my $bufcount = @buffers;
{
my $cc ;
my $gz ;
my $hsize ;
my %headers = () ;
foreach my $fb ( qw( file filehandle buffer ) )
{
foreach my $i (1 .. @buffers) {
title "Testing $CompressClass with $i streams to $fb";
my @buffs = @buffers[0..$i -1] ;
if ($CompressClass eq 'IO::Compress::Gzip') {
%headers = (
Strict => 1,
Comment => "this is a comment",
ExtraField => ["so" => "me extra"],
HeaderCRC => 1);
}
my $lex = new LexFile my $name ;
my $output ;
if ($fb eq 'buffer')
{
my $compressed = '';
$output = \$compressed;
}
elsif ($fb eq 'filehandle')
{
$output = new IO::File ">$name" ;
}
else
{
$output = $name ;
}
my $x = new $CompressClass($output, AutoClose => 1, %headers);
isa_ok $x, $CompressClass, ' $x' ;
foreach my $buffer (@buffs) {
ok $x->write($buffer), " Write OK" ;
# this will add an extra "empty" stream
ok $x->newStream(), " newStream OK" ;
}
ok $x->close, " Close ok" ;
foreach my $unc ($UncompressClass, 'IO::Uncompress::AnyUncompress') {
title " Testing $CompressClass with $unc and $i streams, from $fb";
$cc = $output ;
if ($fb eq 'filehandle')
{
$cc = new IO::File "<$name" ;
}
my @opts = $unc ne $UncompressClass
? (RawInflate => 1)
: ();
my $gz = new $unc($cc,
@opts,
Strict => 1,
AutoClose => 1,
Append => 1,
MultiStream => 1,
Transparent => 0)
or diag $$UnError;
isa_ok $gz, $UncompressClass, ' $gz' ;
my $un = '';
1 while $gz->read($un) > 0 ;
#print "[[$un]]\n" while $gz->read($un) > 0 ;
ok ! $gz->error(), " ! error()"
or diag "Error is " . $gz->error() ;
ok $gz->eof(), " eof()";
ok $gz->close(), " close() ok"
or diag "errno $!\n" ;
is $gz->streamCount(), $i +1, " streamCount ok " . ($i +1)
or diag "Stream count is " . $gz->streamCount();
ok $un eq join('', @buffs), " expected output" ;
}
foreach my $unc ($UncompressClass, 'IO::Uncompress::AnyUncompress') {
foreach my $blk (1, 20, $b0length - 1, $b0length, $b0length +1) {
title " Testing $CompressClass with $unc, BlockSize $blk and $i streams, from $fb";
$cc = $output ;
if ($fb eq 'filehandle')
{
$cc = new IO::File "<$name" ;
}
my @opts = $unc ne $UncompressClass
? (RawInflate => 1)
: ();
my $gz = new $unc($cc,
@opts,
Strict => 1,
AutoClose => 1,
Append => 1,
MultiStream => 1,
Transparent => 0)
or diag $$UnError;
isa_ok $gz, $UncompressClass, ' $gz' ;
my $un = '';
my $b = $blk;
# Want the first read to be in the middle of a stream
# and the second to cross a stream boundary
$b = 1000 while $gz->read($un, $b) > 0 ;
#print "[[$un]]\n" while $gz->read($un) > 0 ;
ok ! $gz->error(), " ! error()"
or diag "Error is " . $gz->error() ;
ok $gz->eof(), " eof()";
ok $gz->close(), " close() ok"
or diag "errno $!\n" ;
is $gz->streamCount(), $i +1, " streamCount ok " . ($i +1)
or diag "Stream count is " . $gz->streamCount();
ok $un eq join('', @buffs), " expected output" ;
}
}
foreach my $unc ($UncompressClass, 'IO::Uncompress::AnyUncompress') {
foreach my $trans (0, 1) {
title " Testing $CompressClass with $unc nextStream and $i streams, from $fb, Transparent => $trans";
$cc = $output ;
if ($fb eq 'filehandle')
{
$cc = new IO::File "<$name" ;
}
my @opts = $unc ne $UncompressClass
? (RawInflate => 1)
: ();
my $gz = new $unc($cc,
@opts,
Strict => 1,
AutoClose => 1,
Append => 1,
MultiStream => 0,
Transparent => $trans)
or diag $$UnError;
isa_ok $gz, $UncompressClass, ' $gz' ;
for my $stream (1 .. $i)
{
my $buff = $buffs[$stream-1];
my @lines = split("\n", $buff);
my $lines = @lines;
my $un = '';
#while (<$gz>) {
while ($_ = $gz->getline()) {
$un .= $_;
}
is $., $lines, " \$. is $lines";
ok ! $gz->error(), " ! error()"
or diag "Error is " . $gz->error() ;
ok $gz->eof(), " eof()";
is $gz->streamCount(), $stream, " streamCount is $stream"
or diag "Stream count is " . $gz->streamCount();
ok $un eq $buff, " expected output" ;
#is $gz->tell(), length $buff, " tell is ok";
is $gz->nextStream(), 1, " nextStream ok";
is $gz->tell(), 0, " tell is 0";
is $., 0, ' $. is 0';
}
{
my $un = '';
#1 while $gz->read($un) > 0 ;
is $., 0, " \$. is 0";
$gz->read($un) ;
#print "[[$un]]\n" while $gz->read($un) > 0 ;
ok ! $gz->error(), " ! error()"
or diag "Error is " . $gz->error() ;
ok $gz->eof(), " eof()";
is $gz->streamCount(), $i+1, " streamCount is ok"
or diag "Stream count is " . $gz->streamCount();
ok $un eq "", " expected output" ;
is $gz->tell(), 0, " tell is 0";
}
is $gz->nextStream(), 0, " nextStream ok"
or diag $gz->error() ;
ok $gz->eof(), " eof()";
ok $gz->close(), " close() ok"
or diag "errno $!\n" ;
is $gz->streamCount(), $i +1, " streamCount ok"
or diag "Stream count is " . $gz->streamCount();
}
}
}
}
}
}
# corrupt one of the streams - all previous should be ok
# trailing stuff
# check that "tell" works ok
1;
|