2 * Copyright 1999-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
10 /* Internal tests for the asn1 module */
15 #include <openssl/asn1.h>
16 #include <openssl/evp.h>
17 #include <openssl/objects.h>
22 const char *test_case_name;
23 const char *test_section;
26 /**********************************************************************
28 * Test of a_strnid's tbl_standard
32 static SIMPLE_FIXTURE setup_tbl_standard(const char *const test_case_name)
34 SIMPLE_FIXTURE fixture;
35 fixture.test_case_name = test_case_name;
39 #include "../crypto/asn1/tbl_standard.h"
41 static int execute_tbl_standard(SIMPLE_FIXTURE fixture)
43 const ASN1_STRING_TABLE *tmp;
47 for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++) {
48 if (tmp->nid < last_nid) {
56 fprintf(stderr, "%s: Table order OK\n", fixture.test_section);
60 for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++)
61 fprintf(stderr, "%s: Index %" OSSLzu ", NID %d, Name=%s\n",
62 fixture.test_section, i, tmp->nid, OBJ_nid2ln(tmp->nid));
67 static void teardown_tbl_standard(SIMPLE_FIXTURE fixture)
71 /**********************************************************************
73 * Test of ameth_lib's standard_methods
77 static SIMPLE_FIXTURE setup_standard_methods(const char *const test_case_name)
79 SIMPLE_FIXTURE fixture;
80 fixture.test_case_name = test_case_name;
84 #include "internal/asn1_int.h"
85 #include "../crypto/asn1/standard_methods.h"
87 static int execute_standard_methods(SIMPLE_FIXTURE fixture)
89 const EVP_PKEY_ASN1_METHOD **tmp;
90 int last_pkey_id = -1;
93 for (tmp = standard_methods, i = 0; i < OSSL_NELEM(standard_methods);
95 if ((*tmp)->pkey_id < last_pkey_id) {
99 last_pkey_id = (*tmp)->pkey_id;
102 if (last_pkey_id != 0) {
103 fprintf(stderr, "%s: Table order OK\n", fixture.test_section);
107 for (tmp = standard_methods, i = 0; i < OSSL_NELEM(standard_methods);
109 fprintf(stderr, "%s: Index %" OSSLzu ", pkey ID %d, Name=%s\n",
110 fixture.test_section, i, (*tmp)->pkey_id,
111 OBJ_nid2sn((*tmp)->pkey_id));
116 static void teardown_standard_methods(SIMPLE_FIXTURE fixture)
120 /**********************************************************************
128 SIMPLE_FIXTURE (*setup)(const char *const test_case_name);
129 int (*execute)(SIMPLE_FIXTURE);
130 void (*teardown)(SIMPLE_FIXTURE);
132 {"asn1 tlb_standard", setup_tbl_standard, execute_tbl_standard,
133 teardown_tbl_standard},
134 {"asn1 standard_methods", setup_standard_methods, execute_standard_methods,
135 teardown_standard_methods}
138 static int drive_tests(int idx)
140 SETUP_TEST_FIXTURE(SIMPLE_FIXTURE, tests[idx].setup);
141 fixture.test_section = tests[idx].section;
142 EXECUTE_TEST(tests[idx].execute, tests[idx].teardown);
145 int main(int argc, char **argv)
147 ADD_ALL_TESTS(drive_tests, OSSL_NELEM(tests));
149 return run_tests(argv[0]);