2 test_cases_add_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_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_address_01(void **state);
33 static bool test_steps_mesh_add_address_01(void);
34 static void test_case_mesh_add_address_02(void **state);
35 static bool test_steps_mesh_add_address_02(void);
36 static void test_case_mesh_add_address_03(void **state);
37 static bool test_steps_mesh_add_address_03(void);
39 /* State structure for meshlink_add_address Test Case #1 */
40 static black_box_state_t test_mesh_add_address_01_state = {
41 .test_case_name = "test_case_mesh_add_address_01",
44 /* State structure for meshlink_add_address Test Case #2 */
45 static black_box_state_t test_mesh_add_address_02_state = {
46 .test_case_name = "test_case_mesh_add_address_02",
49 /* State structure for meshlink_add_address Test Case #3 */
50 static black_box_state_t test_mesh_add_address_03_state = {
51 .test_case_name = "test_case_mesh_add_address_03",
54 /* Execute meshlink_add_address Test Case # 1 */
55 static void test_case_mesh_add_address_01(void **state) {
56 execute_test(test_steps_mesh_add_address_01, state);
59 /* Test Steps for meshlink_add_address Test Case # 1
62 1. Create node instance
63 2. Add an address to the host node
64 2. Open host file from confbase & verify address being added
67 meshlink_add_address API adds the new address given to it's confbase
69 static bool test_steps_mesh_add_address_01(void) {
71 meshlink_destroy("add_conf.1");
73 // Create node instance
74 meshlink_handle_t *mesh = meshlink_open("add_conf.1", node, "chat", DEV_CLASS_STATIONARY);
77 char *hostname = "localhost";
78 bool ret = meshlink_add_address(mesh, hostname);
79 assert_int_equal(ret, true);
81 // Open the foo host file from confbase to verify address being added
83 FILE *fp = fopen("./add_conf.1/hosts/foo", "r");
87 while(fgets(line, 100, fp) != NULL) {
88 if(strcasestr(line, "Address") && strcasestr(line, hostname)) {
95 assert_int_equal(found, true);
99 meshlink_destroy("add_conf.1");
103 /* Execute meshlink_add_address Test Case # 2 */
104 static void test_case_mesh_add_address_02(void **state) {
105 execute_test(test_steps_mesh_add_address_02, state);
108 /* Test Steps for meshlink_add_address Test Case # 2
111 1. Create node instance
112 2. Call meshlink_add_address API using NULL as mesh handle argument
115 meshlink_add_address API returns false by reporting error successfully.
117 static bool test_steps_mesh_add_address_02(void) {
118 // Passing NULL as mesh handle argument to meshlink_add_address API
119 bool result = meshlink_add_address(NULL, "localhost");
120 assert_int_equal(result, false);
125 /* Execute meshlink_add_address Test Case # 3 */
126 static void test_case_mesh_add_address_03(void **state) {
127 execute_test(test_steps_mesh_add_address_03, state);
130 /* Test Steps for meshlink_add_address Test Case # 3
133 1. Create node instance
134 2. Call meshlink_add_address API using NULL as address argument
137 meshlink_add_address API returns false by reporting error successfully.
139 static bool test_steps_mesh_add_address_03(void) {
140 meshlink_destroy("add_conf.3");
142 // Create node instance
143 meshlink_handle_t *mesh = meshlink_open("add_conf.3", "foo", "chat", DEV_CLASS_STATIONARY);
144 assert(mesh != NULL);
146 bool result = meshlink_add_address(mesh, NULL);
147 assert_int_equal(result, false);
149 meshlink_close(mesh);
150 meshlink_destroy("add_conf.3");
154 int test_meshlink_add_address(void) {
155 const struct CMUnitTest blackbox_add_addr_tests[] = {
156 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_add_address_01, NULL, NULL,
157 (void *)&test_mesh_add_address_01_state),
158 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_add_address_02, NULL, NULL,
159 (void *)&test_mesh_add_address_02_state),
160 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_add_address_03, NULL, NULL,
161 (void *)&test_mesh_add_address_03_state)
164 total_tests += sizeof(blackbox_add_addr_tests) / sizeof(blackbox_add_addr_tests[0]);
166 return cmocka_run_group_tests(blackbox_add_addr_tests, NULL, NULL);