Fix $Config{ccflags} for Win32 perls built with dmake
[p5sagit/p5-mst-13.2.git] / ext / Compress / Zlib / t / 04encoding.t
1
2 use strict ;
3 use warnings ;
4
5 BEGIN 
6 {
7
8     eval { require Encode; Encode->import(); };
9     
10     if ($@) {
11         print "1..0 #  Skip: Encode is not available\n";
12         #exit 0;
13         $::bomb_out = 1;
14     }
15 }
16
17 exit 0 if $::bomb_out ;
18
19 use Compress::Zlib ;
20 #use Encode;
21
22 sub ok
23 {
24     my ($no, $ok) = @_ ;
25
26     #++ $total ;
27     #++ $totalBad unless $ok ;
28
29     print "ok $no\n" if $ok ;
30     print "not ok $no\n" unless $ok ;
31 }
32
33 sub readFile
34 {
35     my ($filename) = @_ ;
36     my ($string) = '' ;
37  
38     open (F, "<$filename")
39         or die "Cannot open $filename: $!\n" ;
40     binmode(F);
41     while (<F>)
42       { $string .= $_ }
43     close F ;
44     $string ;
45 }     
46
47 print "1..15\n" ;
48
49 # Check zlib_version and ZLIB_VERSION are the same.
50 ok(1, Compress::Zlib::zlib_version eq ZLIB_VERSION) ;
51
52
53 {
54     # length of this string is 2 characters
55     my $s = "\x{df}\x{100}"; 
56
57     my $cs = Compress::Zlib::memGzip($s); 
58
59     # length stored at end of gzip file should be 4
60     my ($crc, $len) = unpack ("VV", substr($cs, -8, 8));
61     
62     ok(2, $len == 4);
63 }
64
65 {
66     # length of this string is 2 characters
67     my $s = "\x{df}\x{100}"; 
68
69     my $cs = Compress::Zlib::memGzip(Encode::encode_utf8($s));
70
71     # length stored at end of gzip file should be 4
72     my ($crc, $len) = unpack ("VV", substr($cs, -8, 8));
73     
74     ok(3, $len == 4);
75 }
76
77 {
78     my $s = "\x{df}\x{100}";                                   
79     my $s_copy = $s ;
80
81     my $cs = compress($s);                      
82     my $ces = compress(Encode::encode_utf8($s_copy));
83
84     ok(4, $cs eq $ces);
85
86     my $un = uncompress($cs);
87     ok(5, $un ne $s);
88  
89     $un = uncompress($ces);
90     ok(6, $un ne $s);
91  
92     $un = Encode::decode_utf8(uncompress($cs));
93     ok(7, $un eq $s);
94
95 }
96
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(8, my $fil = gzopen($name, "wb")) ;
104
105     ok(9, $fil->gzwrite($s) == $byte_len) ;
106
107     ok(10, ! $fil->gzclose ) ;
108
109     ok(11, $fil = gzopen($name, "rb") ) ;
110
111     ok(12, $fil->gzread($uncomp) == $byte_len) ;
112     ok(13, length($uncomp) == $byte_len);
113
114     ok(14, ! $fil->gzclose ) ;
115
116     unlink $name ;
117
118     ok(15, $s eq Encode::decode_utf8($uncomp)) ;
119
120 }