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 => 641 + $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;
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");
784 is $io->read($buf, 0), 0, "Requested 0 bytes" ;
786 is $io->read($buf, 3), 3 ;
789 is $io->sysread($buf, 3, 2), 3 ;
791 or print "# [$buf]\n" ;;
798 # ok read($io, $buf, 20) == 4 ;
799 # ok $buf eq "e.\n\n";
801 # ok read($io, $buf, 20) == 0 ;
810 # Read from non-compressed file
821 my $lex = new LexFile my $name ;
823 writeFile($name, $str);
827 my $io = new $UncompressClass $name, -Transparent => 1 ;
831 ok $io->tell() == 0 ;
832 my @lines = $io->getlines();
834 ok $lines[1] eq "of a paragraph\n" ;
835 ok join('', @lines) eq $str ;
837 is $io->input_line_number, 6;
838 ok $io->tell() == length($str) ;
842 ok ! ( defined($io->getline) ||
843 (@tmp = $io->getlines) ||
844 defined($io->getline) ||
845 defined($io->getc) ||
846 $io->read($buf, 100) != 0) ;
851 local $/; # slurp mode
852 my $io = $UncompressClass->new($name);
854 my @lines = $io->getlines;
856 is $io->input_line_number, 1;
858 ok @lines == 1 && $lines[0] eq $str;
860 $io = $UncompressClass->new($name);
862 my $line = $io->getline;
864 is $io->input_line_number, 1;
870 local $/ = ""; # paragraph mode
871 my $io = $UncompressClass->new($name);
873 my @lines = $io->getlines;
875 is $io->input_line_number, 2;
878 or print "# exected 2 lines, got " . scalar(@lines) . "\n";
879 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
880 or print "# [$lines[0]]\n" ;
881 ok $lines[1] eq "and a single line.\n\n";
887 my $expected_records = int(length($str) / $reclen)
888 + (length($str) % $reclen ? 1 : 0);
891 my $io = $UncompressClass->new($name);
893 is $io->input_line_number, 0;
896 my @lines = $io->getlines();
897 is $., $expected_records;
898 is $io->input_line_number, $expected_records;
900 is @lines, $expected_records,
901 "Got $expected_records records\n" ;
902 ok $lines[0] eq substr($str, 0, $reclen)
903 or print "# $lines[0]\n";
904 ok $lines[1] eq substr($str, $reclen, $reclen);
909 my $io = $UncompressClass->new($name);
914 while (my $a = $io->getline) {
916 $err++ if $. != ++$no;
920 is $io->input_line_number, 3;
926 ok join("-", @lines) eq
927 "This- is- an example\n" .
928 "of a paragraph\n\n\n" .
929 "and a single line.\n\n";
936 my $io = $UncompressClass->new($name);
938 ok $io->read($buf, 3) == 3 ;
941 ok $io->sysread($buf, 3, 2) == 3 ;
949 # ok read($io, $buf, 20) == 4 ;
950 # ok $buf eq "e.\n\n";
952 # ok read($io, $buf, 20) == 0 ;
962 # Vary the length parameter in a read
977 foreach my $bufsize (1, 3, 512, 4096, length($str)-1, length($str), length($str)+1)
979 foreach my $trans (0, 1)
981 foreach my $append (0, 1)
983 title "Read Tests - buf length $bufsize, Transparent $trans, Append $append" ;
985 my $lex = new LexFile my $name ;
988 writeFile($name, $str) ;
991 my $iow = new $CompressClass $name;
997 my $io = $UncompressClass->new($name,
999 -Transparent => $trans);
1006 1 while $io->read($buf, $bufsize) > 0;
1010 $buf .= $tmp while $io->read($tmp, $bufsize) > 0 ;
1012 is length $buf, length $str;
1021 foreach my $file (0, 1)
1023 foreach my $trans (0, 1)
1025 title "seek tests - file $file trans $trans" ;
1029 my $lex = new LexFile my $name ;
1031 my $first = "beginning" ;
1032 my $last = "the end" ;
1036 $buffer = $first . "\x00" x 10 . $last;
1037 writeFile($name, $buffer);
1051 my $iow = new $CompressClass $output ;
1052 $iow->print($first) ;
1053 ok $iow->seek(5, SEEK_CUR) ;
1054 ok $iow->tell() == length($first)+5;
1055 ok $iow->seek(0, SEEK_CUR) ;
1056 ok $iow->tell() == length($first)+5;
1057 ok $iow->seek(length($first)+10, SEEK_SET) ;
1058 ok $iow->tell() == length($first)+10;
1060 $iow->print($last) ;
1074 ok myGZreadFile($input) eq $first . "\x00" x 10 . $last ;
1076 my $io = $UncompressClass->new($input, Strict => 1);
1077 ok $io->seek(length($first), SEEK_CUR)
1080 is $io->tell(), length($first);
1082 ok $io->read($buff, 5) ;
1083 is $buff, "\x00" x 5 ;
1084 is $io->tell(), length($first) + 5;
1086 ok $io->seek(0, SEEK_CUR) ;
1087 my $here = $io->tell() ;
1088 is $here, length($first)+5;
1090 ok $io->seek($here+5, SEEK_SET) ;
1091 is $io->tell(), $here+5 ;
1092 ok $io->read($buff, 100) ;
1099 title "seek error cases" ;
1102 my $a = new $CompressClass(\$b) ;
1105 eval { $a->seek(-1, 10) ; };
1106 like $@, mkErr("^${CompressClass}::seek: unknown value, 10, for whence parameter");
1108 eval { $a->seek(-1, SEEK_END) ; };
1109 like $@, mkErr("^${CompressClass}::seek: cannot seek backwards");
1115 my $u = new $UncompressClass(\$b) ;
1117 eval { $u->seek(-1, 10) ; };
1118 like $@, mkErr("^${UncompressClass}::seek: unknown value, 10, for whence parameter");
1120 eval { $u->seek(-1, SEEK_END) ; };
1121 like $@, mkErr("^${UncompressClass}::seek: SEEK_END not allowed");
1123 eval { $u->seek(-1, SEEK_CUR) ; };
1124 like $@, mkErr("^${UncompressClass}::seek: cannot seek backwards");
1127 foreach my $fb (qw(filename buffer filehandle))
1129 foreach my $append (0, 1)
1132 title "$CompressClass -- Append $append, Output to $fb" ;
1134 my $lex = new LexFile my $name ;
1136 my $already = 'already';
1137 my $buffer = $already;
1140 if ($fb eq 'buffer')
1141 { $output = \$buffer }
1142 elsif ($fb eq 'filename')
1145 writeFile($name, $buffer);
1147 elsif ($fb eq 'filehandle')
1149 $output = new IO::File ">$name" ;
1150 print $output $buffer;
1153 my $a = new $CompressClass($output, Append => $append) ;
1154 ok $a, " Created $CompressClass";
1155 my $string = "appended";
1160 if ($fb eq 'buffer')
1167 if $fb eq 'filehandle';
1168 $data = readFile($name);
1171 if ($append || $fb eq 'filehandle')
1173 is substr($data, 0, length($already)), $already, " got prefix";
1174 substr($data, 0, length($already)) = '';
1179 my $x = new $UncompressClass(\$data, Append => 1) ;
1180 ok $x, " created $UncompressClass";
1183 1 while ($len = $x->read($uncomp)) > 0 ;
1186 is $uncomp, $string, ' Got uncompressed data' ;
1192 foreach my $type (qw(buffer filename filehandle))
1194 foreach my $good (0, 1)
1196 title "$UncompressClass -- InputLength, read from $type, good data => $good";
1199 my $string = "some data";
1200 my $appended = "append";
1204 my $c = new $CompressClass(\$compressed);
1210 $compressed = $string ;
1213 my $comp_len = length $compressed;
1214 $compressed .= $appended;
1216 my $lex = new LexFile my $name ;
1218 writeFile ($name, $compressed);
1220 if ($type eq 'buffer')
1222 $input = \$compressed;
1224 if ($type eq 'filename')
1228 elsif ($type eq 'filehandle')
1230 my $fh = new IO::File "<$name" ;
1231 ok $fh, "opened file $name ok";
1235 my $x = new $UncompressClass($input,
1236 InputLength => $comp_len,
1238 ok $x, " created $UncompressClass";
1242 $len = $x->read($output, 100);
1244 is $len, length($string);
1245 is $output, $string;
1247 if ($type eq 'filehandle')
1250 $input->read($rest, 1000);
1251 is $rest, $appended;
1258 foreach my $append (0, 1)
1260 title "$UncompressClass -- Append $append" ;
1262 my $lex = new LexFile my $name ;
1264 my $string = "appended";
1266 my $c = new $CompressClass(\$compressed);
1270 my $x = new $UncompressClass(\$compressed, Append => $append) ;
1271 ok $x, " created $UncompressClass";
1273 my $already = 'already';
1274 my $output = $already;
1277 $len = $x->read($output, 100);
1278 is $len, length($string);
1284 is substr($output, 0, length($already)), $already, " got prefix";
1285 substr($output, 0, length($already)) = '';
1287 is $output, $string, ' Got uncompressed data' ;
1291 foreach my $file (0, 1)
1293 foreach my $trans (0, 1)
1295 title "ungetc, File $file, Transparent $trans" ;
1297 my $lex = new LexFile my $name ;
1299 my $string = 'abcdeABCDE';
1307 my $a = new $CompressClass(\$b) ;
1315 writeFile($name, $b);
1323 my $u = $UncompressClass->new($from, Transparent => 1) ;
1327 # do an ungetc before reading
1329 $first = $u->getc();
1332 $first = $u->getc();
1333 is $first, substr($string, 0,1);
1335 $first = $u->getc();
1336 is $first, substr($string, 0,1);
1339 is $u->read($buff, 5), 5 ;
1340 is $buff, substr($string, 0, 5);
1343 is $u->read($buff, length($string)), length($string) ;
1346 is $u->read($buff, 1), 0;
1349 my $extra = 'extra';
1352 is $u->read($buff), length($extra) ;
1355 is $u->read($buff, 1), 0;
1358 # getc returns undef on eof
1359 is $u->getc(), undef;
1367 title "write tests - invalid data" ;
1369 #my $lex = new LexFile my $name1 ;
1372 #ok ! -e $name1, " File $name1 does not exist";
1375 [ '{ }', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1376 [ '[ { } ]', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1377 [ '[ [ { } ] ]', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1378 [ '[ "" ]', "${CompressClass}::write: input filename is undef or null string" ],
1379 [ '[ undef ]', "${CompressClass}::write: input filename is undef or null string" ],
1380 [ '[ \$Answer ]',"${CompressClass}::write: input and output buffer are identical" ],
1381 #[ "not readable", 'xx' ],
1382 # same filehandle twice, 'xx'
1385 foreach my $data (@data)
1387 my ($send, $get) = @$data ;
1388 title "${CompressClass}::write( $send )";
1390 eval "\$copy = $send";
1391 my $x = new $CompressClass(\$Answer);
1392 ok $x, " Created $CompressClass object";
1393 eval { $x->write($copy) } ;
1394 #like $@, "/^$get/", " error - $get";
1395 like $@, "/not a scalar reference /", " error - not a scalar reference";
1399 # [ '[ $name1 ]', "input file '$name1' does not exist" ],
1400 # #[ "not readable", 'xx' ],
1401 # # same filehandle twice, 'xx'
1404 # foreach my $data (@data)
1406 # my ($send, $get) = @$data ;
1407 # title "${CompressClass}::write( $send )";
1409 # eval "\$copy = $send";
1410 # my $x = new $CompressClass(\$Answer);
1411 # ok $x, " Created $CompressClass object";
1412 # ok ! $x->write($copy), " write fails" ;
1413 # like $$Error, "/^$get/", " error - $get";
1423 # if (! ref $_[0] || ref $_[0] eq 'SCALAR')
1428 # if (ref $_[0] eq 'ARRAY')
1431 # for my $x ( @{ $_[0] })
1433 # push @a, deepCopy($x);
1439 # croak "bad! $_[0]";
1445 # #my $data = shift ;
1446 # my $from = $_[1] ;
1452 # if $_[0] eq $from ;
1457 # if (ref $_[0] eq 'SCALAR')
1460 # if defined ${ $_[0] } && ${ $_[0] } eq $from ;
1465 # if (ref $_[0] eq 'ARRAY')
1467 # for my $x ( @{ $_[0] })
1469 # deepSubst($x, $from, $to);
1473 # #croak "bad! $_[0]";
1477 # title "More write tests" ;
1479 # my $file1 = "file1" ;
1480 # my $file2 = "file2" ;
1481 # my $file3 = "file3" ;
1482 # my $lex = new LexFile $file1, $file2, $file3 ;
1484 # writeFile($file1, "F1");
1485 # writeFile($file2, "F2");
1486 # writeFile($file3, "F3");
1491 # [ '"abcd"', "abcd" ],
1495 # [ '\"abcd"', "abcd" ],
1501 # [ '[\undef]', "" ],
1502 # [ '[\"abcd"]', "abcd" ],
1503 # [ '[\"ab", \"cd"]', "abcd" ],
1504 # [ '[[\"ab"], [\"cd"]]', "abcd" ],
1506 # [ '$file1', $file1 ],
1508 # [ '[$file1, \"abc"]', "F1abc"],
1509 # [ '[\"a", $file1, \"bc"]', "aF1bc"],
1510 # [ '[\"a", $fh1, \"bc"]', "aF1bc"],
1511 # [ '[\"a", $fh1, \"bc", $file2]', "aF1bcF2"],
1512 # [ '[\"a", $fh1, \"bc", $file2, $fh3]', "aF1bcF2F3"],
1516 # foreach my $data (@data)
1518 # my ($send, $get) = @$data ;
1520 # my $fh1 = new IO::File "< $file1" ;
1521 # my $fh2 = new IO::File "< $file2" ;
1522 # my $fh3 = new IO::File "< $file3" ;
1524 # title "${CompressClass}::write( $send )";
1526 # eval "\$copy = $send";
1528 # my $x = new $CompressClass(\$Answer);
1529 # ok $x, " Created $CompressClass object";
1530 # my $len = length $get;
1531 # is $x->write($copy), length($get), " write $len bytes";
1532 # ok $x->close(), " close ok" ;
1534 # is myGZreadFile(\$Answer), $get, " got expected output" ;
1535 # cmp_ok $$Error, '==', 0, " no error";