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.
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"
36 /* Modify this to change the logging level of Meshlink */
37 #define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG
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);
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",
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",
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",
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",
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",
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);
80 /* Test Steps for meshlink_open Test Case # 1
83 1. Open the node instance using meshlink_open
86 meshlink_open API should successfully return a mesh handle.
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);
94 assert(meshlink_destroy("open_conf"));
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);
103 /* Test Steps for meshlink_open Test Case # 2
106 1. Open the node instance using meshlink_open with NULL as confbase argument
109 meshlink_open API should successfully report error by returning NULL pointer
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);
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);
124 /* Test Steps for meshlink_open Test Case # 3
127 1. Open the node instance using meshlink_open with NULL as node name argument
130 meshlink_open API should successfully report error by returning NULL pointer
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);
137 assert(meshlink_destroy("open_conf"));
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);
146 /* Test Steps for meshlink_open Test Case # 4
149 1. Open the node instance using meshlink_open with NULL as app name argument
152 meshlink_open API should successfully report error by returning NULL pointer
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);
159 assert(meshlink_destroy("open_conf"));
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);
168 /* Test Steps for meshlink_open Test Case # 5
171 1. Open the node instance using meshlink_open with invalid device class argument
174 meshlink_open API should successfully report error by returning NULL pointer
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);
181 assert(meshlink_destroy("open_conf"));
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)
199 total_tests += sizeof(blackbox_open_tests) / sizeof(blackbox_open_tests[0]);
201 return cmocka_run_group_tests(blackbox_open_tests, NULL, NULL);