]> git.meshlink.io Git - meshlink/blob - test/blackbox/run_blackbox_tests/test_cases_start.c
Fix __warn_unused_result__, add more of it and fix the resulting warnings.
[meshlink] / test / blackbox / run_blackbox_tests / test_cases_start.c
1 /*
2     test_cases_start.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 #ifdef NDEBUG
21 #undef NDEBUG
22 #endif
23
24 #include "execute_tests.h"
25 #include "test_cases_start.h"
26 #include "../common/containers.h"
27 #include "../common/test_step.h"
28 #include "../common/common_handlers.h"
29 #include <stdlib.h>
30 #include <stdarg.h>
31 #include <setjmp.h>
32 #include <cmocka.h>
33 #include <assert.h>
34 #include <string.h>
35
36 static void test_case_mesh_start_01(void **state);
37 static bool test_steps_mesh_start_01(void);
38 static void test_case_mesh_start_02(void **state);
39 static bool test_steps_mesh_start_02(void);
40
41 /* State structure for meshlink_start Test Case #1 */
42 static black_box_state_t test_mesh_start_01_state = {
43         .test_case_name = "test_case_mesh_start_01",
44 };
45
46 /* State structure for meshlink_start Test Case #2 */
47 static black_box_state_t test_mesh_start_02_state = {
48         .test_case_name = "test_case_mesh_start_02",
49 };
50
51 /* Execute meshlink_start Test Case # 1*/
52 static void test_case_mesh_start_01(void **state) {
53         execute_test(test_steps_mesh_start_01, state);
54 }
55
56 /* Test Steps for meshlink_start Test Case # 1
57
58     Test Steps:
59     1. Open Instance & start node
60
61     Expected Result:
62     Successfully node instance should be running
63 */
64 static bool test_steps_mesh_start_01(void) {
65
66         // Open instance
67
68         bool result = false;
69         meshlink_handle_t *mesh = meshlink_open("start_conf", "foo", "test", DEV_CLASS_STATIONARY);
70         assert(mesh);
71
72         // Run node instance
73
74         result = meshlink_start(mesh);
75
76         // Clean up
77         meshlink_close(mesh);
78         assert(meshlink_destroy("start_conf"));
79
80         if(!result) {
81                 fprintf(stderr, "meshlink_start status1: %s\n", meshlink_strerror(meshlink_errno));
82                 return false;
83         } else {
84                 return true;
85         }
86 }
87
88 /* Execute meshlink_start Test Case # 2*/
89 static void test_case_mesh_start_02(void **state) {
90         execute_test(test_steps_mesh_start_02, state);
91 }
92
93 /* Test Steps for meshlink_start Test Case # 2
94
95     Test Steps:
96     1. Calling meshlink_start with NULL as mesh handle argument.
97
98     Expected Result:
99     meshlink_start API handles the invalid parameter by returning false.
100 */
101 static bool test_steps_mesh_start_02(void) {
102         bool result = false;
103         assert(meshlink_destroy("start_conf"));
104         meshlink_handle_t *mesh = meshlink_open("start_conf", "foo", "test", DEV_CLASS_STATIONARY);
105         assert(mesh);
106
107         // Run instance with NULL argument
108
109         result = meshlink_start(NULL);
110         assert_int_equal(result, true);
111
112         // Clean up
113
114         meshlink_close(mesh);
115         assert(meshlink_destroy("start_conf"));
116         return true;
117 }
118
119 int test_meshlink_start(void) {
120         const struct CMUnitTest blackbox_start_tests[] = {
121                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_start_01, NULL, NULL,
122                                 (void *)&test_mesh_start_01_state),
123                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_start_02, NULL, NULL,
124                                 (void *)&test_mesh_start_02_state)
125
126         };
127
128         total_tests += sizeof(blackbox_start_tests) / sizeof(blackbox_start_tests[0]);
129
130         return cmocka_run_group_tests(blackbox_start_tests, NULL, NULL);
131 }