Imported Upstream version 0.19.1
[platform/upstream/p11-kit.git] / p11-kit / tests / test-log.c
1 /*
2  * Copyright (c) 2013 Red Hat Inc
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  *     * Redistributions of source code must retain the above
9  *       copyright notice, this list of conditions and the
10  *       following disclaimer.
11  *     * Redistributions in binary form must reproduce the
12  *       above copyright notice, this list of conditions and
13  *       the following disclaimer in the documentation and/or
14  *       other materials provided with the distribution.
15  *     * The names of contributors to this software may not be
16  *       used to endorse or promote products derived from this
17  *       software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
29  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
30  * DAMAGE.
31  *
32  * Author: Stef Walter <stefw@redhat.com>
33  */
34
35 #include "config.h"
36 #include "test.h"
37
38 #include "dict.h"
39 #include "library.h"
40 #include "log.h"
41 #include "mock.h"
42 #include "modules.h"
43 #include "p11-kit.h"
44 #include "virtual.h"
45
46 #include <errno.h>
47 #include <stdlib.h>
48 #include <stdio.h>
49 #include <string.h>
50
51 static CK_FUNCTION_LIST_PTR
52 setup_mock_module (CK_SESSION_HANDLE *session)
53 {
54         CK_FUNCTION_LIST_PTR module;
55         CK_RV rv;
56
57         p11_lock ();
58         p11_log_force = true;
59
60         rv = p11_module_load_inlock_reentrant (&mock_module, 0, &module);
61         assert (rv == CKR_OK);
62         assert_ptr_not_null (module);
63         assert (p11_virtual_is_wrapper (module));
64
65         p11_unlock ();
66
67         rv = p11_kit_module_initialize (module);
68         assert (rv == CKR_OK);
69
70         if (session) {
71                 rv = (module->C_OpenSession) (MOCK_SLOT_ONE_ID,
72                                               CKF_RW_SESSION | CKF_SERIAL_SESSION,
73                                               NULL, NULL, session);
74                 assert (rv == CKR_OK);
75         }
76
77         return module;
78 }
79
80 static void
81 teardown_mock_module (CK_FUNCTION_LIST_PTR module)
82 {
83         CK_RV rv;
84
85         rv = p11_kit_module_finalize (module);
86         assert (rv == CKR_OK);
87
88         p11_lock ();
89
90         rv = p11_module_release_inlock_reentrant (module);
91         assert (rv == CKR_OK);
92
93         p11_unlock ();
94 }
95
96 /* Bring in all the mock module tests */
97 #include "test-mock.c"
98
99 int
100 main (int argc,
101       char *argv[])
102 {
103         p11_library_init ();
104         mock_module_init ();
105
106         test_mock_add_tests ("/log");
107
108         p11_kit_be_quiet ();
109         p11_log_output = false;
110
111         return p11_test_run (argc, argv);
112 }