]> git.meshlink.io Git - meshlink/blob - test/blackbox/run_blackbox_tests/test_cases_get_ex_addr.c
Fix __warn_unused_result__, add more of it and fix the resulting warnings.
[meshlink] / test / blackbox / run_blackbox_tests / test_cases_get_ex_addr.c
1 /*
2     test_cases_get_ex_addr.c -- Execution of specific meshlink black box test cases
3     Copyright (C) 2018  Guus Sliepen <guus@meshlink.io>
4
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.
9
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.
14
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.
18 */
19
20 #ifdef NDEBUG
21 #undef NDEBUG
22 #endif
23
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"
29 #include <stdlib.h>
30 #include <stdarg.h>
31 #include <setjmp.h>
32 #include <cmocka.h>
33 #include <assert.h>
34 #include <string.h>
35
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);
42
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",
46 };
47
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",
51 };
52
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",
56 };
57
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);
61 }
62
63 /* Test Steps for meshlink_get_external_address Test Case # 1
64
65     Test Steps:
66     1. Create an instance of the node & start it
67     2. Get node's external address using meshlink_get_external_address
68
69     Expected Result:
70     API returns the external address successfully.
71 */
72 static bool test_steps_mesh_get_address_01(void) {
73         meshlink_handle_t *mesh = meshlink_open("getex_conf", "foo", "test", DEV_CLASS_STATIONARY);
74         assert(mesh != NULL);
75         assert(meshlink_start(mesh));
76
77         char *addr = meshlink_get_external_address(mesh);
78         assert_int_not_equal(addr, NULL);
79
80         free(addr);
81         meshlink_close(mesh);
82         assert(meshlink_destroy("getex_conf"));
83         return true;
84 }
85
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);
89 }
90
91 /* Test Steps for meshlink_get_external_address Test Case # 2
92
93     Test Steps:
94     1. Obtain external address by passing NULL as mesh handle
95         to meshlink_get_external_address API
96
97     Expected Result:
98     Return NULL by reporting error successfully.
99 */
100 static bool test_steps_mesh_get_address_02(void) {
101         char *ext = meshlink_get_external_address(NULL);
102         assert_int_equal(ext, NULL);
103
104         return true;
105 }
106
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);
110 }
111
112 /* Test Steps for meshlink_get_external_address Test Case # 3 - Functionality test
113
114     Test Steps:
115     1. Create an instance of the node
116     2. Get node's external address using meshlink_get_external_address
117
118     Expected Result:
119     API returns the external address successfully even if the mesh is started.
120 */
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));
125
126         char *addr = meshlink_get_external_address(mesh);
127         assert_int_not_equal(addr, NULL);
128
129         free(addr);
130         meshlink_close(mesh);
131         assert(meshlink_destroy("getex_conf"));
132         return true;
133 }
134
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)
143         };
144         total_tests += sizeof(blackbox_get_ex_addr_tests) / sizeof(blackbox_get_ex_addr_tests[0]);
145
146         return cmocka_run_group_tests(blackbox_get_ex_addr_tests, NULL, NULL);
147 }