]> git.meshlink.io Git - meshlink/blob - test/blackbox/run_blackbox_tests/test_cases_open.c
2655376f55bd786ede08d582b5d6bc9316193c0e
[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 #include "execute_tests.h"
21 #include "test_cases_open.h"
22 #include "../common/containers.h"
23 #include "../common/test_step.h"
24 #include "../common/common_handlers.h"
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <setjmp.h>
28 #include <cmocka.h>
29 #include <assert.h>
30 #include <string.h>
31
32 /* Modify this to change the logging level of Meshlink */
33 #define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG
34
35 static void test_case_mesh_open_01(void **state);
36 static bool test_steps_mesh_open_01(void);
37 static void test_case_mesh_open_02(void **state);
38 static bool test_steps_mesh_open_02(void);
39 static void test_case_mesh_open_03(void **state);
40 static bool test_steps_mesh_open_03(void);
41 static void test_case_mesh_open_04(void **state);
42 static bool test_steps_mesh_open_04(void);
43 static void test_case_mesh_open_05(void **state);
44 static bool test_steps_mesh_open_05(void);
45
46 /* State structure for meshlink_open Test Case #1 */
47 static black_box_state_t test_mesh_open_01_state = {
48         .test_case_name = "test_case_mesh_open_01",
49 };
50
51 /* State structure for meshlink_open Test Case #2 */
52 static black_box_state_t test_mesh_open_02_state = {
53         .test_case_name = "test_case_mesh_open_02",
54 };
55
56 /* State structure for meshlink_open Test Case #3 */
57 static black_box_state_t test_mesh_open_03_state = {
58         .test_case_name = "test_case_mesh_open_03",
59 };
60
61 /* State structure for meshlink_open Test Case #4 */
62 static black_box_state_t test_mesh_open_04_state = {
63         .test_case_name = "test_case_mesh_open_04",
64 };
65
66 /* State structure for meshlink_open Test Case #5 */
67 static black_box_state_t test_mesh_open_05_state = {
68         .test_case_name = "test_case_mesh_open_05",
69 };
70
71 /* Execute meshlink_open Test Case # 1*/
72 static void test_case_mesh_open_01(void **state) {
73         execute_test(test_steps_mesh_open_01, state);
74 }
75
76 /* Test Steps for meshlink_open Test Case # 1
77
78     Test Steps:
79     1. Open the node instance using meshlink_open
80
81     Expected Result:
82     meshlink_open API should successfully return a mesh handle.
83 */
84 static bool test_steps_mesh_open_01(void) {
85         meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
86         meshlink_handle_t *mesh = meshlink_open("open_conf", "foo", "test", DEV_CLASS_STATIONARY);
87         assert_int_not_equal(mesh, NULL);
88
89         meshlink_close(mesh);
90         meshlink_destroy("open_conf");
91         return true;
92 }
93
94 /* Execute meshlink_open Test Case # 2*/
95 static void test_case_mesh_open_02(void **state) {
96         execute_test(test_steps_mesh_open_02, state);
97 }
98
99 /* Test Steps for meshlink_open Test Case # 2
100
101     Test Steps:
102     1. Open the node instance using meshlink_open with NULL as confbase argument
103
104     Expected Result:
105     meshlink_open API should successfully report error by returning NULL pointer
106 */
107 static bool test_steps_mesh_open_02(void) {
108         meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
109         meshlink_handle_t *mesh = meshlink_open(NULL, "foo", "test", DEV_CLASS_STATIONARY);
110         assert_int_equal(mesh, NULL);
111
112         return true;
113 }
114
115 /* Execute meshlink_open Test Case # 3 */
116 static void test_case_mesh_open_03(void **state) {
117         execute_test(test_steps_mesh_open_03, state);
118 }
119
120 /* Test Steps for meshlink_open Test Case # 3
121
122     Test Steps:
123     1. Open the node instance using meshlink_open with NULL as node name argument
124
125     Expected Result:
126     meshlink_open API should successfully report error by returning NULL pointer
127 */
128 static bool test_steps_mesh_open_03(void) {
129         meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
130         meshlink_handle_t *mesh = meshlink_open("openconf", NULL, "test", DEV_CLASS_STATIONARY);
131         assert_int_equal(mesh, NULL);
132
133         meshlink_destroy("open_conf");
134         return true;
135 }
136
137 /* Execute meshlink_open Test Case # 4*/
138 static void test_case_mesh_open_04(void **state) {
139         execute_test(test_steps_mesh_open_04, state);
140 }
141
142 /* Test Steps for meshlink_open Test Case # 4
143
144     Test Steps:
145     1. Open the node instance using meshlink_open with NULL as app name argument
146
147     Expected Result:
148     meshlink_open API should successfully report error by returning NULL pointer
149 */
150 static bool test_steps_mesh_open_04(void) {
151         meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
152         meshlink_handle_t *mesh = meshlink_open("openconf", "foo", NULL, DEV_CLASS_STATIONARY);
153         assert_int_equal(mesh, NULL);
154
155         meshlink_destroy("open_conf");
156         return true;
157 }
158
159 /* Execute meshlink_open Test Case # 5*/
160 static void test_case_mesh_open_05(void **state) {
161         execute_test(test_steps_mesh_open_05, state);
162 }
163
164 /* Test Steps for meshlink_open Test Case # 5
165
166     Test Steps:
167     1. Open the node instance using meshlink_open with invalid device class argument
168
169     Expected Result:
170     meshlink_open API should successfully report error by returning NULL pointer
171 */
172 static bool test_steps_mesh_open_05(void) {
173         meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
174         meshlink_handle_t *mesh = meshlink_open("openconf", "foo", "test", -1);
175         assert_int_equal(mesh, NULL);
176
177         meshlink_destroy("open_conf");
178         return true;
179 }
180
181 int test_meshlink_open(void) {
182         const struct CMUnitTest blackbox_open_tests[] = {
183                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_open_01, NULL, NULL,
184                                 (void *)&test_mesh_open_01_state),
185                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_open_02, NULL, NULL,
186                                 (void *)&test_mesh_open_02_state),
187                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_open_03, NULL, NULL,
188                                 (void *)&test_mesh_open_03_state),
189                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_open_04, NULL, NULL,
190                                 (void *)&test_mesh_open_04_state),
191                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_open_05, NULL, NULL,
192                                 (void *)&test_mesh_open_05_state)
193
194         };
195         total_tests += sizeof(blackbox_open_tests) / sizeof(blackbox_open_tests[0]);
196
197         return cmocka_run_group_tests(blackbox_open_tests, NULL, NULL);
198 }