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