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
|
BEGIN {
if ($ENV{PERL_CORE}) {
chdir 't' if -d 't';
@INC = ("../lib", "lib/compress");
}
}
use lib qw(t t/compress);
use strict;
use warnings;
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 => 38 + $extra ;
use_ok('Compress::Raw::Zlib', 2) ;
}
my $hello = <<EOM ;
hello world
this is a test
EOM
my $len = length $hello ;
# Check zlib_version and ZLIB_VERSION are the same.
SKIP: {
skip "TEST_SKIP_VERSION_CHECK is set", 1
if $ENV{TEST_SKIP_VERSION_CHECK};
is Compress::Raw::Zlib::zlib_version, ZLIB_VERSION,
"ZLIB_VERSION matches Compress::Raw::Zlib::zlib_version" ;
}
{
title 'non-PV dictionary';
# ==============================
my $dictionary = *hello ;
ok my $x = new Compress::Raw::Zlib::Deflate({-Level => Z_BEST_COMPRESSION,
-Dictionary => $dictionary}) ;
my $dictID = $x->dict_adler() ;
my ($X, $Y, $Z);
cmp_ok $x->deflate($hello, $X), '==', Z_OK;
cmp_ok $x->flush($Y), '==', Z_OK;
$X .= $Y ;
ok my $k = new Compress::Raw::Zlib::Inflate(-Dictionary => $dictionary) ;
cmp_ok $k->inflate($X, $Z), '==', Z_STREAM_END;
is $k->dict_adler(), $dictID;
is $hello, $Z ;
}
{
title "deflate/inflate - non-PV buffers";
# ==============================
my $hello = *hello ;
my ($err, $x, $X, $status);
ok( ($x, $err) = new Compress::Raw::Zlib::Deflate, "Create deflate object" );
ok $x, "Compress::Raw::Zlib::Deflate ok" ;
cmp_ok $err, '==', Z_OK, "status is Z_OK" ;
ok ! defined $x->msg() ;
is $x->total_in(), 0, "total_in() == 0" ;
is $x->total_out(), 0, "total_out() == 0" ;
$X = *X;
my $Answer = '';
$status = $x->deflate($hello, $X) ;
$Answer .= $X ;
cmp_ok $status, '==', Z_OK, "deflate returned Z_OK" ;
$X = *X;
cmp_ok $x->flush($X), '==', Z_OK, "flush returned Z_OK" ;
$Answer .= $X ;
ok ! defined $x->msg() ;
is $x->total_in(), length $hello, "total_in ok" ;
is $x->total_out(), length $Answer, "total_out ok" ;
my $k;
ok(($k, $err) = new Compress::Raw::Zlib::Inflate);
ok $k, "Compress::Raw::Zlib::Inflate ok" ;
cmp_ok $err, '==', Z_OK, "status is Z_OK" ;
ok ! defined $k->msg(), "No error messages" ;
is $k->total_in(), 0, "total_in() == 0" ;
is $k->total_out(), 0, "total_out() == 0" ;
my $GOT = '';
my $Z;
$Z = *Z;
my $Alen = length $Answer;
$status = $k->inflate($Answer, $Z) ;
$GOT .= $Z ;
cmp_ok $status, '==', Z_STREAM_END, "Got Z_STREAM_END" ;
is $GOT, $hello, "uncompressed data matches ok" ;
ok ! defined $k->msg(), "No error messages" ;
is $k->total_in(), $Alen, "total_in ok" ;
is $k->total_out(), length $hello , "total_out ok";
ok(($k, $err) = new Compress::Raw::Zlib::Inflate);
ok $k, "Compress::Raw::Zlib::Inflate ok" ;
cmp_ok $err, '==', Z_OK, "status is Z_OK" ;
$Z = *Z;
$status = $k->inflate($hello, $Z);
is $Z, "", 'inflating *hello does not crash';
$hello = *hello;
$status = $k->inflateSync($hello);
cmp_ok $status, "!=", Z_OK,
"inflateSync on *hello returns error (and does not crash)";
}
|