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.
27 defined($conversionforms{$testtype}) ?
28 @{$conversionforms{$testtype}} :
29 @{$conversionforms{"*"}};
30 my @openssl_args = @_;
31 if (!@openssl_args) { @openssl_args = ($testtype); }
33 my $n = scalar @conversionforms;
36 + $n # initial conversions from p to all forms (A)
37 + $n*$n # conversion from result of A to all forms (B)
38 + 1 # comparing original test file to p form of A
39 + $n*($n-1); # comparing first conversion to each fom in A with B
40 $totaltests-- if ($testtype eq "p7d"); # no comparison of original test file
41 plan tests => $totaltests;
43 my @cmd = ("openssl", @openssl_args);
46 if (scalar @openssl_args > 0 && $openssl_args[0] eq "pkey") {
47 $init = ok(run(app([@cmd, "-in", $t, "-out", "$testtype-fff.p"])),
50 $init = ok(copy($t, "$testtype-fff.p"), 'initializing');
53 diag("Trying to copy $t to $testtype-fff.p : $!");
57 skip "Not initialized, skipping...", 22 unless $init;
59 foreach my $to (@conversionforms) {
61 "-in", "$testtype-fff.p",
63 "-out", "$testtype-f.$to",
68 foreach my $to (@conversionforms) {
69 foreach my $from (@conversionforms) {
71 "-in", "$testtype-f.$from",
73 "-out", "$testtype-ff.$from$to",
79 if ($testtype ne "p7d") {
80 is(cmp_text("$testtype-fff.p", "$testtype-f.p"), 0,
81 'comparing orig to p');
84 foreach my $to (@conversionforms) {
86 foreach my $from (@conversionforms) {
87 is(cmp_text("$testtype-f.$to", "$testtype-ff.$from$to"), 0,
88 "comparing $to to $from$to");
92 unlink glob "$testtype-f.*";
93 unlink glob "$testtype-ff.*";
94 unlink glob "$testtype-fff.*";
98 return compare_text(@_, sub {
101 return $_[0] ne $_[1];