]> git.meshlink.io Git - meshlink/blob - test/blackbox/run_blackbox_tests/test_cases_get_ex_addr.c
Add the blackbox container based test suite.
[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 #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"
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <setjmp.h>
28 #include <cmocka.h>
29 #include <assert.h>
30 #include <string.h>
31
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);
38
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",
42 };
43
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",
47 };
48
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",
52 };
53
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);
57 }
58
59 /* Test Steps for meshlink_get_external_address Test Case # 1
60
61     Test Steps:
62     1. Create an instance of the node & start it
63     2. Get node's external address using meshlink_get_external_address
64
65     Expected Result:
66     API returns the external address successfully.
67 */
68 static bool test_steps_mesh_get_address_01(void) {
69         meshlink_handle_t *mesh = meshlink_open("getex_conf", "foo", "test", DEV_CLASS_STATIONARY);
70         assert(mesh != NULL);
71         assert(meshlink_start(mesh));
72
73         char *addr = meshlink_get_external_address(mesh);
74         assert_int_not_equal(addr, NULL);
75
76         free(addr);
77         meshlink_close(mesh);
78         meshlink_destroy("getex_conf");
79         return true;
80 }
81
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);
85 }
86
87 /* Test Steps for meshlink_get_external_address Test Case # 2
88
89     Test Steps:
90     1. Obtain external address by passing NULL as mesh handle
91         to meshlink_get_external_address API
92
93     Expected Result:
94     Return NULL by reporting error successfully.
95 */
96 static bool test_steps_mesh_get_address_02(void) {
97         char *ext = meshlink_get_external_address(NULL);
98         assert_int_equal(ext, NULL);
99
100         return true;
101 }
102
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);
106 }
107
108 /* Test Steps for meshlink_get_external_address Test Case # 3 - Functionality test
109
110     Test Steps:
111     1. Create an instance of the node
112     2. Get node's external address using meshlink_get_external_address
113
114     Expected Result:
115     API returns the external address successfully even if the mesh is started.
116 */
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));
121
122         char *addr = meshlink_get_external_address(mesh);
123         assert_int_not_equal(addr, NULL);
124
125         free(addr);
126         meshlink_close(mesh);
127         meshlink_destroy("getex_conf");
128         return true;
129 }
130
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)
139         };
140         total_tests += sizeof(blackbox_get_ex_addr_tests) / sizeof(blackbox_get_ex_addr_tests[0]);
141
142         return cmocka_run_group_tests(blackbox_get_ex_addr_tests, NULL, NULL);
143 }