4 @INC = ("../lib", "lib");
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 $lex = new LexFile my $name ;
157 my $io = $CompressClass->new($name);
161 my $heisan = "Heisan\n";
166 is $io->tell(), length($heisan) ;
168 print($io "a", "b", "c");
174 print $io "f", "g", "h";
177 my $foo = "1234567890";
179 ok syswrite($io, $foo, length($foo)) == length($foo) ;
181 { is $io->syswrite($foo, length $foo), length $foo }
183 { is $io->syswrite($foo), length $foo }
184 ok $io->syswrite($foo, length($foo)) == length $foo;
185 ok $io->write($foo, length($foo), 5) == 5;
186 ok $io->write("xxx\n", 100, -1) == 1;
189 printf $io "i(%d)", $_;
190 $io->printf("[%d]\n", $_);
200 is myGZreadFile($name), "Heisan\nabcde\nf,g,h\n" .
201 ("1234567890" x 3) . "67890\n" .
202 "i(1)[1]\ni(2)[2]\ni(3)[3]\n\n";
218 my $lex = new LexFile my $name ;
220 my $iow = new $CompressClass $name ;
227 my $io = new $UncompressClass $name ;
233 or print "# Got " . scalar(@lines) . " lines, expected 6\n" ;
234 is $lines[1], "of a paragraph\n" ;
235 is join('', @lines), $str ;
237 is $io->tell(), length($str) ;
241 ok ! ( defined($io->getline) ||
242 (@tmp = $io->getlines) ||
244 defined($io->getc) ||
245 read($io, $buf, 100) != 0) ;
250 local $/; # slurp mode
251 my $io = $UncompressClass->new($name);
253 my @lines = $io->getlines;
255 ok @lines == 1 && $lines[0] eq $str;
257 $io = $UncompressClass->new($name);
265 local $/ = ""; # paragraph mode
266 my $io = $UncompressClass->new($name);
271 or print "# Got " . scalar(@lines) . " lines, expected 2\n" ;
272 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
273 or print "# $lines[0]\n";
274 ok $lines[1] eq "and a single line.\n\n";
279 my $io = $UncompressClass->new($name);
286 $err++ if $. != ++$no;
293 or print "# Got " . scalar(@lines) . " lines, expected 3\n" ;
294 ok join("-", @lines) eq
295 "This- is- an example\n" .
296 "of a paragraph\n\n\n" .
297 "and a single line.\n\n";
304 my $io = $UncompressClass->new($name);
308 eval { read($io, $buf, -1) } ;
309 like $@, mkErr("length parameter is negative");
312 is read($io, $buf, 0), 0, "Requested 0 bytes" ;
314 ok read($io, $buf, 3) == 3 ;
317 ok sysread($io, $buf, 3, 2) == 3 ;
319 or print "# [$buf]\n" ;;
326 # ok read($io, $buf, 20) == 4 ;
327 # ok $buf eq "e.\n\n";
329 # ok read($io, $buf, 20) == 0 ;
338 # Read from non-compressed file
349 my $lex = new LexFile my $name ;
351 writeFile($name, $str);
355 my $io = new $UncompressClass $name, -Transparent => 1 ;
359 ok $io->tell() == 0 ;
362 ok $lines[1] eq "of a paragraph\n" ;
363 ok join('', @lines) eq $str ;
365 ok $io->tell() == length($str) ;
369 ok ! ( defined($io->getline) ||
370 (@tmp = $io->getlines) ||
372 defined($io->getc) ||
373 read($io, $buf, 100) != 0) ;
378 local $/; # slurp mode
379 my $io = $UncompressClass->new($name);
381 my @lines = $io->getlines;
383 ok @lines == 1 && $lines[0] eq $str;
385 $io = $UncompressClass->new($name);
393 local $/ = ""; # paragraph mode
394 my $io = $UncompressClass->new($name);
399 or print "# exected 2 lines, got " . scalar(@lines) . "\n";
400 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
401 or print "# [$lines[0]]\n" ;
402 ok $lines[1] eq "and a single line.\n\n";
407 my $io = $UncompressClass->new($name);
414 $err++ if $. != ++$no;
421 ok join("-", @lines) eq
422 "This- is- an example\n" .
423 "of a paragraph\n\n\n" .
424 "and a single line.\n\n";
431 my $io = $UncompressClass->new($name);
433 ok read($io, $buf, 3) == 3 ;
436 ok sysread($io, $buf, 3, 2) == 3 ;
444 # ok read($io, $buf, 20) == 4 ;
445 # ok $buf eq "e.\n\n";
447 # ok read($io, $buf, 20) == 0 ;
457 # Vary the length parameter in a read
472 foreach my $bufsize (1, 3, 512, 4096, length($str)-1, length($str), length($str)+1)
474 foreach my $trans (0, 1)
476 foreach my $append (0, 1)
478 title "Read Tests - buf length $bufsize, Transparent $trans, Append $append" ;
480 my $lex = new LexFile my $name ;
483 writeFile($name, $str) ;
486 my $iow = new $CompressClass $name ;
492 my $io = $UncompressClass->new($name,
494 -Transparent => $trans);
501 1 while $io->read($buf, $bufsize) > 0;
505 $buf .= $tmp while $io->read($tmp, $bufsize) > 0 ;
507 is length $buf, length $str;