2 test_cases_send.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_send.h"
22 #include "../common/containers.h"
23 #include "../common/test_step.h"
24 #include "../common/common_handlers.h"
32 static void test_case_mesh_send_01(void **state);
33 static bool test_steps_mesh_send_01(void);
34 static void test_case_mesh_send_02(void **state);
35 static bool test_steps_mesh_send_02(void);
36 static void test_case_mesh_send_03(void **state);
37 static bool test_steps_mesh_send_03(void);
39 /* State structure for meshlink_send Test Case #1 */
40 static black_box_state_t test_mesh_send_01_state = {
41 .test_case_name = "test_case_mesh_send_01",
44 /* State structure for meshlink_send Test Case #2 */
45 static black_box_state_t test_mesh_send_02_state = {
46 .test_case_name = "test_case_mesh_send_02",
49 /* State structure for meshlink_send Test Case #3 */
50 static black_box_state_t test_mesh_send_03_state = {
51 .test_case_name = "test_case_mesh_send_03",
54 /* Execute meshlink_send Test Case # 1 */
55 static void test_case_mesh_send_01(void **state) {
56 execute_test(test_steps_mesh_send_01, state);
59 static bool receive_data = false;
60 static void receive(meshlink_handle_t *mesh, meshlink_node_t *dest_node, const void *data, size_t len) {
66 if(!memcmp(data, "test", 5)) {
71 /* Test Steps for meshlink_send Test Case # 1
74 1. Open instance of foo node
75 2. Run and send data to itself
78 Node should receive data sent to itself
80 static bool test_steps_mesh_send_01(void) {
83 meshlink_handle_t *mesh = meshlink_open("send_conf", "foo", "test", DEV_CLASS_STATIONARY);
85 meshlink_set_receive_cb(mesh, receive);
86 assert(meshlink_start(mesh));
88 meshlink_node_t *dest_node = meshlink_get_self(mesh);
92 result = meshlink_send(mesh, dest_node, "test", 5);
93 assert_int_equal(result, true);
95 assert_int_equal(receive_data, true);
98 meshlink_destroy("send_conf");
102 /* Execute meshlink_send Test Case # 2
105 1. Open instance of foo node
106 2. meshlink_send with NULL as mesh handle
109 meshlink_send returns false because of NULL handle
111 static void test_case_mesh_send_02(void **state) {
112 execute_test(test_steps_mesh_send_02, state);
115 /* Test Steps for meshlink_send Test Case # 2*/
116 static bool test_steps_mesh_send_02(void) {
117 meshlink_handle_t *mesh = meshlink_open("send_conf", "foo", "chat", DEV_CLASS_STATIONARY);
118 assert(mesh != NULL);
119 meshlink_set_receive_cb(mesh, receive);
121 assert(meshlink_start(mesh));
122 meshlink_node_t *dest_node = meshlink_get_self(mesh);
125 bool ret = meshlink_send(NULL, dest_node, "test", 5);
126 assert_int_equal(ret, false);
128 meshlink_close(mesh);
129 meshlink_destroy("send_conf");
133 /* Execute meshlink_send Test Case # 3
136 1. Open instance of foo node
137 2. meshlink_send with NULL as node handle
140 meshlink_send returns false because of NULL handle
142 static void test_case_mesh_send_03(void **state) {
143 execute_test(test_steps_mesh_send_03, state);
146 /* Test Steps for meshlink_send Test Case # 3*/
147 static bool test_steps_mesh_send_03(void) {
148 meshlink_handle_t *mesh = meshlink_open("send_conf", "foo", "chat", DEV_CLASS_STATIONARY);
149 assert(mesh != NULL);
150 meshlink_set_receive_cb(mesh, receive);
152 assert(meshlink_start(mesh));
154 bool ret = meshlink_send(mesh, NULL, "test", 5);
155 assert_int_equal(ret, false);
157 meshlink_close(mesh);
158 meshlink_destroy("send_conf");
162 int test_meshlink_send(void) {
163 const struct CMUnitTest blackbox_send_tests[] = {
164 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_send_01, NULL, NULL,
165 (void *)&test_mesh_send_01_state),
166 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_send_02, NULL, NULL,
167 (void *)&test_mesh_send_02_state),
168 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_send_03, NULL, NULL,
169 (void *)&test_mesh_send_03_state)
172 total_tests += sizeof(blackbox_send_tests) / sizeof(blackbox_send_tests[0]);
174 return cmocka_run_group_tests(blackbox_send_tests, NULL, NULL);