1
# Test Archive::Zip updating
3
# Before `make install' is performed this script should be runnable with
4
# `make test'. After `make install' it should work as `perl t/testUpdate.t'
5
# vim: set ts=4 sw=4 ft=perl
11
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
16
BEGIN { plan tests => 12, todo => [] }
18
my ($testFileVolume, $testFileDirs, $testFileName) = File::Spec->splitpath($0);
20
my $zip = Archive::Zip->new();
21
my $testDir = File::Spec->catpath( $testFileVolume, $testFileDirs, '' );
23
my $numberOfMembers = 0;
25
sub countMembers { unless ($_ eq '.')
26
{ push(@memberNames, $_); $numberOfMembers++; } };
27
File::Find::find( \&countMembers, $testDir );
28
ok( $numberOfMembers > 1, 1, 'not enough members to test');
30
# an initial updateTree() should act like an addTree()
31
ok( $zip->updateTree( $testDir ), AZ_OK, 'initial updateTree failed' );
32
ok( scalar($zip->members()), $numberOfMembers, 'wrong number of members after create' );
34
my $firstFile = $memberNames[0];
35
my $firstMember = ($zip->members())[0];
37
ok( $firstFile, $firstMember->fileName(), 'member name wrong');
39
# add a file to the directory
40
$testFileName = File::Spec->catpath( $testFileVolume, $testFileDirs, 'xxxxxx' );
41
my $fh = IO::File->new( $testFileName, 'w');
44
ok( -f $testFileName, 1, "creating $testFileName failed");
46
# Then update it. It should be added.
47
ok( $zip->updateTree( $testDir ), AZ_OK, 'updateTree failed' );
48
ok( scalar($zip->members()), $numberOfMembers + 1, 'wrong number of members after update' );
51
unlink($testFileName);
52
ok( -f $testFileName, undef, "deleting $testFileName failed");
54
# updating without the mirror option should keep the members
55
ok( $zip->updateTree( $testDir ), AZ_OK, 'updateTree failed' );
56
ok( scalar($zip->members()), $numberOfMembers + 1, 'wrong number of members after update' );
58
# now try again with the mirror option; should delete the last file.
59
ok( $zip->updateTree( $testDir, undef, undef, 1 ), AZ_OK, 'updateTree failed' );
60
ok( scalar($zip->members()), $numberOfMembers, 'wrong number of members after mirror' );