summaryrefslogtreecommitdiff
path: root/t/lib/compress/any.pl
blob: d95766b0a9ada5e6ceba55374b769c6322295d8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

use lib 't';
 
use strict;
use warnings;
use bytes;

use Test::More ;
use CompTestUtils;

BEGIN {
    # use Test::NoWarnings, if available
    my $extra = 0 ;
    $extra = 1
        if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };

    plan tests => 48 + $extra ;

}

sub run
{
    my $CompressClass   = identify();
    my $AnyClass        = getClass();
    my $UncompressClass = getInverse($CompressClass);
    my $Error           = getErrorRef($CompressClass);
    my $UnError         = getErrorRef($UncompressClass);

    my $AnyConstruct = "IO::Uncompress::${AnyClass}" ;
    no strict 'refs';
    my $AnyError = \${ "IO::Uncompress::${AnyClass}::${AnyClass}Error" };

    for my $trans ( 0, 1 )
    {
        for my $file ( 0, 1 )
        {
            title "$AnyClass(Transparent => $trans, File=>$file) with $CompressClass" ;
            my $string = "some text" x 100 ;

            my $buffer ;
            my $x = new $CompressClass(\$buffer) ;
            ok $x, "  create $CompressClass object" ;
            ok $x->write($string), "  write to object" ;
            ok $x->close, "  close ok" ;

            my $lex = new LexFile my $output;
            my $input ;

            if ($file) {
                writeFile($output, $buffer);
                $input = $output;
            }
            else {
                $input = \$buffer;
            }

            {
                my $unc = new $AnyConstruct $input, Transparent => $trans,
                                           RawInflate => 1,
                                           Append => 1  ;

                ok $unc, "  Created $AnyClass object" 
                    or print "# $$AnyError\n";
                my $uncomp ;
                1 while  $unc->read($uncomp) > 0 ;
                #ok $unc->read($uncomp) > 0 
                #    or print "# $$AnyError\n";
                my $y;
                is $unc->read($y, 1), 0, "  at eof" ;
                ok $unc->eof(), "  at eof" ;
                #ok $unc->type eq $Type;

                is $uncomp, $string, "  expected output" ;
            }

            {
                my $unc = new $AnyConstruct $input, Transparent => $trans,
                                           RawInflate => 1,
                                           Append => 1  ;

                ok $unc, "  Created $AnyClass object" 
                    or print "# $$AnyError\n";
                my $uncomp ;
                1 while  $unc->read($uncomp, 100) > 0 ;
                #ok $unc->read($uncomp) > 0 
                #    or print "# $$AnyError\n";
                my $y;
                is $unc->read($y, 1), 0, "  at eof" ;
                ok $unc->eof(), "  at eof" ;
                #ok $unc->type eq $Type;

                is $uncomp, $string, "  expected output" ;
            }
        }
    }
}

1;