2 test_cases_add_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_add_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_add_ex_address_01(void **state);
33 static bool test_steps_mesh_add_ex_address_01(void);
34 static void test_case_mesh_add_ex_address_02(void **state);
35 static bool test_steps_mesh_add_ex_address_02(void);
37 /* State structure for meshlink_add_external_address Test Case #1 */
38 static black_box_state_t test_mesh_add_ex_address_01_state = {
39 .test_case_name = "test_case_mesh_add_ex_address_01",
42 /* State structure for meshlink_add_external_address Test Case #2 */
43 static black_box_state_t test_mesh_add_ex_address_02_state = {
44 .test_case_name = "test_case_mesh_add_ex_address_01",
47 /* Execute meshlink_add_external_address Test Case # 1 */
48 void test_case_mesh_add_ex_address_01(void **state) {
49 execute_test(test_steps_mesh_add_ex_address_01, state);
52 /* Test Steps for meshlink_add_external_address Test Case # 1
55 1. Create node instance
56 2. Get mesh's external address
57 3. Add external address using meshlink_add_external_address API
58 4. Open nodes confbase and read the external address from the list if addresses
61 meshlink_add_external_address API adds the new address given to it's confbase
63 bool test_steps_mesh_add_ex_address_01(void) {
64 meshlink_destroy("addex_conf.1");
66 // Create node instance
67 meshlink_handle_t *mesh = meshlink_open("addex_conf.1", "foo", "test", DEV_CLASS_STATIONARY);
70 char *external_address = meshlink_get_external_address(mesh);
71 assert(external_address);
73 bool ret = meshlink_add_external_address(mesh);
74 assert_int_equal(ret, true);
76 // Open the foo host file from confbase to verify address being added
78 FILE *fp = fopen("./addex_conf.1/hosts/foo", "r");
82 while(fgets(line, 100, fp) != NULL) {
83 if(strcasestr(line, "Address") && strcasestr(line, external_address)) {
90 assert_int_equal(found, true);
93 meshlink_destroy("addex_conf.1");
97 /* Execute meshlink_add_external_address Test Case # 2 */
98 void test_case_mesh_add_ex_address_02(void **state) {
99 execute_test(test_steps_mesh_add_ex_address_02, state);
102 /* Test Steps for meshlink_add_external_address Test Case # 2
105 1. Create node instance
106 2. Call meshlink_add_external_address API using NULL as mesh handle argument
109 meshlink_add_external_address API returns false by reporting error successfully.
111 bool test_steps_mesh_add_ex_address_02(void) {
112 bool result = meshlink_add_external_address(NULL);
113 assert_int_equal(result, false);
118 int test_meshlink_add_external_address(void) {
119 const struct CMUnitTest blackbox_add_ex_addr_tests[] = {
120 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_add_ex_address_01, NULL, NULL,
121 (void *)&test_mesh_add_ex_address_01_state),
122 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_add_ex_address_02, NULL, NULL,
123 (void *)&test_mesh_add_ex_address_02_state)
126 total_tests += sizeof(blackbox_add_ex_addr_tests) / sizeof(blackbox_add_ex_addr_tests[0]);
128 return cmocka_run_group_tests(blackbox_add_ex_addr_tests, NULL, NULL);