2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-01 11:22:29 +00:00
qpdf/libtests/qtest/rc4.test
Jay Berkenbilt 1639d972ea Run libtests for crypto with all available providers
If QPDF_CRYPTO_PROVIDER is set, just run the tests for the given
provider. This is to support cases of running the entire test suite
for each provider. If QPDF_CRYPTO_PROVIDER is not set, run the tests
that exercise the cyrpto provider for each available provider.
2019-11-09 09:53:42 -05:00

71 lines
1.7 KiB
Perl

#!/usr/bin/env perl
require 5.008;
BEGIN { $^W = 1; }
use strict;
chdir("rc4") or die "chdir testdir failed: $!\n";
require TestDriver;
my $td = new TestDriver('RC4');
my @providers = ();
if (exists $ENV{'QPDF_CRYPTO_PROVIDER'})
{
push(@providers, $ENV{'QPDF_CRYPTO_PROVIDER'});
}
else
{
open(Q, "qpdf --show-crypto|") or die;
while (<Q>)
{
s/\s+$//s;
push(@providers, $_);
}
close(Q);
}
my @tests = ('0123456789abcdef',
'0123456789abcdef',
'0000000000000000',
'ef012345',
'0123456789abcdef');
foreach my $p (@providers)
{
$ENV{'QPDF_CRYPTO_PROVIDER'} = $p;
cleanup();
my $n = 0;
foreach my $key (@tests)
{
++$n;
$td->runtest("test $n ($p)",
{$td->COMMAND => "rc4 $key test$n.in tmp1-$n.out"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
{$td->FILE => "tmp1-$n.out"},
{$td->FILE => "test$n.out"});
$td->runtest("test $n reverse ($p)",
{$td->COMMAND => "rc4 $key test$n.out tmp2-$n.out"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
{$td->FILE => "tmp2-$n.out"},
{$td->FILE => "test$n.in"});
}
$td->runtest("other tests ($p)",
{$td->COMMAND => "rc4 other"},
{$td->STRING => "passed\n", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
cleanup();
}
$td->report((1 + (4 * scalar(@tests))) * scalar(@providers));
sub cleanup
{
system("rm -f tmp*-*");
}