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