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);
172 skip 'readonly + threads', 1
173 if $Config{useithreads};
176 eval { $a = $Func->(\$in, \$out, TrailingData => \"abc") ;} ;
177 like $@, mkErr("^$TopType: Parameter 'TrailingData' not writable"),
178 ' TrailingData output not writable';
181 eval { $a = $Func->(\$in, \$out, TrailingData => \@x) ;} ;
182 like $@, mkErr("^$TopType: Parameter 'TrailingData' not a scalar reference"),
183 ' TrailingData output not scaral reference';
187 foreach my $bit ($UncompressClass,
188 'IO::Uncompress::AnyUncompress',
191 my $Error = getErrorRef($bit);
192 my $Func = getTopFuncRef($bit);
193 my $TopType = getTopFuncName($bit);
195 my $data = "mary had a little lamb" ;
198 for my $trans ( 0, 1)
200 title "Non-compressed data with $TopType, Transparent => $trans ";
205 $a = $Func->(\$data, \$out, Transparent => $trans) ;
207 is $data, $keep, " Input buffer not changed" ;
211 ok $a, " $TopType returned true" ;
212 is $out, $data, " got expected output" ;
213 ok ! $$Error, " no error [$$Error]" ;
217 ok ! $a, " $TopType returned false" ;
218 #like $$Error, '/xxx/', " error" ;
219 ok $$Error, " error is '$$Error'" ;
224 foreach my $bit ($CompressClass
227 my $Error = getErrorRef($bit);
228 my $Func = getTopFuncRef($bit);
229 my $TopType = getTopFuncName($bit);
230 my $TopTypeInverse = getInverse($bit);
231 my $FuncInverse = getTopFuncRef($TopTypeInverse);
232 my $ErrorInverse = getErrorRef($TopTypeInverse);
234 title "$TopTypeInverse - corrupt data";
236 my $data = "abcd" x 100 ;
239 ok $Func->(\$data, \$out), " $TopType ok";
241 # corrupt the compressed data
242 #substr($out, -10, 10) = "x" x 10 ;
243 substr($out, int(length($out)/3), 10) = 'abcdeabcde';
246 ok ! $FuncInverse->(\$out => \$result, Transparent => 0), " $TopTypeInverse ok";
247 ok $$ErrorInverse, " Got error '$$ErrorInverse'" ;
249 #is $result, $data, " data ok";
251 ok ! anyuncompress(\$out => \$result, Transparent => 0), "anyuncompress ok";
252 ok $AnyUncompressError, " Got error '$AnyUncompressError'" ;
256 foreach my $bit ($CompressClass
259 my $Error = getErrorRef($bit);
260 my $Func = getTopFuncRef($bit);
261 my $TopType = getTopFuncName($bit);
262 my $TopTypeInverse = getInverse($bit);
263 my $FuncInverse = getTopFuncRef($TopTypeInverse);
266 @opts = (RawInflate => 1)
267 if $CompressClass eq 'IO::Compress::RawInflate';
269 for my $append ( 1, 0 )
272 $already = 'abcde' if $append ;
274 for my $buffer ( undef, '', "abcde" )
277 my $disp_content = defined $buffer ? $buffer : '<undef>' ;
280 my $out_file = "abcde.out";
281 my $in_file = "abcde.in";
284 title "$TopType - From Buff to Buff content '$disp_content' Append $append" ;
286 my $output = $already;
287 ok &$Func(\$buffer, \$output, Append => $append), ' Compressed ok' ;
289 is $keep, $buffer, " Input buffer not changed" ;
290 my $got = anyUncompress(\$output, $already);
291 $got = undef if ! defined $buffer && $got eq '' ;
292 is $got, $buffer, " Uncompressed matches original";
297 title "$TopType - From Buff to Array Ref content '$disp_content' Append $append" ;
299 my @output = ('first') ;
300 ok &$Func(\$buffer, \@output, Append => $append), ' Compressed ok' ;
302 is $output[0], 'first', " Array[0] unchanged";
303 is $keep, $buffer, " Input buffer not changed" ;
304 my $got = anyUncompress($output[1]);
305 $got = undef if ! defined $buffer && $got eq '' ;
306 is $got, $buffer, " Uncompressed matches original";
310 title "$TopType - From Array Ref to Array Ref content '$disp_content' Append $append" ;
312 my $lex = new LexFile my $in_file ;
313 writeFile($in_file, $buffer);
314 my @output = ('first') ;
315 my @input = ($in_file);
316 ok &$Func(\@input, \@output, Append => $append), ' Compressed ok' ;
318 is $output[0], 'first', " Array[0] unchanged";
319 my $got = anyUncompress($output[1]);
320 $got = undef if ! defined $buffer && $got eq '' ;
321 is $got, $buffer, " Uncompressed matches original";
325 title "$TopType - From Buff to Filename content '$disp_content' Append $append" ;
327 my $lex = new LexFile my $out_file ;
328 ok ! -e $out_file, " Output file does not exist";
329 writeFile($out_file, $already);
331 ok &$Func(\$buffer, $out_file, Append => $append), ' Compressed ok' ;
333 ok -e $out_file, " Created output file";
334 my $got = anyUncompress($out_file, $already);
335 $got = undef if ! defined $buffer && $got eq '' ;
336 is $got, $buffer, " Uncompressed matches original";
340 title "$TopType - From Buff to Handle content '$disp_content' Append $append" ;
342 my $lex = new LexFile my $out_file ;
344 ok ! -e $out_file, " Output file does not exist";
345 writeFile($out_file, $already);
346 my $of = new IO::File ">>$out_file" ;
347 ok $of, " Created output filehandle" ;
349 ok &$Func(\$buffer, $of, 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 Filename content '$disp_content' Append $append" ;
361 my $lex = new LexFile(my $in_file, my $out_file) ;
362 writeFile($in_file, $buffer);
364 ok ! -e $out_file, " Output file does not exist";
365 writeFile($out_file, $already);
367 ok &$Func($in_file => $out_file, Append => $append), ' Compressed ok' ;
369 ok -e $out_file, " Created output file";
370 my $got = anyUncompress($out_file, $already);
371 $got = undef if ! defined $buffer && $got eq '' ;
372 is $got, $buffer, " Uncompressed matches original";
377 title "$TopType - From Filename to Handle content '$disp_content' Append $append" ;
379 my $lex = new LexFile(my $in_file, my $out_file) ;
380 writeFile($in_file, $buffer);
382 ok ! -e $out_file, " Output file does not exist";
383 writeFile($out_file, $already);
384 my $out = new IO::File ">>$out_file" ;
386 ok &$Func($in_file, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
388 ok -e $out_file, " Created output file";
389 my $got = anyUncompress($out_file, $already);
390 $got = undef if ! defined $buffer && $got eq '' ;
391 is $got, $buffer, " Uncompressed matches original";
396 title "$TopType - From Filename to Buffer content '$disp_content' Append $append" ;
398 my $lex = new LexFile(my $in_file, my $out_file) ;
399 writeFile($in_file, $buffer);
403 ok &$Func($in_file => \$out, Append => $append), ' Compressed ok' ;
405 my $got = anyUncompress(\$out, $already);
406 $got = undef if ! defined $buffer && $got eq '' ;
407 is $got, $buffer, " Uncompressed matches original";
412 title "$TopType - From Handle to Filename content '$disp_content' Append $append" ;
414 my $lex = new LexFile(my $in_file, my $out_file) ;
415 writeFile($in_file, $buffer);
416 my $in = new IO::File "<$in_file" ;
418 ok ! -e $out_file, " Output file does not exist";
419 writeFile($out_file, $already);
421 ok &$Func($in, $out_file, Append => $append), ' Compressed ok'
422 or diag "error is $$Error" ;
424 ok -e $out_file, " Created output file";
425 my $got = anyUncompress($out_file, $already);
426 $got = undef if ! defined $buffer && $got eq '' ;
427 is $buffer, $got, " Uncompressed matches original";
432 title "$TopType - From Handle to Handle content '$disp_content' Append $append" ;
434 my $lex = new LexFile(my $in_file, my $out_file) ;
435 writeFile($in_file, $buffer);
436 my $in = new IO::File "<$in_file" ;
438 ok ! -e $out_file, " Output file does not exist";
439 writeFile($out_file, $already);
440 my $out = new IO::File ">>$out_file" ;
442 ok &$Func($in, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
444 ok -e $out_file, " Created output file";
445 my $got = anyUncompress($out_file, $already);
446 $got = undef if ! defined $buffer && $got eq '' ;
447 is $buffer, $got, " Uncompressed matches original";
452 title "$TopType - From Handle to Buffer content '$disp_content' Append $append" ;
454 my $lex = new LexFile(my $in_file, my $out_file) ;
455 writeFile($in_file, $buffer);
456 my $in = new IO::File "<$in_file" ;
460 ok &$Func($in, \$out, Append => $append), ' Compressed ok' ;
462 my $got = anyUncompress(\$out, $already);
463 $got = undef if ! defined $buffer && $got eq '' ;
464 is $buffer, $got, " Uncompressed matches original";
469 title "$TopType - From stdin (via '-') to Buffer content '$disp_content' Append $append" ;
471 my $lex = new LexFile(my $in_file, my $out_file) ;
472 writeFile($in_file, $buffer);
474 open(SAVEIN, "<&STDIN");
475 my $dummy = fileno SAVEIN ;
476 ok open(STDIN, "<$in_file"), " redirect STDIN";
480 ok &$Func('-', \$out, Append => $append), ' Compressed ok'
483 open(STDIN, "<&SAVEIN");
485 my $got = anyUncompress(\$out, $already);
486 $got = undef if ! defined $buffer && $got eq '' ;
487 is $buffer, $got, " Uncompressed matches original";
495 foreach my $bit ($CompressClass)
497 my $Error = getErrorRef($bit);
498 my $Func = getTopFuncRef($bit);
499 my $TopType = getTopFuncName($bit);
501 my $TopTypeInverse = getInverse($bit);
502 my $FuncInverse = getTopFuncRef($TopTypeInverse);
504 my $lex = new LexFile(my $file1, my $file2) ;
506 writeFile($file1, "data1");
507 writeFile($file2, "data2");
508 my $of = new IO::File "<$file1" ;
509 ok $of, " Created output filehandle" ;
511 #my @input = ( undef, "", $file2, \undef, \'', \"abcde", $of) ;
512 #my @expected = ("", "", $file2, "", "", "abcde", "data1");
513 #my @uexpected = ("", "", "data2", "", "", "abcde", "data1");
514 #my @input = ( $file2, \"abcde", $of) ;
515 #my @expected = ( $file2, "abcde", "data1");
516 #my @uexpected = ("data2", "abcde", "data1");
518 my @input = ( $file1, $file2) ;
519 #my @expected = ( $file1, $file2);
520 my @expected = ("data1", "data2");
521 my @uexpected = ("data1", "data2");
526 title "$TopType - From Array Ref to Array Ref" ;
528 my @output = ('first') ;
529 ok &$Func(\@input, \@output, AutoClose => 0), ' Compressed ok' ;
531 is $output[0], 'first', " Array[0] unchanged";
533 is_deeply \@input, \@keep, " Input array not changed" ;
534 my @got = shift @output;
535 foreach (@output) { push @got, anyUncompress($_) }
537 is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
541 foreach my $ms (@MultiValues)
544 title "$TopType - From Array Ref to Buffer, MultiStream $ms" ;
546 # rewind the filehandle
547 $of->open("<$file1") ;
550 ok &$Func(\@input, \$output, MultiStream => $ms, AutoClose => 0), ' Compressed ok'
553 my $got = anyUncompress([ \$output, MultiStream => $ms ]);
555 is $got, join('', @uexpected), " Got Expected uncompressed data";
556 my @headers = getHeaders(\$output);
557 is @headers, $ms ? @input : 1, " Header count ok";
561 title "$TopType - From Array Ref to Filename, MultiStream $ms" ;
563 my $lex = new LexFile( my $file3) ;
565 # rewind the filehandle
566 $of->open("<$file1") ;
569 ok &$Func(\@input, $file3, MultiStream => $ms, AutoClose => 0), ' Compressed ok' ;
571 my $got = anyUncompress([ $file3, MultiStream => $ms ]);
573 is $got, join('', @uexpected), " Got Expected uncompressed data";
574 my @headers = getHeaders($file3);
575 is @headers, $ms ? @input : 1, " Header count ok";
579 title "$TopType - From Array Ref to Filehandle, MultiStream $ms" ;
581 my $lex = new LexFile(my $file3) ;
583 my $fh3 = new IO::File ">$file3";
585 # rewind the filehandle
586 $of->open("<$file1") ;
589 ok &$Func(\@input, $fh3, MultiStream => $ms, AutoClose => 0), ' Compressed ok' ;
593 my $got = anyUncompress([ $file3, MultiStream => $ms ]);
595 is $got, join('', @uexpected), " Got Expected uncompressed data";
596 my @headers = getHeaders($file3);
597 is @headers, $ms ? @input : 1, " Header count ok";
602 foreach my $bit ($UncompressClass,
603 #'IO::Uncompress::AnyUncompress',
606 my $Error = getErrorRef($bit);
607 my $Func = getTopFuncRef($bit);
608 my $TopType = getTopFuncName($bit);
609 my $CompressClass = getInverse($bit);
610 my $C_Func = getTopFuncRef($CompressClass);
614 my $data = "mary had a little lamb" ;
616 my $extra = "after the main event";
618 foreach my $fb ( qw( filehandle buffer ) )
620 title "Trailingdata with $TopType, from $fb";
622 my $lex = new LexFile my $name ;
626 ok &$C_Func(\$data, \$compressed), ' Compressed ok' ;
627 $compressed .= $extra;
631 $input = \$compressed;
635 writeFile($name, $compressed);
637 $input = new IO::File "<$name" ;
642 ok $Func->($input, \$out, TrailingData => $trailing), " Uncompressed OK" ;
643 is $out, $keep, " Got uncompressed data";
646 if ($fb eq 'filehandle')
648 read($input, $rest, 10000) ;
651 is $trailing . $rest, $extra, " Got trailing data";
657 # foreach my $bit ($CompressClass)
659 # my $Error = getErrorRef($bit);
660 # my $Func = getTopFuncRef($bit);
661 # my $TopType = getTopFuncName($bit);
663 # my $TopTypeInverse = getInverse($bit);
664 # my $FuncInverse = getTopFuncRef($TopTypeInverse);
666 # my @inFiles = map { "in$_.tmp" } 1..4;
667 # my @outFiles = map { "out$_.tmp" } 1..4;
668 # my $lex = new LexFile(@inFiles, @outFiles);
670 # writeFile($_, "data $_") foreach @inFiles ;
673 # title "$TopType - Hash Ref: to filename" ;
676 # ok &$Func( { $inFiles[0] => $outFiles[0],
677 # $inFiles[1] => $outFiles[1],
678 # $inFiles[2] => $outFiles[2] } ), ' Compressed ok' ;
682 # my $got = anyUncompress($outFiles[$_]);
683 # is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
688 # title "$TopType - Hash Ref: to buffer" ;
691 # ok &$Func( { $inFiles[0] => \$buffer[0],
692 # $inFiles[1] => \$buffer[1],
693 # $inFiles[2] => \$buffer[2] } ), ' Compressed ok' ;
697 # my $got = anyUncompress(\$buffer[$_]);
698 # is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
703 # title "$TopType - Hash Ref: to undef" ;
706 # my %hash = ( $inFiles[0] => undef,
707 # $inFiles[1] => undef,
708 # $inFiles[2] => undef,
711 # ok &$Func( \%hash ), ' Compressed ok' ;
713 # foreach (keys %hash)
715 # my $got = anyUncompress(\$hash{$_});
716 # is $got, "data $_", " Uncompressed $_ matches original";
721 # title "$TopType - Filename to Hash Ref" ;
724 # ok &$Func( $inFiles[0] => \%output), ' Compressed ok' ;
726 # is keys %output, 1, " one pair in hash" ;
727 # my ($k, $v) = each %output;
728 # is $k, $inFiles[0], " key is '$inFiles[0]'";
729 # my $got = anyUncompress($v);
730 # is $got, "data $inFiles[0]", " Uncompressed matches original";
734 # title "$TopType - File Glob to Hash Ref" ;
737 # ok &$Func( '<in*.tmp>' => \%output), ' Compressed ok' ;
739 # is keys %output, 4, " four pairs in hash" ;
740 # foreach my $fil (@inFiles)
742 # ok exists $output{$fil}, " key '$fil' exists" ;
743 # my $got = anyUncompress($output{$fil});
744 # is $got, "data $fil", " Uncompressed matches original";
751 # foreach my $bit ($CompressClass)
753 # my $Error = getErrorRef($bit);
754 # my $Func = getTopFuncRef($bit);
755 # my $TopType = getTopFuncName($bit);
757 # my $TopTypeInverse = getInverse($bit);
758 # my $FuncInverse = getTopFuncRef($TopTypeInverse);
760 # my @inFiles = map { "in$_.tmp" } 1..4;
761 # my @outFiles = map { "out$_.tmp" } 1..4;
762 # my $lex = new LexFile(@inFiles, @outFiles);
764 # writeFile($_, "data $_") foreach @inFiles ;
770 # # title "$TopType - Hash Ref to Array Ref" ;
772 # # my @output = ('first') ;
773 # # ok &$Func( { \@input, \@output } , AutoClose => 0), ' Compressed ok' ;
775 # # is $output[0], 'first', " Array[0] unchanged";
777 # # is_deeply \@input, \@keep, " Input array not changed" ;
778 # # my @got = shift @output;
779 # # foreach (@output) { push @got, anyUncompress($_) }
781 # # is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
787 # # title "$TopType - From Array Ref to Buffer" ;
789 # # # rewind the filehandle
790 # # $of->open("<$file1") ;
793 # # ok &$Func(\@input, \$output, AutoClose => 0), ' Compressed ok' ;
795 # # my $got = anyUncompress(\$output);
797 # # is $got, join('', @expected), " Got Expected uncompressed data";
802 # # title "$TopType - From Array Ref to Filename" ;
804 # # my ($file3) = ("file3");
805 # # my $lex = new LexFile($file3) ;
807 # # # rewind the filehandle
808 # # $of->open("<$file1") ;
811 # # ok &$Func(\@input, $file3, AutoClose => 0), ' Compressed ok' ;
813 # # my $got = anyUncompress($file3);
815 # # is $got, join('', @expected), " Got Expected uncompressed data";
820 # # title "$TopType - From Array Ref to Filehandle" ;
822 # # my ($file3) = ("file3");
823 # # my $lex = new LexFile($file3) ;
825 # # my $fh3 = new IO::File ">$file3";
827 # # # rewind the filehandle
828 # # $of->open("<$file1") ;
831 # # ok &$Func(\@input, $fh3, AutoClose => 0), ' Compressed ok' ;
835 # # my $got = anyUncompress($file3);
837 # # is $got, join('', @expected), " Got Expected uncompressed data";
841 foreach my $bit ($CompressClass
844 my $Error = getErrorRef($bit);
845 my $Func = getTopFuncRef($bit);
846 my $TopType = getTopFuncName($bit);
848 for my $files ( [qw(a1)], [qw(a1 a2 a3)] )
851 my $tmpDir1 = 'tmpdir1';
852 my $tmpDir2 = 'tmpdir2';
853 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
855 mkdir $tmpDir1, 0777;
856 mkdir $tmpDir2, 0777;
858 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
859 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
861 my @files = map { "$tmpDir1/$_.tmp" } @$files ;
862 foreach (@files) { writeFile($_, "abc $_") }
864 my @expected = map { "abc $_" } @files ;
865 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
868 title "$TopType - From FileGlob to FileGlob files [@$files]" ;
870 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>"), ' Compressed ok'
873 my @copy = @expected;
874 for my $file (@outFiles)
876 is anyUncompress($file), shift @copy, " got expected from $file" ;
879 is @copy, 0, " got all files";
883 title "$TopType - From FileGlob to Array files [@$files]" ;
885 my @buffer = ('first') ;
886 ok &$Func("<$tmpDir1/a*.tmp>" => \@buffer), ' Compressed ok'
889 is shift @buffer, 'first';
891 my @copy = @expected;
892 for my $buffer (@buffer)
894 is anyUncompress($buffer), shift @copy, " got expected " ;
897 is @copy, 0, " got all files";
900 foreach my $ms (@MultiValues)
903 title "$TopType - From FileGlob to Buffer files [@$files], MS $ms" ;
906 ok &$Func("<$tmpDir1/a*.tmp>" => \$buffer,
907 MultiStream => $ms), ' Compressed ok'
912 my $got = anyUncompress([ \$buffer, MultiStream => $ms ]);
914 is $got, join("", @expected), " got expected" ;
915 my @headers = getHeaders(\$buffer);
916 is @headers, $ms ? @files : 1, " Header count ok";
920 title "$TopType - From FileGlob to Filename files [@$files], MS $ms" ;
922 my $filename = "abcde";
923 my $lex = new LexFile($filename) ;
925 ok &$Func("<$tmpDir1/a*.tmp>" => $filename,
926 MultiStream => $ms), ' Compressed ok'
931 my $got = anyUncompress([$filename, MultiStream => $ms]);
933 is $got, join("", @expected), " got expected" ;
934 my @headers = getHeaders($filename);
935 is @headers, $ms ? @files : 1, " Header count ok";
939 title "$TopType - From FileGlob to Filehandle files [@$files], MS $ms" ;
941 my $filename = "abcde";
942 my $lex = new LexFile($filename) ;
943 my $fh = new IO::File ">$filename";
945 ok &$Func("<$tmpDir1/a*.tmp>" => $fh,
946 MultiStream => $ms, AutoClose => 1), ' Compressed ok'
951 my $got = anyUncompress([$filename, MultiStream => $ms]);
953 is $got, join("", @expected), " got expected" ;
954 my @headers = getHeaders($filename);
955 is @headers, $ms ? @files : 1, " Header count ok";
962 foreach my $bit ($UncompressClass,
963 'IO::Uncompress::AnyUncompress',
966 my $Error = getErrorRef($bit);
967 my $Func = getTopFuncRef($bit);
968 my $TopType = getTopFuncName($bit);
970 my $buffer = "abcde" ;
971 my $buffer2 = "ABCDE" ;
972 my $keep_orig = $buffer;
974 my $comp = compressBuffer(getTopFuncName($UncompressClass), $buffer) ;
975 my $comp2 = compressBuffer(getTopFuncName($UncompressClass), $buffer2) ;
976 my $keep_comp = $comp;
978 my $incumbent = "incumbent data" ;
980 my @opts = (Strict => 1);
981 push @opts, (RawInflate => 1)
982 if $bit eq 'IO::Uncompress::AnyUncompress';
984 for my $append (0, 1)
986 my $expected = $buffer ;
987 $expected = $incumbent . $buffer if $append ;
990 title "$TopType - From Buff to Buff, Append($append)" ;
993 $output = $incumbent if $append ;
994 ok &$Func(\$comp, \$output, Append => $append, @opts), ' Uncompressed ok' ;
996 is $keep_comp, $comp, " Input buffer not changed" ;
997 is $output, $expected, " Uncompressed matches original";
1001 title "$TopType - From Buff to Array, Append($append)" ;
1003 my @output = ('first');
1004 #$output = $incumbent if $append ;
1005 ok &$Func(\$comp, \@output, Append => $append, @opts), ' Uncompressed ok' ;
1007 is $keep_comp, $comp, " Input buffer not changed" ;
1008 is $output[0], 'first', " Uncompressed matches original";
1009 is ${ $output[1] }, $buffer, " Uncompressed matches original"
1010 or diag $output[1] ;
1011 is @output, 2, " only 2 elements in the array" ;
1015 title "$TopType - From Buff to Filename, Append($append)" ;
1017 my $lex = new LexFile(my $out_file) ;
1019 { writeFile($out_file, $incumbent) }
1021 { ok ! -e $out_file, " Output file does not exist" }
1023 ok &$Func(\$comp, $out_file, Append => $append, @opts), ' Uncompressed ok' ;
1025 ok -e $out_file, " Created output file";
1026 my $content = readFile($out_file) ;
1028 is $keep_comp, $comp, " Input buffer not changed" ;
1029 is $content, $expected, " Uncompressed matches original";
1033 title "$TopType - From Buff to Handle, Append($append)" ;
1035 my $lex = new LexFile(my $out_file) ;
1038 writeFile($out_file, $incumbent) ;
1039 $of = new IO::File "+< $out_file" ;
1042 ok ! -e $out_file, " Output file does not exist" ;
1043 $of = new IO::File "> $out_file" ;
1045 isa_ok $of, 'IO::File', ' $of' ;
1047 ok &$Func(\$comp, $of, Append => $append, AutoClose => 1, @opts), ' Uncompressed ok' ;
1049 ok -e $out_file, " Created output file";
1050 my $content = readFile($out_file) ;
1052 is $keep_comp, $comp, " Input buffer not changed" ;
1053 is $content, $expected, " Uncompressed matches original";
1057 title "$TopType - From Filename to Filename, Append($append)" ;
1059 my $lex = new LexFile(my $in_file, my $out_file) ;
1061 { writeFile($out_file, $incumbent) }
1063 { ok ! -e $out_file, " Output file does not exist" }
1065 writeFile($in_file, $comp);
1067 ok &$Func($in_file, $out_file, Append => $append, @opts), ' Uncompressed ok' ;
1069 ok -e $out_file, " Created output file";
1070 my $content = readFile($out_file) ;
1072 is $keep_comp, $comp, " Input buffer not changed" ;
1073 is $content, $expected, " Uncompressed matches original";
1077 title "$TopType - From Filename to Handle, Append($append)" ;
1079 my $lex = new LexFile(my $in_file, my $out_file) ;
1082 writeFile($out_file, $incumbent) ;
1083 $out = new IO::File "+< $out_file" ;
1086 ok ! -e $out_file, " Output file does not exist" ;
1087 $out = new IO::File "> $out_file" ;
1089 isa_ok $out, 'IO::File', ' $out' ;
1091 writeFile($in_file, $comp);
1093 ok &$Func($in_file, $out, Append => $append, AutoClose => 1, @opts), ' Uncompressed ok' ;
1095 ok -e $out_file, " Created output file";
1096 my $content = readFile($out_file) ;
1098 is $keep_comp, $comp, " Input buffer not changed" ;
1099 is $content, $expected, " Uncompressed matches original";
1103 title "$TopType - From Filename to Buffer, Append($append)" ;
1105 my $lex = new LexFile(my $in_file) ;
1106 writeFile($in_file, $comp);
1109 $output = $incumbent if $append ;
1111 ok &$Func($in_file, \$output, Append => $append, @opts), ' Uncompressed ok' ;
1113 is $keep_comp, $comp, " Input buffer not changed" ;
1114 is $output, $expected, " Uncompressed matches original";
1118 title "$TopType - From Handle to Filename, Append($append)" ;
1120 my $lex = new LexFile(my $in_file, my $out_file) ;
1122 { writeFile($out_file, $incumbent) }
1124 { ok ! -e $out_file, " Output file does not exist" }
1126 writeFile($in_file, $comp);
1127 my $in = new IO::File "<$in_file" ;
1129 ok &$Func($in, $out_file, Append => $append, @opts), ' Uncompressed ok' ;
1131 ok -e $out_file, " Created output file";
1132 my $content = readFile($out_file) ;
1134 is $keep_comp, $comp, " Input buffer not changed" ;
1135 is $content, $expected, " Uncompressed matches original";
1139 title "$TopType - From Handle to Handle, Append($append)" ;
1141 my $lex = new LexFile(my $in_file, my $out_file) ;
1144 writeFile($out_file, $incumbent) ;
1145 $out = new IO::File "+< $out_file" ;
1148 ok ! -e $out_file, " Output file does not exist" ;
1149 $out = new IO::File "> $out_file" ;
1151 isa_ok $out, 'IO::File', ' $out' ;
1153 writeFile($in_file, $comp);
1154 my $in = new IO::File "<$in_file" ;
1156 ok &$Func($in, $out, Append => $append, AutoClose => 1, @opts), ' Uncompressed ok' ;
1158 ok -e $out_file, " Created output file";
1159 my $content = readFile($out_file) ;
1161 is $keep_comp, $comp, " Input buffer not changed" ;
1162 is $content, $expected, " Uncompressed matches original";
1166 title "$TopType - From Filename to Buffer, Append($append)" ;
1168 my $lex = new LexFile(my $in_file) ;
1169 writeFile($in_file, $comp);
1170 my $in = new IO::File "<$in_file" ;
1173 $output = $incumbent if $append ;
1175 ok &$Func($in, \$output, Append => $append, @opts), ' Uncompressed ok' ;
1177 is $keep_comp, $comp, " Input buffer not changed" ;
1178 is $output, $expected, " Uncompressed matches original";
1182 title "$TopType - From stdin (via '-') to Buffer content, Append($append) " ;
1184 my $lex = new LexFile(my $in_file) ;
1185 writeFile($in_file, $comp);
1187 open(SAVEIN, "<&STDIN");
1188 my $dummy = fileno SAVEIN ;
1189 ok open(STDIN, "<$in_file"), " redirect STDIN";
1192 $output = $incumbent if $append ;
1194 ok &$Func('-', \$output, Append => $append, @opts), ' Uncompressed ok'
1197 open(STDIN, "<&SAVEIN");
1199 is $keep_comp, $comp, " Input buffer not changed" ;
1200 is $output, $expected, " Uncompressed matches original";
1205 title "$TopType - From Handle to Buffer, InputLength" ;
1207 my $lex = new LexFile(my $in_file, my $out_file) ;
1210 my $expected = $buffer ;
1211 my $appended = 'appended';
1212 my $len_appended = length $appended;
1213 writeFile($in_file, $comp . $appended . $comp . $appended) ;
1214 my $in = new IO::File "<$in_file" ;
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 ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp, @opts), ' Uncompressed ok' ;
1227 is $out, $expected, " Uncompressed matches original";
1230 is $in->read($buff, $len_appended), $len_appended, " Length of Appended data ok";
1231 is $buff, $appended, " Appended data ok";
1234 for my $stdin ('-', *STDIN) # , \*STDIN)
1236 title "$TopType - From stdin (via $stdin) to Buffer content, InputLength" ;
1238 my $lex = new LexFile my $in_file ;
1239 my $expected = $buffer ;
1240 my $appended = 'appended';
1241 my $len_appended = length $appended;
1242 writeFile($in_file, $comp . $appended ) ;
1244 open(SAVEIN, "<&STDIN");
1245 my $dummy = fileno SAVEIN ;
1246 ok open(STDIN, "<$in_file"), " redirect STDIN";
1250 ok &$Func($stdin, \$output, Transparent => 0, InputLength => length $comp, @opts), ' Uncompressed ok'
1254 is read(STDIN, $buff, $len_appended), $len_appended, " Length of Appended data ok";
1256 is $output, $expected, " Uncompressed matches original";
1257 is $buff, $appended, " Appended data ok";
1259 open(STDIN, "<&SAVEIN");
1263 foreach my $bit ($UncompressClass,
1264 'IO::Uncompress::AnyUncompress',
1267 # TODO -- Add Append mode tests
1269 my $Error = getErrorRef($bit);
1270 my $Func = getTopFuncRef($bit);
1271 my $TopType = getTopFuncName($bit);
1273 my $buffer = "abcde" ;
1274 my $keep_orig = $buffer;
1276 my $null = compressBuffer(getTopFuncName($UncompressClass), "") ;
1277 my $undef = compressBuffer(getTopFuncName($UncompressClass), undef) ;
1278 my $comp = compressBuffer(getTopFuncName($UncompressClass), $buffer) ;
1279 my $keep_comp = $comp;
1282 @opts = (RawInflate => 1)
1283 if $bit eq 'IO::Uncompress::AnyUncompress';
1285 my $incumbent = "incumbent data" ;
1287 my $lex = new LexFile(my $file1, my $file2) ;
1289 writeFile($file1, compressBuffer(getTopFuncName($UncompressClass),"data1"));
1290 writeFile($file2, compressBuffer(getTopFuncName($UncompressClass),"data2"));
1292 my $of = new IO::File "<$file1" ;
1293 ok $of, " Created output filehandle" ;
1295 #my @input = ($file2, \$undef, \$null, \$comp, $of) ;
1296 #my @expected = ('data2', '', '', 'abcde', 'data1');
1297 my @input = ($file1, $file2);
1298 my @expected = ('data1', 'data2');
1303 title "$TopType - From ArrayRef to Buffer" ;
1306 ok &$Func(\@input, \$output, AutoClose => 0, @opts), ' UnCompressed ok' ;
1308 is $output, join('', @expected)
1312 title "$TopType - From ArrayRef to Filename" ;
1314 my $lex = new LexFile my $output;
1315 $of->open("<$file1") ;
1317 ok &$Func(\@input, $output, AutoClose => 0, @opts), ' UnCompressed ok' ;
1319 is readFile($output), join('', @expected)
1323 title "$TopType - From ArrayRef to Filehandle" ;
1325 my $lex = new LexFile my $output;
1326 my $fh = new IO::File ">$output" ;
1327 $of->open("<$file1") ;
1329 ok &$Func(\@input, $fh, AutoClose => 0, @opts), ' UnCompressed ok' ;
1332 is readFile($output), join('', @expected)
1336 title "$TopType - From Array Ref to Array Ref" ;
1338 my @output = (\'first') ;
1339 $of->open("<$file1") ;
1340 ok &$Func(\@input, \@output, AutoClose => 0, @opts), ' UnCompressed ok' ;
1342 is_deeply \@input, \@keep, " Input array not changed" ;
1343 is_deeply [map { defined $$_ ? $$_ : "" } @output],
1344 ['first', @expected],
1345 " Got Expected uncompressed data";
1350 foreach my $bit ($UncompressClass,
1351 'IO::Uncompress::AnyUncompress',
1354 # TODO -- Add Append mode tests
1356 my $Error = getErrorRef($bit);
1357 my $Func = getTopFuncRef($bit);
1358 my $TopType = getTopFuncName($bit);
1360 my $tmpDir1 = 'tmpdir1';
1361 my $tmpDir2 = 'tmpdir2';
1362 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
1364 mkdir $tmpDir1, 0777;
1365 mkdir $tmpDir2, 0777;
1368 @opts = (RawInflate => 1)
1369 if $bit eq 'IO::Uncompress::AnyUncompress';
1371 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
1372 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
1374 my @files = map { "$tmpDir1/$_.tmp" } qw( a1 a2 a3) ;
1375 foreach (@files) { writeFile($_, compressBuffer(getTopFuncName($UncompressClass), "abc $_")) }
1377 my @expected = map { "abc $_" } @files ;
1378 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
1381 title "$TopType - From FileGlob to FileGlob" ;
1383 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>", @opts), ' UnCompressed ok'
1386 my @copy = @expected;
1387 for my $file (@outFiles)
1389 is readFile($file), shift @copy, " got expected from $file" ;
1392 is @copy, 0, " got all files";
1396 title "$TopType - From FileGlob to Arrayref" ;
1398 my @output = (\'first');
1399 ok &$Func("<$tmpDir1/a*.tmp>" => \@output, @opts), ' UnCompressed ok'
1402 my @copy = ('first', @expected);
1403 for my $data (@output)
1405 is $$data, shift @copy, " got expected data" ;
1408 is @copy, 0, " got all files";
1412 title "$TopType - From FileGlob to Buffer" ;
1415 ok &$Func("<$tmpDir1/a*.tmp>" => \$output, @opts), ' UnCompressed ok'
1418 is $output, join('', @expected), " got expected uncompressed data";
1422 title "$TopType - From FileGlob to Filename" ;
1424 my $lex = new LexFile my $output ;
1425 ok ! -e $output, " $output does not exist" ;
1426 ok &$Func("<$tmpDir1/a*.tmp>" => $output, @opts), ' UnCompressed ok'
1429 ok -e $output, " $output does exist" ;
1430 is readFile($output), join('', @expected), " got expected uncompressed data";
1434 title "$TopType - From FileGlob to Filehandle" ;
1436 my $output = 'abc' ;
1437 my $lex = new LexFile $output ;
1438 my $fh = new IO::File ">$output" ;
1439 ok &$Func("<$tmpDir1/a*.tmp>" => $fh, AutoClose => 1, @opts), ' UnCompressed ok'
1442 ok -e $output, " $output does exist" ;
1443 is readFile($output), join('', @expected), " got expected uncompressed data";
1448 foreach my $TopType ($CompressClass
1449 # TODO -- add the inflate classes
1452 my $Error = getErrorRef($TopType);
1453 my $Func = getTopFuncRef($TopType);
1454 my $Name = getTopFuncName($TopType);
1456 title "More write tests" ;
1458 my $lex = new LexFile(my $file1, my $file2, my $file3) ;
1460 writeFile($file1, "F1");
1461 writeFile($file2, "F2");
1462 writeFile($file3, "F3");
1465 # [ '[\"ab", \"cd"]', "abcd" ],
1467 # [ '[\"a", $fh1, \"bc"]', "aF1bc"],
1471 # foreach my $data (@data)
1473 # my ($send, $get) = @$data ;
1475 # my $fh1 = new IO::File "< $file1" ;
1476 # my $fh2 = new IO::File "< $file2" ;
1477 # my $fh3 = new IO::File "< $file3" ;
1481 # eval "\$copy = $send";
1483 # ok &$Func($copy, \$Answer), " $Name ok";
1485 # my $got = anyUncompress(\$Answer);
1486 # is $got, $get, " got expected output" ;
1487 # ok ! $$Error, " no error"
1488 # or diag "Error is $$Error";
1492 title "Array Input Error tests" ;
1495 [ '[]', "empty array reference"],
1496 [ '[[]]', "unknown input parameter"],
1497 [ '[[[]]]', "unknown input parameter"],
1498 [ '[[\"ab"], [\"cd"]]', "unknown input parameter"],
1499 [ '[\""]', "not a filename"],
1500 [ '[\undef]', "not a filename"],
1501 [ '[\"abcd"]', "not a filename"],
1502 [ '[\&xx]', "unknown input parameter"],
1503 [ '[$fh2]', "not a filename"],
1507 foreach my $data (@data)
1509 my ($send, $get) = @$data ;
1511 my $fh1 = new IO::File "< $file1" ;
1512 my $fh2 = new IO::File "< $file2" ;
1513 my $fh3 = new IO::File "< $file3" ;
1517 eval "\$copy = $send";
1520 eval { $a = &$Func($copy, \$Answer) };
1521 ok ! $a, " $Name fails";
1523 is $$Error, $get, " got error message";
1533 foreach my $send (@data)
1537 eval "\$copy = $send";
1539 eval { &$Func($copy, \$Answer) } ;
1540 like $@, mkErr("^$TopFuncName: input filename is undef or null string"),
1541 " got error message";
1548 # TODO add more error cases