|
Packit Service |
084de1 |
/*
|
|
Packit Service |
084de1 |
* Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
|
|
Packit Service |
084de1 |
*
|
|
Packit Service |
084de1 |
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
Packit Service |
084de1 |
* this file except in compliance with the License. You can obtain a copy
|
|
Packit Service |
084de1 |
* in the file LICENSE in the source distribution or at
|
|
Packit Service |
084de1 |
* https://www.openssl.org/source/license.html
|
|
Packit Service |
084de1 |
*/
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/* Tests for the ANS1_STRING_TABLE_* functions */
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#include <stdio.h>
|
|
Packit Service |
084de1 |
#include <string.h>
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#include <openssl/asn1.h>
|
|
Packit Service |
084de1 |
#include "testutil.h"
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
static int test_string_tbl(void)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
const ASN1_STRING_TABLE *tmp = NULL;
|
|
Packit Service |
084de1 |
int nid = 12345678, nid2 = 87654321, rv = 0, ret = 0;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
tmp = ASN1_STRING_TABLE_get(nid);
|
|
Packit Service |
084de1 |
if (!TEST_ptr_null(tmp)) {
|
|
Packit Service |
084de1 |
TEST_info("asn1 string table: ASN1_STRING_TABLE_get non-exist nid");
|
|
Packit Service |
084de1 |
goto out;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
ret = ASN1_STRING_TABLE_add(nid, -1, -1, MBSTRING_ASC, 0);
|
|
Packit Service |
084de1 |
if (!TEST_true(ret)) {
|
|
Packit Service |
084de1 |
TEST_info("asn1 string table: add NID(%d) failed", nid);
|
|
Packit Service |
084de1 |
goto out;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
ret = ASN1_STRING_TABLE_add(nid2, -1, -1, MBSTRING_ASC, 0);
|
|
Packit Service |
084de1 |
if (!TEST_true(ret)) {
|
|
Packit Service |
084de1 |
TEST_info("asn1 string table: add NID(%d) failed", nid2);
|
|
Packit Service |
084de1 |
goto out;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
tmp = ASN1_STRING_TABLE_get(nid);
|
|
Packit Service |
084de1 |
if (!TEST_ptr(tmp)) {
|
|
Packit Service |
084de1 |
TEST_info("asn1 string table: get NID(%d) failed", nid);
|
|
Packit Service |
084de1 |
goto out;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
tmp = ASN1_STRING_TABLE_get(nid2);
|
|
Packit Service |
084de1 |
if (!TEST_ptr(tmp)) {
|
|
Packit Service |
084de1 |
TEST_info("asn1 string table: get NID(%d) failed", nid2);
|
|
Packit Service |
084de1 |
goto out;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
ASN1_STRING_TABLE_cleanup();
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/* check if all newly added NIDs are cleaned up */
|
|
Packit Service |
084de1 |
tmp = ASN1_STRING_TABLE_get(nid);
|
|
Packit Service |
084de1 |
if (!TEST_ptr_null(tmp)) {
|
|
Packit Service |
084de1 |
TEST_info("asn1 string table: get NID(%d) failed", nid);
|
|
Packit Service |
084de1 |
goto out;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
tmp = ASN1_STRING_TABLE_get(nid2);
|
|
Packit Service |
084de1 |
if (!TEST_ptr_null(tmp)) {
|
|
Packit Service |
084de1 |
TEST_info("asn1 string table: get NID(%d) failed", nid2);
|
|
Packit Service |
084de1 |
goto out;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
rv = 1;
|
|
Packit Service |
084de1 |
out:
|
|
Packit Service |
084de1 |
return rv;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
int setup_tests(void)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
ADD_TEST(test_string_tbl);
|
|
Packit Service |
084de1 |
return 1;
|
|
Packit Service |
084de1 |
}
|