10 plan(skip_all => "oneshot needs Perl 5.005 or better - you have Perl $]" )
14 # use Test::NoWarnings, if available
17 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
19 plan tests => 956 + $extra ;
21 use_ok('IO::Uncompress::AnyUncompress', qw(anyuncompress $AnyUncompressError)) ;
28 my $CompressClass = identify();
29 my $UncompressClass = getInverse($CompressClass);
30 my $Error = getErrorRef($CompressClass);
31 my $UnError = getErrorRef($UncompressClass);
32 my $TopFuncName = getTopFuncName($CompressClass);
36 foreach my $bit ($CompressClass, $UncompressClass,
37 'IO::Uncompress::AnyUncompress',
40 my $Error = getErrorRef($bit);
41 my $Func = getTopFuncRef($bit);
42 my $TopType = getTopFuncName($bit);
44 title "Testing $TopType Error Cases";
49 eval { $a = $Func->(\$a => \$x, Fred => 1) ;} ;
50 like $@, mkErr("^$TopType: unknown key value\\(s\\) Fred"), ' Illegal Parameters';
52 eval { $a = $Func->() ;} ;
53 like $@, mkErr("^$TopType: expected at least 1 parameters"), ' No Parameters';
55 eval { $a = $Func->(\$x, \1) ;} ;
56 like $$Error, "/^$TopType: output buffer is read-only/", ' Output is read-only' ;
59 eval { $a = $Func->($in, \$x) ;} ;
60 like $@, mkErr("^$TopType: input filename is undef or null string"),
61 ' Input filename undef' ;
64 eval { $a = $Func->($in, \$x) ;} ;
65 like $@, mkErr("^$TopType: input filename is undef or null string"),
66 ' Input filename empty' ;
69 my $lex1 = new LexFile my $in ;
70 writeFile($in, "abc");
72 eval { $a = $Func->($in, $out) ;} ;
73 like $@, mkErr("^$TopType: input and output filename are identical"),
74 ' Input and Output filename are the same';
79 my $lex = new LexDir $dir ;
82 $a = $Func->($dir, \$x) ;
83 is $a, undef, " $TopType returned undef";
84 like $$Error, "/input file '$dir' is a directory/",
85 ' Input filename is a directory';
87 $a = $Func->(\$x, $dir) ;
88 is $a, undef, " $TopType returned undef";
89 like $$Error, "/output file '$dir' is a directory/",
90 ' Output filename is a directory';
93 eval { $a = $Func->(\$in, \$in) ;} ;
94 like $@, mkErr("^$TopType: input and output buffer are identical"),
95 ' Input and Output buffer are the same';
97 my $lex = new LexFile my $out_file ;
98 open OUT, ">$out_file" ;
99 eval { $a = $Func->(\*OUT, \*OUT) ;} ;
100 like $@, mkErr("^$TopType: input and output handle are identical"),
101 ' Input and Output handle are the same';
104 is -s $out_file, 0, " File zero length" ;
107 my $object = bless \%x, "someClass" ;
109 # Buffer not a scalar reference
110 #eval { $a = $Func->(\$x, \%x) ;} ;
111 eval { $a = $Func->(\$x, $object) ;} ;
112 like $@, mkErr("^$TopType: illegal output parameter"),
115 # Buffer not a scalar reference
116 eval { $a = $Func->(\$x, \%x) ;} ;
117 like $@, mkErr("^$TopType: illegal output parameter"),
121 eval { $a = $Func->(\%x, \$x) ;} ;
122 like $@, mkErr("^$TopType: illegal input parameter"),
125 #eval { $a = $Func->(\%x, \$x) ;} ;
126 eval { $a = $Func->($object, \$x) ;} ;
127 like $@, mkErr("^$TopType: illegal input parameter"),
131 my $filename = 'abc.def';
132 ok ! -e $filename, " input file '$filename' does not exist";
133 $a = $Func->($filename, \$x) ;
134 is $a, undef, " $TopType returned undef";
135 like $$Error, "/^input file '$filename' does not exist\$/", " input File '$filename' does not exist";
137 $filename = '/tmp/abd/abc.def';
138 ok ! -e $filename, " output File '$filename' does not exist";
139 $a = $Func->(\$x, $filename) ;
140 is $a, undef, " $TopType returned undef";
141 like $$Error, ("/^(cannot open file '$filename'|input file '$filename' does not exist):/"), " output File '$filename' does not exist";
143 eval { $a = $Func->(\$x, '<abc>') } ;
144 like $$Error, "/Need input fileglob for outout fileglob/",
145 ' Output fileglob with no input fileglob';
146 is $a, undef, " $TopType returned undef";
148 $a = $Func->('<abc)>', '<abc>') ;
149 is $a, undef, " $TopType returned undef";
150 like $$Error, "/Unmatched \\) in input fileglob/",
151 " Unmatched ) in input fileglob";
154 foreach my $bit ($UncompressClass,
155 'IO::Uncompress::AnyUncompress',
158 my $Error = getErrorRef($bit);
159 my $Func = getTopFuncRef($bit);
160 my $TopType = getTopFuncName($bit);
162 my $data = "mary had a little lamb" ;
165 for my $trans ( 0, 1)
167 title "Non-compressed data with $TopType, Transparent => $trans ";
172 $a = $Func->(\$data, \$out, Transparent => $trans) ;
174 is $data, $keep, " Input buffer not changed" ;
178 ok $a, " $TopType returned true" ;
179 is $out, $data, " got expected output" ;
180 ok ! $$Error, " no error [$$Error]" ;
184 ok ! $a, " $TopType returned false" ;
185 #like $$Error, '/xxx/', " error" ;
186 ok $$Error, " error is '$$Error'" ;
191 foreach my $bit ($CompressClass
194 my $Error = getErrorRef($bit);
195 my $Func = getTopFuncRef($bit);
196 my $TopType = getTopFuncName($bit);
197 my $TopTypeInverse = getInverse($bit);
198 my $FuncInverse = getTopFuncRef($TopTypeInverse);
199 my $ErrorInverse = getErrorRef($TopTypeInverse);
201 title "$TopTypeInverse - corrupt data";
203 my $data = "abcd" x 100 ;
206 ok $Func->(\$data, \$out), " $TopType ok";
208 # corrupt the compressed data
209 #substr($out, -10, 10) = "x" x 10 ;
210 substr($out, int(length($out)/3), 10) = 'abcdeabcde';
213 ok ! $FuncInverse->(\$out => \$result, Transparent => 0), " $TopTypeInverse ok";
214 ok $$ErrorInverse, " Got error '$$ErrorInverse'" ;
216 #is $result, $data, " data ok";
218 ok ! anyuncompress(\$out => \$result, Transparent => 0), "anyuncompress ok";
219 ok $AnyUncompressError, " Got error '$AnyUncompressError'" ;
223 foreach my $bit ($CompressClass
226 my $Error = getErrorRef($bit);
227 my $Func = getTopFuncRef($bit);
228 my $TopType = getTopFuncName($bit);
229 my $TopTypeInverse = getInverse($bit);
230 my $FuncInverse = getTopFuncRef($TopTypeInverse);
233 @opts = (RawInflate => 1)
234 if $CompressClass eq 'IO::Compress::RawInflate';
236 for my $append ( 1, 0 )
239 $already = 'abcde' if $append ;
241 for my $buffer ( undef, '', "abcde" )
244 my $disp_content = defined $buffer ? $buffer : '<undef>' ;
247 my $out_file = "abcde.out";
248 my $in_file = "abcde.in";
251 title "$TopType - From Buff to Buff content '$disp_content' Append $append" ;
253 my $output = $already;
254 ok &$Func(\$buffer, \$output, Append => $append), ' Compressed ok' ;
256 is $keep, $buffer, " Input buffer not changed" ;
257 my $got = anyUncompress(\$output, $already);
258 $got = undef if ! defined $buffer && $got eq '' ;
259 is $got, $buffer, " Uncompressed matches original";
264 title "$TopType - From Buff to Array Ref content '$disp_content' Append $append" ;
266 my @output = ('first') ;
267 ok &$Func(\$buffer, \@output, Append => $append), ' Compressed ok' ;
269 is $output[0], 'first', " Array[0] unchanged";
270 is $keep, $buffer, " Input buffer not changed" ;
271 my $got = anyUncompress($output[1]);
272 $got = undef if ! defined $buffer && $got eq '' ;
273 is $got, $buffer, " Uncompressed matches original";
277 title "$TopType - From Array Ref to Array Ref content '$disp_content' Append $append" ;
279 my $lex = new LexFile my $in_file ;
280 writeFile($in_file, $buffer);
281 my @output = ('first') ;
282 my @input = ($in_file);
283 ok &$Func(\@input, \@output, Append => $append), ' Compressed ok' ;
285 is $output[0], 'first', " Array[0] unchanged";
286 my $got = anyUncompress($output[1]);
287 $got = undef if ! defined $buffer && $got eq '' ;
288 is $got, $buffer, " Uncompressed matches original";
292 title "$TopType - From Buff to Filename content '$disp_content' Append $append" ;
294 my $lex = new LexFile my $out_file ;
295 ok ! -e $out_file, " Output file does not exist";
296 writeFile($out_file, $already);
298 ok &$Func(\$buffer, $out_file, Append => $append), ' Compressed ok' ;
300 ok -e $out_file, " Created output file";
301 my $got = anyUncompress($out_file, $already);
302 $got = undef if ! defined $buffer && $got eq '' ;
303 is $got, $buffer, " Uncompressed matches original";
307 title "$TopType - From Buff to Handle content '$disp_content' Append $append" ;
309 my $lex = new LexFile my $out_file ;
311 ok ! -e $out_file, " Output file does not exist";
312 writeFile($out_file, $already);
313 my $of = new IO::File ">>$out_file" ;
314 ok $of, " Created output filehandle" ;
316 ok &$Func(\$buffer, $of, AutoClose => 1, Append => $append), ' Compressed ok' ;
318 ok -e $out_file, " Created output file";
319 my $got = anyUncompress($out_file, $already);
320 $got = undef if ! defined $buffer && $got eq '' ;
321 is $got, $buffer, " Uncompressed matches original";
326 title "$TopType - From Filename to Filename content '$disp_content' Append $append" ;
328 my $lex = new LexFile(my $in_file, my $out_file) ;
329 writeFile($in_file, $buffer);
331 ok ! -e $out_file, " Output file does not exist";
332 writeFile($out_file, $already);
334 ok &$Func($in_file => $out_file, Append => $append), ' Compressed ok' ;
336 ok -e $out_file, " Created output file";
337 my $got = anyUncompress($out_file, $already);
338 $got = undef if ! defined $buffer && $got eq '' ;
339 is $got, $buffer, " Uncompressed matches original";
344 title "$TopType - From Filename to Handle content '$disp_content' Append $append" ;
346 my $lex = new LexFile(my $in_file, my $out_file) ;
347 writeFile($in_file, $buffer);
349 ok ! -e $out_file, " Output file does not exist";
350 writeFile($out_file, $already);
351 my $out = new IO::File ">>$out_file" ;
353 ok &$Func($in_file, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
355 ok -e $out_file, " Created output file";
356 my $got = anyUncompress($out_file, $already);
357 $got = undef if ! defined $buffer && $got eq '' ;
358 is $got, $buffer, " Uncompressed matches original";
363 title "$TopType - From Filename to Buffer content '$disp_content' Append $append" ;
365 my $lex = new LexFile(my $in_file, my $out_file) ;
366 writeFile($in_file, $buffer);
370 ok &$Func($in_file => \$out, Append => $append), ' Compressed ok' ;
372 my $got = anyUncompress(\$out, $already);
373 $got = undef if ! defined $buffer && $got eq '' ;
374 is $got, $buffer, " Uncompressed matches original";
379 title "$TopType - From Handle to Filename content '$disp_content' Append $append" ;
381 my $lex = new LexFile(my $in_file, my $out_file) ;
382 writeFile($in_file, $buffer);
383 my $in = new IO::File "<$in_file" ;
385 ok ! -e $out_file, " Output file does not exist";
386 writeFile($out_file, $already);
388 ok &$Func($in, $out_file, Append => $append), ' Compressed ok'
389 or diag "error is $$Error" ;
391 ok -e $out_file, " Created output file";
392 my $got = anyUncompress($out_file, $already);
393 $got = undef if ! defined $buffer && $got eq '' ;
394 is $buffer, $got, " Uncompressed matches original";
399 title "$TopType - From Handle to Handle content '$disp_content' Append $append" ;
401 my $lex = new LexFile(my $in_file, my $out_file) ;
402 writeFile($in_file, $buffer);
403 my $in = new IO::File "<$in_file" ;
405 ok ! -e $out_file, " Output file does not exist";
406 writeFile($out_file, $already);
407 my $out = new IO::File ">>$out_file" ;
409 ok &$Func($in, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
411 ok -e $out_file, " Created output file";
412 my $got = anyUncompress($out_file, $already);
413 $got = undef if ! defined $buffer && $got eq '' ;
414 is $buffer, $got, " Uncompressed matches original";
419 title "$TopType - From Handle to Buffer content '$disp_content' Append $append" ;
421 my $lex = new LexFile(my $in_file, my $out_file) ;
422 writeFile($in_file, $buffer);
423 my $in = new IO::File "<$in_file" ;
427 ok &$Func($in, \$out, Append => $append), ' Compressed ok' ;
429 my $got = anyUncompress(\$out, $already);
430 $got = undef if ! defined $buffer && $got eq '' ;
431 is $buffer, $got, " Uncompressed matches original";
436 title "$TopType - From stdin (via '-') to Buffer content '$disp_content' Append $append" ;
438 my $lex = new LexFile(my $in_file, my $out_file) ;
439 writeFile($in_file, $buffer);
441 open(SAVEIN, "<&STDIN");
442 my $dummy = fileno SAVEIN ;
443 ok open(STDIN, "<$in_file"), " redirect STDIN";
447 ok &$Func('-', \$out, Append => $append), ' Compressed ok'
450 open(STDIN, "<&SAVEIN");
452 my $got = anyUncompress(\$out, $already);
453 $got = undef if ! defined $buffer && $got eq '' ;
454 is $buffer, $got, " Uncompressed matches original";
462 foreach my $bit ($CompressClass)
464 my $Error = getErrorRef($bit);
465 my $Func = getTopFuncRef($bit);
466 my $TopType = getTopFuncName($bit);
468 my $TopTypeInverse = getInverse($bit);
469 my $FuncInverse = getTopFuncRef($TopTypeInverse);
471 my $lex = new LexFile(my $file1, my $file2) ;
473 writeFile($file1, "data1");
474 writeFile($file2, "data2");
475 my $of = new IO::File "<$file1" ;
476 ok $of, " Created output filehandle" ;
478 #my @input = ( undef, "", $file2, \undef, \'', \"abcde", $of) ;
479 #my @expected = ("", "", $file2, "", "", "abcde", "data1");
480 #my @uexpected = ("", "", "data2", "", "", "abcde", "data1");
481 #my @input = ( $file2, \"abcde", $of) ;
482 #my @expected = ( $file2, "abcde", "data1");
483 #my @uexpected = ("data2", "abcde", "data1");
485 my @input = ( $file1, $file2) ;
486 #my @expected = ( $file1, $file2);
487 my @expected = ("data1", "data2");
488 my @uexpected = ("data1", "data2");
493 title "$TopType - From Array Ref to Array Ref" ;
495 my @output = ('first') ;
496 ok &$Func(\@input, \@output, AutoClose => 0), ' Compressed ok' ;
498 is $output[0], 'first', " Array[0] unchanged";
500 is_deeply \@input, \@keep, " Input array not changed" ;
501 my @got = shift @output;
502 foreach (@output) { push @got, anyUncompress($_) }
504 is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
508 foreach my $ms (1, 0)
511 title "$TopType - From Array Ref to Buffer, MultiStream $ms" ;
513 # rewind the filehandle
514 $of->open("<$file1") ;
517 ok &$Func(\@input, \$output, MultiStream => $ms, AutoClose => 0), ' Compressed ok'
520 my $got = anyUncompress([ \$output, MultiStream => $ms ]);
522 is $got, join('', @uexpected), " Got Expected uncompressed data";
523 my @headers = getHeaders(\$output);
524 is @headers, $ms ? @input : 1, " Header count ok";
528 title "$TopType - From Array Ref to Filename, MultiStream $ms" ;
530 my $lex = new LexFile( my $file3) ;
532 # rewind the filehandle
533 $of->open("<$file1") ;
536 ok &$Func(\@input, $file3, MultiStream => $ms, AutoClose => 0), ' Compressed ok' ;
538 my $got = anyUncompress([ $file3, MultiStream => $ms ]);
540 is $got, join('', @uexpected), " Got Expected uncompressed data";
541 my @headers = getHeaders($file3);
542 is @headers, $ms ? @input : 1, " Header count ok";
546 title "$TopType - From Array Ref to Filehandle, MultiStream $ms" ;
548 my $lex = new LexFile(my $file3) ;
550 my $fh3 = new IO::File ">$file3";
552 # rewind the filehandle
553 $of->open("<$file1") ;
556 ok &$Func(\@input, $fh3, MultiStream => $ms, AutoClose => 0), ' Compressed ok' ;
560 my $got = anyUncompress([ $file3, MultiStream => $ms ]);
562 is $got, join('', @uexpected), " Got Expected uncompressed data";
563 my @headers = getHeaders($file3);
564 is @headers, $ms ? @input : 1, " Header count ok";
569 # foreach my $bit ($CompressClass)
571 # my $Error = getErrorRef($bit);
572 # my $Func = getTopFuncRef($bit);
573 # my $TopType = getTopFuncName($bit);
575 # my $TopTypeInverse = getInverse($bit);
576 # my $FuncInverse = getTopFuncRef($TopTypeInverse);
578 # my @inFiles = map { "in$_.tmp" } 1..4;
579 # my @outFiles = map { "out$_.tmp" } 1..4;
580 # my $lex = new LexFile(@inFiles, @outFiles);
582 # writeFile($_, "data $_") foreach @inFiles ;
585 # title "$TopType - Hash Ref: to filename" ;
588 # ok &$Func( { $inFiles[0] => $outFiles[0],
589 # $inFiles[1] => $outFiles[1],
590 # $inFiles[2] => $outFiles[2] } ), ' Compressed ok' ;
594 # my $got = anyUncompress($outFiles[$_]);
595 # is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
600 # title "$TopType - Hash Ref: to buffer" ;
603 # ok &$Func( { $inFiles[0] => \$buffer[0],
604 # $inFiles[1] => \$buffer[1],
605 # $inFiles[2] => \$buffer[2] } ), ' Compressed ok' ;
609 # my $got = anyUncompress(\$buffer[$_]);
610 # is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
615 # title "$TopType - Hash Ref: to undef" ;
618 # my %hash = ( $inFiles[0] => undef,
619 # $inFiles[1] => undef,
620 # $inFiles[2] => undef,
623 # ok &$Func( \%hash ), ' Compressed ok' ;
625 # foreach (keys %hash)
627 # my $got = anyUncompress(\$hash{$_});
628 # is $got, "data $_", " Uncompressed $_ matches original";
633 # title "$TopType - Filename to Hash Ref" ;
636 # ok &$Func( $inFiles[0] => \%output), ' Compressed ok' ;
638 # is keys %output, 1, " one pair in hash" ;
639 # my ($k, $v) = each %output;
640 # is $k, $inFiles[0], " key is '$inFiles[0]'";
641 # my $got = anyUncompress($v);
642 # is $got, "data $inFiles[0]", " Uncompressed matches original";
646 # title "$TopType - File Glob to Hash Ref" ;
649 # ok &$Func( '<in*.tmp>' => \%output), ' Compressed ok' ;
651 # is keys %output, 4, " four pairs in hash" ;
652 # foreach my $fil (@inFiles)
654 # ok exists $output{$fil}, " key '$fil' exists" ;
655 # my $got = anyUncompress($output{$fil});
656 # is $got, "data $fil", " Uncompressed matches original";
663 # foreach my $bit ($CompressClass)
665 # my $Error = getErrorRef($bit);
666 # my $Func = getTopFuncRef($bit);
667 # my $TopType = getTopFuncName($bit);
669 # my $TopTypeInverse = getInverse($bit);
670 # my $FuncInverse = getTopFuncRef($TopTypeInverse);
672 # my @inFiles = map { "in$_.tmp" } 1..4;
673 # my @outFiles = map { "out$_.tmp" } 1..4;
674 # my $lex = new LexFile(@inFiles, @outFiles);
676 # writeFile($_, "data $_") foreach @inFiles ;
682 # # title "$TopType - Hash Ref to Array Ref" ;
684 # # my @output = ('first') ;
685 # # ok &$Func( { \@input, \@output } , AutoClose => 0), ' Compressed ok' ;
687 # # is $output[0], 'first', " Array[0] unchanged";
689 # # is_deeply \@input, \@keep, " Input array not changed" ;
690 # # my @got = shift @output;
691 # # foreach (@output) { push @got, anyUncompress($_) }
693 # # is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
699 # # title "$TopType - From Array Ref to Buffer" ;
701 # # # rewind the filehandle
702 # # $of->open("<$file1") ;
705 # # ok &$Func(\@input, \$output, AutoClose => 0), ' Compressed ok' ;
707 # # my $got = anyUncompress(\$output);
709 # # is $got, join('', @expected), " Got Expected uncompressed data";
714 # # title "$TopType - From Array Ref to Filename" ;
716 # # my ($file3) = ("file3");
717 # # my $lex = new LexFile($file3) ;
719 # # # rewind the filehandle
720 # # $of->open("<$file1") ;
723 # # ok &$Func(\@input, $file3, AutoClose => 0), ' Compressed ok' ;
725 # # my $got = anyUncompress($file3);
727 # # is $got, join('', @expected), " Got Expected uncompressed data";
732 # # title "$TopType - From Array Ref to Filehandle" ;
734 # # my ($file3) = ("file3");
735 # # my $lex = new LexFile($file3) ;
737 # # my $fh3 = new IO::File ">$file3";
739 # # # rewind the filehandle
740 # # $of->open("<$file1") ;
743 # # ok &$Func(\@input, $fh3, AutoClose => 0), ' Compressed ok' ;
747 # # my $got = anyUncompress($file3);
749 # # is $got, join('', @expected), " Got Expected uncompressed data";
753 foreach my $bit ($CompressClass
756 my $Error = getErrorRef($bit);
757 my $Func = getTopFuncRef($bit);
758 my $TopType = getTopFuncName($bit);
760 for my $files ( [qw(a1)], [qw(a1 a2 a3)] )
763 my $tmpDir1 = 'tmpdir1';
764 my $tmpDir2 = 'tmpdir2';
765 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
767 mkdir $tmpDir1, 0777;
768 mkdir $tmpDir2, 0777;
770 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
771 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
773 my @files = map { "$tmpDir1/$_.tmp" } @$files ;
774 foreach (@files) { writeFile($_, "abc $_") }
776 my @expected = map { "abc $_" } @files ;
777 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
780 title "$TopType - From FileGlob to FileGlob files [@$files]" ;
782 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>"), ' Compressed ok'
785 my @copy = @expected;
786 for my $file (@outFiles)
788 is anyUncompress($file), shift @copy, " got expected from $file" ;
791 is @copy, 0, " got all files";
795 title "$TopType - From FileGlob to Array files [@$files]" ;
797 my @buffer = ('first') ;
798 ok &$Func("<$tmpDir1/a*.tmp>" => \@buffer), ' Compressed ok'
801 is shift @buffer, 'first';
803 my @copy = @expected;
804 for my $buffer (@buffer)
806 is anyUncompress($buffer), shift @copy, " got expected " ;
809 is @copy, 0, " got all files";
812 foreach my $ms (0, 1)
815 title "$TopType - From FileGlob to Buffer files [@$files], MS $ms" ;
818 ok &$Func("<$tmpDir1/a*.tmp>" => \$buffer,
819 MultiStream => $ms), ' Compressed ok'
824 my $got = anyUncompress([ \$buffer, MultiStream => $ms ]);
826 is $got, join("", @expected), " got expected" ;
827 my @headers = getHeaders(\$buffer);
828 is @headers, $ms ? @files : 1, " Header count ok";
832 title "$TopType - From FileGlob to Filename files [@$files], MS $ms" ;
834 my $filename = "abcde";
835 my $lex = new LexFile($filename) ;
837 ok &$Func("<$tmpDir1/a*.tmp>" => $filename,
838 MultiStream => $ms), ' Compressed ok'
843 my $got = anyUncompress([$filename, MultiStream => $ms]);
845 is $got, join("", @expected), " got expected" ;
846 my @headers = getHeaders($filename);
847 is @headers, $ms ? @files : 1, " Header count ok";
851 title "$TopType - From FileGlob to Filehandle files [@$files], MS $ms" ;
853 my $filename = "abcde";
854 my $lex = new LexFile($filename) ;
855 my $fh = new IO::File ">$filename";
857 ok &$Func("<$tmpDir1/a*.tmp>" => $fh,
858 MultiStream => $ms, AutoClose => 1), ' Compressed ok'
863 my $got = anyUncompress([$filename, MultiStream => $ms]);
865 is $got, join("", @expected), " got expected" ;
866 my @headers = getHeaders($filename);
867 is @headers, $ms ? @files : 1, " Header count ok";
874 foreach my $bit ($UncompressClass,
875 'IO::Uncompress::AnyUncompress',
878 my $Error = getErrorRef($bit);
879 my $Func = getTopFuncRef($bit);
880 my $TopType = getTopFuncName($bit);
882 my $buffer = "abcde" ;
883 my $buffer2 = "ABCDE" ;
884 my $keep_orig = $buffer;
886 my $comp = compressBuffer(getTopFuncName($UncompressClass), $buffer) ;
887 my $comp2 = compressBuffer(getTopFuncName($UncompressClass), $buffer2) ;
888 my $keep_comp = $comp;
890 my $incumbent = "incumbent data" ;
893 @opts = (RawInflate => 1)
894 if $bit eq 'IO::Uncompress::AnyUncompress';
896 for my $append (0, 1)
898 my $expected = $buffer ;
899 $expected = $incumbent . $buffer if $append ;
902 title "$TopType - From Buff to Buff, Append($append)" ;
905 $output = $incumbent if $append ;
906 ok &$Func(\$comp, \$output, Append => $append, @opts), ' Uncompressed ok' ;
908 is $keep_comp, $comp, " Input buffer not changed" ;
909 is $output, $expected, " Uncompressed matches original";
913 title "$TopType - From Buff to Array, Append($append)" ;
915 my @output = ('first');
916 #$output = $incumbent if $append ;
917 ok &$Func(\$comp, \@output, Append => $append, @opts), ' Uncompressed ok' ;
919 is $keep_comp, $comp, " Input buffer not changed" ;
920 is $output[0], 'first', " Uncompressed matches original";
921 is ${ $output[1] }, $buffer, " Uncompressed matches original"
923 is @output, 2, " only 2 elements in the array" ;
927 title "$TopType - From Buff to Filename, Append($append)" ;
929 my $lex = new LexFile(my $out_file) ;
931 { writeFile($out_file, $incumbent) }
933 { ok ! -e $out_file, " Output file does not exist" }
935 ok &$Func(\$comp, $out_file, Append => $append, @opts), ' Uncompressed ok' ;
937 ok -e $out_file, " Created output file";
938 my $content = readFile($out_file) ;
940 is $keep_comp, $comp, " Input buffer not changed" ;
941 is $content, $expected, " Uncompressed matches original";
945 title "$TopType - From Buff to Handle, Append($append)" ;
947 my $lex = new LexFile(my $out_file) ;
950 writeFile($out_file, $incumbent) ;
951 $of = new IO::File "+< $out_file" ;
954 ok ! -e $out_file, " Output file does not exist" ;
955 $of = new IO::File "> $out_file" ;
957 isa_ok $of, 'IO::File', ' $of' ;
959 ok &$Func(\$comp, $of, Append => $append, AutoClose => 1, @opts), ' Uncompressed ok' ;
961 ok -e $out_file, " Created output file";
962 my $content = readFile($out_file) ;
964 is $keep_comp, $comp, " Input buffer not changed" ;
965 is $content, $expected, " Uncompressed matches original";
969 title "$TopType - From Filename to Filename, Append($append)" ;
971 my $lex = new LexFile(my $in_file, my $out_file) ;
973 { writeFile($out_file, $incumbent) }
975 { ok ! -e $out_file, " Output file does not exist" }
977 writeFile($in_file, $comp);
979 ok &$Func($in_file, $out_file, Append => $append, @opts), ' Uncompressed ok' ;
981 ok -e $out_file, " Created output file";
982 my $content = readFile($out_file) ;
984 is $keep_comp, $comp, " Input buffer not changed" ;
985 is $content, $expected, " Uncompressed matches original";
989 title "$TopType - From Filename to Handle, Append($append)" ;
991 my $lex = new LexFile(my $in_file, my $out_file) ;
994 writeFile($out_file, $incumbent) ;
995 $out = new IO::File "+< $out_file" ;
998 ok ! -e $out_file, " Output file does not exist" ;
999 $out = new IO::File "> $out_file" ;
1001 isa_ok $out, 'IO::File', ' $out' ;
1003 writeFile($in_file, $comp);
1005 ok &$Func($in_file, $out, Append => $append, AutoClose => 1, @opts), ' Uncompressed ok' ;
1007 ok -e $out_file, " Created output file";
1008 my $content = readFile($out_file) ;
1010 is $keep_comp, $comp, " Input buffer not changed" ;
1011 is $content, $expected, " Uncompressed matches original";
1015 title "$TopType - From Filename to Buffer, Append($append)" ;
1017 my $lex = new LexFile(my $in_file) ;
1018 writeFile($in_file, $comp);
1021 $output = $incumbent if $append ;
1023 ok &$Func($in_file, \$output, Append => $append, @opts), ' Uncompressed ok' ;
1025 is $keep_comp, $comp, " Input buffer not changed" ;
1026 is $output, $expected, " Uncompressed matches original";
1030 title "$TopType - From Handle to Filename, Append($append)" ;
1032 my $lex = new LexFile(my $in_file, my $out_file) ;
1034 { writeFile($out_file, $incumbent) }
1036 { ok ! -e $out_file, " Output file does not exist" }
1038 writeFile($in_file, $comp);
1039 my $in = new IO::File "<$in_file" ;
1041 ok &$Func($in, $out_file, Append => $append, @opts), ' Uncompressed ok' ;
1043 ok -e $out_file, " Created output file";
1044 my $content = readFile($out_file) ;
1046 is $keep_comp, $comp, " Input buffer not changed" ;
1047 is $content, $expected, " Uncompressed matches original";
1051 title "$TopType - From Handle to Handle, Append($append)" ;
1053 my $lex = new LexFile(my $in_file, my $out_file) ;
1056 writeFile($out_file, $incumbent) ;
1057 $out = new IO::File "+< $out_file" ;
1060 ok ! -e $out_file, " Output file does not exist" ;
1061 $out = new IO::File "> $out_file" ;
1063 isa_ok $out, 'IO::File', ' $out' ;
1065 writeFile($in_file, $comp);
1066 my $in = new IO::File "<$in_file" ;
1068 ok &$Func($in, $out, Append => $append, AutoClose => 1, @opts), ' Uncompressed ok' ;
1070 ok -e $out_file, " Created output file";
1071 my $content = readFile($out_file) ;
1073 is $keep_comp, $comp, " Input buffer not changed" ;
1074 is $content, $expected, " Uncompressed matches original";
1078 title "$TopType - From Filename to Buffer, Append($append)" ;
1080 my $lex = new LexFile(my $in_file) ;
1081 writeFile($in_file, $comp);
1082 my $in = new IO::File "<$in_file" ;
1085 $output = $incumbent if $append ;
1087 ok &$Func($in, \$output, Append => $append, @opts), ' Uncompressed ok' ;
1089 is $keep_comp, $comp, " Input buffer not changed" ;
1090 is $output, $expected, " Uncompressed matches original";
1094 title "$TopType - From stdin (via '-') to Buffer content, Append($append) " ;
1096 my $lex = new LexFile(my $in_file) ;
1097 writeFile($in_file, $comp);
1099 open(SAVEIN, "<&STDIN");
1100 my $dummy = fileno SAVEIN ;
1101 ok open(STDIN, "<$in_file"), " redirect STDIN";
1104 $output = $incumbent if $append ;
1106 ok &$Func('-', \$output, Append => $append, @opts), ' Uncompressed ok'
1109 open(STDIN, "<&SAVEIN");
1111 is $keep_comp, $comp, " Input buffer not changed" ;
1112 is $output, $expected, " Uncompressed matches original";
1117 title "$TopType - From Handle to Buffer, InputLength" ;
1119 my $lex = new LexFile(my $in_file, my $out_file) ;
1122 my $expected = $buffer ;
1123 my $appended = 'appended';
1124 my $len_appended = length $appended;
1125 writeFile($in_file, $comp . $appended . $comp . $appended) ;
1126 my $in = new IO::File "<$in_file" ;
1128 ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp, @opts), ' Uncompressed ok' ;
1130 is $out, $expected, " Uncompressed matches original";
1133 is $in->read($buff, $len_appended), $len_appended, " Length of Appended data ok";
1134 is $buff, $appended, " Appended data ok";
1137 ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp, @opts), ' Uncompressed ok' ;
1139 is $out, $expected, " Uncompressed matches original";
1142 is $in->read($buff, $len_appended), $len_appended, " Length of Appended data ok";
1143 is $buff, $appended, " Appended data ok";
1146 for my $stdin ('-', *STDIN) # , \*STDIN)
1148 title "$TopType - From stdin (via $stdin) to Buffer content, InputLength" ;
1150 my $lex = new LexFile my $in_file ;
1151 my $expected = $buffer ;
1152 my $appended = 'appended';
1153 my $len_appended = length $appended;
1154 writeFile($in_file, $comp . $appended ) ;
1156 open(SAVEIN, "<&STDIN");
1157 my $dummy = fileno SAVEIN ;
1158 ok open(STDIN, "<$in_file"), " redirect STDIN";
1162 ok &$Func($stdin, \$output, Transparent => 0, InputLength => length $comp, @opts), ' Uncompressed ok'
1166 is read(STDIN, $buff, $len_appended), $len_appended, " Length of Appended data ok";
1168 is $output, $expected, " Uncompressed matches original";
1169 is $buff, $appended, " Appended data ok";
1171 open(STDIN, "<&SAVEIN");
1175 foreach my $bit ($UncompressClass,
1176 'IO::Uncompress::AnyUncompress',
1179 # TODO -- Add Append mode tests
1181 my $Error = getErrorRef($bit);
1182 my $Func = getTopFuncRef($bit);
1183 my $TopType = getTopFuncName($bit);
1185 my $buffer = "abcde" ;
1186 my $keep_orig = $buffer;
1188 my $null = compressBuffer(getTopFuncName($UncompressClass), "") ;
1189 my $undef = compressBuffer(getTopFuncName($UncompressClass), undef) ;
1190 my $comp = compressBuffer(getTopFuncName($UncompressClass), $buffer) ;
1191 my $keep_comp = $comp;
1194 @opts = (RawInflate => 1)
1195 if $bit eq 'IO::Uncompress::AnyUncompress';
1197 my $incumbent = "incumbent data" ;
1199 my $lex = new LexFile(my $file1, my $file2) ;
1201 writeFile($file1, compressBuffer(getTopFuncName($UncompressClass),"data1"));
1202 writeFile($file2, compressBuffer(getTopFuncName($UncompressClass),"data2"));
1204 my $of = new IO::File "<$file1" ;
1205 ok $of, " Created output filehandle" ;
1207 #my @input = ($file2, \$undef, \$null, \$comp, $of) ;
1208 #my @expected = ('data2', '', '', 'abcde', 'data1');
1209 my @input = ($file1, $file2);
1210 my @expected = ('data1', 'data2');
1215 title "$TopType - From ArrayRef to Buffer" ;
1218 ok &$Func(\@input, \$output, AutoClose => 0, @opts), ' UnCompressed ok' ;
1220 is $output, join('', @expected)
1224 title "$TopType - From ArrayRef to Filename" ;
1226 my $lex = new LexFile my $output;
1227 $of->open("<$file1") ;
1229 ok &$Func(\@input, $output, AutoClose => 0, @opts), ' UnCompressed ok' ;
1231 is readFile($output), join('', @expected)
1235 title "$TopType - From ArrayRef to Filehandle" ;
1237 my $lex = new LexFile my $output;
1238 my $fh = new IO::File ">$output" ;
1239 $of->open("<$file1") ;
1241 ok &$Func(\@input, $fh, AutoClose => 0, @opts), ' UnCompressed ok' ;
1244 is readFile($output), join('', @expected)
1248 title "$TopType - From Array Ref to Array Ref" ;
1250 my @output = (\'first') ;
1251 $of->open("<$file1") ;
1252 ok &$Func(\@input, \@output, AutoClose => 0, @opts), ' UnCompressed ok' ;
1254 is_deeply \@input, \@keep, " Input array not changed" ;
1255 is_deeply [map { defined $$_ ? $$_ : "" } @output],
1256 ['first', @expected],
1257 " Got Expected uncompressed data";
1262 foreach my $bit ($UncompressClass,
1263 'IO::Uncompress::AnyUncompress',
1266 # TODO -- Add Append mode tests
1268 my $Error = getErrorRef($bit);
1269 my $Func = getTopFuncRef($bit);
1270 my $TopType = getTopFuncName($bit);
1272 my $tmpDir1 = 'tmpdir1';
1273 my $tmpDir2 = 'tmpdir2';
1274 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
1276 mkdir $tmpDir1, 0777;
1277 mkdir $tmpDir2, 0777;
1280 @opts = (RawInflate => 1)
1281 if $bit eq 'IO::Uncompress::AnyUncompress';
1283 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
1284 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
1286 my @files = map { "$tmpDir1/$_.tmp" } qw( a1 a2 a3) ;
1287 foreach (@files) { writeFile($_, compressBuffer(getTopFuncName($UncompressClass), "abc $_")) }
1289 my @expected = map { "abc $_" } @files ;
1290 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
1293 title "$TopType - From FileGlob to FileGlob" ;
1295 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>", @opts), ' UnCompressed ok'
1298 my @copy = @expected;
1299 for my $file (@outFiles)
1301 is readFile($file), shift @copy, " got expected from $file" ;
1304 is @copy, 0, " got all files";
1308 title "$TopType - From FileGlob to Arrayref" ;
1310 my @output = (\'first');
1311 ok &$Func("<$tmpDir1/a*.tmp>" => \@output, @opts), ' UnCompressed ok'
1314 my @copy = ('first', @expected);
1315 for my $data (@output)
1317 is $$data, shift @copy, " got expected data" ;
1320 is @copy, 0, " got all files";
1324 title "$TopType - From FileGlob to Buffer" ;
1327 ok &$Func("<$tmpDir1/a*.tmp>" => \$output, @opts), ' UnCompressed ok'
1330 is $output, join('', @expected), " got expected uncompressed data";
1334 title "$TopType - From FileGlob to Filename" ;
1336 my $lex = new LexFile my $output ;
1337 ok ! -e $output, " $output does not exist" ;
1338 ok &$Func("<$tmpDir1/a*.tmp>" => $output, @opts), ' UnCompressed ok'
1341 ok -e $output, " $output does exist" ;
1342 is readFile($output), join('', @expected), " got expected uncompressed data";
1346 title "$TopType - From FileGlob to Filehandle" ;
1348 my $output = 'abc' ;
1349 my $lex = new LexFile $output ;
1350 my $fh = new IO::File ">$output" ;
1351 ok &$Func("<$tmpDir1/a*.tmp>" => $fh, AutoClose => 1, @opts), ' UnCompressed ok'
1354 ok -e $output, " $output does exist" ;
1355 is readFile($output), join('', @expected), " got expected uncompressed data";
1360 foreach my $TopType ($CompressClass
1361 # TODO -- add the inflate classes
1364 my $Error = getErrorRef($TopType);
1365 my $Func = getTopFuncRef($TopType);
1366 my $Name = getTopFuncName($TopType);
1368 title "More write tests" ;
1370 my $lex = new LexFile(my $file1, my $file2, my $file3) ;
1372 writeFile($file1, "F1");
1373 writeFile($file2, "F2");
1374 writeFile($file3, "F3");
1377 # [ '[\"ab", \"cd"]', "abcd" ],
1379 # [ '[\"a", $fh1, \"bc"]', "aF1bc"],
1383 # foreach my $data (@data)
1385 # my ($send, $get) = @$data ;
1387 # my $fh1 = new IO::File "< $file1" ;
1388 # my $fh2 = new IO::File "< $file2" ;
1389 # my $fh3 = new IO::File "< $file3" ;
1393 # eval "\$copy = $send";
1395 # ok &$Func($copy, \$Answer), " $Name ok";
1397 # my $got = anyUncompress(\$Answer);
1398 # is $got, $get, " got expected output" ;
1399 # ok ! $$Error, " no error"
1400 # or diag "Error is $$Error";
1404 title "Array Input Error tests" ;
1407 [ '[]', "empty array reference"],
1408 [ '[[]]', "unknown input parameter"],
1409 [ '[[[]]]', "unknown input parameter"],
1410 [ '[[\"ab"], [\"cd"]]', "unknown input parameter"],
1411 [ '[\""]', "not a filename"],
1412 [ '[\undef]', "not a filename"],
1413 [ '[\"abcd"]', "not a filename"],
1414 [ '[\&xx]', "unknown input parameter"],
1415 [ '[$fh2]', "not a filename"],
1419 foreach my $data (@data)
1421 my ($send, $get) = @$data ;
1423 my $fh1 = new IO::File "< $file1" ;
1424 my $fh2 = new IO::File "< $file2" ;
1425 my $fh3 = new IO::File "< $file3" ;
1429 eval "\$copy = $send";
1432 eval { $a = &$Func($copy, \$Answer) };
1433 ok ! $a, " $Name fails";
1435 is $$Error, $get, " got error message";
1445 foreach my $send (@data)
1449 eval "\$copy = $send";
1451 eval { &$Func($copy, \$Answer) } ;
1452 like $@, mkErr("^$TopFuncName: input filename is undef or null string"),
1453 " got error message";
1460 # TODO add more error cases