20 plan(skip_all => "Tied Filehandle needs Perl 5.005 or better" )
23 # use Test::NoWarnings, if available
26 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
29 $BadPerl = ($] >= 5.006 or $] <= 5.008) ;
38 plan tests => $tests + $extra ;
40 use_ok('Compress::Zlib', 2) ;
42 use_ok('IO::Compress::Gzip', qw($GzipError)) ;
43 use_ok('IO::Uncompress::Gunzip', qw($GunzipError)) ;
45 use_ok('IO::Compress::Deflate', qw($DeflateError)) ;
46 use_ok('IO::Uncompress::Inflate', qw($InflateError)) ;
48 use_ok('IO::Compress::RawDeflate', qw($RawDeflateError)) ;
49 use_ok('IO::Uncompress::RawInflate', qw($RawInflateError)) ;
53 use IO::Handle qw(SEEK_SET SEEK_CUR SEEK_END);
58 our ($UncompressClass);
63 my $filename = shift ;
67 my $fil = new $UncompressClass $filename,
73 $data = $init if defined $init ;
74 1 while $fil->read($data) > 0;
80 # Check zlib_version and ZLIB_VERSION are the same.
81 is Compress::Zlib::zlib_version, ZLIB_VERSION,
82 "ZLIB_VERSION matches Compress::Zlib::zlib_version" ;
86 foreach my $CompressClass ('IO::Compress::Gzip',
87 'IO::Compress::Deflate',
88 'IO::Compress::RawDeflate')
93 title "Testing $CompressClass";
97 my $gz = new $CompressClass(\$x);
102 like $@, mkErr("^getc Not Available: File opened only for output");
104 eval { read($gz, $buff, 1) } ;
105 like $@, mkErr("^read Not Available: File opened only for output");
108 like $@, mkErr("^readline Not Available: File opened only for output");
112 foreach my $CompressClass ('IO::Compress::Gzip',
113 'IO::Compress::Deflate',
114 'IO::Compress::RawDeflate')
117 $UncompressClass = getInverse($CompressClass);
119 title "Testing $UncompressClass";
122 my $guz = new $CompressClass(\$gc);
127 my $gz = new $UncompressClass(\$gc);
131 eval { print $gz "abc" } ;
132 like $@, mkErr("^print Not Available: File opened only for intput");
134 eval { printf $gz "fmt", "abc" } ;
135 like $@, mkErr("^printf Not Available: File opened only for intput");
137 #eval { write($gz, $buff, 1) } ;
138 #like $@, mkErr("^write Not Available: File opened only for intput");
142 foreach my $CompressClass ('IO::Compress::Gzip',
143 'IO::Compress::Deflate',
144 'IO::Compress::RawDeflate')
146 $UncompressClass = getInverse($CompressClass);
148 title "Testing $CompressClass and $UncompressClass";
153 # these tests come almost 100% from IO::String
155 my $name = "test.gz" ;
156 my $lex = new LexFile $name ;
158 my $io = $CompressClass->new($name);
162 my $heisan = "Heisan\n";
167 is $io->tell(), length($heisan) ;
169 print($io "a", "b", "c");
175 print $io "f", "g", "h";
178 my $foo = "1234567890";
180 ok syswrite($io, $foo, length($foo)) == length($foo) ;
182 { is $io->syswrite($foo, length $foo), length $foo }
184 { is $io->syswrite($foo), length $foo }
185 ok $io->syswrite($foo, length($foo)) == length $foo;
186 ok $io->write($foo, length($foo), 5) == 5;
187 ok $io->write("xxx\n", 100, -1) == 1;
190 printf $io "i(%d)", $_;
191 $io->printf("[%d]\n", $_);
201 is myGZreadFile($name), "Heisan\nabcde\nf,g,h\n" .
202 ("1234567890" x 3) . "67890\n" .
203 "i(1)[1]\ni(2)[2]\ni(3)[3]\n\n";
219 my $name = "test.gz" ;
220 my $lex = new LexFile $name ;
222 my $iow = new $CompressClass $name ;
229 my $io = new $UncompressClass $name ;
235 or print "# Got " . scalar(@lines) . " lines, expected 6\n" ;
236 is $lines[1], "of a paragraph\n" ;
237 is join('', @lines), $str ;
239 is $io->tell(), length($str) ;
243 ok ! ( defined($io->getline) ||
244 (@tmp = $io->getlines) ||
246 defined($io->getc) ||
247 read($io, $buf, 100) != 0) ;
252 local $/; # slurp mode
253 my $io = $UncompressClass->new($name);
255 my @lines = $io->getlines;
257 ok @lines == 1 && $lines[0] eq $str;
259 $io = $UncompressClass->new($name);
267 local $/ = ""; # paragraph mode
268 my $io = $UncompressClass->new($name);
273 or print "# Got " . scalar(@lines) . " lines, expected 2\n" ;
274 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
275 or print "# $lines[0]\n";
276 ok $lines[1] eq "and a single line.\n\n";
281 my $io = $UncompressClass->new($name);
288 $err++ if $. != ++$no;
295 or print "# Got " . scalar(@lines) . " lines, expected 3\n" ;
296 ok join("-", @lines) eq
297 "This- is- an example\n" .
298 "of a paragraph\n\n\n" .
299 "and a single line.\n\n";
306 my $io = $UncompressClass->new($name);
310 eval { read($io, $buf, -1) } ;
311 like $@, mkErr("length parameter is negative");
314 is read($io, $buf, 0), 0, "Requested 0 bytes" ;
316 ok read($io, $buf, 3) == 3 ;
319 ok sysread($io, $buf, 3, 2) == 3 ;
321 or print "# [$buf]\n" ;;
328 # ok read($io, $buf, 20) == 4 ;
329 # ok $buf eq "e.\n\n";
331 # ok read($io, $buf, 20) == 0 ;
340 # Read from non-compressed file
351 my $name = "test.gz" ;
352 my $lex = new LexFile $name ;
354 writeFile($name, $str);
358 my $io = new $UncompressClass $name, -Transparent => 1 ;
362 ok $io->tell() == 0 ;
365 ok $lines[1] eq "of a paragraph\n" ;
366 ok join('', @lines) eq $str ;
368 ok $io->tell() == length($str) ;
372 ok ! ( defined($io->getline) ||
373 (@tmp = $io->getlines) ||
375 defined($io->getc) ||
376 read($io, $buf, 100) != 0) ;
381 local $/; # slurp mode
382 my $io = $UncompressClass->new($name);
384 my @lines = $io->getlines;
386 ok @lines == 1 && $lines[0] eq $str;
388 $io = $UncompressClass->new($name);
396 local $/ = ""; # paragraph mode
397 my $io = $UncompressClass->new($name);
402 or print "# exected 2 lines, got " . scalar(@lines) . "\n";
403 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
404 or print "# [$lines[0]]\n" ;
405 ok $lines[1] eq "and a single line.\n\n";
410 my $io = $UncompressClass->new($name);
417 $err++ if $. != ++$no;
424 ok join("-", @lines) eq
425 "This- is- an example\n" .
426 "of a paragraph\n\n\n" .
427 "and a single line.\n\n";
434 my $io = $UncompressClass->new($name);
436 ok read($io, $buf, 3) == 3 ;
439 ok sysread($io, $buf, 3, 2) == 3 ;
447 # ok read($io, $buf, 20) == 4 ;
448 # ok $buf eq "e.\n\n";
450 # ok read($io, $buf, 20) == 0 ;
460 # Vary the length parameter in a read
475 foreach my $bufsize (1, 3, 512, 4096, length($str)-1, length($str), length($str)+1)
477 foreach my $trans (0, 1)
479 foreach my $append (0, 1)
481 title "Read Tests - buf length $bufsize, Transparent $trans, Append $append" ;
483 my $name = "testz.gz" ;
484 my $lex = new LexFile $name ;
487 writeFile($name, $str) ;
490 my $iow = new $CompressClass $name ;
496 my $io = $UncompressClass->new($name,
498 -Transparent => $trans);
505 1 while $io->read($buf, $bufsize) > 0;
509 $buf .= $tmp while $io->read($tmp, $bufsize) > 0 ;
511 is length $buf, length $str;