10 use Compress::Zlib 2 ;
12 use IO::Compress::Gzip ;
13 use IO::Uncompress::Gunzip ;
15 use IO::Compress::Deflate ;
16 use IO::Uncompress::Inflate ;
18 use IO::Compress::RawDeflate ;
19 use IO::Uncompress::RawInflate ;
26 # use Test::NoWarnings, if available
29 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
32 my $ver = Compress::Zlib::zlib_version();
33 plan skip_all => "gzsetparams needs zlib 1.0.6 or better. You have $ver\n"
34 if ZLIB_VERNUM() < 0x1060 ;
36 plan tests => 51 + $extra ;
38 # Check zlib_version and ZLIB_VERSION are the same.
39 is Compress::Zlib::zlib_version, ZLIB_VERSION,
40 "ZLIB_VERSION matches Compress::Zlib::zlib_version" ;
44 title "Testing gzsetparams";
46 my $hello = "I am a HAL 9000 computer" x 2001 ;
47 my $len_hello = length $hello ;
48 my $goodbye = "Will I dream?" x 2010;
49 my $len_goodbye = length $goodbye;
51 my ($input, $err, $answer, $X, $status, $Answer);
53 my $name = "test.gz" ;
55 ok my $x = gzopen($name, "wb");
58 is $x->gzwrite($hello), $len_hello, "gzwrite returned $len_hello" ;
61 eval { $x->gzsetparams() };
62 like $@, mkErr('^Usage: Compress::Zlib::gzFile::gzsetparams\(file, level, strategy\)');
64 # Change both Level & Strategy
65 $status = $x->gzsetparams(Z_BEST_SPEED, Z_HUFFMAN_ONLY) ;
66 cmp_ok $status, '==', Z_OK, "status is Z_OK";
69 is $x->gzwrite($goodbye), $len_goodbye, "gzwrite returned $len_goodbye" ;
71 ok ! $x->gzclose, "closed" ;
73 ok my $k = gzopen($name, "rb") ;
75 # calling gzsetparams on reading is not allowed.
76 $status = $k->gzsetparams(Z_BEST_SPEED, Z_HUFFMAN_ONLY) ;
77 cmp_ok $status, '==', Z_STREAM_ERROR, "status is Z_STREAM_ERROR" ;
79 my $len = length $input ;
81 is $len, $k->gzread($uncompressed, $len) ;
83 ok $uncompressed eq $input ;
91 foreach my $CompressClass ('IO::Compress::Gzip',
92 'IO::Compress::Deflate',
93 'IO::Compress::RawDeflate',
96 my $UncompressClass = getInverse($CompressClass);
98 title "Testing $CompressClass";
103 my $hello = "I am a HAL 9000 computer" x 2001 ;
104 my $len_hello = length $hello ;
105 my $goodbye = "Will I dream?" x 2010;
106 my $len_goodbye = length $goodbye;
108 #my ($input, $err, $answer, $X, $status, $Answer);
111 ok my $x = new $CompressClass(\$compressed) ;
114 is $x->write($hello), $len_hello ;
116 # Change both Level & Strategy
117 ok $x->deflateParams(Z_BEST_SPEED, Z_HUFFMAN_ONLY);
120 is $x->write($goodbye), $len_goodbye ;
124 ok my $k = new $UncompressClass(\$compressed);
126 my $len = length $input ;
128 is $k->read($uncompressed, $len), $len
129 or diag "$IO::Uncompress::Gunzip::GunzipError" ;
131 ok $uncompressed eq $input ;