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