18 # use Test::NoWarnings, if available
21 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
23 plan tests => 1775 + $extra ;
25 use_ok('Compress::Zlib', 2) ;
27 use_ok('IO::Compress::Gzip', qw($GzipError)) ;
28 use_ok('IO::Uncompress::Gunzip', qw($GunzipError)) ;
30 use_ok('IO::Compress::Deflate', qw($DeflateError)) ;
31 use_ok('IO::Uncompress::Inflate', qw($InflateError)) ;
33 use_ok('IO::Compress::RawDeflate', qw($RawDeflateError)) ;
34 use_ok('IO::Uncompress::RawInflate', qw($RawInflateError)) ;
38 use IO::Handle qw(SEEK_SET SEEK_CUR SEEK_END);
41 our ($UncompressClass);
46 my $filename = shift ;
50 my $fil = new $UncompressClass $filename,
56 $data = $init if defined $init ;
57 1 while $fil->read($data) > 0;
63 # Check zlib_version and ZLIB_VERSION are the same.
64 is Compress::Zlib::zlib_version, ZLIB_VERSION,
65 "ZLIB_VERSION matches Compress::Zlib::zlib_version" ;
69 foreach my $CompressClass ('IO::Compress::Gzip',
70 'IO::Compress::Deflate',
71 'IO::Compress::RawDeflate')
74 title "Testing $CompressClass";
77 eval qq[\$a = new $CompressClass(\\1) ;] ;
78 like $@, mkEvalErr("^$CompressClass: output buffer is read-only") ;
81 eval qq[\$a = new $CompressClass \$out ;] ;
82 like $@, mkEvalErr("^$CompressClass: output filename is undef or null string");
85 eval qq[\$a = new $CompressClass \$out ;] ;
86 like $@, mkEvalErr("^$CompressClass: output filename is undef or null string");
89 my $gz = new $CompressClass(\$x);
91 foreach my $name (qw(read readline getc))
93 eval " \$gz->$name() " ;
94 like $@, mkEvalErr("^$name Not Available: File opened only for output");
97 eval ' $gz->write({})' ;
98 like $@, mkEvalErr("^${CompressClass}::write: not a scalar reference");
99 #like $@, mkEvalErr("^${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref");
101 eval ' $gz->syswrite("abc", 1, 5)' ;
102 like $@, mkEvalErr("^${CompressClass}::write: offset outside string");
104 eval ' $gz->syswrite("abc", 1, -4)' ;
105 like $@, mkEvalErr("^${CompressClass}::write: offset outside string");
109 foreach my $CompressClass ('IO::Compress::Gzip',
110 'IO::Compress::Deflate',
111 'IO::Compress::RawDeflate',
114 $UncompressClass = getInverse($CompressClass);
115 my $Error = getErrorRef($CompressClass);
116 my $UnError = getErrorRef($UncompressClass);
118 title "Testing $UncompressClass";
121 eval qq[\$a = new $UncompressClass \$out ;] ;
122 like $@, mkEvalErr("^$UncompressClass: input filename is undef or null string");
125 eval qq[\$a = new $UncompressClass \$out ;] ;
126 like $@, mkEvalErr("^$UncompressClass: input filename is undef or null string");
128 my $lex = new LexFile my $name ;
130 ok ! -e $name, " $name does not exist";
132 eval qq[\$a = new $UncompressClass "$name" ;] ;
133 is $$UnError, "input file '$name' does not exist";
136 my $guz = new $CompressClass(\$gc);
141 my $gz = new $UncompressClass(\$gc);
143 foreach my $name (qw(print printf write))
145 eval " \$gz->$name() " ;
146 like $@, mkEvalErr("^$name Not Available: File opened only for intput");
151 foreach my $CompressClass ('IO::Compress::Gzip',
152 'IO::Compress::Deflate',
153 'IO::Compress::RawDeflate',
156 $UncompressClass = getInverse($CompressClass);
157 my $Error = getErrorRef($CompressClass);
158 my $ErrorUnc = getErrorRef($UncompressClass);
161 title "Testing $CompressClass and $UncompressClass";
164 my ($a, $x, @x) = ("","","") ;
166 # Buffer not a scalar reference
167 eval qq[\$a = new $CompressClass \\\@x ;] ;
168 like $@, mkEvalErr("^$CompressClass: output parameter not a filename, filehandle or scalar ref");
170 # Buffer not a scalar reference
171 eval qq[\$a = new $UncompressClass \\\@x ;] ;
172 like $@, mkEvalErr("^$UncompressClass: input parameter not a filename, filehandle, array ref or scalar ref");
175 foreach my $Type ( $CompressClass, $UncompressClass)
177 # Check error handling with IO::Compress::Deflate and IO::Uncompress::Inflate
179 my ($a, $x, @x) = ("","","") ;
181 # Odd number of parameters
182 eval qq[\$a = new $Type "abc", -Output ] ;
183 like $@, mkEvalErr("^$Type: Expected even number of parameters, got 1");
186 eval qq[\$a = new $Type "anc", -Fred => 123 ;] ;
187 like $@, mkEvalErr("^$Type: unknown key value\\(s\\) Fred");
190 eval qq[\$a = new $Type ;] ;
191 like $@, mkEvalErr("^$Type: Missing (Input|Output) parameter");
197 # write a very simple compressed file
199 #========================================
202 my $lex = new LexFile my $name ;
211 ok $x = new $CompressClass $name ;
213 ok $x->write($hello), "write" ;
214 ok $x->flush(Z_FINISH), "flush";
215 ok $x->close, "close" ;
220 ok my $x = new $UncompressClass $name, -Append => 1 ;
223 1 while ($len = $x->read($uncomp)) > 0 ;
231 # write a very simple compressed file
233 #========================================
236 my $name = "test.gz" ;
237 my $lex = new LexFile $name ;
246 ok $x = new $CompressClass $name ;
248 is $x->write(''), 0, "Write empty string is ok";
249 is $x->write(undef), 0, "Write undef is ok";
250 ok $x->write($hello), "Write ok" ;
251 ok $x->close, "Close ok" ;
256 my $x = new $UncompressClass $name ;
257 ok $x, "creates $UncompressClass $name" ;
260 $data .= $uncomp while $x->read($uncomp) > 0 ;
262 ok $x->close, "close ok" ;
263 is $data, $uncomp,"expected output" ;
269 # write a very simple file with using an IO filehandle
271 #========================================
274 my $name = "test.gz" ;
275 my $lex = new LexFile $name ;
283 my $fh = new IO::File ">$name" ;
284 ok $fh, "opened file $name ok";
285 my $x = new $CompressClass $fh ;
286 ok $x, " created $CompressClass $fh" ;
288 is $x->fileno(), fileno($fh), "fileno match" ;
289 is $x->write(''), 0, "Write empty string is ok";
290 is $x->write(undef), 0, "Write undef is ok";
291 ok $x->write($hello), "write ok" ;
292 ok $x->flush(), "flush";
293 ok $x->close,"close" ;
300 ok my $fh1 = new IO::File "<$name" ;
301 ok $x = new $UncompressClass $fh1, -Append => 1 ;
302 ok $x->fileno() == fileno $fh1 ;
304 1 while $x->read($uncomp) > 0 ;
309 ok $hello eq $uncomp ;
313 # write a very simple file with using a glob filehandle
315 #========================================
318 my $lex = new LexFile my $name ;
326 title "$CompressClass: Input from typeglob filehandle";
327 ok open FH, ">$name" ;
329 my $x = new $CompressClass *FH ;
330 ok $x, " create $CompressClass" ;
332 is $x->fileno(), fileno(*FH), " fileno" ;
333 is $x->write(''), 0, " Write empty string is ok";
334 is $x->write(undef), 0, " Write undef is ok";
335 ok $x->write($hello), " Write ok" ;
336 ok $x->flush(), " Flush";
337 ok $x->close, " Close" ;
343 title "$UncompressClass: Input from typeglob filehandle, append output";
345 ok open FH, "<$name" ;
346 ok $x = new $UncompressClass *FH, -Append => 1, Transparent => 0 ;
347 is $x->fileno(), fileno FH, " fileno ok" ;
349 1 while $x->read($uncomp) > 0 ;
351 ok $x->close, " close" ;
354 is $uncomp, $hello, " expected output" ;
358 my $name = "test.gz" ;
359 my $lex = new LexFile $name ;
367 title "Outout to stdout via '-'" ;
369 open(SAVEOUT, ">&STDOUT");
370 my $dummy = fileno SAVEOUT;
371 open STDOUT, ">$name" ;
373 my $x = new $CompressClass '-' ;
377 open(STDOUT, ">&SAVEOUT");
379 ok 1, " wrote to stdout" ;
383 title "Input from stdin via filename '-'";
387 my $stdinFileno = fileno(STDIN);
388 # open below doesn't return 1 sometines on XP
389 open(SAVEIN, "<&STDIN");
390 ok open(STDIN, "<$name"), " redirect STDIN";
391 my $dummy = fileno SAVEIN;
392 $x = new $UncompressClass '-';
393 ok $x, " created object" ;
394 is $x->fileno(), $stdinFileno, " fileno ok" ;
396 1 while $x->read($uncomp) > 0 ;
398 ok $x->close, " close" ;
399 open(STDIN, "<&SAVEIN");
400 is $hello, $uncomp, " expected output" ;
405 # write a compressed file to memory
407 #========================================
409 my $name = "test.gz" ;
419 ok $x = new $CompressClass(\$buffer) ;
421 ok ! defined $x->fileno() ;
422 is $x->write(''), 0, "Write empty string is ok";
423 is $x->write(undef), 0, "Write undef is ok";
424 ok $x->write($hello) ;
428 writeFile($name, $buffer) ;
429 #is anyUncompress(\$buffer), $hello, " any ok";
436 ok $x = new $UncompressClass(\$buffer, Append => 1) ;
438 ok ! defined $x->fileno() ;
439 1 while $x->read($uncomp) > 0 ;
445 ok $buffer eq $keep ;
448 if ($CompressClass ne 'RawDeflate')
451 #========================================
456 ok $x = new $CompressClass(\$buffer) ;
465 ok $x = new $UncompressClass(\$buffer, Append => 1) ;
467 1 while $x->read($uncomp) > 0 ;
473 ok $buffer eq $keep ;
478 # write a larger file
479 #========================================
482 my $lex = new LexFile my $name ;
493 my $x = new $CompressClass $name ;
494 ok $x, " created $CompressClass object";
496 ok $x->write($hello), " write ok" ;
498 ok $x->write("another line"), " write ok" ;
499 $input .= "another line" ;
502 { $contents .= chr int $_ }
503 # generate a long random string
505 { $contents .= chr int rand 256 }
507 ok $x->write($contents), " write ok" ;
508 $input .= $contents ;
509 ok $x->close, " close ok" ;
512 ok myGZreadFile($name) eq $input ;
513 my $x = readFile($name) ;
514 #print "length " . length($x) . " \n";
518 # embed a compressed file in another file
519 #================================
522 my $name = "test.gz" ;
523 my $lex = new LexFile $name ;
530 my $header = "header info\n" ;
531 my $trailer = "trailer data\n" ;
535 ok $fh = new IO::File ">$name" ;
538 ok $x = new $CompressClass $fh,
542 ok $x->write($hello) ;
550 ok $fh1 = new IO::File "<$name" ;
553 ok $line eq $header ;
555 ok my $x = new $UncompressClass $fh1 ;
557 my $got = $x->read($uncomp);
559 ok $uncomp eq $hello ;
561 read($fh1, $rest, 5000);
562 is ${ $x->trailingData() } . $rest, $trailer ;
563 #print ${ $x->trailingData() } . $rest ;
569 # these tests come almost 100% from IO::String
571 my $name = "test.gz" ;
572 my $lex = new LexFile $name ;
574 my $io = $CompressClass->new($name);
576 is $io->tell(), 0, " tell returns 0"; ;
578 my $heisan = "Heisan\n";
579 $io->print($heisan) ;
581 ok ! $io->eof(), " ! eof";
583 is $io->tell(), length($heisan), " tell is " . length($heisan) ;
585 $io->print("a", "b", "c");
589 $io->print("d", "e");
591 $io->print("f", "g", "h");
596 $io->print("D", "E");
598 $io->print("F", "G", "H");
601 my $foo = "1234567890";
603 is $io->syswrite($foo, length($foo)), length($foo), " syswrite ok" ;
605 { is $io->syswrite($foo, length $foo), length $foo, " syswrite ok" }
607 { is $io->syswrite($foo), length $foo, " syswrite ok" }
608 is $io->syswrite($foo, length($foo)), length $foo, " syswrite ok";
609 is $io->write($foo, length($foo), 5), 5, " write 5";
610 is $io->write("xxx\n", 100, -1), 1, " write 1";
613 $io->printf("i(%d)", $_);
614 $io->printf("[%d]\n", $_);
620 ok $io->eof(), " eof";
622 is myGZreadFile($name), "Heisan\nabcde\nf,g,h\nDEF.G.H" .
623 ("1234567890" x 3) . "67890\n" .
624 "i(1)[1]\ni(2)[2]\ni(3)[3]\n\n";
640 my $name = "test.gz" ;
641 my $lex = new LexFile $name ;
644 %opts = (CRC32 => 1, Adler32 => 1)
645 if $CompressClass ne "IO::Compress::Gzip";
646 my $iow = new $CompressClass $name, %opts;
653 my $io = new $UncompressClass $name ;
658 my @lines = $io->getlines();
660 or print "# Got " . scalar(@lines) . " lines, expected 6\n" ;
661 is $lines[1], "of a paragraph\n" ;
662 is join('', @lines), $str ;
664 is $io->tell(), length($str) ;
668 ok ! ( defined($io->getline) ||
669 (@tmp = $io->getlines) ||
670 defined($io->getline) ||
671 defined($io->getc) ||
672 $io->read($buf, 100) != 0) ;
677 local $/; # slurp mode
678 my $io = $UncompressClass->new($name);
680 my @lines = $io->getlines;
682 ok @lines == 1 && $lines[0] eq $str;
684 $io = $UncompressClass->new($name);
686 my $line = $io->getline();
692 local $/ = ""; # paragraph mode
693 my $io = $UncompressClass->new($name);
695 my @lines = $io->getlines();
698 or print "# Got " . scalar(@lines) . " lines, expected 2\n" ;
699 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
700 or print "# $lines[0]\n";
701 ok $lines[1] eq "and a single line.\n\n";
706 my $io = $UncompressClass->new($name);
711 while (my $a = $io->getline()) {
713 $err++ if $. != ++$no;
720 or print "# Got " . scalar(@lines) . " lines, expected 3\n" ;
721 ok join("-", @lines) eq
722 "This- is- an example\n" .
723 "of a paragraph\n\n\n" .
724 "and a single line.\n\n";
731 my $io = $UncompressClass->new($name);
734 eval { $io->read(1) } ;
735 like $@, mkErr("buffer parameter is read-only");
737 is $io->read($buf, 0), 0, "Requested 0 bytes" ;
739 ok $io->read($buf, 3) == 3 ;
742 ok $io->sysread($buf, 3, 2) == 3 ;
744 or print "# [$buf]\n" ;;
751 # ok read($io, $buf, 20) == 4 ;
752 # ok $buf eq "e.\n\n";
754 # ok read($io, $buf, 20) == 0 ;
763 # Read from non-compressed file
774 my $name = "test.gz" ;
775 my $lex = new LexFile $name ;
777 writeFile($name, $str);
781 my $io = new $UncompressClass $name, -Transparent => 1 ;
785 ok $io->tell() == 0 ;
786 my @lines = $io->getlines();
788 ok $lines[1] eq "of a paragraph\n" ;
789 ok join('', @lines) eq $str ;
791 ok $io->tell() == length($str) ;
795 ok ! ( defined($io->getline) ||
796 (@tmp = $io->getlines) ||
797 defined($io->getline) ||
798 defined($io->getc) ||
799 $io->read($buf, 100) != 0) ;
804 local $/; # slurp mode
805 my $io = $UncompressClass->new($name);
807 my @lines = $io->getlines;
809 ok @lines == 1 && $lines[0] eq $str;
811 $io = $UncompressClass->new($name);
813 my $line = $io->getline;
819 local $/ = ""; # paragraph mode
820 my $io = $UncompressClass->new($name);
822 my @lines = $io->getlines;
825 or print "# exected 2 lines, got " . scalar(@lines) . "\n";
826 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
827 or print "# [$lines[0]]\n" ;
828 ok $lines[1] eq "and a single line.\n\n";
833 my $io = $UncompressClass->new($name);
838 while (my $a = $io->getline) {
840 $err++ if $. != ++$no;
847 ok join("-", @lines) eq
848 "This- is- an example\n" .
849 "of a paragraph\n\n\n" .
850 "and a single line.\n\n";
857 my $io = $UncompressClass->new($name);
859 ok $io->read($buf, 3) == 3 ;
862 ok $io->sysread($buf, 3, 2) == 3 ;
870 # ok read($io, $buf, 20) == 4 ;
871 # ok $buf eq "e.\n\n";
873 # ok read($io, $buf, 20) == 0 ;
883 # Vary the length parameter in a read
898 foreach my $bufsize (1, 3, 512, 4096, length($str)-1, length($str), length($str)+1)
900 foreach my $trans (0, 1)
902 foreach my $append (0, 1)
904 title "Read Tests - buf length $bufsize, Transparent $trans, Append $append" ;
906 my $name = "testz.gz" ;
907 my $lex = new LexFile $name ;
910 writeFile($name, $str) ;
913 my $iow = new $CompressClass $name;
919 my $io = $UncompressClass->new($name,
921 -Transparent => $trans);
928 1 while $io->read($buf, $bufsize) > 0;
932 $buf .= $tmp while $io->read($tmp, $bufsize) > 0 ;
934 is length $buf, length $str;
943 foreach my $file (0, 1)
945 foreach my $trans (0, 1)
947 title "seek tests - file $file trans $trans" ;
951 my $name = "test.gz" ;
952 my $lex = new LexFile $name ;
954 my $first = "beginning" ;
955 my $last = "the end" ;
959 $buffer = $first . "\x00" x 10 . $last;
960 writeFile($name, $buffer);
974 my $iow = new $CompressClass $output ;
975 $iow->print($first) ;
976 ok $iow->seek(5, SEEK_CUR) ;
977 ok $iow->tell() == length($first)+5;
978 ok $iow->seek(0, SEEK_CUR) ;
979 ok $iow->tell() == length($first)+5;
980 ok $iow->seek(length($first)+10, SEEK_SET) ;
981 ok $iow->tell() == length($first)+10;
997 ok myGZreadFile($input) eq $first . "\x00" x 10 . $last ;
999 my $io = $UncompressClass->new($input, Strict => 1);
1000 ok $io->seek(length($first), SEEK_CUR) ;
1002 is $io->tell(), length($first);
1004 ok $io->read($buff, 5) ;
1005 is $buff, "\x00" x 5 ;
1006 is $io->tell(), length($first) + 5;
1008 ok $io->seek(0, SEEK_CUR) ;
1009 my $here = $io->tell() ;
1010 is $here, length($first)+5;
1012 ok $io->seek($here+5, SEEK_SET) ;
1013 is $io->tell(), $here+5 ;
1014 ok $io->read($buff, 100) ;
1021 title "seek error cases" ;
1024 my $a = new $CompressClass(\$b) ;
1027 eval { $a->seek(-1, 10) ; };
1028 like $@, mkErr("^${CompressClass}::seek: unknown value, 10, for whence parameter");
1030 eval { $a->seek(-1, SEEK_END) ; };
1031 like $@, mkErr("^${CompressClass}::seek: cannot seek backwards");
1037 my $u = new $UncompressClass(\$b) ;
1039 eval { $u->seek(-1, 10) ; };
1040 like $@, mkErr("^${UncompressClass}::seek: unknown value, 10, for whence parameter");
1042 eval { $u->seek(-1, SEEK_END) ; };
1043 like $@, mkErr("^${UncompressClass}::seek: SEEK_END not allowed");
1045 eval { $u->seek(-1, SEEK_CUR) ; };
1046 like $@, mkErr("^${UncompressClass}::seek: cannot seek backwards");
1049 foreach my $fb (qw(filename buffer filehandle))
1051 foreach my $append (0, 1)
1054 title "$CompressClass -- Append $append, Output to $fb" ;
1056 my $name = "test.gz" ;
1057 my $lex = new LexFile $name ;
1059 my $already = 'already';
1060 my $buffer = $already;
1063 if ($fb eq 'buffer')
1064 { $output = \$buffer }
1065 elsif ($fb eq 'filename')
1068 writeFile($name, $buffer);
1070 elsif ($fb eq 'filehandle')
1072 $output = new IO::File ">$name" ;
1073 print $output $buffer;
1076 my $a = new $CompressClass($output, Append => $append) ;
1077 ok $a, " Created $CompressClass";
1078 my $string = "appended";
1083 if ($fb eq 'buffer')
1090 if $fb eq 'filehandle';
1091 $data = readFile($name);
1094 if ($append || $fb eq 'filehandle')
1096 is substr($data, 0, length($already)), $already, " got prefix";
1097 substr($data, 0, length($already)) = '';
1102 my $x = new $UncompressClass(\$data, Append => 1) ;
1103 ok $x, " created $UncompressClass";
1106 1 while ($len = $x->read($uncomp)) > 0 ;
1109 is $uncomp, $string, ' Got uncompressed data' ;
1115 foreach my $type (qw(buffer filename filehandle))
1117 title "$UncompressClass -- InputLength, read from $type";
1120 my $string = "some data";
1121 my $c = new $CompressClass(\$compressed);
1125 my $appended = "append";
1126 my $comp_len = length $compressed;
1127 $compressed .= $appended;
1129 my $name = "test.gz" ;
1130 my $lex = new LexFile $name ;
1132 writeFile ($name, $compressed);
1134 if ($type eq 'buffer')
1136 $input = \$compressed;
1138 if ($type eq 'filename')
1142 elsif ($type eq 'filehandle')
1144 my $fh = new IO::File "<$name" ;
1145 ok $fh, "opened file $name ok";
1149 my $x = new $UncompressClass($input, InputLength => $comp_len) ;
1150 ok $x, " created $UncompressClass";
1154 $len = $x->read($output, 100);
1155 is $len, length($string);
1156 is $output, $string;
1158 if ($type eq 'filehandle')
1161 $input->read($rest, 1000);
1162 is $rest, $appended;
1168 foreach my $append (0, 1)
1170 title "$UncompressClass -- Append $append" ;
1172 my $name = "test.gz" ;
1173 my $lex = new LexFile $name ;
1175 my $string = "appended";
1177 my $c = new $CompressClass(\$compressed);
1181 my $x = new $UncompressClass(\$compressed, Append => $append) ;
1182 ok $x, " created $UncompressClass";
1184 my $already = 'already';
1185 my $output = $already;
1188 $len = $x->read($output, 100);
1189 is $len, length($string);
1195 is substr($output, 0, length($already)), $already, " got prefix";
1196 substr($output, 0, length($already)) = '';
1198 is $output, $string, ' Got uncompressed data' ;
1202 foreach my $file (0, 1)
1204 foreach my $trans (0, 1)
1206 title "ungetc, File $file, Transparent $trans" ;
1208 my $name = "test.gz" ;
1209 my $lex = new LexFile $name ;
1211 my $string = 'abcdeABCDE';
1219 my $a = new $CompressClass(\$b) ;
1227 writeFile($name, $b);
1235 my $u = $UncompressClass->new($from, Transparent => 1) ;
1239 # do an ungetc before reading
1241 $first = $u->getc();
1244 $first = $u->getc();
1245 is $first, substr($string, 0,1);
1247 $first = $u->getc();
1248 is $first, substr($string, 0,1);
1251 is $u->read($buff, 5), 5 ;
1252 is $buff, substr($string, 0, 5);
1255 is $u->read($buff, length($string)), length($string) ;
1260 my $extra = 'extra';
1263 is $u->read($buff), length($extra) ;
1274 title "inflateSync on plain file";
1276 my $hello = "I am a HAL 9000 computer" x 2001 ;
1278 my ($k, $err) = new $UncompressClass(\$hello, Transparent => 1);
1280 cmp_ok $err, '==', Z_OK ;
1282 # Skip to the flush point -- no-op for plain file
1283 my $status = $k->inflateSync();
1285 or diag $k->error() ;
1288 is $k->read($rest, length($hello)), length($hello)
1289 or diag $k->error() ;
1290 ok $rest eq $hello ;
1296 title "inflateSync for real";
1298 # create a deflate stream with flush points
1300 my $hello = "I am a HAL 9000 computer" x 2001 ;
1301 my $goodbye = "Will I dream?" x 2010;
1302 my ($x, $err, $answer, $X, $Z, $status);
1305 ok ($x = new $CompressClass(\$Answer));
1308 is $x->write($hello), length($hello);
1310 # create a flush point
1311 ok $x->flush(Z_FULL_FLUSH) ;
1313 is $x->write($goodbye), length($goodbye);
1318 ($k, $err) = new $UncompressClass(\$Answer, BlockSize => 1);
1320 cmp_ok $err, '==', Z_OK ;
1323 is $k->read($initial, 1), 1 ;
1324 is $initial, substr($hello, 0, 1);
1326 # Skip to the flush point
1327 $status = $k->inflateSync();
1329 or diag $k->error() ;
1332 is $k->read($rest, length($hello) + length($goodbye)),
1334 or diag $k->error() ;
1335 ok $rest eq $goodbye ;
1341 title "inflateSync no FLUSH point";
1343 # create a deflate stream with flush points
1345 my $hello = "I am a HAL 9000 computer" x 2001 ;
1346 my ($x, $err, $answer, $X, $Z, $status);
1349 ok ($x = new $CompressClass(\$Answer));
1352 is $x->write($hello), length($hello);
1357 ($k, $err) = new $UncompressClass(\$Answer, BlockSize => 1);
1359 cmp_ok $err, '==', Z_OK ;
1362 is $k->read($initial, 1), 1 ;
1363 is $initial, substr($hello, 0, 1);
1365 # Skip to the flush point
1366 $status = $k->inflateSync();
1368 or diag $k->error() ;
1371 is $k->inflateSync(), 0 ;
1375 title "write tests - invalid data" ;
1377 #my $name1 = "test.gz" ;
1378 #my $lex = new LexFile $name1 ;
1381 #ok ! -e $name1, " File $name1 does not exist";
1384 [ '{ }', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1385 [ '[ { } ]', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1386 [ '[ [ { } ] ]', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1387 [ '[ "" ]', "${CompressClass}::write: input filename is undef or null string" ],
1388 [ '[ undef ]', "${CompressClass}::write: input filename is undef or null string" ],
1389 [ '[ \$Answer ]',"${CompressClass}::write: input and output buffer are identical" ],
1390 #[ "not readable", 'xx' ],
1391 # same filehandle twice, 'xx'
1394 foreach my $data (@data)
1396 my ($send, $get) = @$data ;
1397 title "${CompressClass}::write( $send )";
1399 eval "\$copy = $send";
1400 my $x = new $CompressClass(\$Answer);
1401 ok $x, " Created $CompressClass object";
1402 eval { $x->write($copy) } ;
1403 #like $@, "/^$get/", " error - $get";
1404 like $@, "/not a scalar reference /", " error - not a scalar reference";
1408 # [ '[ $name1 ]', "input file '$name1' does not exist" ],
1409 # #[ "not readable", 'xx' ],
1410 # # same filehandle twice, 'xx'
1413 # foreach my $data (@data)
1415 # my ($send, $get) = @$data ;
1416 # title "${CompressClass}::write( $send )";
1418 # eval "\$copy = $send";
1419 # my $x = new $CompressClass(\$Answer);
1420 # ok $x, " Created $CompressClass object";
1421 # ok ! $x->write($copy), " write fails" ;
1422 # like $$Error, "/^$get/", " error - $get";
1432 # if (! ref $_[0] || ref $_[0] eq 'SCALAR')
1437 # if (ref $_[0] eq 'ARRAY')
1440 # for my $x ( @{ $_[0] })
1442 # push @a, deepCopy($x);
1448 # croak "bad! $_[0]";
1454 # #my $data = shift ;
1455 # my $from = $_[1] ;
1461 # if $_[0] eq $from ;
1466 # if (ref $_[0] eq 'SCALAR')
1469 # if defined ${ $_[0] } && ${ $_[0] } eq $from ;
1474 # if (ref $_[0] eq 'ARRAY')
1476 # for my $x ( @{ $_[0] })
1478 # deepSubst($x, $from, $to);
1482 # #croak "bad! $_[0]";
1486 # title "More write tests" ;
1488 # my $file1 = "file1" ;
1489 # my $file2 = "file2" ;
1490 # my $file3 = "file3" ;
1491 # my $lex = new LexFile $file1, $file2, $file3 ;
1493 # writeFile($file1, "F1");
1494 # writeFile($file2, "F2");
1495 # writeFile($file3, "F3");
1500 # [ '"abcd"', "abcd" ],
1504 # [ '\"abcd"', "abcd" ],
1510 # [ '[\undef]', "" ],
1511 # [ '[\"abcd"]', "abcd" ],
1512 # [ '[\"ab", \"cd"]', "abcd" ],
1513 # [ '[[\"ab"], [\"cd"]]', "abcd" ],
1515 # [ '$file1', $file1 ],
1517 # [ '[$file1, \"abc"]', "F1abc"],
1518 # [ '[\"a", $file1, \"bc"]', "aF1bc"],
1519 # [ '[\"a", $fh1, \"bc"]', "aF1bc"],
1520 # [ '[\"a", $fh1, \"bc", $file2]', "aF1bcF2"],
1521 # [ '[\"a", $fh1, \"bc", $file2, $fh3]', "aF1bcF2F3"],
1525 # foreach my $data (@data)
1527 # my ($send, $get) = @$data ;
1529 # my $fh1 = new IO::File "< $file1" ;
1530 # my $fh2 = new IO::File "< $file2" ;
1531 # my $fh3 = new IO::File "< $file3" ;
1533 # title "${CompressClass}::write( $send )";
1535 # eval "\$copy = $send";
1537 # my $x = new $CompressClass(\$Answer);
1538 # ok $x, " Created $CompressClass object";
1539 # my $len = length $get;
1540 # is $x->write($copy), length($get), " write $len bytes";
1541 # ok $x->close(), " close ok" ;
1543 # is myGZreadFile(\$Answer), $get, " got expected output" ;
1544 # cmp_ok $$Error, '==', 0, " no error";