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