Add ARM files
[dh-make-perl] / dev / arm / libarchive-zip-perl / libarchive-zip-perl-1.18 / t / 06_update.t
1 #!/usr/bin/perl -w
2
3 # Test Archive::Zip updating
4
5 use strict;
6 use File::Spec ();
7 use IO::File   ();
8 use File::Find ();
9 use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
10
11 use Test::More tests => 12;
12 BEGIN {
13     unshift @INC, "t/"; 
14     require( File::Spec->catfile('t', 'common.pl') )
15                 or die "Can't load t/common.pl";
16 }
17
18 my ($testFileVolume, $testFileDirs, $testFileName) = File::Spec->splitpath($0);
19
20 my $zip = Archive::Zip->new();
21 my $testDir = File::Spec->catpath( $testFileVolume, $testFileDirs, '' );
22
23 my $numberOfMembers = 0;
24 my @memberNames;
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');
29
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' );
33
34 my $firstFile = $memberNames[0];
35 my $firstMember = ($zip->members())[0];
36
37 is( $firstFile, $firstMember->fileName(), 'member name wrong');
38
39 # add a file to the directory
40 $testFileName = File::Spec->catpath( $testFileVolume, $testFileDirs, 'xxxxxx' );
41 my $fh = IO::File->new( $testFileName, 'w');
42 $fh->print('xxxx');
43 undef($fh);
44 is( -f $testFileName, 1, "creating $testFileName failed");
45
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' );
49
50 # Delete the file.
51 unlink($testFileName);
52 is( -f $testFileName, undef, "deleting $testFileName failed");
53
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' );
57
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' );