2 * Copyright 2019-2020 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"
16 * Everything between BEGIN EXAMPLE and END EXAMPLE is copied from
17 * doc/internal/man3/ossl_lib_ctx_get_data.pod
21 * ======================================================================
25 typedef struct foo_st
{
30 static void *foo_new(OSSL_LIB_CTX
*ctx
)
32 FOO
*ptr
= OPENSSL_zalloc(sizeof(*ptr
));
37 static void foo_free(void *ptr
)
41 static const OSSL_LIB_CTX_METHOD foo_method
= {
48 * ======================================================================
51 static int test_context(OSSL_LIB_CTX
*ctx
)
55 return TEST_ptr(data
= ossl_lib_ctx_get_data(ctx
, 0, &foo_method
))
56 /* OPENSSL_zalloc in foo_new() initialized it to zero */
57 && TEST_int_eq(data
->i
, 42);
60 static int test_app_context(void)
62 OSSL_LIB_CTX
*ctx
= NULL
;
64 TEST_ptr(ctx
= OSSL_LIB_CTX_new())
67 OSSL_LIB_CTX_free(ctx
);
71 static int test_def_context(void)
73 return test_context(NULL
);
78 ADD_TEST(test_app_context
);
79 ADD_TEST(test_def_context
);