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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
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 Test::More ;
use CompTestUtils;
use IO::Uncompress::Unzip 'unzip' ;
BEGIN
{
plan(skip_all => "Needs Perl 5.005 or better - you have Perl $]" )
if $] < 5.005 ;
# use Test::NoWarnings, if available
my $extra = 0 ;
$extra = 1
if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
plan tests => 136 + $extra ;
}
my $Inc = join " ", map qq["-I$_"] => @INC;
$Inc = '"-MExtUtils::testlib"'
if ! $ENV{PERL_CORE} && eval " require ExtUtils::testlib; " ;
my $Perl = ($ENV{'FULLPERL'} or $^X or 'perl') ;
$Perl = qq["$Perl"] if $^O eq 'MSWin32' ;
$Perl = "$Perl $Inc -w" ;
#$Perl .= " -Mblib " ;
my $binDir = $ENV{PERL_CORE} ? "../ext/IO-Compress/bin/"
: "./bin/";
my $hello1 = <<EOM ;
hello
this is
a test
message
x ttttt
xuuuuuu
the end
EOM
my $lex = LexFile->new( my $stderr );
sub check
{
my $command = shift ;
my $expected = shift ;
my $lex = LexFile->new( my $stderr );
my $cmd = "$command 2>$stderr";
my $stdout = `$cmd` ;
my $aok = 1 ;
$aok &= is $?, 0, " exit status is 0" ;
$aok &= is readFile($stderr), '', " no stderr" ;
$aok &= is $stdout, $expected, " expected content is ok"
if defined $expected ;
if (! $aok) {
diag "Command line: $cmd";
my ($file, $line) = (caller)[1,2];
diag "Test called from $file, line $line";
}
1 while unlink $stderr;
}
# streamzip
# #########
{
title "streamzip" ;
my ($infile, $outfile);
my $lex = LexFile->new( $infile, $outfile );
writeFile($infile, $hello1) ;
check "$Perl ${binDir}/streamzip <$infile >$outfile";
my $uncompressed ;
unzip $outfile => \$uncompressed;
is $uncompressed, $hello1;
}
{
title "streamzip - zipfile option" ;
my ($infile, $outfile);
my $lex = LexFile->new( $infile, $outfile );
writeFile($infile, $hello1) ;
check "$Perl ${binDir}/streamzip -zipfile $outfile <$infile";
my $uncompressed ;
unzip $outfile => \$uncompressed;
is $uncompressed, $hello1;
}
for my $method (qw(store deflate bzip2 lzma xz zstd))
{
SKIP:
{
if ($method eq 'lzma')
{
no warnings;
eval { require IO::Compress::Lzma && defined &{ 'IO::Compress::Adapter::Bzip2::mkRawZipCompObject' } } ;
skip "Method 'lzma' needs IO::Compress::Lzma\n", 8
if $@;
}
if ($method eq 'zstd')
{
no warnings;
eval { require IO::Compress::Zstd && defined &{ 'IO::Compress::Adapter::Zstd::mkRawZipCompObject' }} ;
skip "Method 'zstd' needs IO::Compress::Zstd\n", 8
if $@;
}
if ($method eq 'xz')
{
no warnings;
eval { require IO::Compress::Xz && defined &{ 'IO::Compress::Adapter::Xz::mkRawZipCompObject' }} ;
skip "Method 'xz' needs IO::Compress::Xz\n", 8
if $@;
}
{
title "streamzip method $method" ;
skip "streaming unzip not supported with zstd\n", 7
if $method eq 'zstd' ;
my ($infile, $outfile);
my $lex = LexFile->new( $infile, $outfile );
writeFile($infile, $hello1) ;
check "$Perl ${binDir}/streamzip -method $method <$infile >$outfile";
my $uncompressed ;
unzip $outfile => \$uncompressed;
is $uncompressed, $hello1;
}
{
title "streamzip $method- zipfile option" ;
my ($infile, $outfile);
my $lex = LexFile->new( $infile, $outfile );
writeFile($infile, $hello1) ;
check "$Perl ${binDir}/streamzip -zipfile $outfile -method $method <$infile";
my $uncompressed ;
unzip $outfile => \$uncompressed;
is $uncompressed, $hello1;
}
}
}
for my $level (0 ..9)
{
{
title "streamzip level $level" ;
my ($infile, $outfile);
my $lex = LexFile->new( $infile, $outfile );
writeFile($infile, $hello1) ;
check "$Perl ${binDir}/streamzip -$level <$infile >$outfile";
my $uncompressed ;
unzip $outfile => \$uncompressed;
is $uncompressed, $hello1;
}
{
title "streamzip level $level- zipfile option" ;
my ($infile, $outfile);
my $lex = LexFile->new( $infile, $outfile );
writeFile($infile, $hello1) ;
check "$Perl ${binDir}/streamzip -zipfile $outfile -$level <$infile";
my $uncompressed ;
unzip $outfile => \$uncompressed;
is $uncompressed, $hello1;
}
}
|