4 @INC = ("../lib", "lib/compress");
8 use lib qw(t t/compress);
17 plan(skip_all => "oneshot needs Perl 5.005 or better - you have Perl $]" )
20 plan(skip_all => "IO::Compress::Bzip2 not available" )
21 unless eval { require IO::Compress::Bzip2;
22 require IO::Uncompress::Bunzip2;
26 # use Test::NoWarnings, if available
29 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
31 plan tests => 120 + $extra ;
33 #use_ok('IO::Compress::Zip', qw(zip $ZipError :zip_method)) ;
34 use_ok('IO::Compress::Zip', qw(:all)) ;
35 use_ok('IO::Uncompress::Unzip', qw(unzip $UnzipError)) ;
50 ok zip($in, \$out, %opts), " zip ok" ;
51 ok unzip(\$out, \$got), " unzip ok"
53 is $got, $content, " got expected content" ;
55 my $gunz = new IO::Uncompress::Unzip \$out, Strict => 0
56 or diag "UnzipError is $IO::Uncompress::Unzip::UnzipError" ;
57 ok $gunz, " Created IO::Uncompress::Unzip object";
58 my $hdr = $gunz->getHeaderInfo();
59 ok $hdr, " got Header info";
61 ok $gunz->read($uncomp), " read ok" ;
62 is $uncomp, $content, " got expected content";
63 ok $gunz->close, " closed ok" ;
74 next if $zip64 && ! $stream;
76 for my $method (ZIP_CM_STORE, ZIP_CM_DEFLATE, ZIP_CM_BZIP2)
78 title "Stream $stream, Zip64 $zip64, Method $method";
80 my $lex = new LexFile my $file1;
82 my $content = "hello ";
83 #writeFile($file1, $content);
85 ok zip(\$content => $file1 , Method => $method,
87 Stream => $stream), " zip ok"
91 if ($stream && $method == ZIP_CM_STORE ) {
92 #eval ' unzip($file1 => \$got) ';
93 ok ! unzip($file1 => \$got), " unzip fails";
94 like $UnzipError, "/Streamed Stored content not supported/",
95 " Streamed Stored content not supported";
99 ok unzip($file1 => \$got), " unzip ok"
100 or diag $UnzipError ;
102 is $got, $content, " content ok";
104 my $u = new IO::Uncompress::Unzip $file1
107 my $hdr = $u->getHeaderInfo();
108 ok $hdr, " got header";
110 is $hdr->{Stream}, $stream, " stream is $stream" ;
111 is $hdr->{MethodID}, $method, " MethodID is $method" ;
112 is $hdr->{Zip64}, $zip64, " Zip64 is $zip64" ;
117 for my $stream (0, 1)
121 next if $zip64 && ! $stream;
123 for my $method (ZIP_CM_STORE, ZIP_CM_DEFLATE, ZIP_CM_BZIP2)
125 title "Stream $stream, Zip64 $zip64, Method $method";
130 my $lex = new LexFile $file1, $file2, $zipfile;
132 my $content1 = "hello ";
133 writeFile($file1, $content1);
135 my $content2 = "goodbye ";
136 writeFile($file2, $content2);
138 my %content = ( $file1 => $content1,
142 ok zip([$file1, $file2] => $zipfile , Method => $method,
144 Stream => $stream), " zip ok"
147 for my $file ($file1, $file2)
150 if ($stream && $method == ZIP_CM_STORE ) {
151 #eval ' unzip($zipfile => \$got) ';
152 ok ! unzip($zipfile => \$got, Name => $file), " unzip fails";
153 like $UnzipError, "/Streamed Stored content not supported/",
154 " Streamed Stored content not supported";
158 ok unzip($zipfile => \$got, Name => $file), " unzip $file ok"
159 or diag $UnzipError ;
161 is $got, $content{$file}, " content ok";
167 # TODO add more error cases