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",
47 static black_box_state_t test_case_channel_get_flags_02_state = {
48 .test_case_name = "test_case_channel_get_flags_02",
51 static black_box_state_t test_case_channel_get_flags_03_state = {
52 .test_case_name = "test_case_channel_get_flags_03",
55 /* Execute meshlink_channel_get_flags Test Case # 1 - Valid case*/
56 static void test_case_channel_get_flags_01(void **state) {
57 execute_test(test_steps_channel_get_flags_01, state);
59 /* Test Steps for meshlink_channel_get_flags Test Case # 1
62 1. Run NUT(Node Under Test)
63 2. Open channel to ourself (with TCP semantic here)
64 3. Get flag(s) of that channel
67 API returning exact flag that has been assigned while opening (here TCP)
69 static bool test_steps_channel_get_flags_01(void) {
70 meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
72 /* Create meshlink instance */
73 meshlink_handle_t *mesh_handle = meshlink_open("getflagsconf", "nut", "node_sim", 1);
75 meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
76 meshlink_set_node_status_cb(mesh_handle, meshlink_callback_node_status);
77 meshlink_set_channel_accept_cb(mesh_handle, NULL);
79 assert(meshlink_start(mesh_handle));
81 meshlink_node_t *node = meshlink_get_self(mesh_handle);
85 /* Passing all valid arguments for meshlink_channel_open_ex */
86 meshlink_channel_t *channel;
87 channel = meshlink_channel_open_ex(mesh_handle, node, PORT, NULL, NULL, 0, MESHLINK_CHANNEL_TCP);
88 assert(channel != NULL);
90 // Obtaining channel flags using meshlink_channel_get_flags
91 uint32_t flags = meshlink_channel_get_flags(mesh_handle, channel);
92 assert_int_equal(flags, MESHLINK_CHANNEL_TCP);
94 meshlink_close(mesh_handle);
95 meshlink_destroy("getflagsconf");
100 /* Execute meshlink_channel_get_flags Test Case # 2 - Invalid case*/
101 static void test_case_channel_get_flags_02(void **state) {
102 execute_test(test_steps_channel_get_flags_02, state);
104 /* Test Steps for meshlink_channel_get_flags Test Case # 2
107 1. Run NUT(Node Under Test)
108 2. Open channel to ourself (with TCP semantic here)
109 3. Call meshlink_channel_get_flags by passing NULL as mesh handle argument
112 API reporting error accordingly.
114 static bool test_steps_channel_get_flags_02(void) {
115 meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
117 /* Create meshlink instance */
118 meshlink_handle_t *mesh_handle = meshlink_open("getflagsconf", "nut", "node_sim", 1);
121 meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
122 meshlink_set_node_status_cb(mesh_handle, meshlink_callback_node_status);
123 meshlink_set_channel_accept_cb(mesh_handle, NULL);
125 assert(meshlink_start(mesh_handle));
127 /* Getting node handle for itself */
128 meshlink_node_t *node = meshlink_get_self(mesh_handle);
129 assert(node != NULL);
132 /* Passing all valid arguments for meshlink_channel_open_ex */
133 meshlink_channel_t *channel;
134 channel = meshlink_channel_open_ex(mesh_handle, node, PORT, NULL, NULL, 0, MESHLINK_CHANNEL_TCP);
135 assert(channel != NULL);
137 // passing NULL as mesh handle argument for meshlink_channel_get_flags
138 uint32_t flags = meshlink_channel_get_flags(NULL, channel);
140 assert_int_equal((int32_t)flags, -1);
141 assert_int_equal(meshlink_errno, MESHLINK_EINVAL);
143 meshlink_close(mesh_handle);
144 meshlink_destroy("getflagsconf");
148 /* Execute meshlink_channel_get flags Test Case # 3 - Invalid case*/
149 static void test_case_channel_get_flags_03(void **state) {
150 execute_test(test_steps_channel_get_flags_03, state);
152 /* Test Steps for meshlink_channel_get_flags Test Case # 3
155 1. Run NUT(Node Under Test)
156 3. Call meshlink_channel_get_flags by passing NULL as channel handle argument
159 API reporting error accordingly.
161 static bool test_steps_channel_get_flags_03(void) {
162 meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
164 /* Create meshlink instance */
165 meshlink_handle_t *mesh_handle = meshlink_open("getflagsconf", "nut", "node_sim", 1);
167 meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
168 meshlink_set_node_status_cb(mesh_handle, meshlink_callback_node_status);
169 meshlink_set_channel_accept_cb(mesh_handle, NULL);
171 assert(meshlink_start(mesh_handle));
173 // passing NULL as channel handle argument for meshlink_channel_get_flags
174 uint32_t flags = meshlink_channel_get_flags(mesh_handle, NULL);
176 assert_int_equal((int32_t)flags, -1);
177 assert_int_equal(meshlink_errno, MESHLINK_EINVAL);
179 meshlink_close(mesh_handle);
180 meshlink_destroy("getflagsconf");
185 int test_meshlink_channel_get_flags(void) {
186 const struct CMUnitTest blackbox_channel_get_flags_tests[] = {
187 cmocka_unit_test_prestate_setup_teardown(test_case_channel_get_flags_01, NULL, NULL,
188 (void *)&test_case_channel_get_flags_01_state),
189 cmocka_unit_test_prestate_setup_teardown(test_case_channel_get_flags_02, NULL, NULL,
190 (void *)&test_case_channel_get_flags_02_state),
191 cmocka_unit_test_prestate_setup_teardown(test_case_channel_get_flags_03, NULL, NULL,
192 (void *)&test_case_channel_get_flags_03_state)
195 total_tests += sizeof(blackbox_channel_get_flags_tests) / sizeof(blackbox_channel_get_flags_tests[0]);
197 return cmocka_run_group_tests(blackbox_channel_get_flags_tests, NULL, NULL);