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
|
BEGIN {
if ($ENV{PERL_CORE}) {
chdir 't' if -d 't';
@INC = ("../lib", "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 => 10612 + $extra ;
use_ok('Compress::Zlib', 2) ;
use_ok('IO::Compress::Gzip', qw($GzipError)) ;
use_ok('IO::Uncompress::Gunzip', qw($GunzipError)) ;
use_ok('IO::Compress::Deflate', qw($DeflateError)) ;
use_ok('IO::Uncompress::Inflate', qw($InflateError)) ;
use_ok('IO::Compress::RawDeflate', qw($RawDeflateError)) ;
use_ok('IO::Uncompress::RawInflate', qw($RawInflateError)) ;
}
my $hello = <<EOM ;
hello world
this is a test
some more stuff on this line
ad finally...
EOM
foreach my $CompressClass ('IO::Compress::Gzip',
'IO::Compress::Deflate',
'IO::Compress::RawDeflate',
)
{
my $UncompressClass = getInverse($CompressClass);
print "#\n# Testing $UncompressClass\n#\n";
my $compressed ;
my $cc ;
my $gz ;
my $hsize ;
if ($CompressClass eq 'IO::Compress::Gzip') {
ok( my $x = new IO::Compress::Gzip \$compressed,
-Name => "My name",
-Comment => "this is a comment",
-ExtraField => [ 'ab' => "extra"],
-HeaderCRC => 1);
ok $x->write($hello) ;
ok $x->close ;
$cc = $compressed ;
#hexDump($compressed) ;
ok($gz = new IO::Uncompress::Gunzip \$cc,
#-Strict => 1,
-Transparent => 0)
or print "$GunzipError\n";
my $un;
ok $gz->read($un) > 0 ;
ok $gz->close();
ok $un eq $hello ;
}
else {
ok( my $x = new $CompressClass(\$compressed));
ok $x->write($hello) ;
ok $x->close ;
$cc = $compressed ;
ok($gz = new $UncompressClass(\$cc,
-Transparent => 0))
or print "$GunzipError\n";
my $un;
ok $gz->read($un) > 0 ;
ok $gz->close();
ok $un eq $hello ;
}
for my $blocksize (1,2,13)
{
for my $i (0 .. length($compressed) - 1)
{
for my $useBuf (0 .. 1)
{
print "#\n# BlockSize $blocksize, Length $i, Buffer $useBuf\n#\n" ;
my $name = "test.gz" ;
unlink $name ;
my $lex = new LexFile $name ;
my $prime = substr($compressed, 0, $i);
my $rest = substr($compressed, $i);
my $start ;
if ($useBuf) {
$start = \$rest ;
}
else {
$start = $name ;
writeFile($name, $rest);
}
#my $gz = new $UncompressClass $name,
my $gz = new $UncompressClass $start,
-Append => 1,
-BlockSize => $blocksize,
-Prime => $prime,
-Transparent => 0
;
ok $gz;
ok ! $gz->error() ;
my $un ;
my $status = 1 ;
$status = $gz->read($un) while $status > 0 ;
ok $status == 0
or print "status $status\n" ;
ok ! $gz->error()
or print "Error is '" . $gz->error() . "'\n";
ok $un eq $hello
or print "# got [$un]\n";
ok $gz->eof() ;
ok $gz->close() ;
}
}
}
}
|