2 * Copyright 2019-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
10 /* Internal tests for the OpenSSL library context */
12 #include "internal/cryptlib.h"
15 static int test_set0_default(void)
17 OSSL_LIB_CTX
*global
= OSSL_LIB_CTX_get0_global_default();
18 OSSL_LIB_CTX
*local
= OSSL_LIB_CTX_new();
24 || !TEST_ptr_eq(global
, OSSL_LIB_CTX_set0_default(NULL
)))
27 /* Check we can change the local default context */
28 if (!TEST_ptr(prev
= OSSL_LIB_CTX_set0_default(local
))
29 || !TEST_ptr_eq(global
, prev
))
32 /* Calling OSSL_LIB_CTX_set0_default() with a NULL should be a no-op */
33 if (!TEST_ptr_eq(local
, OSSL_LIB_CTX_set0_default(NULL
)))
36 /* Global default should be unchanged */
37 if (!TEST_ptr_eq(global
, OSSL_LIB_CTX_get0_global_default()))
40 /* Check we can swap back to the global default */
41 if (!TEST_ptr(prev
= OSSL_LIB_CTX_set0_default(global
))
42 || !TEST_ptr_eq(local
, prev
))
47 OSSL_LIB_CTX_free(local
);
51 static int test_set_get_conf_diagnostics(void)
53 OSSL_LIB_CTX
*ctx
= OSSL_LIB_CTX_new();
59 if (!TEST_false(OSSL_LIB_CTX_get_conf_diagnostics(ctx
)))
62 OSSL_LIB_CTX_set_conf_diagnostics(ctx
, 1);
64 if (!TEST_true(OSSL_LIB_CTX_get_conf_diagnostics(ctx
)))
67 OSSL_LIB_CTX_set_conf_diagnostics(ctx
, 0);
69 if (!TEST_false(OSSL_LIB_CTX_get_conf_diagnostics(ctx
)))
74 OSSL_LIB_CTX_free(ctx
);
80 ADD_TEST(test_set0_default
);
81 ADD_TEST(test_set_get_conf_diagnostics
);