4 @INC = ("../lib", "lib/compress");
17 plan(skip_all => "oneshot needs Perl 5.005 or better - you have Perl $]" )
21 # use Test::NoWarnings, if available
24 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
26 plan tests => 95 + $extra ;
28 use_ok('IO::Compress::Zip', qw(zip $ZipError)) ;
29 use_ok('IO::Uncompress::Unzip', qw(unzip $UnzipError)) ;
44 ok zip($in, \$out, %opts), " zip ok" ;
45 ok unzip(\$out, \$got), " unzip ok"
47 is $got, $content, " got expected content" ;
49 my $gunz = new IO::Uncompress::Unzip \$out, Strict => 0
50 or diag "UnzipError is $IO::Uncompress::Unzip::UnzipError" ;
51 ok $gunz, " Created IO::Uncompress::Unzip object";
52 my $hdr = $gunz->getHeaderInfo();
53 ok $hdr, " got Header info";
55 ok $gunz->read($uncomp), " read ok" ;
56 is $uncomp, $content, " got expected content";
57 ok $gunz->close, " closed ok" ;
64 title "Check zip header default NAME & MTIME settings" ;
66 my $lex = new LexFile my $file1;
68 my $content = "hello ";
72 writeFile($file1, $content);
73 $mtime = (stat($file1))[8];
74 # make sure that the zip file isn't created in the same
75 # second as the input file
77 $hdr = zipGetHeader($file1, $content);
79 is $hdr->{Name}, $file1, " Name is '$file1'";
80 is $hdr->{Time}>>1, $mtime>>1, " Time is ok";
82 title "Override Name" ;
84 writeFile($file1, $content);
85 $mtime = (stat($file1))[8];
87 $hdr = zipGetHeader($file1, $content, Name => "abcde");
89 is $hdr->{Name}, "abcde", " Name is 'abcde'" ;
90 is $hdr->{Time} >> 1, $mtime >> 1, " Time is ok";
92 title "Override Time" ;
94 writeFile($file1, $content);
95 my $useTime = time + 2000 ;
96 $hdr = zipGetHeader($file1, $content, Time => $useTime);
98 is $hdr->{Name}, $file1, " Name is '$file1'" ;
99 is $hdr->{Time} >> 1 , $useTime >> 1 , " Time is $useTime";
101 title "Override Name and Time" ;
103 $useTime = time + 5000 ;
104 writeFile($file1, $content);
105 $hdr = zipGetHeader($file1, $content, Time => $useTime, Name => "abcde");
107 is $hdr->{Name}, "abcde", " Name is 'abcde'" ;
108 is $hdr->{Time} >> 1 , $useTime >> 1 , " Time is $useTime";
110 title "Filehandle doesn't have default Name or Time" ;
111 my $fh = new IO::File "< $file1"
112 or diag "Cannot open '$file1': $!\n" ;
115 $hdr = zipGetHeader($fh, $content);
118 ok ! defined $hdr->{Name}, " Name is undef";
119 cmp_ok $hdr->{Time} >> 1, '>=', $before >> 1, " Time is ok";
120 cmp_ok $hdr->{Time} >> 1, '<=', $after >> 1, " Time is ok";
124 title "Buffer doesn't have default Name or Time" ;
125 my $buffer = $content;
127 $hdr = zipGetHeader(\$buffer, $content);
130 ok ! defined $hdr->{Name}, " Name is undef";
131 cmp_ok $hdr->{Time} >> 1, '>=', $before >> 1, " Time is ok";
132 cmp_ok $hdr->{Time} >> 1, '<=', $after >> 1, " Time is ok";
135 for my $stream (0, 1)
139 title "Stream $stream, Store $store";
141 my $lex = new LexFile my $file1;
143 my $content = "hello ";
144 writeFile($file1, $content);
146 ok zip(\$content => $file1 , Store => !$store, Stream => $stream), " zip ok"
150 if ($stream && ! $store) {
151 #eval ' unzip($file1 => \$got) ';
152 ok ! unzip($file1 => \$got), " unzip fails";
153 like $UnzipError, "/Streamed Stored content not supported/",
154 " Streamed Stored content not supported";
158 ok unzip($file1 => \$got), " unzip ok"
159 or diag $UnzipError ;
161 is $got, $content, " content ok";
163 my $u = new IO::Uncompress::Unzip $file1
166 my $hdr = $u->getHeaderInfo();
167 ok $hdr, " got header";
169 is $hdr->{Stream}, $stream, " stream is $stream" ;
170 is $hdr->{MethodID}, $store, " MethodID is $store" ;
174 # TODO add more error cases