Commit | Line | Data |
1a6a8453 |
1 | |
2 | use strict; |
3 | use warnings; |
4 | use bytes; |
5 | |
6 | use Test::More ; |
25f0751f |
7 | use CompTestUtils; |
1a6a8453 |
8 | |
9 | use IO::Handle qw(SEEK_SET SEEK_CUR SEEK_END); |
10 | |
11 | our ($UncompressClass); |
12 | BEGIN |
13 | { |
14 | # use Test::NoWarnings, if available |
15 | my $extra = 0 ; |
16 | |
17 | my $st = eval { require Test::NoWarnings ; import Test::NoWarnings; 1; }; |
18 | $extra = 1 |
19 | if $st ; |
1a6a8453 |
20 | |
2b4e0969 |
21 | plan(tests => 615 + $extra) ; |
1a6a8453 |
22 | } |
23 | |
1a6a8453 |
24 | sub myGZreadFile |
25 | { |
26 | my $filename = shift ; |
27 | my $init = shift ; |
28 | |
29 | |
30 | my $fil = new $UncompressClass $filename, |
31 | -Strict => 0, |
32 | -Append => 1 |
33 | ; |
34 | |
35 | my $data = ''; |
36 | $data = $init if defined $init ; |
37 | 1 while $fil->read($data) > 0; |
38 | |
39 | $fil->close ; |
40 | return $data ; |
41 | } |
42 | |
43 | sub run |
44 | { |
1a6a8453 |
45 | my $CompressClass = identify(); |
46 | $UncompressClass = getInverse($CompressClass); |
47 | my $Error = getErrorRef($CompressClass); |
48 | my $UnError = getErrorRef($UncompressClass); |
49 | |
50 | { |
51 | |
52 | title "Testing $CompressClass Errors"; |
53 | |
54 | # Buffer not writable |
55 | eval qq[\$a = new $CompressClass(\\1) ;] ; |
56 | like $@, mkEvalErr("^$CompressClass: output buffer is read-only") ; |
57 | |
58 | my($out, $gz); |
59 | $out = "" ; |
60 | eval qq[\$a = new $CompressClass ] . '$out ;' ; |
61 | like $@, mkEvalErr("^$CompressClass: output filename is undef or null string"); |
62 | |
63 | $out = undef ; |
64 | eval qq[\$a = new $CompressClass \$out ;] ; |
65 | like $@, mkEvalErr("^$CompressClass: output filename is undef or null string"); |
66 | |
67 | my $x ; |
68 | $gz = new $CompressClass(\$x); |
69 | |
70 | foreach my $name (qw(read readline getc)) |
71 | { |
72 | eval " \$gz->$name() " ; |
73 | like $@, mkEvalErr("^$name Not Available: File opened only for output"); |
74 | } |
75 | |
76 | eval ' $gz->write({})' ; |
77 | like $@, mkEvalErr("^${CompressClass}::write: not a scalar reference"); |
78 | #like $@, mkEvalErr("^${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref"); |
79 | |
80 | eval ' $gz->syswrite("abc", 1, 5)' ; |
81 | like $@, mkEvalErr("^${CompressClass}::write: offset outside string"); |
82 | |
83 | eval ' $gz->syswrite("abc", 1, -4)' ; |
84 | like $@, mkEvalErr("^${CompressClass}::write: offset outside string"); |
85 | } |
86 | |
87 | |
88 | { |
89 | title "Testing $UncompressClass Errors"; |
90 | |
91 | my $out = "" ; |
92 | eval qq[\$a = new $UncompressClass \$out ;] ; |
93 | like $@, mkEvalErr("^$UncompressClass: input filename is undef or null string"); |
94 | $out = undef ; |
95 | eval qq[\$a = new $UncompressClass \$out ;] ; |
96 | like $@, mkEvalErr("^$UncompressClass: input filename is undef or null string"); |
97 | |
98 | my $lex = new LexFile my $name ; |
99 | |
100 | ok ! -e $name, " $name does not exist"; |
101 | |
102 | eval qq[\$a = new $UncompressClass "$name" ;] ; |
103 | is $$UnError, "input file '$name' does not exist"; |
104 | |
105 | my $gc ; |
106 | my $guz = new $CompressClass(\$gc); |
107 | $guz->write("abc") ; |
108 | $guz->close(); |
109 | |
110 | my $x ; |
111 | my $gz = new $UncompressClass(\$gc); |
112 | |
113 | foreach my $name (qw(print printf write)) |
114 | { |
115 | eval " \$gz->$name() " ; |
116 | like $@, mkEvalErr("^$name Not Available: File opened only for intput"); |
117 | } |
118 | |
119 | } |
120 | |
121 | { |
122 | title "Testing $CompressClass and $UncompressClass"; |
123 | |
124 | { |
125 | my ($a, $x, @x) = ("","","") ; |
126 | |
127 | # Buffer not a scalar reference |
128 | eval qq[\$a = new $CompressClass \\\@x ;] ; |
129 | like $@, mkEvalErr("^$CompressClass: output parameter not a filename, filehandle or scalar ref"); |
130 | |
131 | # Buffer not a scalar reference |
132 | eval qq[\$a = new $UncompressClass \\\@x ;] ; |
133 | like $@, mkEvalErr("^$UncompressClass: input parameter not a filename, filehandle, array ref or scalar ref"); |
134 | } |
135 | |
136 | foreach my $Type ( $CompressClass, $UncompressClass) |
137 | { |
138 | # Check error handling with IO::Compress::Deflate and IO::Uncompress::Inflate |
139 | |
140 | my ($a, $x, @x) = ("","","") ; |
141 | |
142 | # Odd number of parameters |
143 | eval qq[\$a = new $Type "abc", -Output ] ; |
144 | like $@, mkEvalErr("^$Type: Expected even number of parameters, got 1"); |
145 | |
146 | # Unknown parameter |
147 | eval qq[\$a = new $Type "anc", -Fred => 123 ;] ; |
148 | like $@, mkEvalErr("^$Type: unknown key value\\(s\\) Fred"); |
149 | |
150 | # no in or out param |
151 | eval qq[\$a = new $Type ;] ; |
152 | like $@, mkEvalErr("^$Type: Missing (Input|Output) parameter"); |
153 | |
154 | } |
155 | |
156 | |
157 | { |
158 | # write a very simple compressed file |
159 | # and read back |
160 | #======================================== |
161 | |
162 | |
163 | my $lex = new LexFile my $name ; |
164 | |
165 | my $hello = <<EOM ; |
166 | hello world |
167 | this is a test |
168 | EOM |
169 | |
170 | { |
171 | my $x ; |
172 | ok $x = new $CompressClass $name ; |
25f0751f |
173 | is $x->autoflush(1), 0, "autoflush"; |
174 | is $x->autoflush(1), 1, "autoflush"; |
175 | ok $x->opened(), "opened"; |
1a6a8453 |
176 | |
177 | ok $x->write($hello), "write" ; |
178 | ok $x->flush(), "flush"; |
179 | ok $x->close, "close" ; |
25f0751f |
180 | ok ! $x->opened(), "! opened"; |
1a6a8453 |
181 | } |
182 | |
183 | { |
184 | my $uncomp; |
185 | ok my $x = new $UncompressClass $name, -Append => 1 ; |
25f0751f |
186 | ok $x->opened(), "opened"; |
1a6a8453 |
187 | |
188 | my $len ; |
189 | 1 while ($len = $x->read($uncomp)) > 0 ; |
190 | |
191 | is $len, 0, "read returned 0" |
192 | or diag $$UnError ; |
193 | |
194 | ok $x->close ; |
195 | is $uncomp, $hello ; |
25f0751f |
196 | ok !$x->opened(), "! opened"; |
1a6a8453 |
197 | } |
198 | } |
199 | |
200 | { |
201 | # write a very simple compressed file |
202 | # and read back |
203 | #======================================== |
204 | |
205 | |
206 | my $lex = new LexFile my $name ; |
207 | |
208 | my $hello = <<EOM ; |
209 | hello world |
210 | this is a test |
211 | EOM |
212 | |
213 | { |
214 | my $x ; |
215 | ok $x = new $CompressClass $name ; |
216 | |
217 | is $x->write(''), 0, "Write empty string is ok"; |
218 | is $x->write(undef), 0, "Write undef is ok"; |
219 | ok $x->write($hello), "Write ok" ; |
220 | ok $x->close, "Close ok" ; |
221 | } |
222 | |
223 | { |
224 | my $uncomp; |
225 | my $x = new $UncompressClass $name ; |
226 | ok $x, "creates $UncompressClass $name" ; |
227 | |
228 | my $data = ''; |
229 | $data .= $uncomp while $x->read($uncomp) > 0 ; |
230 | |
231 | ok $x->close, "close ok" ; |
232 | is $data, $hello, "expected output" ; |
233 | } |
234 | } |
235 | |
236 | |
237 | { |
238 | # write a very simple file with using an IO filehandle |
239 | # and read back |
240 | #======================================== |
241 | |
242 | |
243 | my $lex = new LexFile my $name ; |
244 | |
245 | my $hello = <<EOM ; |
246 | hello world |
247 | this is a test |
248 | EOM |
249 | |
250 | { |
251 | my $fh = new IO::File ">$name" ; |
252 | ok $fh, "opened file $name ok"; |
253 | my $x = new $CompressClass $fh ; |
254 | ok $x, " created $CompressClass $fh" ; |
255 | |
256 | is $x->fileno(), fileno($fh), "fileno match" ; |
257 | is $x->write(''), 0, "Write empty string is ok"; |
258 | is $x->write(undef), 0, "Write undef is ok"; |
259 | ok $x->write($hello), "write ok" ; |
260 | ok $x->flush(), "flush"; |
261 | ok $x->close,"close" ; |
262 | $fh->close() ; |
263 | } |
264 | |
265 | my $uncomp; |
266 | { |
267 | my $x ; |
268 | ok my $fh1 = new IO::File "<$name" ; |
269 | ok $x = new $UncompressClass $fh1, -Append => 1 ; |
270 | ok $x->fileno() == fileno $fh1 ; |
271 | |
272 | 1 while $x->read($uncomp) > 0 ; |
273 | |
274 | ok $x->close ; |
275 | } |
276 | |
277 | ok $hello eq $uncomp ; |
278 | } |
279 | |
280 | { |
281 | # write a very simple file with using a glob filehandle |
282 | # and read back |
283 | #======================================== |
284 | |
285 | |
286 | my $lex = new LexFile my $name ; |
25f0751f |
287 | #my $name = "/tmp/fred"; |
1a6a8453 |
288 | |
289 | my $hello = <<EOM ; |
290 | hello world |
291 | this is a test |
292 | EOM |
293 | |
294 | { |
295 | title "$CompressClass: Input from typeglob filehandle"; |
296 | ok open FH, ">$name" ; |
297 | |
298 | my $x = new $CompressClass *FH ; |
299 | ok $x, " create $CompressClass" ; |
300 | |
301 | is $x->fileno(), fileno(*FH), " fileno" ; |
302 | is $x->write(''), 0, " Write empty string is ok"; |
303 | is $x->write(undef), 0, " Write undef is ok"; |
304 | ok $x->write($hello), " Write ok" ; |
305 | ok $x->flush(), " Flush"; |
306 | ok $x->close, " Close" ; |
307 | close FH; |
308 | } |
309 | |
310 | |
311 | my $uncomp; |
312 | { |
313 | title "$UncompressClass: Input from typeglob filehandle, append output"; |
314 | my $x ; |
315 | ok open FH, "<$name" ; |
316 | ok $x = new $UncompressClass *FH, -Append => 1, Transparent => 0 |
317 | or diag $$UnError ; |
318 | is $x->fileno(), fileno FH, " fileno ok" ; |
319 | |
320 | 1 while $x->read($uncomp) > 0 ; |
321 | |
322 | ok $x->close, " close" ; |
323 | } |
324 | #exit; |
325 | |
326 | is $uncomp, $hello, " expected output" ; |
327 | } |
328 | |
329 | { |
330 | my $lex = new LexFile my $name ; |
25f0751f |
331 | #my $name = "/tmp/fred"; |
1a6a8453 |
332 | |
333 | my $hello = <<EOM ; |
334 | hello world |
335 | this is a test |
336 | EOM |
337 | |
338 | { |
339 | title "Outout to stdout via '-'" ; |
340 | |
341 | open(SAVEOUT, ">&STDOUT"); |
342 | my $dummy = fileno SAVEOUT; |
343 | open STDOUT, ">$name" ; |
344 | |
345 | my $x = new $CompressClass '-' ; |
346 | $x->write($hello); |
347 | $x->close; |
348 | |
349 | open(STDOUT, ">&SAVEOUT"); |
350 | |
351 | ok 1, " wrote to stdout" ; |
352 | } |
25f0751f |
353 | is myGZreadFile($name), $hello, " wrote OK"; |
354 | #hexDump($name); |
1a6a8453 |
355 | |
356 | { |
357 | title "Input from stdin via filename '-'"; |
358 | |
359 | my $x ; |
360 | my $uncomp ; |
361 | my $stdinFileno = fileno(STDIN); |
362 | # open below doesn't return 1 sometines on XP |
363 | open(SAVEIN, "<&STDIN"); |
364 | ok open(STDIN, "<$name"), " redirect STDIN"; |
365 | my $dummy = fileno SAVEIN; |
25f0751f |
366 | $x = new $UncompressClass '-', Append => 1, Transparent => 0 |
367 | or diag $$UnError ; |
1a6a8453 |
368 | ok $x, " created object" ; |
369 | is $x->fileno(), $stdinFileno, " fileno ok" ; |
370 | |
371 | 1 while $x->read($uncomp) > 0 ; |
372 | |
373 | ok $x->close, " close" ; |
374 | open(STDIN, "<&SAVEIN"); |
375 | is $uncomp, $hello, " expected output" ; |
376 | } |
377 | } |
378 | |
379 | { |
380 | # write a compressed file to memory |
381 | # and read back |
382 | #======================================== |
383 | |
25f0751f |
384 | #my $name = "test.gz" ; |
385 | my $lex = new LexFile my $name ; |
1a6a8453 |
386 | |
387 | my $hello = <<EOM ; |
388 | hello world |
389 | this is a test |
390 | EOM |
391 | |
392 | my $buffer ; |
393 | { |
394 | my $x ; |
395 | ok $x = new $CompressClass(\$buffer) ; |
396 | |
25f0751f |
397 | ok ! defined $x->autoflush(1) ; |
398 | ok ! defined $x->autoflush(1) ; |
1a6a8453 |
399 | ok ! defined $x->fileno() ; |
400 | is $x->write(''), 0, "Write empty string is ok"; |
401 | is $x->write(undef), 0, "Write undef is ok"; |
402 | ok $x->write($hello) ; |
403 | ok $x->flush(); |
404 | ok $x->close ; |
405 | |
406 | writeFile($name, $buffer) ; |
407 | #is anyUncompress(\$buffer), $hello, " any ok"; |
408 | } |
409 | |
410 | my $keep = $buffer ; |
411 | my $uncomp; |
412 | { |
413 | my $x ; |
414 | ok $x = new $UncompressClass(\$buffer, Append => 1) ; |
415 | |
25f0751f |
416 | ok ! defined $x->autoflush(1) ; |
417 | ok ! defined $x->autoflush(1) ; |
1a6a8453 |
418 | ok ! defined $x->fileno() ; |
419 | 1 while $x->read($uncomp) > 0 ; |
420 | |
421 | ok $x->close ; |
422 | } |
423 | |
424 | is $uncomp, $hello ; |
425 | ok $buffer eq $keep ; |
426 | } |
427 | |
428 | if ($CompressClass ne 'RawDeflate') |
429 | { |
430 | # write empty file |
431 | #======================================== |
432 | |
433 | my $buffer = ''; |
434 | { |
435 | my $x ; |
436 | ok $x = new $CompressClass(\$buffer) ; |
437 | ok $x->close ; |
438 | |
439 | } |
440 | |
441 | my $keep = $buffer ; |
442 | my $uncomp= ''; |
443 | { |
444 | my $x ; |
445 | ok $x = new $UncompressClass(\$buffer, Append => 1) ; |
446 | |
447 | 1 while $x->read($uncomp) > 0 ; |
448 | |
449 | ok $x->close ; |
450 | } |
451 | |
452 | ok $uncomp eq '' ; |
453 | ok $buffer eq $keep ; |
454 | |
455 | } |
456 | |
457 | { |
458 | # write a larger file |
459 | #======================================== |
460 | |
461 | |
462 | my $lex = new LexFile my $name ; |
463 | |
464 | my $hello = <<EOM ; |
465 | hello world |
466 | this is a test |
467 | EOM |
468 | |
469 | my $input = '' ; |
470 | my $contents = '' ; |
471 | |
472 | { |
473 | my $x = new $CompressClass $name ; |
474 | ok $x, " created $CompressClass object"; |
475 | |
476 | ok $x->write($hello), " write ok" ; |
477 | $input .= $hello ; |
478 | ok $x->write("another line"), " write ok" ; |
479 | $input .= "another line" ; |
480 | # all characters |
481 | foreach (0 .. 255) |
482 | { $contents .= chr int $_ } |
483 | # generate a long random string |
484 | foreach (1 .. 5000) |
485 | { $contents .= chr int rand 256 } |
486 | |
487 | ok $x->write($contents), " write ok" ; |
488 | $input .= $contents ; |
489 | ok $x->close, " close ok" ; |
490 | } |
491 | |
492 | ok myGZreadFile($name) eq $input ; |
493 | my $x = readFile($name) ; |
494 | #print "length " . length($x) . " \n"; |
495 | } |
496 | |
497 | { |
498 | # embed a compressed file in another file |
499 | #================================ |
500 | |
501 | |
502 | my $lex = new LexFile my $name ; |
503 | |
504 | my $hello = <<EOM ; |
505 | hello world |
506 | this is a test |
507 | EOM |
508 | |
509 | my $header = "header info\n" ; |
510 | my $trailer = "trailer data\n" ; |
511 | |
512 | { |
513 | my $fh ; |
514 | ok $fh = new IO::File ">$name" ; |
515 | print $fh $header ; |
516 | my $x ; |
517 | ok $x = new $CompressClass $fh, |
518 | -AutoClose => 0 ; |
519 | |
520 | ok $x->binmode(); |
521 | ok $x->write($hello) ; |
522 | ok $x->close ; |
523 | print $fh $trailer ; |
524 | $fh->close() ; |
525 | } |
526 | |
527 | my ($fil, $uncomp) ; |
528 | my $fh1 ; |
529 | ok $fh1 = new IO::File "<$name" ; |
530 | # skip leading junk |
531 | my $line = <$fh1> ; |
532 | ok $line eq $header ; |
533 | |
534 | ok my $x = new $UncompressClass $fh1, Append => 1 ; |
535 | ok $x->binmode(); |
536 | 1 while $x->read($uncomp) > 0 ; |
537 | |
538 | ok $uncomp eq $hello ; |
539 | my $rest ; |
540 | read($fh1, $rest, 5000); |
541 | is $x->trailingData() . $rest, $trailer ; |
542 | #print "# [".$x->trailingData() . "][$rest]\n" ; |
543 | #exit; |
544 | |
545 | } |
546 | |
547 | { |
548 | # Write |
549 | # these tests come almost 100% from IO::String |
550 | |
551 | my $lex = new LexFile my $name ; |
552 | |
553 | my $io = $CompressClass->new($name); |
554 | |
555 | is $io->tell(), 0, " tell returns 0"; ; |
556 | |
557 | my $heisan = "Heisan\n"; |
558 | $io->print($heisan) ; |
559 | |
560 | ok ! $io->eof(), " ! eof"; |
561 | |
562 | is $io->tell(), length($heisan), " tell is " . length($heisan) ; |
563 | |
564 | $io->print("a", "b", "c"); |
565 | |
566 | { |
567 | local($\) = "\n"; |
568 | $io->print("d", "e"); |
569 | local($,) = ","; |
570 | $io->print("f", "g", "h"); |
571 | } |
572 | |
573 | { |
574 | local($\) ; |
575 | $io->print("D", "E"); |
576 | local($,) = "."; |
577 | $io->print("F", "G", "H"); |
578 | } |
579 | |
580 | my $foo = "1234567890"; |
581 | |
582 | is $io->syswrite($foo, length($foo)), length($foo), " syswrite ok" ; |
583 | if ( $[ < 5.6 ) |
584 | { is $io->syswrite($foo, length $foo), length $foo, " syswrite ok" } |
585 | else |
586 | { is $io->syswrite($foo), length $foo, " syswrite ok" } |
587 | is $io->syswrite($foo, length($foo)), length $foo, " syswrite ok"; |
588 | is $io->write($foo, length($foo), 5), 5, " write 5"; |
589 | is $io->write("xxx\n", 100, -1), 1, " write 1"; |
590 | |
591 | for (1..3) { |
592 | $io->printf("i(%d)", $_); |
593 | $io->printf("[%d]\n", $_); |
594 | } |
595 | $io->print("\n"); |
596 | |
597 | $io->close ; |
598 | |
599 | ok $io->eof(), " eof"; |
600 | |
601 | is myGZreadFile($name), "Heisan\nabcde\nf,g,h\nDEF.G.H" . |
602 | ("1234567890" x 3) . "67890\n" . |
603 | "i(1)[1]\ni(2)[2]\ni(3)[3]\n\n"; |
604 | |
605 | |
606 | } |
607 | |
608 | { |
609 | # Read |
610 | my $str = <<EOT; |
611 | This is an example |
612 | of a paragraph |
613 | |
614 | |
615 | and a single line. |
616 | |
617 | EOT |
618 | |
619 | my $lex = new LexFile my $name ; |
620 | |
621 | my %opts = () ; |
622 | my $iow = new $CompressClass $name, %opts; |
623 | $iow->print($str) ; |
624 | $iow->close ; |
625 | |
626 | my @tmp; |
627 | my $buf; |
628 | { |
629 | my $io = new $UncompressClass $name ; |
630 | |
25f0751f |
631 | is $., 0; |
632 | is $io->input_line_number, 0; |
1a6a8453 |
633 | ok ! $io->eof; |
634 | is $io->tell(), 0 ; |
635 | #my @lines = <$io>; |
636 | my @lines = $io->getlines(); |
637 | is @lines, 6 |
638 | or print "# Got " . scalar(@lines) . " lines, expected 6\n" ; |
639 | is $lines[1], "of a paragraph\n" ; |
640 | is join('', @lines), $str ; |
641 | is $., 6; |
25f0751f |
642 | is $io->input_line_number, 6; |
1a6a8453 |
643 | is $io->tell(), length($str) ; |
644 | |
645 | ok $io->eof; |
646 | |
647 | ok ! ( defined($io->getline) || |
648 | (@tmp = $io->getlines) || |
649 | defined($io->getline) || |
650 | defined($io->getc) || |
651 | $io->read($buf, 100) != 0) ; |
652 | } |
653 | |
654 | |
655 | { |
656 | local $/; # slurp mode |
657 | my $io = $UncompressClass->new($name); |
25f0751f |
658 | is $., 0; |
659 | is $io->input_line_number, 0; |
1a6a8453 |
660 | ok ! $io->eof; |
661 | my @lines = $io->getlines; |
25f0751f |
662 | is $., 1; |
663 | is $io->input_line_number, 1; |
1a6a8453 |
664 | ok $io->eof; |
665 | ok @lines == 1 && $lines[0] eq $str; |
666 | |
667 | $io = $UncompressClass->new($name); |
668 | ok ! $io->eof; |
669 | my $line = $io->getline(); |
670 | ok $line eq $str; |
671 | ok $io->eof; |
672 | } |
673 | |
674 | { |
675 | local $/ = ""; # paragraph mode |
676 | my $io = $UncompressClass->new($name); |
25f0751f |
677 | is $., 0; |
678 | is $io->input_line_number, 0; |
1a6a8453 |
679 | ok ! $io->eof; |
680 | my @lines = $io->getlines(); |
25f0751f |
681 | is $., 2; |
682 | is $io->input_line_number, 2; |
1a6a8453 |
683 | ok $io->eof; |
684 | ok @lines == 2 |
685 | or print "# Got " . scalar(@lines) . " lines, expected 2\n" ; |
686 | ok $lines[0] eq "This is an example\nof a paragraph\n\n\n" |
687 | or print "# $lines[0]\n"; |
688 | ok $lines[1] eq "and a single line.\n\n"; |
689 | } |
690 | |
691 | { |
692 | local $/ = "is"; |
693 | my $io = $UncompressClass->new($name); |
694 | my @lines = (); |
695 | my $no = 0; |
696 | my $err = 0; |
697 | ok ! $io->eof; |
698 | while (my $a = $io->getline()) { |
699 | push(@lines, $a); |
700 | $err++ if $. != ++$no; |
701 | } |
702 | |
703 | ok $err == 0 ; |
704 | ok $io->eof; |
705 | |
25f0751f |
706 | is $., 3; |
707 | is $io->input_line_number, 3; |
1a6a8453 |
708 | ok @lines == 3 |
709 | or print "# Got " . scalar(@lines) . " lines, expected 3\n" ; |
710 | ok join("-", @lines) eq |
711 | "This- is- an example\n" . |
712 | "of a paragraph\n\n\n" . |
713 | "and a single line.\n\n"; |
714 | } |
715 | |
716 | |
717 | # Test read |
718 | |
719 | { |
720 | my $io = $UncompressClass->new($name); |
721 | |
722 | |
723 | eval { $io->read(1) } ; |
724 | like $@, mkErr("buffer parameter is read-only"); |
725 | |
726 | is $io->read($buf, 0), 0, "Requested 0 bytes" ; |
727 | |
728 | ok $io->read($buf, 3) == 3 ; |
729 | ok $buf eq "Thi"; |
730 | |
731 | ok $io->sysread($buf, 3, 2) == 3 ; |
732 | ok $buf eq "Ths i" |
733 | or print "# [$buf]\n" ;; |
734 | ok ! $io->eof; |
735 | |
736 | # $io->seek(-4, 2); |
737 | # |
738 | # ok ! $io->eof; |
739 | # |
740 | # ok read($io, $buf, 20) == 4 ; |
741 | # ok $buf eq "e.\n\n"; |
742 | # |
743 | # ok read($io, $buf, 20) == 0 ; |
744 | # ok $buf eq ""; |
745 | # |
746 | # ok ! $io->eof; |
747 | } |
748 | |
749 | } |
750 | |
751 | { |
752 | # Read from non-compressed file |
753 | |
754 | my $str = <<EOT; |
755 | This is an example |
756 | of a paragraph |
757 | |
758 | |
759 | and a single line. |
760 | |
761 | EOT |
762 | |
763 | my $lex = new LexFile my $name ; |
764 | |
765 | writeFile($name, $str); |
766 | my @tmp; |
767 | my $buf; |
768 | { |
769 | my $io = new $UncompressClass $name, -Transparent => 1 ; |
770 | |
771 | ok defined $io; |
772 | ok ! $io->eof; |
773 | ok $io->tell() == 0 ; |
774 | my @lines = $io->getlines(); |
25f0751f |
775 | is @lines, 6; |
1a6a8453 |
776 | ok $lines[1] eq "of a paragraph\n" ; |
777 | ok join('', @lines) eq $str ; |
25f0751f |
778 | is $., 6; |
779 | is $io->input_line_number, 6; |
1a6a8453 |
780 | ok $io->tell() == length($str) ; |
781 | |
782 | ok $io->eof; |
783 | |
784 | ok ! ( defined($io->getline) || |
785 | (@tmp = $io->getlines) || |
786 | defined($io->getline) || |
787 | defined($io->getc) || |
788 | $io->read($buf, 100) != 0) ; |
789 | } |
790 | |
791 | |
792 | { |
793 | local $/; # slurp mode |
794 | my $io = $UncompressClass->new($name); |
795 | ok ! $io->eof; |
796 | my @lines = $io->getlines; |
25f0751f |
797 | is $., 1; |
798 | is $io->input_line_number, 1; |
1a6a8453 |
799 | ok $io->eof; |
800 | ok @lines == 1 && $lines[0] eq $str; |
801 | |
802 | $io = $UncompressClass->new($name); |
803 | ok ! $io->eof; |
804 | my $line = $io->getline; |
25f0751f |
805 | is $., 1; |
806 | is $io->input_line_number, 1; |
1a6a8453 |
807 | ok $line eq $str; |
808 | ok $io->eof; |
809 | } |
810 | |
811 | { |
812 | local $/ = ""; # paragraph mode |
813 | my $io = $UncompressClass->new($name); |
814 | ok ! $io->eof; |
815 | my @lines = $io->getlines; |
25f0751f |
816 | is $., 2; |
817 | is $io->input_line_number, 2; |
1a6a8453 |
818 | ok $io->eof; |
819 | ok @lines == 2 |
820 | or print "# exected 2 lines, got " . scalar(@lines) . "\n"; |
821 | ok $lines[0] eq "This is an example\nof a paragraph\n\n\n" |
822 | or print "# [$lines[0]]\n" ; |
823 | ok $lines[1] eq "and a single line.\n\n"; |
824 | } |
825 | |
826 | { |
827 | local $/ = "is"; |
828 | my $io = $UncompressClass->new($name); |
829 | my @lines = (); |
830 | my $no = 0; |
831 | my $err = 0; |
832 | ok ! $io->eof; |
833 | while (my $a = $io->getline) { |
834 | push(@lines, $a); |
835 | $err++ if $. != ++$no; |
836 | } |
837 | |
25f0751f |
838 | is $., 3; |
839 | is $io->input_line_number, 3; |
1a6a8453 |
840 | ok $err == 0 ; |
841 | ok $io->eof; |
842 | |
25f0751f |
843 | |
1a6a8453 |
844 | ok @lines == 3 ; |
845 | ok join("-", @lines) eq |
846 | "This- is- an example\n" . |
847 | "of a paragraph\n\n\n" . |
848 | "and a single line.\n\n"; |
849 | } |
850 | |
851 | |
852 | # Test read |
853 | |
854 | { |
855 | my $io = $UncompressClass->new($name); |
856 | |
857 | ok $io->read($buf, 3) == 3 ; |
858 | ok $buf eq "Thi"; |
859 | |
860 | ok $io->sysread($buf, 3, 2) == 3 ; |
861 | ok $buf eq "Ths i"; |
862 | ok ! $io->eof; |
863 | |
864 | # $io->seek(-4, 2); |
865 | # |
866 | # ok ! $io->eof; |
867 | # |
868 | # ok read($io, $buf, 20) == 4 ; |
869 | # ok $buf eq "e.\n\n"; |
870 | # |
871 | # ok read($io, $buf, 20) == 0 ; |
872 | # ok $buf eq ""; |
873 | # |
874 | # ok ! $io->eof; |
875 | } |
876 | |
877 | |
878 | } |
879 | |
880 | { |
881 | # Vary the length parameter in a read |
882 | |
883 | my $str = <<EOT; |
884 | x |
885 | x |
886 | This is an example |
887 | of a paragraph |
888 | |
889 | |
890 | and a single line. |
891 | |
892 | EOT |
893 | $str = $str x 100 ; |
894 | |
895 | |
896 | foreach my $bufsize (1, 3, 512, 4096, length($str)-1, length($str), length($str)+1) |
897 | { |
898 | foreach my $trans (0, 1) |
899 | { |
900 | foreach my $append (0, 1) |
901 | { |
902 | title "Read Tests - buf length $bufsize, Transparent $trans, Append $append" ; |
903 | |
904 | my $lex = new LexFile my $name ; |
905 | |
906 | if ($trans) { |
907 | writeFile($name, $str) ; |
908 | } |
909 | else { |
910 | my $iow = new $CompressClass $name; |
911 | $iow->print($str) ; |
912 | $iow->close ; |
913 | } |
914 | |
915 | |
916 | my $io = $UncompressClass->new($name, |
917 | -Append => $append, |
918 | -Transparent => $trans); |
919 | |
920 | my $buf; |
921 | |
922 | is $io->tell(), 0; |
923 | |
924 | if ($append) { |
925 | 1 while $io->read($buf, $bufsize) > 0; |
926 | } |
927 | else { |
928 | my $tmp ; |
929 | $buf .= $tmp while $io->read($tmp, $bufsize) > 0 ; |
930 | } |
931 | is length $buf, length $str; |
932 | ok $buf eq $str ; |
933 | ok ! $io->error() ; |
934 | ok $io->eof; |
935 | } |
936 | } |
937 | } |
938 | } |
939 | |
940 | foreach my $file (0, 1) |
941 | { |
942 | foreach my $trans (0, 1) |
943 | { |
944 | title "seek tests - file $file trans $trans" ; |
945 | |
946 | my $buffer ; |
947 | my $buff ; |
948 | my $lex = new LexFile my $name ; |
949 | |
950 | my $first = "beginning" ; |
951 | my $last = "the end" ; |
952 | |
953 | if ($trans) |
954 | { |
955 | $buffer = $first . "\x00" x 10 . $last; |
956 | writeFile($name, $buffer); |
957 | } |
958 | else |
959 | { |
960 | my $output ; |
961 | if ($file) |
962 | { |
963 | $output = $name ; |
964 | } |
965 | else |
966 | { |
967 | $output = \$buffer; |
968 | } |
969 | |
970 | my $iow = new $CompressClass $output ; |
971 | $iow->print($first) ; |
972 | ok $iow->seek(5, SEEK_CUR) ; |
973 | ok $iow->tell() == length($first)+5; |
974 | ok $iow->seek(0, SEEK_CUR) ; |
975 | ok $iow->tell() == length($first)+5; |
976 | ok $iow->seek(length($first)+10, SEEK_SET) ; |
977 | ok $iow->tell() == length($first)+10; |
978 | |
979 | $iow->print($last) ; |
980 | $iow->close ; |
981 | } |
982 | |
983 | my $input ; |
984 | if ($file) |
985 | { |
986 | $input = $name ; |
987 | } |
988 | else |
989 | { |
990 | $input = \$buffer ; |
991 | } |
992 | |
993 | ok myGZreadFile($input) eq $first . "\x00" x 10 . $last ; |
994 | |
995 | my $io = $UncompressClass->new($input, Strict => 1); |
25f0751f |
996 | ok $io->seek(length($first), SEEK_CUR) |
997 | or diag $$UnError ; |
1a6a8453 |
998 | ok ! $io->eof; |
999 | is $io->tell(), length($first); |
1000 | |
1001 | ok $io->read($buff, 5) ; |
1002 | is $buff, "\x00" x 5 ; |
1003 | is $io->tell(), length($first) + 5; |
1004 | |
1005 | ok $io->seek(0, SEEK_CUR) ; |
1006 | my $here = $io->tell() ; |
1007 | is $here, length($first)+5; |
1008 | |
1009 | ok $io->seek($here+5, SEEK_SET) ; |
1010 | is $io->tell(), $here+5 ; |
1011 | ok $io->read($buff, 100) ; |
1012 | ok $buff eq $last ; |
1013 | ok $io->eof; |
1014 | } |
1015 | } |
1016 | |
1017 | { |
1018 | title "seek error cases" ; |
1019 | |
1020 | my $b ; |
1021 | my $a = new $CompressClass(\$b) ; |
1022 | |
1023 | ok ! $a->error() ; |
1024 | eval { $a->seek(-1, 10) ; }; |
1025 | like $@, mkErr("^${CompressClass}::seek: unknown value, 10, for whence parameter"); |
1026 | |
1027 | eval { $a->seek(-1, SEEK_END) ; }; |
1028 | like $@, mkErr("^${CompressClass}::seek: cannot seek backwards"); |
1029 | |
1030 | $a->write("fred"); |
1031 | $a->close ; |
1032 | |
1033 | |
1034 | my $u = new $UncompressClass(\$b) ; |
1035 | |
1036 | eval { $u->seek(-1, 10) ; }; |
1037 | like $@, mkErr("^${UncompressClass}::seek: unknown value, 10, for whence parameter"); |
1038 | |
1039 | eval { $u->seek(-1, SEEK_END) ; }; |
1040 | like $@, mkErr("^${UncompressClass}::seek: SEEK_END not allowed"); |
1041 | |
1042 | eval { $u->seek(-1, SEEK_CUR) ; }; |
1043 | like $@, mkErr("^${UncompressClass}::seek: cannot seek backwards"); |
1044 | } |
1045 | |
1046 | foreach my $fb (qw(filename buffer filehandle)) |
1047 | { |
1048 | foreach my $append (0, 1) |
1049 | { |
1050 | { |
1051 | title "$CompressClass -- Append $append, Output to $fb" ; |
1052 | |
1053 | my $lex = new LexFile my $name ; |
1054 | |
1055 | my $already = 'already'; |
1056 | my $buffer = $already; |
1057 | my $output; |
1058 | |
1059 | if ($fb eq 'buffer') |
1060 | { $output = \$buffer } |
1061 | elsif ($fb eq 'filename') |
1062 | { |
1063 | $output = $name ; |
1064 | writeFile($name, $buffer); |
1065 | } |
1066 | elsif ($fb eq 'filehandle') |
1067 | { |
1068 | $output = new IO::File ">$name" ; |
1069 | print $output $buffer; |
1070 | } |
1071 | |
1072 | my $a = new $CompressClass($output, Append => $append) ; |
1073 | ok $a, " Created $CompressClass"; |
1074 | my $string = "appended"; |
1075 | $a->write($string); |
1076 | $a->close ; |
1077 | |
1078 | my $data ; |
1079 | if ($fb eq 'buffer') |
1080 | { |
1081 | $data = $buffer; |
1082 | } |
1083 | else |
1084 | { |
1085 | $output->close |
1086 | if $fb eq 'filehandle'; |
1087 | $data = readFile($name); |
1088 | } |
1089 | |
1090 | if ($append || $fb eq 'filehandle') |
1091 | { |
1092 | is substr($data, 0, length($already)), $already, " got prefix"; |
1093 | substr($data, 0, length($already)) = ''; |
1094 | } |
1095 | |
1096 | |
1097 | my $uncomp; |
1098 | my $x = new $UncompressClass(\$data, Append => 1) ; |
1099 | ok $x, " created $UncompressClass"; |
1100 | |
1101 | my $len ; |
1102 | 1 while ($len = $x->read($uncomp)) > 0 ; |
1103 | |
1104 | $x->close ; |
1105 | is $uncomp, $string, ' Got uncompressed data' ; |
1106 | |
1107 | } |
1108 | } |
1109 | } |
1110 | |
1111 | foreach my $type (qw(buffer filename filehandle)) |
1112 | { |
2b4e0969 |
1113 | foreach my $good (0, 1) |
1114 | { |
1115 | title "$UncompressClass -- InputLength, read from $type, good data => $good"; |
1a6a8453 |
1116 | |
2b4e0969 |
1117 | my $compressed ; |
1118 | my $string = "some data"; |
1119 | my $appended = "append"; |
1a6a8453 |
1120 | |
2b4e0969 |
1121 | if ($good) |
1122 | { |
1123 | my $c = new $CompressClass(\$compressed); |
1124 | $c->write($string); |
1125 | $c->close(); |
1126 | } |
1127 | else |
1128 | { |
1129 | $compressed = $string ; |
1130 | } |
1a6a8453 |
1131 | |
2b4e0969 |
1132 | my $comp_len = length $compressed; |
1133 | $compressed .= $appended; |
1a6a8453 |
1134 | |
2b4e0969 |
1135 | my $lex = new LexFile my $name ; |
1136 | my $input ; |
1137 | writeFile ($name, $compressed); |
1a6a8453 |
1138 | |
2b4e0969 |
1139 | if ($type eq 'buffer') |
1140 | { |
1141 | $input = \$compressed; |
1142 | } |
1143 | if ($type eq 'filename') |
1144 | { |
1145 | $input = $name; |
1146 | } |
1147 | elsif ($type eq 'filehandle') |
1148 | { |
1149 | my $fh = new IO::File "<$name" ; |
1150 | ok $fh, "opened file $name ok"; |
1151 | $input = $fh ; |
1152 | } |
1a6a8453 |
1153 | |
2b4e0969 |
1154 | my $x = new $UncompressClass($input, |
1155 | InputLength => $comp_len, |
1156 | Transparent => 1) ; |
1157 | ok $x, " created $UncompressClass"; |
1a6a8453 |
1158 | |
2b4e0969 |
1159 | my $len ; |
1160 | my $output; |
1161 | $len = $x->read($output, 100); |
1162 | |
1163 | is $len, length($string); |
1164 | is $output, $string; |
1165 | |
1166 | if ($type eq 'filehandle') |
1167 | { |
1168 | my $rest ; |
1169 | $input->read($rest, 1000); |
1170 | is $rest, $appended; |
1171 | } |
1a6a8453 |
1172 | } |
1173 | |
1174 | |
1175 | } |
1176 | |
1177 | foreach my $append (0, 1) |
1178 | { |
1179 | title "$UncompressClass -- Append $append" ; |
1180 | |
1181 | my $lex = new LexFile my $name ; |
1182 | |
1183 | my $string = "appended"; |
1184 | my $compressed ; |
1185 | my $c = new $CompressClass(\$compressed); |
1186 | $c->write($string); |
1187 | $c->close(); |
1188 | |
1189 | my $x = new $UncompressClass(\$compressed, Append => $append) ; |
1190 | ok $x, " created $UncompressClass"; |
1191 | |
1192 | my $already = 'already'; |
1193 | my $output = $already; |
1194 | |
1195 | my $len ; |
1196 | $len = $x->read($output, 100); |
1197 | is $len, length($string); |
1198 | |
1199 | $x->close ; |
1200 | |
1201 | if ($append) |
1202 | { |
1203 | is substr($output, 0, length($already)), $already, " got prefix"; |
1204 | substr($output, 0, length($already)) = ''; |
1205 | } |
1206 | is $output, $string, ' Got uncompressed data' ; |
1207 | } |
1208 | |
1209 | |
1210 | foreach my $file (0, 1) |
1211 | { |
1212 | foreach my $trans (0, 1) |
1213 | { |
1214 | title "ungetc, File $file, Transparent $trans" ; |
1215 | |
1216 | my $lex = new LexFile my $name ; |
1217 | |
1218 | my $string = 'abcdeABCDE'; |
1219 | my $b ; |
1220 | if ($trans) |
1221 | { |
1222 | $b = $string ; |
1223 | } |
1224 | else |
1225 | { |
1226 | my $a = new $CompressClass(\$b) ; |
1227 | $a->write($string); |
1228 | $a->close ; |
1229 | } |
1230 | |
1231 | my $from ; |
1232 | if ($file) |
1233 | { |
1234 | writeFile($name, $b); |
1235 | $from = $name ; |
1236 | } |
1237 | else |
1238 | { |
1239 | $from = \$b ; |
1240 | } |
1241 | |
1242 | my $u = $UncompressClass->new($from, Transparent => 1) ; |
1243 | my $first; |
1244 | my $buff ; |
1245 | |
1246 | # do an ungetc before reading |
1247 | $u->ungetc("X"); |
1248 | $first = $u->getc(); |
1249 | is $first, 'X'; |
1250 | |
1251 | $first = $u->getc(); |
1252 | is $first, substr($string, 0,1); |
1253 | $u->ungetc($first); |
1254 | $first = $u->getc(); |
1255 | is $first, substr($string, 0,1); |
1256 | $u->ungetc($first); |
1257 | |
1258 | is $u->read($buff, 5), 5 ; |
1259 | is $buff, substr($string, 0, 5); |
1260 | |
1261 | $u->ungetc($buff) ; |
1262 | is $u->read($buff, length($string)), length($string) ; |
1263 | is $buff, $string; |
1264 | |
1265 | is $u->read($buff, 1), 0; |
1266 | ok $u->eof() ; |
1267 | |
1268 | my $extra = 'extra'; |
1269 | $u->ungetc($extra); |
1270 | ok ! $u->eof(); |
1271 | is $u->read($buff), length($extra) ; |
1272 | is $buff, $extra; |
1273 | |
1274 | is $u->read($buff, 1), 0; |
1275 | ok $u->eof() ; |
1276 | |
cb7abd7f |
1277 | # getc returns undef on eof |
1278 | is $u->getc(), undef; |
1a6a8453 |
1279 | $u->close(); |
1280 | |
1281 | } |
1282 | } |
1283 | |
1284 | |
1285 | { |
1286 | title "write tests - invalid data" ; |
1287 | |
1288 | #my $lex = new LexFile my $name1 ; |
1289 | my($Answer); |
1290 | |
1291 | #ok ! -e $name1, " File $name1 does not exist"; |
1292 | |
1293 | my @data = ( |
1294 | [ '{ }', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ], |
1295 | [ '[ { } ]', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ], |
1296 | [ '[ [ { } ] ]', "${CompressClass}::write: input parameter not a filename, filehandle, array ref or scalar ref" ], |
1297 | [ '[ "" ]', "${CompressClass}::write: input filename is undef or null string" ], |
1298 | [ '[ undef ]', "${CompressClass}::write: input filename is undef or null string" ], |
1299 | [ '[ \$Answer ]',"${CompressClass}::write: input and output buffer are identical" ], |
1300 | #[ "not readable", 'xx' ], |
1301 | # same filehandle twice, 'xx' |
1302 | ) ; |
1303 | |
1304 | foreach my $data (@data) |
1305 | { |
1306 | my ($send, $get) = @$data ; |
1307 | title "${CompressClass}::write( $send )"; |
1308 | my($copy); |
1309 | eval "\$copy = $send"; |
1310 | my $x = new $CompressClass(\$Answer); |
1311 | ok $x, " Created $CompressClass object"; |
1312 | eval { $x->write($copy) } ; |
1313 | #like $@, "/^$get/", " error - $get"; |
1314 | like $@, "/not a scalar reference /", " error - not a scalar reference"; |
1315 | } |
1316 | |
1317 | # @data = ( |
1318 | # [ '[ $name1 ]', "input file '$name1' does not exist" ], |
1319 | # #[ "not readable", 'xx' ], |
1320 | # # same filehandle twice, 'xx' |
1321 | # ) ; |
1322 | # |
1323 | # foreach my $data (@data) |
1324 | # { |
1325 | # my ($send, $get) = @$data ; |
1326 | # title "${CompressClass}::write( $send )"; |
1327 | # my $copy; |
1328 | # eval "\$copy = $send"; |
1329 | # my $x = new $CompressClass(\$Answer); |
1330 | # ok $x, " Created $CompressClass object"; |
1331 | # ok ! $x->write($copy), " write fails" ; |
1332 | # like $$Error, "/^$get/", " error - $get"; |
1333 | # } |
1334 | |
1335 | #exit; |
1336 | |
1337 | } |
1338 | |
1339 | |
1340 | # sub deepCopy |
1341 | # { |
1342 | # if (! ref $_[0] || ref $_[0] eq 'SCALAR') |
1343 | # { |
1344 | # return $_[0] ; |
1345 | # } |
1346 | # |
1347 | # if (ref $_[0] eq 'ARRAY') |
1348 | # { |
1349 | # my @a ; |
1350 | # for my $x ( @{ $_[0] }) |
1351 | # { |
1352 | # push @a, deepCopy($x); |
1353 | # } |
1354 | # |
1355 | # return \@a ; |
1356 | # } |
1357 | # |
1358 | # croak "bad! $_[0]"; |
1359 | # |
1360 | # } |
1361 | # |
1362 | # sub deepSubst |
1363 | # { |
1364 | # #my $data = shift ; |
1365 | # my $from = $_[1] ; |
1366 | # my $to = $_[2] ; |
1367 | # |
1368 | # if (! ref $_[0]) |
1369 | # { |
1370 | # $_[0] = $to |
1371 | # if $_[0] eq $from ; |
1372 | # return ; |
1373 | # |
1374 | # } |
1375 | # |
1376 | # if (ref $_[0] eq 'SCALAR') |
1377 | # { |
1378 | # $_[0] = \$to |
1379 | # if defined ${ $_[0] } && ${ $_[0] } eq $from ; |
1380 | # return ; |
1381 | # |
1382 | # } |
1383 | # |
1384 | # if (ref $_[0] eq 'ARRAY') |
1385 | # { |
1386 | # for my $x ( @{ $_[0] }) |
1387 | # { |
1388 | # deepSubst($x, $from, $to); |
1389 | # } |
1390 | # return ; |
1391 | # } |
1392 | # #croak "bad! $_[0]"; |
1393 | # } |
1394 | |
1395 | # { |
1396 | # title "More write tests" ; |
1397 | # |
1398 | # my $file1 = "file1" ; |
1399 | # my $file2 = "file2" ; |
1400 | # my $file3 = "file3" ; |
1401 | # my $lex = new LexFile $file1, $file2, $file3 ; |
1402 | # |
1403 | # writeFile($file1, "F1"); |
1404 | # writeFile($file2, "F2"); |
1405 | # writeFile($file3, "F3"); |
1406 | # |
1407 | # my @data = ( |
1408 | # [ '""', "" ], |
1409 | # [ 'undef', "" ], |
1410 | # [ '"abcd"', "abcd" ], |
1411 | # |
1412 | # [ '\""', "" ], |
1413 | # [ '\undef', "" ], |
1414 | # [ '\"abcd"', "abcd" ], |
1415 | # |
1416 | # [ '[]', "" ], |
1417 | # [ '[[]]', "" ], |
1418 | # [ '[[[]]]', "" ], |
1419 | # [ '[\""]', "" ], |
1420 | # [ '[\undef]', "" ], |
1421 | # [ '[\"abcd"]', "abcd" ], |
1422 | # [ '[\"ab", \"cd"]', "abcd" ], |
1423 | # [ '[[\"ab"], [\"cd"]]', "abcd" ], |
1424 | # |
1425 | # [ '$file1', $file1 ], |
1426 | # [ '$fh2', "F2" ], |
1427 | # [ '[$file1, \"abc"]', "F1abc"], |
1428 | # [ '[\"a", $file1, \"bc"]', "aF1bc"], |
1429 | # [ '[\"a", $fh1, \"bc"]', "aF1bc"], |
1430 | # [ '[\"a", $fh1, \"bc", $file2]', "aF1bcF2"], |
1431 | # [ '[\"a", $fh1, \"bc", $file2, $fh3]', "aF1bcF2F3"], |
1432 | # ) ; |
1433 | # |
1434 | # |
1435 | # foreach my $data (@data) |
1436 | # { |
1437 | # my ($send, $get) = @$data ; |
1438 | # |
1439 | # my $fh1 = new IO::File "< $file1" ; |
1440 | # my $fh2 = new IO::File "< $file2" ; |
1441 | # my $fh3 = new IO::File "< $file3" ; |
1442 | # |
1443 | # title "${CompressClass}::write( $send )"; |
1444 | # my $copy; |
1445 | # eval "\$copy = $send"; |
1446 | # my $Answer ; |
1447 | # my $x = new $CompressClass(\$Answer); |
1448 | # ok $x, " Created $CompressClass object"; |
1449 | # my $len = length $get; |
1450 | # is $x->write($copy), length($get), " write $len bytes"; |
1451 | # ok $x->close(), " close ok" ; |
1452 | # |
1453 | # is myGZreadFile(\$Answer), $get, " got expected output" ; |
1454 | # cmp_ok $$Error, '==', 0, " no error"; |
1455 | # |
1456 | # |
1457 | # } |
1458 | # |
1459 | # } |
1460 | } |
1461 | |
1462 | } |
1463 | |
1464 | 1; |
1465 | |
1466 | |
1467 | |
1468 | |
25f0751f |
1469 | |