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