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");
123 title "Testing $CompressClass and $UncompressClass";
126 my ($a, $x, @x) = ("","","") ;
128 # Buffer not a scalar reference
129 eval qq[\$a = new $CompressClass \\\@x ;] ;
130 like $@, mkEvalErr("^$CompressClass: output parameter not a filename, filehandle or scalar ref");
132 # Buffer not a scalar reference
133 eval qq[\$a = new $UncompressClass \\\@x ;] ;
134 like $@, mkEvalErr("^$UncompressClass: input parameter not a filename, filehandle, array ref or scalar ref");
137 foreach my $Type ( $CompressClass, $UncompressClass)
139 # Check error handling with IO::Compress::Deflate and IO::Uncompress::Inflate
141 my ($a, $x, @x) = ("","","") ;
143 # Odd number of parameters
144 eval qq[\$a = new $Type "abc", -Output ] ;
145 like $@, mkEvalErr("^$Type: Expected even number of parameters, got 1");
148 eval qq[\$a = new $Type "anc", -Fred => 123 ;] ;
149 like $@, mkEvalErr("^$Type: unknown key value\\(s\\) Fred");
152 eval qq[\$a = new $Type ;] ;
153 like $@, mkEvalErr("^$Type: Missing (Input|Output) parameter");
159 # write a very simple compressed file
161 #========================================
164 my $lex = new LexFile my $name ;
173 ok $x = new $CompressClass $name ;
174 is $x->autoflush(1), 0, "autoflush";
175 is $x->autoflush(1), 1, "autoflush";
176 ok $x->opened(), "opened";
178 ok $x->write($hello), "write" ;
179 ok $x->flush(), "flush";
180 ok $x->close, "close" ;
181 ok ! $x->opened(), "! opened";
186 ok my $x = new $UncompressClass $name, -Append => 1 ;
187 ok $x->opened(), "opened";
190 1 while ($len = $x->read($uncomp)) > 0 ;
192 is $len, 0, "read returned 0"
197 ok !$x->opened(), "! opened";
202 # write a very simple compressed file
204 #========================================
207 my $lex = new LexFile my $name ;
216 ok $x = new $CompressClass $name ;
218 is $x->write(''), 0, "Write empty string is ok";
219 is $x->write(undef), 0, "Write undef is ok";
220 ok $x->write($hello), "Write ok" ;
221 ok $x->close, "Close ok" ;
226 my $x = new $UncompressClass $name ;
227 ok $x, "creates $UncompressClass $name" ;
230 $data .= $uncomp while $x->read($uncomp) > 0 ;
232 ok $x->close, "close ok" ;
233 is $data, $hello, "expected output" ;
239 # write a very simple file with using an IO filehandle
241 #========================================
244 my $lex = new LexFile my $name ;
252 my $fh = new IO::File ">$name" ;
253 ok $fh, "opened file $name ok";
254 my $x = new $CompressClass $fh ;
255 ok $x, " created $CompressClass $fh" ;
257 is $x->fileno(), fileno($fh), "fileno match" ;
258 is $x->write(''), 0, "Write empty string is ok";
259 is $x->write(undef), 0, "Write undef is ok";
260 ok $x->write($hello), "write ok" ;
261 ok $x->flush(), "flush";
262 ok $x->close,"close" ;
269 ok my $fh1 = new IO::File "<$name" ;
270 ok $x = new $UncompressClass $fh1, -Append => 1 ;
271 ok $x->fileno() == fileno $fh1 ;
273 1 while $x->read($uncomp) > 0 ;
278 ok $hello eq $uncomp ;
282 # write a very simple file with using a glob filehandle
284 #========================================
287 my $lex = new LexFile my $name ;
288 #my $name = "/tmp/fred";
296 title "$CompressClass: Input from typeglob filehandle";
297 ok open FH, ">$name" ;
299 my $x = new $CompressClass *FH ;
300 ok $x, " create $CompressClass" ;
302 is $x->fileno(), fileno(*FH), " fileno" ;
303 is $x->write(''), 0, " Write empty string is ok";
304 is $x->write(undef), 0, " Write undef is ok";
305 ok $x->write($hello), " Write ok" ;
306 ok $x->flush(), " Flush";
307 ok $x->close, " Close" ;
314 title "$UncompressClass: Input from typeglob filehandle, append output";
316 ok open FH, "<$name" ;
317 ok $x = new $UncompressClass *FH, -Append => 1, Transparent => 0
319 is $x->fileno(), fileno FH, " fileno ok" ;
321 1 while $x->read($uncomp) > 0 ;
323 ok $x->close, " close" ;
326 is $uncomp, $hello, " expected output" ;
330 my $lex = new LexFile my $name ;
331 #my $name = "/tmp/fred";
339 title "Outout to stdout via '-'" ;
341 open(SAVEOUT, ">&STDOUT");
342 my $dummy = fileno SAVEOUT;
343 open STDOUT, ">$name" ;
345 my $x = new $CompressClass '-' ;
349 open(STDOUT, ">&SAVEOUT");
351 ok 1, " wrote to stdout" ;
353 is myGZreadFile($name), $hello, " wrote OK";
357 title "Input from stdin via filename '-'";
361 my $stdinFileno = fileno(STDIN);
362 # open below doesn't return 1 sometines on XP
363 open(SAVEIN, "<&STDIN");
364 ok open(STDIN, "<$name"), " redirect STDIN";
365 my $dummy = fileno SAVEIN;
366 $x = new $UncompressClass '-', Append => 1, Transparent => 0
368 ok $x, " created object" ;
369 is $x->fileno(), $stdinFileno, " fileno ok" ;
371 1 while $x->read($uncomp) > 0 ;
373 ok $x->close, " close" ;
374 open(STDIN, "<&SAVEIN");
375 is $uncomp, $hello, " expected output" ;
380 # write a compressed file to memory
382 #========================================
384 #my $name = "test.gz" ;
385 my $lex = new LexFile my $name ;
395 ok $x = new $CompressClass(\$buffer) ;
397 ok ! defined $x->autoflush(1) ;
398 ok ! defined $x->autoflush(1) ;
399 ok ! defined $x->fileno() ;
400 is $x->write(''), 0, "Write empty string is ok";
401 is $x->write(undef), 0, "Write undef is ok";
402 ok $x->write($hello) ;
406 writeFile($name, $buffer) ;
407 #is anyUncompress(\$buffer), $hello, " any ok";
414 ok $x = new $UncompressClass(\$buffer, Append => 1) ;
416 ok ! defined $x->autoflush(1) ;
417 ok ! defined $x->autoflush(1) ;
418 ok ! defined $x->fileno() ;
419 1 while $x->read($uncomp) > 0 ;
421 ok $x->close, "closed" ;
424 is $uncomp, $hello, "got expected uncompressed data" ;
425 ok $buffer eq $keep, "compressed input not changed" ;
428 if ($CompressClass ne 'RawDeflate')
431 #========================================
436 $x = new $CompressClass(\$buffer);
437 ok $x, "new $CompressClass" ;
438 ok $x->close, "close ok" ;
446 ok $x = new $UncompressClass(\$buffer, Append => 1) ;
448 1 while $x->read($uncomp) > 0 ;
454 ok $buffer eq $keep ;
459 # write a larger file
460 #========================================
463 my $lex = new LexFile my $name ;
474 my $x = new $CompressClass $name ;
475 ok $x, " created $CompressClass object";
477 ok $x->write($hello), " write ok" ;
479 ok $x->write("another line"), " write ok" ;
480 $input .= "another line" ;
483 { $contents .= chr int $_ }
484 # generate a long random string
486 { $contents .= chr int rand 256 }
488 ok $x->write($contents), " write ok" ;
489 $input .= $contents ;
490 ok $x->close, " close ok" ;
493 ok myGZreadFile($name) eq $input ;
494 my $x = readFile($name) ;
495 #print "length " . length($x) . " \n";
499 # embed a compressed file in another file
500 #================================
503 my $lex = new LexFile my $name ;
510 my $header = "header info\n" ;
511 my $trailer = "trailer data\n" ;
515 ok $fh = new IO::File ">$name" ;
518 ok $x = new $CompressClass $fh,
522 ok $x->write($hello) ;
530 ok $fh1 = new IO::File "<$name" ;
533 ok $line eq $header ;
535 ok my $x = new $UncompressClass $fh1, Append => 1 ;
537 1 while $x->read($uncomp) > 0 ;
539 ok $uncomp eq $hello ;
541 read($fh1, $rest, 5000);
542 is $x->trailingData() . $rest, $trailer ;
543 #print "# [".$x->trailingData() . "][$rest]\n" ;
548 # embed a compressed file in another buffer
549 #================================
557 my $trailer = "trailer data" ;
562 ok my $x = new $CompressClass(\$compressed);
564 ok $x->write($hello) ;
566 $compressed .= $trailer ;
570 ok my $x = new $UncompressClass(\$compressed, Append => 1) ;
571 1 while $x->read($uncomp) > 0 ;
573 ok $uncomp eq $hello ;
574 is $x->trailingData(), $trailer ;
580 # these tests come almost 100% from IO::String
582 my $lex = new LexFile my $name ;
584 my $io = $CompressClass->new($name);
586 is $io->tell(), 0, " tell returns 0"; ;
588 my $heisan = "Heisan\n";
589 $io->print($heisan) ;
591 ok ! $io->eof(), " ! eof";
593 is $io->tell(), length($heisan), " tell is " . length($heisan) ;
595 $io->print("a", "b", "c");
599 $io->print("d", "e");
601 $io->print("f", "g", "h");
606 $io->print("D", "E");
608 $io->print("F", "G", "H");
611 my $foo = "1234567890";
613 is $io->syswrite($foo, length($foo)), length($foo), " syswrite ok" ;
615 { is $io->syswrite($foo, length $foo), length $foo, " syswrite ok" }
617 { is $io->syswrite($foo), length $foo, " syswrite ok" }
618 is $io->syswrite($foo, length($foo)), length $foo, " syswrite ok";
619 is $io->write($foo, length($foo), 5), 5, " write 5";
620 is $io->write("xxx\n", 100, -1), 1, " write 1";
623 $io->printf("i(%d)", $_);
624 $io->printf("[%d]\n", $_);
630 ok $io->eof(), " eof";
632 is myGZreadFile($name), "Heisan\nabcde\nf,g,h\nDEF.G.H" .
633 ("1234567890" x 3) . "67890\n" .
634 "i(1)[1]\ni(2)[2]\ni(3)[3]\n\n",
651 my $lex = new LexFile my $name ;
654 my $iow = new $CompressClass $name, %opts;
655 is $iow->input_line_number, undef;
657 is $iow->input_line_number, undef;
663 my $io = new $UncompressClass $name ;
666 is $io->input_line_number, 0;
667 ok ! $io->eof, "eof";
668 is $io->tell(), 0, "tell 0" ;
670 my @lines = $io->getlines();
672 or print "# Got " . scalar(@lines) . " lines, expected 6\n" ;
673 is $lines[1], "of a paragraph\n" ;
674 is join('', @lines), $str ;
676 is $io->input_line_number, 6;
677 is $io->tell(), length($str) ;
681 ok ! ( defined($io->getline) ||
682 (@tmp = $io->getlines) ||
683 defined($io->getline) ||
684 defined($io->getc) ||
685 $io->read($buf, 100) != 0) ;
690 local $/; # slurp mode
691 my $io = $UncompressClass->new($name);
693 is $io->input_line_number, 0;
695 my @lines = $io->getlines;
697 is $io->input_line_number, 1;
699 ok @lines == 1 && $lines[0] eq $str;
701 $io = $UncompressClass->new($name);
703 my $line = $io->getline();
709 local $/ = ""; # paragraph mode
710 my $io = $UncompressClass->new($name);
712 is $io->input_line_number, 0;
714 my @lines = $io->getlines();
716 is $io->input_line_number, 2;
719 or print "# Got " . scalar(@lines) . " lines, expected 2\n" ;
720 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
721 or print "# $lines[0]\n";
722 ok $lines[1] eq "and a single line.\n\n";
728 my $expected_records = int(length($str) / $reclen)
729 + (length($str) % $reclen ? 1 : 0);
732 my $io = $UncompressClass->new($name);
734 is $io->input_line_number, 0;
737 my @lines = $io->getlines();
738 is $., $expected_records;
739 is $io->input_line_number, $expected_records;
741 is @lines, $expected_records,
742 "Got $expected_records records\n" ;
743 ok $lines[0] eq substr($str, 0, $reclen)
744 or print "# $lines[0]\n";
745 ok $lines[1] eq substr($str, $reclen, $reclen);
750 my $io = $UncompressClass->new($name);
755 while (my $a = $io->getline()) {
757 $err++ if $. != ++$no;
764 is $io->input_line_number, 3;
766 or print "# Got " . scalar(@lines) . " lines, expected 3\n" ;
767 ok join("-", @lines) eq
768 "This- is- an example\n" .
769 "of a paragraph\n\n\n" .
770 "and a single line.\n\n";
777 my $io = $UncompressClass->new($name);
780 eval { $io->read(1) } ;
781 like $@, mkErr("buffer parameter is read-only");
784 is $io->read($buf, 0), 0, "Requested 0 bytes" ;
785 is $buf, "", "Buffer empty";
787 is $io->read($buf, 3), 3 ;
790 is $io->sysread($buf, 3, 2), 3 ;
792 or print "# [$buf]\n" ;;
796 is $io->read($buf, 3, 4), 3 ;
797 is $buf, "ab" . "\x00" x 2 . "s a"
798 or print "# [$buf]\n" ;;
801 # read the rest of the file
803 my $remain = length($str) - 9;
804 is $io->read($buf, $remain+1), $remain ;
805 is $buf, substr($str, 9);
809 is $io->read($buf, 10), 0 ;
810 is $buf, "", "Buffer empty";
815 is $io->read($buf, 10), 0 ;
816 is $buf, "hello", "Buffer not empty";
823 # ok read($io, $buf, 20) == 4 ;
824 # ok $buf eq "e.\n\n";
826 # ok read($io, $buf, 20) == 0 ;
835 # Read from non-compressed file
846 my $lex = new LexFile my $name ;
848 writeFile($name, $str);
852 my $io = new $UncompressClass $name, -Transparent => 1 ;
856 ok $io->tell() == 0 ;
857 my @lines = $io->getlines();
859 ok $lines[1] eq "of a paragraph\n" ;
860 ok join('', @lines) eq $str ;
862 is $io->input_line_number, 6;
863 ok $io->tell() == length($str) ;
867 ok ! ( defined($io->getline) ||
868 (@tmp = $io->getlines) ||
869 defined($io->getline) ||
870 defined($io->getc) ||
871 $io->read($buf, 100) != 0) ;
876 local $/; # slurp mode
877 my $io = $UncompressClass->new($name);
879 my @lines = $io->getlines;
881 is $io->input_line_number, 1;
883 ok @lines == 1 && $lines[0] eq $str;
885 $io = $UncompressClass->new($name);
887 my $line = $io->getline;
889 is $io->input_line_number, 1;
895 local $/ = ""; # paragraph mode
896 my $io = $UncompressClass->new($name);
898 my @lines = $io->getlines;
900 is $io->input_line_number, 2;
903 or print "# exected 2 lines, got " . scalar(@lines) . "\n";
904 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
905 or print "# [$lines[0]]\n" ;
906 ok $lines[1] eq "and a single line.\n\n";
912 my $expected_records = int(length($str) / $reclen)
913 + (length($str) % $reclen ? 1 : 0);
916 my $io = $UncompressClass->new($name);
918 is $io->input_line_number, 0;
921 my @lines = $io->getlines();
922 is $., $expected_records;
923 is $io->input_line_number, $expected_records;
925 is @lines, $expected_records,
926 "Got $expected_records records\n" ;
927 ok $lines[0] eq substr($str, 0, $reclen)
928 or print "# $lines[0]\n";
929 ok $lines[1] eq substr($str, $reclen, $reclen);
934 my $io = $UncompressClass->new($name);
939 while (my $a = $io->getline) {
941 $err++ if $. != ++$no;
945 is $io->input_line_number, 3;
951 ok join("-", @lines) eq
952 "This- is- an example\n" .
953 "of a paragraph\n\n\n" .
954 "and a single line.\n\n";
961 my $io = $UncompressClass->new($name);
964 is $io->read($buf, 0), 0, "Requested 0 bytes" ;
965 is $buf, "", "Buffer empty";
967 ok $io->read($buf, 3) == 3 ;
970 ok $io->sysread($buf, 3, 2) == 3 ;
975 is $io->read($buf, 3, 4), 3 ;
976 is $buf, "ab" . "\x00" x 2 . "s a"
977 or print "# [$buf]\n" ;;
980 # read the rest of the file
982 my $remain = length($str) - 9;
983 is $io->read($buf, $remain), $remain ;
984 is $buf, substr($str, 9);
988 is $io->read($buf, 10), 0 ;
989 is $buf, "", "Buffer empty";
994 is $io->read($buf, 10), 0 ;
995 is $buf, "hello", "Buffer not empty";
1002 # ok read($io, $buf, 20) == 4 ;
1003 # ok $buf eq "e.\n\n";
1005 # ok read($io, $buf, 20) == 0 ;
1015 # Vary the length parameter in a read
1030 foreach my $bufsize (1, 3, 512, 4096, length($str)-1, length($str), length($str)+1)
1032 foreach my $trans (0, 1)
1034 foreach my $append (0, 1)
1036 title "Read Tests - buf length $bufsize, Transparent $trans, Append $append" ;
1038 my $lex = new LexFile my $name ;
1041 writeFile($name, $str) ;
1044 my $iow = new $CompressClass $name;
1050 my $io = $UncompressClass->new($name,
1052 -Transparent => $trans);
1059 1 while $io->read($buf, $bufsize) > 0;
1063 $buf .= $tmp while $io->read($tmp, $bufsize) > 0 ;
1065 is length $buf, length $str;
1074 foreach my $file (0, 1)
1076 foreach my $trans (0, 1)
1078 title "seek tests - file $file trans $trans" ;
1082 my $lex = new LexFile my $name ;
1084 my $first = "beginning" ;
1085 my $last = "the end" ;
1089 $buffer = $first . "\x00" x 10 . $last;
1090 writeFile($name, $buffer);
1104 my $iow = new $CompressClass $output ;
1105 $iow->print($first) ;
1106 ok $iow->seek(5, SEEK_CUR) ;
1107 ok $iow->tell() == length($first)+5;
1108 ok $iow->seek(0, SEEK_CUR) ;
1109 ok $iow->tell() == length($first)+5;
1110 ok $iow->seek(length($first)+10, SEEK_SET) ;
1111 ok $iow->tell() == length($first)+10;
1113 $iow->print($last) ;
1127 ok myGZreadFile($input) eq $first . "\x00" x 10 . $last ;
1129 my $io = $UncompressClass->new($input, Strict => 1);
1130 ok $io->seek(length($first), SEEK_CUR)
1133 is $io->tell(), length($first);
1135 ok $io->read($buff, 5) ;
1136 is $buff, "\x00" x 5 ;
1137 is $io->tell(), length($first) + 5;
1139 ok $io->seek(0, SEEK_CUR) ;
1140 my $here = $io->tell() ;
1141 is $here, length($first)+5;
1143 ok $io->seek($here+5, SEEK_SET) ;
1144 is $io->tell(), $here+5 ;
1145 ok $io->read($buff, 100) ;
1152 title "seek error cases" ;
1155 my $a = new $CompressClass(\$b) ;
1158 eval { $a->seek(-1, 10) ; };
1159 like $@, mkErr("^${CompressClass}::seek: unknown value, 10, for whence parameter");
1161 eval { $a->seek(-1, SEEK_END) ; };
1162 like $@, mkErr("^${CompressClass}::seek: cannot seek backwards");
1168 my $u = new $UncompressClass(\$b) ;
1170 eval { $u->seek(-1, 10) ; };
1171 like $@, mkErr("^${UncompressClass}::seek: unknown value, 10, for whence parameter");
1173 eval { $u->seek(-1, SEEK_END) ; };
1174 like $@, mkErr("^${UncompressClass}::seek: SEEK_END not allowed");
1176 eval { $u->seek(-1, SEEK_CUR) ; };
1177 like $@, mkErr("^${UncompressClass}::seek: cannot seek backwards");
1180 foreach my $fb (qw(filename buffer filehandle))
1182 foreach my $append (0, 1)
1185 title "$CompressClass -- Append $append, Output to $fb" ;
1187 my $lex = new LexFile my $name ;
1189 my $already = 'already';
1190 my $buffer = $already;
1193 if ($fb eq 'buffer')
1194 { $output = \$buffer }
1195 elsif ($fb eq 'filename')
1198 writeFile($name, $buffer);
1200 elsif ($fb eq 'filehandle')
1202 $output = new IO::File ">$name" ;
1203 print $output $buffer;
1206 my $a = new $CompressClass($output, Append => $append) ;
1207 ok $a, " Created $CompressClass";
1208 my $string = "appended";
1213 if ($fb eq 'buffer')
1220 if $fb eq 'filehandle';
1221 $data = readFile($name);
1224 if ($append || $fb eq 'filehandle')
1226 is substr($data, 0, length($already)), $already, " got prefix";
1227 substr($data, 0, length($already)) = '';
1232 my $x = new $UncompressClass(\$data, Append => 1) ;
1233 ok $x, " created $UncompressClass";
1236 1 while ($len = $x->read($uncomp)) > 0 ;
1239 is $uncomp, $string, ' Got uncompressed data' ;
1245 foreach my $type (qw(buffer filename filehandle))
1247 foreach my $good (0, 1)
1249 title "$UncompressClass -- InputLength, read from $type, good data => $good";
1252 my $string = "some data";
1253 my $appended = "append";
1257 my $c = new $CompressClass(\$compressed);
1263 $compressed = $string ;
1266 my $comp_len = length $compressed;
1267 $compressed .= $appended;
1269 my $lex = new LexFile my $name ;
1271 writeFile ($name, $compressed);
1273 if ($type eq 'buffer')
1275 $input = \$compressed;
1277 if ($type eq 'filename')
1281 elsif ($type eq 'filehandle')
1283 my $fh = new IO::File "<$name" ;
1284 ok $fh, "opened file $name ok";
1288 my $x = new $UncompressClass($input,
1289 InputLength => $comp_len,
1291 ok $x, " created $UncompressClass";
1295 $len = $x->read($output, 100);
1297 is $len, length($string);
1298 is $output, $string;
1300 if ($type eq 'filehandle')
1303 $input->read($rest, 1000);
1304 is $rest, $appended;
1311 foreach my $append (0, 1)
1313 title "$UncompressClass -- Append $append" ;
1315 my $lex = new LexFile my $name ;
1317 my $string = "appended";
1319 my $c = new $CompressClass(\$compressed);
1323 my $x = new $UncompressClass(\$compressed, Append => $append) ;
1324 ok $x, " created $UncompressClass";
1326 my $already = 'already';
1327 my $output = $already;
1330 $len = $x->read($output, 100);
1331 is $len, length($string);
1337 is substr($output, 0, length($already)), $already, " got prefix";
1338 substr($output, 0, length($already)) = '';
1340 is $output, $string, ' Got uncompressed data' ;
1344 foreach my $file (0, 1)
1346 foreach my $trans (0, 1)
1348 title "ungetc, File $file, Transparent $trans" ;
1350 my $lex = new LexFile my $name ;
1352 my $string = 'abcdeABCDE';
1360 my $a = new $CompressClass(\$b) ;
1368 writeFile($name, $b);
1376 my $u = $UncompressClass->new($from, Transparent => 1) ;
1380 # do an ungetc before reading
1382 $first = $u->getc();
1385 $first = $u->getc();
1386 is $first, substr($string, 0,1);
1388 $first = $u->getc();
1389 is $first, substr($string, 0,1);
1392 is $u->read($buff, 5), 5 ;
1393 is $buff, substr($string, 0, 5);
1396 is $u->read($buff, length($string)), length($string) ;
1399 is $u->read($buff, 1), 0;
1402 my $extra = 'extra';
1405 is $u->read($buff), length($extra) ;
1408 is $u->read($buff, 1), 0;
1411 # getc returns undef on eof
1412 is $u->getc(), undef;
1419 title "write tests - invalid data" ;
1421 #my $lex = new LexFile my $name1 ;
1424 #ok ! -e $name1, " File $name1 does not exist";
1427 [ '{ }', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
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 filename is undef or null string" ],
1431 [ '[ undef ]', "${CompressClass}::write: input filename is undef or null string" ],
1432 [ '[ \$Answer ]',"${CompressClass}::write: input and output buffer are identical" ],
1433 #[ "not readable", 'xx' ],
1434 # same filehandle twice, 'xx'
1437 foreach my $data (@data)
1439 my ($send, $get) = @$data ;
1440 title "${CompressClass}::write( $send )";
1442 eval "\$copy = $send";
1443 my $x = new $CompressClass(\$Answer);
1444 ok $x, " Created $CompressClass object";
1445 eval { $x->write($copy) } ;
1446 #like $@, "/^$get/", " error - $get";
1447 like $@, "/not a scalar reference /", " error - not a scalar reference";
1451 # [ '[ $name1 ]', "input file '$name1' does not exist" ],
1452 # #[ "not readable", 'xx' ],
1453 # # same filehandle twice, 'xx'
1456 # foreach my $data (@data)
1458 # my ($send, $get) = @$data ;
1459 # title "${CompressClass}::write( $send )";
1461 # eval "\$copy = $send";
1462 # my $x = new $CompressClass(\$Answer);
1463 # ok $x, " Created $CompressClass object";
1464 # ok ! $x->write($copy), " write fails" ;
1465 # like $$Error, "/^$get/", " error - $get";
1475 # if (! ref $_[0] || ref $_[0] eq 'SCALAR')
1480 # if (ref $_[0] eq 'ARRAY')
1483 # for my $x ( @{ $_[0] })
1485 # push @a, deepCopy($x);
1491 # croak "bad! $_[0]";
1497 # #my $data = shift ;
1498 # my $from = $_[1] ;
1504 # if $_[0] eq $from ;
1509 # if (ref $_[0] eq 'SCALAR')
1512 # if defined ${ $_[0] } && ${ $_[0] } eq $from ;
1517 # if (ref $_[0] eq 'ARRAY')
1519 # for my $x ( @{ $_[0] })
1521 # deepSubst($x, $from, $to);
1525 # #croak "bad! $_[0]";
1529 # title "More write tests" ;
1531 # my $file1 = "file1" ;
1532 # my $file2 = "file2" ;
1533 # my $file3 = "file3" ;
1534 # my $lex = new LexFile $file1, $file2, $file3 ;
1536 # writeFile($file1, "F1");
1537 # writeFile($file2, "F2");
1538 # writeFile($file3, "F3");
1543 # [ '"abcd"', "abcd" ],
1547 # [ '\"abcd"', "abcd" ],
1553 # [ '[\undef]', "" ],
1554 # [ '[\"abcd"]', "abcd" ],
1555 # [ '[\"ab", \"cd"]', "abcd" ],
1556 # [ '[[\"ab"], [\"cd"]]', "abcd" ],
1558 # [ '$file1', $file1 ],
1560 # [ '[$file1, \"abc"]', "F1abc"],
1561 # [ '[\"a", $file1, \"bc"]', "aF1bc"],
1562 # [ '[\"a", $fh1, \"bc"]', "aF1bc"],
1563 # [ '[\"a", $fh1, \"bc", $file2]', "aF1bcF2"],
1564 # [ '[\"a", $fh1, \"bc", $file2, $fh3]', "aF1bcF2F3"],
1568 # foreach my $data (@data)
1570 # my ($send, $get) = @$data ;
1572 # my $fh1 = new IO::File "< $file1" ;
1573 # my $fh2 = new IO::File "< $file2" ;
1574 # my $fh3 = new IO::File "< $file3" ;
1576 # title "${CompressClass}::write( $send )";
1578 # eval "\$copy = $send";
1580 # my $x = new $CompressClass(\$Answer);
1581 # ok $x, " Created $CompressClass object";
1582 # my $len = length $get;
1583 # is $x->write($copy), length($get), " write $len bytes";
1584 # ok $x->close(), " close ok" ;
1586 # is myGZreadFile(\$Answer), $get, " got expected output" ;
1587 # cmp_ok $$Error, '==', 0, " no error";