1*e0c4386eSCy Schubert /*
2*e0c4386eSCy Schubert * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
3*e0c4386eSCy Schubert *
4*e0c4386eSCy Schubert * Licensed under the Apache License 2.0 (the "License"). You may not use
5*e0c4386eSCy Schubert * this file except in compliance with the License. You can obtain a copy
6*e0c4386eSCy Schubert * in the file LICENSE in the source distribution or at
7*e0c4386eSCy Schubert * https://www.openssl.org/source/license.html
8*e0c4386eSCy Schubert */
9*e0c4386eSCy Schubert
10*e0c4386eSCy Schubert /* Tests for the ASN1_STRING_TABLE_* functions */
11*e0c4386eSCy Schubert
12*e0c4386eSCy Schubert #include <stdio.h>
13*e0c4386eSCy Schubert #include <string.h>
14*e0c4386eSCy Schubert
15*e0c4386eSCy Schubert #include <openssl/asn1.h>
16*e0c4386eSCy Schubert #include "testutil.h"
17*e0c4386eSCy Schubert
test_string_tbl(void)18*e0c4386eSCy Schubert static int test_string_tbl(void)
19*e0c4386eSCy Schubert {
20*e0c4386eSCy Schubert const ASN1_STRING_TABLE *tmp = NULL;
21*e0c4386eSCy Schubert int nid = 12345678, nid2 = 87654321, rv = 0, ret = 0;
22*e0c4386eSCy Schubert
23*e0c4386eSCy Schubert tmp = ASN1_STRING_TABLE_get(nid);
24*e0c4386eSCy Schubert if (!TEST_ptr_null(tmp)) {
25*e0c4386eSCy Schubert TEST_info("asn1 string table: ASN1_STRING_TABLE_get non-exist nid");
26*e0c4386eSCy Schubert goto out;
27*e0c4386eSCy Schubert }
28*e0c4386eSCy Schubert
29*e0c4386eSCy Schubert ret = ASN1_STRING_TABLE_add(nid, -1, -1, MBSTRING_ASC, 0);
30*e0c4386eSCy Schubert if (!TEST_true(ret)) {
31*e0c4386eSCy Schubert TEST_info("asn1 string table: add NID(%d) failed", nid);
32*e0c4386eSCy Schubert goto out;
33*e0c4386eSCy Schubert }
34*e0c4386eSCy Schubert
35*e0c4386eSCy Schubert ret = ASN1_STRING_TABLE_add(nid2, -1, -1, MBSTRING_ASC, 0);
36*e0c4386eSCy Schubert if (!TEST_true(ret)) {
37*e0c4386eSCy Schubert TEST_info("asn1 string table: add NID(%d) failed", nid2);
38*e0c4386eSCy Schubert goto out;
39*e0c4386eSCy Schubert }
40*e0c4386eSCy Schubert
41*e0c4386eSCy Schubert tmp = ASN1_STRING_TABLE_get(nid);
42*e0c4386eSCy Schubert if (!TEST_ptr(tmp)) {
43*e0c4386eSCy Schubert TEST_info("asn1 string table: get NID(%d) failed", nid);
44*e0c4386eSCy Schubert goto out;
45*e0c4386eSCy Schubert }
46*e0c4386eSCy Schubert
47*e0c4386eSCy Schubert tmp = ASN1_STRING_TABLE_get(nid2);
48*e0c4386eSCy Schubert if (!TEST_ptr(tmp)) {
49*e0c4386eSCy Schubert TEST_info("asn1 string table: get NID(%d) failed", nid2);
50*e0c4386eSCy Schubert goto out;
51*e0c4386eSCy Schubert }
52*e0c4386eSCy Schubert
53*e0c4386eSCy Schubert ASN1_STRING_TABLE_cleanup();
54*e0c4386eSCy Schubert
55*e0c4386eSCy Schubert /* check if all newly added NIDs are cleaned up */
56*e0c4386eSCy Schubert tmp = ASN1_STRING_TABLE_get(nid);
57*e0c4386eSCy Schubert if (!TEST_ptr_null(tmp)) {
58*e0c4386eSCy Schubert TEST_info("asn1 string table: get NID(%d) failed", nid);
59*e0c4386eSCy Schubert goto out;
60*e0c4386eSCy Schubert }
61*e0c4386eSCy Schubert
62*e0c4386eSCy Schubert tmp = ASN1_STRING_TABLE_get(nid2);
63*e0c4386eSCy Schubert if (!TEST_ptr_null(tmp)) {
64*e0c4386eSCy Schubert TEST_info("asn1 string table: get NID(%d) failed", nid2);
65*e0c4386eSCy Schubert goto out;
66*e0c4386eSCy Schubert }
67*e0c4386eSCy Schubert
68*e0c4386eSCy Schubert rv = 1;
69*e0c4386eSCy Schubert out:
70*e0c4386eSCy Schubert return rv;
71*e0c4386eSCy Schubert }
72*e0c4386eSCy Schubert
setup_tests(void)73*e0c4386eSCy Schubert int setup_tests(void)
74*e0c4386eSCy Schubert {
75*e0c4386eSCy Schubert ADD_TEST(test_string_tbl);
76*e0c4386eSCy Schubert return 1;
77*e0c4386eSCy Schubert }
78