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