]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/context_internal_test.c
Fix various typos, repeated words, align some spelling to LDP.
[thirdparty/openssl.git] / test / context_internal_test.c
CommitLineData
d64b6299 1/*
fecb3aae 2 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
d64b6299
RL
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/* Internal tests for the OpenSSL library context */
11
12#include "internal/cryptlib.h"
13#include "testutil.h"
14
ee203a87
MC
15static int test_set0_default(void)
16{
17 OSSL_LIB_CTX *global = OSSL_LIB_CTX_get0_global_default();
18 OSSL_LIB_CTX *local = OSSL_LIB_CTX_new();
19 OSSL_LIB_CTX *prev;
20 int testresult = 0;
ee203a87
MC
21
22 if (!TEST_ptr(global)
23 || !TEST_ptr(local)
927d0566 24 || !TEST_ptr_eq(global, OSSL_LIB_CTX_set0_default(NULL)))
ee203a87
MC
25 goto err;
26
27 /* Check we can change the local default context */
28 if (!TEST_ptr(prev = OSSL_LIB_CTX_set0_default(local))
927d0566 29 || !TEST_ptr_eq(global, prev))
ee203a87
MC
30 goto err;
31
32 /* Calling OSSL_LIB_CTX_set0_default() with a NULL should be a no-op */
927d0566 33 if (!TEST_ptr_eq(local, OSSL_LIB_CTX_set0_default(NULL)))
ee203a87
MC
34 goto err;
35
36 /* Global default should be unchanged */
37 if (!TEST_ptr_eq(global, OSSL_LIB_CTX_get0_global_default()))
38 goto err;
39
40 /* Check we can swap back to the global default */
927d0566
HL
41 if (!TEST_ptr(prev = OSSL_LIB_CTX_set0_default(global))
42 || !TEST_ptr_eq(local, prev))
ee203a87
MC
43 goto err;
44
45 testresult = 1;
46 err:
47 OSSL_LIB_CTX_free(local);
48 return testresult;
49}
50
d64b6299
RL
51int setup_tests(void)
52{
ee203a87 53 ADD_TEST(test_set0_default);
d64b6299
RL
54 return 1;
55}