2 test_cases_get_port.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_get_port.h"
22 #include "../common/containers.h"
23 #include "../common/test_step.h"
24 #include "../common/common_handlers.h"
32 static void test_case_mesh_get_port_01(void **state);
33 static bool test_steps_mesh_get_port_01(void);
34 static void test_case_mesh_get_port_02(void **state);
35 static bool test_steps_mesh_get_port_02(void);
37 /* State structure for meshlink_get_port Test Case #1 */
38 static black_box_state_t test_mesh_get_port_01_state = {
39 .test_case_name = "test_case_mesh_get_port_01",
42 /* State structure for meshlink_get_port Test Case #2 */
43 static black_box_state_t test_mesh_get_port_02_state = {
44 .test_case_name = "test_case_mesh_get_port_02",
47 /* Execute meshlink_get_port Test Case # 1 */
48 static void test_case_mesh_get_port_01(void **state) {
49 execute_test(test_steps_mesh_get_port_01, state);
52 /* Test Steps for meshlink_get_port Test Case # 1
56 2. Run the node instance
57 3. Obtain port of that mesh using meshlink_get_port API
60 API returns valid port number.
62 static bool test_steps_mesh_get_port_01(void) {
63 meshlink_handle_t *mesh = meshlink_open("port_conf", "foo", "chat", DEV_CLASS_STATIONARY);
65 assert(meshlink_start(mesh));
67 int port = meshlink_get_port(mesh);
68 assert_int_not_equal(port, -1);
71 meshlink_destroy("port_conf");
75 /* Execute meshlink_get_port Test Case # 2 */
76 static void test_case_mesh_get_port_02(void **state) {
77 execute_test(test_steps_mesh_get_port_02, state);
80 /* Test Steps for meshlink_get_port Test Case # 2 - Invalid case
83 1. Pass NULL as mesh handle argument to meshlink_get_port API
86 Reports error successfully by returning -1
88 static bool test_steps_mesh_get_port_02(void) {
89 int port = meshlink_get_port(NULL);
90 assert_int_equal(port, -1);
95 int test_meshlink_get_port(void) {
96 const struct CMUnitTest blackbox_get_port_tests[] = {
97 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_port_01, NULL, NULL,
98 (void *)&test_mesh_get_port_01_state),
99 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_port_02, NULL, NULL,
100 (void *)&test_mesh_get_port_02_state)
103 total_tests += sizeof(blackbox_get_port_tests) / sizeof(blackbox_get_port_tests[0]);
105 return cmocka_run_group_tests(blackbox_get_port_tests, NULL, NULL);