4 @INC = ("../lib", "lib/compress");
8 use lib qw(t t/compress);
17 # use Test::NoWarnings, if available
20 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
22 plan tests => 62 + $extra ;
24 use_ok('IO::Compress::Zip', qw(:all)) ;
25 use_ok('IO::Uncompress::Unzip', qw(unzip $UnzipError)) ;
28 require IO::Compress::Bzip2 ;
29 import IO::Compress::Bzip2 2.010 ;
30 require IO::Uncompress::Bunzip2 ;
31 import IO::Uncompress::Bunzip2 2.010 ;
41 my $u = new IO::Uncompress::Unzip $filename, Append => 1
42 or die "Cannot open $filename: $UnzipError";
44 isa_ok $u, "IO::Uncompress::Unzip";
49 for ($status = 1; ! $u->eof(); $status = $u->nextStream())
52 my $name = $u->getHeaderInfo()->{Name};
53 #warn "Processing member $name\n" ;
56 1 while ($status = $u->read($buff)) > 0;
59 last unless $status == 0;
62 die "Error processing $filename: $status $!\n"
70 title "Create a simple zip - All Deflate";
72 my $lex = new LexFile my $file1;
80 my $zip = new IO::Compress::Zip $file1,
81 Name => "one", Method => ZIP_CM_DEFLATE, Stream => 0;
82 isa_ok $zip, "IO::Compress::Zip";
84 is $zip->write($content[0]), length($content[0]), "write";
85 $zip->newStream(Name=> "two", Method => ZIP_CM_DEFLATE);
86 is $zip->write($content[1]), length($content[1]), "write";
87 $zip->newStream(Name=> "three", Method => ZIP_CM_DEFLATE);
88 is $zip->write($content[2]), length($content[2]), "write";
89 ok $zip->close(), "closed";
91 my @got = getContent($file1);
93 is $got[0], $content[0], "Got 1st entry";
94 is $got[1], $content[1], "Got 2nd entry";
95 is $got[2], $content[2], "Got 3nd entry";
100 title "Create a simple zip - All Bzip2";
102 skip "IO::Compress::Bzip2 not available", 9
103 unless defined $IO::Compress::Bzip2::VERSION;
105 my $lex = new LexFile my $file1;
113 my $zip = new IO::Compress::Zip $file1,
114 Name => "one", Method => ZIP_CM_BZIP2, Stream => 0;
115 isa_ok $zip, "IO::Compress::Zip";
117 is $zip->write($content[0]), length($content[0]), "write";
118 $zip->newStream(Name=> "two", Method => ZIP_CM_BZIP2);
119 is $zip->write($content[1]), length($content[1]), "write";
120 $zip->newStream(Name=> "three", Method => ZIP_CM_BZIP2);
121 is $zip->write($content[2]), length($content[2]), "write";
122 ok $zip->close(), "closed";
124 my @got = getContent($file1);
126 is $got[0], $content[0], "Got 1st entry";
127 is $got[1], $content[1], "Got 2nd entry";
128 is $got[2], $content[2], "Got 3nd entry";
133 title "Create a simple zip - Deflate + Bzip2";
135 skip "IO::Compress::Bzip2 not available", 9
136 unless $IO::Compress::Bzip2::VERSION;
138 my $lex = new LexFile my $file1;
146 my $zip = new IO::Compress::Zip $file1,
147 Name => "one", Method => ZIP_CM_DEFLATE, Stream => 0;
148 isa_ok $zip, "IO::Compress::Zip";
150 is $zip->write($content[0]), length($content[0]), "write";
151 $zip->newStream(Name=> "two", Method => ZIP_CM_BZIP2);
152 is $zip->write($content[1]), length($content[1]), "write";
153 $zip->newStream(Name=> "three", Method => ZIP_CM_DEFLATE);
154 is $zip->write($content[2]), length($content[2]), "write";
155 ok $zip->close(), "closed";
157 my @got = getContent($file1);
159 is $got[0], $content[0], "Got 1st entry";
160 is $got[1], $content[1], "Got 2nd entry";
161 is $got[2], $content[2], "Got 3nd entry";
165 title "Create a simple zip - All STORE";
167 my $lex = new LexFile my $file1;
175 my $zip = new IO::Compress::Zip $file1,
176 Name => "one", Method => ZIP_CM_STORE, Stream => 0;
177 isa_ok $zip, "IO::Compress::Zip";
179 is $zip->write($content[0]), length($content[0]), "write";
180 $zip->newStream(Name=> "two", Method => ZIP_CM_STORE);
181 is $zip->write($content[1]), length($content[1]), "write";
182 $zip->newStream(Name=> "three", Method => ZIP_CM_STORE);
183 is $zip->write($content[2]), length($content[2]), "write";
184 ok $zip->close(), "closed";
186 my @got = getContent($file1);
188 is $got[0], $content[0], "Got 1st entry";
189 is $got[1], $content[1], "Got 2nd entry";
190 is $got[2], $content[2], "Got 3nd entry";
194 title "Create a simple zip - Deflate + STORE";
196 my $lex = new LexFile my $file1;
204 my $zip = new IO::Compress::Zip $file1,
205 Name => "one", Method => ZIP_CM_DEFLATE, Stream => 0;
206 isa_ok $zip, "IO::Compress::Zip";
208 is $zip->write($content[0]), length($content[0]), "write";
209 $zip->newStream(Name=> "two", Method => ZIP_CM_STORE);
210 is $zip->write($content[1]), length($content[1]), "write";
211 $zip->newStream(Name=> "three", Method => ZIP_CM_DEFLATE);
212 is $zip->write($content[2]), length($content[2]), "write";
213 ok $zip->close(), "closed";
215 my @got = getContent($file1);
217 is $got[0], $content[0], "Got 1st entry";
218 is $got[1], $content[1], "Got 2nd entry";
219 is $got[2], $content[2], "Got 3nd entry";
223 title "Create a simple zip - Deflate + zero length STORE";
225 my $lex = new LexFile my $file1;
233 my $zip = new IO::Compress::Zip $file1,
234 Name => "one", Method => ZIP_CM_DEFLATE, Stream => 0;
235 isa_ok $zip, "IO::Compress::Zip";
237 is $zip->write($content[0]), length($content[0]), "write";
238 $zip->newStream(Name=> "two", Method => ZIP_CM_STORE);
239 is $zip->write($content[1]), length($content[1]), "write";
240 $zip->newStream(Name=> "three", Method => ZIP_CM_DEFLATE);
241 is $zip->write($content[2]), length($content[2]), "write";
242 ok $zip->close(), "closed";
244 my @got = getContent($file1);
246 is $got[0], $content[0], "Got 1st entry";
247 ok $got[1] eq $content[1], "Got 2nd entry";
248 is $got[2], $content[2], "Got 3nd entry";