1
2use lib 't';
3
4use strict;
5use warnings;
6use bytes;
7
8use Test::More ;
9use CompTestUtils;
10
11BEGIN {
12    # use Test::NoWarnings, if available
13    my $extra = 0 ;
14    $extra = 1
15        if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };
16
17    plan tests => 48 + $extra ;
18
19}
20
21sub run
22{
23    my $CompressClass   = identify();
24    my $AnyClass        = getClass();
25    my $UncompressClass = getInverse($CompressClass);
26    my $Error           = getErrorRef($CompressClass);
27    my $UnError         = getErrorRef($UncompressClass);
28
29    my @anyUnLz = ();
30    @anyUnLz = (UnLzma => 1 ) if $CompressClass =~ /lzma/i ;
31
32    my $AnyConstruct = "IO::Uncompress::${AnyClass}" ;
33    no strict 'refs';
34    my $AnyError = \${ "IO::Uncompress::${AnyClass}::${AnyClass}Error" };
35
36    for my $trans ( 0, 1 )
37    {
38        for my $file ( 0, 1 )
39        {
40            title "$AnyClass(Transparent => $trans, File=>$file) with $CompressClass" ;
41            my $string = "some text" x 100 ;
42
43            my $buffer ;
44            my $x = new $CompressClass(\$buffer) ;
45            ok $x, "  create $CompressClass object" ;
46            ok $x->write($string), "  write to object" ;
47            ok $x->close, "  close ok" ;
48
49            my $lex = new LexFile my $output;
50            my $input ;
51
52            if ($file) {
53                writeFile($output, $buffer);
54                $input = $output;
55            }
56            else {
57                $input = \$buffer;
58            }
59
60            {
61                my $unc = new $AnyConstruct $input, Transparent => $trans,
62                                           RawInflate => 1,
63                                           @anyUnLz,
64                                           Append => 1  ;
65
66                ok $unc, "  Created $AnyClass object"
67                    or print "# $$AnyError\n";
68                my $uncomp ;
69                1 while  $unc->read($uncomp) > 0 ;
70                #ok $unc->read($uncomp) > 0
71                #    or print "# $$AnyError\n";
72                my $y;
73                is $unc->read($y, 1), 0, "  at eof" ;
74                ok $unc->eof(), "  at eof" ;
75                #ok $unc->type eq $Type;
76
77                is $uncomp, $string, "  expected output" ;
78            }
79
80            {
81                my $unc = new $AnyConstruct $input, Transparent => $trans,
82                                           RawInflate => 1,
83                                           @anyUnLz,
84                                           Append => 1  ;
85
86                ok $unc, "  Created $AnyClass object"
87                    or print "# $$AnyError\n";
88                my $uncomp ;
89                1 while  $unc->read($uncomp, 100) > 0 ;
90                #ok $unc->read($uncomp) > 0
91                #    or print "# $$AnyError\n";
92                my $y;
93                is $unc->read($y, 1), 0, "  at eof" ;
94                ok $unc->eof(), "  at eof" ;
95                #ok $unc->type eq $Type;
96
97                is $uncomp, $string, "  expected output" ;
98            }
99        }
100    }
101}
102
1031;
104