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