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.
24 #include "execute_tests.h"
25 #include "test_cases_send.h"
26 #include "../common/containers.h"
27 #include "../common/test_step.h"
28 #include "../common/common_handlers.h"
36 static void test_case_mesh_send_01(void **state);
37 static bool test_steps_mesh_send_01(void);
38 static void test_case_mesh_send_02(void **state);
39 static bool test_steps_mesh_send_02(void);
40 static void test_case_mesh_send_03(void **state);
41 static bool test_steps_mesh_send_03(void);
43 /* State structure for meshlink_send Test Case #1 */
44 static black_box_state_t test_mesh_send_01_state = {
45 .test_case_name = "test_case_mesh_send_01",
48 /* State structure for meshlink_send Test Case #2 */
49 static black_box_state_t test_mesh_send_02_state = {
50 .test_case_name = "test_case_mesh_send_02",
53 /* State structure for meshlink_send Test Case #3 */
54 static black_box_state_t test_mesh_send_03_state = {
55 .test_case_name = "test_case_mesh_send_03",
58 /* Execute meshlink_send Test Case # 1 */
59 static void test_case_mesh_send_01(void **state) {
60 execute_test(test_steps_mesh_send_01, state);
63 static bool receive_data = false;
64 static void receive(meshlink_handle_t *mesh, meshlink_node_t *dest_node, const void *data, size_t len) {
70 if(!memcmp(data, "test", 5)) {
75 /* Test Steps for meshlink_send Test Case # 1
78 1. Open instance of foo node
79 2. Run and send data to itself
82 Node should receive data sent to itself
84 static bool test_steps_mesh_send_01(void) {
87 meshlink_handle_t *mesh = meshlink_open("send_conf", "foo", "test", DEV_CLASS_STATIONARY);
89 meshlink_set_receive_cb(mesh, receive);
90 assert(meshlink_start(mesh));
92 meshlink_node_t *dest_node = meshlink_get_self(mesh);
96 result = meshlink_send(mesh, dest_node, "test", 5);
97 assert_int_equal(result, true);
99 assert_int_equal(receive_data, true);
101 meshlink_close(mesh);
102 assert(meshlink_destroy("send_conf"));
106 /* Execute meshlink_send Test Case # 2
109 1. Open instance of foo node
110 2. meshlink_send with NULL as mesh handle
113 meshlink_send returns false because of NULL handle
115 static void test_case_mesh_send_02(void **state) {
116 execute_test(test_steps_mesh_send_02, state);
119 /* Test Steps for meshlink_send Test Case # 2*/
120 static bool test_steps_mesh_send_02(void) {
121 meshlink_handle_t *mesh = meshlink_open("send_conf", "foo", "chat", DEV_CLASS_STATIONARY);
122 assert(mesh != NULL);
123 meshlink_set_receive_cb(mesh, receive);
125 assert(meshlink_start(mesh));
126 meshlink_node_t *dest_node = meshlink_get_self(mesh);
129 bool ret = meshlink_send(NULL, dest_node, "test", 5);
130 assert_int_equal(ret, false);
132 meshlink_close(mesh);
133 assert(meshlink_destroy("send_conf"));
137 /* Execute meshlink_send Test Case # 3
140 1. Open instance of foo node
141 2. meshlink_send with NULL as node handle
144 meshlink_send returns false because of NULL handle
146 static void test_case_mesh_send_03(void **state) {
147 execute_test(test_steps_mesh_send_03, state);
150 /* Test Steps for meshlink_send Test Case # 3*/
151 static bool test_steps_mesh_send_03(void) {
152 meshlink_handle_t *mesh = meshlink_open("send_conf", "foo", "chat", DEV_CLASS_STATIONARY);
153 assert(mesh != NULL);
154 meshlink_set_receive_cb(mesh, receive);
156 assert(meshlink_start(mesh));
158 bool ret = meshlink_send(mesh, NULL, "test", 5);
159 assert_int_equal(ret, false);
161 meshlink_close(mesh);
162 assert(meshlink_destroy("send_conf"));
166 int test_meshlink_send(void) {
167 const struct CMUnitTest blackbox_send_tests[] = {
168 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_send_01, NULL, NULL,
169 (void *)&test_mesh_send_01_state),
170 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_send_02, NULL, NULL,
171 (void *)&test_mesh_send_02_state),
172 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_send_03, NULL, NULL,
173 (void *)&test_mesh_send_03_state)
176 total_tests += sizeof(blackbox_send_tests) / sizeof(blackbox_send_tests[0]);
178 return cmocka_run_group_tests(blackbox_send_tests, NULL, NULL);