aboutsummaryrefslogtreecommitdiffstats
path: root/test/context_internal_test.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2019-05-01 11:02:43 +0100
committerMatt Caswell <matt@openssl.org>2019-05-02 22:42:09 +0100
commit1aedc35fd6c2f40f269c88b2f7d5a617172b47c5 (patch)
tree705bc6f55fe9571651b27af36c3a9a3ce1bc6ea1 /test/context_internal_test.c
parentb8fe36fee000970dcb7cd363f31445969cfbf677 (diff)
downloadopenssl-1aedc35fd6c2f40f269c88b2f7d5a617172b47c5.tar.gz
Instead of global data store it in an OPENSSL_CTX
Various core and property related code files used global data. We should store all of that in an OPENSSL_CTX instead. Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/8857)
Diffstat (limited to 'test/context_internal_test.c')
-rw-r--r--test/context_internal_test.c20
1 files changed, 3 insertions, 17 deletions
diff --git a/test/context_internal_test.c b/test/context_internal_test.c
index aca3db3187..6c675bcf9d 100644
--- a/test/context_internal_test.c
+++ b/test/context_internal_test.c
@@ -22,15 +22,12 @@
* BEGIN EXAMPLE
*/
-/* The index will always be entirely global, and dynamically allocated */
-static int foo_index = -1;
-
typedef struct foo_st {
int i;
void *data;
} FOO;
-static void *foo_new(void)
+static void *foo_new(OPENSSL_CTX *ctx)
{
FOO *ptr = OPENSSL_zalloc(sizeof(*ptr));
if (ptr != NULL)
@@ -46,14 +43,6 @@ static const OPENSSL_CTX_METHOD foo_method = {
foo_free
};
-static int foo_init(void)
-{
- if (foo_index == -1)
- foo_index = openssl_ctx_new_index(&foo_method);
-
- return foo_index != -1;
-}
-
/*
* END EXAMPLE
* ======================================================================
@@ -63,9 +52,7 @@ static int test_context(OPENSSL_CTX *ctx)
{
FOO *data = NULL;
- return
- TEST_true(foo_init())
- && TEST_ptr(data = openssl_ctx_get_data(ctx, foo_index))
+ return TEST_ptr(data = openssl_ctx_get_data(ctx, 0, &foo_method))
/* OPENSSL_zalloc in foo_new() initialized it to zero */
&& TEST_int_eq(data->i, 42);
}
@@ -74,8 +61,7 @@ static int test_app_context(void)
{
OPENSSL_CTX *ctx = NULL;
int result =
- TEST_true(foo_init())
- && TEST_ptr(ctx = OPENSSL_CTX_new())
+ TEST_ptr(ctx = OPENSSL_CTX_new())
&& test_context(ctx);
OPENSSL_CTX_free(ctx);