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