1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
BEGIN {
if ($ENV{PERL_CORE}) {
chdir 't' if -d 't';
@INC = ("../lib", "lib/compress");
}
}
use lib qw(t t/compress);
use strict;
use warnings;
use bytes;
use File::Spec ;
use Test::More ;
use CompTestUtils;
my $GZIP ;
sub ExternalGzipWorks
{
my $lex = new LexFile my $outfile;
my $content = qq {
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut tempus odio id
dolor. Camelus perlus. Larrius in lumen numen. Dolor en quiquum filia
est. Quintus cenum parat.
};
writeWithGzip($outfile, $content)
or return 0;
my $got ;
readWithGzip($outfile, $got)
or return 0;
if ($content ne $got)
{
diag "Uncompressed content is wrong";
return 0 ;
}
return 1 ;
}
sub readWithGzip
{
my $file = shift ;
my $lex = new LexFile my $outfile;
my $comp = "$GZIP -dc" ;
if ( system("$comp $file >$outfile") == 0 )
{
$_[0] = readFile($outfile);
return 1
}
diag "'$comp' failed: $?";
return 0 ;
}
sub getGzipInfo
{
my $file = shift ;
}
sub writeWithGzip
{
my $file = shift ;
my $content = shift ;
my $options = shift || '';
my $lex = new LexFile my $infile;
writeFile($infile, $content);
unlink $file ;
my $comp = "$GZIP -c $options $infile >$file" ;
return 1
if system($comp) == 0 ;
diag "'$comp' failed: $?";
return 0 ;
}
BEGIN {
# Check external gzip is available
my $name = $^O =~ /mswin/i ? 'gzip.exe' : 'gzip';
my $split = $^O =~ /mswin/i ? ";" : ":";
for my $dir (reverse split $split, $ENV{PATH})
{
$GZIP = File::Spec->catfile($dir,$name)
if -x File::Spec->catfile($dir,$name)
}
# Handle spaces in path to gzip
$GZIP = "\"$GZIP\"" if $GZIP =~ /\s/;
plan(skip_all => "Cannot find $name")
if ! $GZIP ;
plan(skip_all => "$name doesn't work as expected")
if ! ExternalGzipWorks();
# use Test::NoWarnings, if available
my $extra = 0 ;
$extra = 1
if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
plan tests => 7 + $extra ;
use_ok('IO::Compress::Gzip', ':all') ;
use_ok('IO::Uncompress::Gunzip', ':all') ;
}
{
title "Test interop with $GZIP" ;
my $file;
my $file1;
my $lex = new LexFile $file, $file1;
my $content = qq {
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut tempus odio id
dolor. Camelus perlus. Larrius in lumen numen. Dolor en quiquum filia
est. Quintus cenum parat.
};
my $got;
ok writeWithGzip($file, $content), "writeWithGzip ok";
gunzip $file => \$got ;
is $got, $content, "got content";
gzip \$content => $file1;
$got = '';
ok readWithGzip($file1, $got), "readWithGzip ok";
is $got, $content, "got content";
}
|