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 => 986 + $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 #my $inverse = getInverse($bit);
46 #my $InverseFunc = getTopFuncRef($inverse);
48 title "Testing $TopType Error Cases";
53 eval { $a = $Func->(\$a => \$x, Fred => 1) ;} ;
54 like $@, mkErr("^$TopType: unknown key value\\(s\\) Fred"), ' Illegal Parameters';
56 eval { $a = $Func->() ;} ;
57 like $@, "/^$TopType: expected at least 1 parameters/", ' No Parameters';
59 eval { $a = $Func->(\$x, \1) ;} ;
60 like $$Error, "/^$TopType: output buffer is read-only/", ' Output is read-only' ;
63 eval { $a = $Func->($in, \$x) ;} ;
64 like $@, mkErr("^$TopType: input filename is undef or null string"),
65 ' Input filename undef' ;
68 eval { $a = $Func->($in, \$x) ;} ;
69 like $@, mkErr("^$TopType: input filename is undef or null string"),
70 ' Input filename empty' ;
73 my $lex1 = new LexFile my $in ;
74 writeFile($in, "abc");
76 eval { $a = $Func->($in, $out) ;} ;
77 like $@, mkErr("^$TopType: input and output filename are identical"),
78 ' Input and Output filename are the same';
83 my $lex = new LexDir $dir ;
86 $a = $Func->($dir, \$x) ;
87 is $a, undef, " $TopType returned undef";
88 like $$Error, "/input file '$dir' is a directory/",
89 ' Input filename is a directory';
91 $a = $Func->(\$x, $dir) ;
92 is $a, undef, " $TopType returned undef";
93 like $$Error, "/output file '$dir' is a directory/",
94 ' Output filename is a directory';
97 eval { $a = $Func->(\$in, \$in) ;} ;
98 like $@, mkErr("^$TopType: input and output buffer are identical"),
99 ' Input and Output buffer are the same';
103 # Threaded 5.6.x seems to have a problem comparing filehandles.
106 skip 'Cannot compare filehandles with threaded $]', 2
107 if $] >= 5.006 && $] < 5.007 && $Config{useithreads};
109 my $lex = new LexFile my $out_file ;
110 open OUT, ">$out_file" ;
111 eval { $a = $Func->(\*OUT, \*OUT) ;} ;
112 like $@, mkErr("^$TopType: input and output handle are identical"),
113 ' Input and Output handle are the same';
116 is -s $out_file, 0, " File zero length" ;
121 my $object = bless \%x, "someClass" ;
123 # Buffer not a scalar reference
124 #eval { $a = $Func->(\$x, \%x) ;} ;
125 eval { $a = $Func->(\$x, $object) ;} ;
126 like $@, mkErr("^$TopType: illegal output parameter"),
129 # Buffer not a scalar reference
130 eval { $a = $Func->(\$x, \%x) ;} ;
131 like $@, mkErr("^$TopType: illegal output parameter"),
135 eval { $a = $Func->(\%x, \$x) ;} ;
136 like $@, mkErr("^$TopType: illegal input parameter"),
139 #eval { $a = $Func->(\%x, \$x) ;} ;
140 eval { $a = $Func->($object, \$x) ;} ;
141 like $@, mkErr("^$TopType: illegal input parameter"),
145 my $filename = 'abc.def';
146 ok ! -e $filename, " input file '$filename' does not exist";
147 $a = $Func->($filename, \$x) ;
148 is $a, undef, " $TopType returned undef";
149 like $$Error, "/^input file '$filename' does not exist\$/", " input File '$filename' does not exist";
151 $filename = '/tmp/abd/abc.def';
152 ok ! -e $filename, " output File '$filename' does not exist";
153 $a = $Func->(\$x, $filename) ;
154 is $a, undef, " $TopType returned undef";
155 like $$Error, ("/^(cannot open file '$filename'|input file '$filename' does not exist):/"), " output File '$filename' does not exist";
157 eval { $a = $Func->(\$x, '<abc>') } ;
158 like $$Error, "/Need input fileglob for outout fileglob/",
159 ' Output fileglob with no input fileglob';
160 is $a, undef, " $TopType returned undef";
162 $a = $Func->('<abc)>', '<abc>') ;
163 is $a, undef, " $TopType returned undef";
164 like $$Error, "/Unmatched \\) in input fileglob/",
165 " Unmatched ) in input fileglob";
168 foreach my $bit ($UncompressClass,
169 'IO::Uncompress::AnyUncompress',
172 my $Error = getErrorRef($bit);
173 my $Func = getTopFuncRef($bit);
174 my $TopType = getTopFuncName($bit);
185 skip 'readonly + threads', 1
186 if $Config{useithreads};
189 eval { $a = $Func->(\$in, \$out, TrailingData => \"abc") ;} ;
190 like $@, mkErr("^$TopType: Parameter 'TrailingData' not writable"),
191 ' TrailingData output not writable';
194 eval { $a = $Func->(\$in, \$out, TrailingData => \@x) ;} ;
195 like $@, mkErr("^$TopType: Parameter 'TrailingData' not a scalar reference"),
196 ' TrailingData output not scalar reference';
200 foreach my $bit ($UncompressClass,
201 'IO::Uncompress::AnyUncompress',
204 my $Error = getErrorRef($bit);
205 my $Func = getTopFuncRef($bit);
206 my $TopType = getTopFuncName($bit);
208 my $data = "mary had a little lamb" ;
211 for my $trans ( 0, 1)
213 title "Non-compressed data with $TopType, Transparent => $trans ";
218 $a = $Func->(\$data, \$out, Transparent => $trans) ;
220 is $data, $keep, " Input buffer not changed" ;
224 ok $a, " $TopType returned true" ;
225 is $out, $data, " got expected output" ;
226 ok ! $$Error, " no error [$$Error]" ;
230 ok ! $a, " $TopType returned false" ;
231 #like $$Error, '/xxx/', " error" ;
232 ok $$Error, " error is '$$Error'" ;
237 foreach my $bit ($CompressClass
240 my $Error = getErrorRef($bit);
241 my $Func = getTopFuncRef($bit);
242 my $TopType = getTopFuncName($bit);
243 my $TopTypeInverse = getInverse($bit);
244 my $FuncInverse = getTopFuncRef($TopTypeInverse);
245 my $ErrorInverse = getErrorRef($TopTypeInverse);
247 title "$TopTypeInverse - corrupt data";
249 my $data = "abcd" x 100 ;
252 ok $Func->(\$data, \$out), " $TopType ok";
254 # corrupt the compressed data
255 #substr($out, -10, 10) = "x" x 10 ;
256 substr($out, int(length($out)/3), 10) = 'abcdeabcde';
259 ok ! $FuncInverse->(\$out => \$result, Transparent => 0), " $TopTypeInverse ok";
260 ok $$ErrorInverse, " Got error '$$ErrorInverse'" ;
262 #is $result, $data, " data ok";
264 ok ! anyuncompress(\$out => \$result, Transparent => 0), "anyuncompress ok";
265 ok $AnyUncompressError, " Got error '$AnyUncompressError'" ;
269 foreach my $bit ($CompressClass
272 my $Error = getErrorRef($bit);
273 my $Func = getTopFuncRef($bit);
274 my $TopType = getTopFuncName($bit);
275 my $TopTypeInverse = getInverse($bit);
276 my $FuncInverse = getTopFuncRef($TopTypeInverse);
279 @opts = (RawInflate => 1)
280 if $CompressClass eq 'IO::Compress::RawInflate';
282 for my $append ( 1, 0 )
285 $already = 'abcde' if $append ;
287 for my $buffer ( undef, '', "abcde" )
290 my $disp_content = defined $buffer ? $buffer : '<undef>' ;
293 my $out_file = "abcde.out";
294 my $in_file = "abcde.in";
297 title "$TopType - From Buff to Buff content '$disp_content' Append $append" ;
299 my $output = $already;
300 ok &$Func(\$buffer, \$output, Append => $append), ' Compressed ok' ;
302 is $keep, $buffer, " Input buffer not changed" ;
303 my $got = anyUncompress(\$output, $already);
304 $got = undef if ! defined $buffer && $got eq '' ;
305 is $got, $buffer, " Uncompressed matches original";
310 title "$TopType - From Buff to Array Ref content '$disp_content' Append $append" ;
312 my @output = ('first') ;
313 ok &$Func(\$buffer, \@output, Append => $append), ' Compressed ok' ;
315 is $output[0], 'first', " Array[0] unchanged";
316 is $keep, $buffer, " Input buffer not changed" ;
317 my $got = anyUncompress($output[1]);
318 $got = undef if ! defined $buffer && $got eq '' ;
319 is $got, $buffer, " Uncompressed matches original";
323 title "$TopType - From Array Ref to Array Ref content '$disp_content' Append $append" ;
325 my $lex = new LexFile my $in_file ;
326 writeFile($in_file, $buffer);
327 my @output = ('first') ;
328 my @input = ($in_file);
329 ok &$Func(\@input, \@output, Append => $append), ' Compressed ok' ;
331 is $output[0], 'first', " Array[0] unchanged";
332 my $got = anyUncompress($output[1]);
333 $got = undef if ! defined $buffer && $got eq '' ;
334 is $got, $buffer, " Uncompressed matches original";
338 title "$TopType - From Buff to Filename content '$disp_content' Append $append" ;
340 my $lex = new LexFile my $out_file ;
341 ok ! -e $out_file, " Output file does not exist";
342 writeFile($out_file, $already);
344 ok &$Func(\$buffer, $out_file, Append => $append), ' Compressed ok' ;
346 ok -e $out_file, " Created output file";
347 my $got = anyUncompress($out_file, $already);
348 $got = undef if ! defined $buffer && $got eq '' ;
349 is $got, $buffer, " Uncompressed matches original";
353 title "$TopType - From Buff to Handle content '$disp_content' Append $append" ;
355 my $lex = new LexFile my $out_file ;
357 ok ! -e $out_file, " Output file does not exist";
358 writeFile($out_file, $already);
359 my $of = new IO::File ">>$out_file" ;
360 ok $of, " Created output filehandle" ;
362 ok &$Func(\$buffer, $of, AutoClose => 1, Append => $append), ' Compressed ok' ;
364 ok -e $out_file, " Created output file";
365 my $got = anyUncompress($out_file, $already);
366 $got = undef if ! defined $buffer && $got eq '' ;
367 is $got, $buffer, " Uncompressed matches original";
372 title "$TopType - From Filename to Filename content '$disp_content' Append $append" ;
374 my $lex = new LexFile(my $in_file, my $out_file) ;
375 writeFile($in_file, $buffer);
377 ok ! -e $out_file, " Output file does not exist";
378 writeFile($out_file, $already);
380 ok &$Func($in_file => $out_file, Append => $append), ' Compressed ok' ;
382 ok -e $out_file, " Created output file";
383 my $got = anyUncompress($out_file, $already);
384 $got = undef if ! defined $buffer && $got eq '' ;
385 is $got, $buffer, " Uncompressed matches original";
390 title "$TopType - From Filename to Handle content '$disp_content' Append $append" ;
392 my $lex = new LexFile(my $in_file, my $out_file) ;
393 writeFile($in_file, $buffer);
395 ok ! -e $out_file, " Output file does not exist";
396 writeFile($out_file, $already);
397 my $out = new IO::File ">>$out_file" ;
399 ok &$Func($in_file, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
401 ok -e $out_file, " Created output file";
402 my $got = anyUncompress($out_file, $already);
403 $got = undef if ! defined $buffer && $got eq '' ;
404 is $got, $buffer, " Uncompressed matches original";
409 title "$TopType - From Filename to Buffer content '$disp_content' Append $append" ;
411 my $lex = new LexFile(my $in_file, my $out_file) ;
412 writeFile($in_file, $buffer);
416 ok &$Func($in_file => \$out, Append => $append), ' Compressed ok' ;
418 my $got = anyUncompress(\$out, $already);
419 $got = undef if ! defined $buffer && $got eq '' ;
420 is $got, $buffer, " Uncompressed matches original";
425 title "$TopType - From Handle to Filename content '$disp_content' Append $append" ;
427 my $lex = new LexFile(my $in_file, my $out_file) ;
428 writeFile($in_file, $buffer);
429 my $in = new IO::File "<$in_file" ;
431 ok ! -e $out_file, " Output file does not exist";
432 writeFile($out_file, $already);
434 ok &$Func($in, $out_file, Append => $append), ' Compressed ok'
435 or diag "error is $$Error" ;
437 ok -e $out_file, " Created output file";
438 my $got = anyUncompress($out_file, $already);
439 $got = undef if ! defined $buffer && $got eq '' ;
440 is $buffer, $got, " Uncompressed matches original";
445 title "$TopType - From Handle to Handle content '$disp_content' Append $append" ;
447 my $lex = new LexFile(my $in_file, my $out_file) ;
448 writeFile($in_file, $buffer);
449 my $in = new IO::File "<$in_file" ;
451 ok ! -e $out_file, " Output file does not exist";
452 writeFile($out_file, $already);
453 my $out = new IO::File ">>$out_file" ;
455 ok &$Func($in, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
457 ok -e $out_file, " Created output file";
458 my $got = anyUncompress($out_file, $already);
459 $got = undef if ! defined $buffer && $got eq '' ;
460 is $buffer, $got, " Uncompressed matches original";
465 title "$TopType - From Handle to Buffer content '$disp_content' Append $append" ;
467 my $lex = new LexFile(my $in_file, my $out_file) ;
468 writeFile($in_file, $buffer);
469 my $in = new IO::File "<$in_file" ;
473 ok &$Func($in, \$out, Append => $append), ' Compressed ok' ;
475 my $got = anyUncompress(\$out, $already);
476 $got = undef if ! defined $buffer && $got eq '' ;
477 is $buffer, $got, " Uncompressed matches original";
482 title "$TopType - From stdin (via '-') to Buffer content '$disp_content' Append $append" ;
484 my $lex = new LexFile(my $in_file, my $out_file) ;
485 writeFile($in_file, $buffer);
487 open(SAVEIN, "<&STDIN");
488 my $dummy = fileno SAVEIN ;
489 ok open(STDIN, "<$in_file"), " redirect STDIN";
493 ok &$Func('-', \$out, Append => $append), ' Compressed ok'
496 open(STDIN, "<&SAVEIN");
498 my $got = anyUncompress(\$out, $already);
499 $got = undef if ! defined $buffer && $got eq '' ;
500 is $buffer, $got, " Uncompressed matches original";
508 foreach my $bit ($CompressClass)
510 my $Error = getErrorRef($bit);
511 my $Func = getTopFuncRef($bit);
512 my $TopType = getTopFuncName($bit);
514 my $TopTypeInverse = getInverse($bit);
515 my $FuncInverse = getTopFuncRef($TopTypeInverse);
516 my $ErrorInverse = getErrorRef($TopTypeInverse);
518 my $lex = new LexFile(my $file1, my $file2) ;
520 writeFile($file1, "data1");
521 writeFile($file2, "data2");
522 my $of = new IO::File "<$file1" ;
523 ok $of, " Created output filehandle" ;
525 #my @input = ( undef, "", $file2, \undef, \'', \"abcde", $of) ;
526 #my @expected = ("", "", $file2, "", "", "abcde", "data1");
527 #my @uexpected = ("", "", "data2", "", "", "abcde", "data1");
528 #my @input = ( $file2, \"abcde", $of) ;
529 #my @expected = ( $file2, "abcde", "data1");
530 #my @uexpected = ("data2", "abcde", "data1");
532 my @input = ( $file1, $file2) ;
533 #my @expected = ( $file1, $file2);
534 my @expected = ("data1", "data2");
535 my @uexpected = ("data1", "data2");
540 title "$TopType - From Array Ref to Array Ref" ;
542 my @output = ('first') ;
543 ok &$Func(\@input, \@output, AutoClose => 0), ' Compressed ok' ;
545 is $output[0], 'first', " Array[0] unchanged";
547 is_deeply \@input, \@keep, " Input array not changed" ;
548 my @got = shift @output;
549 foreach (@output) { push @got, anyUncompress($_) }
551 is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
555 foreach my $ms (@MultiValues)
558 title "$TopType - From Array Ref to Buffer, MultiStream $ms" ;
560 # rewind the filehandle
561 $of->open("<$file1") ;
564 ok &$Func(\@input, \$output, MultiStream => $ms, AutoClose => 0), ' Compressed ok'
567 my $got = anyUncompress([ \$output, MultiStream => $ms ]);
569 is $got, join('', @uexpected), " Got Expected uncompressed data";
570 my @headers = getHeaders(\$output);
571 is @headers, $ms ? @input : 1, " Header count ok";
575 title "$TopType - From Array Ref to Filename, MultiStream $ms" ;
577 my $lex = new LexFile( my $file3) ;
579 # rewind the filehandle
580 $of->open("<$file1") ;
583 ok &$Func(\@input, $file3, MultiStream => $ms, AutoClose => 0), ' Compressed ok' ;
585 my $got = anyUncompress([ $file3, MultiStream => $ms ]);
587 is $got, join('', @uexpected), " Got Expected uncompressed data";
588 my @headers = getHeaders($file3);
589 is @headers, $ms ? @input : 1, " Header count ok";
593 title "$TopType - From Array Ref to Filehandle, MultiStream $ms" ;
595 my $lex = new LexFile(my $file3) ;
597 my $fh3 = new IO::File ">$file3";
599 # rewind the filehandle
600 $of->open("<$file1") ;
603 ok &$Func(\@input, $fh3, MultiStream => $ms, AutoClose => 0), ' Compressed ok' ;
607 my $got = anyUncompress([ $file3, MultiStream => $ms ]);
609 is $got, join('', @uexpected), " Got Expected uncompressed data";
610 my @headers = getHeaders($file3);
611 is @headers, $ms ? @input : 1, " Header count ok";
616 title "Truncated file";
618 if $CompressClass =~ /lzop|lzf/i ;
621 push @in, "abcde" x 10;
622 push @in, "defgh" x 1000;
623 push @in, "12345" x 50000;
628 ok &$Func(\$_ , \$out, Append => 1 ), ' Compressed ok'
631 #ok &$Func(\@in, \$out, MultiStream => 1 ), ' Compressed ok'
632 substr($out, -179) = '';
636 ok $status = &$FuncInverse(\$out => \$got, MultiStream => 0), " Uncompressed stream 1 ok";
637 is $got, "abcde" x 10 ;
638 ok ! &$FuncInverse(\$out => \$got, MultiStream => 1), " Didn't uncompress";
639 is $$ErrorInverse, "unexpected end of file", " Got unexpected eof";
644 foreach my $bit ($UncompressClass,
645 #'IO::Uncompress::AnyUncompress',
648 my $Error = getErrorRef($bit);
649 my $Func = getTopFuncRef($bit);
650 my $TopType = getTopFuncName($bit);
651 my $CompressClass = getInverse($bit);
652 my $C_Func = getTopFuncRef($CompressClass);
656 my $data = "mary had a little lamb" ;
658 my $extra = "after the main event";
660 foreach my $fb ( qw( filehandle buffer ) )
662 title "Trailingdata with $TopType, from $fb";
664 my $lex = new LexFile my $name ;
668 ok &$C_Func(\$data, \$compressed), ' Compressed ok' ;
669 $compressed .= $extra;
673 $input = \$compressed;
677 writeFile($name, $compressed);
679 $input = new IO::File "<$name" ;
684 ok $Func->($input, \$out, TrailingData => $trailing), " Uncompressed OK" ;
685 is $out, $keep, " Got uncompressed data";
688 if ($fb eq 'filehandle')
690 read($input, $rest, 10000) ;
693 is $trailing . $rest, $extra, " Got trailing data";
699 # foreach my $bit ($CompressClass)
701 # my $Error = getErrorRef($bit);
702 # my $Func = getTopFuncRef($bit);
703 # my $TopType = getTopFuncName($bit);
705 # my $TopTypeInverse = getInverse($bit);
706 # my $FuncInverse = getTopFuncRef($TopTypeInverse);
708 # my @inFiles = map { "in$_.tmp" } 1..4;
709 # my @outFiles = map { "out$_.tmp" } 1..4;
710 # my $lex = new LexFile(@inFiles, @outFiles);
712 # writeFile($_, "data $_") foreach @inFiles ;
715 # title "$TopType - Hash Ref: to filename" ;
718 # ok &$Func( { $inFiles[0] => $outFiles[0],
719 # $inFiles[1] => $outFiles[1],
720 # $inFiles[2] => $outFiles[2] } ), ' Compressed ok' ;
724 # my $got = anyUncompress($outFiles[$_]);
725 # is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
730 # title "$TopType - Hash Ref: to buffer" ;
733 # ok &$Func( { $inFiles[0] => \$buffer[0],
734 # $inFiles[1] => \$buffer[1],
735 # $inFiles[2] => \$buffer[2] } ), ' Compressed ok' ;
739 # my $got = anyUncompress(\$buffer[$_]);
740 # is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
745 # title "$TopType - Hash Ref: to undef" ;
748 # my %hash = ( $inFiles[0] => undef,
749 # $inFiles[1] => undef,
750 # $inFiles[2] => undef,
753 # ok &$Func( \%hash ), ' Compressed ok' ;
755 # foreach (keys %hash)
757 # my $got = anyUncompress(\$hash{$_});
758 # is $got, "data $_", " Uncompressed $_ matches original";
763 # title "$TopType - Filename to Hash Ref" ;
766 # ok &$Func( $inFiles[0] => \%output), ' Compressed ok' ;
768 # is keys %output, 1, " one pair in hash" ;
769 # my ($k, $v) = each %output;
770 # is $k, $inFiles[0], " key is '$inFiles[0]'";
771 # my $got = anyUncompress($v);
772 # is $got, "data $inFiles[0]", " Uncompressed matches original";
776 # title "$TopType - File Glob to Hash Ref" ;
779 # ok &$Func( '<in*.tmp>' => \%output), ' Compressed ok' ;
781 # is keys %output, 4, " four pairs in hash" ;
782 # foreach my $fil (@inFiles)
784 # ok exists $output{$fil}, " key '$fil' exists" ;
785 # my $got = anyUncompress($output{$fil});
786 # is $got, "data $fil", " Uncompressed matches original";
793 # foreach my $bit ($CompressClass)
795 # my $Error = getErrorRef($bit);
796 # my $Func = getTopFuncRef($bit);
797 # my $TopType = getTopFuncName($bit);
799 # my $TopTypeInverse = getInverse($bit);
800 # my $FuncInverse = getTopFuncRef($TopTypeInverse);
802 # my @inFiles = map { "in$_.tmp" } 1..4;
803 # my @outFiles = map { "out$_.tmp" } 1..4;
804 # my $lex = new LexFile(@inFiles, @outFiles);
806 # writeFile($_, "data $_") foreach @inFiles ;
812 # # title "$TopType - Hash Ref to Array Ref" ;
814 # # my @output = ('first') ;
815 # # ok &$Func( { \@input, \@output } , AutoClose => 0), ' Compressed ok' ;
817 # # is $output[0], 'first', " Array[0] unchanged";
819 # # is_deeply \@input, \@keep, " Input array not changed" ;
820 # # my @got = shift @output;
821 # # foreach (@output) { push @got, anyUncompress($_) }
823 # # is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
829 # # title "$TopType - From Array Ref to Buffer" ;
831 # # # rewind the filehandle
832 # # $of->open("<$file1") ;
835 # # ok &$Func(\@input, \$output, AutoClose => 0), ' Compressed ok' ;
837 # # my $got = anyUncompress(\$output);
839 # # is $got, join('', @expected), " Got Expected uncompressed data";
844 # # title "$TopType - From Array Ref to Filename" ;
846 # # my ($file3) = ("file3");
847 # # my $lex = new LexFile($file3) ;
849 # # # rewind the filehandle
850 # # $of->open("<$file1") ;
853 # # ok &$Func(\@input, $file3, AutoClose => 0), ' Compressed ok' ;
855 # # my $got = anyUncompress($file3);
857 # # is $got, join('', @expected), " Got Expected uncompressed data";
862 # # title "$TopType - From Array Ref to Filehandle" ;
864 # # my ($file3) = ("file3");
865 # # my $lex = new LexFile($file3) ;
867 # # my $fh3 = new IO::File ">$file3";
869 # # # rewind the filehandle
870 # # $of->open("<$file1") ;
873 # # ok &$Func(\@input, $fh3, AutoClose => 0), ' Compressed ok' ;
877 # # my $got = anyUncompress($file3);
879 # # is $got, join('', @expected), " Got Expected uncompressed data";
883 foreach my $bit ($CompressClass
886 my $Error = getErrorRef($bit);
887 my $Func = getTopFuncRef($bit);
888 my $TopType = getTopFuncName($bit);
890 for my $files ( [qw(a1)], [qw(a1 a2 a3)] )
893 my $tmpDir1 = 'tmpdir1';
894 my $tmpDir2 = 'tmpdir2';
895 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
897 mkdir $tmpDir1, 0777;
898 mkdir $tmpDir2, 0777;
900 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
901 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
903 my @files = map { "$tmpDir1/$_.tmp" } @$files ;
904 foreach (@files) { writeFile($_, "abc $_") }
906 my @expected = map { "abc $_" } @files ;
907 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
910 title "$TopType - From FileGlob to FileGlob files [@$files]" ;
912 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>"), ' Compressed ok'
915 my @copy = @expected;
916 for my $file (@outFiles)
918 is anyUncompress($file), shift @copy, " got expected from $file" ;
921 is @copy, 0, " got all files";
925 title "$TopType - From FileGlob to Array files [@$files]" ;
927 my @buffer = ('first') ;
928 ok &$Func("<$tmpDir1/a*.tmp>" => \@buffer), ' Compressed ok'
931 is shift @buffer, 'first';
933 my @copy = @expected;
934 for my $buffer (@buffer)
936 is anyUncompress($buffer), shift @copy, " got expected " ;
939 is @copy, 0, " got all files";
942 foreach my $ms (@MultiValues)
945 title "$TopType - From FileGlob to Buffer files [@$files], MS $ms" ;
948 ok &$Func("<$tmpDir1/a*.tmp>" => \$buffer,
949 MultiStream => $ms), ' Compressed ok'
954 my $got = anyUncompress([ \$buffer, MultiStream => $ms ]);
956 is $got, join("", @expected), " got expected" ;
957 my @headers = getHeaders(\$buffer);
958 is @headers, $ms ? @files : 1, " Header count ok";
962 title "$TopType - From FileGlob to Filename files [@$files], MS $ms" ;
964 my $filename = "abcde";
965 my $lex = new LexFile($filename) ;
967 ok &$Func("<$tmpDir1/a*.tmp>" => $filename,
968 MultiStream => $ms), ' Compressed ok'
973 my $got = anyUncompress([$filename, MultiStream => $ms]);
975 is $got, join("", @expected), " got expected" ;
976 my @headers = getHeaders($filename);
977 is @headers, $ms ? @files : 1, " Header count ok";
981 title "$TopType - From FileGlob to Filehandle files [@$files], MS $ms" ;
983 my $filename = "abcde";
984 my $lex = new LexFile($filename) ;
985 my $fh = new IO::File ">$filename";
987 ok &$Func("<$tmpDir1/a*.tmp>" => $fh,
988 MultiStream => $ms, AutoClose => 1), ' Compressed ok'
993 my $got = anyUncompress([$filename, MultiStream => $ms]);
995 is $got, join("", @expected), " got expected" ;
996 my @headers = getHeaders($filename);
997 is @headers, $ms ? @files : 1, " Header count ok";
1004 foreach my $bit ($UncompressClass,
1005 'IO::Uncompress::AnyUncompress',
1008 my $Error = getErrorRef($bit);
1009 my $Func = getTopFuncRef($bit);
1010 my $TopType = getTopFuncName($bit);
1012 my $buffer = "abcde" ;
1013 my $buffer2 = "ABCDE" ;
1014 my $keep_orig = $buffer;
1016 my $comp = compressBuffer($UncompressClass, $buffer) ;
1017 my $comp2 = compressBuffer($UncompressClass, $buffer2) ;
1018 my $keep_comp = $comp;
1020 my $incumbent = "incumbent data" ;
1022 my @opts = (Strict => 1);
1023 push @opts, (RawInflate => 1)
1024 if $bit eq 'IO::Uncompress::AnyUncompress';
1026 for my $append (0, 1)
1028 my $expected = $buffer ;
1029 $expected = $incumbent . $buffer if $append ;
1032 title "$TopType - From Buff to Buff, Append($append)" ;
1035 $output = $incumbent if $append ;
1036 ok &$Func(\$comp, \$output, Append => $append, @opts), ' Uncompressed ok' ;
1038 is $keep_comp, $comp, " Input buffer not changed" ;
1039 is $output, $expected, " Uncompressed matches original";
1043 title "$TopType - From Buff to Array, Append($append)" ;
1045 my @output = ('first');
1046 #$output = $incumbent if $append ;
1047 ok &$Func(\$comp, \@output, Append => $append, @opts), ' Uncompressed ok' ;
1049 is $keep_comp, $comp, " Input buffer not changed" ;
1050 is $output[0], 'first', " Uncompressed matches original";
1051 is ${ $output[1] }, $buffer, " Uncompressed matches original"
1052 or diag $output[1] ;
1053 is @output, 2, " only 2 elements in the array" ;
1057 title "$TopType - From Buff to Filename, Append($append)" ;
1059 my $lex = new LexFile(my $out_file) ;
1061 { writeFile($out_file, $incumbent) }
1063 { ok ! -e $out_file, " Output file does not exist" }
1065 ok &$Func(\$comp, $out_file, Append => $append, @opts), ' Uncompressed ok' ;
1067 ok -e $out_file, " Created output file";
1068 my $content = readFile($out_file) ;
1070 is $keep_comp, $comp, " Input buffer not changed" ;
1071 is $content, $expected, " Uncompressed matches original";
1075 title "$TopType - From Buff to Handle, Append($append)" ;
1077 my $lex = new LexFile(my $out_file) ;
1080 writeFile($out_file, $incumbent) ;
1081 $of = new IO::File "+< $out_file" ;
1084 ok ! -e $out_file, " Output file does not exist" ;
1085 $of = new IO::File "> $out_file" ;
1087 isa_ok $of, 'IO::File', ' $of' ;
1089 ok &$Func(\$comp, $of, Append => $append, AutoClose => 1, @opts), ' Uncompressed ok' ;
1091 ok -e $out_file, " Created output file";
1092 my $content = readFile($out_file) ;
1094 is $keep_comp, $comp, " Input buffer not changed" ;
1095 is $content, $expected, " Uncompressed matches original";
1099 title "$TopType - From Filename to Filename, Append($append)" ;
1101 my $lex = new LexFile(my $in_file, my $out_file) ;
1103 { writeFile($out_file, $incumbent) }
1105 { ok ! -e $out_file, " Output file does not exist" }
1107 writeFile($in_file, $comp);
1109 ok &$Func($in_file, $out_file, Append => $append, @opts), ' Uncompressed ok' ;
1111 ok -e $out_file, " Created output file";
1112 my $content = readFile($out_file) ;
1114 is $keep_comp, $comp, " Input buffer not changed" ;
1115 is $content, $expected, " Uncompressed matches original";
1119 title "$TopType - From Filename to Handle, Append($append)" ;
1121 my $lex = new LexFile(my $in_file, my $out_file) ;
1124 writeFile($out_file, $incumbent) ;
1125 $out = new IO::File "+< $out_file" ;
1128 ok ! -e $out_file, " Output file does not exist" ;
1129 $out = new IO::File "> $out_file" ;
1131 isa_ok $out, 'IO::File', ' $out' ;
1133 writeFile($in_file, $comp);
1135 ok &$Func($in_file, $out, Append => $append, AutoClose => 1, @opts), ' Uncompressed ok' ;
1137 ok -e $out_file, " Created output file";
1138 my $content = readFile($out_file) ;
1140 is $keep_comp, $comp, " Input buffer not changed" ;
1141 is $content, $expected, " Uncompressed matches original";
1145 title "$TopType - From Filename to Buffer, Append($append)" ;
1147 my $lex = new LexFile(my $in_file) ;
1148 writeFile($in_file, $comp);
1151 $output = $incumbent if $append ;
1153 ok &$Func($in_file, \$output, Append => $append, @opts), ' Uncompressed ok' ;
1155 is $keep_comp, $comp, " Input buffer not changed" ;
1156 is $output, $expected, " Uncompressed matches original";
1160 title "$TopType - From Handle to Filename, Append($append)" ;
1162 my $lex = new LexFile(my $in_file, my $out_file) ;
1164 { writeFile($out_file, $incumbent) }
1166 { ok ! -e $out_file, " Output file does not exist" }
1168 writeFile($in_file, $comp);
1169 my $in = new IO::File "<$in_file" ;
1171 ok &$Func($in, $out_file, Append => $append, @opts), ' Uncompressed ok' ;
1173 ok -e $out_file, " Created output file";
1174 my $content = readFile($out_file) ;
1176 is $keep_comp, $comp, " Input buffer not changed" ;
1177 is $content, $expected, " Uncompressed matches original";
1181 title "$TopType - From Handle to Handle, Append($append)" ;
1183 my $lex = new LexFile(my $in_file, my $out_file) ;
1186 writeFile($out_file, $incumbent) ;
1187 $out = new IO::File "+< $out_file" ;
1190 ok ! -e $out_file, " Output file does not exist" ;
1191 $out = new IO::File "> $out_file" ;
1193 isa_ok $out, 'IO::File', ' $out' ;
1195 writeFile($in_file, $comp);
1196 my $in = new IO::File "<$in_file" ;
1198 ok &$Func($in, $out, Append => $append, AutoClose => 1, @opts), ' Uncompressed ok' ;
1200 ok -e $out_file, " Created output file";
1201 my $content = readFile($out_file) ;
1203 is $keep_comp, $comp, " Input buffer not changed" ;
1204 is $content, $expected, " Uncompressed matches original";
1208 title "$TopType - From Filename to Buffer, Append($append)" ;
1210 my $lex = new LexFile(my $in_file) ;
1211 writeFile($in_file, $comp);
1212 my $in = new IO::File "<$in_file" ;
1215 $output = $incumbent if $append ;
1217 ok &$Func($in, \$output, Append => $append, @opts), ' Uncompressed ok' ;
1219 is $keep_comp, $comp, " Input buffer not changed" ;
1220 is $output, $expected, " Uncompressed matches original";
1224 title "$TopType - From stdin (via '-') to Buffer content, Append($append) " ;
1226 my $lex = new LexFile(my $in_file) ;
1227 writeFile($in_file, $comp);
1229 open(SAVEIN, "<&STDIN");
1230 my $dummy = fileno SAVEIN ;
1231 ok open(STDIN, "<$in_file"), " redirect STDIN";
1234 $output = $incumbent if $append ;
1236 ok &$Func('-', \$output, Append => $append, @opts), ' Uncompressed ok'
1239 open(STDIN, "<&SAVEIN");
1241 is $keep_comp, $comp, " Input buffer not changed" ;
1242 is $output, $expected, " Uncompressed matches original";
1247 title "$TopType - From Handle to Buffer, InputLength" ;
1249 my $lex = new LexFile(my $in_file, my $out_file) ;
1252 my $expected = $buffer ;
1253 my $appended = 'appended';
1254 my $len_appended = length $appended;
1255 writeFile($in_file, $comp . $appended . $comp . $appended) ;
1256 my $in = new IO::File "<$in_file" ;
1258 ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp, @opts), ' Uncompressed ok' ;
1260 is $out, $expected, " Uncompressed matches original";
1263 is $in->read($buff, $len_appended), $len_appended, " Length of Appended data ok";
1264 is $buff, $appended, " Appended data ok";
1267 ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp, @opts), ' Uncompressed ok' ;
1269 is $out, $expected, " Uncompressed matches original";
1272 is $in->read($buff, $len_appended), $len_appended, " Length of Appended data ok";
1273 is $buff, $appended, " Appended data ok";
1276 for my $stdin ('-', *STDIN) # , \*STDIN)
1278 title "$TopType - From stdin (via $stdin) to Buffer content, InputLength" ;
1280 my $lex = new LexFile my $in_file ;
1281 my $expected = $buffer ;
1282 my $appended = 'appended';
1283 my $len_appended = length $appended;
1284 writeFile($in_file, $comp . $appended ) ;
1286 open(SAVEIN, "<&STDIN");
1287 my $dummy = fileno SAVEIN ;
1288 ok open(STDIN, "<$in_file"), " redirect STDIN";
1292 ok &$Func($stdin, \$output, Transparent => 0, InputLength => length $comp, @opts), ' Uncompressed ok'
1296 is read(STDIN, $buff, $len_appended), $len_appended, " Length of Appended data ok";
1298 is $output, $expected, " Uncompressed matches original";
1299 is $buff, $appended, " Appended data ok";
1301 open(STDIN, "<&SAVEIN");
1305 foreach my $bit ($UncompressClass,
1306 'IO::Uncompress::AnyUncompress',
1309 # TODO -- Add Append mode tests
1311 my $Error = getErrorRef($bit);
1312 my $Func = getTopFuncRef($bit);
1313 my $TopType = getTopFuncName($bit);
1315 my $buffer = "abcde" ;
1316 my $keep_orig = $buffer;
1318 my $null = compressBuffer($UncompressClass, "") ;
1319 my $undef = compressBuffer($UncompressClass, undef) ;
1320 my $comp = compressBuffer($UncompressClass, $buffer) ;
1321 my $keep_comp = $comp;
1324 @opts = (RawInflate => 1)
1325 if $bit eq 'IO::Uncompress::AnyUncompress';
1327 my $incumbent = "incumbent data" ;
1329 my $lex = new LexFile(my $file1, my $file2) ;
1331 writeFile($file1, compressBuffer($UncompressClass,"data1"));
1332 writeFile($file2, compressBuffer($UncompressClass,"data2"));
1334 my $of = new IO::File "<$file1" ;
1335 ok $of, " Created output filehandle" ;
1337 #my @input = ($file2, \$undef, \$null, \$comp, $of) ;
1338 #my @expected = ('data2', '', '', 'abcde', 'data1');
1339 my @input = ($file1, $file2);
1340 my @expected = ('data1', 'data2');
1345 title "$TopType - From ArrayRef to Buffer" ;
1348 ok &$Func(\@input, \$output, AutoClose => 0, @opts), ' UnCompressed ok' ;
1350 is $output, join('', @expected)
1354 title "$TopType - From ArrayRef to Filename" ;
1356 my $lex = new LexFile my $output;
1357 $of->open("<$file1") ;
1359 ok &$Func(\@input, $output, AutoClose => 0, @opts), ' UnCompressed ok' ;
1361 is readFile($output), join('', @expected)
1365 title "$TopType - From ArrayRef to Filehandle" ;
1367 my $lex = new LexFile my $output;
1368 my $fh = new IO::File ">$output" ;
1369 $of->open("<$file1") ;
1371 ok &$Func(\@input, $fh, AutoClose => 0, @opts), ' UnCompressed ok' ;
1374 is readFile($output), join('', @expected)
1378 title "$TopType - From Array Ref to Array Ref" ;
1380 my @output = (\'first') ;
1381 $of->open("<$file1") ;
1382 ok &$Func(\@input, \@output, AutoClose => 0, @opts), ' UnCompressed ok' ;
1384 is_deeply \@input, \@keep, " Input array not changed" ;
1385 is_deeply [map { defined $$_ ? $$_ : "" } @output],
1386 ['first', @expected],
1387 " Got Expected uncompressed data";
1392 foreach my $bit ($UncompressClass,
1393 'IO::Uncompress::AnyUncompress',
1396 # TODO -- Add Append mode tests
1398 my $Error = getErrorRef($bit);
1399 my $Func = getTopFuncRef($bit);
1400 my $TopType = getTopFuncName($bit);
1402 my $tmpDir1 = 'tmpdir1';
1403 my $tmpDir2 = 'tmpdir2';
1404 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
1406 mkdir $tmpDir1, 0777;
1407 mkdir $tmpDir2, 0777;
1410 @opts = (RawInflate => 1)
1411 if $bit eq 'IO::Uncompress::AnyUncompress';
1413 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
1414 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
1416 my @files = map { "$tmpDir1/$_.tmp" } qw( a1 a2 a3) ;
1417 foreach (@files) { writeFile($_, compressBuffer($UncompressClass, "abc $_")) }
1419 my @expected = map { "abc $_" } @files ;
1420 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
1423 title "$TopType - From FileGlob to FileGlob" ;
1425 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>", @opts), ' UnCompressed ok'
1428 my @copy = @expected;
1429 for my $file (@outFiles)
1431 is readFile($file), shift @copy, " got expected from $file" ;
1434 is @copy, 0, " got all files";
1438 title "$TopType - From FileGlob to Arrayref" ;
1440 my @output = (\'first');
1441 ok &$Func("<$tmpDir1/a*.tmp>" => \@output, @opts), ' UnCompressed ok'
1444 my @copy = ('first', @expected);
1445 for my $data (@output)
1447 is $$data, shift @copy, " got expected data" ;
1450 is @copy, 0, " got all files";
1454 title "$TopType - From FileGlob to Buffer" ;
1457 ok &$Func("<$tmpDir1/a*.tmp>" => \$output, @opts), ' UnCompressed ok'
1460 is $output, join('', @expected), " got expected uncompressed data";
1464 title "$TopType - From FileGlob to Filename" ;
1466 my $lex = new LexFile my $output ;
1467 ok ! -e $output, " $output does not exist" ;
1468 ok &$Func("<$tmpDir1/a*.tmp>" => $output, @opts), ' UnCompressed ok'
1471 ok -e $output, " $output does exist" ;
1472 is readFile($output), join('', @expected), " got expected uncompressed data";
1476 title "$TopType - From FileGlob to Filehandle" ;
1478 my $output = 'abc' ;
1479 my $lex = new LexFile $output ;
1480 my $fh = new IO::File ">$output" ;
1481 ok &$Func("<$tmpDir1/a*.tmp>" => $fh, AutoClose => 1, @opts), ' UnCompressed ok'
1484 ok -e $output, " $output does exist" ;
1485 is readFile($output), join('', @expected), " got expected uncompressed data";
1490 foreach my $TopType ($CompressClass
1491 # TODO -- add the inflate classes
1494 my $Error = getErrorRef($TopType);
1495 my $Func = getTopFuncRef($TopType);
1496 my $Name = getTopFuncName($TopType);
1498 title "More write tests" ;
1500 my $lex = new LexFile(my $file1, my $file2, my $file3) ;
1502 writeFile($file1, "F1");
1503 writeFile($file2, "F2");
1504 writeFile($file3, "F3");
1507 # [ '[\"ab", \"cd"]', "abcd" ],
1509 # [ '[\"a", $fh1, \"bc"]', "aF1bc"],
1513 # foreach my $data (@data)
1515 # my ($send, $get) = @$data ;
1517 # my $fh1 = new IO::File "< $file1" ;
1518 # my $fh2 = new IO::File "< $file2" ;
1519 # my $fh3 = new IO::File "< $file3" ;
1523 # eval "\$copy = $send";
1525 # ok &$Func($copy, \$Answer), " $Name ok";
1527 # my $got = anyUncompress(\$Answer);
1528 # is $got, $get, " got expected output" ;
1529 # ok ! $$Error, " no error"
1530 # or diag "Error is $$Error";
1534 title "Array Input Error tests" ;
1537 [ '[]', "empty array reference"],
1538 [ '[[]]', "unknown input parameter"],
1539 [ '[[[]]]', "unknown input parameter"],
1540 [ '[[\"ab"], [\"cd"]]', "unknown input parameter"],
1541 [ '[\""]', "not a filename"],
1542 [ '[\undef]', "not a filename"],
1543 [ '[\"abcd"]', "not a filename"],
1544 [ '[\&xx]', "unknown input parameter"],
1545 [ '[$fh2]', "not a filename"],
1549 foreach my $data (@data)
1551 my ($send, $get) = @$data ;
1553 my $fh1 = new IO::File "< $file1" ;
1554 my $fh2 = new IO::File "< $file2" ;
1555 my $fh3 = new IO::File "< $file3" ;
1559 eval "\$copy = $send";
1562 eval { $a = &$Func($copy, \$Answer) };
1563 ok ! $a, " $Name fails";
1565 is $$Error, $get, " got error message";
1575 foreach my $send (@data)
1579 eval "\$copy = $send";
1581 eval { &$Func($copy, \$Answer) } ;
1582 like $@, mkErr("^$TopFuncName: input filename is undef or null string"),
1583 " got error message";
1590 # TODO add more error cases