Commit | Line | Data |
16816334 |
1 | BEGIN { |
d695c1a1 |
2 | if ($ENV{PERL_CORE}) { |
16816334 |
3 | chdir 't' if -d 't'; |
1a6a8453 |
4 | @INC = ("../lib", "lib/compress"); |
16816334 |
5 | } |
6 | } |
642e522c |
7 | |
8 | use lib 't'; |
9 | use strict; |
10 | use warnings; |
11 | use bytes; |
12 | |
13 | use Test::More ; |
14 | use ZlibTestUtils; |
15 | |
16 | BEGIN |
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. |
40 | is Compress::Zlib::zlib_version, ZLIB_VERSION, |
41 | "ZLIB_VERSION matches Compress::Zlib::zlib_version" ; |
42 | |
43 | |
44 | if(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 | |
642e522c |
98 | my $s = "\x{df}\x{100}"; |
99 | my $byte_len = length( Encode::encode_utf8($s) ); |
100 | my ($uncomp) ; |
101 | |
9f2e3514 |
102 | my $lex = new LexFile my $name ; |
642e522c |
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 | |
642e522c |
116 | is $s, Encode::decode_utf8($uncomp), " decode_utf8 ok" ; |
642e522c |
117 | } |
118 | |
119 | # Add tests that check that the module traps use of wide chars |
120 | |