Add test preambles to Compress::Zlib.
[p5sagit/p5-mst-13.2.git] / ext / Compress / Zlib / t / 16oneshot.t
1 BEGIN {
2     if ($ENV{PERL_CORE} {
3         chdir 't' if -d 't';
4         @INC = '../lib';
5     }
6 }
7
8 use lib 't';
9 use strict;
10 use warnings;
11 use bytes;
12
13 use Test::More ;
14 use ZlibTestUtils;
15
16 BEGIN {
17     plan(skip_all => "oneshot needs Perl 5.005 or better - you have Perl $]" )
18         if $] < 5.005 ;
19
20
21     # use Test::NoWarnings, if available
22     my $extra = 0 ;
23     $extra = 1
24         if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };
25
26     plan tests => 2526 + $extra ;
27
28     use_ok('Compress::Zlib', 2) ;
29
30     use_ok('IO::Compress::Gzip', qw(gzip $GzipError)) ;
31     use_ok('IO::Uncompress::Gunzip', qw(gunzip $GunzipError)) ;
32
33     use_ok('IO::Compress::Deflate', qw(deflate $DeflateError)) ;
34     use_ok('IO::Uncompress::Inflate', qw(inflate $InflateError)) ;
35
36     use_ok('IO::Compress::RawDeflate', qw(rawdeflate $RawDeflateError)) ;
37     use_ok('IO::Uncompress::RawInflate', qw(rawinflate $RawInflateError)) ;
38
39     use_ok('IO::Uncompress::AnyInflate', qw(anyinflate $AnyInflateError)) ;
40
41 }
42
43
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" ;
47
48
49
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',
57                 )
58 {
59     my $Error = getErrorRef($bit);
60     my $Func = getTopFuncRef($bit);
61     my $TopType = getTopFuncName($bit);
62
63     title "Testing $TopType Error Cases";
64
65     my $a;
66     my $x ;
67
68     eval { $a = $Func->(\$a => \$x, Fred => 1) ;} ;
69     like $@, mkErr("^$TopType: unknown key value\\(s\\) Fred"), '  Illegal Parameters';
70
71     eval { $a = $Func->() ;} ;
72     like $@, mkErr("^$TopType: expected at least 1 parameters"), '  No Parameters';
73
74     eval { $a = $Func->(\$x, \1) ;} ;
75     like $@, mkErr("^$TopType: output buffer is read-only"), '  Output is read-only' ;
76
77     my $in ;
78     eval { $a = $Func->($in, \$x) ;} ;
79     like $@, mkErr("^$TopType: input filename is undef or null string"), 
80         '  Input filename undef' ;
81
82     $in = '';    
83     eval { $a = $Func->($in, \$x) ;} ;
84     like $@, mkErr("^$TopType: input filename is undef or null string"), 
85         '  Input filename empty' ;
86
87     $in = 'abc';    
88     my $lex1 = new LexFile($in) ;
89     writeFile($in, "abc");
90     my $out = $in ;
91     eval { $a = $Func->($in, $out) ;} ;
92     like $@, mkErr("^$TopType: input and output filename are identical"),
93         '  Input and Output filename are the same';
94
95     eval { $a = $Func->(\$in, \$in) ;} ;
96     like $@, mkErr("^$TopType: input and output buffer are identical"),
97         '  Input and Output buffer are the same';
98         
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';
105         
106     close OUT;
107     is -s $out_file, 0, "  File zero length" ;
108     {
109         my %x = () ;
110         my $object = bless \%x, "someClass" ;
111
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"),
116             '  Bad Output Param';
117             
118
119         #eval { $a = $Func->(\%x, \$x) ;} ;
120         eval { $a = $Func->($object, \$x) ;} ;
121         like $@, mkErr("^$TopType: illegal input parameter"),
122             '  Bad Input Param';
123     }
124
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";
130         
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";
136         
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';
141
142     $a = $Func->('<abc)>', '<abc>') ;
143     is $a, undef, "  $TopType returned undef";
144     like $$Error, "/Unmatched \\) in input fileglob/",
145             "  Unmatched ) in input fileglob";
146 }
147
148 foreach my $bit ('IO::Uncompress::Gunzip',
149                  'IO::Uncompress::Inflate',
150                  'IO::Uncompress::RawInflate',
151                  'IO::Uncompress::AnyInflate',
152                 )
153 {
154     my $Error = getErrorRef($bit);
155     my $Func = getTopFuncRef($bit);
156     my $TopType = getTopFuncName($bit);
157
158     my $data = "mary had a little lamb" ;
159     my $keep = $data ;
160
161     for my $trans ( 0, 1)
162     {
163         title "Non-compressed data with $TopType, Transparent => $trans ";
164         my $a;
165         my $x ;
166         my $out = '' ;
167
168         $a = $Func->(\$data, \$out, Transparent => $trans) ;
169
170         is $data, $keep, "  Input buffer not changed" ;
171
172         if ($trans)
173         {
174             ok $a, "  $TopType returned true" ;
175             is $out, $data, "  got expected output" ;
176             ok ! $$Error, "  no error [$$Error]" ;
177         }
178         else
179         {
180             ok ! $a, "  $TopType returned false" ;
181             #like $$Error, '/xxx/', "  error" ;
182             ok $$Error, "  error is '$$Error'" ;
183         }
184     }
185 }
186
187 foreach my $bit ('IO::Compress::Gzip',     
188                  'IO::Compress::Deflate', 
189                  'IO::Compress::RawDeflate',
190                 )
191 {
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);
198
199     title "$TopTypeInverse - corrupt data";
200
201     my $data = "abcd" x 100 ;
202     my $out;
203
204     ok $Func->(\$data, \$out), "  $TopType ok";
205
206     # corrupt the compressed data
207     substr($out, -10, 10) = "x" x 10 ;
208
209     my $result;
210     ok ! $FuncInverse->(\$out => \$result, Transparent => 0), "  $TopTypeInverse ok";
211     ok $$ErrorInverse, "  Got error '$$ErrorInverse'" ;
212
213     #is $result, $data, "  data ok";
214
215     ok ! anyinflate(\$out => \$result, Transparent => 0), "  anyinflate ok";
216     ok $AnyInflateError, "  Got error '$AnyInflateError'" ;
217 }
218
219
220 foreach my $bit ('IO::Compress::Gzip',     
221                  'IO::Compress::Deflate', 
222                  'IO::Compress::RawDeflate',
223                 )
224 {
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);
230
231     for my $append ( 1, 0 )
232     {
233         my $already = '';
234         $already = 'abcde' if $append ;
235
236         for my $buffer ( undef, '', "abcde" )
237         {
238
239             my $disp_content = defined $buffer ? $buffer : '<undef>' ;
240
241             my $keep = $buffer;
242             my $out_file = "abcde.out";
243             my $in_file = "abcde.in";
244
245             {
246                 title "$TopType - From Buff to Buff content '$disp_content' Append $append" ;
247
248                 my $output = $already;
249                 ok &$Func(\$buffer, \$output, Append => $append), '  Compressed ok' ;
250
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";
255
256             }
257
258             {
259                 title "$TopType - From Buff to Array Ref content '$disp_content' Append $append" ;
260
261                 my @output = ('first') ;
262                 ok &$Func(\$buffer, \@output, Append => $append), '  Compressed ok' ;
263
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";
269             }
270
271             {
272                 title "$TopType - From Array Ref to Array Ref content '$disp_content' Append $append" ;
273
274                 my @output = ('first') ;
275                 my @input = ( \$buffer);
276                 ok &$Func(\@input, \@output, Append => $append), '  Compressed ok' ;
277
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";
283
284             }
285
286             {
287                 title "$TopType - From Buff to Filename content '$disp_content' Append $append" ;
288
289                 my $lex = new LexFile($out_file) ;
290                 ok ! -e $out_file, "  Output file does not exist";
291                 writeFile($out_file, $already);
292
293                 ok &$Func(\$buffer, $out_file, Append => $append), '  Compressed ok' ;
294
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";
299             }
300
301             {
302                 title "$TopType - From Buff to Handle content '$disp_content' Append $append" ;
303
304                 my $lex = new LexFile($out_file) ;
305
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" ;
310
311                 ok &$Func(\$buffer, $of, AutoClose => 1, Append => $append), '  Compressed ok' ;
312
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";
317             }
318
319
320             {
321                 title "$TopType - From Filename to Filename content '$disp_content' Append $append" ;
322
323                 my $lex = new LexFile($in_file, $out_file) ;
324                 writeFile($in_file, $buffer);
325
326                 ok ! -e $out_file, "  Output file does not exist";
327                 writeFile($out_file, $already);
328
329                 ok &$Func($in_file => $out_file, Append => $append), '  Compressed ok' ;
330
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";
335
336             }
337
338             {
339                 title "$TopType - From Filename to Handle content '$disp_content' Append $append" ;
340
341                 my $lex = new LexFile($in_file, $out_file) ;
342                 writeFile($in_file, $buffer);
343
344                 ok ! -e $out_file, "  Output file does not exist";
345                 writeFile($out_file, $already);
346                 my $out = new IO::File ">>$out_file" ;
347
348                 ok &$Func($in_file, $out, AutoClose => 1, Append => $append), '  Compressed ok' ;
349
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";
354
355             }
356
357             {
358                 title "$TopType - From Filename to Buffer content '$disp_content' Append $append" ;
359
360                 my $lex = new LexFile($in_file, $out_file) ;
361                 writeFile($in_file, $buffer);
362
363                 my $out = $already;
364
365                 ok &$Func($in_file => \$out, Append => $append), '  Compressed ok' ;
366
367                 my $got = anyUncompress(\$out, $already);
368                 $got = undef if ! defined $buffer && $got eq '' ;
369                 is $got, $buffer, "  Uncompressed matches original";
370
371             }
372             
373             {
374                 title "$TopType - From Handle to Filename content '$disp_content' Append $append" ;
375
376                 my $lex = new LexFile($in_file, $out_file) ;
377                 writeFile($in_file, $buffer);
378                 my $in = new IO::File "<$in_file" ;
379
380                 ok ! -e $out_file, "  Output file does not exist";
381                 writeFile($out_file, $already);
382
383                 ok &$Func($in, $out_file, Append => $append), '  Compressed ok' 
384                     or diag "error is $GzipError" ;
385
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";
390
391             }
392
393             {
394                 title "$TopType - From Handle to Handle content '$disp_content' Append $append" ;
395
396                 my $lex = new LexFile($in_file, $out_file) ;
397                 writeFile($in_file, $buffer);
398                 my $in = new IO::File "<$in_file" ;
399
400                 ok ! -e $out_file, "  Output file does not exist";
401                 writeFile($out_file, $already);
402                 my $out = new IO::File ">>$out_file" ;
403
404                 ok &$Func($in, $out, AutoClose => 1, Append => $append), '  Compressed ok' ;
405
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";
410
411             }
412
413             {
414                 title "$TopType - From Handle to Buffer content '$disp_content' Append $append" ;
415
416                 my $lex = new LexFile($in_file, $out_file) ;
417                 writeFile($in_file, $buffer);
418                 my $in = new IO::File "<$in_file" ;
419
420                 my $out = $already ;
421
422                 ok &$Func($in, \$out, Append => $append), '  Compressed ok' ;
423
424                 my $got = anyUncompress(\$out, $already);
425                 $got = undef if ! defined $buffer && $got eq '' ;
426                 is $buffer, $got, "  Uncompressed matches original";
427
428             }
429
430             {
431                 title "$TopType - From stdin (via '-') to Buffer content '$disp_content' Append $append" ;
432
433                 my $lex = new LexFile($in_file, $out_file) ;
434                 writeFile($in_file, $buffer);
435
436                    open(SAVEIN, "<&STDIN");
437                 my $dummy = fileno SAVEIN ;
438                 ok open(STDIN, "<$in_file"), "  redirect STDIN";
439
440                 my $out = $already;
441
442                 ok &$Func('-', \$out, Append => $append), '  Compressed ok' 
443                     or diag $$Error ;
444
445                    open(STDIN, "<&SAVEIN");
446
447                 my $got = anyUncompress(\$out, $already);
448                 $got = undef if ! defined $buffer && $got eq '' ;
449                 is $buffer, $got, "  Uncompressed matches original";
450
451             }
452
453         }
454     }
455 }
456
457 foreach my $bit ('IO::Compress::Gzip',     
458                  'IO::Compress::Deflate', 
459                  'IO::Compress::RawDeflate',
460                 )
461 {
462     my $Error = getErrorRef($bit);
463     my $Func = getTopFuncRef($bit);
464     my $TopType = getTopFuncName($bit);
465
466     my $TopTypeInverse = getInverse($bit);
467     my $FuncInverse = getTopFuncRef($TopTypeInverse);
468
469     my ($file1, $file2) = ("file1", "file2");
470     my $lex = new LexFile($file1, $file2) ;
471
472     writeFile($file1, "data1");
473     writeFile($file2, "data2");
474     my $of = new IO::File "<$file1" ;
475     ok $of, "  Created output filehandle" ;
476
477     my @input = (   undef, "", $file2, \undef, \'', \"abcde", $of) ;
478     my @expected = ("", "", $file2, "", "", "abcde", "data1");
479     my @uexpected = ("", "", "data2", "", "", "abcde", "data1");
480
481     my @keep = @input ;
482
483     {
484         title "$TopType - From Array Ref to Array Ref" ;
485
486         my @output = ('first') ;
487         ok &$Func(\@input, \@output, AutoClose => 0), '  Compressed ok' ;
488
489         is $output[0], 'first', "  Array[0] unchanged";
490
491         is_deeply \@input, \@keep, "  Input array not changed" ;
492         my @got = shift @output;
493         foreach (@output) { push @got, anyUncompress($_) }
494
495         is_deeply \@got, ['first', @expected], "  Got Expected uncompressed data";
496
497     }
498
499     {
500         title "$TopType - From Array Ref to Buffer" ;
501
502         # rewind the filehandle
503         $of->open("<$file1") ;
504
505         my $output  ;
506         ok &$Func(\@input, \$output, AutoClose => 0), '  Compressed ok' ;
507
508         my $got = anyUncompress(\$output);
509
510         is $got, join('', @expected), "  Got Expected uncompressed data";
511     }
512
513     {
514         title "$TopType - From Array Ref to Filename" ;
515
516         my ($file3) = ("file3");
517         my $lex = new LexFile($file3) ;
518
519         # rewind the filehandle
520         $of->open("<$file1") ;
521
522         my $output  ;
523         ok &$Func(\@input, $file3, AutoClose => 0), '  Compressed ok' ;
524
525         my $got = anyUncompress($file3);
526
527         is $got, join('', @expected), "  Got Expected uncompressed data";
528     }
529
530     {
531         title "$TopType - From Array Ref to Filehandle" ;
532
533         my ($file3) = ("file3");
534         my $lex = new LexFile($file3) ;
535
536         my $fh3 = new IO::File ">$file3";
537
538         # rewind the filehandle
539         $of->open("<$file1") ;
540
541         my $output  ;
542         ok &$Func(\@input, $fh3, AutoClose => 0), '  Compressed ok' ;
543
544         $fh3->close();
545
546         my $got = anyUncompress($file3);
547
548         is $got, join('', @expected), "  Got Expected uncompressed data";
549     }
550 }
551
552 foreach my $bit ('IO::Compress::Gzip',     
553                  'IO::Compress::Deflate', 
554                  'IO::Compress::RawDeflate',
555                 )
556 {
557     my $Error = getErrorRef($bit);
558     my $Func = getTopFuncRef($bit);
559     my $TopType = getTopFuncName($bit);
560
561     my $TopTypeInverse = getInverse($bit);
562     my $FuncInverse = getTopFuncRef($TopTypeInverse);
563
564     my @inFiles  = map { "in$_.tmp"  } 1..4;
565     my @outFiles = map { "out$_.tmp" } 1..4;
566     my $lex = new LexFile(@inFiles, @outFiles);
567
568     writeFile($_, "data $_") foreach @inFiles ;
569     
570     {
571         title "$TopType - Hash Ref: to filename" ;
572
573         my $output ;
574         ok &$Func( { $inFiles[0] => $outFiles[0],
575                      $inFiles[1] => $outFiles[1],
576                      $inFiles[2] => $outFiles[2] } ), '  Compressed ok' ;
577
578         foreach (0 .. 2)
579         {
580             my $got = anyUncompress($outFiles[$_]);
581             is $got, "data $inFiles[$_]", "  Uncompressed $_ matches original";
582         }
583     }
584
585     {
586         title "$TopType - Hash Ref: to buffer" ;
587
588         my @buffer ;
589         ok &$Func( { $inFiles[0] => \$buffer[0],
590                      $inFiles[1] => \$buffer[1],
591                      $inFiles[2] => \$buffer[2] } ), '  Compressed ok' ;
592
593         foreach (0 .. 2)
594         {
595             my $got = anyUncompress(\$buffer[$_]);
596             is $got, "data $inFiles[$_]", "  Uncompressed $_ matches original";
597         }
598     }
599
600     {
601         title "$TopType - Hash Ref: to undef" ;
602
603         my @buffer ;
604         my %hash = ( $inFiles[0] => undef,
605                      $inFiles[1] => undef,
606                      $inFiles[2] => undef, 
607                  );  
608
609         ok &$Func( \%hash ), '  Compressed ok' ;
610
611         foreach (keys %hash)
612         {
613             my $got = anyUncompress(\$hash{$_});
614             is $got, "data $_", "  Uncompressed $_ matches original";
615         }
616     }
617
618     {
619         title "$TopType - Filename to Hash Ref" ;
620
621         my %output ;
622         ok &$Func( $inFiles[0] => \%output), '  Compressed ok' ;
623
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";
629     }
630
631     {
632         title "$TopType - File Glob to Hash Ref" ;
633
634         my %output ;
635         ok &$Func( '<in*.tmp>' => \%output), '  Compressed ok' ;
636
637         is keys %output, 4, "  four pairs in hash" ;
638         foreach my $fil (@inFiles)
639         {
640             ok exists $output{$fil}, "  key '$fil' exists" ;
641             my $got = anyUncompress($output{$fil});
642             is $got, "data $fil", "  Uncompressed matches original";
643         }
644     }
645
646
647 #    if (0)
648 #    {
649 #        title "$TopType - Hash Ref to Array Ref" ;
650 #
651 #        my @output = ('first') ;
652 #        ok &$Func( { \@input, \@output } , AutoClose => 0), '  Compressed ok' ;
653 #
654 #        is $output[0], 'first', "  Array[0] unchanged";
655 #
656 #        is_deeply \@input, \@keep, "  Input array not changed" ;
657 #        my @got = shift @output;
658 #        foreach (@output) { push @got, anyUncompress($_) }
659 #
660 #        is_deeply \@got, ['first', @expected], "  Got Expected uncompressed data";
661 #
662 #    }
663 #
664 #    if (0)
665 #    {
666 #        title "$TopType - From Array Ref to Buffer" ;
667 #
668 #        # rewind the filehandle
669 #        $of->open("<$file1") ;
670 #
671 #        my $output  ;
672 #        ok &$Func(\@input, \$output, AutoClose => 0), '  Compressed ok' ;
673 #
674 #        my $got = anyUncompress(\$output);
675 #
676 #        is $got, join('', @expected), "  Got Expected uncompressed data";
677 #    }
678 #
679 #    if (0)
680 #    {
681 #        title "$TopType - From Array Ref to Filename" ;
682 #
683 #        my ($file3) = ("file3");
684 #        my $lex = new LexFile($file3) ;
685 #
686 #        # rewind the filehandle
687 #        $of->open("<$file1") ;
688 #
689 #        my $output  ;
690 #        ok &$Func(\@input, $file3, AutoClose => 0), '  Compressed ok' ;
691 #
692 #        my $got = anyUncompress($file3);
693 #
694 #        is $got, join('', @expected), "  Got Expected uncompressed data";
695 #    }
696 #
697 #    if (0)
698 #    {
699 #        title "$TopType - From Array Ref to Filehandle" ;
700 #
701 #        my ($file3) = ("file3");
702 #        my $lex = new LexFile($file3) ;
703 #
704 #        my $fh3 = new IO::File ">$file3";
705 #
706 #        # rewind the filehandle
707 #        $of->open("<$file1") ;
708 #
709 #        my $output  ;
710 #        ok &$Func(\@input, $fh3, AutoClose => 0), '  Compressed ok' ;
711 #
712 #        $fh3->close();
713 #
714 #        my $got = anyUncompress($file3);
715 #
716 #        is $got, join('', @expected), "  Got Expected uncompressed data";
717 #    }
718 }
719
720 foreach my $bit ('IO::Compress::Gzip',     
721                  'IO::Compress::Deflate', 
722                  'IO::Compress::RawDeflate',
723                 )
724 {
725     my $Error = getErrorRef($bit);
726     my $Func = getTopFuncRef($bit);
727     my $TopType = getTopFuncName($bit);
728
729     for my $files ( [qw(a1)], [qw(a1 a2 a3)] )
730     {
731
732         my $tmpDir1 = 'tmpdir1';
733         my $tmpDir2 = 'tmpdir2';
734         my $lex = new LexDir($tmpDir1, $tmpDir2) ;
735
736         mkdir $tmpDir1, 0777;
737         mkdir $tmpDir2, 0777;
738
739         ok   -d $tmpDir1, "  Temp Directory $tmpDir1 exists";
740         #ok ! -d $tmpDir2, "  Temp Directory $tmpDir2 does not exist";
741
742         my @files = map { "$tmpDir1/$_.tmp" } @$files ;
743         foreach (@files) { writeFile($_, "abc $_") }
744
745         my @expected = map { "abc $_" } @files ;
746         my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
747
748         {
749             title "$TopType - From FileGlob to FileGlob files [@$files]" ;
750
751             ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>"), '  Compressed ok' 
752                 or diag $$Error ;
753
754             my @copy = @expected;
755             for my $file (@outFiles)
756             {
757                 is anyUncompress($file), shift @copy, "  got expected from $file" ;
758             }
759
760             is @copy, 0, "  got all files";
761         }
762
763         {
764             title "$TopType - From FileGlob to Array files [@$files]" ;
765
766             my @buffer = ('first') ;
767             ok &$Func("<$tmpDir1/a*.tmp>" => \@buffer), '  Compressed ok' 
768                 or diag $$Error ;
769
770             is shift @buffer, 'first';
771
772             my @copy = @expected;
773             for my $buffer (@buffer)
774             {
775                 is anyUncompress($buffer), shift @copy, "  got expected " ;
776             }
777
778             is @copy, 0, "  got all files";
779         }
780
781         {
782             title "$TopType - From FileGlob to Buffer files [@$files]" ;
783
784             my $buffer ;
785             ok &$Func("<$tmpDir1/a*.tmp>" => \$buffer), '  Compressed ok' 
786                 or diag $$Error ;
787
788             #hexDump(\$buffer);
789
790             my $got = anyUncompress([ \$buffer, MultiStream => 1 ]);
791
792             is $got, join("", @expected), "  got expected" ;
793         }
794
795         {
796             title "$TopType - From FileGlob to Filename files [@$files]" ;
797
798             my $filename = "abcde";
799             my $lex = new LexFile($filename) ;
800             
801             ok &$Func("<$tmpDir1/a*.tmp>" => $filename), '  Compressed ok' 
802                 or diag $$Error ;
803
804             #hexDump(\$buffer);
805
806             my $got = anyUncompress([$filename, MultiStream => 1]);
807
808             is $got, join("", @expected), "  got expected" ;
809         }
810
811         {
812             title "$TopType - From FileGlob to Filehandle files [@$files]" ;
813
814             my $filename = "abcde";
815             my $lex = new LexFile($filename) ;
816             my $fh = new IO::File ">$filename";
817             
818             ok &$Func("<$tmpDir1/a*.tmp>" => $fh, AutoClose => 1), '  Compressed ok' 
819                 or diag $$Error ;
820
821             #hexDump(\$buffer);
822
823             my $got = anyUncompress([$filename, MultiStream => 1]);
824
825             is $got, join("", @expected), "  got expected" ;
826         }
827     }
828
829 }
830
831 foreach my $bit ('IO::Uncompress::Gunzip',     
832                  'IO::Uncompress::Inflate', 
833                  'IO::Uncompress::RawInflate',
834                  'IO::Uncompress::AnyInflate',
835                 )
836 {
837     my $Error = getErrorRef($bit);
838     my $Func = getTopFuncRef($bit);
839     my $TopType = getTopFuncName($bit);
840
841     my $buffer = "abcde" ;
842     my $buffer2 = "ABCDE" ;
843     my $keep_orig = $buffer;
844
845     my $comp = compressBuffer($TopType, $buffer) ;
846     my $comp2 = compressBuffer($TopType, $buffer2) ;
847     my $keep_comp = $comp;
848
849     my $incumbent = "incumbent data" ;
850
851     for my $append (0, 1)
852     {
853         my $expected = $buffer ;
854         $expected = $incumbent . $buffer if $append ;
855
856         {
857             title "$TopType - From Buff to Buff, Append($append)" ;
858
859             my $output ;
860             $output = $incumbent if $append ;
861             ok &$Func(\$comp, \$output, Append => $append), '  Uncompressed ok' ;
862
863             is $keep_comp, $comp, "  Input buffer not changed" ;
864             is $output, $expected, "  Uncompressed matches original";
865         }
866
867         {
868             title "$TopType - From Buff to Array, Append($append)" ;
869
870             my @output = ('first');
871             #$output = $incumbent if $append ;
872             ok &$Func(\$comp, \@output, Append => $append), '  Uncompressed ok' ;
873
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"
877                 or diag $output[1] ;
878             is @output, 2, "  only 2 elements in the array" ;
879         }
880
881         {
882             title "$TopType - From Buff to Filename, Append($append)" ;
883
884             my $out_file = "abcde";
885             my $lex = new LexFile($out_file) ;
886             if ($append)
887               { writeFile($out_file, $incumbent) }
888             else
889               { ok ! -e $out_file, "  Output file does not exist" }
890
891             ok &$Func(\$comp, $out_file, Append => $append), '  Uncompressed ok' ;
892
893             ok -e $out_file, "  Created output file";
894             my $content = readFile($out_file) ;
895
896             is $keep_comp, $comp, "  Input buffer not changed" ;
897             is $content, $expected, "  Uncompressed matches original";
898         }
899
900         {
901             title "$TopType - From Buff to Handle, Append($append)" ;
902
903             my $out_file = "abcde";
904             my $lex = new LexFile($out_file) ;
905             my $of ;
906             if ($append) {
907                 writeFile($out_file, $incumbent) ;
908                 $of = new IO::File "+< $out_file" ;
909             }
910             else {
911                 ok ! -e $out_file, "  Output file does not exist" ;
912                 $of = new IO::File "> $out_file" ;
913             }
914             isa_ok $of, 'IO::File', '  $of' ;
915
916             ok &$Func(\$comp, $of, Append => $append, AutoClose => 1), '  Uncompressed ok' ;
917
918             ok -e $out_file, "  Created output file";
919             my $content = readFile($out_file) ;
920
921             is $keep_comp, $comp, "  Input buffer not changed" ;
922             is $content, $expected, "  Uncompressed matches original";
923         }
924
925         {
926             title "$TopType - From Filename to Filename, Append($append)" ;
927
928             my $out_file = "abcde.out";
929             my $in_file = "abcde.in";
930             my $lex = new LexFile($in_file, $out_file) ;
931             if ($append)
932               { writeFile($out_file, $incumbent) }
933             else
934               { ok ! -e $out_file, "  Output file does not exist" }
935
936             writeFile($in_file, $comp);
937
938             ok &$Func($in_file, $out_file, Append => $append), '  Uncompressed ok' ;
939
940             ok -e $out_file, "  Created output file";
941             my $content = readFile($out_file) ;
942
943             is $keep_comp, $comp, "  Input buffer not changed" ;
944             is $content, $expected, "  Uncompressed matches original";
945         }
946
947         {
948             title "$TopType - From Filename to Handle, Append($append)" ;
949
950             my $out_file = "abcde.out";
951             my $in_file = "abcde.in";
952             my $lex = new LexFile($in_file, $out_file) ;
953             my $out ;
954             if ($append) {
955                 writeFile($out_file, $incumbent) ;
956                 $out = new IO::File "+< $out_file" ;
957             }
958             else {
959                 ok ! -e $out_file, "  Output file does not exist" ;
960                 $out = new IO::File "> $out_file" ;
961             }
962             isa_ok $out, 'IO::File', '  $out' ;
963
964             writeFile($in_file, $comp);
965
966             ok &$Func($in_file, $out, Append => $append, AutoClose => 1), '  Uncompressed ok' ;
967
968             ok -e $out_file, "  Created output file";
969             my $content = readFile($out_file) ;
970
971             is $keep_comp, $comp, "  Input buffer not changed" ;
972             is $content, $expected, "  Uncompressed matches original";
973         }
974
975         {
976             title "$TopType - From Filename to Buffer, Append($append)" ;
977
978             my $in_file = "abcde.in";
979             my $lex = new LexFile($in_file) ;
980             writeFile($in_file, $comp);
981
982             my $output ;
983             $output = $incumbent if $append ;
984
985             ok &$Func($in_file, \$output, Append => $append), '  Uncompressed ok' ;
986
987             is $keep_comp, $comp, "  Input buffer not changed" ;
988             is $output, $expected, "  Uncompressed matches original";
989         }
990
991         {
992             title "$TopType - From Handle to Filename, Append($append)" ;
993
994             my $out_file = "abcde.out";
995             my $in_file = "abcde.in";
996             my $lex = new LexFile($in_file, $out_file) ;
997             if ($append)
998               { writeFile($out_file, $incumbent) }
999             else
1000               { ok ! -e $out_file, "  Output file does not exist" }
1001
1002             writeFile($in_file, $comp);
1003             my $in = new IO::File "<$in_file" ;
1004
1005             ok &$Func($in, $out_file, Append => $append), '  Uncompressed ok' ;
1006
1007             ok -e $out_file, "  Created output file";
1008             my $content = readFile($out_file) ;
1009
1010             is $keep_comp, $comp, "  Input buffer not changed" ;
1011             is $content, $expected, "  Uncompressed matches original";
1012         }
1013
1014         {
1015             title "$TopType - From Handle to Handle, Append($append)" ;
1016
1017             my $out_file = "abcde.out";
1018             my $in_file = "abcde.in";
1019             my $lex = new LexFile($in_file, $out_file) ;
1020             my $out ;
1021             if ($append) {
1022                 writeFile($out_file, $incumbent) ;
1023                 $out = new IO::File "+< $out_file" ;
1024             }
1025             else {
1026                 ok ! -e $out_file, "  Output file does not exist" ;
1027                 $out = new IO::File "> $out_file" ;
1028             }
1029             isa_ok $out, 'IO::File', '  $out' ;
1030
1031             writeFile($in_file, $comp);
1032             my $in = new IO::File "<$in_file" ;
1033
1034             ok &$Func($in, $out, Append => $append, AutoClose => 1), '  Uncompressed ok' ;
1035
1036             ok -e $out_file, "  Created output file";
1037             my $content = readFile($out_file) ;
1038
1039             is $keep_comp, $comp, "  Input buffer not changed" ;
1040             is $content, $expected, "  Uncompressed matches original";
1041         }
1042
1043         {
1044             title "$TopType - From Filename to Buffer, Append($append)" ;
1045
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" ;
1050
1051             my $output ;
1052             $output = $incumbent if $append ;
1053
1054             ok &$Func($in, \$output, Append => $append), '  Uncompressed ok' ;
1055
1056             is $keep_comp, $comp, "  Input buffer not changed" ;
1057             is $output, $expected, "  Uncompressed matches original";
1058         }
1059
1060         {
1061             title "$TopType - From stdin (via '-') to Buffer content, Append($append) " ;
1062
1063             my $in_file = "abcde.in";
1064             my $lex = new LexFile($in_file) ;
1065             writeFile($in_file, $comp);
1066
1067             ok open(SAVEIN, "<&STDIN"), "  save STDIN";
1068             my $dummy = fileno SAVEIN ;
1069             ok open(STDIN, "<$in_file"), "  redirect STDIN";
1070
1071             my $output ;
1072             $output = $incumbent if $append ;
1073
1074             ok &$Func('-', \$output, Append => $append), '  Uncompressed ok' 
1075                 or diag $$Error ;
1076
1077             ok open(STDIN, "<&SAVEIN"), "  put STDIN back";
1078
1079             is $keep_comp, $comp, "  Input buffer not changed" ;
1080             is $output, $expected, "  Uncompressed matches original";
1081         }
1082     }
1083
1084     {
1085         title "$TopType - From Handle to Buffer, InputLength" ;
1086
1087         my $out_file = "abcde.out";
1088         my $in_file = "abcde.in";
1089         my $lex = new LexFile($in_file, $out_file) ;
1090         my $out ;
1091
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" ;
1097
1098         ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp), '  Uncompressed ok' ;
1099
1100         is $out, $expected, "  Uncompressed matches original";
1101
1102         my $buff;
1103         is $in->read($buff, $len_appended), $len_appended, "  Length of Appended data ok";
1104         is $buff, $appended, "  Appended data ok";
1105
1106         $out = '';
1107         ok &$Func($in, \$out, Transparent => 0, InputLength => length $comp), '  Uncompressed ok' ;
1108
1109         is $out, $expected, "  Uncompressed matches original";
1110
1111         $buff = '';
1112         is $in->read($buff, $len_appended), $len_appended, "  Length of Appended data ok";
1113         is $buff, $appended, "  Appended data ok";
1114     }
1115
1116     for my $stdin ('-', *STDIN) # , \*STDIN)
1117     {
1118         title "$TopType - From stdin (via $stdin) to Buffer content, InputLength" ;
1119
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) ;
1126
1127         ok open(SAVEIN, "<&STDIN"), "  save STDIN";
1128         my $dummy = fileno SAVEIN ;
1129         ok open(STDIN, "<$in_file"), "  redirect STDIN";
1130
1131         my $output ;
1132
1133         ok &$Func($stdin, \$output, Transparent => 0, InputLength => length $comp), '  Uncompressed ok' 
1134             or diag $$Error ;
1135
1136         my $buff ;
1137         is read(STDIN, $buff, $len_appended), $len_appended, "  Length of Appended data ok";
1138
1139         is $output, $expected, "  Uncompressed matches original";
1140         is $buff, $appended, "  Appended data ok";
1141
1142         $output = '';
1143         ok &$Func($stdin, \$output, Transparent => 0, InputLength => length $comp), '  Uncompressed ok' 
1144             or diag $$Error ;
1145
1146         $buff = '';
1147         is read(STDIN, $buff, $len_appended), $len_appended, "  Length of Appended data ok"
1148             or diag "read failed $!";
1149
1150         is $output, $expected, "  Uncompressed matches original";
1151         is $buff, $appended, "  Appended data ok";
1152
1153         ok open(STDIN, "<&SAVEIN"), "  put STDIN back";
1154     }
1155 }
1156
1157 foreach my $bit ('IO::Uncompress::Gunzip',     
1158                  'IO::Uncompress::Inflate', 
1159                  'IO::Uncompress::RawInflate',
1160                  'IO::Uncompress::AnyInflate',
1161                 )
1162 {
1163     # TODO -- Add Append mode tests
1164
1165     my $Error = getErrorRef($bit);
1166     my $Func = getTopFuncRef($bit);
1167     my $TopType = getTopFuncName($bit);
1168
1169     my $buffer = "abcde" ;
1170     my $keep_orig = $buffer;
1171
1172
1173     my $null = compressBuffer($TopType, "") ;
1174     my $undef = compressBuffer($TopType, undef) ;
1175     my $comp = compressBuffer($TopType, $buffer) ;
1176     my $keep_comp = $comp;
1177
1178     my $incumbent = "incumbent data" ;
1179
1180     my ($file1, $file2) = ("file1", "file2");
1181     my $lex = new LexFile($file1, $file2) ;
1182
1183     writeFile($file1, compressBuffer($TopType,"data1"));
1184     writeFile($file2, compressBuffer($TopType,"data2"));
1185
1186     my $of = new IO::File "<$file1" ;
1187     ok $of, "  Created output filehandle" ;
1188
1189     my @input    = ($file2, \$undef, \$null, \$comp, $of) ;
1190     my @expected = ('data2', '',      '',    'abcde', 'data1');
1191
1192     my @keep = @input ;
1193
1194     {
1195         title "$TopType - From ArrayRef to Buffer" ;
1196
1197         my $output  ;
1198         ok &$Func(\@input, \$output, AutoClose => 0), '  UnCompressed ok' ;
1199
1200         is $output, join('', @expected)
1201     }
1202
1203     {
1204         title "$TopType - From ArrayRef to Filename" ;
1205
1206         my $output  = 'abc';
1207         my $lex = new LexFile $output;
1208         $of->open("<$file1") ;
1209
1210         ok &$Func(\@input, $output, AutoClose => 0), '  UnCompressed ok' ;
1211
1212         is readFile($output), join('', @expected)
1213     }
1214
1215     {
1216         title "$TopType - From ArrayRef to Filehandle" ;
1217
1218         my $output  = 'abc';
1219         my $lex = new LexFile $output;
1220         my $fh = new IO::File ">$output" ;
1221         $of->open("<$file1") ;
1222
1223         ok &$Func(\@input, $fh, AutoClose => 0), '  UnCompressed ok' ;
1224         $fh->close;
1225
1226         is readFile($output), join('', @expected)
1227     }
1228
1229     {
1230         title "$TopType - From Array Ref to Array Ref" ;
1231
1232         my @output = (\'first') ;
1233         $of->open("<$file1") ;
1234         ok &$Func(\@input, \@output, AutoClose => 0), '  UnCompressed ok' ;
1235
1236         is_deeply \@input, \@keep, "  Input array not changed" ;
1237         is_deeply [map { defined $$_ ? $$_ : "" } @output], 
1238                   ['first', @expected], 
1239                   "  Got Expected uncompressed data";
1240
1241     }
1242 }
1243
1244 foreach my $bit ('IO::Uncompress::Gunzip',     
1245                  'IO::Uncompress::Inflate', 
1246                  'IO::Uncompress::RawInflate',
1247                  'IO::Uncompress::AnyInflate',
1248                 )
1249 {
1250     # TODO -- Add Append mode tests
1251
1252     my $Error = getErrorRef($bit);
1253     my $Func = getTopFuncRef($bit);
1254     my $TopType = getTopFuncName($bit);
1255
1256     my $tmpDir1 = 'tmpdir1';
1257     my $tmpDir2 = 'tmpdir2';
1258     my $lex = new LexDir($tmpDir1, $tmpDir2) ;
1259
1260     mkdir $tmpDir1, 0777;
1261     mkdir $tmpDir2, 0777;
1262
1263     ok   -d $tmpDir1, "  Temp Directory $tmpDir1 exists";
1264     #ok ! -d $tmpDir2, "  Temp Directory $tmpDir2 does not exist";
1265
1266     my @files = map { "$tmpDir1/$_.tmp" } qw( a1 a2 a3) ;
1267     foreach (@files) { writeFile($_, compressBuffer($TopType, "abc $_")) }
1268
1269     my @expected = map { "abc $_" } @files ;
1270     my @outFiles = map { s/$tmpDir1/$tmpDir2/; $_ } @files ;
1271
1272     {
1273         title "$TopType - From FileGlob to FileGlob" ;
1274
1275         ok &$Func("<$tmpDir1/a*.tmp>" => "<$tmpDir2/a#1.tmp>"), '  UnCompressed ok' 
1276             or diag $$Error ;
1277
1278         my @copy = @expected;
1279         for my $file (@outFiles)
1280         {
1281             is readFile($file), shift @copy, "  got expected from $file" ;
1282         }
1283
1284         is @copy, 0, "  got all files";
1285     }
1286
1287     {
1288         title "$TopType - From FileGlob to Arrayref" ;
1289
1290         my @output = (\'first');
1291         ok &$Func("<$tmpDir1/a*.tmp>" => \@output), '  UnCompressed ok' 
1292             or diag $$Error ;
1293
1294         my @copy = ('first', @expected);
1295         for my $data (@output)
1296         {
1297             is $$data, shift @copy, "  got expected data" ;
1298         }
1299
1300         is @copy, 0, "  got all files";
1301     }
1302
1303     {
1304         title "$TopType - From FileGlob to Buffer" ;
1305
1306         my $output ;
1307         ok &$Func("<$tmpDir1/a*.tmp>" => \$output), '  UnCompressed ok' 
1308             or diag $$Error ;
1309
1310         is $output, join('', @expected), "  got expected uncompressed data";
1311     }
1312
1313     {
1314         title "$TopType - From FileGlob to Filename" ;
1315
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' 
1320             or diag $$Error ;
1321
1322         ok -e $output, "  $output does exist" ;
1323         is readFile($output), join('', @expected), "  got expected uncompressed data";
1324     }
1325
1326     {
1327         title "$TopType - From FileGlob to Filehandle" ;
1328
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' 
1333             or diag $$Error ;
1334
1335         ok -e $output, "  $output does exist" ;
1336         is readFile($output), join('', @expected), "  got expected uncompressed data";
1337     }
1338
1339 }
1340
1341 foreach my $TopType ('IO::Compress::Gzip::gzip', 
1342                      'IO::Compress::Deflate', 
1343                      'IO::Compress::RawDeflate', 
1344                      # TODO -- add the inflate classes
1345                     )
1346 {
1347     my $Error = getErrorRef($TopType);
1348     my $Func = getTopFuncRef($TopType);
1349     my $Name = getTopFuncName($TopType);
1350
1351     title "More write tests" ;
1352
1353     my $file1 = "file1" ;
1354     my $file2 = "file2" ;
1355     my $file3 = "file3" ;
1356     my $lex = new LexFile $file1, $file2, $file3 ;
1357
1358     writeFile($file1, "F1");
1359     writeFile($file2, "F2");
1360     writeFile($file3, "F3");
1361
1362     my @data = (
1363           [ '[]',                                    ""     ],
1364           [ '[\""]',                                 ""     ],
1365           [ '[\undef]',                              ""     ],
1366           [ '[\"abcd"]',                             "abcd" ],
1367           [ '[\"ab", \"cd"]',                        "abcd" ],
1368
1369           [ '$fh2',                                  "F2"   ],
1370           [ '[\"a", $fh1, \"bc"]',                   "aF1bc"],
1371         ) ;
1372
1373
1374     foreach my $data (@data)
1375     {
1376         my ($send, $get) = @$data ;
1377
1378         my $fh1 = new IO::File "< $file1" ;
1379         my $fh2 = new IO::File "< $file2" ;
1380         my $fh3 = new IO::File "< $file3" ;
1381
1382         title "$send";
1383         my $copy;
1384         eval "\$copy = $send";
1385         my $Answer ;
1386         ok &$Func($copy, \$Answer), "  $Name ok";
1387
1388         my $got = anyUncompress(\$Answer);
1389         is $got, $get, "  got expected output" ;
1390         cmp_ok $$Error, '==', 0, "  no error";
1391
1392
1393     }
1394
1395     title "Array Input Error tests" ;
1396
1397     @data = (
1398                '[[]]', 
1399                '[[[]]]',
1400                '[[\"ab"], [\"cd"]]',
1401             ) ;
1402
1403
1404     foreach my $send (@data)
1405     {
1406         my $fh1 = new IO::File "< $file1" ;
1407         my $fh2 = new IO::File "< $file2" ;
1408         my $fh3 = new IO::File "< $file3" ;
1409
1410         title "$send";
1411         my $copy;
1412         eval "\$copy = $send";
1413         my $Answer ;
1414         ok ! &$Func($copy, \$Answer), "  $Name fails";
1415
1416         is $$Error, "unknown input parameter", "  got error message";
1417
1418     }
1419 }
1420
1421 sub gzipGetHeader
1422 {
1423     my $in = shift;
1424     my $content = shift ;
1425     my %opts = @_ ;
1426
1427     my $out ;
1428     my $got ;
1429
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" ;
1434
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";
1440     my $uncomp ;
1441     ok $gunz->read($uncomp), " read ok" ;
1442     is $uncomp, $content, "  got expected content";
1443     ok $gunz->close, "  closed ok" ;
1444
1445     return $hdr ;
1446     
1447 }
1448
1449 {
1450     title "Check gzip header default NAME & MTIME settings" ;
1451
1452     my $file1 = "file1" ;
1453     my $lex = new LexFile $file1;
1454
1455     my $content = "hello ";
1456     my $hdr ;
1457     my $mtime ;
1458
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
1463     sleep 3 ; 
1464     $hdr = gzipGetHeader($file1, $content);
1465
1466     is $hdr->{Name}, $file1, "  Name is '$file1'";
1467     is $hdr->{Time}, $mtime, "  Time is ok";
1468
1469     title "Override Name" ;
1470
1471     writeFile($file1, $content);
1472     $mtime = (stat($file1))[8];
1473     sleep 3 ; 
1474     $hdr = gzipGetHeader($file1, $content, Name => "abcde");
1475
1476     is $hdr->{Name}, "abcde", "  Name is 'abcde'" ;
1477     is $hdr->{Time}, $mtime, "  Time is ok";
1478
1479     title "Override Time" ;
1480
1481     writeFile($file1, $content);
1482     $hdr = gzipGetHeader($file1, $content, Time => 1234);
1483
1484     is $hdr->{Name}, $file1, "  Name is '$file1'" ;
1485     is $hdr->{Time}, 1234,  "  Time is 1234";
1486
1487     title "Override Name and Time" ;
1488
1489     writeFile($file1, $content);
1490     $hdr = gzipGetHeader($file1, $content, Time => 4321, Name => "abcde");
1491
1492     is $hdr->{Name}, "abcde", "  Name is 'abcde'" ;
1493     is $hdr->{Time}, 4321, "  Time is 4321";
1494
1495     title "Filehandle doesn't have default Name or Time" ;
1496     my $fh = new IO::File "< $file1"
1497         or diag "Cannot open '$file1': $!\n" ;
1498     sleep 3 ; 
1499     my $before = time ;
1500     $hdr = gzipGetHeader($fh, $content);
1501     my $after = time ;
1502
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";
1506
1507     $fh->close;
1508
1509     title "Buffer doesn't have default Name or Time" ;
1510     my $buffer = $content;
1511     $before = time ;
1512     $hdr = gzipGetHeader(\$buffer, $content);
1513     $after = time ;
1514
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";
1518 }
1519
1520 # TODO add more error cases
1521