4 @INC = ("../lib", "lib/compress");
8 use lib qw(t t/compress);
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 $lex = new LexFile my $name ;
60 ok my $x = gzopen($name, "wb");
63 is $x->gzwrite($hello), $len_hello, "gzwrite returned $len_hello" ;
66 eval { $x->gzsetparams() };
67 like $@, mkErr('^Usage: Compress::Zlib::gzFile::gzsetparams\(file, level, strategy\)');
69 # Change both Level & Strategy
70 $status = $x->gzsetparams(Z_BEST_SPEED, Z_HUFFMAN_ONLY) ;
71 cmp_ok $status, '==', Z_OK, "status is Z_OK";
74 is $x->gzwrite($goodbye), $len_goodbye, "gzwrite returned $len_goodbye" ;
76 ok ! $x->gzclose, "closed" ;
78 ok my $k = gzopen($name, "rb") ;
80 # calling gzsetparams on reading is not allowed.
81 $status = $k->gzsetparams(Z_BEST_SPEED, Z_HUFFMAN_ONLY) ;
82 cmp_ok $status, '==', Z_STREAM_ERROR, "status is Z_STREAM_ERROR" ;
84 my $len = length $input ;
86 is $len, $k->gzread($uncompressed, $len) ;
88 ok $uncompressed eq $input ;
95 foreach my $CompressClass ('IO::Compress::Gzip',
96 'IO::Compress::Deflate',
97 'IO::Compress::RawDeflate',
100 my $UncompressClass = getInverse($CompressClass);
102 title "Testing $CompressClass";
107 my $hello = "I am a HAL 9000 computer" x 2001 ;
108 my $len_hello = length $hello ;
109 my $goodbye = "Will I dream?" x 2010;
110 my $len_goodbye = length $goodbye;
112 #my ($input, $err, $answer, $X, $status, $Answer);
115 ok my $x = new $CompressClass(\$compressed) ;
118 is $x->write($hello), $len_hello ;
120 # Change both Level & Strategy
121 ok $x->deflateParams(Z_BEST_SPEED, Z_HUFFMAN_ONLY);
124 is $x->write($goodbye), $len_goodbye ;
128 ok my $k = new $UncompressClass(\$compressed);
130 my $len = length $input ;
132 is $k->read($uncompressed, $len), $len
133 or diag "$IO::Uncompress::Gunzip::GunzipError" ;
135 ok $uncompressed eq $input ;