2 # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
13 use File::Compare qw/compare_text/;
16 use OpenSSL::Test qw/:DEFAULT/;
18 my %conversionforms = (
19 # Default conversion forms. Other series may be added with
20 # specific test types as key.
22 "msb" => [ "d", "p", "msblob" ],
28 defined($conversionforms{$testtype}) ?
29 @{$conversionforms{$testtype}} :
30 @{$conversionforms{"*"}};
31 my @openssl_args = @_;
32 if (!@openssl_args) { @openssl_args = ($testtype); }
34 my $n = scalar @conversionforms;
37 + $n # initial conversions from p to all forms (A)
38 + $n*$n # conversion from result of A to all forms (B)
39 + 1 # comparing original test file to p form of A
40 + $n*($n-1); # comparing first conversion to each fom in A with B
41 $totaltests-- if ($testtype eq "p7d"); # no comparison of original test file
42 plan tests => $totaltests;
44 my @cmd = ("openssl", @openssl_args);
47 if (scalar @openssl_args > 0 && $openssl_args[0] eq "pkey") {
48 $init = ok(run(app([@cmd, "-in", $t, "-out", "$testtype-fff.p"])),
51 $init = ok(copy($t, "$testtype-fff.p"), 'initializing');
54 diag("Trying to copy $t to $testtype-fff.p : $!");
58 skip "Not initialized, skipping...", 22 unless $init;
60 foreach my $to (@conversionforms) {
62 "-in", "$testtype-fff.p",
64 "-out", "$testtype-f.$to",
69 foreach my $to (@conversionforms) {
70 foreach my $from (@conversionforms) {
72 "-in", "$testtype-f.$from",
74 "-out", "$testtype-ff.$from$to",
80 if ($testtype ne "p7d") {
81 is(cmp_text("$testtype-fff.p", "$testtype-f.p"), 0,
82 'comparing orig to p');
85 foreach my $to (@conversionforms) {
87 foreach my $from (@conversionforms) {
88 is(cmp_text("$testtype-f.$to", "$testtype-ff.$from$to"), 0,
89 "comparing $to to $from$to");
93 unlink glob "$testtype-f.*";
94 unlink glob "$testtype-ff.*";
95 unlink glob "$testtype-fff.*";
99 return compare_text(@_, sub {
102 return $_[0] ne $_[1];