summaryrefslogtreecommitdiffstats
path: root/test/asn1_string_table_test.c
diff options
context:
space:
mode:
authorPaul Yang <yang.yang@baishancloud.com>2017-07-27 01:18:50 +0800
committerAndy Polyakov <appro@openssl.org>2017-07-26 20:06:51 +0200
commit7b608d0828c6df0b3bcd49224cdf6ccf4ab4af90 (patch)
tree6eacfa0139d539c5021f396ff8e83fcc054d0bf1 /test/asn1_string_table_test.c
parente4b16013e9b3d19241d3ba0bb0875f0d70d93509 (diff)
Add test cases and docs for ASN1_STRING_TABLE_* functions
Reviewed-by: Richard Levitte <levitte@openssl.org> Reviewed-by: Andy Polyakov <appro@openssl.org> (Merged from https://github.com/openssl/openssl/pull/3998)
Diffstat (limited to 'test/asn1_string_table_test.c')
-rw-r--r--test/asn1_string_table_test.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/test/asn1_string_table_test.c b/test/asn1_string_table_test.c
new file mode 100644
index 0000000000..7e542b952e
--- /dev/null
+++ b/test/asn1_string_table_test.c
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License"). You may not use
+ * 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
+ */
+
+/* Tests for the ANS1_STRING_TABLE_* functions */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <openssl/asn1.h>
+#include "testutil.h"
+
+static int test_string_tbl()
+{
+ 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;
+}
+
+void register_tests(void)
+{
+ ADD_TEST(test_string_tbl);
+}