4 @INC = ("../lib", "lib");
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 => 2462 + $extra ;
28 use_ok('Compress::Zlib', 2) ;
30 use_ok('IO::Compress::Gzip', qw($GzipError)) ;
31 use_ok('IO::Uncompress::Gunzip', qw($GunzipError)) ;
33 use_ok('IO::Compress::Deflate', qw($DeflateError)) ;
34 use_ok('IO::Uncompress::Inflate', qw($InflateError)) ;
36 use_ok('IO::Compress::RawDeflate', qw($RawDeflateError)) ;
37 use_ok('IO::Uncompress::RawInflate', qw($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 ;
208 substr($out, int(length($out)/3), 10) = 'abcdeabcde';
211 ok ! $FuncInverse->(\$out => \$result, Transparent => 0), " $TopTypeInverse ok";
212 ok $$ErrorInverse, " Got error '$$ErrorInverse'" ;
214 #is $result, $data, " data ok";
216 ok ! anyinflate(\$out => \$result, Transparent => 0), " anyinflate ok";
217 ok $AnyInflateError, " Got error '$AnyInflateError'" ;
221 foreach my $bit ('IO::Compress::Gzip',
222 'IO::Compress::Deflate',
223 'IO::Compress::RawDeflate',
226 my $Error = getErrorRef($bit);
227 my $Func = getTopFuncRef($bit);
228 my $TopType = getTopFuncName($bit);
229 my $TopTypeInverse = getInverse($bit);
230 my $FuncInverse = getTopFuncRef($TopTypeInverse);
232 for my $append ( 1, 0 )
235 $already = 'abcde' if $append ;
237 for my $buffer ( undef, '', "abcde" )
240 my $disp_content = defined $buffer ? $buffer : '<undef>' ;
243 my $out_file = "abcde.out";
244 my $in_file = "abcde.in";
247 title "$TopType - From Buff to Buff content '$disp_content' Append $append" ;
249 my $output = $already;
250 ok &$Func(\$buffer, \$output, Append => $append), ' Compressed ok' ;
252 is $keep, $buffer, " Input buffer not changed" ;
253 my $got = anyUncompress(\$output, $already);
254 $got = undef if ! defined $buffer && $got eq '' ;
255 is $got, $buffer, " Uncompressed matches original";
260 title "$TopType - From Buff to Array Ref content '$disp_content' Append $append" ;
262 my @output = ('first') ;
263 ok &$Func(\$buffer, \@output, Append => $append), ' Compressed ok' ;
265 is $output[0], 'first', " Array[0] unchanged";
266 is $keep, $buffer, " Input buffer not changed" ;
267 my $got = anyUncompress($output[1]);
268 $got = undef if ! defined $buffer && $got eq '' ;
269 is $got, $buffer, " Uncompressed matches original";
273 title "$TopType - From Array Ref to Array Ref content '$disp_content' Append $append" ;
275 my @output = ('first') ;
276 my @input = ( \$buffer);
277 ok &$Func(\@input, \@output, Append => $append), ' Compressed ok' ;
279 is $output[0], 'first', " Array[0] unchanged";
280 is $keep, $buffer, " Input buffer not changed" ;
281 my $got = anyUncompress($output[1]);
282 $got = undef if ! defined $buffer && $got eq '' ;
283 is $got, $buffer, " Uncompressed matches original";
288 title "$TopType - From Buff to Filename content '$disp_content' Append $append" ;
290 my $lex = new LexFile($out_file) ;
291 ok ! -e $out_file, " Output file does not exist";
292 writeFile($out_file, $already);
294 ok &$Func(\$buffer, $out_file, Append => $append), ' Compressed ok' ;
296 ok -e $out_file, " Created output file";
297 my $got = anyUncompress($out_file, $already);
298 $got = undef if ! defined $buffer && $got eq '' ;
299 is $got, $buffer, " Uncompressed matches original";
303 title "$TopType - From Buff to Handle content '$disp_content' Append $append" ;
305 my $lex = new LexFile($out_file) ;
307 ok ! -e $out_file, " Output file does not exist";
308 writeFile($out_file, $already);
309 my $of = new IO::File ">>$out_file" ;
310 ok $of, " Created output filehandle" ;
312 ok &$Func(\$buffer, $of, AutoClose => 1, Append => $append), ' Compressed ok' ;
314 ok -e $out_file, " Created output file";
315 my $got = anyUncompress($out_file, $already);
316 $got = undef if ! defined $buffer && $got eq '' ;
317 is $got, $buffer, " Uncompressed matches original";
322 title "$TopType - From Filename to Filename content '$disp_content' Append $append" ;
324 my $lex = new LexFile($in_file, $out_file) ;
325 writeFile($in_file, $buffer);
327 ok ! -e $out_file, " Output file does not exist";
328 writeFile($out_file, $already);
330 ok &$Func($in_file => $out_file, Append => $append), ' Compressed ok' ;
332 ok -e $out_file, " Created output file";
333 my $got = anyUncompress($out_file, $already);
334 $got = undef if ! defined $buffer && $got eq '' ;
335 is $got, $buffer, " Uncompressed matches original";
340 title "$TopType - From Filename to Handle content '$disp_content' Append $append" ;
342 my $lex = new LexFile($in_file, $out_file) ;
343 writeFile($in_file, $buffer);
345 ok ! -e $out_file, " Output file does not exist";
346 writeFile($out_file, $already);
347 my $out = new IO::File ">>$out_file" ;
349 ok &$Func($in_file, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
351 ok -e $out_file, " Created output file";
352 my $got = anyUncompress($out_file, $already);
353 $got = undef if ! defined $buffer && $got eq '' ;
354 is $got, $buffer, " Uncompressed matches original";
359 title "$TopType - From Filename to Buffer content '$disp_content' Append $append" ;
361 my $lex = new LexFile($in_file, $out_file) ;
362 writeFile($in_file, $buffer);
366 ok &$Func($in_file => \$out, Append => $append), ' Compressed ok' ;
368 my $got = anyUncompress(\$out, $already);
369 $got = undef if ! defined $buffer && $got eq '' ;
370 is $got, $buffer, " Uncompressed matches original";
375 title "$TopType - From Handle to Filename content '$disp_content' Append $append" ;
377 my $lex = new LexFile($in_file, $out_file) ;
378 writeFile($in_file, $buffer);
379 my $in = new IO::File "<$in_file" ;
381 ok ! -e $out_file, " Output file does not exist";
382 writeFile($out_file, $already);
384 ok &$Func($in, $out_file, Append => $append), ' Compressed ok'
385 or diag "error is $GzipError" ;
387 ok -e $out_file, " Created output file";
388 my $got = anyUncompress($out_file, $already);
389 $got = undef if ! defined $buffer && $got eq '' ;
390 is $buffer, $got, " Uncompressed matches original";
395 title "$TopType - From Handle to Handle content '$disp_content' Append $append" ;
397 my $lex = new LexFile($in_file, $out_file) ;
398 writeFile($in_file, $buffer);
399 my $in = new IO::File "<$in_file" ;
401 ok ! -e $out_file, " Output file does not exist";
402 writeFile($out_file, $already);
403 my $out = new IO::File ">>$out_file" ;
405 ok &$Func($in, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
407 ok -e $out_file, " Created output file";
408 my $got = anyUncompress($out_file, $already);
409 $got = undef if ! defined $buffer && $got eq '' ;
410 is $buffer, $got, " Uncompressed matches original";
415 title "$TopType - From Handle to Buffer content '$disp_content' Append $append" ;
417 my $lex = new LexFile($in_file, $out_file) ;
418 writeFile($in_file, $buffer);
419 my $in = new IO::File "<$in_file" ;
423 ok &$Func($in, \$out, Append => $append), ' Compressed ok' ;
425 my $got = anyUncompress(\$out, $already);
426 $got = undef if ! defined $buffer && $got eq '' ;
427 is $buffer, $got, " Uncompressed matches original";
432 title "$TopType - From stdin (via '-') to Buffer content '$disp_content' Append $append" ;
434 my $lex = new LexFile($in_file, $out_file) ;
435 writeFile($in_file, $buffer);
437 open(SAVEIN, "<&STDIN");
438 my $dummy = fileno SAVEIN ;
439 ok open(STDIN, "<$in_file"), " redirect STDIN";
443 ok &$Func('-', \$out, Append => $append), ' Compressed ok'
446 open(STDIN, "<&SAVEIN");
448 my $got = anyUncompress(\$out, $already);
449 $got = undef if ! defined $buffer && $got eq '' ;
450 is $buffer, $got, " Uncompressed matches original";
458 foreach my $bit ('IO::Compress::Gzip',
459 'IO::Compress::Deflate',
460 'IO::Compress::RawDeflate',
463 my $Error = getErrorRef($bit);
464 my $Func = getTopFuncRef($bit);
465 my $TopType = getTopFuncName($bit);
467 my $TopTypeInverse = getInverse($bit);
468 my $FuncInverse = getTopFuncRef($TopTypeInverse);
470 my ($file1, $file2) = ("file1", "file2");
471 my $lex = new LexFile($file1, $file2) ;
473 writeFile($file1, "data1");
474 writeFile($file2, "data2");
475 my $of = new IO::File "<$file1" ;
476 ok $of, " Created output filehandle" ;
478 my @input = ( undef, "", $file2, \undef, \'', \"abcde", $of) ;
479 my @expected = ("", "", $file2, "", "", "abcde", "data1");
480 my @uexpected = ("", "", "data2", "", "", "abcde", "data1");
485 title "$TopType - From Array Ref to Array Ref" ;
487 my @output = ('first') ;
488 ok &$Func(\@input, \@output, AutoClose => 0), ' Compressed ok' ;
490 is $output[0], 'first', " Array[0] unchanged";
492 is_deeply \@input, \@keep, " Input array not changed" ;
493 my @got = shift @output;
494 foreach (@output) { push @got, anyUncompress($_) }
496 is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
501 title "$TopType - From Array Ref to Buffer" ;
503 # rewind the filehandle
504 $of->open("<$file1") ;
507 ok &$Func(\@input, \$output, AutoClose => 0), ' Compressed ok' ;
509 my $got = anyUncompress(\$output);
511 is $got, join('', @expected), " Got Expected uncompressed data";
515 title "$TopType - From Array Ref to Filename" ;
517 my ($file3) = ("file3");
518 my $lex = new LexFile($file3) ;
520 # rewind the filehandle
521 $of->open("<$file1") ;
524 ok &$Func(\@input, $file3, AutoClose => 0), ' Compressed ok' ;
526 my $got = anyUncompress($file3);
528 is $got, join('', @expected), " Got Expected uncompressed data";
532 title "$TopType - From Array Ref to Filehandle" ;
534 my ($file3) = ("file3");
535 my $lex = new LexFile($file3) ;
537 my $fh3 = new IO::File ">$file3";
539 # rewind the filehandle
540 $of->open("<$file1") ;
543 ok &$Func(\@input, $fh3, AutoClose => 0), ' Compressed ok' ;
547 my $got = anyUncompress($file3);
549 is $got, join('', @expected), " Got Expected uncompressed data";
553 foreach my $bit ('IO::Compress::Gzip',
554 'IO::Compress::Deflate',
555 'IO::Compress::RawDeflate',
558 my $Error = getErrorRef($bit);
559 my $Func = getTopFuncRef($bit);
560 my $TopType = getTopFuncName($bit);
562 my $TopTypeInverse = getInverse($bit);
563 my $FuncInverse = getTopFuncRef($TopTypeInverse);
565 my @inFiles = map { "in$_.tmp" } 1..4;
566 my @outFiles = map { "out$_.tmp" } 1..4;
567 my $lex = new LexFile(@inFiles, @outFiles);
569 writeFile($_, "data $_") foreach @inFiles ;
572 title "$TopType - Hash Ref: to filename" ;
575 ok &$Func( { $inFiles[0] => $outFiles[0],
576 $inFiles[1] => $outFiles[1],
577 $inFiles[2] => $outFiles[2] } ), ' Compressed ok' ;
581 my $got = anyUncompress($outFiles[$_]);
582 is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
587 title "$TopType - Hash Ref: to buffer" ;
590 ok &$Func( { $inFiles[0] => \$buffer[0],
591 $inFiles[1] => \$buffer[1],
592 $inFiles[2] => \$buffer[2] } ), ' Compressed ok' ;
596 my $got = anyUncompress(\$buffer[$_]);
597 is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
602 title "$TopType - Hash Ref: to undef" ;
605 my %hash = ( $inFiles[0] => undef,
606 $inFiles[1] => undef,
607 $inFiles[2] => undef,
610 ok &$Func( \%hash ), ' Compressed ok' ;
614 my $got = anyUncompress(\$hash{$_});
615 is $got, "data $_", " Uncompressed $_ matches original";
620 title "$TopType - Filename to Hash Ref" ;
623 ok &$Func( $inFiles[0] => \%output), ' Compressed ok' ;
625 is keys %output, 1, " one pair in hash" ;
626 my ($k, $v) = each %output;
627 is $k, $inFiles[0], " key is '$inFiles[0]'";
628 my $got = anyUncompress($v);
629 is $got, "data $inFiles[0]", " Uncompressed matches original";
633 title "$TopType - File Glob to Hash Ref" ;
636 ok &$Func( '<in*.tmp>' => \%output), ' Compressed ok' ;
638 is keys %output, 4, " four pairs in hash" ;
639 foreach my $fil (@inFiles)
641 ok exists $output{$fil}, " key '$fil' exists" ;
642 my $got = anyUncompress($output{$fil});
643 is $got, "data $fil", " Uncompressed matches original";
650 # title "$TopType - Hash Ref to Array Ref" ;
652 # my @output = ('first') ;
653 # ok &$Func( { \@input, \@output } , AutoClose => 0), ' Compressed ok' ;
655 # is $output[0], 'first', " Array[0] unchanged";
657 # is_deeply \@input, \@keep, " Input array not changed" ;
658 # my @got = shift @output;
659 # foreach (@output) { push @got, anyUncompress($_) }
661 # is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
667 # title "$TopType - From Array Ref to Buffer" ;
669 # # rewind the filehandle
670 # $of->open("<$file1") ;
673 # ok &$Func(\@input, \$output, AutoClose => 0), ' Compressed ok' ;
675 # my $got = anyUncompress(\$output);
677 # is $got, join('', @expected), " Got Expected uncompressed data";
682 # title "$TopType - From Array Ref to Filename" ;
684 # my ($file3) = ("file3");
685 # my $lex = new LexFile($file3) ;
687 # # rewind the filehandle
688 # $of->open("<$file1") ;
691 # ok &$Func(\@input, $file3, AutoClose => 0), ' Compressed ok' ;
693 # my $got = anyUncompress($file3);
695 # is $got, join('', @expected), " Got Expected uncompressed data";
700 # title "$TopType - From Array Ref to Filehandle" ;
702 # my ($file3) = ("file3");
703 # my $lex = new LexFile($file3) ;
705 # my $fh3 = new IO::File ">$file3";
707 # # rewind the filehandle
708 # $of->open("<$file1") ;
711 # ok &$Func(\@input, $fh3, AutoClose => 0), ' Compressed ok' ;
715 # my $got = anyUncompress($file3);
717 # is $got, join('', @expected), " Got Expected uncompressed data";
721 foreach my $bit ('IO::Compress::Gzip',
722 'IO::Compress::Deflate',
723 'IO::Compress::RawDeflate',
726 my $Error = getErrorRef($bit);
727 my $Func = getTopFuncRef($bit);
728 my $TopType = getTopFuncName($bit);
730 for my $files ( [qw(a1)], [qw(a1 a2 a3)] )
733 my $tmpDir1 = 'tmpdir1';
734 my $tmpDir2 = 'tmpdir2';
735 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
737 mkdir $tmpDir1, 0777;
738 mkdir $tmpDir2, 0777;
740 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
741 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
743 my @files = map { "$tmpDir1/$_.tmp" } @$files ;
744 foreach (@files) { writeFile($_, "abc $_") }
746 my @expected = map { "abc $_" } @files ;
747 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
750 title "$TopType - From FileGlob to FileGlob files [@$files]" ;
752 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>"), ' Compressed ok'
755 my @copy = @expected;
756 for my $file (@outFiles)
758 is anyUncompress($file), shift @copy, " got expected from $file" ;
761 is @copy, 0, " got all files";
765 title "$TopType - From FileGlob to Array files [@$files]" ;
767 my @buffer = ('first') ;
768 ok &$Func("<$tmpDir1/a*.tmp>" => \@buffer), ' Compressed ok'
771 is shift @buffer, 'first';
773 my @copy = @expected;
774 for my $buffer (@buffer)
776 is anyUncompress($buffer), shift @copy, " got expected " ;
779 is @copy, 0, " got all files";
783 title "$TopType - From FileGlob to Buffer files [@$files]" ;
786 ok &$Func("<$tmpDir1/a*.tmp>" => \$buffer), ' Compressed ok'
791 my $got = anyUncompress([ \$buffer, MultiStream => 1 ]);
793 is $got, join("", @expected), " got expected" ;
797 title "$TopType - From FileGlob to Filename files [@$files]" ;
799 my $filename = "abcde";
800 my $lex = new LexFile($filename) ;
802 ok &$Func("<$tmpDir1/a*.tmp>" => $filename), ' Compressed ok'
807 my $got = anyUncompress([$filename, MultiStream => 1]);
809 is $got, join("", @expected), " got expected" ;
813 title "$TopType - From FileGlob to Filehandle files [@$files]" ;
815 my $filename = "abcde";
816 my $lex = new LexFile($filename) ;
817 my $fh = new IO::File ">$filename";
819 ok &$Func("<$tmpDir1/a*.tmp>" => $fh, AutoClose => 1), ' Compressed ok'
824 my $got = anyUncompress([$filename, MultiStream => 1]);
826 is $got, join("", @expected), " got expected" ;
832 foreach my $bit ('IO::Uncompress::Gunzip',
833 'IO::Uncompress::Inflate',
834 'IO::Uncompress::RawInflate',
835 'IO::Uncompress::AnyInflate',
838 my $Error = getErrorRef($bit);
839 my $Func = getTopFuncRef($bit);
840 my $TopType = getTopFuncName($bit);
842 my $buffer = "abcde" ;
843 my $buffer2 = "ABCDE" ;
844 my $keep_orig = $buffer;
846 my $comp = compressBuffer($TopType, $buffer) ;
847 my $comp2 = compressBuffer($TopType, $buffer2) ;
848 my $keep_comp = $comp;
850 my $incumbent = "incumbent data" ;
852 for my $append (0, 1)
854 my $expected = $buffer ;
855 $expected = $incumbent . $buffer if $append ;
858 title "$TopType - From Buff to Buff, Append($append)" ;
861 $output = $incumbent if $append ;
862 ok &$Func(\$comp, \$output, Append => $append), ' Uncompressed ok' ;
864 is $keep_comp, $comp, " Input buffer not changed" ;
865 is $output, $expected, " Uncompressed matches original";
869 title "$TopType - From Buff to Array, Append($append)" ;
871 my @output = ('first');
872 #$output = $incumbent if $append ;
873 ok &$Func(\$comp, \@output, Append => $append), ' Uncompressed ok' ;
875 is $keep_comp, $comp, " Input buffer not changed" ;
876 is $output[0], 'first', " Uncompressed matches original";
877 is ${ $output[1] }, $buffer, " Uncompressed matches original"
879 is @output, 2, " only 2 elements in the array" ;
883 title "$TopType - From Buff to Filename, Append($append)" ;
885 my $out_file = "abcde";
886 my $lex = new LexFile($out_file) ;
888 { writeFile($out_file, $incumbent) }
890 { ok ! -e $out_file, " Output file does not exist" }
892 ok &$Func(\$comp, $out_file, Append => $append), ' Uncompressed ok' ;
894 ok -e $out_file, " Created output file";
895 my $content = readFile($out_file) ;
897 is $keep_comp, $comp, " Input buffer not changed" ;
898 is $content, $expected, " Uncompressed matches original";
902 title "$TopType - From Buff to Handle, Append($append)" ;
904 my $out_file = "abcde";
905 my $lex = new LexFile($out_file) ;
908 writeFile($out_file, $incumbent) ;
909 $of = new IO::File "+< $out_file" ;
912 ok ! -e $out_file, " Output file does not exist" ;
913 $of = new IO::File "> $out_file" ;
915 isa_ok $of, 'IO::File', ' $of' ;
917 ok &$Func(\$comp, $of, Append => $append, AutoClose => 1), ' Uncompressed ok' ;
919 ok -e $out_file, " Created output file";
920 my $content = readFile($out_file) ;
922 is $keep_comp, $comp, " Input buffer not changed" ;
923 is $content, $expected, " Uncompressed matches original";
927 title "$TopType - From Filename to Filename, Append($append)" ;
929 my $out_file = "abcde.out";
930 my $in_file = "abcde.in";
931 my $lex = new LexFile($in_file, $out_file) ;
933 { writeFile($out_file, $incumbent) }
935 { ok ! -e $out_file, " Output file does not exist" }
937 writeFile($in_file, $comp);
939 ok &$Func($in_file, $out_file, Append => $append), ' Uncompressed ok' ;
941 ok -e $out_file, " Created output file";
942 my $content = readFile($out_file) ;
944 is $keep_comp, $comp, " Input buffer not changed" ;
945 is $content, $expected, " Uncompressed matches original";
949 title "$TopType - From Filename to Handle, Append($append)" ;
951 my $out_file = "abcde.out";
952 my $in_file = "abcde.in";
953 my $lex = new LexFile($in_file, $out_file) ;
956 writeFile($out_file, $incumbent) ;
957 $out = new IO::File "+< $out_file" ;
960 ok ! -e $out_file, " Output file does not exist" ;
961 $out = new IO::File "> $out_file" ;
963 isa_ok $out, 'IO::File', ' $out' ;
965 writeFile($in_file, $comp);
967 ok &$Func($in_file, $out, Append => $append, AutoClose => 1), ' Uncompressed ok' ;
969 ok -e $out_file, " Created output file";
970 my $content = readFile($out_file) ;
972 is $keep_comp, $comp, " Input buffer not changed" ;
973 is $content, $expected, " Uncompressed matches original";
977 title "$TopType - From Filename to Buffer, Append($append)" ;
979 my $in_file = "abcde.in";
980 my $lex = new LexFile($in_file) ;
981 writeFile($in_file, $comp);
984 $output = $incumbent if $append ;
986 ok &$Func($in_file, \$output, Append => $append), ' Uncompressed ok' ;
988 is $keep_comp, $comp, " Input buffer not changed" ;
989 is $output, $expected, " Uncompressed matches original";
993 title "$TopType - From Handle to Filename, Append($append)" ;
995 my $out_file = "abcde.out";
996 my $in_file = "abcde.in";
997 my $lex = new LexFile($in_file, $out_file) ;
999 { writeFile($out_file, $incumbent) }
1001 { ok ! -e $out_file, " Output file does not exist" }
1003 writeFile($in_file, $comp);
1004 my $in = new IO::File "<$in_file" ;
1006 ok &$Func($in, $out_file, Append => $append), ' Uncompressed ok' ;
1008 ok -e $out_file, " Created output file";
1009 my $content = readFile($out_file) ;
1011 is $keep_comp, $comp, " Input buffer not changed" ;
1012 is $content, $expected, " Uncompressed matches original";
1016 title "$TopType - From Handle to Handle, Append($append)" ;
1018 my $out_file = "abcde.out";
1019 my $in_file = "abcde.in";
1020 my $lex = new LexFile($in_file, $out_file) ;
1023 writeFile($out_file, $incumbent) ;
1024 $out = new IO::File "+< $out_file" ;
1027 ok ! -e $out_file, " Output file does not exist" ;
1028 $out = new IO::File "> $out_file" ;
1030 isa_ok $out, 'IO::File', ' $out' ;
1032 writeFile($in_file, $comp);
1033 my $in = new IO::File "<$in_file" ;
1035 ok &$Func($in, $out, Append => $append, AutoClose => 1), ' Uncompressed ok' ;
1037 ok -e $out_file, " Created output file";
1038 my $content = readFile($out_file) ;
1040 is $keep_comp, $comp, " Input buffer not changed" ;
1041 is $content, $expected, " Uncompressed matches original";
1045 title "$TopType - From Filename to Buffer, Append($append)" ;
1047 my $in_file = "abcde.in";
1048 my $lex = new LexFile($in_file) ;
1049 writeFile($in_file, $comp);
1050 my $in = new IO::File "<$in_file" ;
1053 $output = $incumbent if $append ;
1055 ok &$Func($in, \$output, Append => $append), ' Uncompressed ok' ;
1057 is $keep_comp, $comp, " Input buffer not changed" ;
1058 is $output, $expected, " Uncompressed matches original";
1062 title "$TopType - From stdin (via '-') to Buffer content, Append($append) " ;
1064 my $in_file = "abcde.in";
1065 my $lex = new LexFile($in_file) ;
1066 writeFile($in_file, $comp);
1068 open(SAVEIN, "<&STDIN");
1069 my $dummy = fileno SAVEIN ;
1070 ok open(STDIN, "<$in_file"), " redirect STDIN";
1073 $output = $incumbent if $append ;
1075 ok &$Func('-', \$output, Append => $append), ' Uncompressed ok'
1078 open(STDIN, "<&SAVEIN");
1080 is $keep_comp, $comp, " Input buffer not changed" ;
1081 is $output, $expected, " Uncompressed matches original";
1086 title "$TopType - From Handle to Buffer, InputLength" ;
1088 my $out_file = "abcde.out";
1089 my $in_file = "abcde.in";
1090 my $lex = new LexFile($in_file, $out_file) ;
1093 my $expected = $buffer ;
1094 my $appended = 'appended';
1095 my $len_appended = length $appended;
1096 writeFile($in_file, $comp . $appended . $comp . $appended) ;
1097 my $in = new IO::File "<$in_file" ;
1099 ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp), ' Uncompressed ok' ;
1101 is $out, $expected, " Uncompressed matches original";
1104 is $in->read($buff, $len_appended), $len_appended, " Length of Appended data ok";
1105 is $buff, $appended, " Appended data ok";
1108 ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp), ' Uncompressed ok' ;
1110 is $out, $expected, " Uncompressed matches original";
1113 is $in->read($buff, $len_appended), $len_appended, " Length of Appended data ok";
1114 is $buff, $appended, " Appended data ok";
1117 for my $stdin ('-', *STDIN) # , \*STDIN)
1119 title "$TopType - From stdin (via $stdin) to Buffer content, InputLength" ;
1121 my $lex = new LexFile my $in_file ;
1122 my $expected = $buffer ;
1123 my $appended = 'appended';
1124 my $len_appended = length $appended;
1125 writeFile($in_file, $comp . $appended ) ;
1127 open(SAVEIN, "<&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";
1142 open(STDIN, "<&SAVEIN");
1146 foreach my $bit ('IO::Uncompress::Gunzip',
1147 'IO::Uncompress::Inflate',
1148 'IO::Uncompress::RawInflate',
1149 'IO::Uncompress::AnyInflate',
1152 # TODO -- Add Append mode tests
1154 my $Error = getErrorRef($bit);
1155 my $Func = getTopFuncRef($bit);
1156 my $TopType = getTopFuncName($bit);
1158 my $buffer = "abcde" ;
1159 my $keep_orig = $buffer;
1162 my $null = compressBuffer($TopType, "") ;
1163 my $undef = compressBuffer($TopType, undef) ;
1164 my $comp = compressBuffer($TopType, $buffer) ;
1165 my $keep_comp = $comp;
1167 my $incumbent = "incumbent data" ;
1169 my ($file1, $file2) = ("file1", "file2");
1170 my $lex = new LexFile($file1, $file2) ;
1172 writeFile($file1, compressBuffer($TopType,"data1"));
1173 writeFile($file2, compressBuffer($TopType,"data2"));
1175 my $of = new IO::File "<$file1" ;
1176 ok $of, " Created output filehandle" ;
1178 my @input = ($file2, \$undef, \$null, \$comp, $of) ;
1179 my @expected = ('data2', '', '', 'abcde', 'data1');
1184 title "$TopType - From ArrayRef to Buffer" ;
1187 ok &$Func(\@input, \$output, AutoClose => 0), ' UnCompressed ok' ;
1189 is $output, join('', @expected)
1193 title "$TopType - From ArrayRef to Filename" ;
1196 my $lex = new LexFile $output;
1197 $of->open("<$file1") ;
1199 ok &$Func(\@input, $output, AutoClose => 0), ' UnCompressed ok' ;
1201 is readFile($output), join('', @expected)
1205 title "$TopType - From ArrayRef to Filehandle" ;
1208 my $lex = new LexFile $output;
1209 my $fh = new IO::File ">$output" ;
1210 $of->open("<$file1") ;
1212 ok &$Func(\@input, $fh, AutoClose => 0), ' UnCompressed ok' ;
1215 is readFile($output), join('', @expected)
1219 title "$TopType - From Array Ref to Array Ref" ;
1221 my @output = (\'first') ;
1222 $of->open("<$file1") ;
1223 ok &$Func(\@input, \@output, AutoClose => 0), ' UnCompressed ok' ;
1225 is_deeply \@input, \@keep, " Input array not changed" ;
1226 is_deeply [map { defined $$_ ? $$_ : "" } @output],
1227 ['first', @expected],
1228 " Got Expected uncompressed data";
1233 foreach my $bit ('IO::Uncompress::Gunzip',
1234 'IO::Uncompress::Inflate',
1235 'IO::Uncompress::RawInflate',
1236 'IO::Uncompress::AnyInflate',
1239 # TODO -- Add Append mode tests
1241 my $Error = getErrorRef($bit);
1242 my $Func = getTopFuncRef($bit);
1243 my $TopType = getTopFuncName($bit);
1245 my $tmpDir1 = 'tmpdir1';
1246 my $tmpDir2 = 'tmpdir2';
1247 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
1249 mkdir $tmpDir1, 0777;
1250 mkdir $tmpDir2, 0777;
1252 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
1253 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
1255 my @files = map { "$tmpDir1/$_.tmp" } qw( a1 a2 a3) ;
1256 foreach (@files) { writeFile($_, compressBuffer($TopType, "abc $_")) }
1258 my @expected = map { "abc $_" } @files ;
1259 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
1262 title "$TopType - From FileGlob to FileGlob" ;
1264 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>"), ' UnCompressed ok'
1267 my @copy = @expected;
1268 for my $file (@outFiles)
1270 is readFile($file), shift @copy, " got expected from $file" ;
1273 is @copy, 0, " got all files";
1277 title "$TopType - From FileGlob to Arrayref" ;
1279 my @output = (\'first');
1280 ok &$Func("<$tmpDir1/a*.tmp>" => \@output), ' UnCompressed ok'
1283 my @copy = ('first', @expected);
1284 for my $data (@output)
1286 is $$data, shift @copy, " got expected data" ;
1289 is @copy, 0, " got all files";
1293 title "$TopType - From FileGlob to Buffer" ;
1296 ok &$Func("<$tmpDir1/a*.tmp>" => \$output), ' UnCompressed ok'
1299 is $output, join('', @expected), " got expected uncompressed data";
1303 title "$TopType - From FileGlob to Filename" ;
1305 my $output = 'abc' ;
1306 my $lex = new LexFile $output ;
1307 ok ! -e $output, " $output does not exist" ;
1308 ok &$Func("<$tmpDir1/a*.tmp>" => $output), ' UnCompressed ok'
1311 ok -e $output, " $output does exist" ;
1312 is readFile($output), join('', @expected), " got expected uncompressed data";
1316 title "$TopType - From FileGlob to Filehandle" ;
1318 my $output = 'abc' ;
1319 my $lex = new LexFile $output ;
1320 my $fh = new IO::File ">$output" ;
1321 ok &$Func("<$tmpDir1/a*.tmp>" => $fh, AutoClose => 1), ' UnCompressed ok'
1324 ok -e $output, " $output does exist" ;
1325 is readFile($output), join('', @expected), " got expected uncompressed data";
1330 foreach my $TopType ('IO::Compress::Gzip::gzip',
1331 'IO::Compress::Deflate',
1332 'IO::Compress::RawDeflate',
1333 # TODO -- add the inflate classes
1336 my $Error = getErrorRef($TopType);
1337 my $Func = getTopFuncRef($TopType);
1338 my $Name = getTopFuncName($TopType);
1340 title "More write tests" ;
1342 my $file1 = "file1" ;
1343 my $file2 = "file2" ;
1344 my $file3 = "file3" ;
1345 my $lex = new LexFile $file1, $file2, $file3 ;
1347 writeFile($file1, "F1");
1348 writeFile($file2, "F2");
1349 writeFile($file3, "F3");
1355 [ '[\"abcd"]', "abcd" ],
1356 [ '[\"ab", \"cd"]', "abcd" ],
1359 [ '[\"a", $fh1, \"bc"]', "aF1bc"],
1363 foreach my $data (@data)
1365 my ($send, $get) = @$data ;
1367 my $fh1 = new IO::File "< $file1" ;
1368 my $fh2 = new IO::File "< $file2" ;
1369 my $fh3 = new IO::File "< $file3" ;
1373 eval "\$copy = $send";
1375 ok &$Func($copy, \$Answer), " $Name ok";
1377 my $got = anyUncompress(\$Answer);
1378 is $got, $get, " got expected output" ;
1379 ok ! $$Error, " no error"
1380 or diag "Error is $$Error";
1384 title "Array Input Error tests" ;
1389 '[[\"ab"], [\"cd"]]',
1393 foreach my $send (@data)
1395 my $fh1 = new IO::File "< $file1" ;
1396 my $fh2 = new IO::File "< $file2" ;
1397 my $fh3 = new IO::File "< $file3" ;
1401 eval "\$copy = $send";
1403 ok ! &$Func($copy, \$Answer), " $Name fails";
1405 is $$Error, "unknown input parameter", " got error message";
1413 my $content = shift ;
1419 ok IO::Compress::Gzip::gzip($in, \$out, %opts), " gzip ok" ;
1420 ok IO::Uncompress::Gunzip::gunzip(\$out, \$got), " gunzip ok"
1421 or diag $GunzipError ;
1422 is $got, $content, " got expected content" ;
1424 my $gunz = new IO::Uncompress::Gunzip \$out, Strict => 0
1425 or diag "GunzipError is $IO::Uncompress::Gunzip::GunzipError" ;
1426 ok $gunz, " Created IO::Uncompress::Gunzip object";
1427 my $hdr = $gunz->getHeaderInfo();
1428 ok $hdr, " got Header info";
1430 ok $gunz->read($uncomp), " read ok" ;
1431 is $uncomp, $content, " got expected content";
1432 ok $gunz->close, " closed ok" ;
1439 title "Check gzip header default NAME & MTIME settings" ;
1441 my $file1 = "file1" ;
1442 my $lex = new LexFile $file1;
1444 my $content = "hello ";
1448 writeFile($file1, $content);
1449 $mtime = (stat($file1))[8];
1450 # make sure that the gzip file isn't created in the same
1451 # second as the input file
1453 $hdr = gzipGetHeader($file1, $content);
1455 is $hdr->{Name}, $file1, " Name is '$file1'";
1456 is $hdr->{Time}, $mtime, " Time is ok";
1458 title "Override Name" ;
1460 writeFile($file1, $content);
1461 $mtime = (stat($file1))[8];
1463 $hdr = gzipGetHeader($file1, $content, Name => "abcde");
1465 is $hdr->{Name}, "abcde", " Name is 'abcde'" ;
1466 is $hdr->{Time}, $mtime, " Time is ok";
1468 title "Override Time" ;
1470 writeFile($file1, $content);
1471 $hdr = gzipGetHeader($file1, $content, Time => 1234);
1473 is $hdr->{Name}, $file1, " Name is '$file1'" ;
1474 is $hdr->{Time}, 1234, " Time is 1234";
1476 title "Override Name and Time" ;
1478 writeFile($file1, $content);
1479 $hdr = gzipGetHeader($file1, $content, Time => 4321, Name => "abcde");
1481 is $hdr->{Name}, "abcde", " Name is 'abcde'" ;
1482 is $hdr->{Time}, 4321, " Time is 4321";
1484 title "Filehandle doesn't have default Name or Time" ;
1485 my $fh = new IO::File "< $file1"
1486 or diag "Cannot open '$file1': $!\n" ;
1489 $hdr = gzipGetHeader($fh, $content);
1492 ok ! defined $hdr->{Name}, " Name is undef";
1493 cmp_ok $hdr->{Time}, '>=', $before, " Time is ok";
1494 cmp_ok $hdr->{Time}, '<=', $after, " Time is ok";
1498 title "Buffer doesn't have default Name or Time" ;
1499 my $buffer = $content;
1501 $hdr = gzipGetHeader(\$buffer, $content);
1504 ok ! defined $hdr->{Name}, " Name is undef";
1505 cmp_ok $hdr->{Time}, '>=', $before, " Time is ok";
1506 cmp_ok $hdr->{Time}, '<=', $after, " Time is ok";
1509 # TODO add more error cases