2 * Copyright 2019 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
11 #include "internal/provider.h"
14 #if !defined(DSO_VMS) && !defined(DSO_DLCFN) && !defined(DSO_DL) \
15 && !defined(DSO_WIN32) && !defined(DSO_DLFCN)
16 # define OPENSSL_NO_DSO
19 extern OSSL_provider_init_fn PROVIDER_INIT_FUNCTION_NAME;
22 static size_t buf_l = 0;
23 static OSSL_PARAM greeting_request[] = {
24 { "greeting", OSSL_PARAM_UTF8_STRING, buf, sizeof(buf), &buf_l },
25 { NULL, 0, NULL, 0, NULL }
28 static int test_provider(OSSL_PROVIDER *prov)
30 const char *name = NULL;
31 const char *greeting = NULL;
32 char expected_greeting[256];
35 if (!TEST_ptr(name = ossl_provider_name(prov)))
38 snprintf(expected_greeting, sizeof(expected_greeting),
39 "Hello OpenSSL %.20s, greetings from %s!",
40 OPENSSL_VERSION_STR, name);
43 TEST_true(ossl_provider_activate(prov))
44 && TEST_true(ossl_provider_get_params(prov, greeting_request))
45 && TEST_ptr(greeting = greeting_request[0].data)
46 && TEST_size_t_gt(greeting_request[0].data_size, 0)
47 && TEST_str_eq(greeting, expected_greeting);
49 ossl_provider_free(prov);
53 static int test_builtin_provider(void)
55 const char *name = "p_test_builtin";
56 OSSL_PROVIDER *prov = NULL;
60 ossl_provider_new(NULL, name, PROVIDER_INIT_FUNCTION_NAME))
61 && test_provider(prov);
64 #ifndef OPENSSL_NO_DSO
65 static int test_loaded_provider(void)
67 const char *name = "p_test";
68 OSSL_PROVIDER *prov = NULL;
71 TEST_ptr(prov = ossl_provider_new(NULL, name, NULL))
72 && test_provider(prov);
78 ADD_TEST(test_builtin_provider);
79 #ifndef OPENSSL_NO_DSO
80 ADD_TEST(test_loaded_provider);