4 @INC = ("../lib", "lib");
18 # use Test::NoWarnings, if available
21 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
23 plan tests => 1769 + $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 ;
225 is $len, 0, "read returned 0";
233 # write a very simple compressed file
235 #========================================
238 my $lex = new LexFile my $name ;
247 ok $x = new $CompressClass $name ;
249 is $x->write(''), 0, "Write empty string is ok";
250 is $x->write(undef), 0, "Write undef is ok";
251 ok $x->write($hello), "Write ok" ;
252 ok $x->close, "Close ok" ;
257 my $x = new $UncompressClass $name ;
258 ok $x, "creates $UncompressClass $name" ;
261 $data .= $uncomp while $x->read($uncomp) > 0 ;
263 ok $x->close, "close ok" ;
264 is $data, $uncomp,"expected output" ;
270 # write a very simple file with using an IO filehandle
272 #========================================
275 my $lex = new LexFile my $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 $lex = new LexFile my $name ;
366 title "Outout to stdout via '-'" ;
368 open(SAVEOUT, ">&STDOUT");
369 my $dummy = fileno SAVEOUT;
370 open STDOUT, ">$name" ;
372 my $x = new $CompressClass '-' ;
376 open(STDOUT, ">&SAVEOUT");
378 ok 1, " wrote to stdout" ;
382 title "Input from stdin via filename '-'";
386 my $stdinFileno = fileno(STDIN);
387 # open below doesn't return 1 sometines on XP
388 open(SAVEIN, "<&STDIN");
389 ok open(STDIN, "<$name"), " redirect STDIN";
390 my $dummy = fileno SAVEIN;
391 $x = new $UncompressClass '-';
392 ok $x, " created object" ;
393 is $x->fileno(), $stdinFileno, " fileno ok" ;
395 1 while $x->read($uncomp) > 0 ;
397 ok $x->close, " close" ;
398 open(STDIN, "<&SAVEIN");
399 is $hello, $uncomp, " expected output" ;
404 # write a compressed file to memory
406 #========================================
408 my $name = "test.gz" ;
418 ok $x = new $CompressClass(\$buffer) ;
420 ok ! defined $x->fileno() ;
421 is $x->write(''), 0, "Write empty string is ok";
422 is $x->write(undef), 0, "Write undef is ok";
423 ok $x->write($hello) ;
427 writeFile($name, $buffer) ;
428 #is anyUncompress(\$buffer), $hello, " any ok";
435 ok $x = new $UncompressClass(\$buffer, Append => 1) ;
437 ok ! defined $x->fileno() ;
438 1 while $x->read($uncomp) > 0 ;
444 ok $buffer eq $keep ;
447 if ($CompressClass ne 'RawDeflate')
450 #========================================
455 ok $x = new $CompressClass(\$buffer) ;
464 ok $x = new $UncompressClass(\$buffer, Append => 1) ;
466 1 while $x->read($uncomp) > 0 ;
472 ok $buffer eq $keep ;
477 # write a larger file
478 #========================================
481 my $lex = new LexFile my $name ;
492 my $x = new $CompressClass $name ;
493 ok $x, " created $CompressClass object";
495 ok $x->write($hello), " write ok" ;
497 ok $x->write("another line"), " write ok" ;
498 $input .= "another line" ;
501 { $contents .= chr int $_ }
502 # generate a long random string
504 { $contents .= chr int rand 256 }
506 ok $x->write($contents), " write ok" ;
507 $input .= $contents ;
508 ok $x->close, " close ok" ;
511 ok myGZreadFile($name) eq $input ;
512 my $x = readFile($name) ;
513 #print "length " . length($x) . " \n";
517 # embed a compressed file in another file
518 #================================
521 my $lex = new LexFile my $name ;
528 my $header = "header info\n" ;
529 my $trailer = "trailer data\n" ;
533 ok $fh = new IO::File ">$name" ;
536 ok $x = new $CompressClass $fh,
540 ok $x->write($hello) ;
548 ok $fh1 = new IO::File "<$name" ;
551 ok $line eq $header ;
553 ok my $x = new $UncompressClass $fh1 ;
555 my $got = $x->read($uncomp);
557 ok $uncomp eq $hello ;
559 read($fh1, $rest, 5000);
560 is ${ $x->trailingData() } . $rest, $trailer ;
561 #print ${ $x->trailingData() } . $rest ;
567 # these tests come almost 100% from IO::String
569 my $lex = new LexFile my $name ;
571 my $io = $CompressClass->new($name);
573 is $io->tell(), 0, " tell returns 0"; ;
575 my $heisan = "Heisan\n";
576 $io->print($heisan) ;
578 ok ! $io->eof(), " ! eof";
580 is $io->tell(), length($heisan), " tell is " . length($heisan) ;
582 $io->print("a", "b", "c");
586 $io->print("d", "e");
588 $io->print("f", "g", "h");
593 $io->print("D", "E");
595 $io->print("F", "G", "H");
598 my $foo = "1234567890";
600 is $io->syswrite($foo, length($foo)), length($foo), " syswrite ok" ;
602 { is $io->syswrite($foo, length $foo), length $foo, " syswrite ok" }
604 { is $io->syswrite($foo), length $foo, " syswrite ok" }
605 is $io->syswrite($foo, length($foo)), length $foo, " syswrite ok";
606 is $io->write($foo, length($foo), 5), 5, " write 5";
607 is $io->write("xxx\n", 100, -1), 1, " write 1";
610 $io->printf("i(%d)", $_);
611 $io->printf("[%d]\n", $_);
617 ok $io->eof(), " eof";
619 is myGZreadFile($name), "Heisan\nabcde\nf,g,h\nDEF.G.H" .
620 ("1234567890" x 3) . "67890\n" .
621 "i(1)[1]\ni(2)[2]\ni(3)[3]\n\n";
637 my $lex = new LexFile my $name ;
640 %opts = (CRC32 => 1, Adler32 => 1)
641 if $CompressClass ne "IO::Compress::Gzip";
642 my $iow = new $CompressClass $name, %opts;
649 my $io = new $UncompressClass $name ;
654 my @lines = $io->getlines();
656 or print "# Got " . scalar(@lines) . " lines, expected 6\n" ;
657 is $lines[1], "of a paragraph\n" ;
658 is join('', @lines), $str ;
660 is $io->tell(), length($str) ;
664 ok ! ( defined($io->getline) ||
665 (@tmp = $io->getlines) ||
666 defined($io->getline) ||
667 defined($io->getc) ||
668 $io->read($buf, 100) != 0) ;
673 local $/; # slurp mode
674 my $io = $UncompressClass->new($name);
676 my @lines = $io->getlines;
678 ok @lines == 1 && $lines[0] eq $str;
680 $io = $UncompressClass->new($name);
682 my $line = $io->getline();
688 local $/ = ""; # paragraph mode
689 my $io = $UncompressClass->new($name);
691 my @lines = $io->getlines();
694 or print "# Got " . scalar(@lines) . " lines, expected 2\n" ;
695 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
696 or print "# $lines[0]\n";
697 ok $lines[1] eq "and a single line.\n\n";
702 my $io = $UncompressClass->new($name);
707 while (my $a = $io->getline()) {
709 $err++ if $. != ++$no;
716 or print "# Got " . scalar(@lines) . " lines, expected 3\n" ;
717 ok join("-", @lines) eq
718 "This- is- an example\n" .
719 "of a paragraph\n\n\n" .
720 "and a single line.\n\n";
727 my $io = $UncompressClass->new($name);
730 eval { $io->read(1) } ;
731 like $@, mkErr("buffer parameter is read-only");
733 is $io->read($buf, 0), 0, "Requested 0 bytes" ;
735 ok $io->read($buf, 3) == 3 ;
738 ok $io->sysread($buf, 3, 2) == 3 ;
740 or print "# [$buf]\n" ;;
747 # ok read($io, $buf, 20) == 4 ;
748 # ok $buf eq "e.\n\n";
750 # ok read($io, $buf, 20) == 0 ;
759 # Read from non-compressed file
770 my $lex = new LexFile my $name ;
772 writeFile($name, $str);
776 my $io = new $UncompressClass $name, -Transparent => 1 ;
780 ok $io->tell() == 0 ;
781 my @lines = $io->getlines();
783 ok $lines[1] eq "of a paragraph\n" ;
784 ok join('', @lines) eq $str ;
786 ok $io->tell() == length($str) ;
790 ok ! ( defined($io->getline) ||
791 (@tmp = $io->getlines) ||
792 defined($io->getline) ||
793 defined($io->getc) ||
794 $io->read($buf, 100) != 0) ;
799 local $/; # slurp mode
800 my $io = $UncompressClass->new($name);
802 my @lines = $io->getlines;
804 ok @lines == 1 && $lines[0] eq $str;
806 $io = $UncompressClass->new($name);
808 my $line = $io->getline;
814 local $/ = ""; # paragraph mode
815 my $io = $UncompressClass->new($name);
817 my @lines = $io->getlines;
820 or print "# exected 2 lines, got " . scalar(@lines) . "\n";
821 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
822 or print "# [$lines[0]]\n" ;
823 ok $lines[1] eq "and a single line.\n\n";
828 my $io = $UncompressClass->new($name);
833 while (my $a = $io->getline) {
835 $err++ if $. != ++$no;
842 ok join("-", @lines) eq
843 "This- is- an example\n" .
844 "of a paragraph\n\n\n" .
845 "and a single line.\n\n";
852 my $io = $UncompressClass->new($name);
854 ok $io->read($buf, 3) == 3 ;
857 ok $io->sysread($buf, 3, 2) == 3 ;
865 # ok read($io, $buf, 20) == 4 ;
866 # ok $buf eq "e.\n\n";
868 # ok read($io, $buf, 20) == 0 ;
878 # Vary the length parameter in a read
893 foreach my $bufsize (1, 3, 512, 4096, length($str)-1, length($str), length($str)+1)
895 foreach my $trans (0, 1)
897 foreach my $append (0, 1)
899 title "Read Tests - buf length $bufsize, Transparent $trans, Append $append" ;
901 my $lex = new LexFile my $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 $lex = new LexFile my $name ;
947 my $first = "beginning" ;
948 my $last = "the end" ;
952 $buffer = $first . "\x00" x 10 . $last;
953 writeFile($name, $buffer);
967 my $iow = new $CompressClass $output ;
968 $iow->print($first) ;
969 ok $iow->seek(5, SEEK_CUR) ;
970 ok $iow->tell() == length($first)+5;
971 ok $iow->seek(0, SEEK_CUR) ;
972 ok $iow->tell() == length($first)+5;
973 ok $iow->seek(length($first)+10, SEEK_SET) ;
974 ok $iow->tell() == length($first)+10;
990 ok myGZreadFile($input) eq $first . "\x00" x 10 . $last ;
992 my $io = $UncompressClass->new($input, Strict => 1);
993 ok $io->seek(length($first), SEEK_CUR) ;
995 is $io->tell(), length($first);
997 ok $io->read($buff, 5) ;
998 is $buff, "\x00" x 5 ;
999 is $io->tell(), length($first) + 5;
1001 ok $io->seek(0, SEEK_CUR) ;
1002 my $here = $io->tell() ;
1003 is $here, length($first)+5;
1005 ok $io->seek($here+5, SEEK_SET) ;
1006 is $io->tell(), $here+5 ;
1007 ok $io->read($buff, 100) ;
1014 title "seek error cases" ;
1017 my $a = new $CompressClass(\$b) ;
1020 eval { $a->seek(-1, 10) ; };
1021 like $@, mkErr("^${CompressClass}::seek: unknown value, 10, for whence parameter");
1023 eval { $a->seek(-1, SEEK_END) ; };
1024 like $@, mkErr("^${CompressClass}::seek: cannot seek backwards");
1030 my $u = new $UncompressClass(\$b) ;
1032 eval { $u->seek(-1, 10) ; };
1033 like $@, mkErr("^${UncompressClass}::seek: unknown value, 10, for whence parameter");
1035 eval { $u->seek(-1, SEEK_END) ; };
1036 like $@, mkErr("^${UncompressClass}::seek: SEEK_END not allowed");
1038 eval { $u->seek(-1, SEEK_CUR) ; };
1039 like $@, mkErr("^${UncompressClass}::seek: cannot seek backwards");
1042 foreach my $fb (qw(filename buffer filehandle))
1044 foreach my $append (0, 1)
1047 title "$CompressClass -- Append $append, Output to $fb" ;
1049 my $lex = new LexFile my $name ;
1051 my $already = 'already';
1052 my $buffer = $already;
1055 if ($fb eq 'buffer')
1056 { $output = \$buffer }
1057 elsif ($fb eq 'filename')
1060 writeFile($name, $buffer);
1062 elsif ($fb eq 'filehandle')
1064 $output = new IO::File ">$name" ;
1065 print $output $buffer;
1068 my $a = new $CompressClass($output, Append => $append) ;
1069 ok $a, " Created $CompressClass";
1070 my $string = "appended";
1075 if ($fb eq 'buffer')
1082 if $fb eq 'filehandle';
1083 $data = readFile($name);
1086 if ($append || $fb eq 'filehandle')
1088 is substr($data, 0, length($already)), $already, " got prefix";
1089 substr($data, 0, length($already)) = '';
1094 my $x = new $UncompressClass(\$data, Append => 1) ;
1095 ok $x, " created $UncompressClass";
1098 1 while ($len = $x->read($uncomp)) > 0 ;
1101 is $uncomp, $string, ' Got uncompressed data' ;
1107 foreach my $type (qw(buffer filename filehandle))
1109 title "$UncompressClass -- InputLength, read from $type";
1112 my $string = "some data";
1113 my $c = new $CompressClass(\$compressed);
1117 my $appended = "append";
1118 my $comp_len = length $compressed;
1119 $compressed .= $appended;
1121 my $lex = new LexFile my $name ;
1123 writeFile ($name, $compressed);
1125 if ($type eq 'buffer')
1127 $input = \$compressed;
1129 if ($type eq 'filename')
1133 elsif ($type eq 'filehandle')
1135 my $fh = new IO::File "<$name" ;
1136 ok $fh, "opened file $name ok";
1140 my $x = new $UncompressClass($input, InputLength => $comp_len) ;
1141 ok $x, " created $UncompressClass";
1145 $len = $x->read($output, 100);
1146 is $len, length($string);
1147 is $output, $string;
1149 if ($type eq 'filehandle')
1152 $input->read($rest, 1000);
1153 is $rest, $appended;
1159 foreach my $append (0, 1)
1161 title "$UncompressClass -- Append $append" ;
1163 my $lex = new LexFile my $name ;
1165 my $string = "appended";
1167 my $c = new $CompressClass(\$compressed);
1171 my $x = new $UncompressClass(\$compressed, Append => $append) ;
1172 ok $x, " created $UncompressClass";
1174 my $already = 'already';
1175 my $output = $already;
1178 $len = $x->read($output, 100);
1179 is $len, length($string);
1185 is substr($output, 0, length($already)), $already, " got prefix";
1186 substr($output, 0, length($already)) = '';
1188 is $output, $string, ' Got uncompressed data' ;
1192 foreach my $file (0, 1)
1194 foreach my $trans (0, 1)
1196 title "ungetc, File $file, Transparent $trans" ;
1198 my $lex = new LexFile my $name ;
1200 my $string = 'abcdeABCDE';
1208 my $a = new $CompressClass(\$b) ;
1216 writeFile($name, $b);
1224 my $u = $UncompressClass->new($from, Transparent => 1) ;
1228 # do an ungetc before reading
1230 $first = $u->getc();
1233 $first = $u->getc();
1234 is $first, substr($string, 0,1);
1236 $first = $u->getc();
1237 is $first, substr($string, 0,1);
1240 is $u->read($buff, 5), 5 ;
1241 is $buff, substr($string, 0, 5);
1244 is $u->read($buff, length($string)), length($string) ;
1249 my $extra = 'extra';
1252 is $u->read($buff), length($extra) ;
1263 title "inflateSync on plain file";
1265 my $hello = "I am a HAL 9000 computer" x 2001 ;
1267 my $k = new $UncompressClass(\$hello, Transparent => 1);
1270 # Skip to the flush point -- no-op for plain file
1271 my $status = $k->inflateSync();
1273 or diag $k->error() ;
1276 is $k->read($rest, length($hello)), length($hello)
1277 or diag $k->error() ;
1278 ok $rest eq $hello ;
1284 title "inflateSync for real";
1286 # create a deflate stream with flush points
1288 my $hello = "I am a HAL 9000 computer" x 2001 ;
1289 my $goodbye = "Will I dream?" x 2010;
1290 my ($x, $err, $answer, $X, $Z, $status);
1293 ok ($x = new $CompressClass(\$Answer));
1296 is $x->write($hello), length($hello);
1298 # create a flush point
1299 ok $x->flush(Z_FULL_FLUSH) ;
1301 is $x->write($goodbye), length($goodbye);
1306 $k = new $UncompressClass(\$Answer, BlockSize => 1);
1310 is $k->read($initial, 1), 1 ;
1311 is $initial, substr($hello, 0, 1);
1313 # Skip to the flush point
1314 $status = $k->inflateSync();
1316 or diag $k->error() ;
1319 is $k->read($rest, length($hello) + length($goodbye)),
1321 or diag $k->error() ;
1322 ok $rest eq $goodbye ;
1328 title "inflateSync no FLUSH point";
1330 # create a deflate stream with flush points
1332 my $hello = "I am a HAL 9000 computer" x 2001 ;
1333 my ($x, $err, $answer, $X, $Z, $status);
1336 ok ($x = new $CompressClass(\$Answer));
1339 is $x->write($hello), length($hello);
1343 my $k = new $UncompressClass(\$Answer, BlockSize => 1);
1347 is $k->read($initial, 1), 1 ;
1348 is $initial, substr($hello, 0, 1);
1350 # Skip to the flush point
1351 $status = $k->inflateSync();
1353 or diag $k->error() ;
1356 is $k->inflateSync(), 0 ;
1360 title "write tests - invalid data" ;
1362 #my $lex = new LexFile my $name1 ;
1365 #ok ! -e $name1, " File $name1 does not exist";
1368 [ '{ }', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1369 [ '[ { } ]', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1370 [ '[ [ { } ] ]', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1371 [ '[ "" ]', "${CompressClass}::write: input filename is undef or null string" ],
1372 [ '[ undef ]', "${CompressClass}::write: input filename is undef or null string" ],
1373 [ '[ \$Answer ]',"${CompressClass}::write: input and output buffer are identical" ],
1374 #[ "not readable", 'xx' ],
1375 # same filehandle twice, 'xx'
1378 foreach my $data (@data)
1380 my ($send, $get) = @$data ;
1381 title "${CompressClass}::write( $send )";
1383 eval "\$copy = $send";
1384 my $x = new $CompressClass(\$Answer);
1385 ok $x, " Created $CompressClass object";
1386 eval { $x->write($copy) } ;
1387 #like $@, "/^$get/", " error - $get";
1388 like $@, "/not a scalar reference /", " error - not a scalar reference";
1392 # [ '[ $name1 ]', "input file '$name1' does not exist" ],
1393 # #[ "not readable", 'xx' ],
1394 # # same filehandle twice, 'xx'
1397 # foreach my $data (@data)
1399 # my ($send, $get) = @$data ;
1400 # title "${CompressClass}::write( $send )";
1402 # eval "\$copy = $send";
1403 # my $x = new $CompressClass(\$Answer);
1404 # ok $x, " Created $CompressClass object";
1405 # ok ! $x->write($copy), " write fails" ;
1406 # like $$Error, "/^$get/", " error - $get";
1416 # if (! ref $_[0] || ref $_[0] eq 'SCALAR')
1421 # if (ref $_[0] eq 'ARRAY')
1424 # for my $x ( @{ $_[0] })
1426 # push @a, deepCopy($x);
1432 # croak "bad! $_[0]";
1438 # #my $data = shift ;
1439 # my $from = $_[1] ;
1445 # if $_[0] eq $from ;
1450 # if (ref $_[0] eq 'SCALAR')
1453 # if defined ${ $_[0] } && ${ $_[0] } eq $from ;
1458 # if (ref $_[0] eq 'ARRAY')
1460 # for my $x ( @{ $_[0] })
1462 # deepSubst($x, $from, $to);
1466 # #croak "bad! $_[0]";
1470 # title "More write tests" ;
1472 # my $file1 = "file1" ;
1473 # my $file2 = "file2" ;
1474 # my $file3 = "file3" ;
1475 # my $lex = new LexFile $file1, $file2, $file3 ;
1477 # writeFile($file1, "F1");
1478 # writeFile($file2, "F2");
1479 # writeFile($file3, "F3");
1484 # [ '"abcd"', "abcd" ],
1488 # [ '\"abcd"', "abcd" ],
1494 # [ '[\undef]', "" ],
1495 # [ '[\"abcd"]', "abcd" ],
1496 # [ '[\"ab", \"cd"]', "abcd" ],
1497 # [ '[[\"ab"], [\"cd"]]', "abcd" ],
1499 # [ '$file1', $file1 ],
1501 # [ '[$file1, \"abc"]', "F1abc"],
1502 # [ '[\"a", $file1, \"bc"]', "aF1bc"],
1503 # [ '[\"a", $fh1, \"bc"]', "aF1bc"],
1504 # [ '[\"a", $fh1, \"bc", $file2]', "aF1bcF2"],
1505 # [ '[\"a", $fh1, \"bc", $file2, $fh3]', "aF1bcF2F3"],
1509 # foreach my $data (@data)
1511 # my ($send, $get) = @$data ;
1513 # my $fh1 = new IO::File "< $file1" ;
1514 # my $fh2 = new IO::File "< $file2" ;
1515 # my $fh3 = new IO::File "< $file3" ;
1517 # title "${CompressClass}::write( $send )";
1519 # eval "\$copy = $send";
1521 # my $x = new $CompressClass(\$Answer);
1522 # ok $x, " Created $CompressClass object";
1523 # my $len = length $get;
1524 # is $x->write($copy), length($get), " write $len bytes";
1525 # ok $x->close(), " close ok" ;
1527 # is myGZreadFile(\$Answer), $get, " got expected output" ;
1528 # cmp_ok $$Error, '==', 0, " no error";