2 test_cases_get_ex_addr.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_ex_addr.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_address_01(void **state);
33 static bool test_steps_mesh_get_address_01(void);
34 static void test_case_mesh_get_address_02(void **state);
35 static bool test_steps_mesh_get_address_02(void);
36 static void test_case_mesh_get_address_03(void **state);
37 static bool test_steps_mesh_get_address_03(void);
39 /* State structure for meshlink_get_external_address Test Case #1 */
40 static black_box_state_t test_mesh_get_address_01_state = {
41 .test_case_name = "test_case_mesh_get_address_01",
44 /* State structure for meshlink_get_external_address Test Case #2 */
45 static black_box_state_t test_mesh_get_address_02_state = {
46 .test_case_name = "test_case_mesh_get_address_02",
49 /* State structure for meshlink_get_external_address Test Case #3 */
50 static black_box_state_t test_mesh_get_address_03_state = {
51 .test_case_name = "test_case_mesh_get_address_03",
54 /* Execute meshlink_get_external_address Test Case # 1 */
55 static void test_case_mesh_get_address_01(void **state) {
56 execute_test(test_steps_mesh_get_address_01, state);
59 /* Test Steps for meshlink_get_external_address Test Case # 1
62 1. Create an instance of the node & start it
63 2. Get node's external address using meshlink_get_external_address
66 API returns the external address successfully.
68 static bool test_steps_mesh_get_address_01(void) {
69 meshlink_handle_t *mesh = meshlink_open("getex_conf", "foo", "test", DEV_CLASS_STATIONARY);
71 assert(meshlink_start(mesh));
73 char *addr = meshlink_get_external_address(mesh);
74 assert_int_not_equal(addr, NULL);
78 meshlink_destroy("getex_conf");
82 /* Execute meshlink_get_external_address Test Case # 2 */
83 static void test_case_mesh_get_address_02(void **state) {
84 execute_test(test_steps_mesh_get_address_02, state);
87 /* Test Steps for meshlink_get_external_address Test Case # 2
90 1. Obtain external address by passing NULL as mesh handle
91 to meshlink_get_external_address API
94 Return NULL by reporting error successfully.
96 static bool test_steps_mesh_get_address_02(void) {
97 char *ext = meshlink_get_external_address(NULL);
98 assert_int_equal(ext, NULL);
103 /* Execute meshlink_get_external_address Test Case # 3 */
104 static void test_case_mesh_get_address_03(void **state) {
105 execute_test(test_steps_mesh_get_address_03, state);
108 /* Test Steps for meshlink_get_external_address Test Case # 3 - Functionality test
111 1. Create an instance of the node
112 2. Get node's external address using meshlink_get_external_address
115 API returns the external address successfully even if the mesh is started.
117 static bool test_steps_mesh_get_address_03(void) {
118 meshlink_handle_t *mesh = meshlink_open("getex_conf", "foo", "test", DEV_CLASS_STATIONARY);
119 assert(mesh != NULL);
120 assert(meshlink_start(mesh));
122 char *addr = meshlink_get_external_address(mesh);
123 assert_int_not_equal(addr, NULL);
126 meshlink_close(mesh);
127 meshlink_destroy("getex_conf");
131 int test_meshlink_get_external_address(void) {
132 const struct CMUnitTest blackbox_get_ex_addr_tests[] = {
133 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_address_01, NULL, NULL,
134 (void *)&test_mesh_get_address_01_state),
135 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_address_02, NULL, NULL,
136 (void *)&test_mesh_get_address_02_state),
137 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_address_03, NULL, NULL,
138 (void *)&test_mesh_get_address_03_state)
140 total_tests += sizeof(blackbox_get_ex_addr_tests) / sizeof(blackbox_get_ex_addr_tests[0]);
142 return cmocka_run_group_tests(blackbox_get_ex_addr_tests, NULL, NULL);