Debian lenny version packages
[pkg-perl] / deb-src / libarchive-zip-perl / libarchive-zip-perl-1.18 / t / 03_ex.t
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
5 use File::Spec;
6 use IO::File;
7
8 use Test::More tests => 17;
9 BEGIN {
10     unshift @INC, "t/"; 
11     require( File::Spec->catfile('t', 'common.pl') )
12                 or die "Can't load t/common.pl";
13 }
14
15 sub runPerlCommand
16 {
17         my $libs = join ( ' -I', @INC );
18         my $cmd    = "\"$^X\" \"-I$libs\" -w \"". join('" "', @_). '"';
19         my $output = `$cmd`;
20         return wantarray ? ( $?, $output ) : $?;
21 }
22
23 use constant FILENAME => File::Spec->catpath( '', TESTDIR, 'testing.txt' );
24 use constant ZFILENAME => TESTDIR . "/testing.txt"; # name in zip
25
26 my $zip = Archive::Zip->new();
27 isa_ok( $zip, 'Archive::Zip' );
28 $zip->addString( TESTSTRING, FILENAME );
29 $zip->writeToFileNamed(INPUTZIP);
30
31 my ( $status, $output );
32 my $fh = IO::File->new( "test.log", "w" );
33 isa_ok( $fh, 'IO::File' );
34
35 is( runPerlCommand( 'examples/copy.pl', INPUTZIP, OUTPUTZIP ), 0 );
36
37 is( runPerlCommand( 'examples/extract.pl', OUTPUTZIP, ZFILENAME ), 0 );
38
39 is( runPerlCommand( 'examples/mfh.pl', INPUTZIP ), 0 );
40
41 is( runPerlCommand( 'examples/zip.pl', OUTPUTZIP, INPUTZIP, FILENAME ), 0 );
42
43 ( $status, $output ) = runPerlCommand( 'examples/zipinfo.pl', INPUTZIP );
44 is( $status, 0 );
45 $fh->print("zipinfo output:\n");
46 $fh->print($output);
47
48 ( $status, $output ) = runPerlCommand( 'examples/ziptest.pl', INPUTZIP );
49 is( $status, 0 );
50 $fh->print("ziptest output:\n");
51 $fh->print($output);
52
53 ( $status, $output ) = runPerlCommand( 'examples/zipGrep.pl', '100', INPUTZIP );
54 is( $status, 0 );
55 is( $output, ZFILENAME . ":100\n" );
56
57 # calcSizes.pl
58 # creates test.zip, may be sensitive to /dev/null
59
60 # removed because requires IO::Scalar
61 # ok( runPerlCommand('examples/readScalar.pl'), 0 );
62
63 unlink(OUTPUTZIP);
64 is( runPerlCommand( 'examples/selfex.pl', OUTPUTZIP, FILENAME ), 0 );
65 unlink(FILENAME);
66 is( runPerlCommand(OUTPUTZIP), 0 );
67 my $fn =
68   File::Spec->catpath( '', File::Spec->catdir( 'extracted', TESTDIR ),
69         'testing.txt' );
70 is( -f $fn, 1, "$fn exists" );
71
72 # unzipAll.pl
73 # updateZip.pl
74 # writeScalar.pl
75 # zipcheck.pl
76 # ziprecent.pl
77
78 unlink(OUTPUTZIP);
79 is( runPerlCommand( 'examples/updateTree.pl', OUTPUTZIP, TESTDIR ), 0, "updateTree.pl create" );
80 is( -f OUTPUTZIP, 1, "zip created" );
81 is( runPerlCommand( 'examples/updateTree.pl', OUTPUTZIP, TESTDIR ), 0, "updateTree.pl update" );
82 is( -f OUTPUTZIP, 1, "zip updated" );
83 unlink(OUTPUTZIP);