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 => 970 + $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);
35 my @MultiValues = getMultiValues($CompressClass);
37 foreach my $bit ($CompressClass, $UncompressClass,
38 'IO::Uncompress::AnyUncompress',
41 my $Error = getErrorRef($bit);
42 my $Func = getTopFuncRef($bit);
43 my $TopType = getTopFuncName($bit);
45 title "Testing $TopType Error Cases";
50 eval { $a = $Func->(\$a => \$x, Fred => 1) ;} ;
51 like $@, mkErr("^$TopType: unknown key value\\(s\\) Fred"), ' Illegal Parameters';
53 eval { $a = $Func->() ;} ;
54 like $@, mkErr("^$TopType: expected at least 1 parameters"), ' No Parameters';
56 eval { $a = $Func->(\$x, \1) ;} ;
57 like $$Error, "/^$TopType: output buffer is read-only/", ' Output is read-only' ;
60 eval { $a = $Func->($in, \$x) ;} ;
61 like $@, mkErr("^$TopType: input filename is undef or null string"),
62 ' Input filename undef' ;
65 eval { $a = $Func->($in, \$x) ;} ;
66 like $@, mkErr("^$TopType: input filename is undef or null string"),
67 ' Input filename empty' ;
70 my $lex1 = new LexFile my $in ;
71 writeFile($in, "abc");
73 eval { $a = $Func->($in, $out) ;} ;
74 like $@, mkErr("^$TopType: input and output filename are identical"),
75 ' Input and Output filename are the same';
80 my $lex = new LexDir $dir ;
83 $a = $Func->($dir, \$x) ;
84 is $a, undef, " $TopType returned undef";
85 like $$Error, "/input file '$dir' is a directory/",
86 ' Input filename is a directory';
88 $a = $Func->(\$x, $dir) ;
89 is $a, undef, " $TopType returned undef";
90 like $$Error, "/output file '$dir' is a directory/",
91 ' Output filename is a directory';
94 eval { $a = $Func->(\$in, \$in) ;} ;
95 like $@, mkErr("^$TopType: input and output buffer are identical"),
96 ' Input and Output buffer are the same';
98 my $lex = new LexFile my $out_file ;
99 open OUT, ">$out_file" ;
100 eval { $a = $Func->(\*OUT, \*OUT) ;} ;
101 like $@, mkErr("^$TopType: input and output handle are identical"),
102 ' Input and Output handle are the same';
105 is -s $out_file, 0, " File zero length" ;
108 my $object = bless \%x, "someClass" ;
110 # Buffer not a scalar reference
111 #eval { $a = $Func->(\$x, \%x) ;} ;
112 eval { $a = $Func->(\$x, $object) ;} ;
113 like $@, mkErr("^$TopType: illegal output parameter"),
116 # Buffer not a scalar reference
117 eval { $a = $Func->(\$x, \%x) ;} ;
118 like $@, mkErr("^$TopType: illegal output parameter"),
122 eval { $a = $Func->(\%x, \$x) ;} ;
123 like $@, mkErr("^$TopType: illegal input parameter"),
126 #eval { $a = $Func->(\%x, \$x) ;} ;
127 eval { $a = $Func->($object, \$x) ;} ;
128 like $@, mkErr("^$TopType: illegal input parameter"),
132 my $filename = 'abc.def';
133 ok ! -e $filename, " input file '$filename' does not exist";
134 $a = $Func->($filename, \$x) ;
135 is $a, undef, " $TopType returned undef";
136 like $$Error, "/^input file '$filename' does not exist\$/", " input File '$filename' does not exist";
138 $filename = '/tmp/abd/abc.def';
139 ok ! -e $filename, " output File '$filename' does not exist";
140 $a = $Func->(\$x, $filename) ;
141 is $a, undef, " $TopType returned undef";
142 like $$Error, ("/^(cannot open file '$filename'|input file '$filename' does not exist):/"), " output File '$filename' does not exist";
144 eval { $a = $Func->(\$x, '<abc>') } ;
145 like $$Error, "/Need input fileglob for outout fileglob/",
146 ' Output fileglob with no input fileglob';
147 is $a, undef, " $TopType returned undef";
149 $a = $Func->('<abc)>', '<abc>') ;
150 is $a, undef, " $TopType returned undef";
151 like $$Error, "/Unmatched \\) in input fileglob/",
152 " Unmatched ) in input fileglob";
155 foreach my $bit ($UncompressClass,
156 'IO::Uncompress::AnyUncompress',
159 my $Error = getErrorRef($bit);
160 my $Func = getTopFuncRef($bit);
161 my $TopType = getTopFuncName($bit);
168 eval { $a = $Func->(\$in, \$out, TrailingData => \"abc") ;} ;
169 like $@, mkErr("^$TopType: Parameter 'TrailingData' not writable"),
170 ' TrailingData output not writable';
172 eval { $a = $Func->(\$in, \$out, TrailingData => \@x) ;} ;
173 like $@, mkErr("^$TopType: Parameter 'TrailingData' not a scalar reference"),
174 ' TrailingData output not scaral reference';
178 foreach my $bit ($UncompressClass,
179 'IO::Uncompress::AnyUncompress',
182 my $Error = getErrorRef($bit);
183 my $Func = getTopFuncRef($bit);
184 my $TopType = getTopFuncName($bit);
186 my $data = "mary had a little lamb" ;
189 for my $trans ( 0, 1)
191 title "Non-compressed data with $TopType, Transparent => $trans ";
196 $a = $Func->(\$data, \$out, Transparent => $trans) ;
198 is $data, $keep, " Input buffer not changed" ;
202 ok $a, " $TopType returned true" ;
203 is $out, $data, " got expected output" ;
204 ok ! $$Error, " no error [$$Error]" ;
208 ok ! $a, " $TopType returned false" ;
209 #like $$Error, '/xxx/', " error" ;
210 ok $$Error, " error is '$$Error'" ;
215 foreach my $bit ($CompressClass
218 my $Error = getErrorRef($bit);
219 my $Func = getTopFuncRef($bit);
220 my $TopType = getTopFuncName($bit);
221 my $TopTypeInverse = getInverse($bit);
222 my $FuncInverse = getTopFuncRef($TopTypeInverse);
223 my $ErrorInverse = getErrorRef($TopTypeInverse);
225 title "$TopTypeInverse - corrupt data";
227 my $data = "abcd" x 100 ;
230 ok $Func->(\$data, \$out), " $TopType ok";
232 # corrupt the compressed data
233 #substr($out, -10, 10) = "x" x 10 ;
234 substr($out, int(length($out)/3), 10) = 'abcdeabcde';
237 ok ! $FuncInverse->(\$out => \$result, Transparent => 0), " $TopTypeInverse ok";
238 ok $$ErrorInverse, " Got error '$$ErrorInverse'" ;
240 #is $result, $data, " data ok";
242 ok ! anyuncompress(\$out => \$result, Transparent => 0), "anyuncompress ok";
243 ok $AnyUncompressError, " Got error '$AnyUncompressError'" ;
247 foreach my $bit ($CompressClass
250 my $Error = getErrorRef($bit);
251 my $Func = getTopFuncRef($bit);
252 my $TopType = getTopFuncName($bit);
253 my $TopTypeInverse = getInverse($bit);
254 my $FuncInverse = getTopFuncRef($TopTypeInverse);
257 @opts = (RawInflate => 1)
258 if $CompressClass eq 'IO::Compress::RawInflate';
260 for my $append ( 1, 0 )
263 $already = 'abcde' if $append ;
265 for my $buffer ( undef, '', "abcde" )
268 my $disp_content = defined $buffer ? $buffer : '<undef>' ;
271 my $out_file = "abcde.out";
272 my $in_file = "abcde.in";
275 title "$TopType - From Buff to Buff content '$disp_content' Append $append" ;
277 my $output = $already;
278 ok &$Func(\$buffer, \$output, Append => $append), ' Compressed ok' ;
280 is $keep, $buffer, " Input buffer not changed" ;
281 my $got = anyUncompress(\$output, $already);
282 $got = undef if ! defined $buffer && $got eq '' ;
283 is $got, $buffer, " Uncompressed matches original";
288 title "$TopType - From Buff to Array Ref content '$disp_content' Append $append" ;
290 my @output = ('first') ;
291 ok &$Func(\$buffer, \@output, Append => $append), ' Compressed ok' ;
293 is $output[0], 'first', " Array[0] unchanged";
294 is $keep, $buffer, " Input buffer not changed" ;
295 my $got = anyUncompress($output[1]);
296 $got = undef if ! defined $buffer && $got eq '' ;
297 is $got, $buffer, " Uncompressed matches original";
301 title "$TopType - From Array Ref to Array Ref content '$disp_content' Append $append" ;
303 my $lex = new LexFile my $in_file ;
304 writeFile($in_file, $buffer);
305 my @output = ('first') ;
306 my @input = ($in_file);
307 ok &$Func(\@input, \@output, Append => $append), ' Compressed ok' ;
309 is $output[0], 'first', " Array[0] unchanged";
310 my $got = anyUncompress($output[1]);
311 $got = undef if ! defined $buffer && $got eq '' ;
312 is $got, $buffer, " Uncompressed matches original";
316 title "$TopType - From Buff to Filename content '$disp_content' Append $append" ;
318 my $lex = new LexFile my $out_file ;
319 ok ! -e $out_file, " Output file does not exist";
320 writeFile($out_file, $already);
322 ok &$Func(\$buffer, $out_file, Append => $append), ' Compressed ok' ;
324 ok -e $out_file, " Created output file";
325 my $got = anyUncompress($out_file, $already);
326 $got = undef if ! defined $buffer && $got eq '' ;
327 is $got, $buffer, " Uncompressed matches original";
331 title "$TopType - From Buff to Handle content '$disp_content' Append $append" ;
333 my $lex = new LexFile my $out_file ;
335 ok ! -e $out_file, " Output file does not exist";
336 writeFile($out_file, $already);
337 my $of = new IO::File ">>$out_file" ;
338 ok $of, " Created output filehandle" ;
340 ok &$Func(\$buffer, $of, AutoClose => 1, Append => $append), ' Compressed ok' ;
342 ok -e $out_file, " Created output file";
343 my $got = anyUncompress($out_file, $already);
344 $got = undef if ! defined $buffer && $got eq '' ;
345 is $got, $buffer, " Uncompressed matches original";
350 title "$TopType - From Filename to Filename content '$disp_content' Append $append" ;
352 my $lex = new LexFile(my $in_file, my $out_file) ;
353 writeFile($in_file, $buffer);
355 ok ! -e $out_file, " Output file does not exist";
356 writeFile($out_file, $already);
358 ok &$Func($in_file => $out_file, Append => $append), ' Compressed ok' ;
360 ok -e $out_file, " Created output file";
361 my $got = anyUncompress($out_file, $already);
362 $got = undef if ! defined $buffer && $got eq '' ;
363 is $got, $buffer, " Uncompressed matches original";
368 title "$TopType - From Filename to Handle content '$disp_content' Append $append" ;
370 my $lex = new LexFile(my $in_file, my $out_file) ;
371 writeFile($in_file, $buffer);
373 ok ! -e $out_file, " Output file does not exist";
374 writeFile($out_file, $already);
375 my $out = new IO::File ">>$out_file" ;
377 ok &$Func($in_file, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
379 ok -e $out_file, " Created output file";
380 my $got = anyUncompress($out_file, $already);
381 $got = undef if ! defined $buffer && $got eq '' ;
382 is $got, $buffer, " Uncompressed matches original";
387 title "$TopType - From Filename to Buffer content '$disp_content' Append $append" ;
389 my $lex = new LexFile(my $in_file, my $out_file) ;
390 writeFile($in_file, $buffer);
394 ok &$Func($in_file => \$out, Append => $append), ' Compressed ok' ;
396 my $got = anyUncompress(\$out, $already);
397 $got = undef if ! defined $buffer && $got eq '' ;
398 is $got, $buffer, " Uncompressed matches original";
403 title "$TopType - From Handle to Filename content '$disp_content' Append $append" ;
405 my $lex = new LexFile(my $in_file, my $out_file) ;
406 writeFile($in_file, $buffer);
407 my $in = new IO::File "<$in_file" ;
409 ok ! -e $out_file, " Output file does not exist";
410 writeFile($out_file, $already);
412 ok &$Func($in, $out_file, Append => $append), ' Compressed ok'
413 or diag "error is $$Error" ;
415 ok -e $out_file, " Created output file";
416 my $got = anyUncompress($out_file, $already);
417 $got = undef if ! defined $buffer && $got eq '' ;
418 is $buffer, $got, " Uncompressed matches original";
423 title "$TopType - From Handle to Handle content '$disp_content' Append $append" ;
425 my $lex = new LexFile(my $in_file, my $out_file) ;
426 writeFile($in_file, $buffer);
427 my $in = new IO::File "<$in_file" ;
429 ok ! -e $out_file, " Output file does not exist";
430 writeFile($out_file, $already);
431 my $out = new IO::File ">>$out_file" ;
433 ok &$Func($in, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
435 ok -e $out_file, " Created output file";
436 my $got = anyUncompress($out_file, $already);
437 $got = undef if ! defined $buffer && $got eq '' ;
438 is $buffer, $got, " Uncompressed matches original";
443 title "$TopType - From Handle to Buffer content '$disp_content' Append $append" ;
445 my $lex = new LexFile(my $in_file, my $out_file) ;
446 writeFile($in_file, $buffer);
447 my $in = new IO::File "<$in_file" ;
451 ok &$Func($in, \$out, Append => $append), ' Compressed ok' ;
453 my $got = anyUncompress(\$out, $already);
454 $got = undef if ! defined $buffer && $got eq '' ;
455 is $buffer, $got, " Uncompressed matches original";
460 title "$TopType - From stdin (via '-') to Buffer content '$disp_content' Append $append" ;
462 my $lex = new LexFile(my $in_file, my $out_file) ;
463 writeFile($in_file, $buffer);
465 open(SAVEIN, "<&STDIN");
466 my $dummy = fileno SAVEIN ;
467 ok open(STDIN, "<$in_file"), " redirect STDIN";
471 ok &$Func('-', \$out, Append => $append), ' Compressed ok'
474 open(STDIN, "<&SAVEIN");
476 my $got = anyUncompress(\$out, $already);
477 $got = undef if ! defined $buffer && $got eq '' ;
478 is $buffer, $got, " Uncompressed matches original";
486 foreach my $bit ($CompressClass)
488 my $Error = getErrorRef($bit);
489 my $Func = getTopFuncRef($bit);
490 my $TopType = getTopFuncName($bit);
492 my $TopTypeInverse = getInverse($bit);
493 my $FuncInverse = getTopFuncRef($TopTypeInverse);
495 my $lex = new LexFile(my $file1, my $file2) ;
497 writeFile($file1, "data1");
498 writeFile($file2, "data2");
499 my $of = new IO::File "<$file1" ;
500 ok $of, " Created output filehandle" ;
502 #my @input = ( undef, "", $file2, \undef, \'', \"abcde", $of) ;
503 #my @expected = ("", "", $file2, "", "", "abcde", "data1");
504 #my @uexpected = ("", "", "data2", "", "", "abcde", "data1");
505 #my @input = ( $file2, \"abcde", $of) ;
506 #my @expected = ( $file2, "abcde", "data1");
507 #my @uexpected = ("data2", "abcde", "data1");
509 my @input = ( $file1, $file2) ;
510 #my @expected = ( $file1, $file2);
511 my @expected = ("data1", "data2");
512 my @uexpected = ("data1", "data2");
517 title "$TopType - From Array Ref to Array Ref" ;
519 my @output = ('first') ;
520 ok &$Func(\@input, \@output, AutoClose => 0), ' Compressed ok' ;
522 is $output[0], 'first', " Array[0] unchanged";
524 is_deeply \@input, \@keep, " Input array not changed" ;
525 my @got = shift @output;
526 foreach (@output) { push @got, anyUncompress($_) }
528 is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
532 foreach my $ms (@MultiValues)
535 title "$TopType - From Array Ref to Buffer, MultiStream $ms" ;
537 # rewind the filehandle
538 $of->open("<$file1") ;
541 ok &$Func(\@input, \$output, MultiStream => $ms, AutoClose => 0), ' Compressed ok'
544 my $got = anyUncompress([ \$output, MultiStream => $ms ]);
546 is $got, join('', @uexpected), " Got Expected uncompressed data";
547 my @headers = getHeaders(\$output);
548 is @headers, $ms ? @input : 1, " Header count ok";
552 title "$TopType - From Array Ref to Filename, MultiStream $ms" ;
554 my $lex = new LexFile( my $file3) ;
556 # rewind the filehandle
557 $of->open("<$file1") ;
560 ok &$Func(\@input, $file3, MultiStream => $ms, AutoClose => 0), ' Compressed ok' ;
562 my $got = anyUncompress([ $file3, MultiStream => $ms ]);
564 is $got, join('', @uexpected), " Got Expected uncompressed data";
565 my @headers = getHeaders($file3);
566 is @headers, $ms ? @input : 1, " Header count ok";
570 title "$TopType - From Array Ref to Filehandle, MultiStream $ms" ;
572 my $lex = new LexFile(my $file3) ;
574 my $fh3 = new IO::File ">$file3";
576 # rewind the filehandle
577 $of->open("<$file1") ;
580 ok &$Func(\@input, $fh3, MultiStream => $ms, AutoClose => 0), ' Compressed ok' ;
584 my $got = anyUncompress([ $file3, MultiStream => $ms ]);
586 is $got, join('', @uexpected), " Got Expected uncompressed data";
587 my @headers = getHeaders($file3);
588 is @headers, $ms ? @input : 1, " Header count ok";
593 foreach my $bit ($UncompressClass,
594 #'IO::Uncompress::AnyUncompress',
597 my $Error = getErrorRef($bit);
598 my $Func = getTopFuncRef($bit);
599 my $TopType = getTopFuncName($bit);
600 my $CompressClass = getInverse($bit);
601 my $C_Func = getTopFuncRef($CompressClass);
605 my $data = "mary had a little lamb" ;
607 my $extra = "after the main event";
609 foreach my $fb ( qw( filehandle buffer ) )
611 title "Trailingdata with $TopType, from $fb";
613 my $lex = new LexFile my $name ;
617 ok &$C_Func(\$data, \$compressed), ' Compressed ok' ;
618 $compressed .= $extra;
622 $input = \$compressed;
626 writeFile($name, $compressed);
628 $input = new IO::File "<$name" ;
633 ok $Func->($input, \$out, TrailingData => $trailing), " Uncompressed OK" ;
634 is $out, $keep, " Got uncompressed data";
637 if ($fb eq 'filehandle')
639 read($input, $rest, 10000) ;
642 is $trailing . $rest, $extra, " Got trailing data";
648 # foreach my $bit ($CompressClass)
650 # my $Error = getErrorRef($bit);
651 # my $Func = getTopFuncRef($bit);
652 # my $TopType = getTopFuncName($bit);
654 # my $TopTypeInverse = getInverse($bit);
655 # my $FuncInverse = getTopFuncRef($TopTypeInverse);
657 # my @inFiles = map { "in$_.tmp" } 1..4;
658 # my @outFiles = map { "out$_.tmp" } 1..4;
659 # my $lex = new LexFile(@inFiles, @outFiles);
661 # writeFile($_, "data $_") foreach @inFiles ;
664 # title "$TopType - Hash Ref: to filename" ;
667 # ok &$Func( { $inFiles[0] => $outFiles[0],
668 # $inFiles[1] => $outFiles[1],
669 # $inFiles[2] => $outFiles[2] } ), ' Compressed ok' ;
673 # my $got = anyUncompress($outFiles[$_]);
674 # is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
679 # title "$TopType - Hash Ref: to buffer" ;
682 # ok &$Func( { $inFiles[0] => \$buffer[0],
683 # $inFiles[1] => \$buffer[1],
684 # $inFiles[2] => \$buffer[2] } ), ' Compressed ok' ;
688 # my $got = anyUncompress(\$buffer[$_]);
689 # is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
694 # title "$TopType - Hash Ref: to undef" ;
697 # my %hash = ( $inFiles[0] => undef,
698 # $inFiles[1] => undef,
699 # $inFiles[2] => undef,
702 # ok &$Func( \%hash ), ' Compressed ok' ;
704 # foreach (keys %hash)
706 # my $got = anyUncompress(\$hash{$_});
707 # is $got, "data $_", " Uncompressed $_ matches original";
712 # title "$TopType - Filename to Hash Ref" ;
715 # ok &$Func( $inFiles[0] => \%output), ' Compressed ok' ;
717 # is keys %output, 1, " one pair in hash" ;
718 # my ($k, $v) = each %output;
719 # is $k, $inFiles[0], " key is '$inFiles[0]'";
720 # my $got = anyUncompress($v);
721 # is $got, "data $inFiles[0]", " Uncompressed matches original";
725 # title "$TopType - File Glob to Hash Ref" ;
728 # ok &$Func( '<in*.tmp>' => \%output), ' Compressed ok' ;
730 # is keys %output, 4, " four pairs in hash" ;
731 # foreach my $fil (@inFiles)
733 # ok exists $output{$fil}, " key '$fil' exists" ;
734 # my $got = anyUncompress($output{$fil});
735 # is $got, "data $fil", " Uncompressed matches original";
742 # foreach my $bit ($CompressClass)
744 # my $Error = getErrorRef($bit);
745 # my $Func = getTopFuncRef($bit);
746 # my $TopType = getTopFuncName($bit);
748 # my $TopTypeInverse = getInverse($bit);
749 # my $FuncInverse = getTopFuncRef($TopTypeInverse);
751 # my @inFiles = map { "in$_.tmp" } 1..4;
752 # my @outFiles = map { "out$_.tmp" } 1..4;
753 # my $lex = new LexFile(@inFiles, @outFiles);
755 # writeFile($_, "data $_") foreach @inFiles ;
761 # # title "$TopType - Hash Ref to Array Ref" ;
763 # # my @output = ('first') ;
764 # # ok &$Func( { \@input, \@output } , AutoClose => 0), ' Compressed ok' ;
766 # # is $output[0], 'first', " Array[0] unchanged";
768 # # is_deeply \@input, \@keep, " Input array not changed" ;
769 # # my @got = shift @output;
770 # # foreach (@output) { push @got, anyUncompress($_) }
772 # # is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
778 # # title "$TopType - From Array Ref to Buffer" ;
780 # # # rewind the filehandle
781 # # $of->open("<$file1") ;
784 # # ok &$Func(\@input, \$output, AutoClose => 0), ' Compressed ok' ;
786 # # my $got = anyUncompress(\$output);
788 # # is $got, join('', @expected), " Got Expected uncompressed data";
793 # # title "$TopType - From Array Ref to Filename" ;
795 # # my ($file3) = ("file3");
796 # # my $lex = new LexFile($file3) ;
798 # # # rewind the filehandle
799 # # $of->open("<$file1") ;
802 # # ok &$Func(\@input, $file3, AutoClose => 0), ' Compressed ok' ;
804 # # my $got = anyUncompress($file3);
806 # # is $got, join('', @expected), " Got Expected uncompressed data";
811 # # title "$TopType - From Array Ref to Filehandle" ;
813 # # my ($file3) = ("file3");
814 # # my $lex = new LexFile($file3) ;
816 # # my $fh3 = new IO::File ">$file3";
818 # # # rewind the filehandle
819 # # $of->open("<$file1") ;
822 # # ok &$Func(\@input, $fh3, AutoClose => 0), ' Compressed ok' ;
826 # # my $got = anyUncompress($file3);
828 # # is $got, join('', @expected), " Got Expected uncompressed data";
832 foreach my $bit ($CompressClass
835 my $Error = getErrorRef($bit);
836 my $Func = getTopFuncRef($bit);
837 my $TopType = getTopFuncName($bit);
839 for my $files ( [qw(a1)], [qw(a1 a2 a3)] )
842 my $tmpDir1 = 'tmpdir1';
843 my $tmpDir2 = 'tmpdir2';
844 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
846 mkdir $tmpDir1, 0777;
847 mkdir $tmpDir2, 0777;
849 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
850 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
852 my @files = map { "$tmpDir1/$_.tmp" } @$files ;
853 foreach (@files) { writeFile($_, "abc $_") }
855 my @expected = map { "abc $_" } @files ;
856 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
859 title "$TopType - From FileGlob to FileGlob files [@$files]" ;
861 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>"), ' Compressed ok'
864 my @copy = @expected;
865 for my $file (@outFiles)
867 is anyUncompress($file), shift @copy, " got expected from $file" ;
870 is @copy, 0, " got all files";
874 title "$TopType - From FileGlob to Array files [@$files]" ;
876 my @buffer = ('first') ;
877 ok &$Func("<$tmpDir1/a*.tmp>" => \@buffer), ' Compressed ok'
880 is shift @buffer, 'first';
882 my @copy = @expected;
883 for my $buffer (@buffer)
885 is anyUncompress($buffer), shift @copy, " got expected " ;
888 is @copy, 0, " got all files";
891 foreach my $ms (@MultiValues)
894 title "$TopType - From FileGlob to Buffer files [@$files], MS $ms" ;
897 ok &$Func("<$tmpDir1/a*.tmp>" => \$buffer,
898 MultiStream => $ms), ' Compressed ok'
903 my $got = anyUncompress([ \$buffer, MultiStream => $ms ]);
905 is $got, join("", @expected), " got expected" ;
906 my @headers = getHeaders(\$buffer);
907 is @headers, $ms ? @files : 1, " Header count ok";
911 title "$TopType - From FileGlob to Filename files [@$files], MS $ms" ;
913 my $filename = "abcde";
914 my $lex = new LexFile($filename) ;
916 ok &$Func("<$tmpDir1/a*.tmp>" => $filename,
917 MultiStream => $ms), ' Compressed ok'
922 my $got = anyUncompress([$filename, MultiStream => $ms]);
924 is $got, join("", @expected), " got expected" ;
925 my @headers = getHeaders($filename);
926 is @headers, $ms ? @files : 1, " Header count ok";
930 title "$TopType - From FileGlob to Filehandle files [@$files], MS $ms" ;
932 my $filename = "abcde";
933 my $lex = new LexFile($filename) ;
934 my $fh = new IO::File ">$filename";
936 ok &$Func("<$tmpDir1/a*.tmp>" => $fh,
937 MultiStream => $ms, AutoClose => 1), ' Compressed ok'
942 my $got = anyUncompress([$filename, MultiStream => $ms]);
944 is $got, join("", @expected), " got expected" ;
945 my @headers = getHeaders($filename);
946 is @headers, $ms ? @files : 1, " Header count ok";
953 foreach my $bit ($UncompressClass,
954 'IO::Uncompress::AnyUncompress',
957 my $Error = getErrorRef($bit);
958 my $Func = getTopFuncRef($bit);
959 my $TopType = getTopFuncName($bit);
961 my $buffer = "abcde" ;
962 my $buffer2 = "ABCDE" ;
963 my $keep_orig = $buffer;
965 my $comp = compressBuffer(getTopFuncName($UncompressClass), $buffer) ;
966 my $comp2 = compressBuffer(getTopFuncName($UncompressClass), $buffer2) ;
967 my $keep_comp = $comp;
969 my $incumbent = "incumbent data" ;
971 my @opts = (Strict => 1);
972 push @opts, (RawInflate => 1)
973 if $bit eq 'IO::Uncompress::AnyUncompress';
975 for my $append (0, 1)
977 my $expected = $buffer ;
978 $expected = $incumbent . $buffer if $append ;
981 title "$TopType - From Buff to Buff, Append($append)" ;
984 $output = $incumbent if $append ;
985 ok &$Func(\$comp, \$output, Append => $append, @opts), ' Uncompressed ok' ;
987 is $keep_comp, $comp, " Input buffer not changed" ;
988 is $output, $expected, " Uncompressed matches original";
992 title "$TopType - From Buff to Array, Append($append)" ;
994 my @output = ('first');
995 #$output = $incumbent if $append ;
996 ok &$Func(\$comp, \@output, Append => $append, @opts), ' Uncompressed ok' ;
998 is $keep_comp, $comp, " Input buffer not changed" ;
999 is $output[0], 'first', " Uncompressed matches original";
1000 is ${ $output[1] }, $buffer, " Uncompressed matches original"
1001 or diag $output[1] ;
1002 is @output, 2, " only 2 elements in the array" ;
1006 title "$TopType - From Buff to Filename, Append($append)" ;
1008 my $lex = new LexFile(my $out_file) ;
1010 { writeFile($out_file, $incumbent) }
1012 { ok ! -e $out_file, " Output file does not exist" }
1014 ok &$Func(\$comp, $out_file, Append => $append, @opts), ' Uncompressed ok' ;
1016 ok -e $out_file, " Created output file";
1017 my $content = readFile($out_file) ;
1019 is $keep_comp, $comp, " Input buffer not changed" ;
1020 is $content, $expected, " Uncompressed matches original";
1024 title "$TopType - From Buff to Handle, Append($append)" ;
1026 my $lex = new LexFile(my $out_file) ;
1029 writeFile($out_file, $incumbent) ;
1030 $of = new IO::File "+< $out_file" ;
1033 ok ! -e $out_file, " Output file does not exist" ;
1034 $of = new IO::File "> $out_file" ;
1036 isa_ok $of, 'IO::File', ' $of' ;
1038 ok &$Func(\$comp, $of, Append => $append, AutoClose => 1, @opts), ' Uncompressed ok' ;
1040 ok -e $out_file, " Created output file";
1041 my $content = readFile($out_file) ;
1043 is $keep_comp, $comp, " Input buffer not changed" ;
1044 is $content, $expected, " Uncompressed matches original";
1048 title "$TopType - From Filename to Filename, Append($append)" ;
1050 my $lex = new LexFile(my $in_file, my $out_file) ;
1052 { writeFile($out_file, $incumbent) }
1054 { ok ! -e $out_file, " Output file does not exist" }
1056 writeFile($in_file, $comp);
1058 ok &$Func($in_file, $out_file, Append => $append, @opts), ' Uncompressed ok' ;
1060 ok -e $out_file, " Created output file";
1061 my $content = readFile($out_file) ;
1063 is $keep_comp, $comp, " Input buffer not changed" ;
1064 is $content, $expected, " Uncompressed matches original";
1068 title "$TopType - From Filename to Handle, Append($append)" ;
1070 my $lex = new LexFile(my $in_file, my $out_file) ;
1073 writeFile($out_file, $incumbent) ;
1074 $out = new IO::File "+< $out_file" ;
1077 ok ! -e $out_file, " Output file does not exist" ;
1078 $out = new IO::File "> $out_file" ;
1080 isa_ok $out, 'IO::File', ' $out' ;
1082 writeFile($in_file, $comp);
1084 ok &$Func($in_file, $out, Append => $append, AutoClose => 1, @opts), ' Uncompressed ok' ;
1086 ok -e $out_file, " Created output file";
1087 my $content = readFile($out_file) ;
1089 is $keep_comp, $comp, " Input buffer not changed" ;
1090 is $content, $expected, " Uncompressed matches original";
1094 title "$TopType - From Filename to Buffer, Append($append)" ;
1096 my $lex = new LexFile(my $in_file) ;
1097 writeFile($in_file, $comp);
1100 $output = $incumbent if $append ;
1102 ok &$Func($in_file, \$output, Append => $append, @opts), ' Uncompressed ok' ;
1104 is $keep_comp, $comp, " Input buffer not changed" ;
1105 is $output, $expected, " Uncompressed matches original";
1109 title "$TopType - From Handle to Filename, Append($append)" ;
1111 my $lex = new LexFile(my $in_file, my $out_file) ;
1113 { writeFile($out_file, $incumbent) }
1115 { ok ! -e $out_file, " Output file does not exist" }
1117 writeFile($in_file, $comp);
1118 my $in = new IO::File "<$in_file" ;
1120 ok &$Func($in, $out_file, Append => $append, @opts), ' Uncompressed ok' ;
1122 ok -e $out_file, " Created output file";
1123 my $content = readFile($out_file) ;
1125 is $keep_comp, $comp, " Input buffer not changed" ;
1126 is $content, $expected, " Uncompressed matches original";
1130 title "$TopType - From Handle to Handle, Append($append)" ;
1132 my $lex = new LexFile(my $in_file, my $out_file) ;
1135 writeFile($out_file, $incumbent) ;
1136 $out = new IO::File "+< $out_file" ;
1139 ok ! -e $out_file, " Output file does not exist" ;
1140 $out = new IO::File "> $out_file" ;
1142 isa_ok $out, 'IO::File', ' $out' ;
1144 writeFile($in_file, $comp);
1145 my $in = new IO::File "<$in_file" ;
1147 ok &$Func($in, $out, Append => $append, AutoClose => 1, @opts), ' Uncompressed ok' ;
1149 ok -e $out_file, " Created output file";
1150 my $content = readFile($out_file) ;
1152 is $keep_comp, $comp, " Input buffer not changed" ;
1153 is $content, $expected, " Uncompressed matches original";
1157 title "$TopType - From Filename to Buffer, Append($append)" ;
1159 my $lex = new LexFile(my $in_file) ;
1160 writeFile($in_file, $comp);
1161 my $in = new IO::File "<$in_file" ;
1164 $output = $incumbent if $append ;
1166 ok &$Func($in, \$output, Append => $append, @opts), ' Uncompressed ok' ;
1168 is $keep_comp, $comp, " Input buffer not changed" ;
1169 is $output, $expected, " Uncompressed matches original";
1173 title "$TopType - From stdin (via '-') to Buffer content, Append($append) " ;
1175 my $lex = new LexFile(my $in_file) ;
1176 writeFile($in_file, $comp);
1178 open(SAVEIN, "<&STDIN");
1179 my $dummy = fileno SAVEIN ;
1180 ok open(STDIN, "<$in_file"), " redirect STDIN";
1183 $output = $incumbent if $append ;
1185 ok &$Func('-', \$output, Append => $append, @opts), ' Uncompressed ok'
1188 open(STDIN, "<&SAVEIN");
1190 is $keep_comp, $comp, " Input buffer not changed" ;
1191 is $output, $expected, " Uncompressed matches original";
1196 title "$TopType - From Handle to Buffer, InputLength" ;
1198 my $lex = new LexFile(my $in_file, my $out_file) ;
1201 my $expected = $buffer ;
1202 my $appended = 'appended';
1203 my $len_appended = length $appended;
1204 writeFile($in_file, $comp . $appended . $comp . $appended) ;
1205 my $in = new IO::File "<$in_file" ;
1207 ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp, @opts), ' Uncompressed ok' ;
1209 is $out, $expected, " Uncompressed matches original";
1212 is $in->read($buff, $len_appended), $len_appended, " Length of Appended data ok";
1213 is $buff, $appended, " Appended data ok";
1216 ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp, @opts), ' Uncompressed ok' ;
1218 is $out, $expected, " Uncompressed matches original";
1221 is $in->read($buff, $len_appended), $len_appended, " Length of Appended data ok";
1222 is $buff, $appended, " Appended data ok";
1225 for my $stdin ('-', *STDIN) # , \*STDIN)
1227 title "$TopType - From stdin (via $stdin) to Buffer content, InputLength" ;
1229 my $lex = new LexFile my $in_file ;
1230 my $expected = $buffer ;
1231 my $appended = 'appended';
1232 my $len_appended = length $appended;
1233 writeFile($in_file, $comp . $appended ) ;
1235 open(SAVEIN, "<&STDIN");
1236 my $dummy = fileno SAVEIN ;
1237 ok open(STDIN, "<$in_file"), " redirect STDIN";
1241 ok &$Func($stdin, \$output, Transparent => 0, InputLength => length $comp, @opts), ' Uncompressed ok'
1245 is read(STDIN, $buff, $len_appended), $len_appended, " Length of Appended data ok";
1247 is $output, $expected, " Uncompressed matches original";
1248 is $buff, $appended, " Appended data ok";
1250 open(STDIN, "<&SAVEIN");
1254 foreach my $bit ($UncompressClass,
1255 'IO::Uncompress::AnyUncompress',
1258 # TODO -- Add Append mode tests
1260 my $Error = getErrorRef($bit);
1261 my $Func = getTopFuncRef($bit);
1262 my $TopType = getTopFuncName($bit);
1264 my $buffer = "abcde" ;
1265 my $keep_orig = $buffer;
1267 my $null = compressBuffer(getTopFuncName($UncompressClass), "") ;
1268 my $undef = compressBuffer(getTopFuncName($UncompressClass), undef) ;
1269 my $comp = compressBuffer(getTopFuncName($UncompressClass), $buffer) ;
1270 my $keep_comp = $comp;
1273 @opts = (RawInflate => 1)
1274 if $bit eq 'IO::Uncompress::AnyUncompress';
1276 my $incumbent = "incumbent data" ;
1278 my $lex = new LexFile(my $file1, my $file2) ;
1280 writeFile($file1, compressBuffer(getTopFuncName($UncompressClass),"data1"));
1281 writeFile($file2, compressBuffer(getTopFuncName($UncompressClass),"data2"));
1283 my $of = new IO::File "<$file1" ;
1284 ok $of, " Created output filehandle" ;
1286 #my @input = ($file2, \$undef, \$null, \$comp, $of) ;
1287 #my @expected = ('data2', '', '', 'abcde', 'data1');
1288 my @input = ($file1, $file2);
1289 my @expected = ('data1', 'data2');
1294 title "$TopType - From ArrayRef to Buffer" ;
1297 ok &$Func(\@input, \$output, AutoClose => 0, @opts), ' UnCompressed ok' ;
1299 is $output, join('', @expected)
1303 title "$TopType - From ArrayRef to Filename" ;
1305 my $lex = new LexFile my $output;
1306 $of->open("<$file1") ;
1308 ok &$Func(\@input, $output, AutoClose => 0, @opts), ' UnCompressed ok' ;
1310 is readFile($output), join('', @expected)
1314 title "$TopType - From ArrayRef to Filehandle" ;
1316 my $lex = new LexFile my $output;
1317 my $fh = new IO::File ">$output" ;
1318 $of->open("<$file1") ;
1320 ok &$Func(\@input, $fh, AutoClose => 0, @opts), ' UnCompressed ok' ;
1323 is readFile($output), join('', @expected)
1327 title "$TopType - From Array Ref to Array Ref" ;
1329 my @output = (\'first') ;
1330 $of->open("<$file1") ;
1331 ok &$Func(\@input, \@output, AutoClose => 0, @opts), ' UnCompressed ok' ;
1333 is_deeply \@input, \@keep, " Input array not changed" ;
1334 is_deeply [map { defined $$_ ? $$_ : "" } @output],
1335 ['first', @expected],
1336 " Got Expected uncompressed data";
1341 foreach my $bit ($UncompressClass,
1342 'IO::Uncompress::AnyUncompress',
1345 # TODO -- Add Append mode tests
1347 my $Error = getErrorRef($bit);
1348 my $Func = getTopFuncRef($bit);
1349 my $TopType = getTopFuncName($bit);
1351 my $tmpDir1 = 'tmpdir1';
1352 my $tmpDir2 = 'tmpdir2';
1353 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
1355 mkdir $tmpDir1, 0777;
1356 mkdir $tmpDir2, 0777;
1359 @opts = (RawInflate => 1)
1360 if $bit eq 'IO::Uncompress::AnyUncompress';
1362 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
1363 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
1365 my @files = map { "$tmpDir1/$_.tmp" } qw( a1 a2 a3) ;
1366 foreach (@files) { writeFile($_, compressBuffer(getTopFuncName($UncompressClass), "abc $_")) }
1368 my @expected = map { "abc $_" } @files ;
1369 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
1372 title "$TopType - From FileGlob to FileGlob" ;
1374 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>", @opts), ' UnCompressed ok'
1377 my @copy = @expected;
1378 for my $file (@outFiles)
1380 is readFile($file), shift @copy, " got expected from $file" ;
1383 is @copy, 0, " got all files";
1387 title "$TopType - From FileGlob to Arrayref" ;
1389 my @output = (\'first');
1390 ok &$Func("<$tmpDir1/a*.tmp>" => \@output, @opts), ' UnCompressed ok'
1393 my @copy = ('first', @expected);
1394 for my $data (@output)
1396 is $$data, shift @copy, " got expected data" ;
1399 is @copy, 0, " got all files";
1403 title "$TopType - From FileGlob to Buffer" ;
1406 ok &$Func("<$tmpDir1/a*.tmp>" => \$output, @opts), ' UnCompressed ok'
1409 is $output, join('', @expected), " got expected uncompressed data";
1413 title "$TopType - From FileGlob to Filename" ;
1415 my $lex = new LexFile my $output ;
1416 ok ! -e $output, " $output does not exist" ;
1417 ok &$Func("<$tmpDir1/a*.tmp>" => $output, @opts), ' UnCompressed ok'
1420 ok -e $output, " $output does exist" ;
1421 is readFile($output), join('', @expected), " got expected uncompressed data";
1425 title "$TopType - From FileGlob to Filehandle" ;
1427 my $output = 'abc' ;
1428 my $lex = new LexFile $output ;
1429 my $fh = new IO::File ">$output" ;
1430 ok &$Func("<$tmpDir1/a*.tmp>" => $fh, AutoClose => 1, @opts), ' UnCompressed ok'
1433 ok -e $output, " $output does exist" ;
1434 is readFile($output), join('', @expected), " got expected uncompressed data";
1439 foreach my $TopType ($CompressClass
1440 # TODO -- add the inflate classes
1443 my $Error = getErrorRef($TopType);
1444 my $Func = getTopFuncRef($TopType);
1445 my $Name = getTopFuncName($TopType);
1447 title "More write tests" ;
1449 my $lex = new LexFile(my $file1, my $file2, my $file3) ;
1451 writeFile($file1, "F1");
1452 writeFile($file2, "F2");
1453 writeFile($file3, "F3");
1456 # [ '[\"ab", \"cd"]', "abcd" ],
1458 # [ '[\"a", $fh1, \"bc"]', "aF1bc"],
1462 # foreach my $data (@data)
1464 # my ($send, $get) = @$data ;
1466 # my $fh1 = new IO::File "< $file1" ;
1467 # my $fh2 = new IO::File "< $file2" ;
1468 # my $fh3 = new IO::File "< $file3" ;
1472 # eval "\$copy = $send";
1474 # ok &$Func($copy, \$Answer), " $Name ok";
1476 # my $got = anyUncompress(\$Answer);
1477 # is $got, $get, " got expected output" ;
1478 # ok ! $$Error, " no error"
1479 # or diag "Error is $$Error";
1483 title "Array Input Error tests" ;
1486 [ '[]', "empty array reference"],
1487 [ '[[]]', "unknown input parameter"],
1488 [ '[[[]]]', "unknown input parameter"],
1489 [ '[[\"ab"], [\"cd"]]', "unknown input parameter"],
1490 [ '[\""]', "not a filename"],
1491 [ '[\undef]', "not a filename"],
1492 [ '[\"abcd"]', "not a filename"],
1493 [ '[\&xx]', "unknown input parameter"],
1494 [ '[$fh2]', "not a filename"],
1498 foreach my $data (@data)
1500 my ($send, $get) = @$data ;
1502 my $fh1 = new IO::File "< $file1" ;
1503 my $fh2 = new IO::File "< $file2" ;
1504 my $fh3 = new IO::File "< $file3" ;
1508 eval "\$copy = $send";
1511 eval { $a = &$Func($copy, \$Answer) };
1512 ok ! $a, " $Name fails";
1514 is $$Error, $get, " got error message";
1524 foreach my $send (@data)
1528 eval "\$copy = $send";
1530 eval { &$Func($copy, \$Answer) } ;
1531 like $@, mkErr("^$TopFuncName: input filename is undef or null string"),
1532 " got error message";
1539 # TODO add more error cases