~ubuntu-branches/ubuntu/vivid/libarchive-zip-perl/vivid-proposed

« back to all changes in this revision

Viewing changes to t/testex.t

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2004-10-30 22:19:15 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20041030221915-gtxn2xoojblyekyh
Tags: 1.14-1
* New upstream version.
  - Fixes: Archive::Zip is fooled by manipulated ZIP directory
    Closes: #277773.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Test examples
2
 
# $Revision: 1.3 $
 
2
# $Revision: 1.9 $
3
3
# Before `make install' is performed this script should be runnable with
4
4
# `make test'. After `make install' it should work as `perl t/testex.t'
5
5
# vim: ts=4 sw=4 ft=perl
6
6
 
7
7
$^W = 1;
8
 
$| = 1;
 
8
$|  = 1;
9
9
use strict;
10
10
use Test;
11
11
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
12
 
use FileHandle;
 
12
use File::Spec;
 
13
use IO::File;
13
14
 
14
 
BEGIN { plan tests => 6, todo => [] }
 
15
BEGIN { plan tests => 15, todo => [] }
15
16
 
16
17
BEGIN { require 't/common.pl' }
17
18
 
18
19
sub runPerlCommand
19
20
{
20
 
        my $libs = join(' -I', @INC);
21
 
        my $cmd = "$^X -I$libs -w @_";
22
 
        my $output = qx($cmd);
23
 
        return wantarray ? ($?, $output) : $?;
 
21
        my $libs = join ( ' -I', @INC );
 
22
        my $cmd    = "\"$^X\" \"-I$libs\" -w \"". join('" "', @_). '"';
 
23
        my $output = `$cmd`;
 
24
        return wantarray ? ( $?, $output ) : $?;
24
25
}
25
26
 
26
 
use constant FILENAME => TESTDIR . 'testing.txt';
 
27
use constant FILENAME => File::Spec->catpath( '', TESTDIR, 'testing.txt' );
 
28
use constant ZFILENAME => TESTDIR . "/testing.txt"; # name in zip
 
29
 
27
30
my $zip = Archive::Zip->new();
28
 
$zip->addString(TESTSTRING, FILENAME);
 
31
$zip->addString( TESTSTRING, FILENAME );
29
32
$zip->writeToFileNamed(INPUTZIP);
30
33
 
31
 
my ($status, $output);
32
 
my $fh = FileHandle->new("test.log", "w");
33
 
 
34
 
ok(runPerlCommand( 'examples/copy.pl', INPUTZIP, OUTPUTZIP ), 0);
35
 
ok(runPerlCommand( 'examples/extract.pl', OUTPUTZIP,  FILENAME), 0);
36
 
ok(runPerlCommand( 'examples/mfh.pl', INPUTZIP ), 0);
37
 
ok(runPerlCommand( 'examples/zip.pl', OUTPUTZIP, INPUTZIP, FILENAME ), 0);
38
 
($status, $output) = runPerlCommand( 'examples/zipinfo.pl', INPUTZIP );
39
 
ok($status, 0);
 
34
my ( $status, $output );
 
35
my $fh = IO::File->new( "test.log", "w" );
 
36
 
 
37
ok( runPerlCommand( 'examples/copy.pl', INPUTZIP, OUTPUTZIP ), 0 );
 
38
 
 
39
ok( runPerlCommand( 'examples/extract.pl', OUTPUTZIP, ZFILENAME ), 0 );
 
40
 
 
41
ok( runPerlCommand( 'examples/mfh.pl', INPUTZIP ), 0 );
 
42
 
 
43
ok( runPerlCommand( 'examples/zip.pl', OUTPUTZIP, INPUTZIP, FILENAME ), 0 );
 
44
 
 
45
( $status, $output ) = runPerlCommand( 'examples/zipinfo.pl', INPUTZIP );
 
46
ok( $status, 0 );
40
47
$fh->print("zipinfo output:\n");
41
48
$fh->print($output);
42
 
($status, $output) = runPerlCommand( 'examples/ziptest.pl', INPUTZIP );
43
 
ok($status, 0);
 
49
 
 
50
( $status, $output ) = runPerlCommand( 'examples/ziptest.pl', INPUTZIP );
 
51
ok( $status, 0 );
44
52
$fh->print("ziptest output:\n");
45
53
$fh->print($output);
 
54
 
 
55
( $status, $output ) = runPerlCommand( 'examples/zipGrep.pl', '100', INPUTZIP );
 
56
ok( $status, 0 );
 
57
ok( $output, ZFILENAME . ":100\n" );
 
58
 
 
59
# calcSizes.pl
 
60
# creates test.zip, may be sensitive to /dev/null
 
61
 
 
62
# removed because requires IO::Scalar
 
63
# ok( runPerlCommand('examples/readScalar.pl'), 0 );
 
64
 
 
65
unlink(OUTPUTZIP);
 
66
ok( runPerlCommand( 'examples/selfex.pl', OUTPUTZIP, FILENAME ), 0 );
 
67
unlink(FILENAME);
 
68
ok( runPerlCommand(OUTPUTZIP), 0 );
 
69
my $fn =
 
70
  File::Spec->catpath( '', File::Spec->catdir( 'extracted', TESTDIR ),
 
71
        'testing.txt' );
 
72
ok( -f $fn, 1, "$fn exists" );
 
73
 
 
74
# unzipAll.pl
 
75
# updateZip.pl
 
76
# writeScalar.pl
 
77
# zipcheck.pl
 
78
# ziprecent.pl
 
79
 
 
80
unlink(OUTPUTZIP);
 
81
ok( runPerlCommand( 'examples/updateTree.pl', OUTPUTZIP, TESTDIR ), 0, "updateTree.pl create" );
 
82
ok( -f OUTPUTZIP, 1, "zip created" );
 
83
ok( runPerlCommand( 'examples/updateTree.pl', OUTPUTZIP, TESTDIR ), 0, "updateTree.pl update" );
 
84
ok( -f OUTPUTZIP, 1, "zip updated" );
 
85
unlink(OUTPUTZIP);