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 => 639 + $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);
52 title "Testing $CompressClass Errors";
55 eval qq[\$a = new $CompressClass(\\1) ;] ;
56 like $@, mkEvalErr("^$CompressClass: output buffer is read-only") ;
60 eval qq[\$a = new $CompressClass ] . '$out ;' ;
61 like $@, mkEvalErr("^$CompressClass: output filename is undef or null string");
64 eval qq[\$a = new $CompressClass \$out ;] ;
65 like $@, mkEvalErr("^$CompressClass: output filename is undef or null string");
68 $gz = new $CompressClass(\$x);
70 foreach my $name (qw(read readline getc))
72 eval " \$gz->$name() " ;
73 like $@, mkEvalErr("^$name Not Available: File opened only for output");
76 eval ' $gz->write({})' ;
77 like $@, mkEvalErr("^${CompressClass}::write: not a scalar reference");
78 #like $@, mkEvalErr("^${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref");
80 eval ' $gz->syswrite("abc", 1, 5)' ;
81 like $@, mkEvalErr("^${CompressClass}::write: offset outside string");
83 eval ' $gz->syswrite("abc", 1, -4)' ;
84 like $@, mkEvalErr("^${CompressClass}::write: offset outside string");
89 title "Testing $UncompressClass Errors";
92 eval qq[\$a = new $UncompressClass \$out ;] ;
93 like $@, mkEvalErr("^$UncompressClass: input filename is undef or null string");
95 eval qq[\$a = new $UncompressClass \$out ;] ;
96 like $@, mkEvalErr("^$UncompressClass: input filename is undef or null string");
98 my $lex = new LexFile my $name ;
100 ok ! -e $name, " $name does not exist";
102 eval qq[\$a = new $UncompressClass "$name" ;] ;
103 is $$UnError, "input file '$name' does not exist";
106 my $guz = new $CompressClass(\$gc);
111 my $gz = new $UncompressClass(\$gc);
113 foreach my $name (qw(print printf write))
115 eval " \$gz->$name() " ;
116 like $@, mkEvalErr("^$name Not Available: File opened only for intput");
122 title "Testing $CompressClass and $UncompressClass";
125 my ($a, $x, @x) = ("","","") ;
127 # Buffer not a scalar reference
128 eval qq[\$a = new $CompressClass \\\@x ;] ;
129 like $@, mkEvalErr("^$CompressClass: output parameter not a filename, filehandle or scalar ref");
131 # Buffer not a scalar reference
132 eval qq[\$a = new $UncompressClass \\\@x ;] ;
133 like $@, mkEvalErr("^$UncompressClass: input parameter not a filename, filehandle, array ref or scalar ref");
136 foreach my $Type ( $CompressClass, $UncompressClass)
138 # Check error handling with IO::Compress::Deflate and IO::Uncompress::Inflate
140 my ($a, $x, @x) = ("","","") ;
142 # Odd number of parameters
143 eval qq[\$a = new $Type "abc", -Output ] ;
144 like $@, mkEvalErr("^$Type: Expected even number of parameters, got 1");
147 eval qq[\$a = new $Type "anc", -Fred => 123 ;] ;
148 like $@, mkEvalErr("^$Type: unknown key value\\(s\\) Fred");
151 eval qq[\$a = new $Type ;] ;
152 like $@, mkEvalErr("^$Type: Missing (Input|Output) parameter");
158 # write a very simple compressed file
160 #========================================
163 my $lex = new LexFile my $name ;
164 #my $name = "/tmp/try.lzf";
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" ;
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 ;
426 ok $buffer eq $keep ;
429 if ($CompressClass ne 'RawDeflate')
432 #========================================
437 ok $x = new $CompressClass(\$buffer) ;
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" ;
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;
662 my $io = new $UncompressClass $name ;
665 is $io->input_line_number, 0;
666 ok ! $io->eof, "eof";
667 is $io->tell(), 0, "tell 0" ;
669 my @lines = $io->getlines();
671 or print "# Got " . scalar(@lines) . " lines, expected 6\n" ;
672 is $lines[1], "of a paragraph\n" ;
673 is join('', @lines), $str ;
675 is $io->input_line_number, 6;
676 is $io->tell(), length($str) ;
680 ok ! ( defined($io->getline) ||
681 (@tmp = $io->getlines) ||
682 defined($io->getline) ||
683 defined($io->getc) ||
684 $io->read($buf, 100) != 0) ;
689 local $/; # slurp mode
690 my $io = $UncompressClass->new($name);
692 is $io->input_line_number, 0;
694 my @lines = $io->getlines;
696 is $io->input_line_number, 1;
698 ok @lines == 1 && $lines[0] eq $str;
700 $io = $UncompressClass->new($name);
702 my $line = $io->getline();
708 local $/ = ""; # paragraph mode
709 my $io = $UncompressClass->new($name);
711 is $io->input_line_number, 0;
713 my @lines = $io->getlines();
715 is $io->input_line_number, 2;
718 or print "# Got " . scalar(@lines) . " lines, expected 2\n" ;
719 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
720 or print "# $lines[0]\n";
721 ok $lines[1] eq "and a single line.\n\n";
727 my $expected_records = int(length($str) / $reclen)
728 + (length($str) % $reclen ? 1 : 0);
731 my $io = $UncompressClass->new($name);
733 is $io->input_line_number, 0;
736 my @lines = $io->getlines();
737 is $., $expected_records;
738 is $io->input_line_number, $expected_records;
740 is @lines, $expected_records,
741 "Got $expected_records records\n" ;
742 ok $lines[0] eq substr($str, 0, $reclen)
743 or print "# $lines[0]\n";
744 ok $lines[1] eq substr($str, $reclen, $reclen);
749 my $io = $UncompressClass->new($name);
754 while (my $a = $io->getline()) {
756 $err++ if $. != ++$no;
763 is $io->input_line_number, 3;
765 or print "# Got " . scalar(@lines) . " lines, expected 3\n" ;
766 ok join("-", @lines) eq
767 "This- is- an example\n" .
768 "of a paragraph\n\n\n" .
769 "and a single line.\n\n";
776 my $io = $UncompressClass->new($name);
779 eval { $io->read(1) } ;
780 like $@, mkErr("buffer parameter is read-only");
782 is $io->read($buf, 0), 0, "Requested 0 bytes" ;
784 is $io->read($buf, 3), 3 ;
787 is $io->sysread($buf, 3, 2), 3 ;
789 or print "# [$buf]\n" ;;
796 # ok read($io, $buf, 20) == 4 ;
797 # ok $buf eq "e.\n\n";
799 # ok read($io, $buf, 20) == 0 ;
808 # Read from non-compressed file
819 my $lex = new LexFile my $name ;
821 writeFile($name, $str);
825 my $io = new $UncompressClass $name, -Transparent => 1 ;
829 ok $io->tell() == 0 ;
830 my @lines = $io->getlines();
832 ok $lines[1] eq "of a paragraph\n" ;
833 ok join('', @lines) eq $str ;
835 is $io->input_line_number, 6;
836 ok $io->tell() == length($str) ;
840 ok ! ( defined($io->getline) ||
841 (@tmp = $io->getlines) ||
842 defined($io->getline) ||
843 defined($io->getc) ||
844 $io->read($buf, 100) != 0) ;
849 local $/; # slurp mode
850 my $io = $UncompressClass->new($name);
852 my @lines = $io->getlines;
854 is $io->input_line_number, 1;
856 ok @lines == 1 && $lines[0] eq $str;
858 $io = $UncompressClass->new($name);
860 my $line = $io->getline;
862 is $io->input_line_number, 1;
868 local $/ = ""; # paragraph mode
869 my $io = $UncompressClass->new($name);
871 my @lines = $io->getlines;
873 is $io->input_line_number, 2;
876 or print "# exected 2 lines, got " . scalar(@lines) . "\n";
877 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
878 or print "# [$lines[0]]\n" ;
879 ok $lines[1] eq "and a single line.\n\n";
885 my $expected_records = int(length($str) / $reclen)
886 + (length($str) % $reclen ? 1 : 0);
889 my $io = $UncompressClass->new($name);
891 is $io->input_line_number, 0;
894 my @lines = $io->getlines();
895 is $., $expected_records;
896 is $io->input_line_number, $expected_records;
898 is @lines, $expected_records,
899 "Got $expected_records records\n" ;
900 ok $lines[0] eq substr($str, 0, $reclen)
901 or print "# $lines[0]\n";
902 ok $lines[1] eq substr($str, $reclen, $reclen);
907 my $io = $UncompressClass->new($name);
912 while (my $a = $io->getline) {
914 $err++ if $. != ++$no;
918 is $io->input_line_number, 3;
924 ok join("-", @lines) eq
925 "This- is- an example\n" .
926 "of a paragraph\n\n\n" .
927 "and a single line.\n\n";
934 my $io = $UncompressClass->new($name);
936 ok $io->read($buf, 3) == 3 ;
939 ok $io->sysread($buf, 3, 2) == 3 ;
947 # ok read($io, $buf, 20) == 4 ;
948 # ok $buf eq "e.\n\n";
950 # ok read($io, $buf, 20) == 0 ;
960 # Vary the length parameter in a read
975 foreach my $bufsize (1, 3, 512, 4096, length($str)-1, length($str), length($str)+1)
977 foreach my $trans (0, 1)
979 foreach my $append (0, 1)
981 title "Read Tests - buf length $bufsize, Transparent $trans, Append $append" ;
983 my $lex = new LexFile my $name ;
986 writeFile($name, $str) ;
989 my $iow = new $CompressClass $name;
995 my $io = $UncompressClass->new($name,
997 -Transparent => $trans);
1004 1 while $io->read($buf, $bufsize) > 0;
1008 $buf .= $tmp while $io->read($tmp, $bufsize) > 0 ;
1010 is length $buf, length $str;
1019 foreach my $file (0, 1)
1021 foreach my $trans (0, 1)
1023 title "seek tests - file $file trans $trans" ;
1027 my $lex = new LexFile my $name ;
1029 my $first = "beginning" ;
1030 my $last = "the end" ;
1034 $buffer = $first . "\x00" x 10 . $last;
1035 writeFile($name, $buffer);
1049 my $iow = new $CompressClass $output ;
1050 $iow->print($first) ;
1051 ok $iow->seek(5, SEEK_CUR) ;
1052 ok $iow->tell() == length($first)+5;
1053 ok $iow->seek(0, SEEK_CUR) ;
1054 ok $iow->tell() == length($first)+5;
1055 ok $iow->seek(length($first)+10, SEEK_SET) ;
1056 ok $iow->tell() == length($first)+10;
1058 $iow->print($last) ;
1072 ok myGZreadFile($input) eq $first . "\x00" x 10 . $last ;
1074 my $io = $UncompressClass->new($input, Strict => 1);
1075 ok $io->seek(length($first), SEEK_CUR)
1078 is $io->tell(), length($first);
1080 ok $io->read($buff, 5) ;
1081 is $buff, "\x00" x 5 ;
1082 is $io->tell(), length($first) + 5;
1084 ok $io->seek(0, SEEK_CUR) ;
1085 my $here = $io->tell() ;
1086 is $here, length($first)+5;
1088 ok $io->seek($here+5, SEEK_SET) ;
1089 is $io->tell(), $here+5 ;
1090 ok $io->read($buff, 100) ;
1097 title "seek error cases" ;
1100 my $a = new $CompressClass(\$b) ;
1103 eval { $a->seek(-1, 10) ; };
1104 like $@, mkErr("^${CompressClass}::seek: unknown value, 10, for whence parameter");
1106 eval { $a->seek(-1, SEEK_END) ; };
1107 like $@, mkErr("^${CompressClass}::seek: cannot seek backwards");
1113 my $u = new $UncompressClass(\$b) ;
1115 eval { $u->seek(-1, 10) ; };
1116 like $@, mkErr("^${UncompressClass}::seek: unknown value, 10, for whence parameter");
1118 eval { $u->seek(-1, SEEK_END) ; };
1119 like $@, mkErr("^${UncompressClass}::seek: SEEK_END not allowed");
1121 eval { $u->seek(-1, SEEK_CUR) ; };
1122 like $@, mkErr("^${UncompressClass}::seek: cannot seek backwards");
1125 foreach my $fb (qw(filename buffer filehandle))
1127 foreach my $append (0, 1)
1130 title "$CompressClass -- Append $append, Output to $fb" ;
1132 my $lex = new LexFile my $name ;
1134 my $already = 'already';
1135 my $buffer = $already;
1138 if ($fb eq 'buffer')
1139 { $output = \$buffer }
1140 elsif ($fb eq 'filename')
1143 writeFile($name, $buffer);
1145 elsif ($fb eq 'filehandle')
1147 $output = new IO::File ">$name" ;
1148 print $output $buffer;
1151 my $a = new $CompressClass($output, Append => $append) ;
1152 ok $a, " Created $CompressClass";
1153 my $string = "appended";
1158 if ($fb eq 'buffer')
1165 if $fb eq 'filehandle';
1166 $data = readFile($name);
1169 if ($append || $fb eq 'filehandle')
1171 is substr($data, 0, length($already)), $already, " got prefix";
1172 substr($data, 0, length($already)) = '';
1177 my $x = new $UncompressClass(\$data, Append => 1) ;
1178 ok $x, " created $UncompressClass";
1181 1 while ($len = $x->read($uncomp)) > 0 ;
1184 is $uncomp, $string, ' Got uncompressed data' ;
1190 foreach my $type (qw(buffer filename filehandle))
1192 foreach my $good (0, 1)
1194 title "$UncompressClass -- InputLength, read from $type, good data => $good";
1197 my $string = "some data";
1198 my $appended = "append";
1202 my $c = new $CompressClass(\$compressed);
1208 $compressed = $string ;
1211 my $comp_len = length $compressed;
1212 $compressed .= $appended;
1214 my $lex = new LexFile my $name ;
1216 writeFile ($name, $compressed);
1218 if ($type eq 'buffer')
1220 $input = \$compressed;
1222 if ($type eq 'filename')
1226 elsif ($type eq 'filehandle')
1228 my $fh = new IO::File "<$name" ;
1229 ok $fh, "opened file $name ok";
1233 my $x = new $UncompressClass($input,
1234 InputLength => $comp_len,
1236 ok $x, " created $UncompressClass";
1240 $len = $x->read($output, 100);
1242 is $len, length($string);
1243 is $output, $string;
1245 if ($type eq 'filehandle')
1248 $input->read($rest, 1000);
1249 is $rest, $appended;
1256 foreach my $append (0, 1)
1258 title "$UncompressClass -- Append $append" ;
1260 my $lex = new LexFile my $name ;
1262 my $string = "appended";
1264 my $c = new $CompressClass(\$compressed);
1268 my $x = new $UncompressClass(\$compressed, Append => $append) ;
1269 ok $x, " created $UncompressClass";
1271 my $already = 'already';
1272 my $output = $already;
1275 $len = $x->read($output, 100);
1276 is $len, length($string);
1282 is substr($output, 0, length($already)), $already, " got prefix";
1283 substr($output, 0, length($already)) = '';
1285 is $output, $string, ' Got uncompressed data' ;
1289 foreach my $file (0, 1)
1291 foreach my $trans (0, 1)
1293 title "ungetc, File $file, Transparent $trans" ;
1295 my $lex = new LexFile my $name ;
1297 my $string = 'abcdeABCDE';
1305 my $a = new $CompressClass(\$b) ;
1313 writeFile($name, $b);
1321 my $u = $UncompressClass->new($from, Transparent => 1) ;
1325 # do an ungetc before reading
1327 $first = $u->getc();
1330 $first = $u->getc();
1331 is $first, substr($string, 0,1);
1333 $first = $u->getc();
1334 is $first, substr($string, 0,1);
1337 is $u->read($buff, 5), 5 ;
1338 is $buff, substr($string, 0, 5);
1341 is $u->read($buff, length($string)), length($string) ;
1344 is $u->read($buff, 1), 0;
1347 my $extra = 'extra';
1350 is $u->read($buff), length($extra) ;
1353 is $u->read($buff, 1), 0;
1356 # getc returns undef on eof
1357 is $u->getc(), undef;
1365 title "write tests - invalid data" ;
1367 #my $lex = new LexFile my $name1 ;
1370 #ok ! -e $name1, " File $name1 does not exist";
1373 [ '{ }', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1374 [ '[ { } ]', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1375 [ '[ [ { } ] ]', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1376 [ '[ "" ]', "${CompressClass}::write: input filename is undef or null string" ],
1377 [ '[ undef ]', "${CompressClass}::write: input filename is undef or null string" ],
1378 [ '[ \$Answer ]',"${CompressClass}::write: input and output buffer are identical" ],
1379 #[ "not readable", 'xx' ],
1380 # same filehandle twice, 'xx'
1383 foreach my $data (@data)
1385 my ($send, $get) = @$data ;
1386 title "${CompressClass}::write( $send )";
1388 eval "\$copy = $send";
1389 my $x = new $CompressClass(\$Answer);
1390 ok $x, " Created $CompressClass object";
1391 eval { $x->write($copy) } ;
1392 #like $@, "/^$get/", " error - $get";
1393 like $@, "/not a scalar reference /", " error - not a scalar reference";
1397 # [ '[ $name1 ]', "input file '$name1' does not exist" ],
1398 # #[ "not readable", 'xx' ],
1399 # # same filehandle twice, 'xx'
1402 # foreach my $data (@data)
1404 # my ($send, $get) = @$data ;
1405 # title "${CompressClass}::write( $send )";
1407 # eval "\$copy = $send";
1408 # my $x = new $CompressClass(\$Answer);
1409 # ok $x, " Created $CompressClass object";
1410 # ok ! $x->write($copy), " write fails" ;
1411 # like $$Error, "/^$get/", " error - $get";
1421 # if (! ref $_[0] || ref $_[0] eq 'SCALAR')
1426 # if (ref $_[0] eq 'ARRAY')
1429 # for my $x ( @{ $_[0] })
1431 # push @a, deepCopy($x);
1437 # croak "bad! $_[0]";
1443 # #my $data = shift ;
1444 # my $from = $_[1] ;
1450 # if $_[0] eq $from ;
1455 # if (ref $_[0] eq 'SCALAR')
1458 # if defined ${ $_[0] } && ${ $_[0] } eq $from ;
1463 # if (ref $_[0] eq 'ARRAY')
1465 # for my $x ( @{ $_[0] })
1467 # deepSubst($x, $from, $to);
1471 # #croak "bad! $_[0]";
1475 # title "More write tests" ;
1477 # my $file1 = "file1" ;
1478 # my $file2 = "file2" ;
1479 # my $file3 = "file3" ;
1480 # my $lex = new LexFile $file1, $file2, $file3 ;
1482 # writeFile($file1, "F1");
1483 # writeFile($file2, "F2");
1484 # writeFile($file3, "F3");
1489 # [ '"abcd"', "abcd" ],
1493 # [ '\"abcd"', "abcd" ],
1499 # [ '[\undef]', "" ],
1500 # [ '[\"abcd"]', "abcd" ],
1501 # [ '[\"ab", \"cd"]', "abcd" ],
1502 # [ '[[\"ab"], [\"cd"]]', "abcd" ],
1504 # [ '$file1', $file1 ],
1506 # [ '[$file1, \"abc"]', "F1abc"],
1507 # [ '[\"a", $file1, \"bc"]', "aF1bc"],
1508 # [ '[\"a", $fh1, \"bc"]', "aF1bc"],
1509 # [ '[\"a", $fh1, \"bc", $file2]', "aF1bcF2"],
1510 # [ '[\"a", $fh1, \"bc", $file2, $fh3]', "aF1bcF2F3"],
1514 # foreach my $data (@data)
1516 # my ($send, $get) = @$data ;
1518 # my $fh1 = new IO::File "< $file1" ;
1519 # my $fh2 = new IO::File "< $file2" ;
1520 # my $fh3 = new IO::File "< $file3" ;
1522 # title "${CompressClass}::write( $send )";
1524 # eval "\$copy = $send";
1526 # my $x = new $CompressClass(\$Answer);
1527 # ok $x, " Created $CompressClass object";
1528 # my $len = length $get;
1529 # is $x->write($copy), length($get), " write $len bytes";
1530 # ok $x->close(), " close ok" ;
1532 # is myGZreadFile(\$Answer), $get, " got expected output" ;
1533 # cmp_ok $$Error, '==', 0, " no error";