3 # Test Archive::Zip updating
9 use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
11 use Test::More tests => 12;
14 require( File::Spec->catfile('t', 'common.pl') )
15 or die "Can't load t/common.pl";
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 is( $numberOfMembers > 1, 1, 'not enough members to test');
30 # an initial updateTree() should act like an addTree()
31 is( $zip->updateTree( $testDir ), AZ_OK, 'initial updateTree failed' );
32 is( scalar($zip->members()), $numberOfMembers, 'wrong number of members after create' );
34 my $firstFile = $memberNames[0];
35 my $firstMember = ($zip->members())[0];
37 is( $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 is( -f $testFileName, 1, "creating $testFileName failed");
46 # Then update it. It should be added.
47 is( $zip->updateTree( $testDir ), AZ_OK, 'updateTree failed' );
48 is( scalar($zip->members()), $numberOfMembers + 1, 'wrong number of members after update' );
51 unlink($testFileName);
52 is( -f $testFileName, undef, "deleting $testFileName failed");
54 # updating without the mirror option should keep the members
55 is( $zip->updateTree( $testDir ), AZ_OK, 'updateTree failed' );
56 is( 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 is( $zip->updateTree( $testDir, undef, undef, 1 ), AZ_OK, 'updateTree failed' );
60 is( scalar($zip->members()), $numberOfMembers, 'wrong number of members after mirror' );