12 # use Test::NoWarnings, if available
15 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
17 plan tests => 1775 + $extra ;
19 use_ok('Compress::Zlib', 2) ;
21 use_ok('IO::Compress::Gzip', qw($GzipError)) ;
22 use_ok('IO::Uncompress::Gunzip', qw($GunzipError)) ;
24 use_ok('IO::Compress::Deflate', qw($DeflateError)) ;
25 use_ok('IO::Uncompress::Inflate', qw($InflateError)) ;
27 use_ok('IO::Compress::RawDeflate', qw($RawDeflateError)) ;
28 use_ok('IO::Uncompress::RawInflate', qw($RawInflateError)) ;
32 use IO::Handle qw(SEEK_SET SEEK_CUR SEEK_END);
35 our ($UncompressClass);
40 my $filename = shift ;
44 my $fil = new $UncompressClass $filename,
50 $data = $init if defined $init ;
51 1 while $fil->read($data) > 0;
57 # Check zlib_version and ZLIB_VERSION are the same.
58 is Compress::Zlib::zlib_version, ZLIB_VERSION,
59 "ZLIB_VERSION matches Compress::Zlib::zlib_version" ;
63 foreach my $CompressClass ('IO::Compress::Gzip',
64 'IO::Compress::Deflate',
65 'IO::Compress::RawDeflate')
68 title "Testing $CompressClass";
71 eval qq[\$a = new $CompressClass(\\1) ;] ;
72 like $@, mkEvalErr("^$CompressClass: output buffer is read-only") ;
75 eval qq[\$a = new $CompressClass \$out ;] ;
76 like $@, mkEvalErr("^$CompressClass: output filename is undef or null string");
79 eval qq[\$a = new $CompressClass \$out ;] ;
80 like $@, mkEvalErr("^$CompressClass: output filename is undef or null string");
83 my $gz = new $CompressClass(\$x);
85 foreach my $name (qw(read readline getc))
87 eval " \$gz->$name() " ;
88 like $@, mkEvalErr("^$name Not Available: File opened only for output");
91 eval ' $gz->write({})' ;
92 like $@, mkEvalErr("^${CompressClass}::write: not a scalar reference");
93 #like $@, mkEvalErr("^${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref");
95 eval ' $gz->syswrite("abc", 1, 5)' ;
96 like $@, mkEvalErr("^${CompressClass}::write: offset outside string");
98 eval ' $gz->syswrite("abc", 1, -4)' ;
99 like $@, mkEvalErr("^${CompressClass}::write: offset outside string");
103 foreach my $CompressClass ('IO::Compress::Gzip',
104 'IO::Compress::Deflate',
105 'IO::Compress::RawDeflate',
108 $UncompressClass = getInverse($CompressClass);
109 my $Error = getErrorRef($CompressClass);
110 my $UnError = getErrorRef($UncompressClass);
112 title "Testing $UncompressClass";
115 eval qq[\$a = new $UncompressClass \$out ;] ;
116 like $@, mkEvalErr("^$UncompressClass: input filename is undef or null string");
119 eval qq[\$a = new $UncompressClass \$out ;] ;
120 like $@, mkEvalErr("^$UncompressClass: input filename is undef or null string");
122 my $lex = new LexFile my $name ;
124 ok ! -e $name, " $name does not exist";
126 eval qq[\$a = new $UncompressClass "$name" ;] ;
127 is $$UnError, "input file '$name' does not exist";
130 my $guz = new $CompressClass(\$gc);
135 my $gz = new $UncompressClass(\$gc);
137 foreach my $name (qw(print printf write))
139 eval " \$gz->$name() " ;
140 like $@, mkEvalErr("^$name Not Available: File opened only for intput");
145 foreach my $CompressClass ('IO::Compress::Gzip',
146 'IO::Compress::Deflate',
147 'IO::Compress::RawDeflate',
150 $UncompressClass = getInverse($CompressClass);
151 my $Error = getErrorRef($CompressClass);
152 my $ErrorUnc = getErrorRef($UncompressClass);
155 title "Testing $CompressClass and $UncompressClass";
158 my ($a, $x, @x) = ("","","") ;
160 # Buffer not a scalar reference
161 eval qq[\$a = new $CompressClass \\\@x ;] ;
162 like $@, mkEvalErr("^$CompressClass: output parameter not a filename, filehandle or scalar ref");
164 # Buffer not a scalar reference
165 eval qq[\$a = new $UncompressClass \\\@x ;] ;
166 like $@, mkEvalErr("^$UncompressClass: input parameter not a filename, filehandle, array ref or scalar ref");
169 foreach my $Type ( $CompressClass, $UncompressClass)
171 # Check error handling with IO::Compress::Deflate and IO::Uncompress::Inflate
173 my ($a, $x, @x) = ("","","") ;
175 # Odd number of parameters
176 eval qq[\$a = new $Type "abc", -Output ] ;
177 like $@, mkEvalErr("^$Type: Expected even number of parameters, got 1");
180 eval qq[\$a = new $Type "anc", -Fred => 123 ;] ;
181 like $@, mkEvalErr("^$Type: unknown key value\\(s\\) Fred");
184 eval qq[\$a = new $Type ;] ;
185 like $@, mkEvalErr("^$Type: Missing (Input|Output) parameter");
191 # write a very simple compressed file
193 #========================================
196 my $lex = new LexFile my $name ;
205 ok $x = new $CompressClass $name ;
207 ok $x->write($hello), "write" ;
208 ok $x->flush(Z_FINISH), "flush";
209 ok $x->close, "close" ;
214 ok my $x = new $UncompressClass $name, -Append => 1 ;
217 1 while ($len = $x->read($uncomp)) > 0 ;
225 # write a very simple compressed file
227 #========================================
230 my $name = "test.gz" ;
231 my $lex = new LexFile $name ;
240 ok $x = new $CompressClass $name ;
242 is $x->write(''), 0, "Write empty string is ok";
243 is $x->write(undef), 0, "Write undef is ok";
244 ok $x->write($hello), "Write ok" ;
245 ok $x->close, "Close ok" ;
250 my $x = new $UncompressClass $name ;
251 ok $x, "creates $UncompressClass $name" ;
254 $data .= $uncomp while $x->read($uncomp) > 0 ;
256 ok $x->close, "close ok" ;
257 is $data, $uncomp,"expected output" ;
263 # write a very simple file with using an IO filehandle
265 #========================================
268 my $name = "test.gz" ;
269 my $lex = new LexFile $name ;
277 my $fh = new IO::File ">$name" ;
278 ok $fh, "opened file $name ok";
279 my $x = new $CompressClass $fh ;
280 ok $x, " created $CompressClass $fh" ;
282 is $x->fileno(), fileno($fh), "fileno match" ;
283 is $x->write(''), 0, "Write empty string is ok";
284 is $x->write(undef), 0, "Write undef is ok";
285 ok $x->write($hello), "write ok" ;
286 ok $x->flush(), "flush";
287 ok $x->close,"close" ;
294 ok my $fh1 = new IO::File "<$name" ;
295 ok $x = new $UncompressClass $fh1, -Append => 1 ;
296 ok $x->fileno() == fileno $fh1 ;
298 1 while $x->read($uncomp) > 0 ;
303 ok $hello eq $uncomp ;
307 # write a very simple file with using a glob filehandle
309 #========================================
312 my $lex = new LexFile my $name ;
320 title "$CompressClass: Input from typeglob filehandle";
321 ok open FH, ">$name" ;
323 my $x = new $CompressClass *FH ;
324 ok $x, " create $CompressClass" ;
326 is $x->fileno(), fileno(*FH), " fileno" ;
327 is $x->write(''), 0, " Write empty string is ok";
328 is $x->write(undef), 0, " Write undef is ok";
329 ok $x->write($hello), " Write ok" ;
330 ok $x->flush(), " Flush";
331 ok $x->close, " Close" ;
337 title "$UncompressClass: Input from typeglob filehandle, append output";
339 ok open FH, "<$name" ;
340 ok $x = new $UncompressClass *FH, -Append => 1, Transparent => 0 ;
341 is $x->fileno(), fileno FH, " fileno ok" ;
343 1 while $x->read($uncomp) > 0 ;
345 ok $x->close, " close" ;
348 is $uncomp, $hello, " expected output" ;
352 my $name = "test.gz" ;
353 my $lex = new LexFile $name ;
361 title "Outout to stdout via '-'" ;
363 open(SAVEOUT, ">&STDOUT");
364 my $dummy = fileno SAVEOUT;
365 open STDOUT, ">$name" ;
367 my $x = new $CompressClass '-' ;
371 open(STDOUT, ">&SAVEOUT");
373 ok 1, " wrote to stdout" ;
377 title "Input from stdin via filename '-'";
381 my $stdinFileno = fileno(STDIN);
382 # open below doesn't return 1 sometines on XP
383 open(SAVEIN, "<&STDIN");
384 ok open(STDIN, "<$name"), " redirect STDIN";
385 my $dummy = fileno SAVEIN;
386 $x = new $UncompressClass '-';
387 ok $x, " created object" ;
388 is $x->fileno(), $stdinFileno, " fileno ok" ;
390 1 while $x->read($uncomp) > 0 ;
392 ok $x->close, " close" ;
393 open(STDIN, "<&SAVEIN");
394 is $hello, $uncomp, " expected output" ;
399 # write a compressed file to memory
401 #========================================
403 my $name = "test.gz" ;
413 ok $x = new $CompressClass(\$buffer) ;
415 ok ! defined $x->fileno() ;
416 is $x->write(''), 0, "Write empty string is ok";
417 is $x->write(undef), 0, "Write undef is ok";
418 ok $x->write($hello) ;
422 writeFile($name, $buffer) ;
423 #is anyUncompress(\$buffer), $hello, " any ok";
430 ok $x = new $UncompressClass(\$buffer, Append => 1) ;
432 ok ! defined $x->fileno() ;
433 1 while $x->read($uncomp) > 0 ;
439 ok $buffer eq $keep ;
442 if ($CompressClass ne 'RawDeflate')
445 #========================================
450 ok $x = new $CompressClass(\$buffer) ;
459 ok $x = new $UncompressClass(\$buffer, Append => 1) ;
461 1 while $x->read($uncomp) > 0 ;
467 ok $buffer eq $keep ;
472 # write a larger file
473 #========================================
476 my $lex = new LexFile my $name ;
487 my $x = new $CompressClass $name ;
488 ok $x, " created $CompressClass object";
490 ok $x->write($hello), " write ok" ;
492 ok $x->write("another line"), " write ok" ;
493 $input .= "another line" ;
496 { $contents .= chr int $_ }
497 # generate a long random string
499 { $contents .= chr int rand 256 }
501 ok $x->write($contents), " write ok" ;
502 $input .= $contents ;
503 ok $x->close, " close ok" ;
506 ok myGZreadFile($name) eq $input ;
507 my $x = readFile($name) ;
508 #print "length " . length($x) . " \n";
512 # embed a compressed file in another file
513 #================================
516 my $name = "test.gz" ;
517 my $lex = new LexFile $name ;
524 my $header = "header info\n" ;
525 my $trailer = "trailer data\n" ;
529 ok $fh = new IO::File ">$name" ;
532 ok $x = new $CompressClass $fh,
536 ok $x->write($hello) ;
544 ok $fh1 = new IO::File "<$name" ;
547 ok $line eq $header ;
549 ok my $x = new $UncompressClass $fh1 ;
551 my $got = $x->read($uncomp);
553 ok $uncomp eq $hello ;
555 read($fh1, $rest, 5000);
556 is ${ $x->trailingData() } . $rest, $trailer ;
557 #print ${ $x->trailingData() } . $rest ;
563 # these tests come almost 100% from IO::String
565 my $name = "test.gz" ;
566 my $lex = new LexFile $name ;
568 my $io = $CompressClass->new($name);
570 is $io->tell(), 0, " tell returns 0"; ;
572 my $heisan = "Heisan\n";
573 $io->print($heisan) ;
575 ok ! $io->eof(), " ! eof";
577 is $io->tell(), length($heisan), " tell is " . length($heisan) ;
579 $io->print("a", "b", "c");
583 $io->print("d", "e");
585 $io->print("f", "g", "h");
590 $io->print("D", "E");
592 $io->print("F", "G", "H");
595 my $foo = "1234567890";
597 is $io->syswrite($foo, length($foo)), length($foo), " syswrite ok" ;
599 { is $io->syswrite($foo, length $foo), length $foo, " syswrite ok" }
601 { is $io->syswrite($foo), length $foo, " syswrite ok" }
602 is $io->syswrite($foo, length($foo)), length $foo, " syswrite ok";
603 is $io->write($foo, length($foo), 5), 5, " write 5";
604 is $io->write("xxx\n", 100, -1), 1, " write 1";
607 $io->printf("i(%d)", $_);
608 $io->printf("[%d]\n", $_);
614 ok $io->eof(), " eof";
616 is myGZreadFile($name), "Heisan\nabcde\nf,g,h\nDEF.G.H" .
617 ("1234567890" x 3) . "67890\n" .
618 "i(1)[1]\ni(2)[2]\ni(3)[3]\n\n";
634 my $name = "test.gz" ;
635 my $lex = new LexFile $name ;
638 %opts = (CRC32 => 1, Adler32 => 1)
639 if $CompressClass ne "IO::Compress::Gzip";
640 my $iow = new $CompressClass $name, %opts;
647 my $io = new $UncompressClass $name ;
652 my @lines = $io->getlines();
654 or print "# Got " . scalar(@lines) . " lines, expected 6\n" ;
655 is $lines[1], "of a paragraph\n" ;
656 is join('', @lines), $str ;
658 is $io->tell(), length($str) ;
662 ok ! ( defined($io->getline) ||
663 (@tmp = $io->getlines) ||
664 defined($io->getline) ||
665 defined($io->getc) ||
666 $io->read($buf, 100) != 0) ;
671 local $/; # slurp mode
672 my $io = $UncompressClass->new($name);
674 my @lines = $io->getlines;
676 ok @lines == 1 && $lines[0] eq $str;
678 $io = $UncompressClass->new($name);
680 my $line = $io->getline();
686 local $/ = ""; # paragraph mode
687 my $io = $UncompressClass->new($name);
689 my @lines = $io->getlines();
692 or print "# Got " . scalar(@lines) . " lines, expected 2\n" ;
693 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
694 or print "# $lines[0]\n";
695 ok $lines[1] eq "and a single line.\n\n";
700 my $io = $UncompressClass->new($name);
705 while (my $a = $io->getline()) {
707 $err++ if $. != ++$no;
714 or print "# Got " . scalar(@lines) . " lines, expected 3\n" ;
715 ok join("-", @lines) eq
716 "This- is- an example\n" .
717 "of a paragraph\n\n\n" .
718 "and a single line.\n\n";
725 my $io = $UncompressClass->new($name);
728 eval { $io->read(1) } ;
729 like $@, mkErr("buffer parameter is read-only");
731 is $io->read($buf, 0), 0, "Requested 0 bytes" ;
733 ok $io->read($buf, 3) == 3 ;
736 ok $io->sysread($buf, 3, 2) == 3 ;
738 or print "# [$buf]\n" ;;
745 # ok read($io, $buf, 20) == 4 ;
746 # ok $buf eq "e.\n\n";
748 # ok read($io, $buf, 20) == 0 ;
757 # Read from non-compressed file
768 my $name = "test.gz" ;
769 my $lex = new LexFile $name ;
771 writeFile($name, $str);
775 my $io = new $UncompressClass $name, -Transparent => 1 ;
779 ok $io->tell() == 0 ;
780 my @lines = $io->getlines();
782 ok $lines[1] eq "of a paragraph\n" ;
783 ok join('', @lines) eq $str ;
785 ok $io->tell() == length($str) ;
789 ok ! ( defined($io->getline) ||
790 (@tmp = $io->getlines) ||
791 defined($io->getline) ||
792 defined($io->getc) ||
793 $io->read($buf, 100) != 0) ;
798 local $/; # slurp mode
799 my $io = $UncompressClass->new($name);
801 my @lines = $io->getlines;
803 ok @lines == 1 && $lines[0] eq $str;
805 $io = $UncompressClass->new($name);
807 my $line = $io->getline;
813 local $/ = ""; # paragraph mode
814 my $io = $UncompressClass->new($name);
816 my @lines = $io->getlines;
819 or print "# exected 2 lines, got " . scalar(@lines) . "\n";
820 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
821 or print "# [$lines[0]]\n" ;
822 ok $lines[1] eq "and a single line.\n\n";
827 my $io = $UncompressClass->new($name);
832 while (my $a = $io->getline) {
834 $err++ if $. != ++$no;
841 ok join("-", @lines) eq
842 "This- is- an example\n" .
843 "of a paragraph\n\n\n" .
844 "and a single line.\n\n";
851 my $io = $UncompressClass->new($name);
853 ok $io->read($buf, 3) == 3 ;
856 ok $io->sysread($buf, 3, 2) == 3 ;
864 # ok read($io, $buf, 20) == 4 ;
865 # ok $buf eq "e.\n\n";
867 # ok read($io, $buf, 20) == 0 ;
877 # Vary the length parameter in a read
892 foreach my $bufsize (1, 3, 512, 4096, length($str)-1, length($str), length($str)+1)
894 foreach my $trans (0, 1)
896 foreach my $append (0, 1)
898 title "Read Tests - buf length $bufsize, Transparent $trans, Append $append" ;
900 my $name = "testz.gz" ;
901 my $lex = new LexFile $name ;
904 writeFile($name, $str) ;
907 my $iow = new $CompressClass $name;
913 my $io = $UncompressClass->new($name,
915 -Transparent => $trans);
922 1 while $io->read($buf, $bufsize) > 0;
926 $buf .= $tmp while $io->read($tmp, $bufsize) > 0 ;
928 is length $buf, length $str;
937 foreach my $file (0, 1)
939 foreach my $trans (0, 1)
941 title "seek tests - file $file trans $trans" ;
945 my $name = "test.gz" ;
946 my $lex = new LexFile $name ;
948 my $first = "beginning" ;
949 my $last = "the end" ;
953 $buffer = $first . "\x00" x 10 . $last;
954 writeFile($name, $buffer);
968 my $iow = new $CompressClass $output ;
969 $iow->print($first) ;
970 ok $iow->seek(5, SEEK_CUR) ;
971 ok $iow->tell() == length($first)+5;
972 ok $iow->seek(0, SEEK_CUR) ;
973 ok $iow->tell() == length($first)+5;
974 ok $iow->seek(length($first)+10, SEEK_SET) ;
975 ok $iow->tell() == length($first)+10;
991 ok myGZreadFile($input) eq $first . "\x00" x 10 . $last ;
993 my $io = $UncompressClass->new($input, Strict => 1);
994 ok $io->seek(length($first), SEEK_CUR) ;
996 is $io->tell(), length($first);
998 ok $io->read($buff, 5) ;
999 is $buff, "\x00" x 5 ;
1000 is $io->tell(), length($first) + 5;
1002 ok $io->seek(0, SEEK_CUR) ;
1003 my $here = $io->tell() ;
1004 is $here, length($first)+5;
1006 ok $io->seek($here+5, SEEK_SET) ;
1007 is $io->tell(), $here+5 ;
1008 ok $io->read($buff, 100) ;
1015 title "seek error cases" ;
1018 my $a = new $CompressClass(\$b) ;
1021 eval { $a->seek(-1, 10) ; };
1022 like $@, mkErr("^${CompressClass}::seek: unknown value, 10, for whence parameter");
1024 eval { $a->seek(-1, SEEK_END) ; };
1025 like $@, mkErr("^${CompressClass}::seek: cannot seek backwards");
1031 my $u = new $UncompressClass(\$b) ;
1033 eval { $u->seek(-1, 10) ; };
1034 like $@, mkErr("^${UncompressClass}::seek: unknown value, 10, for whence parameter");
1036 eval { $u->seek(-1, SEEK_END) ; };
1037 like $@, mkErr("^${UncompressClass}::seek: SEEK_END not allowed");
1039 eval { $u->seek(-1, SEEK_CUR) ; };
1040 like $@, mkErr("^${UncompressClass}::seek: cannot seek backwards");
1043 foreach my $fb (qw(filename buffer filehandle))
1045 foreach my $append (0, 1)
1048 title "$CompressClass -- Append $append, Output to $fb" ;
1050 my $name = "test.gz" ;
1051 my $lex = new LexFile $name ;
1053 my $already = 'already';
1054 my $buffer = $already;
1057 if ($fb eq 'buffer')
1058 { $output = \$buffer }
1059 elsif ($fb eq 'filename')
1062 writeFile($name, $buffer);
1064 elsif ($fb eq 'filehandle')
1066 $output = new IO::File ">$name" ;
1067 print $output $buffer;
1070 my $a = new $CompressClass($output, Append => $append) ;
1071 ok $a, " Created $CompressClass";
1072 my $string = "appended";
1077 if ($fb eq 'buffer')
1084 if $fb eq 'filehandle';
1085 $data = readFile($name);
1088 if ($append || $fb eq 'filehandle')
1090 is substr($data, 0, length($already)), $already, " got prefix";
1091 substr($data, 0, length($already)) = '';
1096 my $x = new $UncompressClass(\$data, Append => 1) ;
1097 ok $x, " created $UncompressClass";
1100 1 while ($len = $x->read($uncomp)) > 0 ;
1103 is $uncomp, $string, ' Got uncompressed data' ;
1109 foreach my $type (qw(buffer filename filehandle))
1111 title "$UncompressClass -- InputLength, read from $type";
1114 my $string = "some data";
1115 my $c = new $CompressClass(\$compressed);
1119 my $appended = "append";
1120 my $comp_len = length $compressed;
1121 $compressed .= $appended;
1123 my $name = "test.gz" ;
1124 my $lex = new LexFile $name ;
1126 writeFile ($name, $compressed);
1128 if ($type eq 'buffer')
1130 $input = \$compressed;
1132 if ($type eq 'filename')
1136 elsif ($type eq 'filehandle')
1138 my $fh = new IO::File "<$name" ;
1139 ok $fh, "opened file $name ok";
1143 my $x = new $UncompressClass($input, InputLength => $comp_len) ;
1144 ok $x, " created $UncompressClass";
1148 $len = $x->read($output, 100);
1149 is $len, length($string);
1150 is $output, $string;
1152 if ($type eq 'filehandle')
1155 $input->read($rest, 1000);
1156 is $rest, $appended;
1162 foreach my $append (0, 1)
1164 title "$UncompressClass -- Append $append" ;
1166 my $name = "test.gz" ;
1167 my $lex = new LexFile $name ;
1169 my $string = "appended";
1171 my $c = new $CompressClass(\$compressed);
1175 my $x = new $UncompressClass(\$compressed, Append => $append) ;
1176 ok $x, " created $UncompressClass";
1178 my $already = 'already';
1179 my $output = $already;
1182 $len = $x->read($output, 100);
1183 is $len, length($string);
1189 is substr($output, 0, length($already)), $already, " got prefix";
1190 substr($output, 0, length($already)) = '';
1192 is $output, $string, ' Got uncompressed data' ;
1196 foreach my $file (0, 1)
1198 foreach my $trans (0, 1)
1200 title "ungetc, File $file, Transparent $trans" ;
1202 my $name = "test.gz" ;
1203 my $lex = new LexFile $name ;
1205 my $string = 'abcdeABCDE';
1213 my $a = new $CompressClass(\$b) ;
1221 writeFile($name, $b);
1229 my $u = $UncompressClass->new($from, Transparent => 1) ;
1233 # do an ungetc before reading
1235 $first = $u->getc();
1238 $first = $u->getc();
1239 is $first, substr($string, 0,1);
1241 $first = $u->getc();
1242 is $first, substr($string, 0,1);
1245 is $u->read($buff, 5), 5 ;
1246 is $buff, substr($string, 0, 5);
1249 is $u->read($buff, length($string)), length($string) ;
1254 my $extra = 'extra';
1257 is $u->read($buff), length($extra) ;
1268 title "inflateSync on plain file";
1270 my $hello = "I am a HAL 9000 computer" x 2001 ;
1272 my ($k, $err) = new $UncompressClass(\$hello, Transparent => 1);
1274 cmp_ok $err, '==', Z_OK ;
1276 # Skip to the flush point -- no-op for plain file
1277 my $status = $k->inflateSync();
1279 or diag $k->error() ;
1282 is $k->read($rest, length($hello)), length($hello)
1283 or diag $k->error() ;
1284 ok $rest eq $hello ;
1290 title "inflateSync for real";
1292 # create a deflate stream with flush points
1294 my $hello = "I am a HAL 9000 computer" x 2001 ;
1295 my $goodbye = "Will I dream?" x 2010;
1296 my ($x, $err, $answer, $X, $Z, $status);
1299 ok ($x = new $CompressClass(\$Answer));
1302 is $x->write($hello), length($hello);
1304 # create a flush point
1305 ok $x->flush(Z_FULL_FLUSH) ;
1307 is $x->write($goodbye), length($goodbye);
1312 ($k, $err) = new $UncompressClass(\$Answer, BlockSize => 1);
1314 cmp_ok $err, '==', Z_OK ;
1317 is $k->read($initial, 1), 1 ;
1318 is $initial, substr($hello, 0, 1);
1320 # Skip to the flush point
1321 $status = $k->inflateSync();
1323 or diag $k->error() ;
1326 is $k->read($rest, length($hello) + length($goodbye)),
1328 or diag $k->error() ;
1329 ok $rest eq $goodbye ;
1335 title "inflateSync no FLUSH point";
1337 # create a deflate stream with flush points
1339 my $hello = "I am a HAL 9000 computer" x 2001 ;
1340 my ($x, $err, $answer, $X, $Z, $status);
1343 ok ($x = new $CompressClass(\$Answer));
1346 is $x->write($hello), length($hello);
1351 ($k, $err) = new $UncompressClass(\$Answer, BlockSize => 1);
1353 cmp_ok $err, '==', Z_OK ;
1356 is $k->read($initial, 1), 1 ;
1357 is $initial, substr($hello, 0, 1);
1359 # Skip to the flush point
1360 $status = $k->inflateSync();
1362 or diag $k->error() ;
1365 is $k->inflateSync(), 0 ;
1369 title "write tests - invalid data" ;
1371 #my $name1 = "test.gz" ;
1372 #my $lex = new LexFile $name1 ;
1375 #ok ! -e $name1, " File $name1 does not exist";
1378 [ '{ }', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1379 [ '[ { } ]', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1380 [ '[ [ { } ] ]', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1381 [ '[ "" ]', "${CompressClass}::write: input filename is undef or null string" ],
1382 [ '[ undef ]', "${CompressClass}::write: input filename is undef or null string" ],
1383 [ '[ \$Answer ]',"${CompressClass}::write: input and output buffer are identical" ],
1384 #[ "not readable", 'xx' ],
1385 # same filehandle twice, 'xx'
1388 foreach my $data (@data)
1390 my ($send, $get) = @$data ;
1391 title "${CompressClass}::write( $send )";
1393 eval "\$copy = $send";
1394 my $x = new $CompressClass(\$Answer);
1395 ok $x, " Created $CompressClass object";
1396 eval { $x->write($copy) } ;
1397 #like $@, "/^$get/", " error - $get";
1398 like $@, "/not a scalar reference /", " error - not a scalar reference";
1402 # [ '[ $name1 ]', "input file '$name1' does not exist" ],
1403 # #[ "not readable", 'xx' ],
1404 # # same filehandle twice, 'xx'
1407 # foreach my $data (@data)
1409 # my ($send, $get) = @$data ;
1410 # title "${CompressClass}::write( $send )";
1412 # eval "\$copy = $send";
1413 # my $x = new $CompressClass(\$Answer);
1414 # ok $x, " Created $CompressClass object";
1415 # ok ! $x->write($copy), " write fails" ;
1416 # like $$Error, "/^$get/", " error - $get";
1426 # if (! ref $_[0] || ref $_[0] eq 'SCALAR')
1431 # if (ref $_[0] eq 'ARRAY')
1434 # for my $x ( @{ $_[0] })
1436 # push @a, deepCopy($x);
1442 # croak "bad! $_[0]";
1448 # #my $data = shift ;
1449 # my $from = $_[1] ;
1455 # if $_[0] eq $from ;
1460 # if (ref $_[0] eq 'SCALAR')
1463 # if defined ${ $_[0] } && ${ $_[0] } eq $from ;
1468 # if (ref $_[0] eq 'ARRAY')
1470 # for my $x ( @{ $_[0] })
1472 # deepSubst($x, $from, $to);
1476 # #croak "bad! $_[0]";
1480 # title "More write tests" ;
1482 # my $file1 = "file1" ;
1483 # my $file2 = "file2" ;
1484 # my $file3 = "file3" ;
1485 # my $lex = new LexFile $file1, $file2, $file3 ;
1487 # writeFile($file1, "F1");
1488 # writeFile($file2, "F2");
1489 # writeFile($file3, "F3");
1494 # [ '"abcd"', "abcd" ],
1498 # [ '\"abcd"', "abcd" ],
1504 # [ '[\undef]', "" ],
1505 # [ '[\"abcd"]', "abcd" ],
1506 # [ '[\"ab", \"cd"]', "abcd" ],
1507 # [ '[[\"ab"], [\"cd"]]', "abcd" ],
1509 # [ '$file1', $file1 ],
1511 # [ '[$file1, \"abc"]', "F1abc"],
1512 # [ '[\"a", $file1, \"bc"]', "aF1bc"],
1513 # [ '[\"a", $fh1, \"bc"]', "aF1bc"],
1514 # [ '[\"a", $fh1, \"bc", $file2]', "aF1bcF2"],
1515 # [ '[\"a", $fh1, \"bc", $file2, $fh3]', "aF1bcF2F3"],
1519 # foreach my $data (@data)
1521 # my ($send, $get) = @$data ;
1523 # my $fh1 = new IO::File "< $file1" ;
1524 # my $fh2 = new IO::File "< $file2" ;
1525 # my $fh3 = new IO::File "< $file3" ;
1527 # title "${CompressClass}::write( $send )";
1529 # eval "\$copy = $send";
1531 # my $x = new $CompressClass(\$Answer);
1532 # ok $x, " Created $CompressClass object";
1533 # my $len = length $get;
1534 # is $x->write($copy), length($get), " write $len bytes";
1535 # ok $x->close(), " close ok" ;
1537 # is myGZreadFile(\$Answer), $get, " got expected output" ;
1538 # cmp_ok $$Error, '==', 0, " no error";