4 @INC = ("../lib", "lib/compress");
8 use lib qw(t t/compress);
17 use IO::Compress::Zip qw($ZipError);
18 use IO::Uncompress::Unzip qw($UnzipError);
21 plan skip_all => "Encode is not available"
24 eval { require Encode; Encode->import(); };
26 plan skip_all => "Encode is not available"
29 plan skip_all => "Encode not woking in perl $]"
30 if $] >= 5.008 && $] < 5.008004 ;
32 # use Test::NoWarnings, if available
35 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
37 plan tests => 28 + $extra;
41 title "EFS set in zip: Create a simple zip - language encoding flag set";
43 my $lex = new LexFile my $file1;
45 my @names = ( 'alpha \N{GREEK SMALL LETTER ALPHA}',
46 'beta \N{GREEK SMALL LETTER BETA}',
47 'gamma \N{GREEK SMALL LETTER GAMMA}',
48 'delta \N{GREEK SMALL LETTER DELTA}'
51 my @encoded = map { Encode::encode_utf8($_) } @names;
55 my $zip = new IO::Compress::Zip $file1,
56 Name => $names[0], Efs => 1;
58 my $content = 'Hello, world!';
59 ok $zip->print($content), "print";
60 $zip->newStream(Name => $names[1], Efs => 1);
61 ok $zip->print($content), "print";
62 $zip->newStream(Name => $names[2], Efs => 1);
63 ok $zip->print($content), "print";
64 $zip->newStream(Name => $names[3], Efs => 1);
65 ok $zip->print($content), "print";
66 ok $zip->close(), "closed";
69 my $u = new IO::Uncompress::Unzip $file1, Efs => 1
70 or die "Cannot open $file1: $UnzipError";
75 for ($status = 1; $status > 0; $status = $u->nextStream(Efs => 1))
77 push @efs, $u->getHeaderInfo()->{efs};
78 push @unzip_names, $u->getHeaderInfo()->{Name};
81 die "Error processing $file1: $status $!\n"
84 is_deeply \@efs, [1, 1, 1, 1], "language encoding flag set"
85 or diag "Got " . Dumper(\@efs);
86 is_deeply \@unzip_names, [@names], "Names round tripped"
87 or diag "Got " . Dumper(\@unzip_names);
91 my $u = new IO::Uncompress::Unzip $file1, Efs => 0
92 or die "Cannot open $file1: $UnzipError";
97 for ($status = 1; $status > 0; $status = $u->nextStream(Efs => 0))
99 push @efs, $u->getHeaderInfo()->{efs};
100 push @unzip_names, $u->getHeaderInfo()->{Name};
103 die "Error processing $file1: $status $!\n"
106 is_deeply \@efs, [1, 1, 1, 1], "language encoding flag set"
107 or diag "Got " . Dumper(\@efs);
108 is_deeply \@unzip_names, [@names], "Names round tripped"
109 or diag "Got " . Dumper(\@unzip_names);
115 title "Create a simple zip - language encoding flag not set";
117 my $lex = new LexFile my $file1;
119 my @names = ( 'alpha \N{GREEK SMALL LETTER ALPHA}',
120 'beta \N{GREEK SMALL LETTER BETA}',
121 'gamma \N{GREEK SMALL LETTER GAMMA}',
122 'delta \N{GREEK SMALL LETTER DELTA}'
127 my $zip = new IO::Compress::Zip $file1,
128 Name => $names[0], Efs => 0;
130 my $content = 'Hello, world!';
131 ok $zip->print($content), "print";
132 $zip->newStream(Name => $names[1], Efs => 0);
133 ok $zip->print($content), "print";
134 $zip->newStream(Name => $names[2], Efs => 0);
135 ok $zip->print($content), "print";
136 $zip->newStream(Name => $names[3]);
137 ok $zip->print($content), "print";
138 ok $zip->close(), "closed";
140 my $u = new IO::Uncompress::Unzip $file1, Efs => 0
141 or die "Cannot open $file1: $UnzipError";
146 for ($status = 1; $status > 0; $status = $u->nextStream())
148 push @efs, $u->getHeaderInfo()->{efs};
149 push @unzip_names, $u->getHeaderInfo()->{Name};
152 die "Error processing $file1: $status $!\n"
155 is_deeply \@efs, [0, 0, 0, 0], "language encoding flag set"
156 or diag "Got " . Dumper(\@efs);
157 is_deeply \@unzip_names, [@names], "Names round tripped"
158 or diag "Got " . Dumper(\@unzip_names);
162 title "zip: EFS => 0 filename not valid utf8 - language encoding flag not set";
164 my $lex = new LexFile my $file1;
167 my $name = "a\xFF\x{100}";
169 my $zip = new IO::Compress::Zip $file1,
170 Name => $name, Efs => 0 ;
172 ok $zip->print("abcd"), "print";
173 ok $zip->close(), "closed";
175 my $u = new IO::Uncompress::Unzip $file1
176 or die "Cannot open $file1: $UnzipError";
178 ok $u->getHeaderInfo()->{Name} eq $name, "got bad filename";
182 title "unzip: EFS => 0 filename not valid utf8 - language encoding flag set";
184 my $filename = "t/files/bad-efs.zip" ;
185 my $name = "\xF0\xA4\xAD";
187 my $u = new IO::Uncompress::Unzip $filename, efs => 0
188 or die "Cannot open $filename: $UnzipError";
190 ok $u->getHeaderInfo()->{Name} eq $name, "got bad filename";
194 title "unzip: EFS => 1 filename not valid utf8 - language encoding flag set";
196 my $filename = "t/files/bad-efs.zip" ;
197 my $name = "\xF0\xA4\xAD";
199 eval { my $u = new IO::Uncompress::Unzip $filename, efs => 1
200 or die "Cannot open $filename: $UnzipError" };
202 like $@, qr/Zip Filename not UTF-8/,
203 " Zip Filename not UTF-8" ;
208 title "EFS => 1 - filename not valid utf8 - catch bad content writing to zip";
210 my $lex = new LexFile my $file1;
213 my $name = "a\xFF\x{100}";
215 eval { my $zip = new IO::Compress::Zip $file1,
216 Name => $name, Efs => 1 } ;
218 like $@, qr/Wide character in zip filename/,
219 " wide characters in zip filename";