4 @INC = ("../lib", "lib/compress");
8 use lib qw(t t/compress);
18 plan skip_all => "Encode is not available"
21 eval { require Encode; Encode->import(); };
23 plan skip_all => "Encode is not available"
26 # use Test::NoWarnings, if available
29 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
31 plan tests => 29 + $extra ;
33 use_ok('Compress::Zlib', 2);
39 # Check zlib_version and ZLIB_VERSION are the same.
40 is Compress::Zlib::zlib_version, ZLIB_VERSION,
41 "ZLIB_VERSION matches Compress::Zlib::zlib_version" ;
46 # length of this string is 2 characters
47 my $s = "\x{df}\x{100}";
49 my $cs = Compress::Zlib::memGzip(Encode::encode_utf8($s));
51 # length stored at end of gzip file should be 4
52 my ($crc, $len) = unpack ("VV", substr($cs, -8, 8));
54 is $len, 4, " length is 4";
58 title "memGunzip when compressed gzip has been encoded" ;
59 my $s = "hello world" ;
61 my $co = Compress::Zlib::memGzip($s);
62 is Compress::Zlib::memGunzip(my $x = $co), $s, " match uncompressed";
66 my $un = Compress::Zlib::memGunzip($co);
67 ok $un, " got uncompressed";
69 is $un, $s, " uncompressed matched original";
73 title "compress/uncompress";
75 my $s = "\x{df}\x{100}";
78 my $ces = compress(Encode::encode_utf8($s_copy));
80 ok $ces, " compressed ok" ;
82 my $un = Encode::decode_utf8(uncompress($ces));
83 is $un, $s, " decode_utf8 ok";
86 $un = Encode::decode_utf8(uncompress($ces));
87 is $un, $s, " decode_utf8 ok";
94 my $s = "\x{df}\x{100}";
95 my $byte_len = length( Encode::encode_utf8($s) );
98 my $lex = new LexFile my $name ;
99 ok my $fil = gzopen($name, "wb"), " gzopen for write ok" ;
101 is $fil->gzwrite(Encode::encode_utf8($s)), $byte_len, " wrote $byte_len bytes" ;
103 ok ! $fil->gzclose, " gzclose ok" ;
105 ok $fil = gzopen($name, "rb"), " gzopen for read ok" ;
107 is $fil->gzread($uncomp), $byte_len, " read $byte_len bytes" ;
108 is length($uncomp), $byte_len, " uncompress is $byte_len bytes";
110 ok ! $fil->gzclose, "gzclose ok" ;
112 is $s, Encode::decode_utf8($uncomp), " decode_utf8 ok" ;
116 title "Catch wide characters";
118 my $a = "a\xFF\x{100}";
119 eval { Compress::Zlib::memGzip($a) };
120 like($@, qr/Wide character in memGzip/, " wide characters in memGzip");
122 eval { Compress::Zlib::memGunzip($a) };
123 like($@, qr/Wide character in memGunzip/, " wide characters in memGunzip");
125 eval { Compress::Zlib::compress($a) };
126 like($@, qr/Wide character in compress/, " wide characters in compress");
128 eval { Compress::Zlib::uncompress($a) };
129 like($@, qr/Wide character in uncompress/, " wide characters in uncompress");
131 my $lex = new LexFile my $name ;
132 ok my $fil = gzopen($name, "wb"), " gzopen for write ok" ;
134 eval { $fil->gzwrite($a); } ;
135 like($@, qr/Wide character in gzwrite/, " wide characters in gzwrite");
137 ok ! $fil->gzclose, " gzclose ok" ;