diff options
Diffstat (limited to 'cpan/IO-Zlib/t')
-rw-r--r-- | cpan/IO-Zlib/t/basic.t | 46 | ||||
-rw-r--r-- | cpan/IO-Zlib/t/external.t | 142 | ||||
-rw-r--r-- | cpan/IO-Zlib/t/getc.t | 32 | ||||
-rw-r--r-- | cpan/IO-Zlib/t/getline.t | 57 | ||||
-rw-r--r-- | cpan/IO-Zlib/t/import.t | 13 | ||||
-rw-r--r-- | cpan/IO-Zlib/t/large.t | 35 | ||||
-rw-r--r-- | cpan/IO-Zlib/t/tied.t | 37 | ||||
-rw-r--r-- | cpan/IO-Zlib/t/uncomp1.t | 45 | ||||
-rw-r--r-- | cpan/IO-Zlib/t/uncomp2.t | 45 |
9 files changed, 452 insertions, 0 deletions
diff --git a/cpan/IO-Zlib/t/basic.t b/cpan/IO-Zlib/t/basic.t new file mode 100644 index 0000000000..80aed9c60b --- /dev/null +++ b/cpan/IO-Zlib/t/basic.t @@ -0,0 +1,46 @@ +use IO::Zlib; + +sub ok +{ + my ($no, $ok) = @_ ; + + #++ $total ; + #++ $totalBad unless $ok ; + + print "ok $no\n" if $ok ; + print "not ok $no\n" unless $ok ; +} + +$name="test.gz"; + +print "1..17\n"; + +$hello = <<EOM ; +hello world +this is a test +EOM + +ok(1, $file = IO::Zlib->new($name, "wb")); +ok(2, $file->print($hello)); +ok(3, $file->opened()); +ok(4, $file->close()); +ok(5, !$file->opened()); + +ok(6, $file = IO::Zlib->new()); +ok(7, $file->open($name, "rb")); +ok(8, !$file->eof()); +ok(9, $file->read($uncomp, 1024) == length($hello)); +ok(10, $uncomp eq $hello); +ok(11, $file->eof()); +ok(12, $file->opened()); +ok(13, $file->close()); +ok(14, !$file->opened()); + +$file = IO::Zlib->new($name, "rb"); +ok(15, $file->read($uncomp, 1024, length($uncomp)) == length($hello)); +ok(16, $uncomp eq $hello . $hello); +$file->close(); + +unlink($name); + +ok(17, !defined(IO::Zlib->new($name, "rb"))); diff --git a/cpan/IO-Zlib/t/external.t b/cpan/IO-Zlib/t/external.t new file mode 100644 index 0000000000..1d90d7fe2c --- /dev/null +++ b/cpan/IO-Zlib/t/external.t @@ -0,0 +1,142 @@ +# Test this only iff we have an executable /usr/bin/gzip +# AND we have /usr/bin in our PATH +# AND we have a useable /usr/bin directory. +# This limits the testing to UNIX-like +# systems but that should be enough. + +my $gzip = "/usr/bin/gzip"; + +unless( -x $gzip && + ":$ENV{PATH}:" =~ m!:/usr/bin:! && + -d "/usr/bin" && -x "/usr/bin") { + print "1..0 # Skip: no $gzip\n"; + exit 0; +} + +sub ok +{ + my ($no, $ok) = @_ ; + print "ok $no\n" if $ok ; + print "not ok $no\n" unless $ok ; +} + +my $hasCompressZlib; + +BEGIN { + eval { require Compress::Zlib }; + $hasCompressZlib = $@ ? 0 : 1; +} + +use IO::Zlib; + +print "1..33\n"; + +# Other export functionality (none) is tested in import.t. + +ok(1, + $hasCompressZlib == IO::Zlib::has_Compress_Zlib()); + +eval "use IO::Zlib qw(:gzip_external)"; +ok(2, + $@ =~ /^IO::Zlib::import: ':gzip_external' requires an argument /); + +eval "use IO::Zlib"; +ok(3, !$@); + +ok(4, + $hasCompressZlib || IO::Zlib::gzip_used()); + +ok(5, + !defined IO::Zlib::gzip_external()); + +ok(6, + IO::Zlib::gzip_read_open() eq 'gzip -dc %s |'); + +ok(7, + IO::Zlib::gzip_write_open() eq '| gzip > %s'); + +ok(8, + ($hasCompressZlib && \&IO::Zlib::gzopen == \&Compress::Zlib::gzopen) || + \&IO::Zlib::gzopen == \&IO::Zlib::gzopen_external); + +eval "use IO::Zlib qw(:gzip_external 0)"; + +ok(9, + !IO::Zlib::gzip_external()); + +ok(10, + ($hasCompressZlib && \&IO::Zlib::gzopen == \&Compress::Zlib::gzopen) || + (!$hasCompressZlib && + $@ =~ /^IO::Zlib::import: no Compress::Zlib and no external gzip /)); + +eval "use IO::Zlib qw(:gzip_external 1)"; + +ok(11, + IO::Zlib::gzip_used()); + +ok(12, + IO::Zlib::gzip_external()); + +ok(13, + \&IO::Zlib::gzopen == \&IO::Zlib::gzopen_external); + +eval 'IO::Zlib->new("foo", "xyz")'; +ok(14, $@ =~ /^IO::Zlib::gzopen_external: mode 'xyz' is illegal /); + +# The following is a copy of the basic.t, shifted up by 14 tests, +# the difference being that now we should be using the external gzip. + +$name="test.gz"; + +$hello = <<EOM ; +hello world +this is a test +EOM + +ok(15, $file = IO::Zlib->new($name, "wb")); +ok(16, $file->print($hello)); +ok(17, $file->opened()); +ok(18, $file->close()); +ok(19, !$file->opened()); + +ok(20, $file = IO::Zlib->new()); +ok(21, $file->open($name, "rb")); +ok(22, !$file->eof()); +ok(23, $file->read($uncomp, 1024) == length($hello)); +ok(24, $file->eof()); +ok(25, $file->opened()); +ok(26, $file->close()); +ok(27, !$file->opened()); + +unlink($name); + +ok(28, $hello eq $uncomp); + +ok(29, !defined(IO::Zlib->new($name, "rb"))); + +# Then finally test modifying the open commands. + +my $new_read = 'gzip.exe /d /c %s |'; + +eval "use IO::Zlib ':gzip_read_open' => '$new_read'"; + +ok(30, + IO::Zlib::gzip_read_open() eq $new_read); + +eval "use IO::Zlib ':gzip_read_open' => 'bad'"; + +ok(31, + $@ =~ /^IO::Zlib::import: ':gzip_read_open' 'bad' is illegal /); + +my $new_write = '| gzip.exe %s'; + +eval "use IO::Zlib ':gzip_write_open' => '$new_write'"; + +ok(32, + IO::Zlib::gzip_write_open() eq $new_write); + +eval "use IO::Zlib ':gzip_write_open' => 'bad'"; + +ok(33, + $@ =~ /^IO::Zlib::import: ':gzip_write_open' 'bad' is illegal /); + diff --git a/cpan/IO-Zlib/t/getc.t b/cpan/IO-Zlib/t/getc.t new file mode 100644 index 0000000000..2424d5b245 --- /dev/null +++ b/cpan/IO-Zlib/t/getc.t @@ -0,0 +1,32 @@ +use IO::Zlib; + +sub ok +{ + my ($no, $ok) = @_ ; + + #++ $total ; + #++ $totalBad unless $ok ; + + print "ok $no\n" if $ok ; + print "not ok $no\n" unless $ok ; +} + +$name="test.gz"; + +print "1..10\n"; + +$text = "abcd"; + +ok(1, $file = IO::Zlib->new($name, "wb")); +ok(2, $file->print($text)); +ok(3, $file->close()); + +ok(4, $file = IO::Zlib->new($name, "rb")); +ok(5, $file->getc() eq substr($text,0,1)); +ok(6, $file->getc() eq substr($text,1,1)); +ok(7, $file->getc() eq substr($text,2,1)); +ok(8, $file->getc() eq substr($text,3,1)); +ok(9, $file->getc() eq ""); +ok(10, $file->close()); + +unlink($name); diff --git a/cpan/IO-Zlib/t/getline.t b/cpan/IO-Zlib/t/getline.t new file mode 100644 index 0000000000..fed17dac11 --- /dev/null +++ b/cpan/IO-Zlib/t/getline.t @@ -0,0 +1,57 @@ +use IO::Zlib; + +sub ok +{ + my ($no, $ok) = @_ ; + + #++ $total ; + #++ $totalBad unless $ok ; + + print "ok $no\n" if $ok ; + print "not ok $no\n" unless $ok ; +} + +$name="test.gz"; + +print "1..23\n"; + +@text = (<<EOM, <<EOM, <<EOM, <<EOM) ; +this is line 1 +EOM +the second line +EOM +the line after the previous line +EOM +the final line +EOM + +$text = join("", @text) ; + +ok(1, $file = IO::Zlib->new($name, "wb")); +ok(2, $file->print($text)); +ok(3, $file->close()); + +ok(4, $file = IO::Zlib->new($name, "rb")); +ok(5, !$file->eof()); +ok(6, $file->getline() eq $text[0]); +ok(7, $file->getline() eq $text[1]); +ok(8, $file->getline() eq $text[2]); +ok(9, $file->getline() eq $text[3]); +ok(10, !defined($file->getline())); +ok(11, $file->eof()); +ok(12, $file->close()); + +ok(13, $file = IO::Zlib->new($name, "rb")); +ok(14, !$file->eof()); +eval '$file->getlines'; +ok(15, $@ =~ /^IO::Zlib::getlines: must be called in list context /); +ok(16, @lines = $file->getlines()); +ok(17, @lines == @text); +ok(18, $lines[0] eq $text[0]); +ok(19, $lines[1] eq $text[1]); +ok(20, $lines[2] eq $text[2]); +ok(21, $lines[3] eq $text[3]); +ok(22, $file->eof()); +ok(23, $file->close()); + +unlink($name); diff --git a/cpan/IO-Zlib/t/import.t b/cpan/IO-Zlib/t/import.t new file mode 100644 index 0000000000..336d80a943 --- /dev/null +++ b/cpan/IO-Zlib/t/import.t @@ -0,0 +1,13 @@ +print "1..1\n"; + +sub ok +{ + my ($no, $ok) = @_ ; + print "ok $no\n" if $ok ; + print "not ok $no\n" unless $ok ; +} + +# The :gzip tags are tested in external.t. + +eval "use IO::Zlib qw(foo bar)"; +ok(1, $@ =~ /^IO::Zlib::import: 'foo bar' is illegal /); diff --git a/cpan/IO-Zlib/t/large.t b/cpan/IO-Zlib/t/large.t new file mode 100644 index 0000000000..0203182004 --- /dev/null +++ b/cpan/IO-Zlib/t/large.t @@ -0,0 +1,35 @@ +use IO::Zlib; + +sub ok +{ + my ($no, $ok) = @_ ; + + #++ $total ; + #++ $totalBad unless $ok ; + + print "ok $no\n" if $ok ; + print "not ok $no\n" unless $ok ; +} + +$name="test.gz"; + +print "1..7\n"; + +$contents = ""; + +foreach (1 .. 5000) +{ + $contents .= chr(int(rand(255))); +} + +ok(1, $file = IO::Zlib->new($name, "wb")); +ok(2, $file->print($contents)); +ok(3, $file->close()); + +ok(4, $file = IO::Zlib->new($name, "rb")); +ok(5, $file->read($uncomp, 8192) == length($contents)); +ok(6, $file->close()); + +unlink($name); + +ok(7, $contents eq $uncomp); diff --git a/cpan/IO-Zlib/t/tied.t b/cpan/IO-Zlib/t/tied.t new file mode 100644 index 0000000000..029b282721 --- /dev/null +++ b/cpan/IO-Zlib/t/tied.t @@ -0,0 +1,37 @@ +use IO::Zlib; + +sub ok +{ + my ($no, $ok) = @_ ; + + #++ $total ; + #++ $totalBad unless $ok ; + + print "ok $no\n" if $ok ; + print "not ok $no\n" unless $ok ; +} + +$name="test.gz"; + +print "1..11\n"; + +$hello = <<EOM ; +hello world +this is a test +EOM + +ok(1, tie *OUT, "IO::Zlib", $name, "wb"); +ok(2, printf OUT "%s - %d\n", "hello", 123); +ok(3, print OUT $hello); +ok(4, untie *OUT); + +ok(5, tie *IN, "IO::Zlib", $name, "rb"); +ok(6, !eof IN); +ok(7, <IN> eq "hello - 123\n"); +ok(8, read(IN, $uncomp, 1024) == length($hello)); +ok(9, eof IN); +ok(10, untie *IN); + +unlink($name); + +ok(11, $hello eq $uncomp); diff --git a/cpan/IO-Zlib/t/uncomp1.t b/cpan/IO-Zlib/t/uncomp1.t new file mode 100644 index 0000000000..884af47bb7 --- /dev/null +++ b/cpan/IO-Zlib/t/uncomp1.t @@ -0,0 +1,45 @@ +use IO::Zlib; + +sub ok +{ + my ($no, $ok) = @_ ; + + #++ $total ; + #++ $totalBad unless $ok ; + + print "ok $no\n" if $ok ; + print "not ok $no\n" unless $ok ; +} + +print "1..10\n"; + +$hello = <<EOM ; +hello world +this is a test +EOM + +$name = "test$$"; + +if (open(FH, ">$name")) { + binmode FH; + print FH $hello; + close FH; +} else { + die "$name: $!"; +} + +ok(1, $file = IO::Zlib->new()); +ok(2, $file->open($name, "rb")); +ok(3, !$file->eof()); +ok(4, $file->read($uncomp, 1024) == length($hello)); +ok(5, $file->eof()); +ok(6, $file->opened()); +ok(7, $file->close()); +ok(8, !$file->opened()); + +unlink($name); + +ok(9, $hello eq $uncomp); + +ok(10, !defined(IO::Zlib->new($name, "rb"))); + diff --git a/cpan/IO-Zlib/t/uncomp2.t b/cpan/IO-Zlib/t/uncomp2.t new file mode 100644 index 0000000000..e760fded40 --- /dev/null +++ b/cpan/IO-Zlib/t/uncomp2.t @@ -0,0 +1,45 @@ +require IO::Zlib; # uncomp2.t is like uncomp1.t but without 'use' + +sub ok +{ + my ($no, $ok) = @_ ; + + #++ $total ; + #++ $totalBad unless $ok ; + + print "ok $no\n" if $ok ; + print "not ok $no\n" unless $ok ; +} + +print "1..10\n"; + +$hello = <<EOM ; +hello world +this is a test +EOM + +$name = "test$$"; + +if (open(FH, ">$name")) { + binmode FH; + print FH $hello; + close FH; +} else { + die "$name: $!"; +} + +ok(1, $file = IO::Zlib->new()); +ok(2, $file->open($name, "rb")); +ok(3, !$file->eof()); +ok(4, $file->read($uncomp, 1024) == length($hello)); +ok(5, $file->eof()); +ok(6, $file->opened()); +ok(7, $file->close()); +ok(8, !$file->opened()); + +unlink($name); + +ok(9, $hello eq $uncomp); + +ok(10, !defined(IO::Zlib->new($name, "rb"))); + |