~ubuntu-branches/ubuntu/intrepid/horae/intrepid

« back to all changes in this revision

Viewing changes to 0CPAN/Archive-Zip-1.16/t/testUpdate.t

  • Committer: Bazaar Package Importer
  • Author(s): Carlo Segre
  • Date: 2008-02-23 23:13:02 UTC
  • mfrom: (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080223231302-mnyyxs3icvrus4ke
Tags: 066-3
Apply patch to athena_parts/misc.pl for compatibility with 
perl-tk 804.28.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Test Archive::Zip updating
2
 
# $Revision: 1.1 $
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
6
 
 
7
 
$^W = 1;
8
 
$| = 1;
9
 
use strict;
10
 
use Test;
11
 
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
12
 
use IO::File;
13
 
use File::Spec 0.8;
14
 
use File::Find ();
15
 
 
16
 
BEGIN { plan tests => 12, todo => [] }
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
 
ok( $numberOfMembers > 1, 1, 'not enough members to test');
29
 
 
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' );
33
 
 
34
 
my $firstFile = $memberNames[0];
35
 
my $firstMember = ($zip->members())[0];
36
 
 
37
 
ok( $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
 
ok( -f $testFileName, 1, "creating $testFileName failed");
45
 
 
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' );
49
 
 
50
 
# Delete the file.
51
 
unlink($testFileName);
52
 
ok( -f $testFileName, undef, "deleting $testFileName failed");
53
 
 
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' );
57
 
 
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' );
61