s_client.pod: Fix grammar in NOTES section.
[openssl.git] / test / ossl_store_test.c
1 /*
2  * Copyright 2020 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 #include <openssl/store.h>
11 #include <openssl/ui.h>
12 #include "testutil.h"
13
14 typedef enum OPTION_choice {
15     OPT_ERR = -1,
16     OPT_EOF = 0,
17     OPT_INFILE,
18     OPT_TEST_ENUM
19 } OPTION_CHOICE;
20
21 static const char *infile = NULL;
22
23 static int test_store_open(void)
24 {
25     int ret = 0;
26     OSSL_STORE_CTX *sctx = NULL;
27     OSSL_STORE_SEARCH *search = NULL;
28     UI_METHOD *ui_method = NULL;
29
30     ret = TEST_ptr(search = OSSL_STORE_SEARCH_by_alias("nothing"))
31           && TEST_ptr(ui_method= UI_create_method("DummyUI"))
32           && TEST_ptr(sctx = OSSL_STORE_open_with_libctx(infile, NULL, NULL,
33                                                          ui_method, NULL,
34                                                          NULL, NULL))
35           && TEST_false(OSSL_STORE_find(sctx, NULL))
36           && TEST_true(OSSL_STORE_find(sctx, search));
37     UI_destroy_method(ui_method);
38     OSSL_STORE_SEARCH_free(search);
39     OSSL_STORE_close(sctx);
40     return ret;
41 }
42
43 static int test_store_search_by_key_fingerprint_fail(void)
44 {
45     int ret;
46     OSSL_STORE_SEARCH *search = NULL;
47
48     ret = TEST_ptr_null(search = OSSL_STORE_SEARCH_by_key_fingerprint(
49                                      EVP_sha256(), NULL, 0));
50     OSSL_STORE_SEARCH_free(search);
51     return ret;
52 }
53
54 const OPTIONS *test_get_options(void)
55 {
56     static const OPTIONS test_options[] = {
57         OPT_TEST_OPTIONS_DEFAULT_USAGE,
58         { "in", OPT_INFILE, '<', },
59         { NULL }
60     };
61     return test_options;
62 }
63
64 int setup_tests(void)
65 {
66     OPTION_CHOICE o;
67
68     while ((o = opt_next()) != OPT_EOF) {
69         switch (o) {
70         case OPT_INFILE:
71             infile = opt_arg();
72             break;
73         case OPT_TEST_CASES:
74            break;
75         default:
76         case OPT_ERR:
77             return 0;
78         }
79     }
80
81     ADD_TEST(test_store_open);
82     ADD_TEST(test_store_search_by_key_fingerprint_fail);
83     return 1;
84 }