VMS: Fix internals test programs
[openssl.git] / test / asn1_internal_test.c
1 /*
2  * Copyright 1999-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 the asn1 module */
11
12 #include <stdio.h>
13 #include <string.h>
14
15 #include <openssl/asn1.h>
16 #include <openssl/evp.h>
17 #include <openssl/objects.h>
18 #include "test_main.h"
19 #include "testutil.h"
20 #include "e_os.h"
21
22 /**********************************************************************
23  *
24  * Test of a_strnid's tbl_standard
25  *
26  ***/
27
28 #include "../crypto/asn1/tbl_standard.h"
29
30 static int test_tbl_standard()
31 {
32     const ASN1_STRING_TABLE *tmp;
33     int last_nid = -1;
34     size_t i;
35
36     for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++) {
37         if (tmp->nid < last_nid) {
38             last_nid = 0;
39             break;
40         }
41         last_nid = tmp->nid;
42     }
43
44     if (last_nid != 0) {
45         fprintf(stderr, "asn1 tbl_standard: Table order OK\n");
46         return 1;
47     }
48
49     for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++)
50         fprintf(stderr, "asn1 tbl_standard: Index %" OSSLzu ", NID %d, Name=%s\n",
51                 i, tmp->nid, OBJ_nid2ln(tmp->nid));
52
53     return 0;
54 }
55
56 /**********************************************************************
57  *
58  * Test of ameth_lib's standard_methods
59  *
60  ***/
61
62 #ifdef __VMS
63 # pragma names save
64 # pragma names as_is,shortened
65 #endif
66
67 #include "internal/asn1_int.h"
68
69 #ifdef __VMS
70 # pragma names restore
71 #endif
72
73 #include "../crypto/asn1/standard_methods.h"
74
75 static int test_standard_methods()
76 {
77     const EVP_PKEY_ASN1_METHOD **tmp;
78     int last_pkey_id = -1;
79     size_t i;
80
81     for (tmp = standard_methods, i = 0; i < OSSL_NELEM(standard_methods);
82          i++, tmp++) {
83         if ((*tmp)->pkey_id < last_pkey_id) {
84             last_pkey_id = 0;
85             break;
86         }
87         last_pkey_id = (*tmp)->pkey_id;
88     }
89
90     if (last_pkey_id != 0) {
91         fprintf(stderr, "asn1 standard methods: Table order OK\n");
92         return 1;
93     }
94
95     TEST_error("asn1 standard methods out of order");
96     for (tmp = standard_methods, i = 0; i < OSSL_NELEM(standard_methods);
97          i++, tmp++)
98         fprintf(stderr, "asn1 standard methods: Index %" OSSLzu
99                 ", pkey ID %d, Name=%s\n", i, (*tmp)->pkey_id,
100                 OBJ_nid2sn((*tmp)->pkey_id));
101
102     return 0;
103 }
104
105 void register_tests(void)
106 {
107     ADD_TEST(test_tbl_standard);
108     ADD_TEST(test_standard_methods);
109 }