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.
24 #include "execute_tests.h"
25 #include "test_cases_channel_get_flags.h"
26 #include "../common/containers.h"
27 #include "../common/test_step.h"
28 #include "../common/common_handlers.h"
36 #define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG
37 /* Modify this to change the port number */
40 static void test_case_channel_get_flags_01(void **state);
41 static bool test_steps_channel_get_flags_01(void);
42 static void test_case_channel_get_flags_02(void **state);
43 static bool test_steps_channel_get_flags_02(void);
44 static void test_case_channel_get_flags_03(void **state);
45 static bool test_steps_channel_get_flags_03(void);
47 static black_box_state_t test_case_channel_get_flags_01_state = {
48 .test_case_name = "test_case_channel_get_flags_01",
51 static black_box_state_t test_case_channel_get_flags_02_state = {
52 .test_case_name = "test_case_channel_get_flags_02",
55 static black_box_state_t test_case_channel_get_flags_03_state = {
56 .test_case_name = "test_case_channel_get_flags_03",
59 /* Execute meshlink_channel_get_flags Test Case # 1 - Valid case*/
60 static void test_case_channel_get_flags_01(void **state) {
61 execute_test(test_steps_channel_get_flags_01, state);
63 /* Test Steps for meshlink_channel_get_flags Test Case # 1
66 1. Run NUT(Node Under Test)
67 2. Open channel to ourself (with TCP semantic here)
68 3. Get flag(s) of that channel
71 API returning exact flag that has been assigned while opening (here TCP)
73 static bool test_steps_channel_get_flags_01(void) {
74 meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
76 /* Create meshlink instance */
77 meshlink_handle_t *mesh_handle = meshlink_open("getflagsconf", "nut", "node_sim", 1);
79 meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
80 meshlink_set_node_status_cb(mesh_handle, meshlink_callback_node_status);
81 meshlink_set_channel_accept_cb(mesh_handle, NULL);
83 assert(meshlink_start(mesh_handle));
85 meshlink_node_t *node = meshlink_get_self(mesh_handle);
89 /* Passing all valid arguments for meshlink_channel_open_ex */
90 meshlink_channel_t *channel;
91 channel = meshlink_channel_open_ex(mesh_handle, node, PORT, NULL, NULL, 0, MESHLINK_CHANNEL_TCP);
92 assert(channel != NULL);
94 // Obtaining channel flags using meshlink_channel_get_flags
95 uint32_t flags = meshlink_channel_get_flags(mesh_handle, channel);
96 assert_int_equal(flags, MESHLINK_CHANNEL_TCP);
98 meshlink_close(mesh_handle);
99 assert(meshlink_destroy("getflagsconf"));
104 /* Execute meshlink_channel_get_flags Test Case # 2 - Invalid case*/
105 static void test_case_channel_get_flags_02(void **state) {
106 execute_test(test_steps_channel_get_flags_02, state);
108 /* Test Steps for meshlink_channel_get_flags Test Case # 2
111 1. Run NUT(Node Under Test)
112 2. Open channel to ourself (with TCP semantic here)
113 3. Call meshlink_channel_get_flags by passing NULL as mesh handle argument
116 API reporting error accordingly.
118 static bool test_steps_channel_get_flags_02(void) {
119 meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
121 /* Create meshlink instance */
122 meshlink_handle_t *mesh_handle = meshlink_open("getflagsconf", "nut", "node_sim", 1);
125 meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
126 meshlink_set_node_status_cb(mesh_handle, meshlink_callback_node_status);
127 meshlink_set_channel_accept_cb(mesh_handle, NULL);
129 assert(meshlink_start(mesh_handle));
131 /* Getting node handle for itself */
132 meshlink_node_t *node = meshlink_get_self(mesh_handle);
133 assert(node != NULL);
136 /* Passing all valid arguments for meshlink_channel_open_ex */
137 meshlink_channel_t *channel;
138 channel = meshlink_channel_open_ex(mesh_handle, node, PORT, NULL, NULL, 0, MESHLINK_CHANNEL_TCP);
139 assert(channel != NULL);
141 // passing NULL as mesh handle argument for meshlink_channel_get_flags
142 uint32_t flags = meshlink_channel_get_flags(NULL, channel);
144 assert_int_equal((int32_t)flags, -1);
145 assert_int_equal(meshlink_errno, MESHLINK_EINVAL);
147 meshlink_close(mesh_handle);
148 assert(meshlink_destroy("getflagsconf"));
152 /* Execute meshlink_channel_get flags Test Case # 3 - Invalid case*/
153 static void test_case_channel_get_flags_03(void **state) {
154 execute_test(test_steps_channel_get_flags_03, state);
156 /* Test Steps for meshlink_channel_get_flags Test Case # 3
159 1. Run NUT(Node Under Test)
160 3. Call meshlink_channel_get_flags by passing NULL as channel handle argument
163 API reporting error accordingly.
165 static bool test_steps_channel_get_flags_03(void) {
166 meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
168 /* Create meshlink instance */
169 meshlink_handle_t *mesh_handle = meshlink_open("getflagsconf", "nut", "node_sim", 1);
171 meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
172 meshlink_set_node_status_cb(mesh_handle, meshlink_callback_node_status);
173 meshlink_set_channel_accept_cb(mesh_handle, NULL);
175 assert(meshlink_start(mesh_handle));
177 // passing NULL as channel handle argument for meshlink_channel_get_flags
178 uint32_t flags = meshlink_channel_get_flags(mesh_handle, NULL);
180 assert_int_equal((int32_t)flags, -1);
181 assert_int_equal(meshlink_errno, MESHLINK_EINVAL);
183 meshlink_close(mesh_handle);
184 assert(meshlink_destroy("getflagsconf"));
189 int test_meshlink_channel_get_flags(void) {
190 const struct CMUnitTest blackbox_channel_get_flags_tests[] = {
191 cmocka_unit_test_prestate_setup_teardown(test_case_channel_get_flags_01, NULL, NULL,
192 (void *)&test_case_channel_get_flags_01_state),
193 cmocka_unit_test_prestate_setup_teardown(test_case_channel_get_flags_02, NULL, NULL,
194 (void *)&test_case_channel_get_flags_02_state),
195 cmocka_unit_test_prestate_setup_teardown(test_case_channel_get_flags_03, NULL, NULL,
196 (void *)&test_case_channel_get_flags_03_state)
199 total_tests += sizeof(blackbox_channel_get_flags_tests) / sizeof(blackbox_channel_get_flags_tests[0]);
201 return cmocka_run_group_tests(blackbox_channel_get_flags_tests, NULL, NULL);