2017-07-26 17:18:50 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
|
|
|
|
*
|
2018-12-06 12:05:25 +00:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2017-07-26 17:18:50 +00:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*/
|
|
|
|
|
2018-12-10 09:39:24 +00:00
|
|
|
/* Tests for the ASN1_STRING_TABLE_* functions */
|
2017-07-26 17:18:50 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <openssl/asn1.h>
|
|
|
|
#include "testutil.h"
|
|
|
|
|
2017-08-15 21:39:03 +00:00
|
|
|
static int test_string_tbl(void)
|
2017-07-26 17:18:50 +00:00
|
|
|
{
|
|
|
|
const ASN1_STRING_TABLE *tmp = NULL;
|
|
|
|
int nid = 12345678, nid2 = 87654321, rv = 0, ret = 0;
|
|
|
|
|
|
|
|
tmp = ASN1_STRING_TABLE_get(nid);
|
|
|
|
if (!TEST_ptr_null(tmp)) {
|
|
|
|
TEST_info("asn1 string table: ASN1_STRING_TABLE_get non-exist nid");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ASN1_STRING_TABLE_add(nid, -1, -1, MBSTRING_ASC, 0);
|
|
|
|
if (!TEST_true(ret)) {
|
|
|
|
TEST_info("asn1 string table: add NID(%d) failed", nid);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ASN1_STRING_TABLE_add(nid2, -1, -1, MBSTRING_ASC, 0);
|
|
|
|
if (!TEST_true(ret)) {
|
|
|
|
TEST_info("asn1 string table: add NID(%d) failed", nid2);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = ASN1_STRING_TABLE_get(nid);
|
|
|
|
if (!TEST_ptr(tmp)) {
|
|
|
|
TEST_info("asn1 string table: get NID(%d) failed", nid);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = ASN1_STRING_TABLE_get(nid2);
|
|
|
|
if (!TEST_ptr(tmp)) {
|
|
|
|
TEST_info("asn1 string table: get NID(%d) failed", nid2);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASN1_STRING_TABLE_cleanup();
|
|
|
|
|
|
|
|
/* check if all newly added NIDs are cleaned up */
|
|
|
|
tmp = ASN1_STRING_TABLE_get(nid);
|
|
|
|
if (!TEST_ptr_null(tmp)) {
|
|
|
|
TEST_info("asn1 string table: get NID(%d) failed", nid);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = ASN1_STRING_TABLE_get(nid2);
|
|
|
|
if (!TEST_ptr_null(tmp)) {
|
|
|
|
TEST_info("asn1 string table: get NID(%d) failed", nid2);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = 1;
|
|
|
|
out:
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-07-26 22:08:36 +00:00
|
|
|
int setup_tests(void)
|
2017-07-26 17:18:50 +00:00
|
|
|
{
|
|
|
|
ADD_TEST(test_string_tbl);
|
2017-07-26 22:08:36 +00:00
|
|
|
return 1;
|
2017-07-26 17:18:50 +00:00
|
|
|
}
|