Add and use function test_pem to work out test filenames.
[openssl.git] / test / pkey_meth_test.c
1 /*
2  * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
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
8  */
9
10 /* Internal tests for EVP_PKEY method ordering */
11
12 #include <stdio.h>
13 #include <string.h>
14
15 #include <openssl/evp.h>
16 #include "testutil.h"
17 #include "test_main.h"
18
19 /**********************************************************************
20  *
21  * Test of EVP_PKEY_ASN1 method ordering
22  *
23  ***/
24
25 static int test_asn1_meths()
26 {
27     int i;
28     int prev = -1;
29     int good = 1;
30     int pkey_id;
31     const EVP_PKEY_ASN1_METHOD *ameth;
32
33     for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
34         ameth = EVP_PKEY_asn1_get0(i);
35         EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, ameth);
36         if (pkey_id < prev)
37             good = 0;
38         prev = pkey_id;
39
40     }
41     if (!good) {
42         fprintf(stderr, "EVP_PKEY_ASN1_METHOD table out of order!\n");
43         for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
44             const char *info;
45
46             ameth = EVP_PKEY_asn1_get0(i);
47             EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, &info, NULL, ameth);
48             if (info == NULL)
49                 info = "<NO NAME>";
50             fprintf(stderr, "%d : %s : %s\n", pkey_id, OBJ_nid2ln(pkey_id),
51                     info);
52         }
53     } else {
54         fprintf(stderr, "Order OK\n");
55     }
56
57     return good;
58 }
59
60 void register_tests()
61 {
62     ADD_TEST(test_asn1_meths);
63 }