2 test_cases_open.c -- Execution of specific meshlink black box test cases
3 Copyright (C) 2018 Guus Sliepen <guus@meshlink.io>
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.
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.
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.
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"
32 /* Modify this to change the logging level of Meshlink */
33 #define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG
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);
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",
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",
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",
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",
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",
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);
76 /* Test Steps for meshlink_open Test Case # 1
79 1. Open the node instance using meshlink_open
82 meshlink_open API should successfully return a mesh handle.
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);
90 meshlink_destroy("open_conf");
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);
99 /* Test Steps for meshlink_open Test Case # 2
102 1. Open the node instance using meshlink_open with NULL as confbase argument
105 meshlink_open API should successfully report error by returning NULL pointer
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);
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);
120 /* Test Steps for meshlink_open Test Case # 3
123 1. Open the node instance using meshlink_open with NULL as node name argument
126 meshlink_open API should successfully report error by returning NULL pointer
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);
133 meshlink_destroy("open_conf");
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);
142 /* Test Steps for meshlink_open Test Case # 4
145 1. Open the node instance using meshlink_open with NULL as app name argument
148 meshlink_open API should successfully report error by returning NULL pointer
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);
155 meshlink_destroy("open_conf");
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);
164 /* Test Steps for meshlink_open Test Case # 5
167 1. Open the node instance using meshlink_open with invalid device class argument
170 meshlink_open API should successfully report error by returning NULL pointer
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);
177 meshlink_destroy("open_conf");
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)
195 total_tests += sizeof(blackbox_open_tests) / sizeof(blackbox_open_tests[0]);
197 return cmocka_run_group_tests(blackbox_open_tests, NULL, NULL);