16 use Compress::Zlib 2 ;
18 use IO::Compress::Gzip ;
19 use IO::Uncompress::Gunzip ;
21 use IO::Compress::Deflate ;
22 use IO::Uncompress::Inflate ;
24 use IO::Compress::RawDeflate ;
25 use IO::Uncompress::RawInflate ;
32 # use Test::NoWarnings, if available
35 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
38 my $ver = Compress::Zlib::zlib_version();
39 plan skip_all => "gzsetparams needs zlib 1.0.6 or better. You have $ver\n"
40 if ZLIB_VERNUM() < 0x1060 ;
42 plan tests => 51 + $extra ;
44 # Check zlib_version and ZLIB_VERSION are the same.
45 is Compress::Zlib::zlib_version, ZLIB_VERSION,
46 "ZLIB_VERSION matches Compress::Zlib::zlib_version" ;
50 title "Testing gzsetparams";
52 my $hello = "I am a HAL 9000 computer" x 2001 ;
53 my $len_hello = length $hello ;
54 my $goodbye = "Will I dream?" x 2010;
55 my $len_goodbye = length $goodbye;
57 my ($input, $err, $answer, $X, $status, $Answer);
59 my $name = "test.gz" ;
61 ok my $x = gzopen($name, "wb");
64 is $x->gzwrite($hello), $len_hello, "gzwrite returned $len_hello" ;
67 eval { $x->gzsetparams() };
68 like $@, mkErr('^Usage: Compress::Zlib::gzFile::gzsetparams\(file, level, strategy\)');
70 # Change both Level & Strategy
71 $status = $x->gzsetparams(Z_BEST_SPEED, Z_HUFFMAN_ONLY) ;
72 cmp_ok $status, '==', Z_OK, "status is Z_OK";
75 is $x->gzwrite($goodbye), $len_goodbye, "gzwrite returned $len_goodbye" ;
77 ok ! $x->gzclose, "closed" ;
79 ok my $k = gzopen($name, "rb") ;
81 # calling gzsetparams on reading is not allowed.
82 $status = $k->gzsetparams(Z_BEST_SPEED, Z_HUFFMAN_ONLY) ;
83 cmp_ok $status, '==', Z_STREAM_ERROR, "status is Z_STREAM_ERROR" ;
85 my $len = length $input ;
87 is $len, $k->gzread($uncompressed, $len) ;
89 ok $uncompressed eq $input ;
97 foreach my $CompressClass ('IO::Compress::Gzip',
98 'IO::Compress::Deflate',
99 'IO::Compress::RawDeflate',
102 my $UncompressClass = getInverse($CompressClass);
104 title "Testing $CompressClass";
109 my $hello = "I am a HAL 9000 computer" x 2001 ;
110 my $len_hello = length $hello ;
111 my $goodbye = "Will I dream?" x 2010;
112 my $len_goodbye = length $goodbye;
114 #my ($input, $err, $answer, $X, $status, $Answer);
117 ok my $x = new $CompressClass(\$compressed) ;
120 is $x->write($hello), $len_hello ;
122 # Change both Level & Strategy
123 ok $x->deflateParams(Z_BEST_SPEED, Z_HUFFMAN_ONLY);
126 is $x->write($goodbye), $len_goodbye ;
130 ok my $k = new $UncompressClass(\$compressed);
132 my $len = length $input ;
134 is $k->read($uncompressed, $len), $len
135 or diag "$IO::Uncompress::Gunzip::GunzipError" ;
137 ok $uncompressed eq $input ;