]> git.ipfire.org Git - thirdparty/openssl.git/blob - test/namemap_internal_test.c
Modify ossl_method_store_add() to handle reference counting
[thirdparty/openssl.git] / test / namemap_internal_test.c
1 /*
2 * Copyright 2019 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 #include "internal/namemap.h"
11 #include "testutil.h"
12
13 #define NAME1 "name1"
14 #define NAME2 "name2"
15 #define ALIAS1 "alias1"
16 #define ALIAS1_UC "ALIAS1"
17
18 static int test_namemap(OSSL_NAMEMAP *nm)
19 {
20 int num1 = ossl_namemap_add(nm, 0, NAME1);
21 int num2 = ossl_namemap_add(nm, 0, NAME2);
22 int num3 = ossl_namemap_add(nm, num1, ALIAS1);
23 int num4 = ossl_namemap_add(nm, 0, ALIAS1_UC);
24 int check1 = ossl_namemap_name2num(nm, NAME1);
25 int check2 = ossl_namemap_name2num(nm, NAME2);
26 int check3 = ossl_namemap_name2num(nm, ALIAS1);
27 int check4 = ossl_namemap_name2num(nm, ALIAS1_UC);
28 int false1 = ossl_namemap_name2num(nm, "foo");
29
30 return TEST_int_ne(num1, 0)
31 && TEST_int_ne(num2, 0)
32 && TEST_int_eq(num1, num3)
33 && TEST_int_eq(num3, num4)
34 && TEST_int_eq(num1, check1)
35 && TEST_int_eq(num2, check2)
36 && TEST_int_eq(num3, check3)
37 && TEST_int_eq(num4, check4)
38 && TEST_int_eq(false1, 0);
39 }
40
41 static int test_namemap_independent(void)
42 {
43 OSSL_NAMEMAP *nm = ossl_namemap_new();
44 int ok = nm != NULL && test_namemap(nm);
45
46 ossl_namemap_free(nm);
47 return ok;
48 }
49
50 static int test_namemap_stored(void)
51 {
52 OSSL_NAMEMAP *nm = ossl_namemap_stored(NULL);
53
54 return nm != NULL
55 && test_namemap(nm);
56 }
57
58 int setup_tests(void)
59 {
60 ADD_TEST(test_namemap_independent);
61 ADD_TEST(test_namemap_stored);
62 return 1;
63 }