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 => 666 + $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") ;
62 $gz = new $CompressClass(\$x);
64 foreach my $name (qw(read readline getc))
66 eval " \$gz->$name() " ;
67 like $@, mkEvalErr("^$name Not Available: File opened only for output");
70 eval ' $gz->write({})' ;
71 like $@, mkEvalErr("^${CompressClass}::write: not a scalar reference");
73 eval ' $gz->syswrite("abc", 1, 5)' ;
74 like $@, mkEvalErr("^${CompressClass}::write: offset outside string");
76 eval ' $gz->syswrite("abc", 1, -4)' ;
77 like $@, mkEvalErr("^${CompressClass}::write: offset outside string"), "write outside string";
82 title "Testing $UncompressClass Errors";
86 my $lex = new LexFile my $name ;
88 ok ! -e $name, " $name does not exist";
90 $a = new $UncompressClass "$name" ;
94 my $guz = new $CompressClass(\$gc);
99 my $gz = new $UncompressClass(\$gc);
101 foreach my $name (qw(print printf write))
103 eval " \$gz->$name() " ;
104 like $@, mkEvalErr("^$name Not Available: File opened only for intput");
111 title "Testing $CompressClass and $UncompressClass";
114 my ($a, $x, @x) = ("","","") ;
116 # Buffer not a scalar reference
117 eval qq[\$a = new $CompressClass \\\@x ;] ;
118 like $@, mkEvalErr("^$CompressClass: output parameter not a filename, filehandle or scalar ref");
120 # Buffer not a scalar reference
121 eval qq[\$a = new $UncompressClass \\\@x ;] ;
122 like $@, mkEvalErr("^$UncompressClass: input parameter not a filename, filehandle, array ref or scalar ref");
125 foreach my $Type ( $CompressClass, $UncompressClass)
127 # Check error handling with IO::Compress::Deflate and IO::Uncompress::Inflate
129 my ($a, $x, @x) = ("","","") ;
131 # Odd number of parameters
132 eval qq[\$a = new $Type "abc", -Output ] ;
133 like $@, mkEvalErr("^$Type: Expected even number of parameters, got 1");
136 eval qq[\$a = new $Type "anc", -Fred => 123 ;] ;
137 like $@, mkEvalErr("^$Type: unknown key value\\(s\\) Fred");
140 eval qq[\$a = new $Type ;] ;
141 like $@, mkEvalErr("^$Type: Missing (Input|Output) parameter");
147 # write a very simple compressed file
149 #========================================
152 my $lex = new LexFile my $name ;
161 ok $x = new $CompressClass $name ;
162 is $x->autoflush(1), 0, "autoflush";
163 is $x->autoflush(1), 1, "autoflush";
164 ok $x->opened(), "opened";
166 ok $x->write($hello), "write" ;
167 ok $x->flush(), "flush";
168 ok $x->close, "close" ;
169 ok ! $x->opened(), "! opened";
174 ok my $x = new $UncompressClass $name, -Append => 1 ;
175 ok $x->opened(), "opened";
178 1 while ($len = $x->read($uncomp)) > 0 ;
180 is $len, 0, "read returned 0"
185 ok !$x->opened(), "! opened";
190 # write a very simple compressed file
192 #========================================
195 my $lex = new LexFile my $name ;
204 ok $x = new $CompressClass $name ;
206 is $x->write(''), 0, "Write empty string is ok";
207 is $x->write(undef), 0, "Write undef is ok";
208 ok $x->write($hello), "Write ok" ;
209 ok $x->close, "Close ok" ;
214 my $x = new $UncompressClass $name ;
215 ok $x, "creates $UncompressClass $name" ;
218 $data .= $uncomp while $x->read($uncomp) > 0 ;
220 ok $x->close, "close ok" ;
221 is $data, $hello, "expected output" ;
227 # write a very simple file with using an IO filehandle
229 #========================================
232 my $lex = new LexFile my $name ;
240 my $fh = new IO::File ">$name" ;
241 ok $fh, "opened file $name ok";
242 my $x = new $CompressClass $fh ;
243 ok $x, " created $CompressClass $fh" ;
245 is $x->fileno(), fileno($fh), "fileno match" ;
246 is $x->write(''), 0, "Write empty string is ok";
247 is $x->write(undef), 0, "Write undef is ok";
248 ok $x->write($hello), "write ok" ;
249 ok $x->flush(), "flush";
250 ok $x->close,"close" ;
257 ok my $fh1 = new IO::File "<$name" ;
258 ok $x = new $UncompressClass $fh1, -Append => 1 ;
259 ok $x->fileno() == fileno $fh1 ;
261 1 while $x->read($uncomp) > 0 ;
266 ok $hello eq $uncomp ;
270 # write a very simple file with using a glob filehandle
272 #========================================
275 my $lex = new LexFile my $name ;
276 #my $name = "/tmp/fred";
284 title "$CompressClass: Input from typeglob filehandle";
285 ok open FH, ">$name" ;
287 my $x = new $CompressClass *FH ;
288 ok $x, " create $CompressClass" ;
290 is $x->fileno(), fileno(*FH), " fileno" ;
291 is $x->write(''), 0, " Write empty string is ok";
292 is $x->write(undef), 0, " Write undef is ok";
293 ok $x->write($hello), " Write ok" ;
294 ok $x->flush(), " Flush";
295 ok $x->close, " Close" ;
302 title "$UncompressClass: Input from typeglob filehandle, append output";
304 ok open FH, "<$name" ;
305 ok $x = new $UncompressClass *FH, -Append => 1, Transparent => 0
307 is $x->fileno(), fileno FH, " fileno ok" ;
309 1 while $x->read($uncomp) > 0 ;
311 ok $x->close, " close" ;
314 is $uncomp, $hello, " expected output" ;
318 my $lex = new LexFile my $name ;
319 #my $name = "/tmp/fred";
327 title "Outout to stdout via '-'" ;
329 open(SAVEOUT, ">&STDOUT");
330 my $dummy = fileno SAVEOUT;
331 open STDOUT, ">$name" ;
333 my $x = new $CompressClass '-' ;
337 open(STDOUT, ">&SAVEOUT");
339 ok 1, " wrote to stdout" ;
341 is myGZreadFile($name), $hello, " wrote OK";
345 title "Input from stdin via filename '-'";
349 my $stdinFileno = fileno(STDIN);
350 # open below doesn't return 1 sometines on XP
351 open(SAVEIN, "<&STDIN");
352 ok open(STDIN, "<$name"), " redirect STDIN";
353 my $dummy = fileno SAVEIN;
354 $x = new $UncompressClass '-', Append => 1, Transparent => 0
356 ok $x, " created object" ;
357 is $x->fileno(), $stdinFileno, " fileno ok" ;
359 1 while $x->read($uncomp) > 0 ;
361 ok $x->close, " close" ;
362 open(STDIN, "<&SAVEIN");
363 is $uncomp, $hello, " expected output" ;
368 # write a compressed file to memory
370 #========================================
372 #my $name = "test.gz" ;
373 my $lex = new LexFile my $name ;
383 ok $x = new $CompressClass(\$buffer) ;
385 ok ! defined $x->autoflush(1) ;
386 ok ! defined $x->autoflush(1) ;
387 ok ! defined $x->fileno() ;
388 is $x->write(''), 0, "Write empty string is ok";
389 is $x->write(undef), 0, "Write undef is ok";
390 ok $x->write($hello) ;
394 writeFile($name, $buffer) ;
395 #is anyUncompress(\$buffer), $hello, " any ok";
402 ok $x = new $UncompressClass(\$buffer, Append => 1) ;
404 ok ! defined $x->autoflush(1) ;
405 ok ! defined $x->autoflush(1) ;
406 ok ! defined $x->fileno() ;
407 1 while $x->read($uncomp) > 0 ;
409 ok $x->close, "closed" ;
412 is $uncomp, $hello, "got expected uncompressed data" ;
413 ok $buffer eq $keep, "compressed input not changed" ;
416 if ($CompressClass ne 'RawDeflate')
419 #========================================
424 $x = new $CompressClass(\$buffer);
425 ok $x, "new $CompressClass" ;
426 ok $x->close, "close ok" ;
434 ok $x = new $UncompressClass(\$buffer, Append => 1) ;
436 1 while $x->read($uncomp) > 0 ;
442 ok $buffer eq $keep ;
447 # write a larger file
448 #========================================
451 my $lex = new LexFile my $name ;
462 my $x = new $CompressClass $name ;
463 ok $x, " created $CompressClass object";
465 ok $x->write($hello), " write ok" ;
467 ok $x->write("another line"), " write ok" ;
468 $input .= "another line" ;
471 { $contents .= chr int $_ }
472 # generate a long random string
474 { $contents .= chr int rand 256 }
476 ok $x->write($contents), " write ok" ;
477 $input .= $contents ;
478 ok $x->close, " close ok" ;
481 ok myGZreadFile($name) eq $input ;
482 my $x = readFile($name) ;
483 #print "length " . length($x) . " \n";
487 # embed a compressed file in another file
488 #================================
491 my $lex = new LexFile my $name ;
498 my $header = "header info\n" ;
499 my $trailer = "trailer data\n" ;
503 ok $fh = new IO::File ">$name" ;
506 ok $x = new $CompressClass $fh,
510 ok $x->write($hello) ;
518 ok $fh1 = new IO::File "<$name" ;
521 ok $line eq $header ;
523 ok my $x = new $UncompressClass $fh1, Append => 1 ;
525 1 while $x->read($uncomp) > 0 ;
527 ok $uncomp eq $hello ;
529 read($fh1, $rest, 5000);
530 is $x->trailingData() . $rest, $trailer ;
531 #print "# [".$x->trailingData() . "][$rest]\n" ;
536 # embed a compressed file in another buffer
537 #================================
545 my $trailer = "trailer data" ;
550 ok my $x = new $CompressClass(\$compressed);
552 ok $x->write($hello) ;
554 $compressed .= $trailer ;
558 ok my $x = new $UncompressClass(\$compressed, Append => 1) ;
559 1 while $x->read($uncomp) > 0 ;
561 ok $uncomp eq $hello ;
562 is $x->trailingData(), $trailer ;
568 # these tests come almost 100% from IO::String
570 my $lex = new LexFile my $name ;
572 my $io = $CompressClass->new($name);
574 is $io->tell(), 0, " tell returns 0"; ;
576 my $heisan = "Heisan\n";
577 $io->print($heisan) ;
579 ok ! $io->eof(), " ! eof";
581 is $io->tell(), length($heisan), " tell is " . length($heisan) ;
583 $io->print("a", "b", "c");
587 $io->print("d", "e");
589 $io->print("f", "g", "h");
594 $io->print("D", "E");
596 $io->print("F", "G", "H");
599 my $foo = "1234567890";
601 is $io->syswrite($foo, length($foo)), length($foo), " syswrite ok" ;
603 { is $io->syswrite($foo, length $foo), length $foo, " syswrite ok" }
605 { is $io->syswrite($foo), length $foo, " syswrite ok" }
606 is $io->syswrite($foo, length($foo)), length $foo, " syswrite ok";
607 is $io->write($foo, length($foo), 5), 5, " write 5";
608 is $io->write("xxx\n", 100, -1), 1, " write 1";
611 $io->printf("i(%d)", $_);
612 $io->printf("[%d]\n", $_);
618 ok $io->eof(), " eof";
620 is myGZreadFile($name), "Heisan\nabcde\nf,g,h\nDEF.G.H" .
621 ("1234567890" x 3) . "67890\n" .
622 "i(1)[1]\ni(2)[2]\ni(3)[3]\n\n",
639 my $lex = new LexFile my $name ;
642 my $iow = new $CompressClass $name, %opts;
643 is $iow->input_line_number, undef;
645 is $iow->input_line_number, undef;
651 my $io = new $UncompressClass $name ;
654 is $io->input_line_number, 0;
655 ok ! $io->eof, "eof";
656 is $io->tell(), 0, "tell 0" ;
658 my @lines = $io->getlines();
660 or print "# Got " . scalar(@lines) . " lines, expected 6\n" ;
661 is $lines[1], "of a paragraph\n" ;
662 is join('', @lines), $str ;
664 is $io->input_line_number, 6;
665 is $io->tell(), length($str) ;
669 ok ! ( defined($io->getline) ||
670 (@tmp = $io->getlines) ||
671 defined($io->getline) ||
672 defined($io->getc) ||
673 $io->read($buf, 100) != 0) ;
678 local $/; # slurp mode
679 my $io = $UncompressClass->new($name);
681 is $io->input_line_number, 0;
683 my @lines = $io->getlines;
685 is $io->input_line_number, 1;
687 ok @lines == 1 && $lines[0] eq $str;
689 $io = $UncompressClass->new($name);
691 my $line = $io->getline();
697 local $/ = ""; # paragraph mode
698 my $io = $UncompressClass->new($name);
700 is $io->input_line_number, 0;
702 my @lines = $io->getlines();
704 is $io->input_line_number, 2;
707 or print "# Got " . scalar(@lines) . " lines, expected 2\n" ;
708 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
709 or print "# $lines[0]\n";
710 ok $lines[1] eq "and a single line.\n\n";
716 my $expected_records = int(length($str) / $reclen)
717 + (length($str) % $reclen ? 1 : 0);
720 my $io = $UncompressClass->new($name);
722 is $io->input_line_number, 0;
725 my @lines = $io->getlines();
726 is $., $expected_records;
727 is $io->input_line_number, $expected_records;
729 is @lines, $expected_records,
730 "Got $expected_records records\n" ;
731 ok $lines[0] eq substr($str, 0, $reclen)
732 or print "# $lines[0]\n";
733 ok $lines[1] eq substr($str, $reclen, $reclen);
738 my $io = $UncompressClass->new($name);
743 while (my $a = $io->getline()) {
745 $err++ if $. != ++$no;
752 is $io->input_line_number, 3;
754 or print "# Got " . scalar(@lines) . " lines, expected 3\n" ;
755 ok join("-", @lines) eq
756 "This- is- an example\n" .
757 "of a paragraph\n\n\n" .
758 "and a single line.\n\n";
765 my $io = $UncompressClass->new($name);
768 eval { $io->read(1) } ;
769 like $@, mkErr("buffer parameter is read-only");
772 is $io->read($buf, 0), 0, "Requested 0 bytes" ;
773 is $buf, "", "Buffer empty";
775 is $io->read($buf, 3), 3 ;
778 is $io->sysread($buf, 3, 2), 3 ;
780 or print "# [$buf]\n" ;;
784 is $io->read($buf, 3, 4), 3 ;
785 is $buf, "ab" . "\x00" x 2 . "s a"
786 or print "# [$buf]\n" ;;
789 # read the rest of the file
791 my $remain = length($str) - 9;
792 is $io->read($buf, $remain+1), $remain ;
793 is $buf, substr($str, 9);
797 is $io->read($buf, 10), 0 ;
798 is $buf, "", "Buffer empty";
803 is $io->read($buf, 10), 0 ;
804 is $buf, "hello", "Buffer not empty";
811 # ok read($io, $buf, 20) == 4 ;
812 # ok $buf eq "e.\n\n";
814 # ok read($io, $buf, 20) == 0 ;
823 # Read from non-compressed file
834 my $lex = new LexFile my $name ;
836 writeFile($name, $str);
840 my $io = new $UncompressClass $name, -Transparent => 1 ;
844 ok $io->tell() == 0 ;
845 my @lines = $io->getlines();
847 ok $lines[1] eq "of a paragraph\n" ;
848 ok join('', @lines) eq $str ;
850 is $io->input_line_number, 6;
851 ok $io->tell() == length($str) ;
855 ok ! ( defined($io->getline) ||
856 (@tmp = $io->getlines) ||
857 defined($io->getline) ||
858 defined($io->getc) ||
859 $io->read($buf, 100) != 0) ;
864 local $/; # slurp mode
865 my $io = $UncompressClass->new($name);
867 my @lines = $io->getlines;
869 is $io->input_line_number, 1;
871 ok @lines == 1 && $lines[0] eq $str;
873 $io = $UncompressClass->new($name);
875 my $line = $io->getline;
877 is $io->input_line_number, 1;
883 local $/ = ""; # paragraph mode
884 my $io = $UncompressClass->new($name);
886 my @lines = $io->getlines;
888 is $io->input_line_number, 2;
891 or print "# exected 2 lines, got " . scalar(@lines) . "\n";
892 ok $lines[0] eq "This is an example\nof a paragraph\n\n\n"
893 or print "# [$lines[0]]\n" ;
894 ok $lines[1] eq "and a single line.\n\n";
900 my $expected_records = int(length($str) / $reclen)
901 + (length($str) % $reclen ? 1 : 0);
904 my $io = $UncompressClass->new($name);
906 is $io->input_line_number, 0;
909 my @lines = $io->getlines();
910 is $., $expected_records;
911 is $io->input_line_number, $expected_records;
913 is @lines, $expected_records,
914 "Got $expected_records records\n" ;
915 ok $lines[0] eq substr($str, 0, $reclen)
916 or print "# $lines[0]\n";
917 ok $lines[1] eq substr($str, $reclen, $reclen);
922 my $io = $UncompressClass->new($name);
927 while (my $a = $io->getline) {
929 $err++ if $. != ++$no;
933 is $io->input_line_number, 3;
939 ok join("-", @lines) eq
940 "This- is- an example\n" .
941 "of a paragraph\n\n\n" .
942 "and a single line.\n\n";
949 my $io = $UncompressClass->new($name);
952 is $io->read($buf, 0), 0, "Requested 0 bytes" ;
953 is $buf, "", "Buffer empty";
955 ok $io->read($buf, 3) == 3 ;
958 ok $io->sysread($buf, 3, 2) == 3 ;
963 is $io->read($buf, 3, 4), 3 ;
964 is $buf, "ab" . "\x00" x 2 . "s a"
965 or print "# [$buf]\n" ;;
968 # read the rest of the file
970 my $remain = length($str) - 9;
971 is $io->read($buf, $remain), $remain ;
972 is $buf, substr($str, 9);
976 is $io->read($buf, 10), 0 ;
977 is $buf, "", "Buffer empty";
982 is $io->read($buf, 10), 0 ;
983 is $buf, "hello", "Buffer not empty";
990 # ok read($io, $buf, 20) == 4 ;
991 # ok $buf eq "e.\n\n";
993 # ok read($io, $buf, 20) == 0 ;
1003 # Vary the length parameter in a read
1018 foreach my $bufsize (1, 3, 512, 4096, length($str)-1, length($str), length($str)+1)
1020 foreach my $trans (0, 1)
1022 foreach my $append (0, 1)
1024 title "Read Tests - buf length $bufsize, Transparent $trans, Append $append" ;
1026 my $lex = new LexFile my $name ;
1029 writeFile($name, $str) ;
1032 my $iow = new $CompressClass $name;
1038 my $io = $UncompressClass->new($name,
1040 -Transparent => $trans);
1047 1 while $io->read($buf, $bufsize) > 0;
1051 $buf .= $tmp while $io->read($tmp, $bufsize) > 0 ;
1053 is length $buf, length $str;
1062 foreach my $file (0, 1)
1064 foreach my $trans (0, 1)
1066 title "seek tests - file $file trans $trans" ;
1070 my $lex = new LexFile my $name ;
1072 my $first = "beginning" ;
1073 my $last = "the end" ;
1077 $buffer = $first . "\x00" x 10 . $last;
1078 writeFile($name, $buffer);
1092 my $iow = new $CompressClass $output ;
1093 $iow->print($first) ;
1094 ok $iow->seek(5, SEEK_CUR) ;
1095 ok $iow->tell() == length($first)+5;
1096 ok $iow->seek(0, SEEK_CUR) ;
1097 ok $iow->tell() == length($first)+5;
1098 ok $iow->seek(length($first)+10, SEEK_SET) ;
1099 ok $iow->tell() == length($first)+10;
1101 $iow->print($last) ;
1115 ok myGZreadFile($input) eq $first . "\x00" x 10 . $last ;
1117 my $io = $UncompressClass->new($input, Strict => 1);
1118 ok $io->seek(length($first), SEEK_CUR)
1121 is $io->tell(), length($first);
1123 ok $io->read($buff, 5) ;
1124 is $buff, "\x00" x 5 ;
1125 is $io->tell(), length($first) + 5;
1127 ok $io->seek(0, SEEK_CUR) ;
1128 my $here = $io->tell() ;
1129 is $here, length($first)+5;
1131 ok $io->seek($here+5, SEEK_SET) ;
1132 is $io->tell(), $here+5 ;
1133 ok $io->read($buff, 100) ;
1140 title "seek error cases" ;
1143 my $a = new $CompressClass(\$b) ;
1146 eval { $a->seek(-1, 10) ; };
1147 like $@, mkErr("^${CompressClass}::seek: unknown value, 10, for whence parameter");
1149 eval { $a->seek(-1, SEEK_END) ; };
1150 like $@, mkErr("^${CompressClass}::seek: cannot seek backwards");
1156 my $u = new $UncompressClass(\$b) ;
1158 eval { $u->seek(-1, 10) ; };
1159 like $@, mkErr("^${UncompressClass}::seek: unknown value, 10, for whence parameter");
1161 eval { $u->seek(-1, SEEK_END) ; };
1162 like $@, mkErr("^${UncompressClass}::seek: SEEK_END not allowed");
1164 eval { $u->seek(-1, SEEK_CUR) ; };
1165 like $@, mkErr("^${UncompressClass}::seek: cannot seek backwards");
1168 foreach my $fb (qw(filename buffer filehandle))
1170 foreach my $append (0, 1)
1173 title "$CompressClass -- Append $append, Output to $fb" ;
1175 my $lex = new LexFile my $name ;
1177 my $already = 'already';
1178 my $buffer = $already;
1181 if ($fb eq 'buffer')
1182 { $output = \$buffer }
1183 elsif ($fb eq 'filename')
1186 writeFile($name, $buffer);
1188 elsif ($fb eq 'filehandle')
1190 $output = new IO::File ">$name" ;
1191 print $output $buffer;
1194 my $a = new $CompressClass($output, Append => $append) ;
1195 ok $a, " Created $CompressClass";
1196 my $string = "appended";
1201 if ($fb eq 'buffer')
1208 if $fb eq 'filehandle';
1209 $data = readFile($name);
1212 if ($append || $fb eq 'filehandle')
1214 is substr($data, 0, length($already)), $already, " got prefix";
1215 substr($data, 0, length($already)) = '';
1220 my $x = new $UncompressClass(\$data, Append => 1) ;
1221 ok $x, " created $UncompressClass";
1224 1 while ($len = $x->read($uncomp)) > 0 ;
1227 is $uncomp, $string, ' Got uncompressed data' ;
1233 foreach my $type (qw(buffer filename filehandle))
1235 foreach my $good (0, 1)
1237 title "$UncompressClass -- InputLength, read from $type, good data => $good";
1240 my $string = "some data";
1241 my $appended = "append";
1245 my $c = new $CompressClass(\$compressed);
1251 $compressed = $string ;
1254 my $comp_len = length $compressed;
1255 $compressed .= $appended;
1257 my $lex = new LexFile my $name ;
1259 writeFile ($name, $compressed);
1261 if ($type eq 'buffer')
1263 $input = \$compressed;
1265 if ($type eq 'filename')
1269 elsif ($type eq 'filehandle')
1271 my $fh = new IO::File "<$name" ;
1272 ok $fh, "opened file $name ok";
1276 my $x = new $UncompressClass($input,
1277 InputLength => $comp_len,
1279 ok $x, " created $UncompressClass";
1283 $len = $x->read($output, 100);
1285 is $len, length($string);
1286 is $output, $string;
1288 if ($type eq 'filehandle')
1291 $input->read($rest, 1000);
1292 is $rest, $appended;
1299 foreach my $append (0, 1)
1301 title "$UncompressClass -- Append $append" ;
1303 my $lex = new LexFile my $name ;
1305 my $string = "appended";
1307 my $c = new $CompressClass(\$compressed);
1311 my $x = new $UncompressClass(\$compressed, Append => $append) ;
1312 ok $x, " created $UncompressClass";
1314 my $already = 'already';
1315 my $output = $already;
1318 $len = $x->read($output, 100);
1319 is $len, length($string);
1325 is substr($output, 0, length($already)), $already, " got prefix";
1326 substr($output, 0, length($already)) = '';
1328 is $output, $string, ' Got uncompressed data' ;
1332 foreach my $file (0, 1)
1334 foreach my $trans (0, 1)
1336 title "ungetc, File $file, Transparent $trans" ;
1338 my $lex = new LexFile my $name ;
1340 my $string = 'abcdeABCDE';
1348 my $a = new $CompressClass(\$b) ;
1356 writeFile($name, $b);
1364 my $u = $UncompressClass->new($from, Transparent => 1) ;
1368 # do an ungetc before reading
1370 $first = $u->getc();
1373 $first = $u->getc();
1374 is $first, substr($string, 0,1);
1376 $first = $u->getc();
1377 is $first, substr($string, 0,1);
1380 is $u->read($buff, 5), 5 ;
1381 is $buff, substr($string, 0, 5);
1384 is $u->read($buff, length($string)), length($string) ;
1387 is $u->read($buff, 1), 0;
1390 my $extra = 'extra';
1393 is $u->read($buff), length($extra) ;
1396 is $u->read($buff, 1), 0;
1399 # getc returns undef on eof
1400 is $u->getc(), undef;
1407 title "write tests - invalid data" ;
1409 #my $lex = new LexFile my $name1 ;
1412 #ok ! -e $name1, " File $name1 does not exist";
1415 [ '{ }', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1416 [ '[ { } ]', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1417 [ '[ [ { } ] ]', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ],
1418 [ '[ "" ]', "${CompressClass}::write: input filename is undef or null string" ],
1419 [ '[ undef ]', "${CompressClass}::write: input filename is undef or null string" ],
1420 [ '[ \$Answer ]',"${CompressClass}::write: input and output buffer are identical" ],
1421 #[ "not readable", 'xx' ],
1422 # same filehandle twice, 'xx'
1425 foreach my $data (@data)
1427 my ($send, $get) = @$data ;
1428 title "${CompressClass}::write( $send )";
1430 eval "\$copy = $send";
1431 my $x = new $CompressClass(\$Answer);
1432 ok $x, " Created $CompressClass object";
1433 eval { $x->write($copy) } ;
1434 #like $@, "/^$get/", " error - $get";
1435 like $@, "/not a scalar reference /", " error - not a scalar reference";
1439 # [ '[ $name1 ]', "input file '$name1' does not exist" ],
1440 # #[ "not readable", 'xx' ],
1441 # # same filehandle twice, 'xx'
1444 # foreach my $data (@data)
1446 # my ($send, $get) = @$data ;
1447 # title "${CompressClass}::write( $send )";
1449 # eval "\$copy = $send";
1450 # my $x = new $CompressClass(\$Answer);
1451 # ok $x, " Created $CompressClass object";
1452 # ok ! $x->write($copy), " write fails" ;
1453 # like $$Error, "/^$get/", " error - $get";
1463 # if (! ref $_[0] || ref $_[0] eq 'SCALAR')
1468 # if (ref $_[0] eq 'ARRAY')
1471 # for my $x ( @{ $_[0] })
1473 # push @a, deepCopy($x);
1479 # croak "bad! $_[0]";
1485 # #my $data = shift ;
1486 # my $from = $_[1] ;
1492 # if $_[0] eq $from ;
1497 # if (ref $_[0] eq 'SCALAR')
1500 # if defined ${ $_[0] } && ${ $_[0] } eq $from ;
1505 # if (ref $_[0] eq 'ARRAY')
1507 # for my $x ( @{ $_[0] })
1509 # deepSubst($x, $from, $to);
1513 # #croak "bad! $_[0]";
1517 # title "More write tests" ;
1519 # my $file1 = "file1" ;
1520 # my $file2 = "file2" ;
1521 # my $file3 = "file3" ;
1522 # my $lex = new LexFile $file1, $file2, $file3 ;
1524 # writeFile($file1, "F1");
1525 # writeFile($file2, "F2");
1526 # writeFile($file3, "F3");
1531 # [ '"abcd"', "abcd" ],
1535 # [ '\"abcd"', "abcd" ],
1541 # [ '[\undef]', "" ],
1542 # [ '[\"abcd"]', "abcd" ],
1543 # [ '[\"ab", \"cd"]', "abcd" ],
1544 # [ '[[\"ab"], [\"cd"]]', "abcd" ],
1546 # [ '$file1', $file1 ],
1548 # [ '[$file1, \"abc"]', "F1abc"],
1549 # [ '[\"a", $file1, \"bc"]', "aF1bc"],
1550 # [ '[\"a", $fh1, \"bc"]', "aF1bc"],
1551 # [ '[\"a", $fh1, \"bc", $file2]', "aF1bcF2"],
1552 # [ '[\"a", $fh1, \"bc", $file2, $fh3]', "aF1bcF2F3"],
1556 # foreach my $data (@data)
1558 # my ($send, $get) = @$data ;
1560 # my $fh1 = new IO::File "< $file1" ;
1561 # my $fh2 = new IO::File "< $file2" ;
1562 # my $fh3 = new IO::File "< $file3" ;
1564 # title "${CompressClass}::write( $send )";
1566 # eval "\$copy = $send";
1568 # my $x = new $CompressClass(\$Answer);
1569 # ok $x, " Created $CompressClass object";
1570 # my $len = length $get;
1571 # is $x->write($copy), length($get), " write $len bytes";
1572 # ok $x->close(), " close ok" ;
1574 # is myGZreadFile(\$Answer), $get, " got expected output" ;
1575 # cmp_ok $$Error, '==', 0, " no error";