]> git.meshlink.io Git - meshlink/blob - test/blackbox/run_blackbox_tests/test_cases_open.c
Fix __warn_unused_result__, add more of it and fix the resulting warnings.
[meshlink] / test / blackbox / run_blackbox_tests / test_cases_open.c
1 /*
2     test_cases_open.c -- Execution of specific meshlink black box test cases
3     Copyright (C) 2018  Guus Sliepen <guus@meshlink.io>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifdef NDEBUG
21 #undef NDEBUG
22 #endif
23
24 #include "execute_tests.h"
25 #include "test_cases_open.h"
26 #include "../common/containers.h"
27 #include "../common/test_step.h"
28 #include "../common/common_handlers.h"
29 #include <stdlib.h>
30 #include <stdarg.h>
31 #include <setjmp.h>
32 #include <cmocka.h>
33 #include <assert.h>
34 #include <string.h>
35
36 /* Modify this to change the logging level of Meshlink */
37 #define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG
38
39 static void test_case_mesh_open_01(void **state);
40 static bool test_steps_mesh_open_01(void);
41 static void test_case_mesh_open_02(void **state);
42 static bool test_steps_mesh_open_02(void);
43 static void test_case_mesh_open_03(void **state);
44 static bool test_steps_mesh_open_03(void);
45 static void test_case_mesh_open_04(void **state);
46 static bool test_steps_mesh_open_04(void);
47 static void test_case_mesh_open_05(void **state);
48 static bool test_steps_mesh_open_05(void);
49
50 /* State structure for meshlink_open Test Case #1 */
51 static black_box_state_t test_mesh_open_01_state = {
52         .test_case_name = "test_case_mesh_open_01",
53 };
54
55 /* State structure for meshlink_open Test Case #2 */
56 static black_box_state_t test_mesh_open_02_state = {
57         .test_case_name = "test_case_mesh_open_02",
58 };
59
60 /* State structure for meshlink_open Test Case #3 */
61 static black_box_state_t test_mesh_open_03_state = {
62         .test_case_name = "test_case_mesh_open_03",
63 };
64
65 /* State structure for meshlink_open Test Case #4 */
66 static black_box_state_t test_mesh_open_04_state = {
67         .test_case_name = "test_case_mesh_open_04",
68 };
69
70 /* State structure for meshlink_open Test Case #5 */
71 static black_box_state_t test_mesh_open_05_state = {
72         .test_case_name = "test_case_mesh_open_05",
73 };
74
75 /* Execute meshlink_open Test Case # 1*/
76 static void test_case_mesh_open_01(void **state) {
77         execute_test(test_steps_mesh_open_01, state);
78 }
79
80 /* Test Steps for meshlink_open Test Case # 1
81
82     Test Steps:
83     1. Open the node instance using meshlink_open
84
85     Expected Result:
86     meshlink_open API should successfully return a mesh handle.
87 */
88 static bool test_steps_mesh_open_01(void) {
89         meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
90         meshlink_handle_t *mesh = meshlink_open("open_conf", "foo", "test", DEV_CLASS_STATIONARY);
91         assert_int_not_equal(mesh, NULL);
92
93         meshlink_close(mesh);
94         assert(meshlink_destroy("open_conf"));
95         return true;
96 }
97
98 /* Execute meshlink_open Test Case # 2*/
99 static void test_case_mesh_open_02(void **state) {
100         execute_test(test_steps_mesh_open_02, state);
101 }
102
103 /* Test Steps for meshlink_open Test Case # 2
104
105     Test Steps:
106     1. Open the node instance using meshlink_open with NULL as confbase argument
107
108     Expected Result:
109     meshlink_open API should successfully report error by returning NULL pointer
110 */
111 static bool test_steps_mesh_open_02(void) {
112         meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
113         meshlink_handle_t *mesh = meshlink_open(NULL, "foo", "test", DEV_CLASS_STATIONARY);
114         assert_int_equal(mesh, NULL);
115
116         return true;
117 }
118
119 /* Execute meshlink_open Test Case # 3 */
120 static void test_case_mesh_open_03(void **state) {
121         execute_test(test_steps_mesh_open_03, state);
122 }
123
124 /* Test Steps for meshlink_open Test Case # 3
125
126     Test Steps:
127     1. Open the node instance using meshlink_open with NULL as node name argument
128
129     Expected Result:
130     meshlink_open API should successfully report error by returning NULL pointer
131 */
132 static bool test_steps_mesh_open_03(void) {
133         meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
134         meshlink_handle_t *mesh = meshlink_open("openconf", NULL, "test", DEV_CLASS_STATIONARY);
135         assert_int_equal(mesh, NULL);
136
137         assert(meshlink_destroy("open_conf"));
138         return true;
139 }
140
141 /* Execute meshlink_open Test Case # 4*/
142 static void test_case_mesh_open_04(void **state) {
143         execute_test(test_steps_mesh_open_04, state);
144 }
145
146 /* Test Steps for meshlink_open Test Case # 4
147
148     Test Steps:
149     1. Open the node instance using meshlink_open with NULL as app name argument
150
151     Expected Result:
152     meshlink_open API should successfully report error by returning NULL pointer
153 */
154 static bool test_steps_mesh_open_04(void) {
155         meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
156         meshlink_handle_t *mesh = meshlink_open("openconf", "foo", NULL, DEV_CLASS_STATIONARY);
157         assert_int_equal(mesh, NULL);
158
159         assert(meshlink_destroy("open_conf"));
160         return true;
161 }
162
163 /* Execute meshlink_open Test Case # 5*/
164 static void test_case_mesh_open_05(void **state) {
165         execute_test(test_steps_mesh_open_05, state);
166 }
167
168 /* Test Steps for meshlink_open Test Case # 5
169
170     Test Steps:
171     1. Open the node instance using meshlink_open with invalid device class argument
172
173     Expected Result:
174     meshlink_open API should successfully report error by returning NULL pointer
175 */
176 static bool test_steps_mesh_open_05(void) {
177         meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
178         meshlink_handle_t *mesh = meshlink_open("openconf", "foo", "test", -1);
179         assert_int_equal(mesh, NULL);
180
181         assert(meshlink_destroy("open_conf"));
182         return true;
183 }
184
185 int test_meshlink_open(void) {
186         const struct CMUnitTest blackbox_open_tests[] = {
187                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_open_01, NULL, NULL,
188                                 (void *)&test_mesh_open_01_state),
189                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_open_02, NULL, NULL,
190                                 (void *)&test_mesh_open_02_state),
191                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_open_03, NULL, NULL,
192                                 (void *)&test_mesh_open_03_state),
193                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_open_04, NULL, NULL,
194                                 (void *)&test_mesh_open_04_state),
195                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_open_05, NULL, NULL,
196                                 (void *)&test_mesh_open_05_state)
197
198         };
199         total_tests += sizeof(blackbox_open_tests) / sizeof(blackbox_open_tests[0]);
200
201         return cmocka_run_group_tests(blackbox_open_tests, NULL, NULL);
202 }