diff options
author | Paul Marquess <paul.marquess@btinternet.com> | 2006-03-03 10:25:48 +0000 |
---|---|---|
committer | Steve Peters <steve@fisharerojo.org> | 2006-03-06 02:06:04 +0000 |
commit | 25f0751fb55a0f87a7e18ae8960f9acf2407ae32 (patch) | |
tree | 439063d46a0c0b86716646c06a093caf2f50aa44 /t | |
parent | 274ac62a3e605d66baf0a73d4dde20b3a2ea7120 (diff) | |
download | perl-25f0751fb55a0f87a7e18ae8960f9acf2407ae32.tar.gz |
Compress::Zlib
From: "Paul Marquess" <paul.marquess@ntlworld.com>
Message-ID: <007101c63eac$d919c6c0$4c05140a@myopwv.com>
p4raw-id: //depot/perl@27384
Diffstat (limited to 't')
-rw-r--r-- | t/lib/compress/CompTestUtils.pm | 586 | ||||
-rw-r--r-- | t/lib/compress/any.pl | 2 | ||||
-rw-r--r-- | t/lib/compress/anyunc.pl | 2 | ||||
-rw-r--r-- | t/lib/compress/destroy.pl | 2 | ||||
-rw-r--r-- | t/lib/compress/generic.pl | 61 | ||||
-rw-r--r-- | t/lib/compress/merge.pl | 18 | ||||
-rw-r--r-- | t/lib/compress/multi.pl | 11 | ||||
-rw-r--r-- | t/lib/compress/newtied.pl | 2 | ||||
-rw-r--r-- | t/lib/compress/oneshot.pl | 35 | ||||
-rw-r--r-- | t/lib/compress/prime.pl | 2 | ||||
-rw-r--r-- | t/lib/compress/tied.pl | 4 | ||||
-rw-r--r-- | t/lib/compress/truncate.pl | 125 | ||||
-rw-r--r-- | t/lib/compress/zlib-generic.pl | 4 |
13 files changed, 692 insertions, 162 deletions
diff --git a/t/lib/compress/CompTestUtils.pm b/t/lib/compress/CompTestUtils.pm new file mode 100644 index 0000000000..668d66d90c --- /dev/null +++ b/t/lib/compress/CompTestUtils.pm @@ -0,0 +1,586 @@ +package CompTestUtils; + +package main ; + +use strict ; +use warnings; +use bytes; + +use Carp ; + + +sub title +{ + #diag "" ; + ok 1, $_[0] ; + #diag "" ; +} + +sub like_eval +{ + like $@, @_ ; +} + +{ + package LexFile ; + + our ($index); + $index = '00000'; + + sub new + { + my $self = shift ; + foreach (@_) + { + # autogenerate the name unless if none supplied + $_ = "tst" . $index ++ . ".tmp" + unless defined $_; + } + chmod 0777, @_; + for (@_) { 1 while unlink $_ } ; + bless [ @_ ], $self ; + } + + sub DESTROY + { + my $self = shift ; + chmod 0777, @{ $self } ; + for (@$self) { 1 while unlink $_ } ; + } + +} + +{ + package LexDir ; + + use File::Path; + sub new + { + my $self = shift ; + foreach (@_) { rmtree $_ } + bless [ @_ ], $self ; + } + + sub DESTROY + { + my $self = shift ; + foreach (@$self) { rmtree $_ } + } +} +sub readFile +{ + my $f = shift ; + + my @strings ; + + if (IO::Compress::Base::Common::isaFilehandle($f)) + { + my $pos = tell($f); + seek($f, 0,0); + @strings = <$f> ; + seek($f, 0, $pos); + } + else + { + open (F, "<$f") + or croak "Cannot open $f: $!\n" ; + binmode F; + @strings = <F> ; + close F ; + } + + return @strings if wantarray ; + return join "", @strings ; +} + +sub touch +{ + foreach (@_) { writeFile($_, '') } +} + +sub writeFile +{ + my($filename, @strings) = @_ ; + 1 while unlink $filename ; + open (F, ">$filename") + or croak "Cannot open $filename: $!\n" ; + binmode F; + foreach (@strings) { + no warnings ; + print F $_ ; + } + close F ; +} + +sub GZreadFile +{ + my ($filename) = shift ; + + my ($uncomp) = "" ; + my $line = "" ; + my $fil = gzopen($filename, "rb") + or croak "Cannopt open '$filename': $Compress::Zlib::gzerrno" ; + + $uncomp .= $line + while $fil->gzread($line) > 0; + + $fil->gzclose ; + return $uncomp ; +} + +sub hexDump +{ + my $d = shift ; + + if (IO::Compress::Base::Common::isaFilehandle($d)) + { + $d = readFile($d); + } + elsif (IO::Compress::Base::Common::isaFilename($d)) + { + $d = readFile($d); + } + else + { + $d = $$d ; + } + + my $offset = 0 ; + + $d = '' unless defined $d ; + #while (read(STDIN, $data, 16)) { + while (my $data = substr($d, 0, 16)) { + substr($d, 0, 16) = '' ; + printf "# %8.8lx ", $offset; + $offset += 16; + + my @array = unpack('C*', $data); + foreach (@array) { + printf('%2.2x ', $_); + } + print " " x (16 - @array) + if @array < 16 ; + $data =~ tr/\0-\37\177-\377/./; + print " $data\n"; + } + +} + +sub readHeaderInfo +{ + my $name = shift ; + my %opts = @_ ; + + my $string = <<EOM; +some text +EOM + + ok my $x = new IO::Compress::Gzip $name, %opts + or diag "GzipError is $IO::Compress::Gzip::GzipError" ; + ok $x->write($string) ; + ok $x->close ; + + #is GZreadFile($name), $string ; + + ok my $gunz = new IO::Uncompress::Gunzip $name, Strict => 0 + or diag "GunzipError is $IO::Uncompress::Gunzip::GunzipError" ; + ok my $hdr = $gunz->getHeaderInfo(); + my $uncomp ; + ok $gunz->read($uncomp) ; + ok $uncomp eq $string; + ok $gunz->close ; + + return $hdr ; +} + +sub cmpFile +{ + my ($filename, $uue) = @_ ; + return readFile($filename) eq unpack("u", $uue) ; +} + +sub uncompressBuffer +{ + my $compWith = shift ; + my $buffer = shift ; + + my %mapping = ( 'IO::Compress::Gzip' => 'IO::Uncompress::Gunzip', + 'IO::Compress::Gzip::gzip' => 'IO::Uncompress::Gunzip', + 'IO::Compress::Deflate' => 'IO::Uncompress::Inflate', + 'IO::Compress::Deflate::deflate' => 'IO::Uncompress::Inflate', + 'IO::Compress::RawDeflate' => 'IO::Uncompress::RawInflate', + 'IO::Compress::RawDeflate::rawdeflate' => 'IO::Uncompress::RawInflate', + 'IO::Compress::Bzip2' => 'IO::Uncompress::Bunzip2', + 'IO::Compress::Bzip2::bzip2' => 'IO::Uncompress::Bunzip2', + 'IO::Compress::Zip' => 'IO::Uncompress::Unzip', + 'IO::Compress::Zip::zip' => 'IO::Uncompress::Unzip', + 'IO::Compress::Lzop' => 'IO::Uncompress::UnLzop', + 'IO::Compress::Lzop::lzop' => 'IO::Uncompress::UnLzop', + 'IO::Compress::DummyComp' => 'IO::Uncompress::DummyUncomp', + 'IO::Compress::DummyComp::dummycomp' => 'IO::Uncompress::DummyUncomp', + ); + + my $out ; + my $obj = $mapping{$compWith}->new( \$buffer, -Append => 1); + 1 while $obj->read($out) > 0 ; + return $out ; + +} + +my %ErrorMap = ( 'IO::Compress::Gzip' => \$IO::Compress::Gzip::GzipError, + 'IO::Compress::Gzip::gzip' => \$IO::Compress::Gzip::GzipError, + 'IO::Uncompress::Gunzip' => \$IO::Uncompress::Gunzip::GunzipError, + 'IO::Uncompress::Gunzip::gunzip' => \$IO::Uncompress::Gunzip::GunzipError, + 'IO::Uncompress::Inflate' => \$IO::Uncompress::Inflate::InflateError, + 'IO::Uncompress::Inflate::inflate' => \$IO::Uncompress::Inflate::InflateError, + 'IO::Compress::Deflate' => \$IO::Compress::Deflate::DeflateError, + 'IO::Compress::Deflate::deflate' => \$IO::Compress::Deflate::DeflateError, + 'IO::Uncompress::RawInflate' => \$IO::Uncompress::RawInflate::RawInflateError, + 'IO::Uncompress::RawInflate::rawinflate' => \$IO::Uncompress::RawInflate::RawInflateError, + 'IO::Uncompress::AnyInflate' => \$IO::Uncompress::AnyInflate::AnyInflateError, + 'IO::Uncompress::AnyInflate::anyinflate' => \$IO::Uncompress::AnyInflate::AnyInflateError, + 'IO::Uncompress::AnyUncompress' => \$IO::Uncompress::AnyUncompress::AnyUncompressError, + 'IO::Uncompress::AnyUncompress::anyUncompress' => \$IO::Uncompress::AnyUncompress::AnyUncompressError, + 'IO::Compress::RawDeflate' => \$IO::Compress::RawDeflate::RawDeflateError, + 'IO::Compress::RawDeflate::rawdeflate' => \$IO::Compress::RawDeflate::RawDeflateError, + 'IO::Compress::Bzip2' => \$IO::Compress::Bzip2::Bzip2Error, + 'IO::Compress::Bzip2::bzip2' => \$IO::Compress::Bzip2::Bzip2Error, + 'IO::Uncompress::Bunzip2' => \$IO::Uncompress::Bunzip2::Bunzip2Error, + 'IO::Uncompress::Bunzip2::bunzip2' => \$IO::Uncompress::Bunzip2::Bunzip2Error, + 'IO::Compress::Zip' => \$IO::Compress::Zip::ZipError, + 'IO::Compress::Zip::zip' => \$IO::Compress::Zip::ZipError, + 'IO::Uncompress::Unzip' => \$IO::Uncompress::Unzip::UnzipError, + 'IO::Uncompress::Unzip::unzip' => \$IO::Uncompress::Unzip::UnzipError, + 'IO::Compress::Lzop' => \$IO::Compress::Lzop::LzopError, + 'IO::Compress::Lzop::lzop' => \$IO::Compress::Lzop::LzopError, + 'IO::Uncompress::UnLzop' => \$IO::Uncompress::UnLzop::UnLzopError, + 'IO::Uncompress::UnLzop::unlzop' => \$IO::Uncompress::UnLzop::UnLzopError, + + 'IO::Compress::DummyComp' => \$IO::Compress::DummyComp::DummyCompError, + 'IO::Compress::DummyComp::dummycomp'=> \$IO::Compress::DummyComp::DummyCompError, + 'IO::Uncompress::DummyUncomp' => \$IO::Uncompress::DummyUncomp::DummyUncompError, + 'IO::Uncompress::DummyUncomp::dummyuncomp' => \$IO::Uncompress::DummyUncomp::DummyUncompError, + ); + +my %TopFuncMap = ( 'IO::Compress::Gzip' => 'IO::Compress::Gzip::gzip', + 'IO::Uncompress::Gunzip' => 'IO::Uncompress::Gunzip::gunzip', + + 'IO::Compress::Deflate' => 'IO::Compress::Deflate::deflate', + 'IO::Uncompress::Inflate' => 'IO::Uncompress::Inflate::inflate', + + 'IO::Compress::RawDeflate' => 'IO::Compress::RawDeflate::rawdeflate', + 'IO::Uncompress::RawInflate' => 'IO::Uncompress::RawInflate::rawinflate', + + 'IO::Uncompress::AnyInflate' => 'IO::Uncompress::AnyInflate::anyinflate', + 'IO::Uncompress::AnyUncompress' => 'IO::Uncompress::AnyUncompress::anyuncompress', + + 'IO::Compress::Bzip2' => 'IO::Compress::Bzip2::bzip2', + 'IO::Uncompress::Bunzip2' => 'IO::Uncompress::Bunzip2::bunzip2', + + 'IO::Compress::Zip' => 'IO::Compress::Zip::zip', + 'IO::Uncompress::Unzip' => 'IO::Uncompress::Unzip::unzip', + 'IO::Compress::Lzop' => 'IO::Compress::Lzop::lzop', + 'IO::Uncompress::UnLzop' => 'IO::Uncompress::UnLzop::unlzop', + 'IO::Compress::DummyComp' => 'IO::Compress::DummyComp::dummyuncomp', + 'IO::Uncompress::DummyUncomp' => 'IO::Uncompress::DummyUncomp::dummyuncomp', + ); + + %TopFuncMap = map { ($_ => $TopFuncMap{$_}, + $TopFuncMap{$_} => $TopFuncMap{$_}) } + keys %TopFuncMap ; + + #%TopFuncMap = map { ($_ => \&{ $TopFuncMap{$_} ) } + #keys %TopFuncMap ; + + +my %inverse = ( 'IO::Compress::Gzip' => 'IO::Uncompress::Gunzip', + 'IO::Compress::Gzip::gzip' => 'IO::Uncompress::Gunzip::gunzip', + 'IO::Compress::Deflate' => 'IO::Uncompress::Inflate', + 'IO::Compress::Deflate::deflate' => 'IO::Uncompress::Inflate::inflate', + 'IO::Compress::RawDeflate' => 'IO::Uncompress::RawInflate', + 'IO::Compress::RawDeflate::rawdeflate' => 'IO::Uncompress::RawInflate::rawinflate', + 'IO::Compress::Bzip2::bzip2' => 'IO::Uncompress::Bunzip2::bunzip2', + 'IO::Compress::Bzip2' => 'IO::Uncompress::Bunzip2', + 'IO::Compress::Zip::zip' => 'IO::Uncompress::Unzip::unzip', + 'IO::Compress::Zip' => 'IO::Uncompress::Unzip', + 'IO::Compress::Lzop::lzop' => 'IO::Uncompress::UnLzop::unlzop', + 'IO::Compress::Lzop' => 'IO::Uncompress::UnLzop', + 'IO::Compress::DummyComp::dummycomp' => 'IO::Uncompress::DummyUncomp::dummyuncomp', + 'IO::Compress::DummyComp' => 'IO::Uncompress::DummyUncomp', + ); + +%inverse = map { ($_ => $inverse{$_}, $inverse{$_} => $_) } keys %inverse; + +sub getInverse +{ + my $class = shift ; + + return $inverse{$class} ; +} + +sub getErrorRef +{ + my $class = shift ; + + return $ErrorMap{$class} ; +} + +sub getTopFuncRef +{ + my $class = shift ; + + return \&{ $TopFuncMap{$class} } ; +} + +sub getTopFuncName +{ + my $class = shift ; + + return $TopFuncMap{$class} ; +} + +sub compressBuffer +{ + my $compWith = shift ; + my $buffer = shift ; + + my %mapping = ( 'IO::Uncompress::Gunzip' => 'IO::Compress::Gzip', + 'IO::Uncompress::Gunzip::gunzip' => 'IO::Compress::Gzip', + 'IO::Uncompress::Inflate' => 'IO::Compress::Deflate', + 'IO::Uncompress::Inflate::inflate' => 'IO::Compress::Deflate', + 'IO::Uncompress::RawInflate' => 'IO::Compress::RawDeflate', + 'IO::Uncompress::RawInflate::rawinflate' => 'IO::Compress::RawDeflate', + 'IO::Uncompress::Bunzip2' => 'IO::Compress::Bzip2', + 'IO::Uncompress::Bunzip2::bunzip2' => 'IO::Compress::Bzip2', + 'IO::Uncompress::Unzip' => 'IO::Compress::Zip', + 'IO::Uncompress::Unzip::unzip' => 'IO::Compress::Zip', + 'IO::Uncompress::UnLzop' => 'IO::Compress::Lzop', + 'IO::Uncompress::UnLzop::unlzop' => 'IO::Compress::Lzop', + 'IO::Uncompress::AnyInflate' => 'IO::Compress::Gzip', + 'IO::Uncompress::AnyInflate::anyinflate' => 'IO::Compress::Gzip', + 'IO::Uncompress::AnyUncompress' => 'IO::Compress::Gzip', + 'IO::Uncompress::AnyUncompress::anyuncompress' => 'IO::Compress::Gzip', + 'IO::Uncompress::DummyUncomp' => 'IO::Compress::DummyComp', + 'IO::Uncompress::DummyUncomp::dummyuncomp'=> 'IO::Compress::DummyComp', + ); + + my $out ; + my $obj = $mapping{$compWith}->new( \$out); + $obj->write($buffer) ; + $obj->close(); + return $out ; +} + +our ($AnyUncompressError); +BEGIN +{ + eval { require IO::Uncompress::AnyUncompress ; + import IO::Uncompress::AnyUncompress qw($AnyUncompressError) } ; +} + +sub anyUncompress +{ + my $buffer = shift ; + my $already = shift; + + my @opts = (); + if (ref $buffer && ref $buffer eq 'ARRAY') + { + @opts = @$buffer; + $buffer = shift @opts; + } + + if (ref $buffer) + { + croak "buffer is undef" unless defined $$buffer; + croak "buffer is empty" unless length $$buffer; + + } + + + my $data ; + if (IO::Compress::Base::Common::isaFilehandle($buffer)) + { + $data = readFile($buffer); + } + elsif (IO::Compress::Base::Common::isaFilename($buffer)) + { + $data = readFile($buffer); + } + else + { + $data = $$buffer ; + } + + if (defined $already && length $already) + { + + my $got = substr($data, 0, length($already)); + substr($data, 0, length($already)) = ''; + + is $got, $already, ' Already OK' ; + } + + my $out = ''; + my $o = new IO::Uncompress::AnyUncompress \$data, -Append => 1, Transparent => 0, @opts + or croak "Cannot open buffer/file: $AnyUncompressError" ; + + 1 while $o->read($out) > 0 ; + + croak "Error uncompressing -- " . $o->error() + if $o->error() ; + + return $out ; + +} + +sub getHeaders +{ + my $buffer = shift ; + my $already = shift; + + my @opts = (); + if (ref $buffer && ref $buffer eq 'ARRAY') + { + @opts = @$buffer; + $buffer = shift @opts; + } + + if (ref $buffer) + { + croak "buffer is undef" unless defined $$buffer; + croak "buffer is empty" unless length $$buffer; + + } + + + my $data ; + if (IO::Compress::Base::Common::isaFilehandle($buffer)) + { + $data = readFile($buffer); + } + elsif (IO::Compress::Base::Common::isaFilename($buffer)) + { + $data = readFile($buffer); + } + else + { + $data = $$buffer ; + } + + if (defined $already && length $already) + { + + my $got = substr($data, 0, length($already)); + substr($data, 0, length($already)) = ''; + + is $got, $already, ' Already OK' ; + } + + my $out = ''; + my $o = new IO::Uncompress::AnyUncompress \$data, MultiStream => 1, -Append => 1, Transparent => 0, @opts + or croak "Cannot open buffer/file: $AnyUncompressError" ; + + 1 while $o->read($out) > 0 ; + + croak "Error uncompressing -- " . $o->error() + if $o->error() ; + + return ($o->getHeaderInfo()) ; + +} + +sub mkComplete +{ + my $class = shift ; + my $data = shift; + my $Error = getErrorRef($class); + + my $buffer ; + my %params = (); + + if ($class eq 'IO::Compress::Gzip') { + %params = ( + -Name => "My name", + -Comment => "a comment", + -ExtraField => ['ab' => "extra"], + -HeaderCRC => 1); + } + elsif ($class eq 'IO::Compress::Zip'){ + %params = ( + # TODO -- add more here + -Name => "My name", + -Comment => "a comment", + ); + } + + my $z = new $class( \$buffer, %params) + or croak "Cannot create $class object: $$Error"; + $z->write($data); + $z->close(); + + my $unc = getInverse($class); + anyUncompress(\$buffer) eq $data + or die "bad bad bad"; + my $u = new $unc( \$buffer); + my $info = $u->getHeaderInfo() ; + + + return wantarray ? ($info, $buffer) : $buffer ; +} + +sub mkErr +{ + my $string = shift ; + my ($dummy, $file, $line) = caller ; + -- $line ; + + $file = quotemeta($file); + + return "/$string\\s+at $file line $line/" if $] >= 5.006 ; + return "/$string\\s+at /" ; +} + +sub mkEvalErr +{ + my $string = shift ; + + return "/$string\\s+at \\(eval /" if $] > 5.006 ; + return "/$string\\s+at /" ; +} + +sub dumpObj +{ + my $obj = shift ; + + my ($dummy, $file, $line) = caller ; + + if (@_) + { + print "#\n# dumpOBJ from $file line $line @_\n" ; + } + else + { + print "#\n# dumpOBJ from $file line $line \n" ; + } + + my $max = 0 ;; + foreach my $k (keys %{ *$obj }) + { + $max = length $k if length $k > $max ; + } + + foreach my $k (sort keys %{ *$obj }) + { + my $v = $obj->{$k} ; + $v = '-undef-' unless defined $v; + my $pad = ' ' x ($max - length($k) + 2) ; + print "# $k$pad: [$v]\n"; + } + print "#\n" ; +} + + +package CompTestUtils; + +1; diff --git a/t/lib/compress/any.pl b/t/lib/compress/any.pl index 065fedbb58..74f49254e3 100644 --- a/t/lib/compress/any.pl +++ b/t/lib/compress/any.pl @@ -6,7 +6,7 @@ use warnings; use bytes; use Test::More ; -use ZlibTestUtils; +use CompTestUtils; BEGIN { # use Test::NoWarnings, if available diff --git a/t/lib/compress/anyunc.pl b/t/lib/compress/anyunc.pl index 2d5f166bac..d79ff22bb5 100644 --- a/t/lib/compress/anyunc.pl +++ b/t/lib/compress/anyunc.pl @@ -6,7 +6,7 @@ use warnings; use bytes; use Test::More ; -use ZlibTestUtils; +use CompTestUtils; BEGIN { # use Test::NoWarnings, if available diff --git a/t/lib/compress/destroy.pl b/t/lib/compress/destroy.pl index 6c14bec9ec..9107b15096 100644 --- a/t/lib/compress/destroy.pl +++ b/t/lib/compress/destroy.pl @@ -5,7 +5,7 @@ use warnings; use bytes; use Test::More ; -use ZlibTestUtils; +use CompTestUtils; BEGIN { diff --git a/t/lib/compress/generic.pl b/t/lib/compress/generic.pl index 2c0fead5a3..c10b14fee4 100644 --- a/t/lib/compress/generic.pl +++ b/t/lib/compress/generic.pl @@ -4,7 +4,7 @@ use warnings; use bytes; use Test::More ; -use ZlibTestUtils; +use CompTestUtils; use IO::Handle qw(SEEK_SET SEEK_CUR SEEK_END); @@ -17,15 +17,10 @@ BEGIN my $st = eval { require Test::NoWarnings ; import Test::NoWarnings; 1; }; $extra = 1 if $st ; - - - plan(tests => 564 + $extra) ; + plan(tests => 597 + $extra) ; } - - - sub myGZreadFile { my $filename = shift ; @@ -47,7 +42,6 @@ sub myGZreadFile sub run { - my $CompressClass = identify(); $UncompressClass = getInverse($CompressClass); my $Error = getErrorRef($CompressClass); @@ -176,15 +170,20 @@ EOM { my $x ; ok $x = new $CompressClass $name ; + is $x->autoflush(1), 0, "autoflush"; + is $x->autoflush(1), 1, "autoflush"; + ok $x->opened(), "opened"; ok $x->write($hello), "write" ; ok $x->flush(), "flush"; ok $x->close, "close" ; + ok ! $x->opened(), "! opened"; } { my $uncomp; ok my $x = new $UncompressClass $name, -Append => 1 ; + ok $x->opened(), "opened"; my $len ; 1 while ($len = $x->read($uncomp)) > 0 ; @@ -194,6 +193,7 @@ EOM ok $x->close ; is $uncomp, $hello ; + ok !$x->opened(), "! opened"; } } @@ -284,6 +284,7 @@ EOM my $lex = new LexFile my $name ; + #my $name = "/tmp/fred"; my $hello = <<EOM ; hello world @@ -327,6 +328,7 @@ EOM { my $lex = new LexFile my $name ; + #my $name = "/tmp/fred"; my $hello = <<EOM ; hello world @@ -348,6 +350,8 @@ EOM ok 1, " wrote to stdout" ; } + is myGZreadFile($name), $hello, " wrote OK"; + #hexDump($name); { title "Input from stdin via filename '-'"; @@ -359,7 +363,8 @@ EOM open(SAVEIN, "<&STDIN"); ok open(STDIN, "<$name"), " redirect STDIN"; my $dummy = fileno SAVEIN; - $x = new $UncompressClass '-', Append => 1; + $x = new $UncompressClass '-', Append => 1, Transparent => 0 + or diag $$UnError ; ok $x, " created object" ; is $x->fileno(), $stdinFileno, " fileno ok" ; @@ -376,7 +381,8 @@ EOM # and read back #======================================== - my $name = "test.gz" ; + #my $name = "test.gz" ; + my $lex = new LexFile my $name ; my $hello = <<EOM ; hello world @@ -388,6 +394,8 @@ EOM my $x ; ok $x = new $CompressClass(\$buffer) ; + ok ! defined $x->autoflush(1) ; + ok ! defined $x->autoflush(1) ; ok ! defined $x->fileno() ; is $x->write(''), 0, "Write empty string is ok"; is $x->write(undef), 0, "Write undef is ok"; @@ -405,6 +413,8 @@ EOM my $x ; ok $x = new $UncompressClass(\$buffer, Append => 1) ; + ok ! defined $x->autoflush(1) ; + ok ! defined $x->autoflush(1) ; ok ! defined $x->fileno() ; 1 while $x->read($uncomp) > 0 ; @@ -618,6 +628,8 @@ EOT { my $io = new $UncompressClass $name ; + is $., 0; + is $io->input_line_number, 0; ok ! $io->eof; is $io->tell(), 0 ; #my @lines = <$io>; @@ -627,6 +639,7 @@ EOT is $lines[1], "of a paragraph\n" ; is join('', @lines), $str ; is $., 6; + is $io->input_line_number, 6; is $io->tell(), length($str) ; ok $io->eof; @@ -642,8 +655,12 @@ EOT { local $/; # slurp mode my $io = $UncompressClass->new($name); + is $., 0; + is $io->input_line_number, 0; ok ! $io->eof; my @lines = $io->getlines; + is $., 1; + is $io->input_line_number, 1; ok $io->eof; ok @lines == 1 && $lines[0] eq $str; @@ -657,8 +674,12 @@ EOT { local $/ = ""; # paragraph mode my $io = $UncompressClass->new($name); + is $., 0; + is $io->input_line_number, 0; ok ! $io->eof; my @lines = $io->getlines(); + is $., 2; + is $io->input_line_number, 2; ok $io->eof; ok @lines == 2 or print "# Got " . scalar(@lines) . " lines, expected 2\n" ; @@ -682,6 +703,8 @@ EOT ok $err == 0 ; ok $io->eof; + is $., 3; + is $io->input_line_number, 3; ok @lines == 3 or print "# Got " . scalar(@lines) . " lines, expected 3\n" ; ok join("-", @lines) eq @@ -749,10 +772,11 @@ EOT ok ! $io->eof; ok $io->tell() == 0 ; my @lines = $io->getlines(); - ok @lines == 6; + is @lines, 6; ok $lines[1] eq "of a paragraph\n" ; ok join('', @lines) eq $str ; - ok $. == 6; + is $., 6; + is $io->input_line_number, 6; ok $io->tell() == length($str) ; ok $io->eof; @@ -770,12 +794,16 @@ EOT my $io = $UncompressClass->new($name); ok ! $io->eof; my @lines = $io->getlines; + is $., 1; + is $io->input_line_number, 1; ok $io->eof; ok @lines == 1 && $lines[0] eq $str; $io = $UncompressClass->new($name); ok ! $io->eof; my $line = $io->getline; + is $., 1; + is $io->input_line_number, 1; ok $line eq $str; ok $io->eof; } @@ -785,6 +813,8 @@ EOT my $io = $UncompressClass->new($name); ok ! $io->eof; my @lines = $io->getlines; + is $., 2; + is $io->input_line_number, 2; ok $io->eof; ok @lines == 2 or print "# exected 2 lines, got " . scalar(@lines) . "\n"; @@ -805,9 +835,12 @@ EOT $err++ if $. != ++$no; } + is $., 3; + is $io->input_line_number, 3; ok $err == 0 ; ok $io->eof; + ok @lines == 3 ; ok join("-", @lines) eq "This- is- an example\n" . @@ -960,7 +993,8 @@ EOT ok myGZreadFile($input) eq $first . "\x00" x 10 . $last ; my $io = $UncompressClass->new($input, Strict => 1); - ok $io->seek(length($first), SEEK_CUR) ; + ok $io->seek(length($first), SEEK_CUR) + or diag $$UnError ; ok ! $io->eof; is $io->tell(), length($first); @@ -1416,3 +1450,4 @@ EOT + diff --git a/t/lib/compress/merge.pl b/t/lib/compress/merge.pl index 7def4393f5..a80af9d239 100644 --- a/t/lib/compress/merge.pl +++ b/t/lib/compress/merge.pl @@ -4,14 +4,14 @@ use warnings; use bytes; use Test::More ; -use ZlibTestUtils; +use CompTestUtils; -use Compress::Zlib 2 ; +use Compress::Raw::Zlib 2 ; BEGIN { plan(skip_all => "Merge needs Zlib 1.2.1 or better - you have Zlib " - . Compress::Zlib::zlib_version()) + . Compress::Raw::Zlib::zlib_version()) if ZLIB_VERNUM() < 0x1210 ; # use Test::NoWarnings, if available @@ -36,8 +36,8 @@ sub run # Check zlib_version and ZLIB_VERSION are the same. - is Compress::Zlib::zlib_version, ZLIB_VERSION, - "ZLIB_VERSION matches Compress::Zlib::zlib_version" ; + is Compress::Raw::Zlib::zlib_version, ZLIB_VERSION, + "ZLIB_VERSION matches Compress::Raw::Zlib::zlib_version" ; # Tests # destination is a file that doesn't exist -- should work ok unless AnyDeflate @@ -50,11 +50,11 @@ sub run { title "Misc error cases"; - eval { new Compress::Zlib::InflateScan Bufsize => 0} ; - like $@, mkErr("^Compress::Zlib::InflateScan::new: Bufsize must be >= 1, you specified 0"), " catch bufsize == 0"; + eval { new Compress::Raw::Zlib::InflateScan Bufsize => 0} ; + like $@, mkErr("^Compress::Raw::Zlib::InflateScan::new: Bufsize must be >= 1, you specified 0"), " catch bufsize == 0"; - eval { Compress::Zlib::inflateScanStream::createDeflateStream(undef, Bufsize => 0) } ; - like $@, mkErr("^Compress::Zlib::InflateScan::createDeflateStream: Bufsize must be >= 1, you specified 0"), " catch bufsize == 0"; + eval { Compress::Raw::Zlib::inflateScanStream::createDeflateStream(undef, Bufsize => 0) } ; + like $@, mkErr("^Compress::Raw::Zlib::InflateScan::createDeflateStream: Bufsize must be >= 1, you specified 0"), " catch bufsize == 0"; } diff --git a/t/lib/compress/multi.pl b/t/lib/compress/multi.pl index 8d96e9c207..5409606e93 100644 --- a/t/lib/compress/multi.pl +++ b/t/lib/compress/multi.pl @@ -5,7 +5,7 @@ use warnings; use bytes; use Test::More ; -use ZlibTestUtils; +use CompTestUtils; BEGIN { # use Test::NoWarnings, if available @@ -64,9 +64,9 @@ EOM if ($CompressClass eq 'IO::Compress::Gzip') { %headers = ( - Strict => 0, + Strict => 1, Comment => "this is a comment", - ExtraField => "some extra", + ExtraField => ["so" => "me extra"], HeaderCRC => 1); } @@ -107,11 +107,12 @@ EOM $cc = new IO::File "<$name" ; } my $gz = new $unc($cc, - Strict => 0, + Strict => 1, AutoClose => 1, Append => 1, MultiStream => 1, - Transparent => 0); + Transparent => 0) + or diag $$UnError; isa_ok $gz, $UncompressClass, ' $gz' ; my $un = ''; diff --git a/t/lib/compress/newtied.pl b/t/lib/compress/newtied.pl index e31019691f..395039bb1e 100644 --- a/t/lib/compress/newtied.pl +++ b/t/lib/compress/newtied.pl @@ -4,7 +4,7 @@ use warnings; use bytes; use Test::More ; -use ZlibTestUtils; +use CompTestUtils; our ($BadPerl, $UncompressClass); diff --git a/t/lib/compress/oneshot.pl b/t/lib/compress/oneshot.pl index 048006c049..8cc9e22660 100644 --- a/t/lib/compress/oneshot.pl +++ b/t/lib/compress/oneshot.pl @@ -4,7 +4,7 @@ use warnings; use bytes; use Test::More ; -use ZlibTestUtils; +use CompTestUtils; BEGIN { plan(skip_all => "oneshot needs Perl 5.005 or better - you have Perl $]" ) @@ -18,7 +18,7 @@ BEGIN { plan tests => 944 + $extra ; - use_ok('IO::Uncompress::AnyInflate', qw(anyinflate $AnyInflateError)) ; + use_ok('IO::Uncompress::AnyUncompress', qw(anyuncompress $AnyUncompressError)) ; } @@ -34,7 +34,7 @@ sub run foreach my $bit ($CompressClass, $UncompressClass, - 'IO::Uncompress::AnyInflate', + 'IO::Uncompress::AnyUncompress', ) { my $Error = getErrorRef($bit); @@ -136,7 +136,7 @@ sub run } foreach my $bit ($UncompressClass, - 'IO::Uncompress::AnyInflate', + 'IO::Uncompress::AnyUncompress', ) { my $Error = getErrorRef($bit); @@ -199,8 +199,8 @@ sub run #is $result, $data, " data ok"; - ok ! anyinflate(\$out => \$result, Transparent => 0), " anyinflate ok"; - ok $AnyInflateError, " Got error '$AnyInflateError'" ; + ok ! anyuncompress(\$out => \$result, Transparent => 0), "anyuncompress ok"; + ok $AnyUncompressError, " Got error '$AnyUncompressError'" ; } @@ -852,7 +852,7 @@ sub run } foreach my $bit ($UncompressClass, - 'IO::Uncompress::AnyInflate', + 'IO::Uncompress::AnyUncompress', ) { my $Error = getErrorRef($bit); @@ -863,8 +863,8 @@ sub run my $buffer2 = "ABCDE" ; my $keep_orig = $buffer; - my $comp = compressBuffer($TopType, $buffer) ; - my $comp2 = compressBuffer($TopType, $buffer2) ; + my $comp = compressBuffer(getTopFuncName($UncompressClass), $buffer) ; + my $comp2 = compressBuffer(getTopFuncName($UncompressClass), $buffer2) ; my $keep_comp = $comp; my $incumbent = "incumbent data" ; @@ -1149,7 +1149,7 @@ sub run } foreach my $bit ($UncompressClass, - 'IO::Uncompress::AnyInflate', + 'IO::Uncompress::AnyUncompress', ) { # TODO -- Add Append mode tests @@ -1161,18 +1161,17 @@ sub run my $buffer = "abcde" ; my $keep_orig = $buffer; - - my $null = compressBuffer($TopType, "") ; - my $undef = compressBuffer($TopType, undef) ; - my $comp = compressBuffer($TopType, $buffer) ; + my $null = compressBuffer(getTopFuncName($UncompressClass), "") ; + my $undef = compressBuffer(getTopFuncName($UncompressClass), undef) ; + my $comp = compressBuffer(getTopFuncName($UncompressClass), $buffer) ; my $keep_comp = $comp; my $incumbent = "incumbent data" ; my $lex = new LexFile(my $file1, my $file2) ; - writeFile($file1, compressBuffer($TopType,"data1")); - writeFile($file2, compressBuffer($TopType,"data2")); + writeFile($file1, compressBuffer(getTopFuncName($UncompressClass),"data1")); + writeFile($file2, compressBuffer(getTopFuncName($UncompressClass),"data2")); my $of = new IO::File "<$file1" ; ok $of, " Created output filehandle" ; @@ -1233,7 +1232,7 @@ sub run } foreach my $bit ($UncompressClass, - 'IO::Uncompress::AnyInflate', + 'IO::Uncompress::AnyUncompress', ) { # TODO -- Add Append mode tests @@ -1253,7 +1252,7 @@ sub run #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist"; my @files = map { "$tmpDir1/$_.tmp" } qw( a1 a2 a3) ; - foreach (@files) { writeFile($_, compressBuffer($TopType, "abc $_")) } + foreach (@files) { writeFile($_, compressBuffer(getTopFuncName($UncompressClass), "abc $_")) } my @expected = map { "abc $_" } @files ; my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ; diff --git a/t/lib/compress/prime.pl b/t/lib/compress/prime.pl index 2c3718029b..4e804e5b00 100644 --- a/t/lib/compress/prime.pl +++ b/t/lib/compress/prime.pl @@ -5,7 +5,7 @@ use warnings; use bytes; use Test::More ; -use ZlibTestUtils; +use CompTestUtils; our ($extra); diff --git a/t/lib/compress/tied.pl b/t/lib/compress/tied.pl index e84a053d00..2dd52c6add 100644 --- a/t/lib/compress/tied.pl +++ b/t/lib/compress/tied.pl @@ -5,7 +5,7 @@ use warnings; use bytes; use Test::More ; -use ZlibTestUtils; +use CompTestUtils; our ($BadPerl, $UncompressClass); @@ -31,7 +31,7 @@ BEGIN plan tests => $tests + $extra ; - use_ok('Compress::Zlib', 2) ; + use_ok('Compress::Raw::Zlib') ; } diff --git a/t/lib/compress/truncate.pl b/t/lib/compress/truncate.pl index 55e4719f44..a8f022416a 100644 --- a/t/lib/compress/truncate.pl +++ b/t/lib/compress/truncate.pl @@ -5,17 +5,7 @@ use warnings; use bytes; use Test::More ; -use ZlibTestUtils; - -BEGIN { - # use Test::NoWarnings, if available - my $extra = 0 ; - $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; - - plan tests => 2374 + $extra; - -} +use CompTestUtils; sub run { @@ -53,7 +43,7 @@ EOM { my $lex = new LexFile my $name ; - title "Fingerprint Truncation - length $i"; + title "Fingerprint Truncation - length $i, Transparent $trans"; my $part = substr($compressed, 0, $i); writeFile($name, $part); @@ -65,7 +55,7 @@ EOM ok $gz; ok ! $gz->error() ; my $buff ; - ok $gz->read($buff) == length($part) ; + is $gz->read($buff), length($part) ; ok $buff eq $part ; ok $gz->eof() ; $gz->close(); @@ -84,7 +74,7 @@ EOM { my $lex = new LexFile my $name ; - title "Header Truncation - length $i"; + title "Header Truncation - length $i, Transparent $trans"; my $part = substr($compressed, 0, $i); writeFile($name, $part); @@ -97,21 +87,26 @@ EOM foreach my $i ($header_size .. length($compressed) - 1 - $trailer_size) { + next if $i == 0 ; + my $lex = new LexFile my $name ; - title "Compressed Data Truncation - length $i"; + title "Compressed Data Truncation - length $i, Transparent $trans"; my $part = substr($compressed, 0, $i); writeFile($name, $part); ok my $gz = new $UncompressClass $name, + -Strict => 1, -BlockSize => $blocksize, - -Transparent => $trans; + -Transparent => $trans + or diag $$UnError; + my $un ; - my $status = 0 ; - $status = $gz->read($un) while $status >= 0 ; - ok $status < 0 ; - ok $gz->eof() ; + my $status = 1 ; + $status = $gz->read($un) while $status > 0 ; + cmp_ok $status, "<", 0 ; ok $gz->error() ; + ok $gz->eof() ; $gz->close(); } @@ -125,7 +120,7 @@ EOM { my $lex = new LexFile my $name ; - ok 1, "Length $i, Lax $lax" ; + ok 1, "Compressed Trailer Truncation - Length $i, Lax $lax, Transparent $trans" ; my $part = substr($compressed, 0, $i); writeFile($name, $part); ok my $gz = new $UncompressClass $name, @@ -148,7 +143,7 @@ EOM } else { - ok $status < 0 + cmp_ok $status, "<", 0 or diag "Status $status Error is " . $gz->error() ; ok $gz->eof() or diag "Status $status Error is " . $gz->error() ; @@ -163,89 +158,3 @@ EOM 1; -__END__ - - -foreach my $CompressClass ( 'IO::Compress::RawDeflate') -{ - my $UncompressClass = getInverse($CompressClass); - my $Error = getErrorRef($UncompressClass); - - my $compressed ; - ok( my $x = new IO::Compress::RawDeflate \$compressed); - ok $x->write($hello) ; - ok $x->close ; - - - my $cc = $compressed ; - - my $gz ; - ok($gz = new $UncompressClass(\$cc, - -Transparent => 0)) - or diag "$$Error\n"; - my $un; - ok $gz->read($un) > 0 ; - ok $gz->close(); - ok $un eq $hello ; - - for my $trans (0 .. 1) - { - title "Testing $CompressClass, Transparent = $trans"; - - my $info = $gz->getHeaderInfo() ; - my $header_size = $info->{HeaderLength}; - my $trailer_size = $info->{TrailerLength}; - ok 1, "Compressed size is " . length($compressed) ; - ok 1, "Header size is $header_size" ; - ok 1, "Trailer size is $trailer_size" ; - - - title "Compressed Data Truncation"; - foreach my $i (0 .. $blocksize) - { - - my $lex = new LexFile my $name ; - - ok 1, "Length $i" ; - my $part = substr($compressed, 0, $i); - writeFile($name, $part); - my $gz = new $UncompressClass $name, - -BlockSize => $blocksize, - -Transparent => $trans; - if ($trans) { - ok $gz; - ok ! $gz->error() ; - my $buff = ''; - is $gz->read($buff), length $part ; - is $buff, $part ; - ok $gz->eof() ; - $gz->close(); - } - else { - ok !$gz; - } - } - - foreach my $i ($blocksize+1 .. length($compressed)-1) - { - - my $lex = new LexFile my $name ; - - ok 1, "Length $i" ; - my $part = substr($compressed, 0, $i); - writeFile($name, $part); - ok my $gz = new $UncompressClass $name, - -BlockSize => $blocksize, - -Transparent => $trans; - my $un ; - my $status = 0 ; - $status = $gz->read($un) while $status >= 0 ; - ok $status < 0 ; - ok $gz->eof() ; - ok $gz->error() ; - $gz->close(); - } - } - -} - diff --git a/t/lib/compress/zlib-generic.pl b/t/lib/compress/zlib-generic.pl index 05b0de9bca..94e5da9f72 100644 --- a/t/lib/compress/zlib-generic.pl +++ b/t/lib/compress/zlib-generic.pl @@ -4,7 +4,7 @@ use warnings; use bytes; use Test::More ; -use ZlibTestUtils; +use CompTestUtils; BEGIN { @@ -23,7 +23,7 @@ my $UncompressClass = getInverse($CompressClass); my $Error = getErrorRef($CompressClass); my $UnError = getErrorRef($UncompressClass); -use Compress::Zlib; +use Compress::Raw::Zlib; use IO::Handle qw(SEEK_SET SEEK_CUR SEEK_END); sub myGZreadFile |