Imported Upstream version 0.06

This commit is contained in:
Mario Fetka
2017-09-14 11:26:13 +02:00
commit fd6c0eeda3
47 changed files with 2570 additions and 0 deletions

57
t/01-identity.t Normal file
View File

@@ -0,0 +1,57 @@
#!perl -w
use strict;
use Archive::SevenZip;
use File::Basename;
use Test::More tests => 2;
use File::Temp 'tempfile';
my $version = Archive::SevenZip->find_7z_executable();
if( ! $version ) {
SKIP: { skip "7z binary not found (not installed?)", 2; }
exit;
};
diag "7-zip version $version";
my $base = dirname($0) . '/data';
my $archivename = "$base/def.zip";
my $ar = Archive::SevenZip->new(
archivename => $archivename,
);
# Check that extraction to scalar and extraction to file
# result in the same output
sub slurp {
my( $fh ) = @_;
binmode $fh;
local $/;
<$fh>
};
my $originalname = "$base/fred";
open my $fh, '<', $originalname
or die "Couldn't read '$originalname': $!";
my $original= slurp($fh);
sub data_matches_ok {
my( $memory, $name) = @_;
if( length($memory) == -s $originalname) {
cmp_ok $memory, 'eq', $original, "extracted data matches ($name)";
} else {
fail "extracted data matches ($name)";
diag "Got [$memory]";
diag "expected [$original]";
};
}
my $memory = slurp( $ar->openMemberFH("fred"));
data_matches_ok( $memory, "Memory extraction" );
( $fh, my $tempname)= tempfile();
close $fh;
$ar->extractMember("fred",$tempname);
open $fh, '<', $tempname
or die "Couldn't read '$tempname': $!";
my $disk = slurp($fh);
data_matches_ok( $disk, "Direct disk extraction" );

38
t/02-add-scalar.t Normal file
View File

@@ -0,0 +1,38 @@
#!perl -w
use strict;
use Archive::SevenZip;
use File::Basename;
use Test::More tests => 2;
use File::Temp 'tempfile';
my $version = Archive::SevenZip->find_7z_executable();
if( ! $version ) {
SKIP: { skip "7z binary not found (not installed?)", 2; }
exit;
};
diag "7-zip version $version";
if( $version <= 9.20) {
SKIP: {
skip "7z version $version does not support renaming", 2;
}
exit
};
my $base = dirname($0) . '/data';
my $ar = Archive::SevenZip->new(
#archivename => $archivename,
#type => '7z',
);
#(my $tempname, undef) = tempfile;
my $content = "This is\x{0d}\x{0a}the content";
$ar->add_scalar('some-member.txt',$content);
#$ar->writeToFileNamed($tempname);
my @contents = map { $_->fileName } $ar->list();
is_deeply \@contents, ["some-member.txt"], "Contents of created archive are OK";
my $written = $ar->content( membername => 'some-member.txt', binmode => ':raw');
is $written, $content, "Reading back the same data as we wrote";

381
t/02_main.t Normal file
View File

@@ -0,0 +1,381 @@
#!/usr/bin/perl
# Main testing for Archive::Zip
use strict;
BEGIN {
$| = 1;
$^W = 1;
}
use Archive::SevenZip qw( :ERROR_CODES :CONSTANTS );
use FileHandle;
use File::Path;
use File::Spec;
use Test::More;
use vars qw($testZipDoesntWork $status);
BEGIN {
if( ! eval {
require t::common;
t::common->import;
1
}) {
plan skip_all => "Archive::Zip not installed, skipping compatibility tests", 83;
exit;
} else {
plan tests => 83;
}
}
#####################################################################
# Testing Utility Functions
#--------- check CRC
is(TESTSTRINGCRC(), 0xac373f32, 'Testing CRC matches expected');
# Bad times die
SCOPE: {
my @errors = ();
local $Archive::Zip::ErrorHandler = sub { push @errors, @_ };
eval { Archive::Zip::Member::_unixToDosTime(0) };
ok($errors[0] =~ /Tried to add member with zero or undef/,
'Got expected _unixToDosTime error');
}
#--------- check time conversion
foreach my $unix_time (
315576062, 315576064, 315580000, 315600000,
316000000, 320000000, 400000000, 500000000,
600000000, 700000000, 800000000, 900000000,
1000000000, 1100000000, 1200000000, int(time() / 2) * 2,
) {
my $dos_time = Archive::Zip::Member::_unixToDosTime($unix_time);
my $round_trip = Archive::Zip::Member::_dosToUnixTime($dos_time);
is($unix_time, $round_trip, 'Got expected DOS DateTime value');
}
#####################################################################
# Testing Archives
my $version = Archive::SevenZip->find_7z_executable();
if( ! $version ) {
SKIP: { skip "7z binary not found (not installed?)", 65; }
exit;
};
diag "7-zip version $version";
if( $version <= 9.20) {
SKIP: {
skip "7z version $version does not support renaming", 65;
}
exit
};
#--------- empty file
# new # Archive::Zip
# new # Archive::Zip::Archive
my $zip = Archive::SevenZip->archiveZipApi();
isa_ok($zip, 'Archive::SevenZip::API::ArchiveZip');
# members # Archive::Zip::Archive
my @members = $zip->members;
is(scalar(@members), 0, '->members is 0');
# numberOfMembers # Archive::Zip::Archive
my $numberOfMembers = $zip->numberOfMembers();
is($numberOfMembers, 0, '->numberofMembers is 0');
# writeToFileNamed # Archive::Zip::Archive
my $status = $zip->writeToFileNamed(OUTPUTZIP());
is($status, AZ_OK, '->writeToFileNames ok');
my $zipout;
SKIP: {
skip("No 'unzip' program to test against", 1) unless HAVEUNZIP();
if ($^O eq 'MSWin32') {
print STDERR
"\n# You might see an expected 'zipfile is empty' warning now.\n";
}
($status, $zipout) = testZip();
# STDERR->print("status= $status, out=$zipout\n");
skip("test zip doesn't work", 1) if $testZipDoesntWork;
skip("freebsd's unzip doesn't care about empty zips", 1)
if $^O eq 'freebsd';
ok($status != 0);
}
# unzip -t returns error code=1 for warning on empty
#--------- add a directory
my $memberName = TESTDIR() . '/';
my $dirName = TESTDIR();
# addDirectory # Archive::Zip::Archive
# new # Archive::Zip::Member
my $member = $zip->addDirectory($memberName);
ok(defined($member));
is($member->fileName(), $memberName);
# On some (Windows systems) the modification time is
# corrupted. Save this to check late.
my $dir_time = $member->lastModFileDateTime();
# members # Archive::Zip::Archive
@members = $zip->members();
is(scalar(@members), 1);
is($members[0]->fileName, $member->fileName);
# numberOfMembers # Archive::Zip::Archive
$numberOfMembers = $zip->numberOfMembers();
is($numberOfMembers, 1);
# writeToFileNamed # Archive::Zip::Archive
$status = $zip->writeToFileNamed(OUTPUTZIP());
is($status, AZ_OK);
# Does the modification time get corrupted?
is(($zip->members)[0]->lastModFileDateTime(), $dir_time);
SKIP: {
skip("No 'unzip' program to test against", 1) unless HAVEUNZIP();
($status, $zipout) = testZip();
# STDERR->print("status= $status, out=$zipout\n");
skip("test zip doesn't work", 1) if $testZipDoesntWork;
is($status, 0);
}
#--------- extract the directory by name
rmtree([TESTDIR()], 0, 0);
$status = $zip->extractMember($memberName);
is($status, AZ_OK);
ok(-d $dirName);
#--------- extract the directory by identity
ok(rmdir($dirName)); # it's still empty
$status = $zip->extractMember($member);
is($status, AZ_OK);
ok(-d $dirName);
#--------- add a string member, uncompressed
$memberName = TESTDIR() . '/string.txt';
# addString # Archive::Zip::Archive
# newFromString # Archive::Zip::Member
$member = $zip->addString(TESTSTRING(), $memberName);
ok(defined($member));
is($member->fileName(), $memberName);
# members # Archive::Zip::Archive
@members = $zip->members();
is(scalar(@members), 2);
#is($members[1]->fileName, $member->fileName);
# numberOfMembers # Archive::Zip::Archive
$numberOfMembers = $zip->numberOfMembers();
is($numberOfMembers, 2);
# writeToFileNamed # Archive::Zip::Archive
$status = $zip->writeToFileNamed(OUTPUTZIP());
is($status, AZ_OK);
SKIP: {
skip("No 'unzip' program to test against", 1) unless HAVEUNZIP();
($status, $zipout) = testZip();
# STDERR->print("status= $status, out=$zipout\n");
skip("test zip doesn't work", 1) if $testZipDoesntWork;
is($status, 0);
}
is($member->crc32(), TESTSTRINGCRC());
is($member->crc32String(), sprintf("%08x", TESTSTRINGCRC()));
#--------- extract it by name
$status = $zip->extractMember($memberName);
is($status, AZ_OK);
ok(-f $memberName);
is(fileCRC($memberName), TESTSTRINGCRC());
#--------- now compress it and re-test
#my $oldCompressionMethod =
# $member->desiredCompressionMethod(COMPRESSION_DEFLATED);
#is($oldCompressionMethod, COMPRESSION_STORED, 'old compression method OK');
# writeToFileNamed # Archive::Zip::Archive
$status = $zip->writeToFileNamed(OUTPUTZIP());
is($status, AZ_OK, 'writeToFileNamed returns AZ_OK');
is($member->crc32(), TESTSTRINGCRC());
is($member->uncompressedSize(), TESTSTRINGLENGTH());
SKIP: {
skip("No 'unzip' program to test against", 1) unless HAVEUNZIP();
($status, $zipout) = testZip();
# STDERR->print("status= $status, out=$zipout\n");
skip("test zip doesn't work", 1) if $testZipDoesntWork;
is($status, 0);
}
#--------- extract it by name
$status = $zip->extractMember($memberName);
is($status, AZ_OK);
ok(-f $memberName);
is(fileCRC($memberName), TESTSTRINGCRC());
#--------- add a file member, compressed
ok(rename($memberName, TESTDIR() . '/file.txt'));
$memberName = TESTDIR() . '/file.txt';
# addFile # Archive::Zip::Archive
# newFromFile # Archive::Zip::Member
$member = $zip->addFile($memberName);
ok(defined($member));
is($member->desiredCompressionMethod(), COMPRESSION_DEFLATED);
# writeToFileNamed # Archive::Zip::Archive
$status = $zip->writeToFileNamed(OUTPUTZIP());
is($status, AZ_OK);
is($member->crc32(), TESTSTRINGCRC());
is($member->uncompressedSize(), TESTSTRINGLENGTH());
SKIP: {
skip("No 'unzip' program to test against", 1) unless HAVEUNZIP();
($status, $zipout) = testZip();
# STDERR->print("status= $status, out=$zipout\n");
skip("test zip doesn't work", 1) if $testZipDoesntWork;
is($status, 0);
}
#--------- extract it by name (note we have to rename it first
#--------- or we will clobber the original file
my $newName = $memberName;
$newName =~ s/\.txt/2.txt/;
$status = $zip->extractMember($memberName, $newName);
is($status, AZ_OK);
ok(-f $newName);
is(fileCRC($newName), TESTSTRINGCRC());
#--------- now make it uncompressed and re-test
#$oldCompressionMethod = $member->desiredCompressionMethod(COMPRESSION_STORED);
#is($oldCompressionMethod, COMPRESSION_DEFLATED);
# writeToFileNamed # Archive::Zip::Archive
$status = $zip->writeToFileNamed(OUTPUTZIP());
is($status, AZ_OK);
is($member->crc32(), TESTSTRINGCRC());
is($member->uncompressedSize(), TESTSTRINGLENGTH());
SKIP: {
skip("No 'unzip' program to test against", 1) unless HAVEUNZIP();
($status, $zipout) = testZip();
# STDERR->print("status= $status, out=$zipout\n");
skip("test zip doesn't work", 1) if $testZipDoesntWork;
is($status, 0);
}
#--------- extract it by name
$status = $zip->extractMember($memberName, $newName);
is($status, AZ_OK);
ok(-f $newName);
is(fileCRC($newName), TESTSTRINGCRC());
# Now, the contents of OUTPUTZIP() are:
# Length Method Size Ratio Date Time CRC-32 Name
#-------- ------ ------- ----- ---- ---- ------ ----
# 0 Stored 0 0% 03-17-00 11:16 00000000 TESTDIR/
# 300 Defl:N 146 51% 03-17-00 11:16 ac373f32 TESTDIR/string.txt
# 300 Stored 300 0% 03-17-00 11:16 ac373f32 TESTDIR/file.txt
#-------- ------- --- -------
# 600 446 26% 3 files
# members # Archive::Zip::Archive
@members = $zip->members();
is(scalar(@members), 3);
is_deeply([map {$_->fileName}
grep { $_->fileName eq $member->fileName } @members ],
[$member->fileName])
or do { diag "Have: " . $_->fileName for @members };
# memberNames # Archive::Zip::Archive
my @memberNames = $zip->memberNames();
is(scalar(@memberNames), 3);
is_deeply([ grep { $_ eq $member->fileName } @memberNames ],
[ $member->fileName ])
or do { diag sprintf "[%s]", $member->fileName ; diag sprintf "[%s]", $_->fileName for @members };
# memberNamed # Archive::Zip::Archive
is($zip->memberNamed($memberName)->fileName, $member->fileName);
# membersMatching # Archive::Zip::Archive
@members = $zip->membersMatching('file');
is(scalar(@members), 1);
is($members[0]->fileName, $member->fileName);
@members = sort { $a->fileName cmp $b->fileName } $zip->membersMatching('.txt$');
is(scalar(@members), 2);
is($members[0]->fileName, $member->fileName);
#--------- remove the string member and test the file
# removeMember # Archive::Zip::Archive
diag "Removing " . $members[0]->fileName;
$member = $zip->removeMember($members[0]);
is($member, $members[0]);
$status = $zip->writeToFileNamed(OUTPUTZIP());
is($status, AZ_OK);
SKIP: {
skip("No 'unzip' program to test against", 1) unless HAVEUNZIP();
($status, $zipout) = testZip();
# STDERR->print("status= $status, out=$zipout\n");
skip("test zip doesn't work", 1) if $testZipDoesntWork;
is($status, 0);
}
#--------- add the string member at the end and test the file
# addMember # Archive::Zip::Archive
# This will never work in Archive::SevenZip, transplanting
# zip entries in-memory
# This also ruins all of the subsequent tests due to the weirdo
# approach of not setting up a common baseline for each test
# and the insistence on that the implementation maintains the
# order on archive members
#
#$zip->addMember($member);
#@members = $zip->members();
#is(scalar(@members), 3);
#is($members[2], $member);
# memberNames # Archive::Zip::Archive
#@memberNames = $zip->memberNames();
#is(scalar(@memberNames), 3);
#is($memberNames[1], $memberName);
#$status = $zip->writeToFileNamed(OUTPUTZIP());
#is($status, AZ_OK);
#SKIP: {
# skip("No 'unzip' program to test against", 1) unless HAVEUNZIP();
# ($status, $zipout) = testZip();
# # STDERR->print("status= $status, out=$zipout\n");
# skip("test zip doesn't work", 1) if $testZipDoesntWork;
# is($status, 0);
#}

59
t/05_tree.t Normal file
View File

@@ -0,0 +1,59 @@
#!/usr/bin/perl
use strict;
BEGIN {
$| = 1;
$^W = 1;
}
use Archive::SevenZip;
use FileHandle;
use File::Spec;
use Test::More tests => 2;
BEGIN {
if( ! eval {
require t::common;
t::common->import;
1
}) { SKIP: {
skip "Archive::Zip not installed, skipping compatibility tests", 2;
}
exit;
}}
my $version = Archive::SevenZip->find_7z_executable();
if( ! $version ) {
SKIP: { skip "7z binary not found (not installed?)", 2; }
exit;
};
use constant FILENAME => File::Spec->catfile(TESTDIR(), 'testing.txt');
my $zip;
my @memberNames;
sub makeZip {
my ($src, $dest, $pred) = @_;
$zip = Archive::SevenZip->archiveZipApi();
$zip->addTree($src, $dest,);
@memberNames = $zip->memberNames();
}
sub makeZipAndLookFor {
my ($src, $dest, $pred, $lookFor) = @_;
makeZip($src, $dest, $pred);
ok(@memberNames);
ok((grep { $_ eq $lookFor } @memberNames) == 1)
or print STDERR "Can't find $lookFor in ("
. join(",", @memberNames) . ")\n";
}
my ($testFileVolume, $testFileDirs, $testFileName) = File::Spec->splitpath($0);
makeZipAndLookFor('.', '', sub { print "file $_\n"; -f && /\.t$/ },
't/02_main.t');
# Not supported:
#makeZipAndLookFor('.', 'e/', sub { -f && /\.t$/ }, 'e/t/02_main.t');
#makeZipAndLookFor('./t', '', sub { -f && /\.t$/ }, '02_main.t');

59
t/20_bug_github11.t Normal file
View File

@@ -0,0 +1,59 @@
#!/usr/bin/perl
# Github 11: "CRC or size mismatch" when extracting member second time
# Test for correct functionality to prevent regression
use strict;
use warnings;
use Archive::SevenZip 'AZ_OK';
use File::Spec;
use File::Path;
use Test::More;
BEGIN {
if( ! eval {
require t::common;
t::common->import;
1
}) {
plan skip_all => "Archive::Zip not installed, skipping compatibility tests";
exit;
}
else {
plan tests => 2;
}
}
my $version = Archive::SevenZip->find_7z_executable();
if( ! $version ) {
SKIP: { skip "7z binary not found (not installed?)", 2; };
exit
};
diag "7-zip version $version";
# create test env
my $GH_ISSUE = 'github11';
my $TEST_NAME = "20_bug_$GH_ISSUE";
my $TEST_DIR = File::Spec->catdir(TESTDIR, $TEST_NAME);
mkpath($TEST_DIR);
# test 1
my $DATA_DIR = File::Spec->catfile('t', 'data');
my $GOOD_ZIP_FILE = File::Spec->catfile($DATA_DIR, "good_${GH_ISSUE}.zip");
my $GOOD_ZIP = Archive::SevenZip->new($GOOD_ZIP_FILE);
my $MEMBER_FILE = 'FILE';
my $member = $GOOD_ZIP->memberNamed($MEMBER_FILE);
my $OUT_FILE = File::Spec->catfile($TEST_DIR, "out");
# Extracting twice triggered the bug
$member->extractToFileNamed($OUT_FILE);
is($member->extractToFileNamed($OUT_FILE), AZ_OK, 'Testing known good zip');
# test 2
my $BAD_ZIP_FILE = File::Spec->catfile($DATA_DIR, "bad_${GH_ISSUE}.zip");
my $BAD_ZIP = Archive::SevenZip->new($BAD_ZIP_FILE);
$member = $BAD_ZIP->memberNamed($MEMBER_FILE);
# Extracting twice triggered the bug
$member->extractToFileNamed($OUT_FILE);
is($member->extractToFileNamed($OUT_FILE), AZ_OK, 'Testing known bad zip');

BIN
t/badjpeg/expected.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

BIN
t/badjpeg/source.zip Normal file

Binary file not shown.

257
t/common.pm Normal file
View File

@@ -0,0 +1,257 @@
use strict;
# Shared defs for test programs
# Paths. Must make case-insensitive.
use File::Temp qw(tempfile tempdir);
use File::Spec;
BEGIN { mkdir 'testdir' }
use constant TESTDIR => do {
my $tmpdir = File::Spec->abs2rel(tempdir(DIR => 'testdir', CLEANUP => 1));
$tmpdir =~ s!\\!/!g if $^O eq 'MSWin32';
$tmpdir
};
use constant INPUTZIP =>
(tempfile('testin-XXXXX', SUFFIX => '.zip', TMPDIR => 1, $^O eq 'MSWin32' ? () : (UNLINK => 1)))[1];
use constant OUTPUTZIP =>
(tempfile('testout-XXXXX', SUFFIX => '.zip', TMPDIR => 1, $^O eq 'MSWin32' ? () : (UNLINK => 1)))[1];
# Do we have the 'zip' and 'unzip' programs?
# Embed a copy of the module, rather than adding a dependency
BEGIN {
package File::Which;
use File::Spec;
my $Is_VMS = ($^O eq 'VMS');
my $Is_MacOS = ($^O eq 'MacOS');
my $Is_DOSish =
(($^O eq 'MSWin32') or ($^O eq 'dos') or ($^O eq 'os2'));
# For Win32 systems, stores the extensions used for
# executable files
# For others, the empty string is used
# because 'perl' . '' eq 'perl' => easier
my @path_ext = ('');
if ($Is_DOSish) {
if ($ENV{PATHEXT} and $Is_DOSish)
{ # WinNT. PATHEXT might be set on Cygwin, but not used.
push @path_ext, split ';', $ENV{PATHEXT};
} else {
push @path_ext, qw(.com .exe .bat)
; # Win9X or other: doesn't have PATHEXT, so needs hardcoded.
}
} elsif ($Is_VMS) {
push @path_ext, qw(.exe .com);
}
sub which {
my ($exec) = @_;
return undef unless $exec;
my $all = wantarray;
my @results = ();
# check for aliases first
if ($Is_VMS) {
my $symbol = `SHOW SYMBOL $exec`;
chomp($symbol);
if (!$?) {
return $symbol unless $all;
push @results, $symbol;
}
}
if ($Is_MacOS) {
my @aliases = split /\,/, $ENV{Aliases};
foreach my $alias (@aliases) {
# This has not been tested!!
# PPT which says MPW-Perl cannot resolve `Alias $alias`,
# let's just hope it's fixed
if (lc($alias) eq lc($exec)) {
chomp(my $file = `Alias $alias`);
last unless $file; # if it failed, just go on the normal way
return $file unless $all;
push @results, $file;
# we can stop this loop as if it finds more aliases matching,
# it'll just be the same result anyway
last;
}
}
}
my @path = File::Spec->path();
unshift @path, File::Spec->curdir if $Is_DOSish or $Is_VMS or $Is_MacOS;
for my $base (map { File::Spec->catfile($_, $exec) } @path) {
for my $ext (@path_ext) {
my $file = $base . $ext;
# print STDERR "$file\n";
if (
(
-x $file or # executable, normal case
(
$Is_MacOS
|| # MacOS doesn't mark as executable so we check -e
(
$Is_DOSish
and grep { $file =~ /$_$/i }
@path_ext[1 .. $#path_ext])
# DOSish systems don't pass -x on non-exe/bat/com files.
# so we check -e. However, we don't want to pass -e on files
# that aren't in PATHEXT, like README.
and -e _))
and !-d _)
{ # and finally, we don't want dirs to pass (as they are -x)
# print STDERR "-x: ", -x $file, " -e: ", -e _, " -d: ", -d _, "\n";
return $file unless $all;
push @results, $file; # Make list to return later
}
}
}
if ($all) {
return @results;
} else {
return undef;
}
}
}
use constant HAVEZIP => !!File::Which::which('zip');
use constant HAVEUNZIP => !!File::Which::which('unzip');
use constant ZIP => 'zip ';
use constant ZIPTEST => 'unzip -t ';
# 300-character test string
use constant TESTSTRING => join("\n", 1 .. 102) . "\n";
use constant TESTSTRINGLENGTH => length(TESTSTRING);
use Archive::Zip ();
# CRC-32 should be ac373f32
use constant TESTSTRINGCRC => Archive::Zip::computeCRC32(TESTSTRING);
# This is so that it will work on other systems.
use constant CAT => $^X . ' -pe "BEGIN{binmode(STDIN);binmode(STDOUT)}"';
use constant CATPIPE => '| ' . CAT . ' >';
use vars qw($zipWorks $testZipDoesntWork $catWorks);
# Run ZIPTEST to test a zip file.
sub testZip {
my $zipName = shift || OUTPUTZIP;
if ($testZipDoesntWork) {
return wantarray ? (0, '') : 0;
}
my $cmd = ZIPTEST . $zipName . ($^O eq 'MSWin32' ? '' : ' 2>&1');
my $zipout = `$cmd`;
return wantarray ? ($?, $zipout) : $?;
}
# Return the crc-32 of the given file (0 if empty or error)
sub fileCRC {
my $fileName = shift;
local $/ = undef;
my $fh = IO::File->new($fileName, "r");
binmode($fh);
return 0 if not defined($fh);
my $contents = <$fh>;
return Archive::Zip::computeCRC32($contents);
}
#--------- check to see if cat works
sub testCat {
my $fh = IO::File->new(CATPIPE . OUTPUTZIP);
binmode($fh);
my $testString = pack('C256', 0 .. 255);
my $testCrc = Archive::Zip::computeCRC32($testString);
$fh->write($testString, length($testString)) or return 0;
$fh->close();
(-f OUTPUTZIP) or return 0;
my @stat = stat(OUTPUTZIP);
$stat[7] == length($testString) or return 0;
fileCRC(OUTPUTZIP) == $testCrc or return 0;
unlink(OUTPUTZIP);
return 1;
}
BEGIN {
$catWorks = testCat();
unless ($catWorks) {
warn('warning: ', CAT, " doesn't seem to work, may skip some tests");
}
}
#--------- check to see if zip works (and make INPUTZIP)
BEGIN {
unlink(INPUTZIP);
# Do we have zip installed?
if (HAVEZIP) {
my $cmd = ZIP . INPUTZIP . ' *' . ($^O eq 'MSWin32' ? '' : ' 2>&1');
my $zipout = `$cmd`;
$zipWorks = not $?;
unless ($zipWorks) {
warn('warning: ', ZIP,
" doesn't seem to work, may skip some tests");
}
}
}
#--------- check to see if unzip -t works
BEGIN {
$testZipDoesntWork = 1;
if (HAVEUNZIP) {
my ($status, $zipout) = do { local $testZipDoesntWork = 0; testZip(INPUTZIP) };
$testZipDoesntWork = $status;
# Again, on Win32 no big surprise if this doesn't work
if ($testZipDoesntWork) {
warn('warning: ', ZIPTEST,
" doesn't seem to work, may skip some tests");
}
}
}
sub passthrough
{
my $fromFile = shift ;
my $toFile = shift ;
my $action = shift ;
my $z = Archive::Zip->new;
$z->read($fromFile);
if ($action)
{
for my $member($z->members())
{
&$action($member) ;
}
}
$z->writeToFileNamed($toFile);
}
sub readFile
{
my $name = shift ;
local $/;
open F, "<$name"
or die "Cannot open $name: $!\n";
my $data = <F>;
close F ;
return $data;
}
1;

BIN
t/data/bad_github11.zip Normal file

Binary file not shown.

BIN
t/data/chmod.zip Normal file

Binary file not shown.

BIN
t/data/crypcomp.zip Normal file

Binary file not shown.

BIN
t/data/crypt.zip Normal file

Binary file not shown.

BIN
t/data/def.zip Normal file

Binary file not shown.

BIN
t/data/defstr.zip Normal file

Binary file not shown.

BIN
t/data/emptydef.zip Normal file

Binary file not shown.

BIN
t/data/emptydefstr.zip Normal file

Binary file not shown.

BIN
t/data/emptystore.zip Normal file

Binary file not shown.

BIN
t/data/emptystorestr.zip Normal file

Binary file not shown.

1
t/data/fred Normal file
View File

@@ -0,0 +1 @@
abc

BIN
t/data/good_github11.zip Normal file

Binary file not shown.

BIN
t/data/jar.zip Normal file

Binary file not shown.

BIN
t/data/linux.zip Normal file

Binary file not shown.

54
t/data/mkzip.pl Normal file
View File

@@ -0,0 +1,54 @@
#!/usr/bin/perl
#This script will create test zip files used by some of the tests.
#
# File Length Streamed Method
# ===============================================
# emptydef.zip Yes No Deflate
# emptydefstr.zip Yes Yes Deflate
# emptystore.zip Yes No Store
# emptystorestr.zip Yes Yes Store
#
use warnings;
use strict;
use IO::Compress::Zip qw(:all);
my $time = 325532800;
zip \"" => "emptydef.zip",
Name => "fred", Stream => 0, Method => ZIP_CM_DEFLATE, Time => $time
or die "Cannot create zip: $ZipError";
zip \"" => "emptydefstr.zip",
Name => "fred", Stream => 1, Method => ZIP_CM_DEFLATE, Time => $time
or die "Cannot create zip: $ZipError";
zip \"" => "emptystore.zip",
Name => "fred", Stream => 0, Method => ZIP_CM_STORE, Time => $time
or die "Cannot create zip: $ZipError";
zip \"" => "emptystorestr.zip",
Name => "fred", Stream => 1, Method => ZIP_CM_STORE, Time => $time
or die "Cannot create zip: $ZipError";
zip \"abc" => "def.zip",
Name => "fred", Stream => 0, Method => ZIP_CM_DEFLATE, Time => $time
or die "Cannot create zip: $ZipError";
zip \"abc" => "defstr.zip",
Name => "fred", Stream => 1, Method => ZIP_CM_DEFLATE, Time => $time
or die "Cannot create zip: $ZipError";
zip \"abc" => "store.zip",
Name => "fred", Stream => 0, Method => ZIP_CM_STORE, Time => $time
or die "Cannot create zip: $ZipError";
zip \"abc" => "storestr.zip",
Name => "fred", Stream => 1, Method => ZIP_CM_STORE, Time => $time
or die "Cannot create zip: $ZipError";

BIN
t/data/perl.zip Normal file

Binary file not shown.

BIN
t/data/store.zip Normal file

Binary file not shown.

BIN
t/data/storestr.zip Normal file

Binary file not shown.

BIN
t/data/streamed.zip Normal file

Binary file not shown.

BIN
t/data/winzip.zip Normal file

Binary file not shown.

BIN
t/data/zip64.zip Normal file

Binary file not shown.