11 plan(skip_all => "oneshot needs Perl 5.005 or better - you have Perl $]" )
15 # use Test::NoWarnings, if available
18 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
20 plan tests => 2526 + $extra ;
22 use_ok('Compress::Zlib', 2) ;
24 use_ok('IO::Compress::Gzip', qw(gzip $GzipError)) ;
25 use_ok('IO::Uncompress::Gunzip', qw(gunzip $GunzipError)) ;
27 use_ok('IO::Compress::Deflate', qw(deflate $DeflateError)) ;
28 use_ok('IO::Uncompress::Inflate', qw(inflate $InflateError)) ;
30 use_ok('IO::Compress::RawDeflate', qw(rawdeflate $RawDeflateError)) ;
31 use_ok('IO::Uncompress::RawInflate', qw(rawinflate $RawInflateError)) ;
33 use_ok('IO::Uncompress::AnyInflate', qw(anyinflate $AnyInflateError)) ;
38 # Check zlib_version and ZLIB_VERSION are the same.
39 is Compress::Zlib::zlib_version, ZLIB_VERSION,
40 "ZLIB_VERSION matches Compress::Zlib::zlib_version" ;
44 foreach my $bit ('IO::Compress::Gzip',
45 'IO::Uncompress::Gunzip',
46 'IO::Compress::Deflate',
47 'IO::Uncompress::Inflate',
48 'IO::Compress::RawDeflate',
49 'IO::Uncompress::RawInflate',
50 'IO::Uncompress::AnyInflate',
53 my $Error = getErrorRef($bit);
54 my $Func = getTopFuncRef($bit);
55 my $TopType = getTopFuncName($bit);
57 title "Testing $TopType Error Cases";
62 eval { $a = $Func->(\$a => \$x, Fred => 1) ;} ;
63 like $@, mkErr("^$TopType: unknown key value\\(s\\) Fred"), ' Illegal Parameters';
65 eval { $a = $Func->() ;} ;
66 like $@, mkErr("^$TopType: expected at least 1 parameters"), ' No Parameters';
68 eval { $a = $Func->(\$x, \1) ;} ;
69 like $@, mkErr("^$TopType: output buffer is read-only"), ' Output is read-only' ;
72 eval { $a = $Func->($in, \$x) ;} ;
73 like $@, mkErr("^$TopType: input filename is undef or null string"),
74 ' Input filename undef' ;
77 eval { $a = $Func->($in, \$x) ;} ;
78 like $@, mkErr("^$TopType: input filename is undef or null string"),
79 ' Input filename empty' ;
82 my $lex1 = new LexFile($in) ;
83 writeFile($in, "abc");
85 eval { $a = $Func->($in, $out) ;} ;
86 like $@, mkErr("^$TopType: input and output filename are identical"),
87 ' Input and Output filename are the same';
89 eval { $a = $Func->(\$in, \$in) ;} ;
90 like $@, mkErr("^$TopType: input and output buffer are identical"),
91 ' Input and Output buffer are the same';
93 my $out_file = "abcde.out";
94 my $lex = new LexFile($out_file) ;
95 open OUT, ">$out_file" ;
96 eval { $a = $Func->(\*OUT, \*OUT) ;} ;
97 like $@, mkErr("^$TopType: input and output handle are identical"),
98 ' Input and Output handle are the same';
101 is -s $out_file, 0, " File zero length" ;
104 my $object = bless \%x, "someClass" ;
106 # Buffer not a scalar reference
107 #eval { $a = $Func->(\$x, \%x) ;} ;
108 eval { $a = $Func->(\$x, $object) ;} ;
109 like $@, mkErr("^$TopType: illegal output parameter"),
113 #eval { $a = $Func->(\%x, \$x) ;} ;
114 eval { $a = $Func->($object, \$x) ;} ;
115 like $@, mkErr("^$TopType: illegal input parameter"),
119 my $filename = 'abc.def';
120 ok ! -e $filename, " input file '$filename' does not exist";
121 $a = $Func->($filename, \$x) ;
122 is $a, undef, " $TopType returned undef";
123 like $$Error, "/^input file '$filename' does not exist\$/", " input File '$filename' does not exist";
125 $filename = '/tmp/abd/abc.def';
126 ok ! -e $filename, " output File '$filename' does not exist";
127 $a = $Func->(\$x, $filename) ;
128 is $a, undef, " $TopType returned undef";
129 like $$Error, ("/^(cannot open file '$filename'|input file '$filename' does not exist):/"), " output File '$filename' does not exist";
131 $a = $Func->(\$x, '<abc>') ;
132 is $a, undef, " $TopType returned undef";
133 like $$Error, "/Need input fileglob for outout fileglob/",
134 ' Output fileglob with no input fileglob';
136 $a = $Func->('<abc)>', '<abc>') ;
137 is $a, undef, " $TopType returned undef";
138 like $$Error, "/Unmatched \\) in input fileglob/",
139 " Unmatched ) in input fileglob";
142 foreach my $bit ('IO::Uncompress::Gunzip',
143 'IO::Uncompress::Inflate',
144 'IO::Uncompress::RawInflate',
145 'IO::Uncompress::AnyInflate',
148 my $Error = getErrorRef($bit);
149 my $Func = getTopFuncRef($bit);
150 my $TopType = getTopFuncName($bit);
152 my $data = "mary had a little lamb" ;
155 for my $trans ( 0, 1)
157 title "Non-compressed data with $TopType, Transparent => $trans ";
162 $a = $Func->(\$data, \$out, Transparent => $trans) ;
164 is $data, $keep, " Input buffer not changed" ;
168 ok $a, " $TopType returned true" ;
169 is $out, $data, " got expected output" ;
170 ok ! $$Error, " no error [$$Error]" ;
174 ok ! $a, " $TopType returned false" ;
175 #like $$Error, '/xxx/', " error" ;
176 ok $$Error, " error is '$$Error'" ;
181 foreach my $bit ('IO::Compress::Gzip',
182 'IO::Compress::Deflate',
183 'IO::Compress::RawDeflate',
186 my $Error = getErrorRef($bit);
187 my $Func = getTopFuncRef($bit);
188 my $TopType = getTopFuncName($bit);
189 my $TopTypeInverse = getInverse($bit);
190 my $FuncInverse = getTopFuncRef($TopTypeInverse);
191 my $ErrorInverse = getErrorRef($TopTypeInverse);
193 title "$TopTypeInverse - corrupt data";
195 my $data = "abcd" x 100 ;
198 ok $Func->(\$data, \$out), " $TopType ok";
200 # corrupt the compressed data
201 substr($out, -10, 10) = "x" x 10 ;
204 ok ! $FuncInverse->(\$out => \$result, Transparent => 0), " $TopTypeInverse ok";
205 ok $$ErrorInverse, " Got error '$$ErrorInverse'" ;
207 #is $result, $data, " data ok";
209 ok ! anyinflate(\$out => \$result, Transparent => 0), " anyinflate ok";
210 ok $AnyInflateError, " Got error '$AnyInflateError'" ;
214 foreach my $bit ('IO::Compress::Gzip',
215 'IO::Compress::Deflate',
216 'IO::Compress::RawDeflate',
219 my $Error = getErrorRef($bit);
220 my $Func = getTopFuncRef($bit);
221 my $TopType = getTopFuncName($bit);
222 my $TopTypeInverse = getInverse($bit);
223 my $FuncInverse = getTopFuncRef($TopTypeInverse);
225 for my $append ( 1, 0 )
228 $already = 'abcde' if $append ;
230 for my $buffer ( undef, '', "abcde" )
233 my $disp_content = defined $buffer ? $buffer : '<undef>' ;
236 my $out_file = "abcde.out";
237 my $in_file = "abcde.in";
240 title "$TopType - From Buff to Buff content '$disp_content' Append $append" ;
242 my $output = $already;
243 ok &$Func(\$buffer, \$output, Append => $append), ' Compressed ok' ;
245 is $keep, $buffer, " Input buffer not changed" ;
246 my $got = anyUncompress(\$output, $already);
247 $got = undef if ! defined $buffer && $got eq '' ;
248 is $got, $buffer, " Uncompressed matches original";
253 title "$TopType - From Buff to Array Ref content '$disp_content' Append $append" ;
255 my @output = ('first') ;
256 ok &$Func(\$buffer, \@output, Append => $append), ' Compressed ok' ;
258 is $output[0], 'first', " Array[0] unchanged";
259 is $keep, $buffer, " Input buffer not changed" ;
260 my $got = anyUncompress($output[1]);
261 $got = undef if ! defined $buffer && $got eq '' ;
262 is $got, $buffer, " Uncompressed matches original";
266 title "$TopType - From Array Ref to Array Ref content '$disp_content' Append $append" ;
268 my @output = ('first') ;
269 my @input = ( \$buffer);
270 ok &$Func(\@input, \@output, Append => $append), ' Compressed ok' ;
272 is $output[0], 'first', " Array[0] unchanged";
273 is $keep, $buffer, " Input buffer not changed" ;
274 my $got = anyUncompress($output[1]);
275 $got = undef if ! defined $buffer && $got eq '' ;
276 is $got, $buffer, " Uncompressed matches original";
281 title "$TopType - From Buff to Filename content '$disp_content' Append $append" ;
283 my $lex = new LexFile($out_file) ;
284 ok ! -e $out_file, " Output file does not exist";
285 writeFile($out_file, $already);
287 ok &$Func(\$buffer, $out_file, Append => $append), ' Compressed ok' ;
289 ok -e $out_file, " Created output file";
290 my $got = anyUncompress($out_file, $already);
291 $got = undef if ! defined $buffer && $got eq '' ;
292 is $got, $buffer, " Uncompressed matches original";
296 title "$TopType - From Buff to Handle content '$disp_content' Append $append" ;
298 my $lex = new LexFile($out_file) ;
300 ok ! -e $out_file, " Output file does not exist";
301 writeFile($out_file, $already);
302 my $of = new IO::File ">>$out_file" ;
303 ok $of, " Created output filehandle" ;
305 ok &$Func(\$buffer, $of, AutoClose => 1, Append => $append), ' Compressed ok' ;
307 ok -e $out_file, " Created output file";
308 my $got = anyUncompress($out_file, $already);
309 $got = undef if ! defined $buffer && $got eq '' ;
310 is $got, $buffer, " Uncompressed matches original";
315 title "$TopType - From Filename to Filename content '$disp_content' Append $append" ;
317 my $lex = new LexFile($in_file, $out_file) ;
318 writeFile($in_file, $buffer);
320 ok ! -e $out_file, " Output file does not exist";
321 writeFile($out_file, $already);
323 ok &$Func($in_file => $out_file, Append => $append), ' Compressed ok' ;
325 ok -e $out_file, " Created output file";
326 my $got = anyUncompress($out_file, $already);
327 $got = undef if ! defined $buffer && $got eq '' ;
328 is $got, $buffer, " Uncompressed matches original";
333 title "$TopType - From Filename to Handle content '$disp_content' Append $append" ;
335 my $lex = new LexFile($in_file, $out_file) ;
336 writeFile($in_file, $buffer);
338 ok ! -e $out_file, " Output file does not exist";
339 writeFile($out_file, $already);
340 my $out = new IO::File ">>$out_file" ;
342 ok &$Func($in_file, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
344 ok -e $out_file, " Created output file";
345 my $got = anyUncompress($out_file, $already);
346 $got = undef if ! defined $buffer && $got eq '' ;
347 is $got, $buffer, " Uncompressed matches original";
352 title "$TopType - From Filename to Buffer content '$disp_content' Append $append" ;
354 my $lex = new LexFile($in_file, $out_file) ;
355 writeFile($in_file, $buffer);
359 ok &$Func($in_file => \$out, Append => $append), ' Compressed ok' ;
361 my $got = anyUncompress(\$out, $already);
362 $got = undef if ! defined $buffer && $got eq '' ;
363 is $got, $buffer, " Uncompressed matches original";
368 title "$TopType - From Handle to Filename content '$disp_content' Append $append" ;
370 my $lex = new LexFile($in_file, $out_file) ;
371 writeFile($in_file, $buffer);
372 my $in = new IO::File "<$in_file" ;
374 ok ! -e $out_file, " Output file does not exist";
375 writeFile($out_file, $already);
377 ok &$Func($in, $out_file, Append => $append), ' Compressed ok'
378 or diag "error is $GzipError" ;
380 ok -e $out_file, " Created output file";
381 my $got = anyUncompress($out_file, $already);
382 $got = undef if ! defined $buffer && $got eq '' ;
383 is $buffer, $got, " Uncompressed matches original";
388 title "$TopType - From Handle to Handle content '$disp_content' Append $append" ;
390 my $lex = new LexFile($in_file, $out_file) ;
391 writeFile($in_file, $buffer);
392 my $in = new IO::File "<$in_file" ;
394 ok ! -e $out_file, " Output file does not exist";
395 writeFile($out_file, $already);
396 my $out = new IO::File ">>$out_file" ;
398 ok &$Func($in, $out, AutoClose => 1, Append => $append), ' Compressed ok' ;
400 ok -e $out_file, " Created output file";
401 my $got = anyUncompress($out_file, $already);
402 $got = undef if ! defined $buffer && $got eq '' ;
403 is $buffer, $got, " Uncompressed matches original";
408 title "$TopType - From Handle to Buffer content '$disp_content' Append $append" ;
410 my $lex = new LexFile($in_file, $out_file) ;
411 writeFile($in_file, $buffer);
412 my $in = new IO::File "<$in_file" ;
416 ok &$Func($in, \$out, Append => $append), ' Compressed ok' ;
418 my $got = anyUncompress(\$out, $already);
419 $got = undef if ! defined $buffer && $got eq '' ;
420 is $buffer, $got, " Uncompressed matches original";
425 title "$TopType - From stdin (via '-') to Buffer content '$disp_content' Append $append" ;
427 my $lex = new LexFile($in_file, $out_file) ;
428 writeFile($in_file, $buffer);
430 open(SAVEIN, "<&STDIN");
431 my $dummy = fileno SAVEIN ;
432 ok open(STDIN, "<$in_file"), " redirect STDIN";
436 ok &$Func('-', \$out, Append => $append), ' Compressed ok'
439 open(STDIN, "<&SAVEIN");
441 my $got = anyUncompress(\$out, $already);
442 $got = undef if ! defined $buffer && $got eq '' ;
443 is $buffer, $got, " Uncompressed matches original";
451 foreach my $bit ('IO::Compress::Gzip',
452 'IO::Compress::Deflate',
453 'IO::Compress::RawDeflate',
456 my $Error = getErrorRef($bit);
457 my $Func = getTopFuncRef($bit);
458 my $TopType = getTopFuncName($bit);
460 my $TopTypeInverse = getInverse($bit);
461 my $FuncInverse = getTopFuncRef($TopTypeInverse);
463 my ($file1, $file2) = ("file1", "file2");
464 my $lex = new LexFile($file1, $file2) ;
466 writeFile($file1, "data1");
467 writeFile($file2, "data2");
468 my $of = new IO::File "<$file1" ;
469 ok $of, " Created output filehandle" ;
471 my @input = ( undef, "", $file2, \undef, \'', \"abcde", $of) ;
472 my @expected = ("", "", $file2, "", "", "abcde", "data1");
473 my @uexpected = ("", "", "data2", "", "", "abcde", "data1");
478 title "$TopType - From Array Ref to Array Ref" ;
480 my @output = ('first') ;
481 ok &$Func(\@input, \@output, AutoClose => 0), ' Compressed ok' ;
483 is $output[0], 'first', " Array[0] unchanged";
485 is_deeply \@input, \@keep, " Input array not changed" ;
486 my @got = shift @output;
487 foreach (@output) { push @got, anyUncompress($_) }
489 is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
494 title "$TopType - From Array Ref to Buffer" ;
496 # rewind the filehandle
497 $of->open("<$file1") ;
500 ok &$Func(\@input, \$output, AutoClose => 0), ' Compressed ok' ;
502 my $got = anyUncompress(\$output);
504 is $got, join('', @expected), " Got Expected uncompressed data";
508 title "$TopType - From Array Ref to Filename" ;
510 my ($file3) = ("file3");
511 my $lex = new LexFile($file3) ;
513 # rewind the filehandle
514 $of->open("<$file1") ;
517 ok &$Func(\@input, $file3, AutoClose => 0), ' Compressed ok' ;
519 my $got = anyUncompress($file3);
521 is $got, join('', @expected), " Got Expected uncompressed data";
525 title "$TopType - From Array Ref to Filehandle" ;
527 my ($file3) = ("file3");
528 my $lex = new LexFile($file3) ;
530 my $fh3 = new IO::File ">$file3";
532 # rewind the filehandle
533 $of->open("<$file1") ;
536 ok &$Func(\@input, $fh3, AutoClose => 0), ' Compressed ok' ;
540 my $got = anyUncompress($file3);
542 is $got, join('', @expected), " Got Expected uncompressed data";
546 foreach my $bit ('IO::Compress::Gzip',
547 'IO::Compress::Deflate',
548 'IO::Compress::RawDeflate',
551 my $Error = getErrorRef($bit);
552 my $Func = getTopFuncRef($bit);
553 my $TopType = getTopFuncName($bit);
555 my $TopTypeInverse = getInverse($bit);
556 my $FuncInverse = getTopFuncRef($TopTypeInverse);
558 my @inFiles = map { "in$_.tmp" } 1..4;
559 my @outFiles = map { "out$_.tmp" } 1..4;
560 my $lex = new LexFile(@inFiles, @outFiles);
562 writeFile($_, "data $_") foreach @inFiles ;
565 title "$TopType - Hash Ref: to filename" ;
568 ok &$Func( { $inFiles[0] => $outFiles[0],
569 $inFiles[1] => $outFiles[1],
570 $inFiles[2] => $outFiles[2] } ), ' Compressed ok' ;
574 my $got = anyUncompress($outFiles[$_]);
575 is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
580 title "$TopType - Hash Ref: to buffer" ;
583 ok &$Func( { $inFiles[0] => \$buffer[0],
584 $inFiles[1] => \$buffer[1],
585 $inFiles[2] => \$buffer[2] } ), ' Compressed ok' ;
589 my $got = anyUncompress(\$buffer[$_]);
590 is $got, "data $inFiles[$_]", " Uncompressed $_ matches original";
595 title "$TopType - Hash Ref: to undef" ;
598 my %hash = ( $inFiles[0] => undef,
599 $inFiles[1] => undef,
600 $inFiles[2] => undef,
603 ok &$Func( \%hash ), ' Compressed ok' ;
607 my $got = anyUncompress(\$hash{$_});
608 is $got, "data $_", " Uncompressed $_ matches original";
613 title "$TopType - Filename to Hash Ref" ;
616 ok &$Func( $inFiles[0] => \%output), ' Compressed ok' ;
618 is keys %output, 1, " one pair in hash" ;
619 my ($k, $v) = each %output;
620 is $k, $inFiles[0], " key is '$inFiles[0]'";
621 my $got = anyUncompress($v);
622 is $got, "data $inFiles[0]", " Uncompressed matches original";
626 title "$TopType - File Glob to Hash Ref" ;
629 ok &$Func( '<in*.tmp>' => \%output), ' Compressed ok' ;
631 is keys %output, 4, " four pairs in hash" ;
632 foreach my $fil (@inFiles)
634 ok exists $output{$fil}, " key '$fil' exists" ;
635 my $got = anyUncompress($output{$fil});
636 is $got, "data $fil", " Uncompressed matches original";
643 # title "$TopType - Hash Ref to Array Ref" ;
645 # my @output = ('first') ;
646 # ok &$Func( { \@input, \@output } , AutoClose => 0), ' Compressed ok' ;
648 # is $output[0], 'first', " Array[0] unchanged";
650 # is_deeply \@input, \@keep, " Input array not changed" ;
651 # my @got = shift @output;
652 # foreach (@output) { push @got, anyUncompress($_) }
654 # is_deeply \@got, ['first', @expected], " Got Expected uncompressed data";
660 # title "$TopType - From Array Ref to Buffer" ;
662 # # rewind the filehandle
663 # $of->open("<$file1") ;
666 # ok &$Func(\@input, \$output, AutoClose => 0), ' Compressed ok' ;
668 # my $got = anyUncompress(\$output);
670 # is $got, join('', @expected), " Got Expected uncompressed data";
675 # title "$TopType - From Array Ref to Filename" ;
677 # my ($file3) = ("file3");
678 # my $lex = new LexFile($file3) ;
680 # # rewind the filehandle
681 # $of->open("<$file1") ;
684 # ok &$Func(\@input, $file3, AutoClose => 0), ' Compressed ok' ;
686 # my $got = anyUncompress($file3);
688 # is $got, join('', @expected), " Got Expected uncompressed data";
693 # title "$TopType - From Array Ref to Filehandle" ;
695 # my ($file3) = ("file3");
696 # my $lex = new LexFile($file3) ;
698 # my $fh3 = new IO::File ">$file3";
700 # # rewind the filehandle
701 # $of->open("<$file1") ;
704 # ok &$Func(\@input, $fh3, AutoClose => 0), ' Compressed ok' ;
708 # my $got = anyUncompress($file3);
710 # is $got, join('', @expected), " Got Expected uncompressed data";
714 foreach my $bit ('IO::Compress::Gzip',
715 'IO::Compress::Deflate',
716 'IO::Compress::RawDeflate',
719 my $Error = getErrorRef($bit);
720 my $Func = getTopFuncRef($bit);
721 my $TopType = getTopFuncName($bit);
723 for my $files ( [qw(a1)], [qw(a1 a2 a3)] )
726 my $tmpDir1 = 'tmpdir1';
727 my $tmpDir2 = 'tmpdir2';
728 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
730 mkdir $tmpDir1, 0777;
731 mkdir $tmpDir2, 0777;
733 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
734 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
736 my @files = map { "$tmpDir1/$_.tmp" } @$files ;
737 foreach (@files) { writeFile($_, "abc $_") }
739 my @expected = map { "abc $_" } @files ;
740 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
743 title "$TopType - From FileGlob to FileGlob files [@$files]" ;
745 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>"), ' Compressed ok'
748 my @copy = @expected;
749 for my $file (@outFiles)
751 is anyUncompress($file), shift @copy, " got expected from $file" ;
754 is @copy, 0, " got all files";
758 title "$TopType - From FileGlob to Array files [@$files]" ;
760 my @buffer = ('first') ;
761 ok &$Func("<$tmpDir1/a*.tmp>" => \@buffer), ' Compressed ok'
764 is shift @buffer, 'first';
766 my @copy = @expected;
767 for my $buffer (@buffer)
769 is anyUncompress($buffer), shift @copy, " got expected " ;
772 is @copy, 0, " got all files";
776 title "$TopType - From FileGlob to Buffer files [@$files]" ;
779 ok &$Func("<$tmpDir1/a*.tmp>" => \$buffer), ' Compressed ok'
784 my $got = anyUncompress([ \$buffer, MultiStream => 1 ]);
786 is $got, join("", @expected), " got expected" ;
790 title "$TopType - From FileGlob to Filename files [@$files]" ;
792 my $filename = "abcde";
793 my $lex = new LexFile($filename) ;
795 ok &$Func("<$tmpDir1/a*.tmp>" => $filename), ' Compressed ok'
800 my $got = anyUncompress([$filename, MultiStream => 1]);
802 is $got, join("", @expected), " got expected" ;
806 title "$TopType - From FileGlob to Filehandle files [@$files]" ;
808 my $filename = "abcde";
809 my $lex = new LexFile($filename) ;
810 my $fh = new IO::File ">$filename";
812 ok &$Func("<$tmpDir1/a*.tmp>" => $fh, AutoClose => 1), ' Compressed ok'
817 my $got = anyUncompress([$filename, MultiStream => 1]);
819 is $got, join("", @expected), " got expected" ;
825 foreach my $bit ('IO::Uncompress::Gunzip',
826 'IO::Uncompress::Inflate',
827 'IO::Uncompress::RawInflate',
828 'IO::Uncompress::AnyInflate',
831 my $Error = getErrorRef($bit);
832 my $Func = getTopFuncRef($bit);
833 my $TopType = getTopFuncName($bit);
835 my $buffer = "abcde" ;
836 my $buffer2 = "ABCDE" ;
837 my $keep_orig = $buffer;
839 my $comp = compressBuffer($TopType, $buffer) ;
840 my $comp2 = compressBuffer($TopType, $buffer2) ;
841 my $keep_comp = $comp;
843 my $incumbent = "incumbent data" ;
845 for my $append (0, 1)
847 my $expected = $buffer ;
848 $expected = $incumbent . $buffer if $append ;
851 title "$TopType - From Buff to Buff, Append($append)" ;
854 $output = $incumbent if $append ;
855 ok &$Func(\$comp, \$output, Append => $append), ' Uncompressed ok' ;
857 is $keep_comp, $comp, " Input buffer not changed" ;
858 is $output, $expected, " Uncompressed matches original";
862 title "$TopType - From Buff to Array, Append($append)" ;
864 my @output = ('first');
865 #$output = $incumbent if $append ;
866 ok &$Func(\$comp, \@output, Append => $append), ' Uncompressed ok' ;
868 is $keep_comp, $comp, " Input buffer not changed" ;
869 is $output[0], 'first', " Uncompressed matches original";
870 is ${ $output[1] }, $buffer, " Uncompressed matches original"
872 is @output, 2, " only 2 elements in the array" ;
876 title "$TopType - From Buff to Filename, Append($append)" ;
878 my $out_file = "abcde";
879 my $lex = new LexFile($out_file) ;
881 { writeFile($out_file, $incumbent) }
883 { ok ! -e $out_file, " Output file does not exist" }
885 ok &$Func(\$comp, $out_file, Append => $append), ' Uncompressed ok' ;
887 ok -e $out_file, " Created output file";
888 my $content = readFile($out_file) ;
890 is $keep_comp, $comp, " Input buffer not changed" ;
891 is $content, $expected, " Uncompressed matches original";
895 title "$TopType - From Buff to Handle, Append($append)" ;
897 my $out_file = "abcde";
898 my $lex = new LexFile($out_file) ;
901 writeFile($out_file, $incumbent) ;
902 $of = new IO::File "+< $out_file" ;
905 ok ! -e $out_file, " Output file does not exist" ;
906 $of = new IO::File "> $out_file" ;
908 isa_ok $of, 'IO::File', ' $of' ;
910 ok &$Func(\$comp, $of, Append => $append, AutoClose => 1), ' Uncompressed ok' ;
912 ok -e $out_file, " Created output file";
913 my $content = readFile($out_file) ;
915 is $keep_comp, $comp, " Input buffer not changed" ;
916 is $content, $expected, " Uncompressed matches original";
920 title "$TopType - From Filename to Filename, Append($append)" ;
922 my $out_file = "abcde.out";
923 my $in_file = "abcde.in";
924 my $lex = new LexFile($in_file, $out_file) ;
926 { writeFile($out_file, $incumbent) }
928 { ok ! -e $out_file, " Output file does not exist" }
930 writeFile($in_file, $comp);
932 ok &$Func($in_file, $out_file, Append => $append), ' Uncompressed ok' ;
934 ok -e $out_file, " Created output file";
935 my $content = readFile($out_file) ;
937 is $keep_comp, $comp, " Input buffer not changed" ;
938 is $content, $expected, " Uncompressed matches original";
942 title "$TopType - From Filename to Handle, Append($append)" ;
944 my $out_file = "abcde.out";
945 my $in_file = "abcde.in";
946 my $lex = new LexFile($in_file, $out_file) ;
949 writeFile($out_file, $incumbent) ;
950 $out = new IO::File "+< $out_file" ;
953 ok ! -e $out_file, " Output file does not exist" ;
954 $out = new IO::File "> $out_file" ;
956 isa_ok $out, 'IO::File', ' $out' ;
958 writeFile($in_file, $comp);
960 ok &$Func($in_file, $out, Append => $append, AutoClose => 1), ' Uncompressed ok' ;
962 ok -e $out_file, " Created output file";
963 my $content = readFile($out_file) ;
965 is $keep_comp, $comp, " Input buffer not changed" ;
966 is $content, $expected, " Uncompressed matches original";
970 title "$TopType - From Filename to Buffer, Append($append)" ;
972 my $in_file = "abcde.in";
973 my $lex = new LexFile($in_file) ;
974 writeFile($in_file, $comp);
977 $output = $incumbent if $append ;
979 ok &$Func($in_file, \$output, Append => $append), ' Uncompressed ok' ;
981 is $keep_comp, $comp, " Input buffer not changed" ;
982 is $output, $expected, " Uncompressed matches original";
986 title "$TopType - From Handle to Filename, Append($append)" ;
988 my $out_file = "abcde.out";
989 my $in_file = "abcde.in";
990 my $lex = new LexFile($in_file, $out_file) ;
992 { writeFile($out_file, $incumbent) }
994 { ok ! -e $out_file, " Output file does not exist" }
996 writeFile($in_file, $comp);
997 my $in = new IO::File "<$in_file" ;
999 ok &$Func($in, $out_file, Append => $append), ' Uncompressed ok' ;
1001 ok -e $out_file, " Created output file";
1002 my $content = readFile($out_file) ;
1004 is $keep_comp, $comp, " Input buffer not changed" ;
1005 is $content, $expected, " Uncompressed matches original";
1009 title "$TopType - From Handle to Handle, Append($append)" ;
1011 my $out_file = "abcde.out";
1012 my $in_file = "abcde.in";
1013 my $lex = new LexFile($in_file, $out_file) ;
1016 writeFile($out_file, $incumbent) ;
1017 $out = new IO::File "+< $out_file" ;
1020 ok ! -e $out_file, " Output file does not exist" ;
1021 $out = new IO::File "> $out_file" ;
1023 isa_ok $out, 'IO::File', ' $out' ;
1025 writeFile($in_file, $comp);
1026 my $in = new IO::File "<$in_file" ;
1028 ok &$Func($in, $out, Append => $append, AutoClose => 1), ' Uncompressed ok' ;
1030 ok -e $out_file, " Created output file";
1031 my $content = readFile($out_file) ;
1033 is $keep_comp, $comp, " Input buffer not changed" ;
1034 is $content, $expected, " Uncompressed matches original";
1038 title "$TopType - From Filename to Buffer, Append($append)" ;
1040 my $in_file = "abcde.in";
1041 my $lex = new LexFile($in_file) ;
1042 writeFile($in_file, $comp);
1043 my $in = new IO::File "<$in_file" ;
1046 $output = $incumbent if $append ;
1048 ok &$Func($in, \$output, Append => $append), ' Uncompressed ok' ;
1050 is $keep_comp, $comp, " Input buffer not changed" ;
1051 is $output, $expected, " Uncompressed matches original";
1055 title "$TopType - From stdin (via '-') to Buffer content, Append($append) " ;
1057 my $in_file = "abcde.in";
1058 my $lex = new LexFile($in_file) ;
1059 writeFile($in_file, $comp);
1061 ok open(SAVEIN, "<&STDIN"), " save STDIN";
1062 my $dummy = fileno SAVEIN ;
1063 ok open(STDIN, "<$in_file"), " redirect STDIN";
1066 $output = $incumbent if $append ;
1068 ok &$Func('-', \$output, Append => $append), ' Uncompressed ok'
1071 ok open(STDIN, "<&SAVEIN"), " put STDIN back";
1073 is $keep_comp, $comp, " Input buffer not changed" ;
1074 is $output, $expected, " Uncompressed matches original";
1079 title "$TopType - From Handle to Buffer, InputLength" ;
1081 my $out_file = "abcde.out";
1082 my $in_file = "abcde.in";
1083 my $lex = new LexFile($in_file, $out_file) ;
1086 my $expected = $buffer ;
1087 my $appended = 'appended';
1088 my $len_appended = length $appended;
1089 writeFile($in_file, $comp . $appended . $comp . $appended) ;
1090 my $in = new IO::File "<$in_file" ;
1092 ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp), ' Uncompressed ok' ;
1094 is $out, $expected, " Uncompressed matches original";
1097 is $in->read($buff, $len_appended), $len_appended, " Length of Appended data ok";
1098 is $buff, $appended, " Appended data ok";
1101 ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp), ' Uncompressed ok' ;
1103 is $out, $expected, " Uncompressed matches original";
1106 is $in->read($buff, $len_appended), $len_appended, " Length of Appended data ok";
1107 is $buff, $appended, " Appended data ok";
1110 for my $stdin ('-', *STDIN) # , \*STDIN)
1112 title "$TopType - From stdin (via $stdin) to Buffer content, InputLength" ;
1114 my $in_file = "abcde.in";
1115 my $lex = new LexFile($in_file) ;
1116 my $expected = $buffer ;
1117 my $appended = 'appended';
1118 my $len_appended = length $appended;
1119 writeFile($in_file, $comp . $appended . $comp . $appended) ;
1121 ok open(SAVEIN, "<&STDIN"), " save STDIN";
1122 my $dummy = fileno SAVEIN ;
1123 ok open(STDIN, "<$in_file"), " redirect STDIN";
1127 ok &$Func($stdin, \$output, Transparent => 0, InputLength => length $comp), ' Uncompressed ok'
1131 is read(STDIN, $buff, $len_appended), $len_appended, " Length of Appended data ok";
1133 is $output, $expected, " Uncompressed matches original";
1134 is $buff, $appended, " Appended data ok";
1137 ok &$Func($stdin, \$output, Transparent => 0, InputLength => length $comp), ' Uncompressed ok'
1141 is read(STDIN, $buff, $len_appended), $len_appended, " Length of Appended data ok"
1142 or diag "read failed $!";
1144 is $output, $expected, " Uncompressed matches original";
1145 is $buff, $appended, " Appended data ok";
1147 ok open(STDIN, "<&SAVEIN"), " put STDIN back";
1151 foreach my $bit ('IO::Uncompress::Gunzip',
1152 'IO::Uncompress::Inflate',
1153 'IO::Uncompress::RawInflate',
1154 'IO::Uncompress::AnyInflate',
1157 # TODO -- Add Append mode tests
1159 my $Error = getErrorRef($bit);
1160 my $Func = getTopFuncRef($bit);
1161 my $TopType = getTopFuncName($bit);
1163 my $buffer = "abcde" ;
1164 my $keep_orig = $buffer;
1167 my $null = compressBuffer($TopType, "") ;
1168 my $undef = compressBuffer($TopType, undef) ;
1169 my $comp = compressBuffer($TopType, $buffer) ;
1170 my $keep_comp = $comp;
1172 my $incumbent = "incumbent data" ;
1174 my ($file1, $file2) = ("file1", "file2");
1175 my $lex = new LexFile($file1, $file2) ;
1177 writeFile($file1, compressBuffer($TopType,"data1"));
1178 writeFile($file2, compressBuffer($TopType,"data2"));
1180 my $of = new IO::File "<$file1" ;
1181 ok $of, " Created output filehandle" ;
1183 my @input = ($file2, \$undef, \$null, \$comp, $of) ;
1184 my @expected = ('data2', '', '', 'abcde', 'data1');
1189 title "$TopType - From ArrayRef to Buffer" ;
1192 ok &$Func(\@input, \$output, AutoClose => 0), ' UnCompressed ok' ;
1194 is $output, join('', @expected)
1198 title "$TopType - From ArrayRef to Filename" ;
1201 my $lex = new LexFile $output;
1202 $of->open("<$file1") ;
1204 ok &$Func(\@input, $output, AutoClose => 0), ' UnCompressed ok' ;
1206 is readFile($output), join('', @expected)
1210 title "$TopType - From ArrayRef to Filehandle" ;
1213 my $lex = new LexFile $output;
1214 my $fh = new IO::File ">$output" ;
1215 $of->open("<$file1") ;
1217 ok &$Func(\@input, $fh, AutoClose => 0), ' UnCompressed ok' ;
1220 is readFile($output), join('', @expected)
1224 title "$TopType - From Array Ref to Array Ref" ;
1226 my @output = (\'first') ;
1227 $of->open("<$file1") ;
1228 ok &$Func(\@input, \@output, AutoClose => 0), ' UnCompressed ok' ;
1230 is_deeply \@input, \@keep, " Input array not changed" ;
1231 is_deeply [map { defined $$_ ? $$_ : "" } @output],
1232 ['first', @expected],
1233 " Got Expected uncompressed data";
1238 foreach my $bit ('IO::Uncompress::Gunzip',
1239 'IO::Uncompress::Inflate',
1240 'IO::Uncompress::RawInflate',
1241 'IO::Uncompress::AnyInflate',
1244 # TODO -- Add Append mode tests
1246 my $Error = getErrorRef($bit);
1247 my $Func = getTopFuncRef($bit);
1248 my $TopType = getTopFuncName($bit);
1250 my $tmpDir1 = 'tmpdir1';
1251 my $tmpDir2 = 'tmpdir2';
1252 my $lex = new LexDir($tmpDir1, $tmpDir2) ;
1254 mkdir $tmpDir1, 0777;
1255 mkdir $tmpDir2, 0777;
1257 ok -d $tmpDir1, " Temp Directory $tmpDir1 exists";
1258 #ok ! -d $tmpDir2, " Temp Directory $tmpDir2 does not exist";
1260 my @files = map { "$tmpDir1/$_.tmp" } qw( a1 a2 a3) ;
1261 foreach (@files) { writeFile($_, compressBuffer($TopType, "abc $_")) }
1263 my @expected = map { "abc $_" } @files ;
1264 my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
1267 title "$TopType - From FileGlob to FileGlob" ;
1269 ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>"), ' UnCompressed ok'
1272 my @copy = @expected;
1273 for my $file (@outFiles)
1275 is readFile($file), shift @copy, " got expected from $file" ;
1278 is @copy, 0, " got all files";
1282 title "$TopType - From FileGlob to Arrayref" ;
1284 my @output = (\'first');
1285 ok &$Func("<$tmpDir1/a*.tmp>" => \@output), ' UnCompressed ok'
1288 my @copy = ('first', @expected);
1289 for my $data (@output)
1291 is $$data, shift @copy, " got expected data" ;
1294 is @copy, 0, " got all files";
1298 title "$TopType - From FileGlob to Buffer" ;
1301 ok &$Func("<$tmpDir1/a*.tmp>" => \$output), ' UnCompressed ok'
1304 is $output, join('', @expected), " got expected uncompressed data";
1308 title "$TopType - From FileGlob to Filename" ;
1310 my $output = 'abc' ;
1311 my $lex = new LexFile $output ;
1312 ok ! -e $output, " $output does not exist" ;
1313 ok &$Func("<$tmpDir1/a*.tmp>" => $output), ' UnCompressed ok'
1316 ok -e $output, " $output does exist" ;
1317 is readFile($output), join('', @expected), " got expected uncompressed data";
1321 title "$TopType - From FileGlob to Filehandle" ;
1323 my $output = 'abc' ;
1324 my $lex = new LexFile $output ;
1325 my $fh = new IO::File ">$output" ;
1326 ok &$Func("<$tmpDir1/a*.tmp>" => $fh, AutoClose => 1), ' UnCompressed ok'
1329 ok -e $output, " $output does exist" ;
1330 is readFile($output), join('', @expected), " got expected uncompressed data";
1335 foreach my $TopType ('IO::Compress::Gzip::gzip',
1336 'IO::Compress::Deflate',
1337 'IO::Compress::RawDeflate',
1338 # TODO -- add the inflate classes
1341 my $Error = getErrorRef($TopType);
1342 my $Func = getTopFuncRef($TopType);
1343 my $Name = getTopFuncName($TopType);
1345 title "More write tests" ;
1347 my $file1 = "file1" ;
1348 my $file2 = "file2" ;
1349 my $file3 = "file3" ;
1350 my $lex = new LexFile $file1, $file2, $file3 ;
1352 writeFile($file1, "F1");
1353 writeFile($file2, "F2");
1354 writeFile($file3, "F3");
1360 [ '[\"abcd"]', "abcd" ],
1361 [ '[\"ab", \"cd"]', "abcd" ],
1364 [ '[\"a", $fh1, \"bc"]', "aF1bc"],
1368 foreach my $data (@data)
1370 my ($send, $get) = @$data ;
1372 my $fh1 = new IO::File "< $file1" ;
1373 my $fh2 = new IO::File "< $file2" ;
1374 my $fh3 = new IO::File "< $file3" ;
1378 eval "\$copy = $send";
1380 ok &$Func($copy, \$Answer), " $Name ok";
1382 my $got = anyUncompress(\$Answer);
1383 is $got, $get, " got expected output" ;
1384 cmp_ok $$Error, '==', 0, " no error";
1389 title "Array Input Error tests" ;
1394 '[[\"ab"], [\"cd"]]',
1398 foreach my $send (@data)
1400 my $fh1 = new IO::File "< $file1" ;
1401 my $fh2 = new IO::File "< $file2" ;
1402 my $fh3 = new IO::File "< $file3" ;
1406 eval "\$copy = $send";
1408 ok ! &$Func($copy, \$Answer), " $Name fails";
1410 is $$Error, "unknown input parameter", " got error message";
1418 my $content = shift ;
1424 ok IO::Compress::Gzip::gzip($in, \$out, %opts), " gzip ok" ;
1425 ok IO::Uncompress::Gunzip::gunzip(\$out, \$got), " gunzip ok"
1426 or diag $GunzipError ;
1427 is $got, $content, " got expected content" ;
1429 my $gunz = new IO::Uncompress::Gunzip \$out, Strict => 0
1430 or diag "GunzipError is $IO::Uncompress::Gunzip::GunzipError" ;
1431 ok $gunz, " Created IO::Uncompress::Gunzip object";
1432 my $hdr = $gunz->getHeaderInfo();
1433 ok $hdr, " got Header info";
1435 ok $gunz->read($uncomp), " read ok" ;
1436 is $uncomp, $content, " got expected content";
1437 ok $gunz->close, " closed ok" ;
1444 title "Check gzip header default NAME & MTIME settings" ;
1446 my $file1 = "file1" ;
1447 my $lex = new LexFile $file1;
1449 my $content = "hello ";
1453 writeFile($file1, $content);
1454 $mtime = (stat($file1))[8];
1455 # make sure that the gzip file isn't created in the same
1456 # second as the input file
1458 $hdr = gzipGetHeader($file1, $content);
1460 is $hdr->{Name}, $file1, " Name is '$file1'";
1461 is $hdr->{Time}, $mtime, " Time is ok";
1463 title "Override Name" ;
1465 writeFile($file1, $content);
1466 $mtime = (stat($file1))[8];
1468 $hdr = gzipGetHeader($file1, $content, Name => "abcde");
1470 is $hdr->{Name}, "abcde", " Name is 'abcde'" ;
1471 is $hdr->{Time}, $mtime, " Time is ok";
1473 title "Override Time" ;
1475 writeFile($file1, $content);
1476 $hdr = gzipGetHeader($file1, $content, Time => 1234);
1478 is $hdr->{Name}, $file1, " Name is '$file1'" ;
1479 is $hdr->{Time}, 1234, " Time is 1234";
1481 title "Override Name and Time" ;
1483 writeFile($file1, $content);
1484 $hdr = gzipGetHeader($file1, $content, Time => 4321, Name => "abcde");
1486 is $hdr->{Name}, "abcde", " Name is 'abcde'" ;
1487 is $hdr->{Time}, 4321, " Time is 4321";
1489 title "Filehandle doesn't have default Name or Time" ;
1490 my $fh = new IO::File "< $file1"
1491 or diag "Cannot open '$file1': $!\n" ;
1494 $hdr = gzipGetHeader($fh, $content);
1497 ok ! defined $hdr->{Name}, " Name is undef";
1498 cmp_ok $hdr->{Time}, '>=', $before, " Time is ok";
1499 cmp_ok $hdr->{Time}, '<=', $after, " Time is ok";
1503 title "Buffer doesn't have default Name or Time" ;
1504 my $buffer = $content;
1506 $hdr = gzipGetHeader(\$buffer, $content);
1509 ok ! defined $hdr->{Name}, " Name is undef";
1510 cmp_ok $hdr->{Time}, '>=', $before, " Time is ok";
1511 cmp_ok $hdr->{Time}, '<=', $after, " Time is ok";
1514 # TODO add more error cases