17 plan(skip_all => "oneshot needs Perl 5.005 or better - you have Perl $]" )
21 # use Test::NoWarnings, if available
24 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
26 plan tests => 2526 + $extra ;
28 use_ok('Compress::Zlib', 2) ;
30 use_ok('IO::Compress::Gzip', qw(gzip $GzipError)) ;
31 use_ok('IO::Uncompress::Gunzip', qw(gunzip $GunzipError)) ;
33 use_ok('IO::Compress::Deflate', qw(deflate $DeflateError)) ;
34 use_ok('IO::Uncompress::Inflate', qw(inflate $InflateError)) ;
36 use_ok('IO::Compress::RawDeflate', qw(rawdeflate $RawDeflateError)) ;
37 use_ok('IO::Uncompress::RawInflate', qw(rawinflate $RawInflateError)) ;
39 use_ok('IO::Uncompress::AnyInflate', qw(anyinflate $AnyInflateError)) ;
44 # Check zlib_version and ZLIB_VERSION are the same.
45 is Compress::Zlib::zlib_version, ZLIB_VERSION,
46 "ZLIB_VERSION matches Compress::Zlib::zlib_version" ;
50 foreach my $bit ('IO::Compress::Gzip',
51 'IO::Uncompress::Gunzip',
52 'IO::Compress::Deflate',
53 'IO::Uncompress::Inflate',
54 'IO::Compress::RawDeflate',
55 'IO::Uncompress::RawInflate',
56 'IO::Uncompress::AnyInflate',
59 my $Error = getErrorRef($bit);
60 my $Func = getTopFuncRef($bit);
61 my $TopType = getTopFuncName($bit);
63 title "Testing $TopType Error Cases";
68 eval { $a = $Func->(\$a => \$x, Fred => 1) ;} ;
69 like $@, mkErr("^$TopType: unknown key value\\(s\\) Fred"), ' Illegal Parameters';
71 eval { $a = $Func->() ;} ;
72 like $@, mkErr("^$TopType: expected at least 1 parameters"), ' No Parameters';
74 eval { $a = $Func->(\$x, \1) ;} ;
75 like $@, mkErr("^$TopType: output buffer is read-only"), ' Output is read-only' ;
78 eval { $a = $Func->($in, \$x) ;} ;
79 like $@, mkErr("^$TopType: input filename is undef or null string"),
80 ' Input filename undef' ;
83 eval { $a = $Func->($in, \$x) ;} ;
84 like $@, mkErr("^$TopType: input filename is undef or null string"),
85 ' Input filename empty' ;
88 my $lex1 = new LexFile($in) ;
89 writeFile($in, "abc");
91 eval { $a = $Func->($in, $out) ;} ;
92 like $@, mkErr("^$TopType: input and output filename are identical"),
93 ' Input and Output filename are the same';
95 eval { $a = $Func->(\$in, \$in) ;} ;
96 like $@, mkErr("^$TopType: input and output buffer are identical"),
97 ' Input and Output buffer are the same';
99 my $out_file = "abcde.out";
100 my $lex = new LexFile($out_file) ;
101 open OUT, ">$out_file" ;
102 eval { $a = $Func->(\*OUT, \*OUT) ;} ;
103 like $@, mkErr("^$TopType: input and output handle are identical"),
104 ' Input and Output handle are the same';
107 is -s $out_file, 0, " File zero length" ;
110 my $object = bless \%x, "someClass" ;
112 # Buffer not a scalar reference
113 #eval { $a = $Func->(\$x, \%x) ;} ;
114 eval { $a = $Func->(\$x, $object) ;} ;
115 like $@, mkErr("^$TopType: illegal output parameter"),
119 #eval { $a = $Func->(\%x, \$x) ;} ;
120 eval { $a = $Func->($object, \$x) ;} ;
121 like $@, mkErr("^$TopType: illegal input parameter"),
125 my $filename = 'abc.def';
126 ok ! -e $filename, " input file '$filename' does not exist";
127 $a = $Func->($filename, \$x) ;
128 is $a, undef, " $TopType returned undef";
129 like $$Error, "/^input file '$filename' does not exist\$/", " input File '$filename' does not exist";
131 $filename = '/tmp/abd/abc.def';
132 ok ! -e $filename, " output File '$filename' does not exist";
133 $a = $Func->(\$x, $filename) ;
134 is $a, undef, " $TopType returned undef";
135 like $$Error, ("/^(cannot open file '$filename'|input file '$filename' does not exist):/"), " output File '$filename' does not exist";
137 $a = $Func->(\$x, '<abc>') ;
138 is $a, undef, " $TopType returned undef";
139 like $$Error, "/Need input fileglob for outout fileglob/",
140 ' Output fileglob with no input fileglob';
142 $a = $Func->('<abc)>', '<abc>') ;
143 is $a, undef, " $TopType returned undef";
144 like $$Error, "/Unmatched \\) in input fileglob/",
145 " Unmatched ) in input fileglob";
148 foreach my $bit ('IO::Uncompress::Gunzip',
149 'IO::Uncompress::Inflate',
150 'IO::Uncompress::RawInflate',
151 'IO::Uncompress::AnyInflate',
154 my $Error = getErrorRef($bit);
155 my $Func = getTopFuncRef($bit);
156 my $TopType = getTopFuncName($bit);
158 my $data = "mary had a little lamb" ;
161 for my $trans ( 0, 1)
163 title "Non-compressed data with $TopType, Transparent => $trans ";
168 $a = $Func->(\$data, \$out, Transparent => $trans) ;
170 is $data, $keep, " Input buffer not changed" ;
174 ok $a, " $TopType returned true" ;
175 is $out, $data, " got expected output" ;
176 ok ! $$Error, " no error [$$Error]" ;
180 ok ! $a, " $TopType returned false" ;
181 #like $$Error, '/xxx/', " error" ;
182 ok $$Error, " error is '$$Error'" ;
187 foreach my $bit ('IO::Compress::Gzip',
188 'IO::Compress::Deflate',
189 'IO::Compress::RawDeflate',
192 my $Error = getErrorRef($bit);
193 my $Func = getTopFuncRef($bit);
194 my $TopType = getTopFuncName($bit);
195 my $TopTypeInverse = getInverse($bit);
196 my $FuncInverse = getTopFuncRef($TopTypeInverse);
197 my $ErrorInverse = getErrorRef($TopTypeInverse);
199 title "$TopTypeInverse - corrupt data";
201 my $data = "abcd" x 100 ;
204 ok $Func->(\$data, \$out), " $TopType ok";
206 # corrupt the compressed data
207 substr($out, -10, 10) = "x" x 10 ;
210 ok ! $FuncInverse->(\$out => \$result, Transparent => 0), " $TopTypeInverse ok";
211 ok $$ErrorInverse, " Got error '$$ErrorInverse'" ;
213 #is $result, $data, " data ok";
215 ok ! anyinflate(\$out => \$result, Transparent => 0), " anyinflate ok";
216 ok $AnyInflateError, " Got error '$AnyInflateError'" ;
220 foreach my $bit ('IO::Compress::Gzip',
221 'IO::Compress::Deflate',
222 'IO::Compress::RawDeflate',
225 my $Error = getErrorRef($bit);
226 my $Func = getTopFuncRef($bit);
227 my $TopType = getTopFuncName($bit);
228 my $TopTypeInverse = getInverse($bit);
229 my $FuncInverse = getTopFuncRef($TopTypeInverse);
231 for my $append ( 1, 0 )
234 $already = 'abcde' if $append ;
236 for my $buffer ( undef, '', "abcde" )
239 my $disp_content = defined $buffer ? $buffer : '<undef>' ;
242 my $out_file = "abcde.out";
243 my $in_file = "abcde.in";
246 title "$TopType - From Buff to Buff content '$disp_content' Append $append" ;
248 my $output = $already;
249 ok &$Func(\$buffer, \$output, Append => $append), ' Compressed ok' ;
251 is $keep, $buffer, " Input buffer not changed" ;
252 my $got = anyUncompress(\$output, $already);
253 $got = undef if ! defined $buffer && $got eq '' ;
254 is $got, $buffer, " Uncompressed matches original";
259 title "$TopType - From Buff to Array Ref content '$disp_content' Append $append" ;
261 my @output = ('first') ;
262 ok &$Func(\$buffer, \@output, Append => $append), ' Compressed ok' ;
264 is $output[0], 'first', " Array[0] unchanged";
265 is $keep, $buffer, " Input buffer not changed" ;
266 my $got = anyUncompress($output[1]);
267 $got = undef if ! defined $buffer && $got eq '' ;
268 is $got, $buffer, " Uncompressed matches original";
272 title "$TopType - From Array Ref to Array Ref content '$disp_content' Append $append" ;
274 my @output = ('first') ;
275 my @input = ( \$buffer);
276 ok &$Func(\@input, \@output, Append => $append), ' Compressed ok' ;
278 is $output[0], 'first', " Array[0] unchanged";
279 is $keep, $buffer, " Input buffer not changed" ;
280 my $got = anyUncompress($output[1]);
281 $got = undef if ! defined $buffer && $got eq '' ;
282 is $got, $buffer, " Uncompressed matches original";
287 title "$TopType - From Buff to Filename content '$disp_content' Append $append" ;
289 my $lex = new LexFile($out_file) ;
290 ok ! -e $out_file, " Output file does not exist";
291 writeFile($out_file, $already);
293 ok &$Func(\$buffer, $out_file, Append => $append), ' Compressed ok' ;
295 ok -e $out_file, " Created output file";
296 my $got = anyUncompress($out_file, $already);
297 $got = undef if ! defined $buffer && $got eq '' ;
298 is $got, $buffer, " Uncompressed matches original";
302 title "$TopType - From Buff to Handle content '$disp_content' Append $append" ;
304 my $lex = new LexFile($out_file) ;
306 ok ! -e $out_file, " Output file does not exist";
307 writeFile($out_file, $already);
308 my $of = new IO::File ">>$out_file" ;
309 ok $of, " Created output filehandle" ;
311 ok &$Func(\$buffer, $of, AutoClose => 1, Append => $append), ' Compressed ok' ;
313 ok -e $out_file, " Created output file";
314 my $got = anyUncompress($out_file, $already);
315 $got = undef if ! defined $buffer && $got eq '' ;
316 is $got, $buffer, " Uncompressed matches original";
321 title "$TopType - From Filename to Filename content '$disp_content' Append $append" ;
323 my $lex = new LexFile($in_file, $out_file) ;
324 writeFile($in_file, $buffer);
326 ok ! -e $out_file, " Output file does not exist";
327 writeFile($out_file, $already);
329 ok &$Func($in_file => $out_file, Append => $append), ' Compressed ok' ;
331 ok -e $out_file, " Created output file";
332 my $got = anyUncompress($out_file, $already);
333 $got = undef if ! defined $buffer && $got eq '' ;
334 is $got, $buffer, " Uncompressed matches original";
339 title "$TopType - From Filename to Handle content '$disp_content' Append $append" ;
341 my $lex = new LexFile($in_file, $out_file) ;
342 writeFile($in_file, $buffer);
344 ok ! -e $out_file, " Output file does not exist";
345 writeFile($out_file, $already);
346 my $out = new IO::File ">>$out_file" ;
348 ok &$Func($in_file, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
350 ok -e $out_file, " Created output file";
351 my $got = anyUncompress($out_file, $already);
352 $got = undef if ! defined $buffer && $got eq '' ;
353 is $got, $buffer, " Uncompressed matches original";
358 title "$TopType - From Filename to Buffer content '$disp_content' Append $append" ;
360 my $lex = new LexFile($in_file, $out_file) ;
361 writeFile($in_file, $buffer);
365 ok &$Func($in_file => \$out, Append => $append), ' Compressed ok' ;
367 my $got = anyUncompress(\$out, $already);
368 $got = undef if ! defined $buffer && $got eq '' ;
369 is $got, $buffer, " Uncompressed matches original";
374 title "$TopType - From Handle to Filename content '$disp_content' Append $append" ;
376 my $lex = new LexFile($in_file, $out_file) ;
377 writeFile($in_file, $buffer);
378 my $in = new IO::File "<$in_file" ;
380 ok ! -e $out_file, " Output file does not exist";
381 writeFile($out_file, $already);
383 ok &$Func($in, $out_file, Append => $append), ' Compressed ok'
384 or diag "error is $GzipError" ;
386 ok -e $out_file, " Created output file";
387 my $got = anyUncompress($out_file, $already);
388 $got = undef if ! defined $buffer && $got eq '' ;
389 is $buffer, $got, " Uncompressed matches original";
394 title "$TopType - From Handle to Handle content '$disp_content' Append $append" ;
396 my $lex = new LexFile($in_file, $out_file) ;
397 writeFile($in_file, $buffer);
398 my $in = new IO::File "<$in_file" ;
400 ok ! -e $out_file, " Output file does not exist";
401 writeFile($out_file, $already);
402 my $out = new IO::File ">>$out_file" ;
404 ok &$Func($in, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
406 ok -e $out_file, " Created output file";
407 my $got = anyUncompress($out_file, $already);
408 $got = undef if ! defined $buffer && $got eq '' ;
409 is $buffer, $got, " Uncompressed matches original";
414 title "$TopType - From Handle to Buffer content '$disp_content' Append $append" ;
416 my $lex = new LexFile($in_file, $out_file) ;
417 writeFile($in_file, $buffer);
418 my $in = new IO::File "<$in_file" ;
422 ok &$Func($in, \$out, Append => $append), ' Compressed ok' ;
424 my $got = anyUncompress(\$out, $already);
425 $got = undef if ! defined $buffer && $got eq '' ;
426 is $buffer, $got, " Uncompressed matches original";
431 title "$TopType - From stdin (via '-') to Buffer content '$disp_content' Append $append" ;
433 my $lex = new LexFile($in_file, $out_file) ;
434 writeFile($in_file, $buffer);
436 open(SAVEIN, "<&STDIN");
437 my $dummy = fileno SAVEIN ;
438 ok open(STDIN, "<$in_file"), " redirect STDIN";
442 ok &$Func('-', \$out, Append => $append), ' Compressed ok'
445 open(STDIN, "<&SAVEIN");
447 my $got = anyUncompress(\$out, $already);
448 $got = undef if ! defined $buffer && $got eq '' ;
449 is $buffer, $got, " Uncompressed matches original";
457 foreach my $bit ('IO::Compress::Gzip',
458 'IO::Compress::Deflate',
459 'IO::Compress::RawDeflate',
462 my $Error = getErrorRef($bit);
463 my $Func = getTopFuncRef($bit);
464 my $TopType = getTopFuncName($bit);
466 my $TopTypeInverse = getInverse($bit);
467 my $FuncInverse = getTopFuncRef($TopTypeInverse);
469 my ($file1, $file2) = ("file1", "file2");
470 my $lex = new LexFile($file1, $file2) ;
472 writeFile($file1, "data1");
473 writeFile($file2, "data2");
474 my $of = new IO::File "<$file1" ;
475 ok $of, " Created output filehandle" ;
477 my @input = ( undef, "", $file2, \undef, \'', \"abcde", $of) ;
478 my @expected = ("", "", $file2, "", "", "abcde", "data1");
479 my @uexpected = ("", "", "data2", "", "", "abcde", "data1");
484 title "$TopType - From Array Ref to Array Ref" ;
486 my @output = ('first') ;
487 ok &$Func(\@input, \@output, AutoClose => 0), ' Compressed ok' ;
489 is $output[0], 'first', " Array[0] unchanged";
491 is_deeply \@input, \@keep, " Input array not changed" ;
492 my @got = shift @output;
493 foreach (@output) { push @got, anyUncompress($_) }
495 is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
500 title "$TopType - From Array Ref to Buffer" ;
502 # rewind the filehandle
503 $of->open("<$file1") ;
506 ok &$Func(\@input, \$output, AutoClose => 0), ' Compressed ok' ;
508 my $got = anyUncompress(\$output);
510 is $got, join('', @expected), " Got Expected uncompressed data";
514 title "$TopType - From Array Ref to Filename" ;
516 my ($file3) = ("file3");
517 my $lex = new LexFile($file3) ;
519 # rewind the filehandle
520 $of->open("<$file1") ;
523 ok &$Func(\@input, $file3, AutoClose => 0), ' Compressed ok' ;
525 my $got = anyUncompress($file3);
527 is $got, join('', @expected), " Got Expected uncompressed data";
531 title "$TopType - From Array Ref to Filehandle" ;
533 my ($file3) = ("file3");
534 my $lex = new LexFile($file3) ;
536 my $fh3 = new IO::File ">$file3";
538 # rewind the filehandle
539 $of->open("<$file1") ;
542 ok &$Func(\@input, $fh3, AutoClose => 0), ' Compressed ok' ;
546 my $got = anyUncompress($file3);
548 is $got, join('', @expected), " Got Expected uncompressed data";
552 foreach my $bit ('IO::Compress::Gzip',
553 'IO::Compress::Deflate',
554 'IO::Compress::RawDeflate',
557 my $Error = getErrorRef($bit);
558 my $Func = getTopFuncRef($bit);
559 my $TopType = getTopFuncName($bit);
561 my $TopTypeInverse = getInverse($bit);
562 my $FuncInverse = getTopFuncRef($TopTypeInverse);
564 my @inFiles = map { "in$_.tmp" } 1..4;
565 my @outFiles = map { "out$_.tmp" } 1..4;
566 my $lex = new LexFile(@inFiles, @outFiles);
568 writeFile($_, "data $_") foreach @inFiles ;
571 title "$TopType - Hash Ref: to filename" ;
574 ok &$Func( { $inFiles[0] => $outFiles[0],
575 $inFiles[1] => $outFiles[1],
576 $inFiles[2] => $outFiles[2] } ), ' Compressed ok' ;
580 my $got = anyUncompress($outFiles[$_]);
581 is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
586 title "$TopType - Hash Ref: to buffer" ;
589 ok &$Func( { $inFiles[0] => \$buffer[0],
590 $inFiles[1] => \$buffer[1],
591 $inFiles[2] => \$buffer[2] } ), ' Compressed ok' ;
595 my $got = anyUncompress(\$buffer[$_]);
596 is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
601 title "$TopType - Hash Ref: to undef" ;
604 my %hash = ( $inFiles[0] => undef,
605 $inFiles[1] => undef,
606 $inFiles[2] => undef,
609 ok &$Func( \%hash ), ' Compressed ok' ;
613 my $got = anyUncompress(\$hash{$_});
614 is $got, "data $_", " Uncompressed $_ matches original";
619 title "$TopType - Filename to Hash Ref" ;
622 ok &$Func( $inFiles[0] => \%output), ' Compressed ok' ;
624 is keys %output, 1, " one pair in hash" ;
625 my ($k, $v) = each %output;
626 is $k, $inFiles[0], " key is '$inFiles[0]'";
627 my $got = anyUncompress($v);
628 is $got, "data $inFiles[0]", " Uncompressed matches original";
632 title "$TopType - File Glob to Hash Ref" ;
635 ok &$Func( '<in*.tmp>' => \%output), ' Compressed ok' ;
637 is keys %output, 4, " four pairs in hash" ;
638 foreach my $fil (@inFiles)
640 ok exists $output{$fil}, " key '$fil' exists" ;
641 my $got = anyUncompress($output{$fil});
642 is $got, "data $fil", " Uncompressed matches original";
649 # title "$TopType - Hash Ref to Array Ref" ;
651 # my @output = ('first') ;
652 # ok &$Func( { \@input, \@output } , AutoClose => 0), ' Compressed ok' ;
654 # is $output[0], 'first', " Array[0] unchanged";
656 # is_deeply \@input, \@keep, " Input array not changed" ;
657 # my @got = shift @output;
658 # foreach (@output) { push @got, anyUncompress($_) }
660 # is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
666 # title "$TopType - From Array Ref to Buffer" ;
668 # # rewind the filehandle
669 # $of->open("<$file1") ;
672 # ok &$Func(\@input, \$output, AutoClose => 0), ' Compressed ok' ;
674 # my $got = anyUncompress(\$output);
676 # is $got, join('', @expected), " Got Expected uncompressed data";
681 # title "$TopType - From Array Ref to Filename" ;
683 # my ($file3) = ("file3");
684 # my $lex = new LexFile($file3) ;
686 # # rewind the filehandle
687 # $of->open("<$file1") ;
690 # ok &$Func(\@input, $file3, AutoClose => 0), ' Compressed ok' ;
692 # my $got = anyUncompress($file3);
694 # is $got, join('', @expected), " Got Expected uncompressed data";
699 # title "$TopType - From Array Ref to Filehandle" ;
701 # my ($file3) = ("file3");
702 # my $lex = new LexFile($file3) ;
704 # my $fh3 = new IO::File ">$file3";
706 # # rewind the filehandle
707 # $of->open("<$file1") ;
710 # ok &$Func(\@input, $fh3, AutoClose => 0), ' Compressed ok' ;
714 # my $got = anyUncompress($file3);
716 # is $got, join('', @expected), " Got Expected uncompressed data";
720 foreach my $bit ('IO::Compress::Gzip',
721 'IO::Compress::Deflate',
722 'IO::Compress::RawDeflate',
725 my $Error = getErrorRef($bit);
726 my $Func = getTopFuncRef($bit);
727 my $TopType = getTopFuncName($bit);
729 for my $files ( [qw(a1)], [qw(a1 a2 a3)] )
732 my $tmpDir1 = 'tmpdir1';
733 my $tmpDir2 = 'tmpdir2';
734 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
736 mkdir $tmpDir1, 0777;
737 mkdir $tmpDir2, 0777;
739 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
740 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
742 my @files = map { "$tmpDir1/$_.tmp" } @$files ;
743 foreach (@files) { writeFile($_, "abc $_") }
745 my @expected = map { "abc $_" } @files ;
746 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
749 title "$TopType - From FileGlob to FileGlob files [@$files]" ;
751 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>"), ' Compressed ok'
754 my @copy = @expected;
755 for my $file (@outFiles)
757 is anyUncompress($file), shift @copy, " got expected from $file" ;
760 is @copy, 0, " got all files";
764 title "$TopType - From FileGlob to Array files [@$files]" ;
766 my @buffer = ('first') ;
767 ok &$Func("<$tmpDir1/a*.tmp>" => \@buffer), ' Compressed ok'
770 is shift @buffer, 'first';
772 my @copy = @expected;
773 for my $buffer (@buffer)
775 is anyUncompress($buffer), shift @copy, " got expected " ;
778 is @copy, 0, " got all files";
782 title "$TopType - From FileGlob to Buffer files [@$files]" ;
785 ok &$Func("<$tmpDir1/a*.tmp>" => \$buffer), ' Compressed ok'
790 my $got = anyUncompress([ \$buffer, MultiStream => 1 ]);
792 is $got, join("", @expected), " got expected" ;
796 title "$TopType - From FileGlob to Filename files [@$files]" ;
798 my $filename = "abcde";
799 my $lex = new LexFile($filename) ;
801 ok &$Func("<$tmpDir1/a*.tmp>" => $filename), ' Compressed ok'
806 my $got = anyUncompress([$filename, MultiStream => 1]);
808 is $got, join("", @expected), " got expected" ;
812 title "$TopType - From FileGlob to Filehandle files [@$files]" ;
814 my $filename = "abcde";
815 my $lex = new LexFile($filename) ;
816 my $fh = new IO::File ">$filename";
818 ok &$Func("<$tmpDir1/a*.tmp>" => $fh, AutoClose => 1), ' Compressed ok'
823 my $got = anyUncompress([$filename, MultiStream => 1]);
825 is $got, join("", @expected), " got expected" ;
831 foreach my $bit ('IO::Uncompress::Gunzip',
832 'IO::Uncompress::Inflate',
833 'IO::Uncompress::RawInflate',
834 'IO::Uncompress::AnyInflate',
837 my $Error = getErrorRef($bit);
838 my $Func = getTopFuncRef($bit);
839 my $TopType = getTopFuncName($bit);
841 my $buffer = "abcde" ;
842 my $buffer2 = "ABCDE" ;
843 my $keep_orig = $buffer;
845 my $comp = compressBuffer($TopType, $buffer) ;
846 my $comp2 = compressBuffer($TopType, $buffer2) ;
847 my $keep_comp = $comp;
849 my $incumbent = "incumbent data" ;
851 for my $append (0, 1)
853 my $expected = $buffer ;
854 $expected = $incumbent . $buffer if $append ;
857 title "$TopType - From Buff to Buff, Append($append)" ;
860 $output = $incumbent if $append ;
861 ok &$Func(\$comp, \$output, Append => $append), ' Uncompressed ok' ;
863 is $keep_comp, $comp, " Input buffer not changed" ;
864 is $output, $expected, " Uncompressed matches original";
868 title "$TopType - From Buff to Array, Append($append)" ;
870 my @output = ('first');
871 #$output = $incumbent if $append ;
872 ok &$Func(\$comp, \@output, Append => $append), ' Uncompressed ok' ;
874 is $keep_comp, $comp, " Input buffer not changed" ;
875 is $output[0], 'first', " Uncompressed matches original";
876 is ${ $output[1] }, $buffer, " Uncompressed matches original"
878 is @output, 2, " only 2 elements in the array" ;
882 title "$TopType - From Buff to Filename, Append($append)" ;
884 my $out_file = "abcde";
885 my $lex = new LexFile($out_file) ;
887 { writeFile($out_file, $incumbent) }
889 { ok ! -e $out_file, " Output file does not exist" }
891 ok &$Func(\$comp, $out_file, Append => $append), ' Uncompressed ok' ;
893 ok -e $out_file, " Created output file";
894 my $content = readFile($out_file) ;
896 is $keep_comp, $comp, " Input buffer not changed" ;
897 is $content, $expected, " Uncompressed matches original";
901 title "$TopType - From Buff to Handle, Append($append)" ;
903 my $out_file = "abcde";
904 my $lex = new LexFile($out_file) ;
907 writeFile($out_file, $incumbent) ;
908 $of = new IO::File "+< $out_file" ;
911 ok ! -e $out_file, " Output file does not exist" ;
912 $of = new IO::File "> $out_file" ;
914 isa_ok $of, 'IO::File', ' $of' ;
916 ok &$Func(\$comp, $of, Append => $append, AutoClose => 1), ' Uncompressed ok' ;
918 ok -e $out_file, " Created output file";
919 my $content = readFile($out_file) ;
921 is $keep_comp, $comp, " Input buffer not changed" ;
922 is $content, $expected, " Uncompressed matches original";
926 title "$TopType - From Filename to Filename, Append($append)" ;
928 my $out_file = "abcde.out";
929 my $in_file = "abcde.in";
930 my $lex = new LexFile($in_file, $out_file) ;
932 { writeFile($out_file, $incumbent) }
934 { ok ! -e $out_file, " Output file does not exist" }
936 writeFile($in_file, $comp);
938 ok &$Func($in_file, $out_file, Append => $append), ' Uncompressed ok' ;
940 ok -e $out_file, " Created output file";
941 my $content = readFile($out_file) ;
943 is $keep_comp, $comp, " Input buffer not changed" ;
944 is $content, $expected, " Uncompressed matches original";
948 title "$TopType - From Filename to Handle, Append($append)" ;
950 my $out_file = "abcde.out";
951 my $in_file = "abcde.in";
952 my $lex = new LexFile($in_file, $out_file) ;
955 writeFile($out_file, $incumbent) ;
956 $out = new IO::File "+< $out_file" ;
959 ok ! -e $out_file, " Output file does not exist" ;
960 $out = new IO::File "> $out_file" ;
962 isa_ok $out, 'IO::File', ' $out' ;
964 writeFile($in_file, $comp);
966 ok &$Func($in_file, $out, Append => $append, AutoClose => 1), ' Uncompressed ok' ;
968 ok -e $out_file, " Created output file";
969 my $content = readFile($out_file) ;
971 is $keep_comp, $comp, " Input buffer not changed" ;
972 is $content, $expected, " Uncompressed matches original";
976 title "$TopType - From Filename to Buffer, Append($append)" ;
978 my $in_file = "abcde.in";
979 my $lex = new LexFile($in_file) ;
980 writeFile($in_file, $comp);
983 $output = $incumbent if $append ;
985 ok &$Func($in_file, \$output, Append => $append), ' Uncompressed ok' ;
987 is $keep_comp, $comp, " Input buffer not changed" ;
988 is $output, $expected, " Uncompressed matches original";
992 title "$TopType - From Handle to Filename, Append($append)" ;
994 my $out_file = "abcde.out";
995 my $in_file = "abcde.in";
996 my $lex = new LexFile($in_file, $out_file) ;
998 { writeFile($out_file, $incumbent) }
1000 { ok ! -e $out_file, " Output file does not exist" }
1002 writeFile($in_file, $comp);
1003 my $in = new IO::File "<$in_file" ;
1005 ok &$Func($in, $out_file, Append => $append), ' Uncompressed ok' ;
1007 ok -e $out_file, " Created output file";
1008 my $content = readFile($out_file) ;
1010 is $keep_comp, $comp, " Input buffer not changed" ;
1011 is $content, $expected, " Uncompressed matches original";
1015 title "$TopType - From Handle to Handle, Append($append)" ;
1017 my $out_file = "abcde.out";
1018 my $in_file = "abcde.in";
1019 my $lex = new LexFile($in_file, $out_file) ;
1022 writeFile($out_file, $incumbent) ;
1023 $out = new IO::File "+< $out_file" ;
1026 ok ! -e $out_file, " Output file does not exist" ;
1027 $out = new IO::File "> $out_file" ;
1029 isa_ok $out, 'IO::File', ' $out' ;
1031 writeFile($in_file, $comp);
1032 my $in = new IO::File "<$in_file" ;
1034 ok &$Func($in, $out, Append => $append, AutoClose => 1), ' Uncompressed ok' ;
1036 ok -e $out_file, " Created output file";
1037 my $content = readFile($out_file) ;
1039 is $keep_comp, $comp, " Input buffer not changed" ;
1040 is $content, $expected, " Uncompressed matches original";
1044 title "$TopType - From Filename to Buffer, Append($append)" ;
1046 my $in_file = "abcde.in";
1047 my $lex = new LexFile($in_file) ;
1048 writeFile($in_file, $comp);
1049 my $in = new IO::File "<$in_file" ;
1052 $output = $incumbent if $append ;
1054 ok &$Func($in, \$output, Append => $append), ' Uncompressed ok' ;
1056 is $keep_comp, $comp, " Input buffer not changed" ;
1057 is $output, $expected, " Uncompressed matches original";
1061 title "$TopType - From stdin (via '-') to Buffer content, Append($append) " ;
1063 my $in_file = "abcde.in";
1064 my $lex = new LexFile($in_file) ;
1065 writeFile($in_file, $comp);
1067 ok open(SAVEIN, "<&STDIN"), " save STDIN";
1068 my $dummy = fileno SAVEIN ;
1069 ok open(STDIN, "<$in_file"), " redirect STDIN";
1072 $output = $incumbent if $append ;
1074 ok &$Func('-', \$output, Append => $append), ' Uncompressed ok'
1077 ok open(STDIN, "<&SAVEIN"), " put STDIN back";
1079 is $keep_comp, $comp, " Input buffer not changed" ;
1080 is $output, $expected, " Uncompressed matches original";
1085 title "$TopType - From Handle to Buffer, InputLength" ;
1087 my $out_file = "abcde.out";
1088 my $in_file = "abcde.in";
1089 my $lex = new LexFile($in_file, $out_file) ;
1092 my $expected = $buffer ;
1093 my $appended = 'appended';
1094 my $len_appended = length $appended;
1095 writeFile($in_file, $comp . $appended . $comp . $appended) ;
1096 my $in = new IO::File "<$in_file" ;
1098 ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp), ' Uncompressed ok' ;
1100 is $out, $expected, " Uncompressed matches original";
1103 is $in->read($buff, $len_appended), $len_appended, " Length of Appended data ok";
1104 is $buff, $appended, " Appended data ok";
1107 ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp), ' Uncompressed ok' ;
1109 is $out, $expected, " Uncompressed matches original";
1112 is $in->read($buff, $len_appended), $len_appended, " Length of Appended data ok";
1113 is $buff, $appended, " Appended data ok";
1116 for my $stdin ('-', *STDIN) # , \*STDIN)
1118 title "$TopType - From stdin (via $stdin) to Buffer content, InputLength" ;
1120 my $in_file = "abcde.in";
1121 my $lex = new LexFile($in_file) ;
1122 my $expected = $buffer ;
1123 my $appended = 'appended';
1124 my $len_appended = length $appended;
1125 writeFile($in_file, $comp . $appended . $comp . $appended) ;
1127 ok open(SAVEIN, "<&STDIN"), " save STDIN";
1128 my $dummy = fileno SAVEIN ;
1129 ok open(STDIN, "<$in_file"), " redirect STDIN";
1133 ok &$Func($stdin, \$output, Transparent => 0, InputLength => length $comp), ' Uncompressed ok'
1137 is read(STDIN, $buff, $len_appended), $len_appended, " Length of Appended data ok";
1139 is $output, $expected, " Uncompressed matches original";
1140 is $buff, $appended, " Appended data ok";
1143 ok &$Func($stdin, \$output, Transparent => 0, InputLength => length $comp), ' Uncompressed ok'
1147 is read(STDIN, $buff, $len_appended), $len_appended, " Length of Appended data ok"
1148 or diag "read failed $!";
1150 is $output, $expected, " Uncompressed matches original";
1151 is $buff, $appended, " Appended data ok";
1153 ok open(STDIN, "<&SAVEIN"), " put STDIN back";
1157 foreach my $bit ('IO::Uncompress::Gunzip',
1158 'IO::Uncompress::Inflate',
1159 'IO::Uncompress::RawInflate',
1160 'IO::Uncompress::AnyInflate',
1163 # TODO -- Add Append mode tests
1165 my $Error = getErrorRef($bit);
1166 my $Func = getTopFuncRef($bit);
1167 my $TopType = getTopFuncName($bit);
1169 my $buffer = "abcde" ;
1170 my $keep_orig = $buffer;
1173 my $null = compressBuffer($TopType, "") ;
1174 my $undef = compressBuffer($TopType, undef) ;
1175 my $comp = compressBuffer($TopType, $buffer) ;
1176 my $keep_comp = $comp;
1178 my $incumbent = "incumbent data" ;
1180 my ($file1, $file2) = ("file1", "file2");
1181 my $lex = new LexFile($file1, $file2) ;
1183 writeFile($file1, compressBuffer($TopType,"data1"));
1184 writeFile($file2, compressBuffer($TopType,"data2"));
1186 my $of = new IO::File "<$file1" ;
1187 ok $of, " Created output filehandle" ;
1189 my @input = ($file2, \$undef, \$null, \$comp, $of) ;
1190 my @expected = ('data2', '', '', 'abcde', 'data1');
1195 title "$TopType - From ArrayRef to Buffer" ;
1198 ok &$Func(\@input, \$output, AutoClose => 0), ' UnCompressed ok' ;
1200 is $output, join('', @expected)
1204 title "$TopType - From ArrayRef to Filename" ;
1207 my $lex = new LexFile $output;
1208 $of->open("<$file1") ;
1210 ok &$Func(\@input, $output, AutoClose => 0), ' UnCompressed ok' ;
1212 is readFile($output), join('', @expected)
1216 title "$TopType - From ArrayRef to Filehandle" ;
1219 my $lex = new LexFile $output;
1220 my $fh = new IO::File ">$output" ;
1221 $of->open("<$file1") ;
1223 ok &$Func(\@input, $fh, AutoClose => 0), ' UnCompressed ok' ;
1226 is readFile($output), join('', @expected)
1230 title "$TopType - From Array Ref to Array Ref" ;
1232 my @output = (\'first') ;
1233 $of->open("<$file1") ;
1234 ok &$Func(\@input, \@output, AutoClose => 0), ' UnCompressed ok' ;
1236 is_deeply \@input, \@keep, " Input array not changed" ;
1237 is_deeply [map { defined $$_ ? $$_ : "" } @output],
1238 ['first', @expected],
1239 " Got Expected uncompressed data";
1244 foreach my $bit ('IO::Uncompress::Gunzip',
1245 'IO::Uncompress::Inflate',
1246 'IO::Uncompress::RawInflate',
1247 'IO::Uncompress::AnyInflate',
1250 # TODO -- Add Append mode tests
1252 my $Error = getErrorRef($bit);
1253 my $Func = getTopFuncRef($bit);
1254 my $TopType = getTopFuncName($bit);
1256 my $tmpDir1 = 'tmpdir1';
1257 my $tmpDir2 = 'tmpdir2';
1258 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
1260 mkdir $tmpDir1, 0777;
1261 mkdir $tmpDir2, 0777;
1263 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
1264 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
1266 my @files = map { "$tmpDir1/$_.tmp" } qw( a1 a2 a3) ;
1267 foreach (@files) { writeFile($_, compressBuffer($TopType, "abc $_")) }
1269 my @expected = map { "abc $_" } @files ;
1270 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
1273 title "$TopType - From FileGlob to FileGlob" ;
1275 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>"), ' UnCompressed ok'
1278 my @copy = @expected;
1279 for my $file (@outFiles)
1281 is readFile($file), shift @copy, " got expected from $file" ;
1284 is @copy, 0, " got all files";
1288 title "$TopType - From FileGlob to Arrayref" ;
1290 my @output = (\'first');
1291 ok &$Func("<$tmpDir1/a*.tmp>" => \@output), ' UnCompressed ok'
1294 my @copy = ('first', @expected);
1295 for my $data (@output)
1297 is $$data, shift @copy, " got expected data" ;
1300 is @copy, 0, " got all files";
1304 title "$TopType - From FileGlob to Buffer" ;
1307 ok &$Func("<$tmpDir1/a*.tmp>" => \$output), ' UnCompressed ok'
1310 is $output, join('', @expected), " got expected uncompressed data";
1314 title "$TopType - From FileGlob to Filename" ;
1316 my $output = 'abc' ;
1317 my $lex = new LexFile $output ;
1318 ok ! -e $output, " $output does not exist" ;
1319 ok &$Func("<$tmpDir1/a*.tmp>" => $output), ' UnCompressed ok'
1322 ok -e $output, " $output does exist" ;
1323 is readFile($output), join('', @expected), " got expected uncompressed data";
1327 title "$TopType - From FileGlob to Filehandle" ;
1329 my $output = 'abc' ;
1330 my $lex = new LexFile $output ;
1331 my $fh = new IO::File ">$output" ;
1332 ok &$Func("<$tmpDir1/a*.tmp>" => $fh, AutoClose => 1), ' UnCompressed ok'
1335 ok -e $output, " $output does exist" ;
1336 is readFile($output), join('', @expected), " got expected uncompressed data";
1341 foreach my $TopType ('IO::Compress::Gzip::gzip',
1342 'IO::Compress::Deflate',
1343 'IO::Compress::RawDeflate',
1344 # TODO -- add the inflate classes
1347 my $Error = getErrorRef($TopType);
1348 my $Func = getTopFuncRef($TopType);
1349 my $Name = getTopFuncName($TopType);
1351 title "More write tests" ;
1353 my $file1 = "file1" ;
1354 my $file2 = "file2" ;
1355 my $file3 = "file3" ;
1356 my $lex = new LexFile $file1, $file2, $file3 ;
1358 writeFile($file1, "F1");
1359 writeFile($file2, "F2");
1360 writeFile($file3, "F3");
1366 [ '[\"abcd"]', "abcd" ],
1367 [ '[\"ab", \"cd"]', "abcd" ],
1370 [ '[\"a", $fh1, \"bc"]', "aF1bc"],
1374 foreach my $data (@data)
1376 my ($send, $get) = @$data ;
1378 my $fh1 = new IO::File "< $file1" ;
1379 my $fh2 = new IO::File "< $file2" ;
1380 my $fh3 = new IO::File "< $file3" ;
1384 eval "\$copy = $send";
1386 ok &$Func($copy, \$Answer), " $Name ok";
1388 my $got = anyUncompress(\$Answer);
1389 is $got, $get, " got expected output" ;
1390 cmp_ok $$Error, '==', 0, " no error";
1395 title "Array Input Error tests" ;
1400 '[[\"ab"], [\"cd"]]',
1404 foreach my $send (@data)
1406 my $fh1 = new IO::File "< $file1" ;
1407 my $fh2 = new IO::File "< $file2" ;
1408 my $fh3 = new IO::File "< $file3" ;
1412 eval "\$copy = $send";
1414 ok ! &$Func($copy, \$Answer), " $Name fails";
1416 is $$Error, "unknown input parameter", " got error message";
1424 my $content = shift ;
1430 ok IO::Compress::Gzip::gzip($in, \$out, %opts), " gzip ok" ;
1431 ok IO::Uncompress::Gunzip::gunzip(\$out, \$got), " gunzip ok"
1432 or diag $GunzipError ;
1433 is $got, $content, " got expected content" ;
1435 my $gunz = new IO::Uncompress::Gunzip \$out, Strict => 0
1436 or diag "GunzipError is $IO::Uncompress::Gunzip::GunzipError" ;
1437 ok $gunz, " Created IO::Uncompress::Gunzip object";
1438 my $hdr = $gunz->getHeaderInfo();
1439 ok $hdr, " got Header info";
1441 ok $gunz->read($uncomp), " read ok" ;
1442 is $uncomp, $content, " got expected content";
1443 ok $gunz->close, " closed ok" ;
1450 title "Check gzip header default NAME & MTIME settings" ;
1452 my $file1 = "file1" ;
1453 my $lex = new LexFile $file1;
1455 my $content = "hello ";
1459 writeFile($file1, $content);
1460 $mtime = (stat($file1))[8];
1461 # make sure that the gzip file isn't created in the same
1462 # second as the input file
1464 $hdr = gzipGetHeader($file1, $content);
1466 is $hdr->{Name}, $file1, " Name is '$file1'";
1467 is $hdr->{Time}, $mtime, " Time is ok";
1469 title "Override Name" ;
1471 writeFile($file1, $content);
1472 $mtime = (stat($file1))[8];
1474 $hdr = gzipGetHeader($file1, $content, Name => "abcde");
1476 is $hdr->{Name}, "abcde", " Name is 'abcde'" ;
1477 is $hdr->{Time}, $mtime, " Time is ok";
1479 title "Override Time" ;
1481 writeFile($file1, $content);
1482 $hdr = gzipGetHeader($file1, $content, Time => 1234);
1484 is $hdr->{Name}, $file1, " Name is '$file1'" ;
1485 is $hdr->{Time}, 1234, " Time is 1234";
1487 title "Override Name and Time" ;
1489 writeFile($file1, $content);
1490 $hdr = gzipGetHeader($file1, $content, Time => 4321, Name => "abcde");
1492 is $hdr->{Name}, "abcde", " Name is 'abcde'" ;
1493 is $hdr->{Time}, 4321, " Time is 4321";
1495 title "Filehandle doesn't have default Name or Time" ;
1496 my $fh = new IO::File "< $file1"
1497 or diag "Cannot open '$file1': $!\n" ;
1500 $hdr = gzipGetHeader($fh, $content);
1503 ok ! defined $hdr->{Name}, " Name is undef";
1504 cmp_ok $hdr->{Time}, '>=', $before, " Time is ok";
1505 cmp_ok $hdr->{Time}, '<=', $after, " Time is ok";
1509 title "Buffer doesn't have default Name or Time" ;
1510 my $buffer = $content;
1512 $hdr = gzipGetHeader(\$buffer, $content);
1515 ok ! defined $hdr->{Name}, " Name is undef";
1516 cmp_ok $hdr->{Time}, '>=', $before, " Time is ok";
1517 cmp_ok $hdr->{Time}, '<=', $after, " Time is ok";
1520 # TODO add more error cases