4 @INC = ("../lib", "lib");
20 plan(skip_all => "Extra Tied Filehandle needs Perl 5.6 or better - you have Perl $]" )
25 $BadPerl = ($] >= 5.006 or $] <= 5.008) ;
34 # use Test::NoWarnings, if available
37 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
39 plan tests => $tests + $extra ;
41 use_ok('Compress::Zlib', 2) ;
43 use_ok('IO::Compress::Gzip', qw($GzipError)) ;
44 use_ok('IO::Uncompress::Gunzip', qw($GunzipError)) ;
46 use_ok('IO::Compress::Deflate', qw($DeflateError)) ;
47 use_ok('IO::Uncompress::Inflate', qw($InflateError)) ;
49 use_ok('IO::Compress::RawDeflate', qw($RawDeflateError)) ;
50 use_ok('IO::Uncompress::RawInflate', qw($RawInflateError)) ;
56 use IO::Handle qw(SEEK_SET SEEK_CUR SEEK_END);
59 our ($UncompressClass);
64 my $filename = shift ;
68 my $fil = new $UncompressClass $filename,
74 $data = $init if defined $init ;
75 1 while $fil->read($data) > 0;
81 # Check zlib_version and ZLIB_VERSION are the same.
82 is Compress::Zlib::zlib_version, ZLIB_VERSION,
83 "ZLIB_VERSION matches Compress::Zlib::zlib_version" ;
87 foreach my $CompressClass ('IO::Compress::Gzip',
88 'IO::Compress::Deflate',
89 'IO::Compress::RawDeflate',
92 $UncompressClass = getInverse($CompressClass);
94 title "Testing $CompressClass and $UncompressClass";
100 # these tests come almost 100% from IO::String
102 my $lex = new LexFile my $name ;
104 my $io = $CompressClass->new($name);
109 my $heisan = "Heisan\n";
115 is tell($io), length($heisan) ;
116 is $io->tell(), length($heisan) ;
118 $io->print("a", "b", "c");
124 print $io "f", "g", "h";
127 my $foo = "1234567890";
129 ok syswrite($io, $foo, length($foo)) == length($foo) ;
131 { is $io->syswrite($foo, length $foo), length $foo }
133 { is $io->syswrite($foo), length $foo }
134 ok $io->syswrite($foo, length($foo)) == length $foo;
135 ok $io->write($foo, length($foo), 5) == 5;
136 ok $io->write("xxx\n", 100, -1) == 1;
139 printf $io "i(%d)", $_;
140 $io->printf("[%d]\n", $_);
151 is myGZreadFile($name), "Heisan\nabcde\nf,g,h\n" .
152 ("1234567890" x 3) . "67890\n" .
153 "i(1)[1]\ni(2)[2]\ni(3)[3]\n\n";
169 my $lex = new LexFile my $name ;
171 my $iow = new $CompressClass $name ;
178 my $io = new $UncompressClass $name ;
186 or print "# Got " . scalar(@lines) . " lines, expected 6\n" ;
187 is $lines[1], "of a paragraph\n" ;
188 is join('', @lines), $str ;
190 #print "TELL says " . tell($io) , " should be ${ \length($str) }\n" ;
191 is $io->tell(), length($str) ;
192 is tell($io), length($str) ;
197 ok ! ( defined($io->getline) ||
198 (@tmp = $io->getlines) ||
200 defined($io->getc) ||
201 read($io, $buf, 100) != 0) ;
206 local $/; # slurp mode
207 my $io = $UncompressClass->new($name);
209 my @lines = $io->getlines;
211 ok @lines == 1 && $lines[0] eq $str;
213 $io = $UncompressClass->new($name);
221 local $/ = ""; # paragraph mode
222 my $io = $UncompressClass->new($name);
227 or print "# Got " . scalar(@lines) . " lines, expected 2\n" ;
228 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
229 or print "# $lines[0]\n";
230 ok $lines[1] eq "and a single line.\n\n";
235 my $io = $UncompressClass->new($name);
242 $err++ if $. != ++$no;
249 or print "# Got " . scalar(@lines) . " lines, expected 3\n" ;
250 ok join("-", @lines) eq
251 "This- is- an example\n" .
252 "of a paragraph\n\n\n" .
253 "and a single line.\n\n";
260 my $io = $UncompressClass->new($name);
262 ok $io, "opened ok" ;
264 #eval { read($io, $buf, -1); } ;
265 #like $@, mkErr("length parameter is negative"), "xxx $io $UncompressClass $RawInflateError" ;
267 #eval { read($io, 1) } ;
268 #like $@, mkErr("buffer parameter is read-only");
270 is read($io, $buf, 0), 0, "Requested 0 bytes" ;
272 ok read($io, $buf, 3) == 3 ;
275 ok sysread($io, $buf, 3, 2) == 3 ;
277 or print "# [$buf]\n" ;;
284 # ok read($io, $buf, 20) == 4 ;
285 # ok $buf eq "e.\n\n";
287 # ok read($io, $buf, 20) == 0 ;
300 my $lex = new LexFile my $name ;
302 my $first = "beginning" ;
303 my $last = "the end" ;
304 my $iow = new $CompressClass $name ;
306 ok seek $iow, 10, SEEK_CUR ;
307 is tell($iow), length($first)+10;
308 ok $iow->seek(0, SEEK_CUR) ;
309 is tell($iow), length($first)+10;
313 my $io = $UncompressClass->new($name);
314 ok myGZreadFile($name) eq $first . "\x00" x 10 . $last ;
316 $io = $UncompressClass->new($name);
317 ok seek $io, length($first)+10, SEEK_CUR ;
319 is tell($io), length($first)+10;
320 ok seek $io, 0, SEEK_CUR ;
321 is tell($io), length($first)+10;
323 ok read $io, $buff, 100 ;
332 my $a = new $CompressClass(\$b) ;
335 eval { seek($a, -1, 10) ; };
336 like $@, mkErr("^seek: unknown value, 10, for whence parameter");
338 eval { seek($a, -1, SEEK_END) ; };
339 like $@, mkErr("^cannot seek backwards");
345 my $u = new $UncompressClass(\$b) ;
347 eval { seek($u, -1, 10) ; };
348 like $@, mkErr("^seek: unknown value, 10, for whence parameter");
350 eval { seek($u, -1, SEEK_END) ; };
351 like $@, mkErr("^seek: SEEK_END not allowed");
353 eval { seek($u, -1, SEEK_CUR) ; };
354 like $@, mkErr("^cannot seek backwards");
360 my $lex = new LexFile my $name ;
369 ok $fh = new IO::File ">$name" ;
371 ok $x = new $CompressClass $fh ;
373 ok $x->fileno() == fileno($fh) ;
374 ok $x->fileno() == fileno($x) ;
375 ok $x->write($hello) ;
383 ok my $fh1 = new IO::File "<$name" ;
384 ok $x = new $UncompressClass $fh1, -Append => 1 ;
385 ok $x->fileno() == fileno $fh1 ;
386 ok $x->fileno() == fileno $x ;
388 1 while $x->read($uncomp) > 0 ;
393 ok $hello eq $uncomp ;