Archive-SevenZip
view release on metacpan or search on metacpan
t/02_main.t view on Meta::CPAN
# 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
$status = $zip->writeToFileNamed(OUTPUTZIP());
is($status, AZ_OK, '->writeToFileNames ok');
my $zipout;
#--------- add a directory
my $memberName = TESTDIR() . '/';
my $dirName = TESTDIR();
# addDirectory # Archive::Zip::Archive
# new # Archive::Zip::Member
t/02_main.t view on Meta::CPAN
# members # Archive::Zip::Archive
@members = $zip->members();
is(scalar(@members), 1, "We have one member");
is($members[0]->fileName, $member->fileName, "... with the correct 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");
t/02_main.t view on Meta::CPAN
# 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);
}
t/02_main.t view on Meta::CPAN
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;
t/02_main.t view on Meta::CPAN
$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;
t/02_main.t view on Meta::CPAN
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();
t/02_main.t view on Meta::CPAN
@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);
}
t/02_main.t view on Meta::CPAN
#@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);
#}
t/22_deflated_dir.t view on Meta::CPAN
use lib '.';
use t::common;
use Test::More tests => 4;
my $sevenzip = Archive::SevenZip->new();
my $zip = $sevenzip->archiveZipApi;
isa_ok( $sevenzip, 'Archive::SevenZip' );
is( $zip->read(File::Spec->catfile('t', 'data', 'jar.zip')), AZ_OK, 'Read file' );
my $ret = eval { $zip->writeToFileNamed(OUTPUTZIP) };
is($ret, AZ_OK, 'Wrote file');
my ($status, $zipout) = testZip();
# STDERR->print("status= $status, out=$zipout\n");
SKIP: {
skip( "test zip doesn't work", 1 ) if $testZipDoesntWork;
is( $status, 0, "output zip isn't corrupted" );
}
t/common.pm view on Meta::CPAN
# 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;
t/common.pm view on Meta::CPAN
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`;
my $res = ($? != 0 && $? != -1) ? $? : 0;
return wantarray ? ($res, $zipout) : $res;
}
t/common.pm view on Meta::CPAN
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");
}
}
}
( run in 0.433 second using v1.01-cache-2.11-cpan-4e96b696675 )