2 test_cases_channel_get_flags.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_channel_get_flags.h"
22 #include "../common/containers.h"
23 #include "../common/test_step.h"
24 #include "../common/common_handlers.h"
32 #define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG
33 /* Modify this to change the port number */
36 static void test_case_channel_get_flags_01(void **state);
37 static bool test_steps_channel_get_flags_01(void);
38 static void test_case_channel_get_flags_02(void **state);
39 static bool test_steps_channel_get_flags_02(void);
40 static void test_case_channel_get_flags_03(void **state);
41 static bool test_steps_channel_get_flags_03(void);
43 static black_box_state_t test_case_channel_get_flags_01_state = {
44 .test_case_name = "test_case_channel_get_flags_01",
46 static black_box_state_t test_case_channel_get_flags_02_state = {
47 .test_case_name = "test_case_channel_get_flags_02",
49 static black_box_state_t test_case_channel_get_flags_03_state = {
50 .test_case_name = "test_case_channel_get_flags_03",
52 static black_box_state_t test_case_channel_get_flags_04_state = {
53 .test_case_name = "test_case_channel_get_flags_04",
57 /* Execute meshlink_channel_get_flags Test Case # 1 - Valid case*/
58 static void test_case_channel_get_flags_01(void **state) {
59 execute_test(test_steps_channel_get_flags_01, state);
61 /* Test Steps for meshlink_channel_get_flags Test Case # 1
64 1. Run NUT(Node Under Test)
65 2. Open channel to ourself (with TCP semantic here)
66 3. Get flag(s) of that channel
69 API returning exact flag that has been assigned while opening (here TCP)
71 static bool test_steps_channel_get_flags_01(void) {
72 meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
74 /* Create meshlink instance */
75 meshlink_handle_t *mesh_handle = meshlink_open("getflagsconf", "nut", "node_sim", 1);
77 meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
78 meshlink_set_node_status_cb(mesh_handle, meshlink_callback_node_status);
79 meshlink_set_channel_accept_cb(mesh_handle, NULL);
81 assert(meshlink_start(mesh_handle));
83 meshlink_node_t *node = meshlink_get_self(mesh_handle);
87 /* Passing all valid arguments for meshlink_channel_open_ex */
88 meshlink_channel_t *channel;
89 channel = meshlink_channel_open_ex(mesh_handle, node, PORT, NULL, NULL, 0, MESHLINK_CHANNEL_TCP);
90 assert(channel != NULL);
92 // Obtaining channel flags using meshlink_channel_get_flags
93 uint32_t flags = meshlink_channel_get_flags(mesh_handle, channel);
94 assert_int_equal(flags, MESHLINK_CHANNEL_TCP);
96 meshlink_close(mesh_handle);
97 meshlink_destroy("getflagsconf");
102 /* Execute meshlink_channel_get_flags Test Case # 2 - Invalid case*/
103 static void test_case_channel_get_flags_02(void **state) {
104 execute_test(test_steps_channel_get_flags_02, state);
106 /* Test Steps for meshlink_channel_get_flags Test Case # 2
109 1. Run NUT(Node Under Test)
110 2. Open channel to ourself (with TCP semantic here)
111 3. Call meshlink_channel_get_flags by passing NULL as mesh handle argument
114 API reporting error accordingly.
116 static bool test_steps_channel_get_flags_02(void) {
117 meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
119 /* Create meshlink instance */
120 meshlink_handle_t *mesh_handle = meshlink_open("getflagsconf", "nut", "node_sim", 1);
123 meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
124 meshlink_set_node_status_cb(mesh_handle, meshlink_callback_node_status);
125 meshlink_set_channel_accept_cb(mesh_handle, NULL);
127 assert(meshlink_start(mesh_handle));
129 /* Getting node handle for itself */
130 meshlink_node_t *node = meshlink_get_self(mesh_handle);
131 assert(node != NULL);
134 /* Passing all valid arguments for meshlink_channel_open_ex */
135 meshlink_channel_t *channel;
136 channel = meshlink_channel_open_ex(mesh_handle, node, PORT, NULL, NULL, 0, MESHLINK_CHANNEL_TCP);
137 assert(channel != NULL);
139 // passing NULL as mesh handle argument for meshlink_channel_get_flags
140 uint32_t flags = meshlink_channel_get_flags(NULL, channel);
142 assert_int_equal((int32_t)flags, -1);
143 assert_int_equal(meshlink_errno, MESHLINK_EINVAL);
145 meshlink_close(mesh_handle);
146 meshlink_destroy("getflagsconf");
150 /* Execute meshlink_channel_get flags Test Case # 3 - Invalid case*/
151 static void test_case_channel_get_flags_03(void **state) {
152 execute_test(test_steps_channel_get_flags_03, state);
154 /* Test Steps for meshlink_channel_get_flags Test Case # 3
157 1. Run NUT(Node Under Test)
158 3. Call meshlink_channel_get_flags by passing NULL as channel handle argument
161 API reporting error accordingly.
163 static bool test_steps_channel_get_flags_03(void) {
164 meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
166 /* Create meshlink instance */
167 meshlink_handle_t *mesh_handle = meshlink_open("getflagsconf", "nut", "node_sim", 1);
169 meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
170 meshlink_set_node_status_cb(mesh_handle, meshlink_callback_node_status);
171 meshlink_set_channel_accept_cb(mesh_handle, NULL);
173 assert(meshlink_start(mesh_handle));
175 // passing NULL as channel handle argument for meshlink_channel_get_flags
176 uint32_t flags = meshlink_channel_get_flags(mesh_handle, NULL);
178 assert_int_equal((int32_t)flags, -1);
179 assert_int_equal(meshlink_errno, MESHLINK_EINVAL);
181 meshlink_close(mesh_handle);
182 meshlink_destroy("getflagsconf");
187 int test_meshlink_channel_get_flags(void) {
188 const struct CMUnitTest blackbox_channel_get_flags_tests[] = {
189 cmocka_unit_test_prestate_setup_teardown(test_case_channel_get_flags_01, NULL, NULL,
190 (void *)&test_case_channel_get_flags_01_state),
191 cmocka_unit_test_prestate_setup_teardown(test_case_channel_get_flags_02, NULL, NULL,
192 (void *)&test_case_channel_get_flags_02_state),
193 cmocka_unit_test_prestate_setup_teardown(test_case_channel_get_flags_03, NULL, NULL,
194 (void *)&test_case_channel_get_flags_03_state)
197 total_tests += sizeof(blackbox_channel_get_flags_tests) / sizeof(blackbox_channel_get_flags_tests[0]);
199 return cmocka_run_group_tests(blackbox_channel_get_flags_tests, NULL, NULL);