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';
100 # Threaded 5.6.x seems to have a problem comparing filehandles.
103 skip 'Cannot compare filehandles with threaded $]', 2
104 if $] >= 5.006 && $] < 5.007 && $Config{useithreads};
106 my $lex = new LexFile my $out_file ;
107 open OUT, ">$out_file" ;
108 eval { $a = $Func->(\*OUT, \*OUT) ;} ;
109 like $@, mkErr("^$TopType: input and output handle are identical"),
110 ' Input and Output handle are the same';
113 is -s $out_file, 0, " File zero length" ;
118 my $object = bless \%x, "someClass" ;
120 # Buffer not a scalar reference
121 #eval { $a = $Func->(\$x, \%x) ;} ;
122 eval { $a = $Func->(\$x, $object) ;} ;
123 like $@, mkErr("^$TopType: illegal output parameter"),
126 # Buffer not a scalar reference
127 eval { $a = $Func->(\$x, \%x) ;} ;
128 like $@, mkErr("^$TopType: illegal output parameter"),
132 eval { $a = $Func->(\%x, \$x) ;} ;
133 like $@, mkErr("^$TopType: illegal input parameter"),
136 #eval { $a = $Func->(\%x, \$x) ;} ;
137 eval { $a = $Func->($object, \$x) ;} ;
138 like $@, mkErr("^$TopType: illegal input parameter"),
142 my $filename = 'abc.def';
143 ok ! -e $filename, " input file '$filename' does not exist";
144 $a = $Func->($filename, \$x) ;
145 is $a, undef, " $TopType returned undef";
146 like $$Error, "/^input file '$filename' does not exist\$/", " input File '$filename' does not exist";
148 $filename = '/tmp/abd/abc.def';
149 ok ! -e $filename, " output File '$filename' does not exist";
150 $a = $Func->(\$x, $filename) ;
151 is $a, undef, " $TopType returned undef";
152 like $$Error, ("/^(cannot open file '$filename'|input file '$filename' does not exist):/"), " output File '$filename' does not exist";
154 eval { $a = $Func->(\$x, '<abc>') } ;
155 like $$Error, "/Need input fileglob for outout fileglob/",
156 ' Output fileglob with no input fileglob';
157 is $a, undef, " $TopType returned undef";
159 $a = $Func->('<abc)>', '<abc>') ;
160 is $a, undef, " $TopType returned undef";
161 like $$Error, "/Unmatched \\) in input fileglob/",
162 " Unmatched ) in input fileglob";
165 foreach my $bit ($UncompressClass,
166 'IO::Uncompress::AnyUncompress',
169 my $Error = getErrorRef($bit);
170 my $Func = getTopFuncRef($bit);
171 my $TopType = getTopFuncName($bit);
182 skip 'readonly + threads', 1
183 if $Config{useithreads};
186 eval { $a = $Func->(\$in, \$out, TrailingData => \"abc") ;} ;
187 like $@, mkErr("^$TopType: Parameter 'TrailingData' not writable"),
188 ' TrailingData output not writable';
191 eval { $a = $Func->(\$in, \$out, TrailingData => \@x) ;} ;
192 like $@, mkErr("^$TopType: Parameter 'TrailingData' not a scalar reference"),
193 ' TrailingData output not scaral reference';
197 foreach my $bit ($UncompressClass,
198 'IO::Uncompress::AnyUncompress',
201 my $Error = getErrorRef($bit);
202 my $Func = getTopFuncRef($bit);
203 my $TopType = getTopFuncName($bit);
205 my $data = "mary had a little lamb" ;
208 for my $trans ( 0, 1)
210 title "Non-compressed data with $TopType, Transparent => $trans ";
215 $a = $Func->(\$data, \$out, Transparent => $trans) ;
217 is $data, $keep, " Input buffer not changed" ;
221 ok $a, " $TopType returned true" ;
222 is $out, $data, " got expected output" ;
223 ok ! $$Error, " no error [$$Error]" ;
227 ok ! $a, " $TopType returned false" ;
228 #like $$Error, '/xxx/', " error" ;
229 ok $$Error, " error is '$$Error'" ;
234 foreach my $bit ($CompressClass
237 my $Error = getErrorRef($bit);
238 my $Func = getTopFuncRef($bit);
239 my $TopType = getTopFuncName($bit);
240 my $TopTypeInverse = getInverse($bit);
241 my $FuncInverse = getTopFuncRef($TopTypeInverse);
242 my $ErrorInverse = getErrorRef($TopTypeInverse);
244 title "$TopTypeInverse - corrupt data";
246 my $data = "abcd" x 100 ;
249 ok $Func->(\$data, \$out), " $TopType ok";
251 # corrupt the compressed data
252 #substr($out, -10, 10) = "x" x 10 ;
253 substr($out, int(length($out)/3), 10) = 'abcdeabcde';
256 ok ! $FuncInverse->(\$out => \$result, Transparent => 0), " $TopTypeInverse ok";
257 ok $$ErrorInverse, " Got error '$$ErrorInverse'" ;
259 #is $result, $data, " data ok";
261 ok ! anyuncompress(\$out => \$result, Transparent => 0), "anyuncompress ok";
262 ok $AnyUncompressError, " Got error '$AnyUncompressError'" ;
266 foreach my $bit ($CompressClass
269 my $Error = getErrorRef($bit);
270 my $Func = getTopFuncRef($bit);
271 my $TopType = getTopFuncName($bit);
272 my $TopTypeInverse = getInverse($bit);
273 my $FuncInverse = getTopFuncRef($TopTypeInverse);
276 @opts = (RawInflate => 1)
277 if $CompressClass eq 'IO::Compress::RawInflate';
279 for my $append ( 1, 0 )
282 $already = 'abcde' if $append ;
284 for my $buffer ( undef, '', "abcde" )
287 my $disp_content = defined $buffer ? $buffer : '<undef>' ;
290 my $out_file = "abcde.out";
291 my $in_file = "abcde.in";
294 title "$TopType - From Buff to Buff content '$disp_content' Append $append" ;
296 my $output = $already;
297 ok &$Func(\$buffer, \$output, Append => $append), ' Compressed ok' ;
299 is $keep, $buffer, " Input buffer not changed" ;
300 my $got = anyUncompress(\$output, $already);
301 $got = undef if ! defined $buffer && $got eq '' ;
302 is $got, $buffer, " Uncompressed matches original";
307 title "$TopType - From Buff to Array Ref content '$disp_content' Append $append" ;
309 my @output = ('first') ;
310 ok &$Func(\$buffer, \@output, Append => $append), ' Compressed ok' ;
312 is $output[0], 'first', " Array[0] unchanged";
313 is $keep, $buffer, " Input buffer not changed" ;
314 my $got = anyUncompress($output[1]);
315 $got = undef if ! defined $buffer && $got eq '' ;
316 is $got, $buffer, " Uncompressed matches original";
320 title "$TopType - From Array Ref to Array Ref content '$disp_content' Append $append" ;
322 my $lex = new LexFile my $in_file ;
323 writeFile($in_file, $buffer);
324 my @output = ('first') ;
325 my @input = ($in_file);
326 ok &$Func(\@input, \@output, Append => $append), ' Compressed ok' ;
328 is $output[0], 'first', " Array[0] unchanged";
329 my $got = anyUncompress($output[1]);
330 $got = undef if ! defined $buffer && $got eq '' ;
331 is $got, $buffer, " Uncompressed matches original";
335 title "$TopType - From Buff to Filename content '$disp_content' Append $append" ;
337 my $lex = new LexFile my $out_file ;
338 ok ! -e $out_file, " Output file does not exist";
339 writeFile($out_file, $already);
341 ok &$Func(\$buffer, $out_file, Append => $append), ' Compressed ok' ;
343 ok -e $out_file, " Created output file";
344 my $got = anyUncompress($out_file, $already);
345 $got = undef if ! defined $buffer && $got eq '' ;
346 is $got, $buffer, " Uncompressed matches original";
350 title "$TopType - From Buff to Handle content '$disp_content' Append $append" ;
352 my $lex = new LexFile my $out_file ;
354 ok ! -e $out_file, " Output file does not exist";
355 writeFile($out_file, $already);
356 my $of = new IO::File ">>$out_file" ;
357 ok $of, " Created output filehandle" ;
359 ok &$Func(\$buffer, $of, AutoClose => 1, Append => $append), ' Compressed ok' ;
361 ok -e $out_file, " Created output file";
362 my $got = anyUncompress($out_file, $already);
363 $got = undef if ! defined $buffer && $got eq '' ;
364 is $got, $buffer, " Uncompressed matches original";
369 title "$TopType - From Filename to Filename content '$disp_content' Append $append" ;
371 my $lex = new LexFile(my $in_file, my $out_file) ;
372 writeFile($in_file, $buffer);
374 ok ! -e $out_file, " Output file does not exist";
375 writeFile($out_file, $already);
377 ok &$Func($in_file => $out_file, 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 Handle content '$disp_content' Append $append" ;
389 my $lex = new LexFile(my $in_file, my $out_file) ;
390 writeFile($in_file, $buffer);
392 ok ! -e $out_file, " Output file does not exist";
393 writeFile($out_file, $already);
394 my $out = new IO::File ">>$out_file" ;
396 ok &$Func($in_file, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
398 ok -e $out_file, " Created output file";
399 my $got = anyUncompress($out_file, $already);
400 $got = undef if ! defined $buffer && $got eq '' ;
401 is $got, $buffer, " Uncompressed matches original";
406 title "$TopType - From Filename to Buffer content '$disp_content' Append $append" ;
408 my $lex = new LexFile(my $in_file, my $out_file) ;
409 writeFile($in_file, $buffer);
413 ok &$Func($in_file => \$out, Append => $append), ' Compressed ok' ;
415 my $got = anyUncompress(\$out, $already);
416 $got = undef if ! defined $buffer && $got eq '' ;
417 is $got, $buffer, " Uncompressed matches original";
422 title "$TopType - From Handle to Filename content '$disp_content' Append $append" ;
424 my $lex = new LexFile(my $in_file, my $out_file) ;
425 writeFile($in_file, $buffer);
426 my $in = new IO::File "<$in_file" ;
428 ok ! -e $out_file, " Output file does not exist";
429 writeFile($out_file, $already);
431 ok &$Func($in, $out_file, Append => $append), ' Compressed ok'
432 or diag "error is $$Error" ;
434 ok -e $out_file, " Created output file";
435 my $got = anyUncompress($out_file, $already);
436 $got = undef if ! defined $buffer && $got eq '' ;
437 is $buffer, $got, " Uncompressed matches original";
442 title "$TopType - From Handle to Handle content '$disp_content' Append $append" ;
444 my $lex = new LexFile(my $in_file, my $out_file) ;
445 writeFile($in_file, $buffer);
446 my $in = new IO::File "<$in_file" ;
448 ok ! -e $out_file, " Output file does not exist";
449 writeFile($out_file, $already);
450 my $out = new IO::File ">>$out_file" ;
452 ok &$Func($in, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
454 ok -e $out_file, " Created output file";
455 my $got = anyUncompress($out_file, $already);
456 $got = undef if ! defined $buffer && $got eq '' ;
457 is $buffer, $got, " Uncompressed matches original";
462 title "$TopType - From Handle to Buffer content '$disp_content' Append $append" ;
464 my $lex = new LexFile(my $in_file, my $out_file) ;
465 writeFile($in_file, $buffer);
466 my $in = new IO::File "<$in_file" ;
470 ok &$Func($in, \$out, Append => $append), ' Compressed ok' ;
472 my $got = anyUncompress(\$out, $already);
473 $got = undef if ! defined $buffer && $got eq '' ;
474 is $buffer, $got, " Uncompressed matches original";
479 title "$TopType - From stdin (via '-') to Buffer content '$disp_content' Append $append" ;
481 my $lex = new LexFile(my $in_file, my $out_file) ;
482 writeFile($in_file, $buffer);
484 open(SAVEIN, "<&STDIN");
485 my $dummy = fileno SAVEIN ;
486 ok open(STDIN, "<$in_file"), " redirect STDIN";
490 ok &$Func('-', \$out, Append => $append), ' Compressed ok'
493 open(STDIN, "<&SAVEIN");
495 my $got = anyUncompress(\$out, $already);
496 $got = undef if ! defined $buffer && $got eq '' ;
497 is $buffer, $got, " Uncompressed matches original";
505 foreach my $bit ($CompressClass)
507 my $Error = getErrorRef($bit);
508 my $Func = getTopFuncRef($bit);
509 my $TopType = getTopFuncName($bit);
511 my $TopTypeInverse = getInverse($bit);
512 my $FuncInverse = getTopFuncRef($TopTypeInverse);
514 my $lex = new LexFile(my $file1, my $file2) ;
516 writeFile($file1, "data1");
517 writeFile($file2, "data2");
518 my $of = new IO::File "<$file1" ;
519 ok $of, " Created output filehandle" ;
521 #my @input = ( undef, "", $file2, \undef, \'', \"abcde", $of) ;
522 #my @expected = ("", "", $file2, "", "", "abcde", "data1");
523 #my @uexpected = ("", "", "data2", "", "", "abcde", "data1");
524 #my @input = ( $file2, \"abcde", $of) ;
525 #my @expected = ( $file2, "abcde", "data1");
526 #my @uexpected = ("data2", "abcde", "data1");
528 my @input = ( $file1, $file2) ;
529 #my @expected = ( $file1, $file2);
530 my @expected = ("data1", "data2");
531 my @uexpected = ("data1", "data2");
536 title "$TopType - From Array Ref to Array Ref" ;
538 my @output = ('first') ;
539 ok &$Func(\@input, \@output, AutoClose => 0), ' Compressed ok' ;
541 is $output[0], 'first', " Array[0] unchanged";
543 is_deeply \@input, \@keep, " Input array not changed" ;
544 my @got = shift @output;
545 foreach (@output) { push @got, anyUncompress($_) }
547 is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
551 foreach my $ms (@MultiValues)
554 title "$TopType - From Array Ref to Buffer, MultiStream $ms" ;
556 # rewind the filehandle
557 $of->open("<$file1") ;
560 ok &$Func(\@input, \$output, MultiStream => $ms, AutoClose => 0), ' Compressed ok'
563 my $got = anyUncompress([ \$output, MultiStream => $ms ]);
565 is $got, join('', @uexpected), " Got Expected uncompressed data";
566 my @headers = getHeaders(\$output);
567 is @headers, $ms ? @input : 1, " Header count ok";
571 title "$TopType - From Array Ref to Filename, MultiStream $ms" ;
573 my $lex = new LexFile( my $file3) ;
575 # rewind the filehandle
576 $of->open("<$file1") ;
579 ok &$Func(\@input, $file3, MultiStream => $ms, AutoClose => 0), ' Compressed ok' ;
581 my $got = anyUncompress([ $file3, MultiStream => $ms ]);
583 is $got, join('', @uexpected), " Got Expected uncompressed data";
584 my @headers = getHeaders($file3);
585 is @headers, $ms ? @input : 1, " Header count ok";
589 title "$TopType - From Array Ref to Filehandle, MultiStream $ms" ;
591 my $lex = new LexFile(my $file3) ;
593 my $fh3 = new IO::File ">$file3";
595 # rewind the filehandle
596 $of->open("<$file1") ;
599 ok &$Func(\@input, $fh3, MultiStream => $ms, AutoClose => 0), ' Compressed ok' ;
603 my $got = anyUncompress([ $file3, MultiStream => $ms ]);
605 is $got, join('', @uexpected), " Got Expected uncompressed data";
606 my @headers = getHeaders($file3);
607 is @headers, $ms ? @input : 1, " Header count ok";
612 foreach my $bit ($UncompressClass,
613 #'IO::Uncompress::AnyUncompress',
616 my $Error = getErrorRef($bit);
617 my $Func = getTopFuncRef($bit);
618 my $TopType = getTopFuncName($bit);
619 my $CompressClass = getInverse($bit);
620 my $C_Func = getTopFuncRef($CompressClass);
624 my $data = "mary had a little lamb" ;
626 my $extra = "after the main event";
628 foreach my $fb ( qw( filehandle buffer ) )
630 title "Trailingdata with $TopType, from $fb";
632 my $lex = new LexFile my $name ;
636 ok &$C_Func(\$data, \$compressed), ' Compressed ok' ;
637 $compressed .= $extra;
641 $input = \$compressed;
645 writeFile($name, $compressed);
647 $input = new IO::File "<$name" ;
652 ok $Func->($input, \$out, TrailingData => $trailing), " Uncompressed OK" ;
653 is $out, $keep, " Got uncompressed data";
656 if ($fb eq 'filehandle')
658 read($input, $rest, 10000) ;
661 is $trailing . $rest, $extra, " Got trailing data";
667 # foreach my $bit ($CompressClass)
669 # my $Error = getErrorRef($bit);
670 # my $Func = getTopFuncRef($bit);
671 # my $TopType = getTopFuncName($bit);
673 # my $TopTypeInverse = getInverse($bit);
674 # my $FuncInverse = getTopFuncRef($TopTypeInverse);
676 # my @inFiles = map { "in$_.tmp" } 1..4;
677 # my @outFiles = map { "out$_.tmp" } 1..4;
678 # my $lex = new LexFile(@inFiles, @outFiles);
680 # writeFile($_, "data $_") foreach @inFiles ;
683 # title "$TopType - Hash Ref: to filename" ;
686 # ok &$Func( { $inFiles[0] => $outFiles[0],
687 # $inFiles[1] => $outFiles[1],
688 # $inFiles[2] => $outFiles[2] } ), ' Compressed ok' ;
692 # my $got = anyUncompress($outFiles[$_]);
693 # is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
698 # title "$TopType - Hash Ref: to buffer" ;
701 # ok &$Func( { $inFiles[0] => \$buffer[0],
702 # $inFiles[1] => \$buffer[1],
703 # $inFiles[2] => \$buffer[2] } ), ' Compressed ok' ;
707 # my $got = anyUncompress(\$buffer[$_]);
708 # is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
713 # title "$TopType - Hash Ref: to undef" ;
716 # my %hash = ( $inFiles[0] => undef,
717 # $inFiles[1] => undef,
718 # $inFiles[2] => undef,
721 # ok &$Func( \%hash ), ' Compressed ok' ;
723 # foreach (keys %hash)
725 # my $got = anyUncompress(\$hash{$_});
726 # is $got, "data $_", " Uncompressed $_ matches original";
731 # title "$TopType - Filename to Hash Ref" ;
734 # ok &$Func( $inFiles[0] => \%output), ' Compressed ok' ;
736 # is keys %output, 1, " one pair in hash" ;
737 # my ($k, $v) = each %output;
738 # is $k, $inFiles[0], " key is '$inFiles[0]'";
739 # my $got = anyUncompress($v);
740 # is $got, "data $inFiles[0]", " Uncompressed matches original";
744 # title "$TopType - File Glob to Hash Ref" ;
747 # ok &$Func( '<in*.tmp>' => \%output), ' Compressed ok' ;
749 # is keys %output, 4, " four pairs in hash" ;
750 # foreach my $fil (@inFiles)
752 # ok exists $output{$fil}, " key '$fil' exists" ;
753 # my $got = anyUncompress($output{$fil});
754 # is $got, "data $fil", " Uncompressed matches original";
761 # foreach my $bit ($CompressClass)
763 # my $Error = getErrorRef($bit);
764 # my $Func = getTopFuncRef($bit);
765 # my $TopType = getTopFuncName($bit);
767 # my $TopTypeInverse = getInverse($bit);
768 # my $FuncInverse = getTopFuncRef($TopTypeInverse);
770 # my @inFiles = map { "in$_.tmp" } 1..4;
771 # my @outFiles = map { "out$_.tmp" } 1..4;
772 # my $lex = new LexFile(@inFiles, @outFiles);
774 # writeFile($_, "data $_") foreach @inFiles ;
780 # # title "$TopType - Hash Ref to Array Ref" ;
782 # # my @output = ('first') ;
783 # # ok &$Func( { \@input, \@output } , AutoClose => 0), ' Compressed ok' ;
785 # # is $output[0], 'first', " Array[0] unchanged";
787 # # is_deeply \@input, \@keep, " Input array not changed" ;
788 # # my @got = shift @output;
789 # # foreach (@output) { push @got, anyUncompress($_) }
791 # # is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
797 # # title "$TopType - From Array Ref to Buffer" ;
799 # # # rewind the filehandle
800 # # $of->open("<$file1") ;
803 # # ok &$Func(\@input, \$output, AutoClose => 0), ' Compressed ok' ;
805 # # my $got = anyUncompress(\$output);
807 # # is $got, join('', @expected), " Got Expected uncompressed data";
812 # # title "$TopType - From Array Ref to Filename" ;
814 # # my ($file3) = ("file3");
815 # # my $lex = new LexFile($file3) ;
817 # # # rewind the filehandle
818 # # $of->open("<$file1") ;
821 # # ok &$Func(\@input, $file3, AutoClose => 0), ' Compressed ok' ;
823 # # my $got = anyUncompress($file3);
825 # # is $got, join('', @expected), " Got Expected uncompressed data";
830 # # title "$TopType - From Array Ref to Filehandle" ;
832 # # my ($file3) = ("file3");
833 # # my $lex = new LexFile($file3) ;
835 # # my $fh3 = new IO::File ">$file3";
837 # # # rewind the filehandle
838 # # $of->open("<$file1") ;
841 # # ok &$Func(\@input, $fh3, AutoClose => 0), ' Compressed ok' ;
845 # # my $got = anyUncompress($file3);
847 # # is $got, join('', @expected), " Got Expected uncompressed data";
851 foreach my $bit ($CompressClass
854 my $Error = getErrorRef($bit);
855 my $Func = getTopFuncRef($bit);
856 my $TopType = getTopFuncName($bit);
858 for my $files ( [qw(a1)], [qw(a1 a2 a3)] )
861 my $tmpDir1 = 'tmpdir1';
862 my $tmpDir2 = 'tmpdir2';
863 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
865 mkdir $tmpDir1, 0777;
866 mkdir $tmpDir2, 0777;
868 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
869 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
871 my @files = map { "$tmpDir1/$_.tmp" } @$files ;
872 foreach (@files) { writeFile($_, "abc $_") }
874 my @expected = map { "abc $_" } @files ;
875 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
878 title "$TopType - From FileGlob to FileGlob files [@$files]" ;
880 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>"), ' Compressed ok'
883 my @copy = @expected;
884 for my $file (@outFiles)
886 is anyUncompress($file), shift @copy, " got expected from $file" ;
889 is @copy, 0, " got all files";
893 title "$TopType - From FileGlob to Array files [@$files]" ;
895 my @buffer = ('first') ;
896 ok &$Func("<$tmpDir1/a*.tmp>" => \@buffer), ' Compressed ok'
899 is shift @buffer, 'first';
901 my @copy = @expected;
902 for my $buffer (@buffer)
904 is anyUncompress($buffer), shift @copy, " got expected " ;
907 is @copy, 0, " got all files";
910 foreach my $ms (@MultiValues)
913 title "$TopType - From FileGlob to Buffer files [@$files], MS $ms" ;
916 ok &$Func("<$tmpDir1/a*.tmp>" => \$buffer,
917 MultiStream => $ms), ' Compressed ok'
922 my $got = anyUncompress([ \$buffer, MultiStream => $ms ]);
924 is $got, join("", @expected), " got expected" ;
925 my @headers = getHeaders(\$buffer);
926 is @headers, $ms ? @files : 1, " Header count ok";
930 title "$TopType - From FileGlob to Filename files [@$files], MS $ms" ;
932 my $filename = "abcde";
933 my $lex = new LexFile($filename) ;
935 ok &$Func("<$tmpDir1/a*.tmp>" => $filename,
936 MultiStream => $ms), ' Compressed ok'
941 my $got = anyUncompress([$filename, MultiStream => $ms]);
943 is $got, join("", @expected), " got expected" ;
944 my @headers = getHeaders($filename);
945 is @headers, $ms ? @files : 1, " Header count ok";
949 title "$TopType - From FileGlob to Filehandle files [@$files], MS $ms" ;
951 my $filename = "abcde";
952 my $lex = new LexFile($filename) ;
953 my $fh = new IO::File ">$filename";
955 ok &$Func("<$tmpDir1/a*.tmp>" => $fh,
956 MultiStream => $ms, AutoClose => 1), ' Compressed ok'
961 my $got = anyUncompress([$filename, MultiStream => $ms]);
963 is $got, join("", @expected), " got expected" ;
964 my @headers = getHeaders($filename);
965 is @headers, $ms ? @files : 1, " Header count ok";
972 foreach my $bit ($UncompressClass,
973 'IO::Uncompress::AnyUncompress',
976 my $Error = getErrorRef($bit);
977 my $Func = getTopFuncRef($bit);
978 my $TopType = getTopFuncName($bit);
980 my $buffer = "abcde" ;
981 my $buffer2 = "ABCDE" ;
982 my $keep_orig = $buffer;
984 my $comp = compressBuffer(getTopFuncName($UncompressClass), $buffer) ;
985 my $comp2 = compressBuffer(getTopFuncName($UncompressClass), $buffer2) ;
986 my $keep_comp = $comp;
988 my $incumbent = "incumbent data" ;
990 my @opts = (Strict => 1);
991 push @opts, (RawInflate => 1)
992 if $bit eq 'IO::Uncompress::AnyUncompress';
994 for my $append (0, 1)
996 my $expected = $buffer ;
997 $expected = $incumbent . $buffer if $append ;
1000 title "$TopType - From Buff to Buff, Append($append)" ;
1003 $output = $incumbent if $append ;
1004 ok &$Func(\$comp, \$output, Append => $append, @opts), ' Uncompressed ok' ;
1006 is $keep_comp, $comp, " Input buffer not changed" ;
1007 is $output, $expected, " Uncompressed matches original";
1011 title "$TopType - From Buff to Array, Append($append)" ;
1013 my @output = ('first');
1014 #$output = $incumbent if $append ;
1015 ok &$Func(\$comp, \@output, Append => $append, @opts), ' Uncompressed ok' ;
1017 is $keep_comp, $comp, " Input buffer not changed" ;
1018 is $output[0], 'first', " Uncompressed matches original";
1019 is ${ $output[1] }, $buffer, " Uncompressed matches original"
1020 or diag $output[1] ;
1021 is @output, 2, " only 2 elements in the array" ;
1025 title "$TopType - From Buff to Filename, Append($append)" ;
1027 my $lex = new LexFile(my $out_file) ;
1029 { writeFile($out_file, $incumbent) }
1031 { ok ! -e $out_file, " Output file does not exist" }
1033 ok &$Func(\$comp, $out_file, Append => $append, @opts), ' Uncompressed ok' ;
1035 ok -e $out_file, " Created output file";
1036 my $content = readFile($out_file) ;
1038 is $keep_comp, $comp, " Input buffer not changed" ;
1039 is $content, $expected, " Uncompressed matches original";
1043 title "$TopType - From Buff to Handle, Append($append)" ;
1045 my $lex = new LexFile(my $out_file) ;
1048 writeFile($out_file, $incumbent) ;
1049 $of = new IO::File "+< $out_file" ;
1052 ok ! -e $out_file, " Output file does not exist" ;
1053 $of = new IO::File "> $out_file" ;
1055 isa_ok $of, 'IO::File', ' $of' ;
1057 ok &$Func(\$comp, $of, Append => $append, AutoClose => 1, @opts), ' Uncompressed ok' ;
1059 ok -e $out_file, " Created output file";
1060 my $content = readFile($out_file) ;
1062 is $keep_comp, $comp, " Input buffer not changed" ;
1063 is $content, $expected, " Uncompressed matches original";
1067 title "$TopType - From Filename to Filename, Append($append)" ;
1069 my $lex = new LexFile(my $in_file, my $out_file) ;
1071 { writeFile($out_file, $incumbent) }
1073 { ok ! -e $out_file, " Output file does not exist" }
1075 writeFile($in_file, $comp);
1077 ok &$Func($in_file, $out_file, Append => $append, @opts), ' Uncompressed ok' ;
1079 ok -e $out_file, " Created output file";
1080 my $content = readFile($out_file) ;
1082 is $keep_comp, $comp, " Input buffer not changed" ;
1083 is $content, $expected, " Uncompressed matches original";
1087 title "$TopType - From Filename to Handle, Append($append)" ;
1089 my $lex = new LexFile(my $in_file, my $out_file) ;
1092 writeFile($out_file, $incumbent) ;
1093 $out = new IO::File "+< $out_file" ;
1096 ok ! -e $out_file, " Output file does not exist" ;
1097 $out = new IO::File "> $out_file" ;
1099 isa_ok $out, 'IO::File', ' $out' ;
1101 writeFile($in_file, $comp);
1103 ok &$Func($in_file, $out, Append => $append, AutoClose => 1, @opts), ' Uncompressed ok' ;
1105 ok -e $out_file, " Created output file";
1106 my $content = readFile($out_file) ;
1108 is $keep_comp, $comp, " Input buffer not changed" ;
1109 is $content, $expected, " Uncompressed matches original";
1113 title "$TopType - From Filename to Buffer, Append($append)" ;
1115 my $lex = new LexFile(my $in_file) ;
1116 writeFile($in_file, $comp);
1119 $output = $incumbent if $append ;
1121 ok &$Func($in_file, \$output, Append => $append, @opts), ' Uncompressed ok' ;
1123 is $keep_comp, $comp, " Input buffer not changed" ;
1124 is $output, $expected, " Uncompressed matches original";
1128 title "$TopType - From Handle to Filename, Append($append)" ;
1130 my $lex = new LexFile(my $in_file, my $out_file) ;
1132 { writeFile($out_file, $incumbent) }
1134 { ok ! -e $out_file, " Output file does not exist" }
1136 writeFile($in_file, $comp);
1137 my $in = new IO::File "<$in_file" ;
1139 ok &$Func($in, $out_file, Append => $append, @opts), ' Uncompressed ok' ;
1141 ok -e $out_file, " Created output file";
1142 my $content = readFile($out_file) ;
1144 is $keep_comp, $comp, " Input buffer not changed" ;
1145 is $content, $expected, " Uncompressed matches original";
1149 title "$TopType - From Handle to Handle, Append($append)" ;
1151 my $lex = new LexFile(my $in_file, my $out_file) ;
1154 writeFile($out_file, $incumbent) ;
1155 $out = new IO::File "+< $out_file" ;
1158 ok ! -e $out_file, " Output file does not exist" ;
1159 $out = new IO::File "> $out_file" ;
1161 isa_ok $out, 'IO::File', ' $out' ;
1163 writeFile($in_file, $comp);
1164 my $in = new IO::File "<$in_file" ;
1166 ok &$Func($in, $out, Append => $append, AutoClose => 1, @opts), ' Uncompressed ok' ;
1168 ok -e $out_file, " Created output file";
1169 my $content = readFile($out_file) ;
1171 is $keep_comp, $comp, " Input buffer not changed" ;
1172 is $content, $expected, " Uncompressed matches original";
1176 title "$TopType - From Filename to Buffer, Append($append)" ;
1178 my $lex = new LexFile(my $in_file) ;
1179 writeFile($in_file, $comp);
1180 my $in = new IO::File "<$in_file" ;
1183 $output = $incumbent if $append ;
1185 ok &$Func($in, \$output, Append => $append, @opts), ' Uncompressed ok' ;
1187 is $keep_comp, $comp, " Input buffer not changed" ;
1188 is $output, $expected, " Uncompressed matches original";
1192 title "$TopType - From stdin (via '-') to Buffer content, Append($append) " ;
1194 my $lex = new LexFile(my $in_file) ;
1195 writeFile($in_file, $comp);
1197 open(SAVEIN, "<&STDIN");
1198 my $dummy = fileno SAVEIN ;
1199 ok open(STDIN, "<$in_file"), " redirect STDIN";
1202 $output = $incumbent if $append ;
1204 ok &$Func('-', \$output, Append => $append, @opts), ' Uncompressed ok'
1207 open(STDIN, "<&SAVEIN");
1209 is $keep_comp, $comp, " Input buffer not changed" ;
1210 is $output, $expected, " Uncompressed matches original";
1215 title "$TopType - From Handle to Buffer, InputLength" ;
1217 my $lex = new LexFile(my $in_file, my $out_file) ;
1220 my $expected = $buffer ;
1221 my $appended = 'appended';
1222 my $len_appended = length $appended;
1223 writeFile($in_file, $comp . $appended . $comp . $appended) ;
1224 my $in = new IO::File "<$in_file" ;
1226 ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp, @opts), ' Uncompressed ok' ;
1228 is $out, $expected, " Uncompressed matches original";
1231 is $in->read($buff, $len_appended), $len_appended, " Length of Appended data ok";
1232 is $buff, $appended, " Appended data ok";
1235 ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp, @opts), ' Uncompressed ok' ;
1237 is $out, $expected, " Uncompressed matches original";
1240 is $in->read($buff, $len_appended), $len_appended, " Length of Appended data ok";
1241 is $buff, $appended, " Appended data ok";
1244 for my $stdin ('-', *STDIN) # , \*STDIN)
1246 title "$TopType - From stdin (via $stdin) to Buffer content, InputLength" ;
1248 my $lex = new LexFile my $in_file ;
1249 my $expected = $buffer ;
1250 my $appended = 'appended';
1251 my $len_appended = length $appended;
1252 writeFile($in_file, $comp . $appended ) ;
1254 open(SAVEIN, "<&STDIN");
1255 my $dummy = fileno SAVEIN ;
1256 ok open(STDIN, "<$in_file"), " redirect STDIN";
1260 ok &$Func($stdin, \$output, Transparent => 0, InputLength => length $comp, @opts), ' Uncompressed ok'
1264 is read(STDIN, $buff, $len_appended), $len_appended, " Length of Appended data ok";
1266 is $output, $expected, " Uncompressed matches original";
1267 is $buff, $appended, " Appended data ok";
1269 open(STDIN, "<&SAVEIN");
1273 foreach my $bit ($UncompressClass,
1274 'IO::Uncompress::AnyUncompress',
1277 # TODO -- Add Append mode tests
1279 my $Error = getErrorRef($bit);
1280 my $Func = getTopFuncRef($bit);
1281 my $TopType = getTopFuncName($bit);
1283 my $buffer = "abcde" ;
1284 my $keep_orig = $buffer;
1286 my $null = compressBuffer(getTopFuncName($UncompressClass), "") ;
1287 my $undef = compressBuffer(getTopFuncName($UncompressClass), undef) ;
1288 my $comp = compressBuffer(getTopFuncName($UncompressClass), $buffer) ;
1289 my $keep_comp = $comp;
1292 @opts = (RawInflate => 1)
1293 if $bit eq 'IO::Uncompress::AnyUncompress';
1295 my $incumbent = "incumbent data" ;
1297 my $lex = new LexFile(my $file1, my $file2) ;
1299 writeFile($file1, compressBuffer(getTopFuncName($UncompressClass),"data1"));
1300 writeFile($file2, compressBuffer(getTopFuncName($UncompressClass),"data2"));
1302 my $of = new IO::File "<$file1" ;
1303 ok $of, " Created output filehandle" ;
1305 #my @input = ($file2, \$undef, \$null, \$comp, $of) ;
1306 #my @expected = ('data2', '', '', 'abcde', 'data1');
1307 my @input = ($file1, $file2);
1308 my @expected = ('data1', 'data2');
1313 title "$TopType - From ArrayRef to Buffer" ;
1316 ok &$Func(\@input, \$output, AutoClose => 0, @opts), ' UnCompressed ok' ;
1318 is $output, join('', @expected)
1322 title "$TopType - From ArrayRef to Filename" ;
1324 my $lex = new LexFile my $output;
1325 $of->open("<$file1") ;
1327 ok &$Func(\@input, $output, AutoClose => 0, @opts), ' UnCompressed ok' ;
1329 is readFile($output), join('', @expected)
1333 title "$TopType - From ArrayRef to Filehandle" ;
1335 my $lex = new LexFile my $output;
1336 my $fh = new IO::File ">$output" ;
1337 $of->open("<$file1") ;
1339 ok &$Func(\@input, $fh, AutoClose => 0, @opts), ' UnCompressed ok' ;
1342 is readFile($output), join('', @expected)
1346 title "$TopType - From Array Ref to Array Ref" ;
1348 my @output = (\'first') ;
1349 $of->open("<$file1") ;
1350 ok &$Func(\@input, \@output, AutoClose => 0, @opts), ' UnCompressed ok' ;
1352 is_deeply \@input, \@keep, " Input array not changed" ;
1353 is_deeply [map { defined $$_ ? $$_ : "" } @output],
1354 ['first', @expected],
1355 " Got Expected uncompressed data";
1360 foreach my $bit ($UncompressClass,
1361 'IO::Uncompress::AnyUncompress',
1364 # TODO -- Add Append mode tests
1366 my $Error = getErrorRef($bit);
1367 my $Func = getTopFuncRef($bit);
1368 my $TopType = getTopFuncName($bit);
1370 my $tmpDir1 = 'tmpdir1';
1371 my $tmpDir2 = 'tmpdir2';
1372 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
1374 mkdir $tmpDir1, 0777;
1375 mkdir $tmpDir2, 0777;
1378 @opts = (RawInflate => 1)
1379 if $bit eq 'IO::Uncompress::AnyUncompress';
1381 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
1382 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
1384 my @files = map { "$tmpDir1/$_.tmp" } qw( a1 a2 a3) ;
1385 foreach (@files) { writeFile($_, compressBuffer(getTopFuncName($UncompressClass), "abc $_")) }
1387 my @expected = map { "abc $_" } @files ;
1388 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
1391 title "$TopType - From FileGlob to FileGlob" ;
1393 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>", @opts), ' UnCompressed ok'
1396 my @copy = @expected;
1397 for my $file (@outFiles)
1399 is readFile($file), shift @copy, " got expected from $file" ;
1402 is @copy, 0, " got all files";
1406 title "$TopType - From FileGlob to Arrayref" ;
1408 my @output = (\'first');
1409 ok &$Func("<$tmpDir1/a*.tmp>" => \@output, @opts), ' UnCompressed ok'
1412 my @copy = ('first', @expected);
1413 for my $data (@output)
1415 is $$data, shift @copy, " got expected data" ;
1418 is @copy, 0, " got all files";
1422 title "$TopType - From FileGlob to Buffer" ;
1425 ok &$Func("<$tmpDir1/a*.tmp>" => \$output, @opts), ' UnCompressed ok'
1428 is $output, join('', @expected), " got expected uncompressed data";
1432 title "$TopType - From FileGlob to Filename" ;
1434 my $lex = new LexFile my $output ;
1435 ok ! -e $output, " $output does not exist" ;
1436 ok &$Func("<$tmpDir1/a*.tmp>" => $output, @opts), ' UnCompressed ok'
1439 ok -e $output, " $output does exist" ;
1440 is readFile($output), join('', @expected), " got expected uncompressed data";
1444 title "$TopType - From FileGlob to Filehandle" ;
1446 my $output = 'abc' ;
1447 my $lex = new LexFile $output ;
1448 my $fh = new IO::File ">$output" ;
1449 ok &$Func("<$tmpDir1/a*.tmp>" => $fh, AutoClose => 1, @opts), ' UnCompressed ok'
1452 ok -e $output, " $output does exist" ;
1453 is readFile($output), join('', @expected), " got expected uncompressed data";
1458 foreach my $TopType ($CompressClass
1459 # TODO -- add the inflate classes
1462 my $Error = getErrorRef($TopType);
1463 my $Func = getTopFuncRef($TopType);
1464 my $Name = getTopFuncName($TopType);
1466 title "More write tests" ;
1468 my $lex = new LexFile(my $file1, my $file2, my $file3) ;
1470 writeFile($file1, "F1");
1471 writeFile($file2, "F2");
1472 writeFile($file3, "F3");
1475 # [ '[\"ab", \"cd"]', "abcd" ],
1477 # [ '[\"a", $fh1, \"bc"]', "aF1bc"],
1481 # foreach my $data (@data)
1483 # my ($send, $get) = @$data ;
1485 # my $fh1 = new IO::File "< $file1" ;
1486 # my $fh2 = new IO::File "< $file2" ;
1487 # my $fh3 = new IO::File "< $file3" ;
1491 # eval "\$copy = $send";
1493 # ok &$Func($copy, \$Answer), " $Name ok";
1495 # my $got = anyUncompress(\$Answer);
1496 # is $got, $get, " got expected output" ;
1497 # ok ! $$Error, " no error"
1498 # or diag "Error is $$Error";
1502 title "Array Input Error tests" ;
1505 [ '[]', "empty array reference"],
1506 [ '[[]]', "unknown input parameter"],
1507 [ '[[[]]]', "unknown input parameter"],
1508 [ '[[\"ab"], [\"cd"]]', "unknown input parameter"],
1509 [ '[\""]', "not a filename"],
1510 [ '[\undef]', "not a filename"],
1511 [ '[\"abcd"]', "not a filename"],
1512 [ '[\&xx]', "unknown input parameter"],
1513 [ '[$fh2]', "not a filename"],
1517 foreach my $data (@data)
1519 my ($send, $get) = @$data ;
1521 my $fh1 = new IO::File "< $file1" ;
1522 my $fh2 = new IO::File "< $file2" ;
1523 my $fh3 = new IO::File "< $file3" ;
1527 eval "\$copy = $send";
1530 eval { $a = &$Func($copy, \$Answer) };
1531 ok ! $a, " $Name fails";
1533 is $$Error, $get, " got error message";
1543 foreach my $send (@data)
1547 eval "\$copy = $send";
1549 eval { &$Func($copy, \$Answer) } ;
1550 like $@, mkErr("^$TopFuncName: input filename is undef or null string"),
1551 " got error message";
1558 # TODO add more error cases