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.
24 #include "execute_tests.h"
25 #include "test_cases_add_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_add_ex_address_01(void **state);
37 static bool test_steps_mesh_add_ex_address_01(void);
38 static void test_case_mesh_add_ex_address_02(void **state);
39 static bool test_steps_mesh_add_ex_address_02(void);
41 /* State structure for meshlink_add_external_address Test Case #1 */
42 static black_box_state_t test_mesh_add_ex_address_01_state = {
43 .test_case_name = "test_case_mesh_add_ex_address_01",
46 /* State structure for meshlink_add_external_address Test Case #2 */
47 static black_box_state_t test_mesh_add_ex_address_02_state = {
48 .test_case_name = "test_case_mesh_add_ex_address_01",
51 /* Execute meshlink_add_external_address Test Case # 1 */
52 void test_case_mesh_add_ex_address_01(void **state) {
53 execute_test(test_steps_mesh_add_ex_address_01, state);
56 /* Test Steps for meshlink_add_external_address Test Case # 1
59 1. Create node instance
60 2. Get mesh's external address
61 3. Add external address using meshlink_add_external_address API
62 4. Open nodes confbase and read the external address from the list if addresses
65 meshlink_add_external_address API adds the new address given to it's confbase
67 bool test_steps_mesh_add_ex_address_01(void) {
68 meshlink_destroy("addex_conf.1");
70 // Create node instance
71 meshlink_handle_t *mesh = meshlink_open("addex_conf.1", "foo", "test", DEV_CLASS_STATIONARY);
74 char *external_address = meshlink_get_external_address(mesh);
75 assert(external_address);
77 bool ret = meshlink_add_external_address(mesh);
78 assert_int_equal(ret, true);
80 // Open the foo host file from confbase to verify address being added
82 FILE *fp = fopen("./addex_conf.1/hosts/foo", "r");
86 while(fgets(line, 100, fp) != NULL) {
87 if(strcasestr(line, "Address") && strcasestr(line, external_address)) {
94 assert_int_equal(found, true);
97 meshlink_destroy("addex_conf.1");
101 /* Execute meshlink_add_external_address Test Case # 2 */
102 void test_case_mesh_add_ex_address_02(void **state) {
103 execute_test(test_steps_mesh_add_ex_address_02, state);
106 /* Test Steps for meshlink_add_external_address Test Case # 2
109 1. Create node instance
110 2. Call meshlink_add_external_address API using NULL as mesh handle argument
113 meshlink_add_external_address API returns false by reporting error successfully.
115 bool test_steps_mesh_add_ex_address_02(void) {
116 bool result = meshlink_add_external_address(NULL);
117 assert_int_equal(result, false);
122 int test_meshlink_add_external_address(void) {
123 const struct CMUnitTest blackbox_add_ex_addr_tests[] = {
124 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_add_ex_address_01, NULL, NULL,
125 (void *)&test_mesh_add_ex_address_01_state),
126 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_add_ex_address_02, NULL, NULL,
127 (void *)&test_mesh_add_ex_address_02_state)
130 total_tests += sizeof(blackbox_add_ex_addr_tests) / sizeof(blackbox_add_ex_addr_tests[0]);
132 return cmocka_run_group_tests(blackbox_add_ex_addr_tests, NULL, NULL);