diff options
Diffstat (limited to 'test/context_internal_test.c')
-rw-r--r-- | test/context_internal_test.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/context_internal_test.c b/test/context_internal_test.c index 0b786adf67..a875908469 100644 --- a/test/context_internal_test.c +++ b/test/context_internal_test.c @@ -73,9 +73,64 @@ static int test_def_context(void) return test_context(NULL); } +static int test_set0_default(void) +{ + OSSL_LIB_CTX *global = OSSL_LIB_CTX_get0_global_default(); + OSSL_LIB_CTX *local = OSSL_LIB_CTX_new(); + OSSL_LIB_CTX *prev; + int testresult = 0; + FOO *data = NULL; + + if (!TEST_ptr(global) + || !TEST_ptr(local) + || !TEST_ptr_eq(global, OSSL_LIB_CTX_set0_default(NULL)) + || !TEST_ptr(data = ossl_lib_ctx_get_data(local, 0, &foo_method))) + goto err; + + /* Set local "i" value to 43. Global "i" should be 42 */ + data->i++; + if (!TEST_int_eq(data->i, 43)) + goto err; + + /* The default context should still be the "global" default */ + if (!TEST_ptr(data = ossl_lib_ctx_get_data(NULL, 0, &foo_method)) + || !TEST_int_eq(data->i, 42)) + goto err; + + /* Check we can change the local default context */ + if (!TEST_ptr(prev = OSSL_LIB_CTX_set0_default(local)) + || !TEST_ptr_eq(global, prev) + || !TEST_ptr(data = ossl_lib_ctx_get_data(NULL, 0, &foo_method)) + || !TEST_int_eq(data->i, 43)) + goto err; + + /* Calling OSSL_LIB_CTX_set0_default() with a NULL should be a no-op */ + if (!TEST_ptr_eq(local, OSSL_LIB_CTX_set0_default(NULL)) + || !TEST_ptr(data = ossl_lib_ctx_get_data(NULL, 0, &foo_method)) + || !TEST_int_eq(data->i, 43)) + goto err; + + /* Global default should be unchanged */ + if (!TEST_ptr_eq(global, OSSL_LIB_CTX_get0_global_default())) + goto err; + + /* Check we can swap back to the global default */ + if (!TEST_ptr(prev = OSSL_LIB_CTX_set0_default(global)) + || !TEST_ptr_eq(local, prev) + || !TEST_ptr(data = ossl_lib_ctx_get_data(NULL, 0, &foo_method)) + || !TEST_int_eq(data->i, 42)) + goto err; + + testresult = 1; + err: + OSSL_LIB_CTX_free(local); + return testresult; +} + int setup_tests(void) { ADD_TEST(test_app_context); ADD_TEST(test_def_context); + ADD_TEST(test_set0_default); return 1; } |