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.
24 #include "execute_tests.h"
25 #include "test_cases_get_ex_addr.h"
26 #include "../common/containers.h"
27 #include "../common/test_step.h"
28 #include "../common/common_handlers.h"
36 static void test_case_mesh_get_address_01(void **state);
37 static bool test_steps_mesh_get_address_01(void);
38 static void test_case_mesh_get_address_02(void **state);
39 static bool test_steps_mesh_get_address_02(void);
40 static void test_case_mesh_get_address_03(void **state);
41 static bool test_steps_mesh_get_address_03(void);
43 /* State structure for meshlink_get_external_address Test Case #1 */
44 static black_box_state_t test_mesh_get_address_01_state = {
45 .test_case_name = "test_case_mesh_get_address_01",
48 /* State structure for meshlink_get_external_address Test Case #2 */
49 static black_box_state_t test_mesh_get_address_02_state = {
50 .test_case_name = "test_case_mesh_get_address_02",
53 /* State structure for meshlink_get_external_address Test Case #3 */
54 static black_box_state_t test_mesh_get_address_03_state = {
55 .test_case_name = "test_case_mesh_get_address_03",
58 /* Execute meshlink_get_external_address Test Case # 1 */
59 static void test_case_mesh_get_address_01(void **state) {
60 execute_test(test_steps_mesh_get_address_01, state);
63 /* Test Steps for meshlink_get_external_address Test Case # 1
66 1. Create an instance of the node & start it
67 2. Get node's external address using meshlink_get_external_address
70 API returns the external address successfully.
72 static bool test_steps_mesh_get_address_01(void) {
73 meshlink_handle_t *mesh = meshlink_open("getex_conf", "foo", "test", DEV_CLASS_STATIONARY);
75 assert(meshlink_start(mesh));
77 char *addr = meshlink_get_external_address(mesh);
78 assert_int_not_equal(addr, NULL);
82 assert(meshlink_destroy("getex_conf"));
86 /* Execute meshlink_get_external_address Test Case # 2 */
87 static void test_case_mesh_get_address_02(void **state) {
88 execute_test(test_steps_mesh_get_address_02, state);
91 /* Test Steps for meshlink_get_external_address Test Case # 2
94 1. Obtain external address by passing NULL as mesh handle
95 to meshlink_get_external_address API
98 Return NULL by reporting error successfully.
100 static bool test_steps_mesh_get_address_02(void) {
101 char *ext = meshlink_get_external_address(NULL);
102 assert_int_equal(ext, NULL);
107 /* Execute meshlink_get_external_address Test Case # 3 */
108 static void test_case_mesh_get_address_03(void **state) {
109 execute_test(test_steps_mesh_get_address_03, state);
112 /* Test Steps for meshlink_get_external_address Test Case # 3 - Functionality test
115 1. Create an instance of the node
116 2. Get node's external address using meshlink_get_external_address
119 API returns the external address successfully even if the mesh is started.
121 static bool test_steps_mesh_get_address_03(void) {
122 meshlink_handle_t *mesh = meshlink_open("getex_conf", "foo", "test", DEV_CLASS_STATIONARY);
123 assert(mesh != NULL);
124 assert(meshlink_start(mesh));
126 char *addr = meshlink_get_external_address(mesh);
127 assert_int_not_equal(addr, NULL);
130 meshlink_close(mesh);
131 assert(meshlink_destroy("getex_conf"));
135 int test_meshlink_get_external_address(void) {
136 const struct CMUnitTest blackbox_get_ex_addr_tests[] = {
137 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_address_01, NULL, NULL,
138 (void *)&test_mesh_get_address_01_state),
139 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_address_02, NULL, NULL,
140 (void *)&test_mesh_get_address_02_state),
141 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_get_address_03, NULL, NULL,
142 (void *)&test_mesh_get_address_03_state)
144 total_tests += sizeof(blackbox_get_ex_addr_tests) / sizeof(blackbox_get_ex_addr_tests[0]);
146 return cmocka_run_group_tests(blackbox_get_ex_addr_tests, NULL, NULL);