2 * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
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
11 #include <openssl/provider.h>
14 static int test_default_libctx(void)
16 OSSL_LIB_CTX *ctx = NULL;
17 char *path = "./some/path";
18 const char *retrieved_path = NULL;
21 ok = TEST_true(OSSL_PROVIDER_set_default_search_path(ctx, path))
22 && TEST_ptr(retrieved_path = OSSL_PROVIDER_get0_default_search_path(ctx))
23 && TEST_str_eq(path, retrieved_path);
28 static int test_explicit_libctx(void)
30 OSSL_LIB_CTX *ctx = NULL;
31 char *def_libctx_path = "./some/path";
32 char *path = "./another/location";
33 const char *retrieved_defctx_path = NULL;
34 const char *retrieved_path = NULL;
37 /* Set search path for default context, then create a new context and set
38 another path for it. Finally, get both paths and make sure they are
39 still what we set and are separate. */
40 ok = TEST_true(OSSL_PROVIDER_set_default_search_path(NULL, def_libctx_path))
41 && TEST_ptr(ctx = OSSL_LIB_CTX_new())
42 && TEST_true(OSSL_PROVIDER_set_default_search_path(ctx, path))
43 && TEST_ptr(retrieved_defctx_path = OSSL_PROVIDER_get0_default_search_path(NULL))
44 && TEST_str_eq(def_libctx_path, retrieved_defctx_path)
45 && TEST_ptr(retrieved_path = OSSL_PROVIDER_get0_default_search_path(ctx))
46 && TEST_str_eq(path, retrieved_path)
47 && TEST_str_ne(retrieved_path, retrieved_defctx_path);
49 OSSL_LIB_CTX_free(ctx);
55 ADD_TEST(test_default_libctx);
56 ADD_TEST(test_explicit_libctx);