summaryrefslogtreecommitdiff
path: root/ext/Compress/Zlib/t/15multi.t
blob: bf0983aa5ff410b9140252cc13e3e752fb8e5c1f (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
BEGIN {
    if ($ENV{PERL_CORE}) {
	chdir 't' if -d 't';
	@INC = '../lib';
    }
}

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

use Test::More ;
use ZlibTestUtils;

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

    plan tests => 575 + $extra ;

    use_ok('Compress::Zlib', 2) ;

    use_ok('IO::Compress::Gzip', qw($GzipError)) ;
    use_ok('IO::Uncompress::Gunzip', qw($GunzipError)) ;
    use_ok('IO::Uncompress::AnyInflate', qw($AnyInflateError)) ;
    use_ok('IO::Uncompress::Inflate', qw($InflateError)) ;
    use_ok('IO::Compress::Deflate', qw($DeflateError)) ;
    use_ok('IO::Uncompress::RawInflate', qw($RawInflateError)) ;
    use_ok('IO::Compress::RawDeflate', qw($RawDeflateError)) ;
}


my @buffers ;
push @buffers, <<EOM ;
hello world
this is a test
some more stuff on this line
ad finally...
EOM

push @buffers, <<EOM ;
some more stuff
EOM

push @buffers, <<EOM ;
even more stuff
EOM

foreach my $CompressClass ('IO::Compress::Gzip',
                           'IO::Compress::Deflate',
                           'IO::Compress::RawDeflate',
                          )
{
    my $UncompressClass = getInverse($CompressClass);


    my $cc ;
    my $gz ;
    my $hsize ;
    my %headers = () ;
    

    foreach my $fb ( qw( file filehandle buffer ) )
    {

        foreach my $i (1 .. @buffers) {

            title "Testing $CompressClass with $i streams to $fb";

            my @buffs = @buffers[0..$i -1] ;

            if ($CompressClass eq 'IO::Compress::Gzip') {
                %headers = (
                              Strict     => 0,
                              Comment    => "this is a comment",
                              ExtraField => "some extra",
                              HeaderCRC  => 1); 

            }

            my $name = "test.gz" ;
            my $lex = new LexFile $name ;
            my $output ;
            if ($fb eq 'buffer')
            {
                my $compressed = '';
                $output = \$compressed;
            }
            elsif ($fb eq 'filehandle')
            {
                $output = new IO::File ">$name" ;
            }
            else
            {
                $output = $name ;
            }

            my $x = new $CompressClass($output, AutoClose => 1, %headers);
            isa_ok $x, $CompressClass, '  $x' ;

            foreach my $buffer (@buffs) {
                ok $x->write($buffer), "    Write OK" ;
                # this will add an extra "empty" stream
                ok $x->newStream(), "    newStream OK" ;
            }
            ok $x->close, "  Close ok" ;

            #hexDump($compressed) ;

            foreach my $unc ($UncompressClass, 'IO::Uncompress::AnyInflate') {
                title "  Testing $CompressClass with $unc and $i streams, from $fb";
                $cc = $output ;
                if ($fb eq 'filehandle')
                {
                    $cc = new IO::File "<$name" ;
                }
                my $gz = new $unc($cc,
                               Strict      => 0,
                               AutoClose   => 1,
                               Append      => 1,
                               MultiStream => 1,
                               Transparent => 0);
                isa_ok $gz, $unc, '    $gz' ;

                my $un = '';
                1 while $gz->read($un) > 0 ;
                #print "[[$un]]\n" while $gz->read($un) > 0 ;
                ok ! $gz->error(), "      ! error()"
                    or diag "Error is " . $gz->error() ;
                ok $gz->eof(), "      eof()";
                ok $gz->close(), "    close() ok"
                    or diag "errno $!\n" ;

                is $gz->streamCount(), $i +1, "    streamCount ok"
                    or diag "Stream count is " . $gz->streamCount();
                ok $un eq join('', @buffs), "    expected output" ;

            }
        }
    }
}


# corrupt one of the streams - all previous should be ok
# trailing stuff
# need a way to skip to the start of the next stream.
# check that "tell" works ok