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);
232 for my $append ( 1, 0 )
235 $already = 'abcde' if $append ;
237 for my $buffer ( undef, '', "abcde" )
240 my $disp_content = defined $buffer ? $buffer : '<undef>' ;
243 my $out_file = "abcde.out";
244 my $in_file = "abcde.in";
247 title "$TopType - From Buff to Buff content '$disp_content' Append $append" ;
249 my $output = $already;
250 ok &$Func(\$buffer, \$output, Append => $append), ' Compressed ok' ;
252 is $keep, $buffer, " Input buffer not changed" ;
253 my $got = anyUncompress(\$output, $already);
254 $got = undef if ! defined $buffer && $got eq '' ;
255 is $got, $buffer, " Uncompressed matches original";
260 title "$TopType - From Buff to Array Ref content '$disp_content' Append $append" ;
262 my @output = ('first') ;
263 ok &$Func(\$buffer, \@output, Append => $append), ' Compressed ok' ;
265 is $output[0], 'first', " Array[0] unchanged";
266 is $keep, $buffer, " Input buffer not changed" ;
267 my $got = anyUncompress($output[1]);
268 $got = undef if ! defined $buffer && $got eq '' ;
269 is $got, $buffer, " Uncompressed matches original";
273 title "$TopType - From Array Ref to Array Ref content '$disp_content' Append $append" ;
275 my $lex = new LexFile my $in_file ;
276 writeFile($in_file, $buffer);
277 my @output = ('first') ;
278 my @input = ($in_file);
279 ok &$Func(\@input, \@output, Append => $append), ' Compressed ok' ;
281 is $output[0], 'first', " Array[0] unchanged";
282 my $got = anyUncompress($output[1]);
283 $got = undef if ! defined $buffer && $got eq '' ;
284 is $got, $buffer, " Uncompressed matches original";
288 title "$TopType - From Buff to Filename content '$disp_content' Append $append" ;
290 my $lex = new LexFile my $out_file ;
291 ok ! -e $out_file, " Output file does not exist";
292 writeFile($out_file, $already);
294 ok &$Func(\$buffer, $out_file, Append => $append), ' Compressed ok' ;
296 ok -e $out_file, " Created output file";
297 my $got = anyUncompress($out_file, $already);
298 $got = undef if ! defined $buffer && $got eq '' ;
299 is $got, $buffer, " Uncompressed matches original";
303 title "$TopType - From Buff to Handle content '$disp_content' Append $append" ;
305 my $lex = new LexFile my $out_file ;
307 ok ! -e $out_file, " Output file does not exist";
308 writeFile($out_file, $already);
309 my $of = new IO::File ">>$out_file" ;
310 ok $of, " Created output filehandle" ;
312 ok &$Func(\$buffer, $of, AutoClose => 1, Append => $append), ' Compressed ok' ;
314 ok -e $out_file, " Created output file";
315 my $got = anyUncompress($out_file, $already);
316 $got = undef if ! defined $buffer && $got eq '' ;
317 is $got, $buffer, " Uncompressed matches original";
322 title "$TopType - From Filename to Filename content '$disp_content' Append $append" ;
324 my $lex = new LexFile(my $in_file, my $out_file) ;
325 writeFile($in_file, $buffer);
327 ok ! -e $out_file, " Output file does not exist";
328 writeFile($out_file, $already);
330 ok &$Func($in_file => $out_file, Append => $append), ' Compressed ok' ;
332 ok -e $out_file, " Created output file";
333 my $got = anyUncompress($out_file, $already);
334 $got = undef if ! defined $buffer && $got eq '' ;
335 is $got, $buffer, " Uncompressed matches original";
340 title "$TopType - From Filename to Handle content '$disp_content' Append $append" ;
342 my $lex = new LexFile(my $in_file, my $out_file) ;
343 writeFile($in_file, $buffer);
345 ok ! -e $out_file, " Output file does not exist";
346 writeFile($out_file, $already);
347 my $out = new IO::File ">>$out_file" ;
349 ok &$Func($in_file, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
351 ok -e $out_file, " Created output file";
352 my $got = anyUncompress($out_file, $already);
353 $got = undef if ! defined $buffer && $got eq '' ;
354 is $got, $buffer, " Uncompressed matches original";
359 title "$TopType - From Filename to Buffer content '$disp_content' Append $append" ;
361 my $lex = new LexFile(my $in_file, my $out_file) ;
362 writeFile($in_file, $buffer);
366 ok &$Func($in_file => \$out, Append => $append), ' Compressed ok' ;
368 my $got = anyUncompress(\$out, $already);
369 $got = undef if ! defined $buffer && $got eq '' ;
370 is $got, $buffer, " Uncompressed matches original";
375 title "$TopType - From Handle to Filename content '$disp_content' Append $append" ;
377 my $lex = new LexFile(my $in_file, my $out_file) ;
378 writeFile($in_file, $buffer);
379 my $in = new IO::File "<$in_file" ;
381 ok ! -e $out_file, " Output file does not exist";
382 writeFile($out_file, $already);
384 ok &$Func($in, $out_file, Append => $append), ' Compressed ok'
385 or diag "error is $$Error" ;
387 ok -e $out_file, " Created output file";
388 my $got = anyUncompress($out_file, $already);
389 $got = undef if ! defined $buffer && $got eq '' ;
390 is $buffer, $got, " Uncompressed matches original";
395 title "$TopType - From Handle to Handle content '$disp_content' Append $append" ;
397 my $lex = new LexFile(my $in_file, my $out_file) ;
398 writeFile($in_file, $buffer);
399 my $in = new IO::File "<$in_file" ;
401 ok ! -e $out_file, " Output file does not exist";
402 writeFile($out_file, $already);
403 my $out = new IO::File ">>$out_file" ;
405 ok &$Func($in, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
407 ok -e $out_file, " Created output file";
408 my $got = anyUncompress($out_file, $already);
409 $got = undef if ! defined $buffer && $got eq '' ;
410 is $buffer, $got, " Uncompressed matches original";
415 title "$TopType - From Handle to Buffer content '$disp_content' Append $append" ;
417 my $lex = new LexFile(my $in_file, my $out_file) ;
418 writeFile($in_file, $buffer);
419 my $in = new IO::File "<$in_file" ;
423 ok &$Func($in, \$out, Append => $append), ' Compressed ok' ;
425 my $got = anyUncompress(\$out, $already);
426 $got = undef if ! defined $buffer && $got eq '' ;
427 is $buffer, $got, " Uncompressed matches original";
432 title "$TopType - From stdin (via '-') to Buffer content '$disp_content' Append $append" ;
434 my $lex = new LexFile(my $in_file, my $out_file) ;
435 writeFile($in_file, $buffer);
437 open(SAVEIN, "<&STDIN");
438 my $dummy = fileno SAVEIN ;
439 ok open(STDIN, "<$in_file"), " redirect STDIN";
443 ok &$Func('-', \$out, Append => $append), ' Compressed ok'
446 open(STDIN, "<&SAVEIN");
448 my $got = anyUncompress(\$out, $already);
449 $got = undef if ! defined $buffer && $got eq '' ;
450 is $buffer, $got, " Uncompressed matches original";
458 foreach my $bit ($CompressClass)
460 my $Error = getErrorRef($bit);
461 my $Func = getTopFuncRef($bit);
462 my $TopType = getTopFuncName($bit);
464 my $TopTypeInverse = getInverse($bit);
465 my $FuncInverse = getTopFuncRef($TopTypeInverse);
467 my $lex = new LexFile(my $file1, my $file2) ;
469 writeFile($file1, "data1");
470 writeFile($file2, "data2");
471 my $of = new IO::File "<$file1" ;
472 ok $of, " Created output filehandle" ;
474 #my @input = ( undef, "", $file2, \undef, \'', \"abcde", $of) ;
475 #my @expected = ("", "", $file2, "", "", "abcde", "data1");
476 #my @uexpected = ("", "", "data2", "", "", "abcde", "data1");
477 #my @input = ( $file2, \"abcde", $of) ;
478 #my @expected = ( $file2, "abcde", "data1");
479 #my @uexpected = ("data2", "abcde", "data1");
481 my @input = ( $file1, $file2) ;
482 #my @expected = ( $file1, $file2);
483 my @expected = ("data1", "data2");
484 my @uexpected = ("data1", "data2");
489 title "$TopType - From Array Ref to Array Ref" ;
491 my @output = ('first') ;
492 ok &$Func(\@input, \@output, AutoClose => 0), ' Compressed ok' ;
494 is $output[0], 'first', " Array[0] unchanged";
496 is_deeply \@input, \@keep, " Input array not changed" ;
497 my @got = shift @output;
498 foreach (@output) { push @got, anyUncompress($_) }
500 is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
504 foreach my $ms (1, 0)
507 title "$TopType - From Array Ref to Buffer, MultiStream $ms" ;
509 # rewind the filehandle
510 $of->open("<$file1") ;
513 ok &$Func(\@input, \$output, MultiStream => $ms, AutoClose => 0), ' Compressed ok'
516 my $got = anyUncompress([ \$output, MultiStream => $ms ]);
518 is $got, join('', @uexpected), " Got Expected uncompressed data";
519 my @headers = getHeaders(\$output);
520 is @headers, $ms ? @input : 1, " Header count ok";
524 title "$TopType - From Array Ref to Filename, MultiStream $ms" ;
526 my $lex = new LexFile( my $file3) ;
528 # rewind the filehandle
529 $of->open("<$file1") ;
532 ok &$Func(\@input, $file3, MultiStream => $ms, AutoClose => 0), ' Compressed ok' ;
534 my $got = anyUncompress([ $file3, MultiStream => $ms ]);
536 is $got, join('', @uexpected), " Got Expected uncompressed data";
537 my @headers = getHeaders($file3);
538 is @headers, $ms ? @input : 1, " Header count ok";
542 title "$TopType - From Array Ref to Filehandle, MultiStream $ms" ;
544 my $lex = new LexFile(my $file3) ;
546 my $fh3 = new IO::File ">$file3";
548 # rewind the filehandle
549 $of->open("<$file1") ;
552 ok &$Func(\@input, $fh3, MultiStream => $ms, AutoClose => 0), ' Compressed ok' ;
556 my $got = anyUncompress([ $file3, MultiStream => $ms ]);
558 is $got, join('', @uexpected), " Got Expected uncompressed data";
559 my @headers = getHeaders($file3);
560 is @headers, $ms ? @input : 1, " Header count ok";
565 # foreach my $bit ($CompressClass)
567 # my $Error = getErrorRef($bit);
568 # my $Func = getTopFuncRef($bit);
569 # my $TopType = getTopFuncName($bit);
571 # my $TopTypeInverse = getInverse($bit);
572 # my $FuncInverse = getTopFuncRef($TopTypeInverse);
574 # my @inFiles = map { "in$_.tmp" } 1..4;
575 # my @outFiles = map { "out$_.tmp" } 1..4;
576 # my $lex = new LexFile(@inFiles, @outFiles);
578 # writeFile($_, "data $_") foreach @inFiles ;
581 # title "$TopType - Hash Ref: to filename" ;
584 # ok &$Func( { $inFiles[0] => $outFiles[0],
585 # $inFiles[1] => $outFiles[1],
586 # $inFiles[2] => $outFiles[2] } ), ' Compressed ok' ;
590 # my $got = anyUncompress($outFiles[$_]);
591 # is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
596 # title "$TopType - Hash Ref: to buffer" ;
599 # ok &$Func( { $inFiles[0] => \$buffer[0],
600 # $inFiles[1] => \$buffer[1],
601 # $inFiles[2] => \$buffer[2] } ), ' Compressed ok' ;
605 # my $got = anyUncompress(\$buffer[$_]);
606 # is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
611 # title "$TopType - Hash Ref: to undef" ;
614 # my %hash = ( $inFiles[0] => undef,
615 # $inFiles[1] => undef,
616 # $inFiles[2] => undef,
619 # ok &$Func( \%hash ), ' Compressed ok' ;
621 # foreach (keys %hash)
623 # my $got = anyUncompress(\$hash{$_});
624 # is $got, "data $_", " Uncompressed $_ matches original";
629 # title "$TopType - Filename to Hash Ref" ;
632 # ok &$Func( $inFiles[0] => \%output), ' Compressed ok' ;
634 # is keys %output, 1, " one pair in hash" ;
635 # my ($k, $v) = each %output;
636 # is $k, $inFiles[0], " key is '$inFiles[0]'";
637 # my $got = anyUncompress($v);
638 # is $got, "data $inFiles[0]", " Uncompressed matches original";
642 # title "$TopType - File Glob to Hash Ref" ;
645 # ok &$Func( '<in*.tmp>' => \%output), ' Compressed ok' ;
647 # is keys %output, 4, " four pairs in hash" ;
648 # foreach my $fil (@inFiles)
650 # ok exists $output{$fil}, " key '$fil' exists" ;
651 # my $got = anyUncompress($output{$fil});
652 # is $got, "data $fil", " Uncompressed matches original";
659 # foreach my $bit ($CompressClass)
661 # my $Error = getErrorRef($bit);
662 # my $Func = getTopFuncRef($bit);
663 # my $TopType = getTopFuncName($bit);
665 # my $TopTypeInverse = getInverse($bit);
666 # my $FuncInverse = getTopFuncRef($TopTypeInverse);
668 # my @inFiles = map { "in$_.tmp" } 1..4;
669 # my @outFiles = map { "out$_.tmp" } 1..4;
670 # my $lex = new LexFile(@inFiles, @outFiles);
672 # writeFile($_, "data $_") foreach @inFiles ;
678 # # title "$TopType - Hash Ref to Array Ref" ;
680 # # my @output = ('first') ;
681 # # ok &$Func( { \@input, \@output } , AutoClose => 0), ' Compressed ok' ;
683 # # is $output[0], 'first', " Array[0] unchanged";
685 # # is_deeply \@input, \@keep, " Input array not changed" ;
686 # # my @got = shift @output;
687 # # foreach (@output) { push @got, anyUncompress($_) }
689 # # is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
695 # # title "$TopType - From Array Ref to Buffer" ;
697 # # # rewind the filehandle
698 # # $of->open("<$file1") ;
701 # # ok &$Func(\@input, \$output, AutoClose => 0), ' Compressed ok' ;
703 # # my $got = anyUncompress(\$output);
705 # # is $got, join('', @expected), " Got Expected uncompressed data";
710 # # title "$TopType - From Array Ref to Filename" ;
712 # # my ($file3) = ("file3");
713 # # my $lex = new LexFile($file3) ;
715 # # # rewind the filehandle
716 # # $of->open("<$file1") ;
719 # # ok &$Func(\@input, $file3, AutoClose => 0), ' Compressed ok' ;
721 # # my $got = anyUncompress($file3);
723 # # is $got, join('', @expected), " Got Expected uncompressed data";
728 # # title "$TopType - From Array Ref to Filehandle" ;
730 # # my ($file3) = ("file3");
731 # # my $lex = new LexFile($file3) ;
733 # # my $fh3 = new IO::File ">$file3";
735 # # # rewind the filehandle
736 # # $of->open("<$file1") ;
739 # # ok &$Func(\@input, $fh3, AutoClose => 0), ' Compressed ok' ;
743 # # my $got = anyUncompress($file3);
745 # # is $got, join('', @expected), " Got Expected uncompressed data";
749 foreach my $bit ($CompressClass
752 my $Error = getErrorRef($bit);
753 my $Func = getTopFuncRef($bit);
754 my $TopType = getTopFuncName($bit);
756 for my $files ( [qw(a1)], [qw(a1 a2 a3)] )
759 my $tmpDir1 = 'tmpdir1';
760 my $tmpDir2 = 'tmpdir2';
761 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
763 mkdir $tmpDir1, 0777;
764 mkdir $tmpDir2, 0777;
766 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
767 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
769 my @files = map { "$tmpDir1/$_.tmp" } @$files ;
770 foreach (@files) { writeFile($_, "abc $_") }
772 my @expected = map { "abc $_" } @files ;
773 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
776 title "$TopType - From FileGlob to FileGlob files [@$files]" ;
778 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>"), ' Compressed ok'
781 my @copy = @expected;
782 for my $file (@outFiles)
784 is anyUncompress($file), shift @copy, " got expected from $file" ;
787 is @copy, 0, " got all files";
791 title "$TopType - From FileGlob to Array files [@$files]" ;
793 my @buffer = ('first') ;
794 ok &$Func("<$tmpDir1/a*.tmp>" => \@buffer), ' Compressed ok'
797 is shift @buffer, 'first';
799 my @copy = @expected;
800 for my $buffer (@buffer)
802 is anyUncompress($buffer), shift @copy, " got expected " ;
805 is @copy, 0, " got all files";
808 foreach my $ms (0, 1)
811 title "$TopType - From FileGlob to Buffer files [@$files], MS $ms" ;
814 ok &$Func("<$tmpDir1/a*.tmp>" => \$buffer,
815 MultiStream => $ms), ' Compressed ok'
820 my $got = anyUncompress([ \$buffer, MultiStream => $ms ]);
822 is $got, join("", @expected), " got expected" ;
823 my @headers = getHeaders(\$buffer);
824 is @headers, $ms ? @files : 1, " Header count ok";
828 title "$TopType - From FileGlob to Filename files [@$files], MS $ms" ;
830 my $filename = "abcde";
831 my $lex = new LexFile($filename) ;
833 ok &$Func("<$tmpDir1/a*.tmp>" => $filename,
834 MultiStream => $ms), ' Compressed ok'
839 my $got = anyUncompress([$filename, MultiStream => $ms]);
841 is $got, join("", @expected), " got expected" ;
842 my @headers = getHeaders($filename);
843 is @headers, $ms ? @files : 1, " Header count ok";
847 title "$TopType - From FileGlob to Filehandle files [@$files], MS $ms" ;
849 my $filename = "abcde";
850 my $lex = new LexFile($filename) ;
851 my $fh = new IO::File ">$filename";
853 ok &$Func("<$tmpDir1/a*.tmp>" => $fh,
854 MultiStream => $ms, AutoClose => 1), ' Compressed ok'
859 my $got = anyUncompress([$filename, MultiStream => $ms]);
861 is $got, join("", @expected), " got expected" ;
862 my @headers = getHeaders($filename);
863 is @headers, $ms ? @files : 1, " Header count ok";
870 foreach my $bit ($UncompressClass,
871 'IO::Uncompress::AnyUncompress',
874 my $Error = getErrorRef($bit);
875 my $Func = getTopFuncRef($bit);
876 my $TopType = getTopFuncName($bit);
878 my $buffer = "abcde" ;
879 my $buffer2 = "ABCDE" ;
880 my $keep_orig = $buffer;
882 my $comp = compressBuffer(getTopFuncName($UncompressClass), $buffer) ;
883 my $comp2 = compressBuffer(getTopFuncName($UncompressClass), $buffer2) ;
884 my $keep_comp = $comp;
886 my $incumbent = "incumbent data" ;
888 for my $append (0, 1)
890 my $expected = $buffer ;
891 $expected = $incumbent . $buffer if $append ;
894 title "$TopType - From Buff to Buff, Append($append)" ;
897 $output = $incumbent if $append ;
898 ok &$Func(\$comp, \$output, Append => $append), ' Uncompressed ok' ;
900 is $keep_comp, $comp, " Input buffer not changed" ;
901 is $output, $expected, " Uncompressed matches original";
905 title "$TopType - From Buff to Array, Append($append)" ;
907 my @output = ('first');
908 #$output = $incumbent if $append ;
909 ok &$Func(\$comp, \@output, Append => $append), ' Uncompressed ok' ;
911 is $keep_comp, $comp, " Input buffer not changed" ;
912 is $output[0], 'first', " Uncompressed matches original";
913 is ${ $output[1] }, $buffer, " Uncompressed matches original"
915 is @output, 2, " only 2 elements in the array" ;
919 title "$TopType - From Buff to Filename, Append($append)" ;
921 my $lex = new LexFile(my $out_file) ;
923 { writeFile($out_file, $incumbent) }
925 { ok ! -e $out_file, " Output file does not exist" }
927 ok &$Func(\$comp, $out_file, Append => $append), ' Uncompressed ok' ;
929 ok -e $out_file, " Created output file";
930 my $content = readFile($out_file) ;
932 is $keep_comp, $comp, " Input buffer not changed" ;
933 is $content, $expected, " Uncompressed matches original";
937 title "$TopType - From Buff to Handle, Append($append)" ;
939 my $lex = new LexFile(my $out_file) ;
942 writeFile($out_file, $incumbent) ;
943 $of = new IO::File "+< $out_file" ;
946 ok ! -e $out_file, " Output file does not exist" ;
947 $of = new IO::File "> $out_file" ;
949 isa_ok $of, 'IO::File', ' $of' ;
951 ok &$Func(\$comp, $of, Append => $append, AutoClose => 1), ' Uncompressed ok' ;
953 ok -e $out_file, " Created output file";
954 my $content = readFile($out_file) ;
956 is $keep_comp, $comp, " Input buffer not changed" ;
957 is $content, $expected, " Uncompressed matches original";
961 title "$TopType - From Filename to Filename, Append($append)" ;
963 my $lex = new LexFile(my $in_file, my $out_file) ;
965 { writeFile($out_file, $incumbent) }
967 { ok ! -e $out_file, " Output file does not exist" }
969 writeFile($in_file, $comp);
971 ok &$Func($in_file, $out_file, Append => $append), ' Uncompressed ok' ;
973 ok -e $out_file, " Created output file";
974 my $content = readFile($out_file) ;
976 is $keep_comp, $comp, " Input buffer not changed" ;
977 is $content, $expected, " Uncompressed matches original";
981 title "$TopType - From Filename to Handle, Append($append)" ;
983 my $lex = new LexFile(my $in_file, my $out_file) ;
986 writeFile($out_file, $incumbent) ;
987 $out = new IO::File "+< $out_file" ;
990 ok ! -e $out_file, " Output file does not exist" ;
991 $out = new IO::File "> $out_file" ;
993 isa_ok $out, 'IO::File', ' $out' ;
995 writeFile($in_file, $comp);
997 ok &$Func($in_file, $out, Append => $append, AutoClose => 1), ' Uncompressed ok' ;
999 ok -e $out_file, " Created output file";
1000 my $content = readFile($out_file) ;
1002 is $keep_comp, $comp, " Input buffer not changed" ;
1003 is $content, $expected, " Uncompressed matches original";
1007 title "$TopType - From Filename to Buffer, Append($append)" ;
1009 my $lex = new LexFile(my $in_file) ;
1010 writeFile($in_file, $comp);
1013 $output = $incumbent if $append ;
1015 ok &$Func($in_file, \$output, Append => $append), ' Uncompressed ok' ;
1017 is $keep_comp, $comp, " Input buffer not changed" ;
1018 is $output, $expected, " Uncompressed matches original";
1022 title "$TopType - From Handle to Filename, Append($append)" ;
1024 my $lex = new LexFile(my $in_file, my $out_file) ;
1026 { writeFile($out_file, $incumbent) }
1028 { ok ! -e $out_file, " Output file does not exist" }
1030 writeFile($in_file, $comp);
1031 my $in = new IO::File "<$in_file" ;
1033 ok &$Func($in, $out_file, Append => $append), ' Uncompressed ok' ;
1035 ok -e $out_file, " Created output file";
1036 my $content = readFile($out_file) ;
1038 is $keep_comp, $comp, " Input buffer not changed" ;
1039 is $content, $expected, " Uncompressed matches original";
1043 title "$TopType - From Handle to Handle, Append($append)" ;
1045 my $lex = new LexFile(my $in_file, my $out_file) ;
1048 writeFile($out_file, $incumbent) ;
1049 $out = new IO::File "+< $out_file" ;
1052 ok ! -e $out_file, " Output file does not exist" ;
1053 $out = new IO::File "> $out_file" ;
1055 isa_ok $out, 'IO::File', ' $out' ;
1057 writeFile($in_file, $comp);
1058 my $in = new IO::File "<$in_file" ;
1060 ok &$Func($in, $out, Append => $append, AutoClose => 1), ' Uncompressed ok' ;
1062 ok -e $out_file, " Created output file";
1063 my $content = readFile($out_file) ;
1065 is $keep_comp, $comp, " Input buffer not changed" ;
1066 is $content, $expected, " Uncompressed matches original";
1070 title "$TopType - From Filename to Buffer, Append($append)" ;
1072 my $lex = new LexFile(my $in_file) ;
1073 writeFile($in_file, $comp);
1074 my $in = new IO::File "<$in_file" ;
1077 $output = $incumbent if $append ;
1079 ok &$Func($in, \$output, Append => $append), ' Uncompressed ok' ;
1081 is $keep_comp, $comp, " Input buffer not changed" ;
1082 is $output, $expected, " Uncompressed matches original";
1086 title "$TopType - From stdin (via '-') to Buffer content, Append($append) " ;
1088 my $lex = new LexFile(my $in_file) ;
1089 writeFile($in_file, $comp);
1091 open(SAVEIN, "<&STDIN");
1092 my $dummy = fileno SAVEIN ;
1093 ok open(STDIN, "<$in_file"), " redirect STDIN";
1096 $output = $incumbent if $append ;
1098 ok &$Func('-', \$output, Append => $append), ' Uncompressed ok'
1101 open(STDIN, "<&SAVEIN");
1103 is $keep_comp, $comp, " Input buffer not changed" ;
1104 is $output, $expected, " Uncompressed matches original";
1109 title "$TopType - From Handle to Buffer, InputLength" ;
1111 my $lex = new LexFile(my $in_file, my $out_file) ;
1114 my $expected = $buffer ;
1115 my $appended = 'appended';
1116 my $len_appended = length $appended;
1117 writeFile($in_file, $comp . $appended . $comp . $appended) ;
1118 my $in = new IO::File "<$in_file" ;
1120 ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp), ' Uncompressed ok' ;
1122 is $out, $expected, " Uncompressed matches original";
1125 is $in->read($buff, $len_appended), $len_appended, " Length of Appended data ok";
1126 is $buff, $appended, " Appended data ok";
1129 ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp), ' Uncompressed ok' ;
1131 is $out, $expected, " Uncompressed matches original";
1134 is $in->read($buff, $len_appended), $len_appended, " Length of Appended data ok";
1135 is $buff, $appended, " Appended data ok";
1138 for my $stdin ('-', *STDIN) # , \*STDIN)
1140 title "$TopType - From stdin (via $stdin) to Buffer content, InputLength" ;
1142 my $lex = new LexFile my $in_file ;
1143 my $expected = $buffer ;
1144 my $appended = 'appended';
1145 my $len_appended = length $appended;
1146 writeFile($in_file, $comp . $appended ) ;
1148 open(SAVEIN, "<&STDIN");
1149 my $dummy = fileno SAVEIN ;
1150 ok open(STDIN, "<$in_file"), " redirect STDIN";
1154 ok &$Func($stdin, \$output, Transparent => 0, InputLength => length $comp), ' Uncompressed ok'
1158 is read(STDIN, $buff, $len_appended), $len_appended, " Length of Appended data ok";
1160 is $output, $expected, " Uncompressed matches original";
1161 is $buff, $appended, " Appended data ok";
1163 open(STDIN, "<&SAVEIN");
1167 foreach my $bit ($UncompressClass,
1168 'IO::Uncompress::AnyUncompress',
1171 # TODO -- Add Append mode tests
1173 my $Error = getErrorRef($bit);
1174 my $Func = getTopFuncRef($bit);
1175 my $TopType = getTopFuncName($bit);
1177 my $buffer = "abcde" ;
1178 my $keep_orig = $buffer;
1180 my $null = compressBuffer(getTopFuncName($UncompressClass), "") ;
1181 my $undef = compressBuffer(getTopFuncName($UncompressClass), undef) ;
1182 my $comp = compressBuffer(getTopFuncName($UncompressClass), $buffer) ;
1183 my $keep_comp = $comp;
1185 my $incumbent = "incumbent data" ;
1187 my $lex = new LexFile(my $file1, my $file2) ;
1189 writeFile($file1, compressBuffer(getTopFuncName($UncompressClass),"data1"));
1190 writeFile($file2, compressBuffer(getTopFuncName($UncompressClass),"data2"));
1192 my $of = new IO::File "<$file1" ;
1193 ok $of, " Created output filehandle" ;
1195 #my @input = ($file2, \$undef, \$null, \$comp, $of) ;
1196 #my @expected = ('data2', '', '', 'abcde', 'data1');
1197 my @input = ($file1, $file2);
1198 my @expected = ('data1', 'data2');
1203 title "$TopType - From ArrayRef to Buffer" ;
1206 ok &$Func(\@input, \$output, AutoClose => 0), ' UnCompressed ok' ;
1208 is $output, join('', @expected)
1212 title "$TopType - From ArrayRef to Filename" ;
1214 my $lex = new LexFile my $output;
1215 $of->open("<$file1") ;
1217 ok &$Func(\@input, $output, AutoClose => 0), ' UnCompressed ok' ;
1219 is readFile($output), join('', @expected)
1223 title "$TopType - From ArrayRef to Filehandle" ;
1225 my $lex = new LexFile my $output;
1226 my $fh = new IO::File ">$output" ;
1227 $of->open("<$file1") ;
1229 ok &$Func(\@input, $fh, AutoClose => 0), ' UnCompressed ok' ;
1232 is readFile($output), join('', @expected)
1236 title "$TopType - From Array Ref to Array Ref" ;
1238 my @output = (\'first') ;
1239 $of->open("<$file1") ;
1240 ok &$Func(\@input, \@output, AutoClose => 0), ' UnCompressed ok' ;
1242 is_deeply \@input, \@keep, " Input array not changed" ;
1243 is_deeply [map { defined $$_ ? $$_ : "" } @output],
1244 ['first', @expected],
1245 " Got Expected uncompressed data";
1250 foreach my $bit ($UncompressClass,
1251 'IO::Uncompress::AnyUncompress',
1254 # TODO -- Add Append mode tests
1256 my $Error = getErrorRef($bit);
1257 my $Func = getTopFuncRef($bit);
1258 my $TopType = getTopFuncName($bit);
1260 my $tmpDir1 = 'tmpdir1';
1261 my $tmpDir2 = 'tmpdir2';
1262 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
1264 mkdir $tmpDir1, 0777;
1265 mkdir $tmpDir2, 0777;
1267 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
1268 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
1270 my @files = map { "$tmpDir1/$_.tmp" } qw( a1 a2 a3) ;
1271 foreach (@files) { writeFile($_, compressBuffer(getTopFuncName($UncompressClass), "abc $_")) }
1273 my @expected = map { "abc $_" } @files ;
1274 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
1277 title "$TopType - From FileGlob to FileGlob" ;
1279 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>"), ' UnCompressed ok'
1282 my @copy = @expected;
1283 for my $file (@outFiles)
1285 is readFile($file), shift @copy, " got expected from $file" ;
1288 is @copy, 0, " got all files";
1292 title "$TopType - From FileGlob to Arrayref" ;
1294 my @output = (\'first');
1295 ok &$Func("<$tmpDir1/a*.tmp>" => \@output), ' UnCompressed ok'
1298 my @copy = ('first', @expected);
1299 for my $data (@output)
1301 is $$data, shift @copy, " got expected data" ;
1304 is @copy, 0, " got all files";
1308 title "$TopType - From FileGlob to Buffer" ;
1311 ok &$Func("<$tmpDir1/a*.tmp>" => \$output), ' UnCompressed ok'
1314 is $output, join('', @expected), " got expected uncompressed data";
1318 title "$TopType - From FileGlob to Filename" ;
1320 my $lex = new LexFile my $output ;
1321 ok ! -e $output, " $output does not exist" ;
1322 ok &$Func("<$tmpDir1/a*.tmp>" => $output), ' UnCompressed ok'
1325 ok -e $output, " $output does exist" ;
1326 is readFile($output), join('', @expected), " got expected uncompressed data";
1330 title "$TopType - From FileGlob to Filehandle" ;
1332 my $output = 'abc' ;
1333 my $lex = new LexFile $output ;
1334 my $fh = new IO::File ">$output" ;
1335 ok &$Func("<$tmpDir1/a*.tmp>" => $fh, AutoClose => 1), ' UnCompressed ok'
1338 ok -e $output, " $output does exist" ;
1339 is readFile($output), join('', @expected), " got expected uncompressed data";
1344 foreach my $TopType ($CompressClass
1345 # TODO -- add the inflate classes
1348 my $Error = getErrorRef($TopType);
1349 my $Func = getTopFuncRef($TopType);
1350 my $Name = getTopFuncName($TopType);
1352 title "More write tests" ;
1354 my $lex = new LexFile(my $file1, my $file2, my $file3) ;
1356 writeFile($file1, "F1");
1357 writeFile($file2, "F2");
1358 writeFile($file3, "F3");
1361 # [ '[\"ab", \"cd"]', "abcd" ],
1363 # [ '[\"a", $fh1, \"bc"]', "aF1bc"],
1367 # foreach my $data (@data)
1369 # my ($send, $get) = @$data ;
1371 # my $fh1 = new IO::File "< $file1" ;
1372 # my $fh2 = new IO::File "< $file2" ;
1373 # my $fh3 = new IO::File "< $file3" ;
1377 # eval "\$copy = $send";
1379 # ok &$Func($copy, \$Answer), " $Name ok";
1381 # my $got = anyUncompress(\$Answer);
1382 # is $got, $get, " got expected output" ;
1383 # ok ! $$Error, " no error"
1384 # or diag "Error is $$Error";
1388 title "Array Input Error tests" ;
1391 [ '[]', "empty array reference"],
1392 [ '[[]]', "unknown input parameter"],
1393 [ '[[[]]]', "unknown input parameter"],
1394 [ '[[\"ab"], [\"cd"]]', "unknown input parameter"],
1395 [ '[\""]', "not a filename"],
1396 [ '[\undef]', "not a filename"],
1397 [ '[\"abcd"]', "not a filename"],
1398 [ '[\&xx]', "unknown input parameter"],
1399 [ '[$fh2]', "not a filename"],
1403 foreach my $data (@data)
1405 my ($send, $get) = @$data ;
1407 my $fh1 = new IO::File "< $file1" ;
1408 my $fh2 = new IO::File "< $file2" ;
1409 my $fh3 = new IO::File "< $file3" ;
1413 eval "\$copy = $send";
1416 eval { $a = &$Func($copy, \$Answer) };
1417 ok ! $a, " $Name fails";
1419 is $$Error, $get, " got error message";
1429 foreach my $send (@data)
1433 eval "\$copy = $send";
1435 eval { &$Func($copy, \$Answer) } ;
1436 like $@, mkErr("^$TopFuncName: input filename is undef or null string"),
1437 " got error message";
1444 # TODO add more error cases