1 # Shared defs for test programs
3 # Paths. Must make case-insensitive.
4 use constant TESTDIR
=> 'testdir';
5 use constant INPUTZIP
=> 'testin.zip';
6 use constant OUTPUTZIP
=> 'testout.zip';
8 use constant ZIP
=> 'zip ';
9 use constant ZIPTEST
=> 'unzip -t ';
11 # 300-character test string
12 use constant TESTSTRING
=> join ( "\n", 1 .. 102 ) . "\n";
13 use constant TESTSTRINGLENGTH
=> length(TESTSTRING
);
15 # CRC-32 should be ac373f32
16 use constant TESTSTRINGCRC
=> Archive
::Zip
::computeCRC32
(TESTSTRING
);
18 # This is so that it will work on other systems.
19 use constant CAT
=> $^X
. ' -pe "BEGIN{binmode(STDIN);binmode(STDOUT)}"';
20 use constant CATPIPE
=> '| ' . CAT
. ' >';
22 use vars
qw($zipWorks $testZipDoesntWork $catWorks);
23 local ( $zipWorks, $testZipDoesntWork, $catWorks );
25 # Run ZIPTEST to test a zip file.
28 my $zipName = shift || OUTPUTZIP;
29 if ($testZipDoesntWork)
31 return wantarray ? ( 0, '' ) : 0;
33 my $cmd = ZIPTEST . $zipName . ( $^O eq 'MSWin32' ? '' : ' 2>&1' );
35 return wantarray ? ( $?, $zipout ) : $?;
38 # Return the crc-32 of the given file (0 if empty or error)
43 my $fh = IO::File->new( $fileName, "r" );
45 return 0 if not defined($fh);
47 return Archive::Zip::computeCRC32($contents);
50 #--------- check to see if cat works
54 my $fh = IO::File->new( CATPIPE . OUTPUTZIP );
56 my $testString = pack( 'C256', 0 .. 255 );
57 my $testCrc = Archive::Zip::computeCRC32($testString);
58 $fh->write( $testString, length($testString) ) or return 0;
60 ( -f OUTPUTZIP ) or return 0;
61 my @stat = stat(OUTPUTZIP);
62 $stat[7] == length($testString) or return 0;
63 fileCRC(OUTPUTZIP) == $testCrc or return 0;
70 $catWorks = testCat();
71 warn( 'warning: ', CAT, " doesn't seem to work, may skip some tests" )
75 #--------- check to see if zip works (and make INPUTZIP)
80 my $cmd = ZIP . INPUTZIP . ' *' . ( $^O eq 'MSWin32' ? '' : ' 2>&1' );
83 warn( 'warning: ', ZIP, " doesn't seem to work, may skip some tests" )
87 #--------- check to see if unzip -t works
91 $testZipDoesntWork = 0;
92 my ( $status, $zipout ) = testZip(INPUTZIP);
93 $testZipDoesntWork = $status;
94 warn( 'warning: ', ZIPTEST, " doesn't seem to work, may skip some tests" )
95 if $testZipDoesntWork;