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 => 944 + $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';
77 eval { $a = $Func->(\$in, \$in) ;} ;
78 like $@, mkErr("^$TopType: input and output buffer are identical"),
79 ' Input and Output buffer are the same';
81 my $lex = new LexFile my $out_file ;
82 open OUT, ">$out_file" ;
83 eval { $a = $Func->(\*OUT, \*OUT) ;} ;
84 like $@, mkErr("^$TopType: input and output handle are identical"),
85 ' Input and Output handle are the same';
88 is -s $out_file, 0, " File zero length" ;
91 my $object = bless \%x, "someClass" ;
93 # Buffer not a scalar reference
94 #eval { $a = $Func->(\$x, \%x) ;} ;
95 eval { $a = $Func->(\$x, $object) ;} ;
96 like $@, mkErr("^$TopType: illegal output parameter"),
99 # Buffer not a scalar reference
100 eval { $a = $Func->(\$x, \%x) ;} ;
101 like $@, mkErr("^$TopType: illegal output parameter"),
105 eval { $a = $Func->(\%x, \$x) ;} ;
106 like $@, mkErr("^$TopType: illegal input parameter"),
109 #eval { $a = $Func->(\%x, \$x) ;} ;
110 eval { $a = $Func->($object, \$x) ;} ;
111 like $@, mkErr("^$TopType: illegal input parameter"),
115 my $filename = 'abc.def';
116 ok ! -e $filename, " input file '$filename' does not exist";
117 $a = $Func->($filename, \$x) ;
118 is $a, undef, " $TopType returned undef";
119 like $$Error, "/^input file '$filename' does not exist\$/", " input File '$filename' does not exist";
121 $filename = '/tmp/abd/abc.def';
122 ok ! -e $filename, " output File '$filename' does not exist";
123 $a = $Func->(\$x, $filename) ;
124 is $a, undef, " $TopType returned undef";
125 like $$Error, ("/^(cannot open file '$filename'|input file '$filename' does not exist):/"), " output File '$filename' does not exist";
127 eval { $a = $Func->(\$x, '<abc>') } ;
128 like $$Error, "/Need input fileglob for outout fileglob/",
129 ' Output fileglob with no input fileglob';
130 is $a, undef, " $TopType returned undef";
132 $a = $Func->('<abc)>', '<abc>') ;
133 is $a, undef, " $TopType returned undef";
134 like $$Error, "/Unmatched \\) in input fileglob/",
135 " Unmatched ) in input fileglob";
138 foreach my $bit ($UncompressClass,
139 'IO::Uncompress::AnyUncompress',
142 my $Error = getErrorRef($bit);
143 my $Func = getTopFuncRef($bit);
144 my $TopType = getTopFuncName($bit);
146 my $data = "mary had a little lamb" ;
149 for my $trans ( 0, 1)
151 title "Non-compressed data with $TopType, Transparent => $trans ";
156 $a = $Func->(\$data, \$out, Transparent => $trans) ;
158 is $data, $keep, " Input buffer not changed" ;
162 ok $a, " $TopType returned true" ;
163 is $out, $data, " got expected output" ;
164 ok ! $$Error, " no error [$$Error]" ;
168 ok ! $a, " $TopType returned false" ;
169 #like $$Error, '/xxx/', " error" ;
170 ok $$Error, " error is '$$Error'" ;
175 foreach my $bit ($CompressClass
178 my $Error = getErrorRef($bit);
179 my $Func = getTopFuncRef($bit);
180 my $TopType = getTopFuncName($bit);
181 my $TopTypeInverse = getInverse($bit);
182 my $FuncInverse = getTopFuncRef($TopTypeInverse);
183 my $ErrorInverse = getErrorRef($TopTypeInverse);
185 title "$TopTypeInverse - corrupt data";
187 my $data = "abcd" x 100 ;
190 ok $Func->(\$data, \$out), " $TopType ok";
192 # corrupt the compressed data
193 #substr($out, -10, 10) = "x" x 10 ;
194 substr($out, int(length($out)/3), 10) = 'abcdeabcde';
197 ok ! $FuncInverse->(\$out => \$result, Transparent => 0), " $TopTypeInverse ok";
198 ok $$ErrorInverse, " Got error '$$ErrorInverse'" ;
200 #is $result, $data, " data ok";
202 ok ! anyuncompress(\$out => \$result, Transparent => 0), "anyuncompress ok";
203 ok $AnyUncompressError, " Got error '$AnyUncompressError'" ;
207 foreach my $bit ($CompressClass
210 my $Error = getErrorRef($bit);
211 my $Func = getTopFuncRef($bit);
212 my $TopType = getTopFuncName($bit);
213 my $TopTypeInverse = getInverse($bit);
214 my $FuncInverse = getTopFuncRef($TopTypeInverse);
216 for my $append ( 1, 0 )
219 $already = 'abcde' if $append ;
221 for my $buffer ( undef, '', "abcde" )
224 my $disp_content = defined $buffer ? $buffer : '<undef>' ;
227 my $out_file = "abcde.out";
228 my $in_file = "abcde.in";
231 title "$TopType - From Buff to Buff content '$disp_content' Append $append" ;
233 my $output = $already;
234 ok &$Func(\$buffer, \$output, Append => $append), ' Compressed ok' ;
236 is $keep, $buffer, " Input buffer not changed" ;
237 my $got = anyUncompress(\$output, $already);
238 $got = undef if ! defined $buffer && $got eq '' ;
239 is $got, $buffer, " Uncompressed matches original";
244 title "$TopType - From Buff to Array Ref content '$disp_content' Append $append" ;
246 my @output = ('first') ;
247 ok &$Func(\$buffer, \@output, Append => $append), ' Compressed ok' ;
249 is $output[0], 'first', " Array[0] unchanged";
250 is $keep, $buffer, " Input buffer not changed" ;
251 my $got = anyUncompress($output[1]);
252 $got = undef if ! defined $buffer && $got eq '' ;
253 is $got, $buffer, " Uncompressed matches original";
257 title "$TopType - From Array Ref to Array Ref content '$disp_content' Append $append" ;
259 my $lex = new LexFile my $in_file ;
260 writeFile($in_file, $buffer);
261 my @output = ('first') ;
262 my @input = ($in_file);
263 ok &$Func(\@input, \@output, Append => $append), ' Compressed ok' ;
265 is $output[0], 'first', " Array[0] unchanged";
266 my $got = anyUncompress($output[1]);
267 $got = undef if ! defined $buffer && $got eq '' ;
268 is $got, $buffer, " Uncompressed matches original";
272 title "$TopType - From Buff to Filename content '$disp_content' Append $append" ;
274 my $lex = new LexFile my $out_file ;
275 ok ! -e $out_file, " Output file does not exist";
276 writeFile($out_file, $already);
278 ok &$Func(\$buffer, $out_file, Append => $append), ' Compressed ok' ;
280 ok -e $out_file, " Created output file";
281 my $got = anyUncompress($out_file, $already);
282 $got = undef if ! defined $buffer && $got eq '' ;
283 is $got, $buffer, " Uncompressed matches original";
287 title "$TopType - From Buff to Handle content '$disp_content' Append $append" ;
289 my $lex = new LexFile my $out_file ;
291 ok ! -e $out_file, " Output file does not exist";
292 writeFile($out_file, $already);
293 my $of = new IO::File ">>$out_file" ;
294 ok $of, " Created output filehandle" ;
296 ok &$Func(\$buffer, $of, AutoClose => 1, Append => $append), ' Compressed ok' ;
298 ok -e $out_file, " Created output file";
299 my $got = anyUncompress($out_file, $already);
300 $got = undef if ! defined $buffer && $got eq '' ;
301 is $got, $buffer, " Uncompressed matches original";
306 title "$TopType - From Filename to Filename content '$disp_content' Append $append" ;
308 my $lex = new LexFile(my $in_file, my $out_file) ;
309 writeFile($in_file, $buffer);
311 ok ! -e $out_file, " Output file does not exist";
312 writeFile($out_file, $already);
314 ok &$Func($in_file => $out_file, Append => $append), ' Compressed ok' ;
316 ok -e $out_file, " Created output file";
317 my $got = anyUncompress($out_file, $already);
318 $got = undef if ! defined $buffer && $got eq '' ;
319 is $got, $buffer, " Uncompressed matches original";
324 title "$TopType - From Filename to Handle content '$disp_content' Append $append" ;
326 my $lex = new LexFile(my $in_file, my $out_file) ;
327 writeFile($in_file, $buffer);
329 ok ! -e $out_file, " Output file does not exist";
330 writeFile($out_file, $already);
331 my $out = new IO::File ">>$out_file" ;
333 ok &$Func($in_file, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
335 ok -e $out_file, " Created output file";
336 my $got = anyUncompress($out_file, $already);
337 $got = undef if ! defined $buffer && $got eq '' ;
338 is $got, $buffer, " Uncompressed matches original";
343 title "$TopType - From Filename to Buffer content '$disp_content' Append $append" ;
345 my $lex = new LexFile(my $in_file, my $out_file) ;
346 writeFile($in_file, $buffer);
350 ok &$Func($in_file => \$out, Append => $append), ' Compressed ok' ;
352 my $got = anyUncompress(\$out, $already);
353 $got = undef if ! defined $buffer && $got eq '' ;
354 is $got, $buffer, " Uncompressed matches original";
359 title "$TopType - From Handle to Filename content '$disp_content' Append $append" ;
361 my $lex = new LexFile(my $in_file, my $out_file) ;
362 writeFile($in_file, $buffer);
363 my $in = new IO::File "<$in_file" ;
365 ok ! -e $out_file, " Output file does not exist";
366 writeFile($out_file, $already);
368 ok &$Func($in, $out_file, Append => $append), ' Compressed ok'
369 or diag "error is $$Error" ;
371 ok -e $out_file, " Created output file";
372 my $got = anyUncompress($out_file, $already);
373 $got = undef if ! defined $buffer && $got eq '' ;
374 is $buffer, $got, " Uncompressed matches original";
379 title "$TopType - From Handle to Handle 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);
387 my $out = new IO::File ">>$out_file" ;
389 ok &$Func($in, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
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 Buffer 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" ;
407 ok &$Func($in, \$out, Append => $append), ' Compressed ok' ;
409 my $got = anyUncompress(\$out, $already);
410 $got = undef if ! defined $buffer && $got eq '' ;
411 is $buffer, $got, " Uncompressed matches original";
416 title "$TopType - From stdin (via '-') to Buffer content '$disp_content' Append $append" ;
418 my $lex = new LexFile(my $in_file, my $out_file) ;
419 writeFile($in_file, $buffer);
421 open(SAVEIN, "<&STDIN");
422 my $dummy = fileno SAVEIN ;
423 ok open(STDIN, "<$in_file"), " redirect STDIN";
427 ok &$Func('-', \$out, Append => $append), ' Compressed ok'
430 open(STDIN, "<&SAVEIN");
432 my $got = anyUncompress(\$out, $already);
433 $got = undef if ! defined $buffer && $got eq '' ;
434 is $buffer, $got, " Uncompressed matches original";
442 foreach my $bit ($CompressClass)
444 my $Error = getErrorRef($bit);
445 my $Func = getTopFuncRef($bit);
446 my $TopType = getTopFuncName($bit);
448 my $TopTypeInverse = getInverse($bit);
449 my $FuncInverse = getTopFuncRef($TopTypeInverse);
451 my $lex = new LexFile(my $file1, my $file2) ;
453 writeFile($file1, "data1");
454 writeFile($file2, "data2");
455 my $of = new IO::File "<$file1" ;
456 ok $of, " Created output filehandle" ;
458 #my @input = ( undef, "", $file2, \undef, \'', \"abcde", $of) ;
459 #my @expected = ("", "", $file2, "", "", "abcde", "data1");
460 #my @uexpected = ("", "", "data2", "", "", "abcde", "data1");
461 #my @input = ( $file2, \"abcde", $of) ;
462 #my @expected = ( $file2, "abcde", "data1");
463 #my @uexpected = ("data2", "abcde", "data1");
465 my @input = ( $file1, $file2) ;
466 #my @expected = ( $file1, $file2);
467 my @expected = ("data1", "data2");
468 my @uexpected = ("data1", "data2");
473 title "$TopType - From Array Ref to Array Ref" ;
475 my @output = ('first') ;
476 ok &$Func(\@input, \@output, AutoClose => 0), ' Compressed ok' ;
478 is $output[0], 'first', " Array[0] unchanged";
480 is_deeply \@input, \@keep, " Input array not changed" ;
481 my @got = shift @output;
482 foreach (@output) { push @got, anyUncompress($_) }
484 is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
488 foreach my $ms (1, 0)
491 title "$TopType - From Array Ref to Buffer, MultiStream $ms" ;
493 # rewind the filehandle
494 $of->open("<$file1") ;
497 ok &$Func(\@input, \$output, MultiStream => $ms, AutoClose => 0), ' Compressed ok'
500 my $got = anyUncompress([ \$output, MultiStream => $ms ]);
502 is $got, join('', @uexpected), " Got Expected uncompressed data";
503 my @headers = getHeaders(\$output);
504 is @headers, $ms ? @input : 1, " Header count ok";
508 title "$TopType - From Array Ref to Filename, MultiStream $ms" ;
510 my $lex = new LexFile( my $file3) ;
512 # rewind the filehandle
513 $of->open("<$file1") ;
516 ok &$Func(\@input, $file3, MultiStream => $ms, AutoClose => 0), ' Compressed ok' ;
518 my $got = anyUncompress([ $file3, MultiStream => $ms ]);
520 is $got, join('', @uexpected), " Got Expected uncompressed data";
521 my @headers = getHeaders($file3);
522 is @headers, $ms ? @input : 1, " Header count ok";
526 title "$TopType - From Array Ref to Filehandle, MultiStream $ms" ;
528 my $lex = new LexFile(my $file3) ;
530 my $fh3 = new IO::File ">$file3";
532 # rewind the filehandle
533 $of->open("<$file1") ;
536 ok &$Func(\@input, $fh3, MultiStream => $ms, AutoClose => 0), ' Compressed ok' ;
540 my $got = anyUncompress([ $file3, MultiStream => $ms ]);
542 is $got, join('', @uexpected), " Got Expected uncompressed data";
543 my @headers = getHeaders($file3);
544 is @headers, $ms ? @input : 1, " Header count ok";
549 # foreach my $bit ($CompressClass)
551 # my $Error = getErrorRef($bit);
552 # my $Func = getTopFuncRef($bit);
553 # my $TopType = getTopFuncName($bit);
555 # my $TopTypeInverse = getInverse($bit);
556 # my $FuncInverse = getTopFuncRef($TopTypeInverse);
558 # my @inFiles = map { "in$_.tmp" } 1..4;
559 # my @outFiles = map { "out$_.tmp" } 1..4;
560 # my $lex = new LexFile(@inFiles, @outFiles);
562 # writeFile($_, "data $_") foreach @inFiles ;
565 # title "$TopType - Hash Ref: to filename" ;
568 # ok &$Func( { $inFiles[0] => $outFiles[0],
569 # $inFiles[1] => $outFiles[1],
570 # $inFiles[2] => $outFiles[2] } ), ' Compressed ok' ;
574 # my $got = anyUncompress($outFiles[$_]);
575 # is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
580 # title "$TopType - Hash Ref: to buffer" ;
583 # ok &$Func( { $inFiles[0] => \$buffer[0],
584 # $inFiles[1] => \$buffer[1],
585 # $inFiles[2] => \$buffer[2] } ), ' Compressed ok' ;
589 # my $got = anyUncompress(\$buffer[$_]);
590 # is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
595 # title "$TopType - Hash Ref: to undef" ;
598 # my %hash = ( $inFiles[0] => undef,
599 # $inFiles[1] => undef,
600 # $inFiles[2] => undef,
603 # ok &$Func( \%hash ), ' Compressed ok' ;
605 # foreach (keys %hash)
607 # my $got = anyUncompress(\$hash{$_});
608 # is $got, "data $_", " Uncompressed $_ matches original";
613 # title "$TopType - Filename to Hash Ref" ;
616 # ok &$Func( $inFiles[0] => \%output), ' Compressed ok' ;
618 # is keys %output, 1, " one pair in hash" ;
619 # my ($k, $v) = each %output;
620 # is $k, $inFiles[0], " key is '$inFiles[0]'";
621 # my $got = anyUncompress($v);
622 # is $got, "data $inFiles[0]", " Uncompressed matches original";
626 # title "$TopType - File Glob to Hash Ref" ;
629 # ok &$Func( '<in*.tmp>' => \%output), ' Compressed ok' ;
631 # is keys %output, 4, " four pairs in hash" ;
632 # foreach my $fil (@inFiles)
634 # ok exists $output{$fil}, " key '$fil' exists" ;
635 # my $got = anyUncompress($output{$fil});
636 # is $got, "data $fil", " Uncompressed matches original";
643 # foreach my $bit ($CompressClass)
645 # my $Error = getErrorRef($bit);
646 # my $Func = getTopFuncRef($bit);
647 # my $TopType = getTopFuncName($bit);
649 # my $TopTypeInverse = getInverse($bit);
650 # my $FuncInverse = getTopFuncRef($TopTypeInverse);
652 # my @inFiles = map { "in$_.tmp" } 1..4;
653 # my @outFiles = map { "out$_.tmp" } 1..4;
654 # my $lex = new LexFile(@inFiles, @outFiles);
656 # writeFile($_, "data $_") foreach @inFiles ;
662 # # title "$TopType - Hash Ref to Array Ref" ;
664 # # my @output = ('first') ;
665 # # ok &$Func( { \@input, \@output } , AutoClose => 0), ' Compressed ok' ;
667 # # is $output[0], 'first', " Array[0] unchanged";
669 # # is_deeply \@input, \@keep, " Input array not changed" ;
670 # # my @got = shift @output;
671 # # foreach (@output) { push @got, anyUncompress($_) }
673 # # is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
679 # # title "$TopType - From Array Ref to Buffer" ;
681 # # # rewind the filehandle
682 # # $of->open("<$file1") ;
685 # # ok &$Func(\@input, \$output, AutoClose => 0), ' Compressed ok' ;
687 # # my $got = anyUncompress(\$output);
689 # # is $got, join('', @expected), " Got Expected uncompressed data";
694 # # title "$TopType - From Array Ref to Filename" ;
696 # # my ($file3) = ("file3");
697 # # my $lex = new LexFile($file3) ;
699 # # # rewind the filehandle
700 # # $of->open("<$file1") ;
703 # # ok &$Func(\@input, $file3, AutoClose => 0), ' Compressed ok' ;
705 # # my $got = anyUncompress($file3);
707 # # is $got, join('', @expected), " Got Expected uncompressed data";
712 # # title "$TopType - From Array Ref to Filehandle" ;
714 # # my ($file3) = ("file3");
715 # # my $lex = new LexFile($file3) ;
717 # # my $fh3 = new IO::File ">$file3";
719 # # # rewind the filehandle
720 # # $of->open("<$file1") ;
723 # # ok &$Func(\@input, $fh3, AutoClose => 0), ' Compressed ok' ;
727 # # my $got = anyUncompress($file3);
729 # # is $got, join('', @expected), " Got Expected uncompressed data";
733 foreach my $bit ($CompressClass
736 my $Error = getErrorRef($bit);
737 my $Func = getTopFuncRef($bit);
738 my $TopType = getTopFuncName($bit);
740 for my $files ( [qw(a1)], [qw(a1 a2 a3)] )
743 my $tmpDir1 = 'tmpdir1';
744 my $tmpDir2 = 'tmpdir2';
745 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
747 mkdir $tmpDir1, 0777;
748 mkdir $tmpDir2, 0777;
750 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
751 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
753 my @files = map { "$tmpDir1/$_.tmp" } @$files ;
754 foreach (@files) { writeFile($_, "abc $_") }
756 my @expected = map { "abc $_" } @files ;
757 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
760 title "$TopType - From FileGlob to FileGlob files [@$files]" ;
762 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>"), ' Compressed ok'
765 my @copy = @expected;
766 for my $file (@outFiles)
768 is anyUncompress($file), shift @copy, " got expected from $file" ;
771 is @copy, 0, " got all files";
775 title "$TopType - From FileGlob to Array files [@$files]" ;
777 my @buffer = ('first') ;
778 ok &$Func("<$tmpDir1/a*.tmp>" => \@buffer), ' Compressed ok'
781 is shift @buffer, 'first';
783 my @copy = @expected;
784 for my $buffer (@buffer)
786 is anyUncompress($buffer), shift @copy, " got expected " ;
789 is @copy, 0, " got all files";
792 foreach my $ms (0, 1)
795 title "$TopType - From FileGlob to Buffer files [@$files], MS $ms" ;
798 ok &$Func("<$tmpDir1/a*.tmp>" => \$buffer,
799 MultiStream => $ms), ' Compressed ok'
804 my $got = anyUncompress([ \$buffer, MultiStream => $ms ]);
806 is $got, join("", @expected), " got expected" ;
807 my @headers = getHeaders(\$buffer);
808 is @headers, $ms ? @files : 1, " Header count ok";
812 title "$TopType - From FileGlob to Filename files [@$files], MS $ms" ;
814 my $filename = "abcde";
815 my $lex = new LexFile($filename) ;
817 ok &$Func("<$tmpDir1/a*.tmp>" => $filename,
818 MultiStream => $ms), ' Compressed ok'
823 my $got = anyUncompress([$filename, MultiStream => $ms]);
825 is $got, join("", @expected), " got expected" ;
826 my @headers = getHeaders($filename);
827 is @headers, $ms ? @files : 1, " Header count ok";
831 title "$TopType - From FileGlob to Filehandle files [@$files], MS $ms" ;
833 my $filename = "abcde";
834 my $lex = new LexFile($filename) ;
835 my $fh = new IO::File ">$filename";
837 ok &$Func("<$tmpDir1/a*.tmp>" => $fh,
838 MultiStream => $ms, AutoClose => 1), ' 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";
854 foreach my $bit ($UncompressClass,
855 'IO::Uncompress::AnyUncompress',
858 my $Error = getErrorRef($bit);
859 my $Func = getTopFuncRef($bit);
860 my $TopType = getTopFuncName($bit);
862 my $buffer = "abcde" ;
863 my $buffer2 = "ABCDE" ;
864 my $keep_orig = $buffer;
866 my $comp = compressBuffer(getTopFuncName($UncompressClass), $buffer) ;
867 my $comp2 = compressBuffer(getTopFuncName($UncompressClass), $buffer2) ;
868 my $keep_comp = $comp;
870 my $incumbent = "incumbent data" ;
872 for my $append (0, 1)
874 my $expected = $buffer ;
875 $expected = $incumbent . $buffer if $append ;
878 title "$TopType - From Buff to Buff, Append($append)" ;
881 $output = $incumbent if $append ;
882 ok &$Func(\$comp, \$output, Append => $append), ' Uncompressed ok' ;
884 is $keep_comp, $comp, " Input buffer not changed" ;
885 is $output, $expected, " Uncompressed matches original";
889 title "$TopType - From Buff to Array, Append($append)" ;
891 my @output = ('first');
892 #$output = $incumbent if $append ;
893 ok &$Func(\$comp, \@output, Append => $append), ' Uncompressed ok' ;
895 is $keep_comp, $comp, " Input buffer not changed" ;
896 is $output[0], 'first', " Uncompressed matches original";
897 is ${ $output[1] }, $buffer, " Uncompressed matches original"
899 is @output, 2, " only 2 elements in the array" ;
903 title "$TopType - From Buff to Filename, Append($append)" ;
905 my $lex = new LexFile(my $out_file) ;
907 { writeFile($out_file, $incumbent) }
909 { ok ! -e $out_file, " Output file does not exist" }
911 ok &$Func(\$comp, $out_file, Append => $append), ' Uncompressed ok' ;
913 ok -e $out_file, " Created output file";
914 my $content = readFile($out_file) ;
916 is $keep_comp, $comp, " Input buffer not changed" ;
917 is $content, $expected, " Uncompressed matches original";
921 title "$TopType - From Buff to Handle, Append($append)" ;
923 my $lex = new LexFile(my $out_file) ;
926 writeFile($out_file, $incumbent) ;
927 $of = new IO::File "+< $out_file" ;
930 ok ! -e $out_file, " Output file does not exist" ;
931 $of = new IO::File "> $out_file" ;
933 isa_ok $of, 'IO::File', ' $of' ;
935 ok &$Func(\$comp, $of, Append => $append, AutoClose => 1), ' 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 Filename to Filename, Append($append)" ;
947 my $lex = new LexFile(my $in_file, my $out_file) ;
949 { writeFile($out_file, $incumbent) }
951 { ok ! -e $out_file, " Output file does not exist" }
953 writeFile($in_file, $comp);
955 ok &$Func($in_file, $out_file, Append => $append), ' Uncompressed ok' ;
957 ok -e $out_file, " Created output file";
958 my $content = readFile($out_file) ;
960 is $keep_comp, $comp, " Input buffer not changed" ;
961 is $content, $expected, " Uncompressed matches original";
965 title "$TopType - From Filename to Handle, Append($append)" ;
967 my $lex = new LexFile(my $in_file, my $out_file) ;
970 writeFile($out_file, $incumbent) ;
971 $out = new IO::File "+< $out_file" ;
974 ok ! -e $out_file, " Output file does not exist" ;
975 $out = new IO::File "> $out_file" ;
977 isa_ok $out, 'IO::File', ' $out' ;
979 writeFile($in_file, $comp);
981 ok &$Func($in_file, $out, Append => $append, AutoClose => 1), ' Uncompressed ok' ;
983 ok -e $out_file, " Created output file";
984 my $content = readFile($out_file) ;
986 is $keep_comp, $comp, " Input buffer not changed" ;
987 is $content, $expected, " Uncompressed matches original";
991 title "$TopType - From Filename to Buffer, Append($append)" ;
993 my $lex = new LexFile(my $in_file) ;
994 writeFile($in_file, $comp);
997 $output = $incumbent if $append ;
999 ok &$Func($in_file, \$output, Append => $append), ' Uncompressed ok' ;
1001 is $keep_comp, $comp, " Input buffer not changed" ;
1002 is $output, $expected, " Uncompressed matches original";
1006 title "$TopType - From Handle to Filename, Append($append)" ;
1008 my $lex = new LexFile(my $in_file, my $out_file) ;
1010 { writeFile($out_file, $incumbent) }
1012 { ok ! -e $out_file, " Output file does not exist" }
1014 writeFile($in_file, $comp);
1015 my $in = new IO::File "<$in_file" ;
1017 ok &$Func($in, $out_file, Append => $append), ' Uncompressed ok' ;
1019 ok -e $out_file, " Created output file";
1020 my $content = readFile($out_file) ;
1022 is $keep_comp, $comp, " Input buffer not changed" ;
1023 is $content, $expected, " Uncompressed matches original";
1027 title "$TopType - From Handle to Handle, Append($append)" ;
1029 my $lex = new LexFile(my $in_file, my $out_file) ;
1032 writeFile($out_file, $incumbent) ;
1033 $out = new IO::File "+< $out_file" ;
1036 ok ! -e $out_file, " Output file does not exist" ;
1037 $out = new IO::File "> $out_file" ;
1039 isa_ok $out, 'IO::File', ' $out' ;
1041 writeFile($in_file, $comp);
1042 my $in = new IO::File "<$in_file" ;
1044 ok &$Func($in, $out, Append => $append, AutoClose => 1), ' Uncompressed ok' ;
1046 ok -e $out_file, " Created output file";
1047 my $content = readFile($out_file) ;
1049 is $keep_comp, $comp, " Input buffer not changed" ;
1050 is $content, $expected, " Uncompressed matches original";
1054 title "$TopType - From Filename to Buffer, Append($append)" ;
1056 my $lex = new LexFile(my $in_file) ;
1057 writeFile($in_file, $comp);
1058 my $in = new IO::File "<$in_file" ;
1061 $output = $incumbent if $append ;
1063 ok &$Func($in, \$output, Append => $append), ' Uncompressed ok' ;
1065 is $keep_comp, $comp, " Input buffer not changed" ;
1066 is $output, $expected, " Uncompressed matches original";
1070 title "$TopType - From stdin (via '-') to Buffer content, Append($append) " ;
1072 my $lex = new LexFile(my $in_file) ;
1073 writeFile($in_file, $comp);
1075 open(SAVEIN, "<&STDIN");
1076 my $dummy = fileno SAVEIN ;
1077 ok open(STDIN, "<$in_file"), " redirect STDIN";
1080 $output = $incumbent if $append ;
1082 ok &$Func('-', \$output, Append => $append), ' Uncompressed ok'
1085 open(STDIN, "<&SAVEIN");
1087 is $keep_comp, $comp, " Input buffer not changed" ;
1088 is $output, $expected, " Uncompressed matches original";
1093 title "$TopType - From Handle to Buffer, InputLength" ;
1095 my $lex = new LexFile(my $in_file, my $out_file) ;
1098 my $expected = $buffer ;
1099 my $appended = 'appended';
1100 my $len_appended = length $appended;
1101 writeFile($in_file, $comp . $appended . $comp . $appended) ;
1102 my $in = new IO::File "<$in_file" ;
1104 ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp), ' Uncompressed ok' ;
1106 is $out, $expected, " Uncompressed matches original";
1109 is $in->read($buff, $len_appended), $len_appended, " Length of Appended data ok";
1110 is $buff, $appended, " Appended data ok";
1113 ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp), ' Uncompressed ok' ;
1115 is $out, $expected, " Uncompressed matches original";
1118 is $in->read($buff, $len_appended), $len_appended, " Length of Appended data ok";
1119 is $buff, $appended, " Appended data ok";
1122 for my $stdin ('-', *STDIN) # , \*STDIN)
1124 title "$TopType - From stdin (via $stdin) to Buffer content, InputLength" ;
1126 my $lex = new LexFile my $in_file ;
1127 my $expected = $buffer ;
1128 my $appended = 'appended';
1129 my $len_appended = length $appended;
1130 writeFile($in_file, $comp . $appended ) ;
1132 open(SAVEIN, "<&STDIN");
1133 my $dummy = fileno SAVEIN ;
1134 ok open(STDIN, "<$in_file"), " redirect STDIN";
1138 ok &$Func($stdin, \$output, Transparent => 0, InputLength => length $comp), ' Uncompressed ok'
1142 is read(STDIN, $buff, $len_appended), $len_appended, " Length of Appended data ok";
1144 is $output, $expected, " Uncompressed matches original";
1145 is $buff, $appended, " Appended data ok";
1147 open(STDIN, "<&SAVEIN");
1151 foreach my $bit ($UncompressClass,
1152 'IO::Uncompress::AnyUncompress',
1155 # TODO -- Add Append mode tests
1157 my $Error = getErrorRef($bit);
1158 my $Func = getTopFuncRef($bit);
1159 my $TopType = getTopFuncName($bit);
1161 my $buffer = "abcde" ;
1162 my $keep_orig = $buffer;
1164 my $null = compressBuffer(getTopFuncName($UncompressClass), "") ;
1165 my $undef = compressBuffer(getTopFuncName($UncompressClass), undef) ;
1166 my $comp = compressBuffer(getTopFuncName($UncompressClass), $buffer) ;
1167 my $keep_comp = $comp;
1169 my $incumbent = "incumbent data" ;
1171 my $lex = new LexFile(my $file1, my $file2) ;
1173 writeFile($file1, compressBuffer(getTopFuncName($UncompressClass),"data1"));
1174 writeFile($file2, compressBuffer(getTopFuncName($UncompressClass),"data2"));
1176 my $of = new IO::File "<$file1" ;
1177 ok $of, " Created output filehandle" ;
1179 #my @input = ($file2, \$undef, \$null, \$comp, $of) ;
1180 #my @expected = ('data2', '', '', 'abcde', 'data1');
1181 my @input = ($file1, $file2);
1182 my @expected = ('data1', 'data2');
1187 title "$TopType - From ArrayRef to Buffer" ;
1190 ok &$Func(\@input, \$output, AutoClose => 0), ' UnCompressed ok' ;
1192 is $output, join('', @expected)
1196 title "$TopType - From ArrayRef to Filename" ;
1198 my $lex = new LexFile my $output;
1199 $of->open("<$file1") ;
1201 ok &$Func(\@input, $output, AutoClose => 0), ' UnCompressed ok' ;
1203 is readFile($output), join('', @expected)
1207 title "$TopType - From ArrayRef to Filehandle" ;
1209 my $lex = new LexFile my $output;
1210 my $fh = new IO::File ">$output" ;
1211 $of->open("<$file1") ;
1213 ok &$Func(\@input, $fh, AutoClose => 0), ' UnCompressed ok' ;
1216 is readFile($output), join('', @expected)
1220 title "$TopType - From Array Ref to Array Ref" ;
1222 my @output = (\'first') ;
1223 $of->open("<$file1") ;
1224 ok &$Func(\@input, \@output, AutoClose => 0), ' UnCompressed ok' ;
1226 is_deeply \@input, \@keep, " Input array not changed" ;
1227 is_deeply [map { defined $$_ ? $$_ : "" } @output],
1228 ['first', @expected],
1229 " Got Expected uncompressed data";
1234 foreach my $bit ($UncompressClass,
1235 'IO::Uncompress::AnyUncompress',
1238 # TODO -- Add Append mode tests
1240 my $Error = getErrorRef($bit);
1241 my $Func = getTopFuncRef($bit);
1242 my $TopType = getTopFuncName($bit);
1244 my $tmpDir1 = 'tmpdir1';
1245 my $tmpDir2 = 'tmpdir2';
1246 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
1248 mkdir $tmpDir1, 0777;
1249 mkdir $tmpDir2, 0777;
1251 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
1252 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
1254 my @files = map { "$tmpDir1/$_.tmp" } qw( a1 a2 a3) ;
1255 foreach (@files) { writeFile($_, compressBuffer(getTopFuncName($UncompressClass), "abc $_")) }
1257 my @expected = map { "abc $_" } @files ;
1258 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
1261 title "$TopType - From FileGlob to FileGlob" ;
1263 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>"), ' UnCompressed ok'
1266 my @copy = @expected;
1267 for my $file (@outFiles)
1269 is readFile($file), shift @copy, " got expected from $file" ;
1272 is @copy, 0, " got all files";
1276 title "$TopType - From FileGlob to Arrayref" ;
1278 my @output = (\'first');
1279 ok &$Func("<$tmpDir1/a*.tmp>" => \@output), ' UnCompressed ok'
1282 my @copy = ('first', @expected);
1283 for my $data (@output)
1285 is $$data, shift @copy, " got expected data" ;
1288 is @copy, 0, " got all files";
1292 title "$TopType - From FileGlob to Buffer" ;
1295 ok &$Func("<$tmpDir1/a*.tmp>" => \$output), ' UnCompressed ok'
1298 is $output, join('', @expected), " got expected uncompressed data";
1302 title "$TopType - From FileGlob to Filename" ;
1304 my $lex = new LexFile my $output ;
1305 ok ! -e $output, " $output does not exist" ;
1306 ok &$Func("<$tmpDir1/a*.tmp>" => $output), ' UnCompressed ok'
1309 ok -e $output, " $output does exist" ;
1310 is readFile($output), join('', @expected), " got expected uncompressed data";
1314 title "$TopType - From FileGlob to Filehandle" ;
1316 my $output = 'abc' ;
1317 my $lex = new LexFile $output ;
1318 my $fh = new IO::File ">$output" ;
1319 ok &$Func("<$tmpDir1/a*.tmp>" => $fh, AutoClose => 1), ' UnCompressed ok'
1322 ok -e $output, " $output does exist" ;
1323 is readFile($output), join('', @expected), " got expected uncompressed data";
1328 foreach my $TopType ($CompressClass
1329 # TODO -- add the inflate classes
1332 my $Error = getErrorRef($TopType);
1333 my $Func = getTopFuncRef($TopType);
1334 my $Name = getTopFuncName($TopType);
1336 title "More write tests" ;
1338 my $lex = new LexFile(my $file1, my $file2, my $file3) ;
1340 writeFile($file1, "F1");
1341 writeFile($file2, "F2");
1342 writeFile($file3, "F3");
1345 # [ '[\"ab", \"cd"]', "abcd" ],
1347 # [ '[\"a", $fh1, \"bc"]', "aF1bc"],
1351 # foreach my $data (@data)
1353 # my ($send, $get) = @$data ;
1355 # my $fh1 = new IO::File "< $file1" ;
1356 # my $fh2 = new IO::File "< $file2" ;
1357 # my $fh3 = new IO::File "< $file3" ;
1361 # eval "\$copy = $send";
1363 # ok &$Func($copy, \$Answer), " $Name ok";
1365 # my $got = anyUncompress(\$Answer);
1366 # is $got, $get, " got expected output" ;
1367 # ok ! $$Error, " no error"
1368 # or diag "Error is $$Error";
1372 title "Array Input Error tests" ;
1375 [ '[]', "empty array reference"],
1376 [ '[[]]', "unknown input parameter"],
1377 [ '[[[]]]', "unknown input parameter"],
1378 [ '[[\"ab"], [\"cd"]]', "unknown input parameter"],
1379 [ '[\""]', "not a filename"],
1380 [ '[\undef]', "not a filename"],
1381 [ '[\"abcd"]', "not a filename"],
1382 [ '[\&xx]', "unknown input parameter"],
1383 [ '[$fh2]', "not a filename"],
1387 foreach my $data (@data)
1389 my ($send, $get) = @$data ;
1391 my $fh1 = new IO::File "< $file1" ;
1392 my $fh2 = new IO::File "< $file2" ;
1393 my $fh3 = new IO::File "< $file3" ;
1397 eval "\$copy = $send";
1400 eval { $a = &$Func($copy, \$Answer) };
1401 ok ! $a, " $Name fails";
1403 is $$Error, $get, " got error message";
1413 foreach my $send (@data)
1417 eval "\$copy = $send";
1419 eval { &$Func($copy, \$Answer) } ;
1420 like $@, mkErr("^$TopFuncName: input filename is undef or null string"),
1421 " got error message";
1428 # TODO add more error cases