113d40330Schristos /*
213d40330Schristos * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
313d40330Schristos *
4*b0d17251Schristos * Licensed under the Apache License 2.0 (the "License"). You may not use
513d40330Schristos * this file except in compliance with the License. You can obtain a copy
613d40330Schristos * in the file LICENSE in the source distribution or at
713d40330Schristos * https://www.openssl.org/source/license.html
813d40330Schristos */
913d40330Schristos
10*b0d17251Schristos /* Tests for the ASN1_STRING_TABLE_* functions */
1113d40330Schristos
1213d40330Schristos #include <stdio.h>
1313d40330Schristos #include <string.h>
1413d40330Schristos
1513d40330Schristos #include <openssl/asn1.h>
1613d40330Schristos #include "testutil.h"
1713d40330Schristos
test_string_tbl(void)1813d40330Schristos static int test_string_tbl(void)
1913d40330Schristos {
2013d40330Schristos const ASN1_STRING_TABLE *tmp = NULL;
2113d40330Schristos int nid = 12345678, nid2 = 87654321, rv = 0, ret = 0;
2213d40330Schristos
2313d40330Schristos tmp = ASN1_STRING_TABLE_get(nid);
2413d40330Schristos if (!TEST_ptr_null(tmp)) {
2513d40330Schristos TEST_info("asn1 string table: ASN1_STRING_TABLE_get non-exist nid");
2613d40330Schristos goto out;
2713d40330Schristos }
2813d40330Schristos
2913d40330Schristos ret = ASN1_STRING_TABLE_add(nid, -1, -1, MBSTRING_ASC, 0);
3013d40330Schristos if (!TEST_true(ret)) {
3113d40330Schristos TEST_info("asn1 string table: add NID(%d) failed", nid);
3213d40330Schristos goto out;
3313d40330Schristos }
3413d40330Schristos
3513d40330Schristos ret = ASN1_STRING_TABLE_add(nid2, -1, -1, MBSTRING_ASC, 0);
3613d40330Schristos if (!TEST_true(ret)) {
3713d40330Schristos TEST_info("asn1 string table: add NID(%d) failed", nid2);
3813d40330Schristos goto out;
3913d40330Schristos }
4013d40330Schristos
4113d40330Schristos tmp = ASN1_STRING_TABLE_get(nid);
4213d40330Schristos if (!TEST_ptr(tmp)) {
4313d40330Schristos TEST_info("asn1 string table: get NID(%d) failed", nid);
4413d40330Schristos goto out;
4513d40330Schristos }
4613d40330Schristos
4713d40330Schristos tmp = ASN1_STRING_TABLE_get(nid2);
4813d40330Schristos if (!TEST_ptr(tmp)) {
4913d40330Schristos TEST_info("asn1 string table: get NID(%d) failed", nid2);
5013d40330Schristos goto out;
5113d40330Schristos }
5213d40330Schristos
5313d40330Schristos ASN1_STRING_TABLE_cleanup();
5413d40330Schristos
5513d40330Schristos /* check if all newly added NIDs are cleaned up */
5613d40330Schristos tmp = ASN1_STRING_TABLE_get(nid);
5713d40330Schristos if (!TEST_ptr_null(tmp)) {
5813d40330Schristos TEST_info("asn1 string table: get NID(%d) failed", nid);
5913d40330Schristos goto out;
6013d40330Schristos }
6113d40330Schristos
6213d40330Schristos tmp = ASN1_STRING_TABLE_get(nid2);
6313d40330Schristos if (!TEST_ptr_null(tmp)) {
6413d40330Schristos TEST_info("asn1 string table: get NID(%d) failed", nid2);
6513d40330Schristos goto out;
6613d40330Schristos }
6713d40330Schristos
6813d40330Schristos rv = 1;
6913d40330Schristos out:
7013d40330Schristos return rv;
7113d40330Schristos }
7213d40330Schristos
setup_tests(void)7313d40330Schristos int setup_tests(void)
7413d40330Schristos {
7513d40330Schristos ADD_TEST(test_string_tbl);
7613d40330Schristos return 1;
7713d40330Schristos }
78