9 use IO::Handle qw(SEEK_SET SEEK_CUR SEEK_END);
11 our ($UncompressClass);
14 # use Test::NoWarnings, if available
17 my $st = eval { require Test::NoWarnings ; import Test::NoWarnings; 1; };
21 plan(tests => 670 + $extra) ;
26 my $filename = shift ;
30 my $fil = new $UncompressClass $filename,
36 $data = $init if defined $init ;
37 1 while $fil->read($data) > 0;
45 my $CompressClass = identify();
46 $UncompressClass = getInverse($CompressClass);
47 my $Error = getErrorRef($CompressClass);
48 my $UnError = getErrorRef($UncompressClass);
53 title "Testing $CompressClass Errors";
56 eval qq[\$a = new $CompressClass(\\1) ;] ;
57 like $@, mkEvalErr("^$CompressClass: output buffer is read-only") ;
61 eval qq[\$a = new $CompressClass ] . '$out ;' ;
62 like $@, mkEvalErr("^$CompressClass: output filename is undef or null string");
65 eval qq[\$a = new $CompressClass \$out ;] ;
66 like $@, mkEvalErr("^$CompressClass: output filename is undef or null string");
69 $gz = new $CompressClass(\$x);
71 foreach my $name (qw(read readline getc))
73 eval " \$gz->$name() " ;
74 like $@, mkEvalErr("^$name Not Available: File opened only for output");
77 eval ' $gz->write({})' ;
78 like $@, mkEvalErr("^${CompressClass}::write: not a scalar reference");
79 #like $@, mkEvalErr("^${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref");
81 eval ' $gz->syswrite("abc", 1, 5)' ;
82 like $@, mkEvalErr("^${CompressClass}::write: offset outside string");
84 eval ' $gz->syswrite("abc", 1, -4)' ;
85 like $@, mkEvalErr("^${CompressClass}::write: offset outside string"), "write outside string";
90 title "Testing $UncompressClass Errors";
93 eval qq[\$a = new $UncompressClass \$out ;] ;
94 like $@, mkEvalErr("^$UncompressClass: input filename is undef or null string");
96 eval qq[\$a = new $UncompressClass \$out ;] ;
97 like $@, mkEvalErr("^$UncompressClass: input filename is undef or null string");
99 my $lex = new LexFile my $name ;
101 ok ! -e $name, " $name does not exist";
103 eval qq[\$a = new $UncompressClass "$name" ;] ;
104 is $$UnError, "input file '$name' does not exist";
107 my $guz = new $CompressClass(\$gc);
112 my $gz = new $UncompressClass(\$gc);
114 foreach my $name (qw(print printf write))
116 eval " \$gz->$name() " ;
117 like $@, mkEvalErr("^$name Not Available: File opened only for intput");
124 title "Testing $CompressClass and $UncompressClass";
127 my ($a, $x, @x) = ("","","") ;
129 # Buffer not a scalar reference
130 eval qq[\$a = new $CompressClass \\\@x ;] ;
131 like $@, mkEvalErr("^$CompressClass: output parameter not a filename, filehandle or scalar ref");
133 # Buffer not a scalar reference
134 eval qq[\$a = new $UncompressClass \\\@x ;] ;
135 like $@, mkEvalErr("^$UncompressClass: input parameter not a filename, filehandle, array ref or scalar ref");
138 foreach my $Type ( $CompressClass, $UncompressClass)
140 # Check error handling with IO::Compress::Deflate and IO::Uncompress::Inflate
142 my ($a, $x, @x) = ("","","") ;
144 # Odd number of parameters
145 eval qq[\$a = new $Type "abc", -Output ] ;
146 like $@, mkEvalErr("^$Type: Expected even number of parameters, got 1");
149 eval qq[\$a = new $Type "anc", -Fred => 123 ;] ;
150 like $@, mkEvalErr("^$Type: unknown key value\\(s\\) Fred");
153 eval qq[\$a = new $Type ;] ;
154 like $@, mkEvalErr("^$Type: Missing (Input|Output) parameter");
160 # write a very simple compressed file
162 #========================================
165 my $lex = new LexFile my $name ;
174 ok $x = new $CompressClass $name ;
175 is $x->autoflush(1), 0, "autoflush";
176 is $x->autoflush(1), 1, "autoflush";
177 ok $x->opened(), "opened";
179 ok $x->write($hello), "write" ;
180 ok $x->flush(), "flush";
181 ok $x->close, "close" ;
182 ok ! $x->opened(), "! opened";
187 ok my $x = new $UncompressClass $name, -Append => 1 ;
188 ok $x->opened(), "opened";
191 1 while ($len = $x->read($uncomp)) > 0 ;
193 is $len, 0, "read returned 0"
198 ok !$x->opened(), "! opened";
203 # write a very simple compressed file
205 #========================================
208 my $lex = new LexFile my $name ;
217 ok $x = new $CompressClass $name ;
219 is $x->write(''), 0, "Write empty string is ok";
220 is $x->write(undef), 0, "Write undef is ok";
221 ok $x->write($hello), "Write ok" ;
222 ok $x->close, "Close ok" ;
227 my $x = new $UncompressClass $name ;
228 ok $x, "creates $UncompressClass $name" ;
231 $data .= $uncomp while $x->read($uncomp) > 0 ;
233 ok $x->close, "close ok" ;
234 is $data, $hello, "expected output" ;
240 # write a very simple file with using an IO filehandle
242 #========================================
245 my $lex = new LexFile my $name ;
253 my $fh = new IO::File ">$name" ;
254 ok $fh, "opened file $name ok";
255 my $x = new $CompressClass $fh ;
256 ok $x, " created $CompressClass $fh" ;
258 is $x->fileno(), fileno($fh), "fileno match" ;
259 is $x->write(''), 0, "Write empty string is ok";
260 is $x->write(undef), 0, "Write undef is ok";
261 ok $x->write($hello), "write ok" ;
262 ok $x->flush(), "flush";
263 ok $x->close,"close" ;
270 ok my $fh1 = new IO::File "<$name" ;
271 ok $x = new $UncompressClass $fh1, -Append => 1 ;
272 ok $x->fileno() == fileno $fh1 ;
274 1 while $x->read($uncomp) > 0 ;
279 ok $hello eq $uncomp ;
283 # write a very simple file with using a glob filehandle
285 #========================================
288 my $lex = new LexFile my $name ;
289 #my $name = "/tmp/fred";
297 title "$CompressClass: Input from typeglob filehandle";
298 ok open FH, ">$name" ;
300 my $x = new $CompressClass *FH ;
301 ok $x, " create $CompressClass" ;
303 is $x->fileno(), fileno(*FH), " fileno" ;
304 is $x->write(''), 0, " Write empty string is ok";
305 is $x->write(undef), 0, " Write undef is ok";
306 ok $x->write($hello), " Write ok" ;
307 ok $x->flush(), " Flush";
308 ok $x->close, " Close" ;
315 title "$UncompressClass: Input from typeglob filehandle, append output";
317 ok open FH, "<$name" ;
318 ok $x = new $UncompressClass *FH, -Append => 1, Transparent => 0
320 is $x->fileno(), fileno FH, " fileno ok" ;
322 1 while $x->read($uncomp) > 0 ;
324 ok $x->close, " close" ;
327 is $uncomp, $hello, " expected output" ;
331 my $lex = new LexFile my $name ;
332 #my $name = "/tmp/fred";
340 title "Outout to stdout via '-'" ;
342 open(SAVEOUT, ">&STDOUT");
343 my $dummy = fileno SAVEOUT;
344 open STDOUT, ">$name" ;
346 my $x = new $CompressClass '-' ;
350 open(STDOUT, ">&SAVEOUT");
352 ok 1, " wrote to stdout" ;
354 is myGZreadFile($name), $hello, " wrote OK";
358 title "Input from stdin via filename '-'";
362 my $stdinFileno = fileno(STDIN);
363 # open below doesn't return 1 sometines on XP
364 open(SAVEIN, "<&STDIN");
365 ok open(STDIN, "<$name"), " redirect STDIN";
366 my $dummy = fileno SAVEIN;
367 $x = new $UncompressClass '-', Append => 1, Transparent => 0
369 ok $x, " created object" ;
370 is $x->fileno(), $stdinFileno, " fileno ok" ;
372 1 while $x->read($uncomp) > 0 ;
374 ok $x->close, " close" ;
375 open(STDIN, "<&SAVEIN");
376 is $uncomp, $hello, " expected output" ;
381 # write a compressed file to memory
383 #========================================
385 #my $name = "test.gz" ;
386 my $lex = new LexFile my $name ;
396 ok $x = new $CompressClass(\$buffer) ;
398 ok ! defined $x->autoflush(1) ;
399 ok ! defined $x->autoflush(1) ;
400 ok ! defined $x->fileno() ;
401 is $x->write(''), 0, "Write empty string is ok";
402 is $x->write(undef), 0, "Write undef is ok";
403 ok $x->write($hello) ;
407 writeFile($name, $buffer) ;
408 #is anyUncompress(\$buffer), $hello, " any ok";
415 ok $x = new $UncompressClass(\$buffer, Append => 1) ;
417 ok ! defined $x->autoflush(1) ;
418 ok ! defined $x->autoflush(1) ;
419 ok ! defined $x->fileno() ;
420 1 while $x->read($uncomp) > 0 ;
422 ok $x->close, "closed" ;
425 is $uncomp, $hello, "got expected uncompressed data" ;
426 ok $buffer eq $keep, "compressed input not changed" ;
429 if ($CompressClass ne 'RawDeflate')
432 #========================================
437 $x = new $CompressClass(\$buffer);
438 ok $x, "new $CompressClass" ;
439 ok $x->close, "close ok" ;
447 ok $x = new $UncompressClass(\$buffer, Append => 1) ;
449 1 while $x->read($uncomp) > 0 ;
455 ok $buffer eq $keep ;
460 # write a larger file
461 #========================================
464 my $lex = new LexFile my $name ;
475 my $x = new $CompressClass $name ;
476 ok $x, " created $CompressClass object";
478 ok $x->write($hello), " write ok" ;
480 ok $x->write("another line"), " write ok" ;
481 $input .= "another line" ;
484 { $contents .= chr int $_ }
485 # generate a long random string
487 { $contents .= chr int rand 256 }
489 ok $x->write($contents), " write ok" ;
490 $input .= $contents ;
491 ok $x->close, " close ok" ;
494 ok myGZreadFile($name) eq $input ;
495 my $x = readFile($name) ;
496 #print "length " . length($x) . " \n";
500 # embed a compressed file in another file
501 #================================
504 my $lex = new LexFile my $name ;
511 my $header = "header info\n" ;
512 my $trailer = "trailer data\n" ;
516 ok $fh = new IO::File ">$name" ;
519 ok $x = new $CompressClass $fh,
523 ok $x->write($hello) ;
531 ok $fh1 = new IO::File "<$name" ;
534 ok $line eq $header ;
536 ok my $x = new $UncompressClass $fh1, Append => 1 ;
538 1 while $x->read($uncomp) > 0 ;
540 ok $uncomp eq $hello ;
542 read($fh1, $rest, 5000);
543 is $x->trailingData() . $rest, $trailer ;
544 #print "# [".$x->trailingData() . "][$rest]\n" ;
549 # embed a compressed file in another buffer
550 #================================
558 my $trailer = "trailer data" ;
563 ok my $x = new $CompressClass(\$compressed);
565 ok $x->write($hello) ;
567 $compressed .= $trailer ;
571 ok my $x = new $UncompressClass(\$compressed, Append => 1) ;
572 1 while $x->read($uncomp) > 0 ;
574 ok $uncomp eq $hello ;
575 is $x->trailingData(), $trailer ;
581 # these tests come almost 100% from IO::String
583 my $lex = new LexFile my $name ;
585 my $io = $CompressClass->new($name);
587 is $io->tell(), 0, " tell returns 0"; ;
589 my $heisan = "Heisan\n";
590 $io->print($heisan) ;
592 ok ! $io->eof(), " ! eof";
594 is $io->tell(), length($heisan), " tell is " . length($heisan) ;
596 $io->print("a", "b", "c");
600 $io->print("d", "e");
602 $io->print("f", "g", "h");
607 $io->print("D", "E");
609 $io->print("F", "G", "H");
612 my $foo = "1234567890";
614 is $io->syswrite($foo, length($foo)), length($foo), " syswrite ok" ;
616 { is $io->syswrite($foo, length $foo), length $foo, " syswrite ok" }
618 { is $io->syswrite($foo), length $foo, " syswrite ok" }
619 is $io->syswrite($foo, length($foo)), length $foo, " syswrite ok";
620 is $io->write($foo, length($foo), 5), 5, " write 5";
621 is $io->write("xxx\n", 100, -1), 1, " write 1";
624 $io->printf("i(%d)", $_);
625 $io->printf("[%d]\n", $_);
631 ok $io->eof(), " eof";
633 is myGZreadFile($name), "Heisan\nabcde\nf,g,h\nDEF.G.H" .
634 ("1234567890" x 3) . "67890\n" .
635 "i(1)[1]\ni(2)[2]\ni(3)[3]\n\n",
652 my $lex = new LexFile my $name ;
655 my $iow = new $CompressClass $name, %opts;
656 is $iow->input_line_number, undef;
658 is $iow->input_line_number, undef;
664 my $io = new $UncompressClass $name ;
667 is $io->input_line_number, 0;
668 ok ! $io->eof, "eof";
669 is $io->tell(), 0, "tell 0" ;
671 my @lines = $io->getlines();
673 or print "# Got " . scalar(@lines) . " lines, expected 6\n" ;
674 is $lines[1], "of a paragraph\n" ;
675 is join('', @lines), $str ;
677 is $io->input_line_number, 6;
678 is $io->tell(), length($str) ;
682 ok ! ( defined($io->getline) ||
683 (@tmp = $io->getlines) ||
684 defined($io->getline) ||
685 defined($io->getc) ||
686 $io->read($buf, 100) != 0) ;
691 local $/; # slurp mode
692 my $io = $UncompressClass->new($name);
694 is $io->input_line_number, 0;
696 my @lines = $io->getlines;
698 is $io->input_line_number, 1;
700 ok @lines == 1 && $lines[0] eq $str;
702 $io = $UncompressClass->new($name);
704 my $line = $io->getline();
710 local $/ = ""; # paragraph mode
711 my $io = $UncompressClass->new($name);
713 is $io->input_line_number, 0;
715 my @lines = $io->getlines();
717 is $io->input_line_number, 2;
720 or print "# Got " . scalar(@lines) . " lines, expected 2\n" ;
721 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
722 or print "# $lines[0]\n";
723 ok $lines[1] eq "and a single line.\n\n";
729 my $expected_records = int(length($str) / $reclen)
730 + (length($str) % $reclen ? 1 : 0);
733 my $io = $UncompressClass->new($name);
735 is $io->input_line_number, 0;
738 my @lines = $io->getlines();
739 is $., $expected_records;
740 is $io->input_line_number, $expected_records;
742 is @lines, $expected_records,
743 "Got $expected_records records\n" ;
744 ok $lines[0] eq substr($str, 0, $reclen)
745 or print "# $lines[0]\n";
746 ok $lines[1] eq substr($str, $reclen, $reclen);
751 my $io = $UncompressClass->new($name);
756 while (my $a = $io->getline()) {
758 $err++ if $. != ++$no;
765 is $io->input_line_number, 3;
767 or print "# Got " . scalar(@lines) . " lines, expected 3\n" ;
768 ok join("-", @lines) eq
769 "This- is- an example\n" .
770 "of a paragraph\n\n\n" .
771 "and a single line.\n\n";
778 my $io = $UncompressClass->new($name);
781 eval { $io->read(1) } ;
782 like $@, mkErr("buffer parameter is read-only");
785 is $io->read($buf, 0), 0, "Requested 0 bytes" ;
786 is $buf, "", "Buffer empty";
788 is $io->read($buf, 3), 3 ;
791 is $io->sysread($buf, 3, 2), 3 ;
793 or print "# [$buf]\n" ;;
797 is $io->read($buf, 3, 4), 3 ;
798 is $buf, "ab" . "\x00" x 2 . "s a"
799 or print "# [$buf]\n" ;;
802 # read the rest of the file
804 my $remain = length($str) - 9;
805 is $io->read($buf, $remain+1), $remain ;
806 is $buf, substr($str, 9);
810 is $io->read($buf, 10), 0 ;
811 is $buf, "", "Buffer empty";
816 is $io->read($buf, 10), 0 ;
817 is $buf, "hello", "Buffer not empty";
824 # ok read($io, $buf, 20) == 4 ;
825 # ok $buf eq "e.\n\n";
827 # ok read($io, $buf, 20) == 0 ;
836 # Read from non-compressed file
847 my $lex = new LexFile my $name ;
849 writeFile($name, $str);
853 my $io = new $UncompressClass $name, -Transparent => 1 ;
857 ok $io->tell() == 0 ;
858 my @lines = $io->getlines();
860 ok $lines[1] eq "of a paragraph\n" ;
861 ok join('', @lines) eq $str ;
863 is $io->input_line_number, 6;
864 ok $io->tell() == length($str) ;
868 ok ! ( defined($io->getline) ||
869 (@tmp = $io->getlines) ||
870 defined($io->getline) ||
871 defined($io->getc) ||
872 $io->read($buf, 100) != 0) ;
877 local $/; # slurp mode
878 my $io = $UncompressClass->new($name);
880 my @lines = $io->getlines;
882 is $io->input_line_number, 1;
884 ok @lines == 1 && $lines[0] eq $str;
886 $io = $UncompressClass->new($name);
888 my $line = $io->getline;
890 is $io->input_line_number, 1;
896 local $/ = ""; # paragraph mode
897 my $io = $UncompressClass->new($name);
899 my @lines = $io->getlines;
901 is $io->input_line_number, 2;
904 or print "# exected 2 lines, got " . scalar(@lines) . "\n";
905 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
906 or print "# [$lines[0]]\n" ;
907 ok $lines[1] eq "and a single line.\n\n";
913 my $expected_records = int(length($str) / $reclen)
914 + (length($str) % $reclen ? 1 : 0);
917 my $io = $UncompressClass->new($name);
919 is $io->input_line_number, 0;
922 my @lines = $io->getlines();
923 is $., $expected_records;
924 is $io->input_line_number, $expected_records;
926 is @lines, $expected_records,
927 "Got $expected_records records\n" ;
928 ok $lines[0] eq substr($str, 0, $reclen)
929 or print "# $lines[0]\n";
930 ok $lines[1] eq substr($str, $reclen, $reclen);
935 my $io = $UncompressClass->new($name);
940 while (my $a = $io->getline) {
942 $err++ if $. != ++$no;
946 is $io->input_line_number, 3;
952 ok join("-", @lines) eq
953 "This- is- an example\n" .
954 "of a paragraph\n\n\n" .
955 "and a single line.\n\n";
962 my $io = $UncompressClass->new($name);
965 is $io->read($buf, 0), 0, "Requested 0 bytes" ;
966 is $buf, "", "Buffer empty";
968 ok $io->read($buf, 3) == 3 ;
971 ok $io->sysread($buf, 3, 2) == 3 ;
976 is $io->read($buf, 3, 4), 3 ;
977 is $buf, "ab" . "\x00" x 2 . "s a"
978 or print "# [$buf]\n" ;;
981 # read the rest of the file
983 my $remain = length($str) - 9;
984 is $io->read($buf, $remain), $remain ;
985 is $buf, substr($str, 9);
989 is $io->read($buf, 10), 0 ;
990 is $buf, "", "Buffer empty";
995 is $io->read($buf, 10), 0 ;
996 is $buf, "hello", "Buffer not empty";
1003 # ok read($io, $buf, 20) == 4 ;
1004 # ok $buf eq "e.\n\n";
1006 # ok read($io, $buf, 20) == 0 ;
1016 # Vary the length parameter in a read
1031 foreach my $bufsize (1, 3, 512, 4096, length($str)-1, length($str), length($str)+1)
1033 foreach my $trans (0, 1)
1035 foreach my $append (0, 1)
1037 title "Read Tests - buf length $bufsize, Transparent $trans, Append $append" ;
1039 my $lex = new LexFile my $name ;
1042 writeFile($name, $str) ;
1045 my $iow = new $CompressClass $name;
1051 my $io = $UncompressClass->new($name,
1053 -Transparent => $trans);
1060 1 while $io->read($buf, $bufsize) > 0;
1064 $buf .= $tmp while $io->read($tmp, $bufsize) > 0 ;
1066 is length $buf, length $str;
1075 foreach my $file (0, 1)
1077 foreach my $trans (0, 1)
1079 title "seek tests - file $file trans $trans" ;
1083 my $lex = new LexFile my $name ;
1085 my $first = "beginning" ;
1086 my $last = "the end" ;
1090 $buffer = $first . "\x00" x 10 . $last;
1091 writeFile($name, $buffer);
1105 my $iow = new $CompressClass $output ;
1106 $iow->print($first) ;
1107 ok $iow->seek(5, SEEK_CUR) ;
1108 ok $iow->tell() == length($first)+5;
1109 ok $iow->seek(0, SEEK_CUR) ;
1110 ok $iow->tell() == length($first)+5;
1111 ok $iow->seek(length($first)+10, SEEK_SET) ;
1112 ok $iow->tell() == length($first)+10;
1114 $iow->print($last) ;
1128 ok myGZreadFile($input) eq $first . "\x00" x 10 . $last ;
1130 my $io = $UncompressClass->new($input, Strict => 1);
1131 ok $io->seek(length($first), SEEK_CUR)
1134 is $io->tell(), length($first);
1136 ok $io->read($buff, 5) ;
1137 is $buff, "\x00" x 5 ;
1138 is $io->tell(), length($first) + 5;
1140 ok $io->seek(0, SEEK_CUR) ;
1141 my $here = $io->tell() ;
1142 is $here, length($first)+5;
1144 ok $io->seek($here+5, SEEK_SET) ;
1145 is $io->tell(), $here+5 ;
1146 ok $io->read($buff, 100) ;
1153 title "seek error cases" ;
1156 my $a = new $CompressClass(\$b) ;
1159 eval { $a->seek(-1, 10) ; };
1160 like $@, mkErr("^${CompressClass}::seek: unknown value, 10, for whence parameter");
1162 eval { $a->seek(-1, SEEK_END) ; };
1163 like $@, mkErr("^${CompressClass}::seek: cannot seek backwards");
1169 my $u = new $UncompressClass(\$b) ;
1171 eval { $u->seek(-1, 10) ; };
1172 like $@, mkErr("^${UncompressClass}::seek: unknown value, 10, for whence parameter");
1174 eval { $u->seek(-1, SEEK_END) ; };
1175 like $@, mkErr("^${UncompressClass}::seek: SEEK_END not allowed");
1177 eval { $u->seek(-1, SEEK_CUR) ; };
1178 like $@, mkErr("^${UncompressClass}::seek: cannot seek backwards");
1181 foreach my $fb (qw(filename buffer filehandle))
1183 foreach my $append (0, 1)
1186 title "$CompressClass -- Append $append, Output to $fb" ;
1188 my $lex = new LexFile my $name ;
1190 my $already = 'already';
1191 my $buffer = $already;
1194 if ($fb eq 'buffer')
1195 { $output = \$buffer }
1196 elsif ($fb eq 'filename')
1199 writeFile($name, $buffer);
1201 elsif ($fb eq 'filehandle')
1203 $output = new IO::File ">$name" ;
1204 print $output $buffer;
1207 my $a = new $CompressClass($output, Append => $append) ;
1208 ok $a, " Created $CompressClass";
1209 my $string = "appended";
1214 if ($fb eq 'buffer')
1221 if $fb eq 'filehandle';
1222 $data = readFile($name);
1225 if ($append || $fb eq 'filehandle')
1227 is substr($data, 0, length($already)), $already, " got prefix";
1228 substr($data, 0, length($already)) = '';
1233 my $x = new $UncompressClass(\$data, Append => 1) ;
1234 ok $x, " created $UncompressClass";
1237 1 while ($len = $x->read($uncomp)) > 0 ;
1240 is $uncomp, $string, ' Got uncompressed data' ;
1246 foreach my $type (qw(buffer filename filehandle))
1248 foreach my $good (0, 1)
1250 title "$UncompressClass -- InputLength, read from $type, good data => $good";
1253 my $string = "some data";
1254 my $appended = "append";
1258 my $c = new $CompressClass(\$compressed);
1264 $compressed = $string ;
1267 my $comp_len = length $compressed;
1268 $compressed .= $appended;
1270 my $lex = new LexFile my $name ;
1272 writeFile ($name, $compressed);
1274 if ($type eq 'buffer')
1276 $input = \$compressed;
1278 if ($type eq 'filename')
1282 elsif ($type eq 'filehandle')
1284 my $fh = new IO::File "<$name" ;
1285 ok $fh, "opened file $name ok";
1289 my $x = new $UncompressClass($input,
1290 InputLength => $comp_len,
1292 ok $x, " created $UncompressClass";
1296 $len = $x->read($output, 100);
1298 is $len, length($string);
1299 is $output, $string;
1301 if ($type eq 'filehandle')
1304 $input->read($rest, 1000);
1305 is $rest, $appended;
1312 foreach my $append (0, 1)
1314 title "$UncompressClass -- Append $append" ;
1316 my $lex = new LexFile my $name ;
1318 my $string = "appended";
1320 my $c = new $CompressClass(\$compressed);
1324 my $x = new $UncompressClass(\$compressed, Append => $append) ;
1325 ok $x, " created $UncompressClass";
1327 my $already = 'already';
1328 my $output = $already;
1331 $len = $x->read($output, 100);
1332 is $len, length($string);
1338 is substr($output, 0, length($already)), $already, " got prefix";
1339 substr($output, 0, length($already)) = '';
1341 is $output, $string, ' Got uncompressed data' ;
1345 foreach my $file (0, 1)
1347 foreach my $trans (0, 1)
1349 title "ungetc, File $file, Transparent $trans" ;
1351 my $lex = new LexFile my $name ;
1353 my $string = 'abcdeABCDE';
1361 my $a = new $CompressClass(\$b) ;
1369 writeFile($name, $b);
1377 my $u = $UncompressClass->new($from, Transparent => 1) ;
1381 # do an ungetc before reading
1383 $first = $u->getc();
1386 $first = $u->getc();
1387 is $first, substr($string, 0,1);
1389 $first = $u->getc();
1390 is $first, substr($string, 0,1);
1393 is $u->read($buff, 5), 5 ;
1394 is $buff, substr($string, 0, 5);
1397 is $u->read($buff, length($string)), length($string) ;
1400 is $u->read($buff, 1), 0;
1403 my $extra = 'extra';
1406 is $u->read($buff), length($extra) ;
1409 is $u->read($buff, 1), 0;
1412 # getc returns undef on eof
1413 is $u->getc(), undef;
1420 title "write tests - invalid data" ;
1422 #my $lex = new LexFile my $name1 ;
1425 #ok ! -e $name1, " File $name1 does not exist";
1428 [ '{ }', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1429 [ '[ { } ]', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1430 [ '[ [ { } ] ]', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1431 [ '[ "" ]', "${CompressClass}::write: input filename is undef or null string" ],
1432 [ '[ undef ]', "${CompressClass}::write: input filename is undef or null string" ],
1433 [ '[ \$Answer ]',"${CompressClass}::write: input and output buffer are identical" ],
1434 #[ "not readable", 'xx' ],
1435 # same filehandle twice, 'xx'
1438 foreach my $data (@data)
1440 my ($send, $get) = @$data ;
1441 title "${CompressClass}::write( $send )";
1443 eval "\$copy = $send";
1444 my $x = new $CompressClass(\$Answer);
1445 ok $x, " Created $CompressClass object";
1446 eval { $x->write($copy) } ;
1447 #like $@, "/^$get/", " error - $get";
1448 like $@, "/not a scalar reference /", " error - not a scalar reference";
1452 # [ '[ $name1 ]', "input file '$name1' does not exist" ],
1453 # #[ "not readable", 'xx' ],
1454 # # same filehandle twice, 'xx'
1457 # foreach my $data (@data)
1459 # my ($send, $get) = @$data ;
1460 # title "${CompressClass}::write( $send )";
1462 # eval "\$copy = $send";
1463 # my $x = new $CompressClass(\$Answer);
1464 # ok $x, " Created $CompressClass object";
1465 # ok ! $x->write($copy), " write fails" ;
1466 # like $$Error, "/^$get/", " error - $get";
1476 # if (! ref $_[0] || ref $_[0] eq 'SCALAR')
1481 # if (ref $_[0] eq 'ARRAY')
1484 # for my $x ( @{ $_[0] })
1486 # push @a, deepCopy($x);
1492 # croak "bad! $_[0]";
1498 # #my $data = shift ;
1499 # my $from = $_[1] ;
1505 # if $_[0] eq $from ;
1510 # if (ref $_[0] eq 'SCALAR')
1513 # if defined ${ $_[0] } && ${ $_[0] } eq $from ;
1518 # if (ref $_[0] eq 'ARRAY')
1520 # for my $x ( @{ $_[0] })
1522 # deepSubst($x, $from, $to);
1526 # #croak "bad! $_[0]";
1530 # title "More write tests" ;
1532 # my $file1 = "file1" ;
1533 # my $file2 = "file2" ;
1534 # my $file3 = "file3" ;
1535 # my $lex = new LexFile $file1, $file2, $file3 ;
1537 # writeFile($file1, "F1");
1538 # writeFile($file2, "F2");
1539 # writeFile($file3, "F3");
1544 # [ '"abcd"', "abcd" ],
1548 # [ '\"abcd"', "abcd" ],
1554 # [ '[\undef]', "" ],
1555 # [ '[\"abcd"]', "abcd" ],
1556 # [ '[\"ab", \"cd"]', "abcd" ],
1557 # [ '[[\"ab"], [\"cd"]]', "abcd" ],
1559 # [ '$file1', $file1 ],
1561 # [ '[$file1, \"abc"]', "F1abc"],
1562 # [ '[\"a", $file1, \"bc"]', "aF1bc"],
1563 # [ '[\"a", $fh1, \"bc"]', "aF1bc"],
1564 # [ '[\"a", $fh1, \"bc", $file2]', "aF1bcF2"],
1565 # [ '[\"a", $fh1, \"bc", $file2, $fh3]', "aF1bcF2F3"],
1569 # foreach my $data (@data)
1571 # my ($send, $get) = @$data ;
1573 # my $fh1 = new IO::File "< $file1" ;
1574 # my $fh2 = new IO::File "< $file2" ;
1575 # my $fh3 = new IO::File "< $file3" ;
1577 # title "${CompressClass}::write( $send )";
1579 # eval "\$copy = $send";
1581 # my $x = new $CompressClass(\$Answer);
1582 # ok $x, " Created $CompressClass object";
1583 # my $len = length $get;
1584 # is $x->write($copy), length($get), " write $len bytes";
1585 # ok $x->close(), " close ok" ;
1587 # is myGZreadFile(\$Answer), $get, " got expected output" ;
1588 # cmp_ok $$Error, '==', 0, " no error";