compress 2.021
[p5sagit/p5-mst-13.2.git] / ext / IO-Compress / t / 105oneshot-zip-bzip2-only.t
CommitLineData
25f0751f 1BEGIN {
2 if ($ENV{PERL_CORE}) {
3 chdir 't' if -d 't';
4 @INC = ("../lib", "lib/compress");
5 }
6}
7
8use lib qw(t t/compress);
9use strict;
10use warnings;
11use bytes;
12
13use Test::More ;
14use CompTestUtils;
15
16BEGIN {
17 plan(skip_all => "oneshot needs Perl 5.005 or better - you have Perl $]" )
18 if $] < 5.005 ;
19
319fab50 20 plan(skip_all => "IO::Compress::Bzip2 not available" )
21 unless eval { require IO::Compress::Bzip2;
22 require IO::Uncompress::Bunzip2;
23 1
24 } ;
25f0751f 25
26 # use Test::NoWarnings, if available
27 my $extra = 0 ;
28 $extra = 1
29 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
30
10c2b2bb 31 plan tests => 144 + $extra ;
25f0751f 32
2b4e0969 33 #use_ok('IO::Compress::Zip', qw(zip $ZipError :zip_method)) ;
34 use_ok('IO::Compress::Zip', qw(:all)) ;
25f0751f 35 use_ok('IO::Uncompress::Unzip', qw(unzip $UnzipError)) ;
36
37
38}
39
40
41sub zipGetHeader
42{
43 my $in = shift;
44 my $content = shift ;
45 my %opts = @_ ;
46
47 my $out ;
48 my $got ;
49
50 ok zip($in, \$out, %opts), " zip ok" ;
51 ok unzip(\$out, \$got), " unzip ok"
52 or diag $UnzipError ;
53 is $got, $content, " got expected content" ;
54
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";
60 my $uncomp ;
61 ok $gunz->read($uncomp), " read ok" ;
62 is $uncomp, $content, " got expected content";
63 ok $gunz->close, " closed ok" ;
64
65 return $hdr ;
66
67}
68
25f0751f 69
70for my $stream (0, 1)
71{
e7d45986 72 for my $zip64 (0, 1)
25f0751f 73 {
10c2b2bb 74 #next if $zip64 && ! $stream;
25f0751f 75
319fab50 76 for my $method (ZIP_CM_STORE, ZIP_CM_DEFLATE, ZIP_CM_BZIP2)
e7d45986 77 {
e7d45986 78 title "Stream $stream, Zip64 $zip64, Method $method";
25f0751f 79
e7d45986 80 my $lex = new LexFile my $file1;
25f0751f 81
e7d45986 82 my $content = "hello ";
83 #writeFile($file1, $content);
25f0751f 84
319fab50 85 ok zip(\$content => $file1 , Method => $method,
86 Zip64 => $zip64,
87 Stream => $stream), " zip ok"
e7d45986 88 or diag $ZipError ;
25f0751f 89
e7d45986 90 my $got ;
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";
96 next ;
97 }
25f0751f 98
e7d45986 99 ok unzip($file1 => \$got), " unzip ok"
100 or diag $UnzipError ;
101
102 is $got, $content, " content ok";
103
104 my $u = new IO::Uncompress::Unzip $file1
105 or diag $ZipError ;
25f0751f 106
e7d45986 107 my $hdr = $u->getHeaderInfo();
108 ok $hdr, " got header";
109
110 is $hdr->{Stream}, $stream, " stream is $stream" ;
111 is $hdr->{MethodID}, $method, " MethodID is $method" ;
112 is $hdr->{Zip64}, $zip64, " Zip64 is $zip64" ;
113 }
25f0751f 114 }
115}
116
4d91e282 117for my $stream (0, 1)
118{
e7d45986 119 for my $zip64 (0, 1)
4d91e282 120 {
e7d45986 121 next if $zip64 && ! $stream;
319fab50 122
123 for my $method (ZIP_CM_STORE, ZIP_CM_DEFLATE, ZIP_CM_BZIP2)
4d91e282 124 {
e7d45986 125 title "Stream $stream, Zip64 $zip64, Method $method";
126
127 my $file1;
128 my $file2;
129 my $zipfile;
130 my $lex = new LexFile $file1, $file2, $zipfile;
131
132 my $content1 = "hello ";
133 writeFile($file1, $content1);
134
135 my $content2 = "goodbye ";
136 writeFile($file2, $content2);
137
138 my %content = ( $file1 => $content1,
139 $file2 => $content2,
140 );
141
142 ok zip([$file1, $file2] => $zipfile , Method => $method,
143 Zip64 => $zip64,
144 Stream => $stream), " zip ok"
145 or diag $ZipError ;
146
147 for my $file ($file1, $file2)
148 {
149 my $got ;
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";
155 next ;
156 }
157
158 ok unzip($zipfile => \$got, Name => $file), " unzip $file ok"
159 or diag $UnzipError ;
160
161 is $got, $content{$file}, " content ok";
4d91e282 162 }
4d91e282 163 }
164 }
165}
166
25f0751f 167# TODO add more error cases
168