1b39c5158Smillert
2b39c5158Smillertuse lib 't';
3b39c5158Smillertuse strict;
4b39c5158Smillertuse warnings;
5b39c5158Smillertuse bytes;
6b39c5158Smillert
7b39c5158Smillertuse Test::More ;
8b39c5158Smillertuse CompTestUtils;
9b39c5158Smillert
10b39c5158Smillertour ($extra);
11b39c5158Smillert
12b39c5158SmillertBEGIN {
13b8851fccSafresh1    plan skip_all => "Lengthy Tests Disabled\n" .
14b8851fccSafresh1                     "set COMPRESS_ZLIB_RUN_ALL or COMPRESS_ZLIB_RUN_MOST to run this test suite"
15b8851fccSafresh1        unless defined $ENV{COMPRESS_ZLIB_RUN_ALL} or defined $ENV{COMPRESS_ZLIB_RUN_MOST};
16b8851fccSafresh1
17b39c5158Smillert    # use Test::NoWarnings, if available
18b39c5158Smillert    $extra = 0 ;
19b39c5158Smillert    $extra = 1
20b39c5158Smillert        if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };
21b39c5158Smillert
22b39c5158Smillert}
23b39c5158Smillert
24b39c5158Smillertsub run
25b39c5158Smillert{
26b39c5158Smillert
27b39c5158Smillert    my $CompressClass   = identify();
28b39c5158Smillert    my $UncompressClass = getInverse($CompressClass);
29b39c5158Smillert    my $Error           = getErrorRef($CompressClass);
30b39c5158Smillert    my $UnError         = getErrorRef($UncompressClass);
31b39c5158Smillert
32b39c5158Smillert
33b39c5158Smillert
34b39c5158Smillert    my $hello = <<EOM ;
35b39c5158Smillerthello world
36b39c5158Smillertthis is a test
37b39c5158Smillertsome more stuff on this line
38b39c5158Smillertad finally...
39b39c5158SmillertEOM
40b39c5158Smillert
41b39c5158Smillert    print "#\n# Testing $UncompressClass\n#\n";
42b39c5158Smillert
43b39c5158Smillert    my $compressed = mkComplete($CompressClass, $hello);
44b39c5158Smillert    my $cc = $compressed ;
45b39c5158Smillert
46b39c5158Smillert    plan tests => (length($compressed) * 6 * 7) + 1 + $extra ;
47b39c5158Smillert
48b39c5158Smillert    is anyUncompress(\$cc), $hello ;
49b39c5158Smillert
50b39c5158Smillert    for my $blocksize (1, 2, 13)
51b39c5158Smillert    {
52b39c5158Smillert        for my $i (0 .. length($compressed) - 1)
53b39c5158Smillert        {
54b39c5158Smillert            for my $useBuf (0 .. 1)
55b39c5158Smillert            {
56b39c5158Smillert                print "#\n# BlockSize $blocksize, Length $i, Buffer $useBuf\n#\n" ;
57*eac174f2Safresh1                my $lex = LexFile->new( my $name );
58b39c5158Smillert
59b39c5158Smillert                my $prime = substr($compressed, 0, $i);
60b39c5158Smillert                my $rest = substr($compressed, $i);
61b39c5158Smillert
62b39c5158Smillert                my $start  ;
63b39c5158Smillert                if ($useBuf) {
64b39c5158Smillert                    $start = \$rest ;
65b39c5158Smillert                }
66b39c5158Smillert                else {
67b39c5158Smillert                    $start = $name ;
68b39c5158Smillert                    writeFile($name, $rest);
69b39c5158Smillert                }
70b39c5158Smillert
71*eac174f2Safresh1                #my $gz = $UncompressClass->can('new')->( $UncompressClass, $name,
72*eac174f2Safresh1                my $gz = $UncompressClass->can('new')->( $UncompressClass, $start,
73b39c5158Smillert                                              -Append      => 1,
74b39c5158Smillert                                              -BlockSize   => $blocksize,
75b39c5158Smillert                                              -Prime       => $prime,
76b39c5158Smillert                                              -Transparent => 0
77*eac174f2Safresh1                                             );
78b39c5158Smillert                ok $gz;
79b39c5158Smillert                ok ! $gz->error() ;
80b39c5158Smillert                my $un ;
81b39c5158Smillert                my $status = 1 ;
82b39c5158Smillert                $status = $gz->read($un) while $status > 0 ;
83b39c5158Smillert                is $status, 0 ;
84b39c5158Smillert                ok ! $gz->error()
85b39c5158Smillert                    or print "Error is '" . $gz->error() . "'\n";
86b39c5158Smillert                is $un, $hello ;
87b39c5158Smillert                ok $gz->eof() ;
88b39c5158Smillert                ok $gz->close() ;
89b39c5158Smillert            }
90b39c5158Smillert        }
91b39c5158Smillert    }
92b39c5158Smillert}
93b39c5158Smillert
94b39c5158Smillert1;
95