summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2019-05-23 16:00:05 +0200
committerRichard Levitte <levitte@openssl.org>2019-06-24 10:58:13 +0200
commit734a462e4028e2f0136d3af0b37611138e781246 (patch)
tree29c528d67c781415414ac40175ff419df01ae490
parent651d44183e86355b1eb9629a6a61d3da09369bbf (diff)
downloadopenssl-new-734a462e4028e2f0136d3af0b37611138e781246.tar.gz
Add a namemap test
Reviewed-by: Paul Dale <paul.dale@oracle.com> (Merged from https://github.com/openssl/openssl/pull/8967)
-rw-r--r--test/build.info5
-rw-r--r--test/namemap_internal_test.c58
-rw-r--r--test/recipes/03-test_internal_namemap.t16
3 files changed, 79 insertions, 0 deletions
diff --git a/test/build.info b/test/build.info
index 272c439cac..1cf604e37e 100644
--- a/test/build.info
+++ b/test/build.info
@@ -642,6 +642,11 @@ IF[{- !$disabled{tests} -}]
SOURCE[params_test]=params_test.c
INCLUDE[params_test]=.. ../include ../apps/include
DEPEND[params_test]=../libcrypto.a libtestutil.a
+
+ PROGRAMS{noinst}=namemap_internal_test
+ SOURCE[namemap_internal_test]=namemap_internal_test.c
+ INCLUDE[namemap_internal_test]=.. ../include ../apps/include
+ DEPEND[namemap_internal_test]=../libcrypto.a libtestutil.a
ENDIF
{-
diff --git a/test/namemap_internal_test.c b/test/namemap_internal_test.c
new file mode 100644
index 0000000000..ec3e82e11f
--- /dev/null
+++ b/test/namemap_internal_test.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License 2.0 (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
+ */
+
+#include "internal/namemap.h"
+#include "testutil.h"
+
+#define NAME1 "name1"
+#define NAME2 "name2"
+#define ALIAS1 "alias1"
+
+static int test_namemap(OSSL_NAMEMAP *nm)
+{
+ int num1 = ossl_namemap_add(nm, 0, NAME1);
+ int num2 = ossl_namemap_add(nm, 0, NAME2);
+ int num3 = ossl_namemap_add(nm, num1, ALIAS1);
+ int check1 = ossl_namemap_name2num(nm, NAME1);
+ int check2 = ossl_namemap_name2num(nm, NAME2);
+ int check3 = ossl_namemap_name2num(nm, ALIAS1);
+ int false1 = ossl_namemap_name2num(nm, "foo");
+
+ return TEST_int_ne(num1, 0)
+ && TEST_int_ne(num2, 0)
+ && TEST_int_eq(num1, num3)
+ && TEST_int_eq(num1, check1)
+ && TEST_int_eq(num2, check2)
+ && TEST_int_eq(num3, check3)
+ && TEST_int_eq(false1, 0);
+}
+
+static int test_namemap_independent(void)
+{
+ OSSL_NAMEMAP *nm = ossl_namemap_new();
+ int ok = nm != NULL && test_namemap(nm);
+
+ ossl_namemap_free(nm);
+ return ok;
+}
+
+static int test_namemap_stored(void)
+{
+ OSSL_NAMEMAP *nm = ossl_namemap_stored(NULL);
+
+ return nm != NULL
+ && test_namemap(nm);
+}
+
+int setup_tests(void)
+{
+ ADD_TEST(test_namemap_independent);
+ ADD_TEST(test_namemap_stored);
+ return 1;
+}
diff --git a/test/recipes/03-test_internal_namemap.t b/test/recipes/03-test_internal_namemap.t
new file mode 100644
index 0000000000..9214242c70
--- /dev/null
+++ b/test/recipes/03-test_internal_namemap.t
@@ -0,0 +1,16 @@
+#! /usr/bin/env perl
+# Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
+#
+# Licensed under the Apache License 2.0 (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
+
+use strict;
+use OpenSSL::Test; # get 'plan'
+use OpenSSL::Test::Simple;
+use OpenSSL::Test::Utils;
+
+setup("test_internal_namemap");
+
+simple_test("test_internal_namemap", "namemap_internal_test");