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.
24 #include "execute_tests.h"
25 #include "test_cases_add_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_address_01(void **state);
37 static bool test_steps_mesh_add_address_01(void);
38 static void test_case_mesh_add_address_02(void **state);
39 static bool test_steps_mesh_add_address_02(void);
40 static void test_case_mesh_add_address_03(void **state);
41 static bool test_steps_mesh_add_address_03(void);
43 /* State structure for meshlink_add_address Test Case #1 */
44 static black_box_state_t test_mesh_add_address_01_state = {
45 .test_case_name = "test_case_mesh_add_address_01",
48 /* State structure for meshlink_add_address Test Case #2 */
49 static black_box_state_t test_mesh_add_address_02_state = {
50 .test_case_name = "test_case_mesh_add_address_02",
53 /* State structure for meshlink_add_address Test Case #3 */
54 static black_box_state_t test_mesh_add_address_03_state = {
55 .test_case_name = "test_case_mesh_add_address_03",
58 /* Execute meshlink_add_address Test Case # 1 */
59 static void test_case_mesh_add_address_01(void **state) {
60 execute_test(test_steps_mesh_add_address_01, state);
63 /* Test Steps for meshlink_add_address Test Case # 1
66 1. Create node instance
67 2. Add an address to the host node
68 2. Open host file from confbase & verify address being added
71 meshlink_add_address API adds the new address given to it's confbase
73 static bool test_steps_mesh_add_address_01(void) {
75 assert(meshlink_destroy("add_conf.1"));
77 // Create node instance
78 meshlink_handle_t *mesh = meshlink_open("add_conf.1", node, "chat", DEV_CLASS_STATIONARY);
81 char *hostname = "localhost";
82 bool ret = meshlink_add_address(mesh, hostname);
83 assert_int_equal(ret, true);
85 // Open the foo host file from confbase to verify address being added
87 FILE *fp = fopen("./add_conf.1/hosts/foo", "r");
91 while(fgets(line, 100, fp) != NULL) {
92 if(strcasestr(line, "Address") && strcasestr(line, hostname)) {
99 assert_int_equal(found, true);
102 meshlink_close(mesh);
103 assert(meshlink_destroy("add_conf.1"));
107 /* Execute meshlink_add_address Test Case # 2 */
108 static void test_case_mesh_add_address_02(void **state) {
109 execute_test(test_steps_mesh_add_address_02, state);
112 /* Test Steps for meshlink_add_address Test Case # 2
115 1. Create node instance
116 2. Call meshlink_add_address API using NULL as mesh handle argument
119 meshlink_add_address API returns false by reporting error successfully.
121 static bool test_steps_mesh_add_address_02(void) {
122 // Passing NULL as mesh handle argument to meshlink_add_address API
123 bool result = meshlink_add_address(NULL, "localhost");
124 assert_int_equal(result, false);
129 /* Execute meshlink_add_address Test Case # 3 */
130 static void test_case_mesh_add_address_03(void **state) {
131 execute_test(test_steps_mesh_add_address_03, state);
134 /* Test Steps for meshlink_add_address Test Case # 3
137 1. Create node instance
138 2. Call meshlink_add_address API using NULL as address argument
141 meshlink_add_address API returns false by reporting error successfully.
143 static bool test_steps_mesh_add_address_03(void) {
144 assert(meshlink_destroy("add_conf.3"));
146 // Create node instance
147 meshlink_handle_t *mesh = meshlink_open("add_conf.3", "foo", "chat", DEV_CLASS_STATIONARY);
148 assert(mesh != NULL);
150 bool result = meshlink_add_address(mesh, NULL);
151 assert_int_equal(result, false);
153 meshlink_close(mesh);
154 assert(meshlink_destroy("add_conf.3"));
158 int test_meshlink_add_address(void) {
159 const struct CMUnitTest blackbox_add_addr_tests[] = {
160 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_add_address_01, NULL, NULL,
161 (void *)&test_mesh_add_address_01_state),
162 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_add_address_02, NULL, NULL,
163 (void *)&test_mesh_add_address_02_state),
164 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_add_address_03, NULL, NULL,
165 (void *)&test_mesh_add_address_03_state)
168 total_tests += sizeof(blackbox_add_addr_tests) / sizeof(blackbox_add_addr_tests[0]);
170 return cmocka_run_group_tests(blackbox_add_addr_tests, NULL, NULL);