Fix grammar in certificates.txt
[openssl.git] / test / context_internal_test.c
1 /*
2  * Copyright 2019-2022 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 /* Internal tests for the OpenSSL library context */
11
12 #include "internal/cryptlib.h"
13 #include "testutil.h"
14
15 static 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;
21
22     if (!TEST_ptr(global)
23             || !TEST_ptr(local)
24             || !TEST_ptr_eq(global, OSSL_LIB_CTX_set0_default(NULL)))
25         goto err;
26
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))
30         goto err;
31
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)))
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 */
41     if (!TEST_ptr(prev = OSSL_LIB_CTX_set0_default(global))
42             || !TEST_ptr_eq(local, prev))
43         goto err;
44
45     testresult = 1;
46  err:
47     OSSL_LIB_CTX_free(local);
48     return testresult;
49 }
50
51 int setup_tests(void)
52 {
53     ADD_TEST(test_set0_default);
54     return 1;
55 }