14 plan(skip_all => "Tied Filehandle needs Perl 5.005 or better" )
17 # use Test::NoWarnings, if available
20 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
23 $BadPerl = ($] >= 5.006 or $] <= 5.008) ;
32 plan tests => $tests + $extra ;
34 use_ok('Compress::Zlib', 2) ;
36 use_ok('IO::Compress::Gzip', qw($GzipError)) ;
37 use_ok('IO::Uncompress::Gunzip', qw($GunzipError)) ;
39 use_ok('IO::Compress::Deflate', qw($DeflateError)) ;
40 use_ok('IO::Uncompress::Inflate', qw($InflateError)) ;
42 use_ok('IO::Compress::RawDeflate', qw($RawDeflateError)) ;
43 use_ok('IO::Uncompress::RawInflate', qw($RawInflateError)) ;
47 use IO::Handle qw(SEEK_SET SEEK_CUR SEEK_END);
52 our ($UncompressClass);
57 my $filename = shift ;
61 my $fil = new $UncompressClass $filename,
67 $data = $init if defined $init ;
68 1 while $fil->read($data) > 0;
74 # Check zlib_version and ZLIB_VERSION are the same.
75 is Compress::Zlib::zlib_version, ZLIB_VERSION,
76 "ZLIB_VERSION matches Compress::Zlib::zlib_version" ;
80 foreach my $CompressClass ('IO::Compress::Gzip',
81 'IO::Compress::Deflate',
82 'IO::Compress::RawDeflate')
87 title "Testing $CompressClass";
91 my $gz = new $CompressClass(\$x);
96 like $@, mkErr("^getc Not Available: File opened only for output");
98 eval { read($gz, $buff, 1) } ;
99 like $@, mkErr("^read Not Available: File opened only for output");
102 like $@, mkErr("^readline Not Available: File opened only for output");
106 foreach my $CompressClass ('IO::Compress::Gzip',
107 'IO::Compress::Deflate',
108 'IO::Compress::RawDeflate')
111 $UncompressClass = getInverse($CompressClass);
113 title "Testing $UncompressClass";
116 my $guz = new $CompressClass(\$gc);
121 my $gz = new $UncompressClass(\$gc);
125 eval { print $gz "abc" } ;
126 like $@, mkErr("^print Not Available: File opened only for intput");
128 eval { printf $gz "fmt", "abc" } ;
129 like $@, mkErr("^printf Not Available: File opened only for intput");
131 #eval { write($gz, $buff, 1) } ;
132 #like $@, mkErr("^write Not Available: File opened only for intput");
136 foreach my $CompressClass ('IO::Compress::Gzip',
137 'IO::Compress::Deflate',
138 'IO::Compress::RawDeflate')
140 $UncompressClass = getInverse($CompressClass);
142 title "Testing $CompressClass and $UncompressClass";
147 # these tests come almost 100% from IO::String
149 my $name = "test.gz" ;
150 my $lex = new LexFile $name ;
152 my $io = $CompressClass->new($name);
156 my $heisan = "Heisan\n";
161 is $io->tell(), length($heisan) ;
163 print($io "a", "b", "c");
169 print $io "f", "g", "h";
172 my $foo = "1234567890";
174 ok syswrite($io, $foo, length($foo)) == length($foo) ;
176 { is $io->syswrite($foo, length $foo), length $foo }
178 { is $io->syswrite($foo), length $foo }
179 ok $io->syswrite($foo, length($foo)) == length $foo;
180 ok $io->write($foo, length($foo), 5) == 5;
181 ok $io->write("xxx\n", 100, -1) == 1;
184 printf $io "i(%d)", $_;
185 $io->printf("[%d]\n", $_);
195 is myGZreadFile($name), "Heisan\nabcde\nf,g,h\n" .
196 ("1234567890" x 3) . "67890\n" .
197 "i(1)[1]\ni(2)[2]\ni(3)[3]\n\n";
213 my $name = "test.gz" ;
214 my $lex = new LexFile $name ;
216 my $iow = new $CompressClass $name ;
223 my $io = new $UncompressClass $name ;
229 or print "# Got " . scalar(@lines) . " lines, expected 6\n" ;
230 is $lines[1], "of a paragraph\n" ;
231 is join('', @lines), $str ;
233 is $io->tell(), length($str) ;
237 ok ! ( defined($io->getline) ||
238 (@tmp = $io->getlines) ||
240 defined($io->getc) ||
241 read($io, $buf, 100) != 0) ;
246 local $/; # slurp mode
247 my $io = $UncompressClass->new($name);
249 my @lines = $io->getlines;
251 ok @lines == 1 && $lines[0] eq $str;
253 $io = $UncompressClass->new($name);
261 local $/ = ""; # paragraph mode
262 my $io = $UncompressClass->new($name);
267 or print "# Got " . scalar(@lines) . " lines, expected 2\n" ;
268 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
269 or print "# $lines[0]\n";
270 ok $lines[1] eq "and a single line.\n\n";
275 my $io = $UncompressClass->new($name);
282 $err++ if $. != ++$no;
289 or print "# Got " . scalar(@lines) . " lines, expected 3\n" ;
290 ok join("-", @lines) eq
291 "This- is- an example\n" .
292 "of a paragraph\n\n\n" .
293 "and a single line.\n\n";
300 my $io = $UncompressClass->new($name);
304 eval { read($io, $buf, -1) } ;
305 like $@, mkErr("length parameter is negative");
308 is read($io, $buf, 0), 0, "Requested 0 bytes" ;
310 ok read($io, $buf, 3) == 3 ;
313 ok sysread($io, $buf, 3, 2) == 3 ;
315 or print "# [$buf]\n" ;;
322 # ok read($io, $buf, 20) == 4 ;
323 # ok $buf eq "e.\n\n";
325 # ok read($io, $buf, 20) == 0 ;
334 # Read from non-compressed file
345 my $name = "test.gz" ;
346 my $lex = new LexFile $name ;
348 writeFile($name, $str);
352 my $io = new $UncompressClass $name, -Transparent => 1 ;
356 ok $io->tell() == 0 ;
359 ok $lines[1] eq "of a paragraph\n" ;
360 ok join('', @lines) eq $str ;
362 ok $io->tell() == length($str) ;
366 ok ! ( defined($io->getline) ||
367 (@tmp = $io->getlines) ||
369 defined($io->getc) ||
370 read($io, $buf, 100) != 0) ;
375 local $/; # slurp mode
376 my $io = $UncompressClass->new($name);
378 my @lines = $io->getlines;
380 ok @lines == 1 && $lines[0] eq $str;
382 $io = $UncompressClass->new($name);
390 local $/ = ""; # paragraph mode
391 my $io = $UncompressClass->new($name);
396 or print "# exected 2 lines, got " . scalar(@lines) . "\n";
397 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
398 or print "# [$lines[0]]\n" ;
399 ok $lines[1] eq "and a single line.\n\n";
404 my $io = $UncompressClass->new($name);
411 $err++ if $. != ++$no;
418 ok join("-", @lines) eq
419 "This- is- an example\n" .
420 "of a paragraph\n\n\n" .
421 "and a single line.\n\n";
428 my $io = $UncompressClass->new($name);
430 ok read($io, $buf, 3) == 3 ;
433 ok sysread($io, $buf, 3, 2) == 3 ;
441 # ok read($io, $buf, 20) == 4 ;
442 # ok $buf eq "e.\n\n";
444 # ok read($io, $buf, 20) == 0 ;
454 # Vary the length parameter in a read
469 foreach my $bufsize (1, 3, 512, 4096, length($str)-1, length($str), length($str)+1)
471 foreach my $trans (0, 1)
473 foreach my $append (0, 1)
475 title "Read Tests - buf length $bufsize, Transparent $trans, Append $append" ;
477 my $name = "testz.gz" ;
478 my $lex = new LexFile $name ;
481 writeFile($name, $str) ;
484 my $iow = new $CompressClass $name ;
490 my $io = $UncompressClass->new($name,
492 -Transparent => $trans);
499 1 while $io->read($buf, $bufsize) > 0;
503 $buf .= $tmp while $io->read($tmp, $bufsize) > 0 ;
505 is length $buf, length $str;