Debian lenny version packages
[pkg-perl] / deb-src / libio-compress-zlib-perl / libio-compress-zlib-perl-2.012 / t / 105oneshot-zip-bzip2-only.t
1 BEGIN {
2     if ($ENV{PERL_CORE}) {
3         chdir 't' if -d 't';
4         @INC = ("../lib", "lib/compress");
5     }
6 }
7
8 use lib qw(t t/compress);
9 use strict;
10 use warnings;
11 use bytes;
12
13 use Test::More ;
14 use CompTestUtils;
15
16 BEGIN {
17     plan(skip_all => "oneshot needs Perl 5.005 or better - you have Perl $]" )
18         if $] < 5.005 ;
19
20     plan(skip_all => "IO::Compress::Bzip2 not available" )
21         unless eval { require IO::Compress::Bzip2; 
22                       require IO::Uncompress::Bunzip2; 
23                       1
24                     } ;
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
31     plan tests => 120 + $extra ;
32
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)) ;
36
37
38 }
39
40
41 sub 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
69
70 for my $stream (0, 1)
71 {
72     for my $zip64 (0, 1)
73     {
74         next if $zip64 && ! $stream;
75
76         for my $method (ZIP_CM_STORE, ZIP_CM_DEFLATE, ZIP_CM_BZIP2)
77         {
78             title "Stream $stream, Zip64 $zip64, Method $method";
79
80             my $lex = new LexFile my $file1;
81
82             my $content = "hello ";
83             #writeFile($file1, $content);
84
85             ok zip(\$content => $file1 , Method => $method, 
86                                          Zip64  => $zip64,
87                                          Stream => $stream), " zip ok" 
88                 or diag $ZipError ;
89
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             }
98
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 ;
106
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         }
114     }
115 }
116
117 for my $stream (0, 1)
118 {
119     for my $zip64 (0, 1)
120     {
121         next if $zip64 && ! $stream;
122
123         for my $method (ZIP_CM_STORE, ZIP_CM_DEFLATE, ZIP_CM_BZIP2)
124         {
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";
162             }
163         }
164     }
165 }
166
167 # TODO add more error cases
168