proposal [perl #34301]: IO::Socket calls getpeername far too often
[p5sagit/p5-mst-13.2.git] / ext / Compress / Zlib / t / 08encoding.t
CommitLineData
642e522c 1
2use lib 't';
3use strict;
4use warnings;
5use bytes;
6
7use Test::More ;
8use ZlibTestUtils;
9
10BEGIN
11{
12 plan skip_all => "Encode is not available"
13 if $] < 5.006 ;
14
15 eval { require Encode; Encode->import(); };
16
17 plan skip_all => "Encode is not available"
18 if $@ ;
19
20 # use Test::NoWarnings, if available
21 my $extra = 0 ;
22 $extra = 1
23 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
24
25 plan tests => 16 + $extra ;
26
27 use_ok('Compress::Zlib', 2);
28}
29
30
31
32
33# Check zlib_version and ZLIB_VERSION are the same.
34is Compress::Zlib::zlib_version, ZLIB_VERSION,
35 "ZLIB_VERSION matches Compress::Zlib::zlib_version" ;
36
37
38if(0)
39{
40 # length of this string is 2 characters
41 my $s = "\x{df}\x{100}";
42
43 my $cs = Compress::Zlib::memGzip($s);
44
45 # length stored at end of gzip file should be 4
46 my ($crc, $len) = unpack ("VV", substr($cs, -8, 8));
47
48 is $len, 4, "length is 4";
49}
50
51{
52 title "memGzip" ;
53 # length of this string is 2 characters
54 my $s = "\x{df}\x{100}";
55
56 my $cs = Compress::Zlib::memGzip(Encode::encode_utf8($s));
57
58 # length stored at end of gzip file should be 4
59 my ($crc, $len) = unpack ("VV", substr($cs, -8, 8));
60
61 is $len, 4, " length is 4";
62}
63
64{
65 title "compress/uncompress";
66
67 my $s = "\x{df}\x{100}";
68 my $s_copy = $s ;
69
70 #my $cs = compress($s);
71 my $ces = compress(Encode::encode_utf8($s_copy));
72
73 ok $ces, " compressed ok" ;
74
75 #is $s, $ces ;
76
77 #my $un = uncompress($cs);
78 #is $un, $s;
79
80 my $un = Encode::decode_utf8(uncompress($ces));
81 #my $un = uncompress($ces);
82 is $un, $s, " decode_utf8 ok";
83
84 #$un = Encode::decode_utf8(uncompress($cs));
85 #is $un, $s;
86
87}
88
89{
90 title "gzopen" ;
91
92 my $name = "test.gz" ;
93 my $s = "\x{df}\x{100}";
94 my $byte_len = length( Encode::encode_utf8($s) );
95 my ($uncomp) ;
96
97 ok my $fil = gzopen($name, "wb"), " gzopen for write ok" ;
98
99 is $fil->gzwrite(Encode::encode_utf8($s)), $byte_len, " wrote $byte_len bytes" ;
100
101 ok ! $fil->gzclose, " gzclose ok" ;
102
103 ok $fil = gzopen($name, "rb"), " gzopen for read ok" ;
104
105 is $fil->gzread($uncomp), $byte_len, " read $byte_len bytes" ;
106 is length($uncomp), $byte_len, " uncompress is $byte_len bytes";
107
108 ok ! $fil->gzclose, "gzclose ok" ;
109
110 unlink $name ;
111
112 is $s, Encode::decode_utf8($uncomp), " decode_utf8 ok" ;
113
114}
115
116# Add tests that check that the module traps use of wide chars
117