]> git.meshlink.io Git - meshlink/blob - test/blackbox/run_blackbox_tests/test_cases_pmtu.c
Fix __warn_unused_result__, add more of it and fix the resulting warnings.
[meshlink] / test / blackbox / run_blackbox_tests / test_cases_pmtu.c
1 /*
2     test_cases_pmtu.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_pmtu.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_pmtu_01(void **state);
37 static bool test_steps_mesh_pmtu_01(void);
38 static void test_case_mesh_pmtu_02(void **state);
39 static bool test_steps_mesh_pmtu_02(void);
40 static void test_case_mesh_pmtu_03(void **state);
41 static bool test_steps_mesh_pmtu_03(void);
42
43 /* State structure for meshlink_get_pmtu Test Case #1 */
44 static black_box_state_t test_mesh_pmtu_01_state = {
45         .test_case_name = "test_case_mesh_pmtu_01",
46 };
47
48 /* State structure for meshlink_get_pmtu Test Case #2 */
49 static black_box_state_t test_mesh_pmtu_02_state = {
50         .test_case_name = "test_case_mesh_pmtu_02",
51 };
52
53 /* State structure for meshlink_get_pmtu Test Case #3 */
54 static black_box_state_t test_mesh_pmtu_03_state = {
55         .test_case_name = "test_case_mesh_pmtu_03",
56 };
57
58 /* Execute meshlink_get_pmtu Test Case # 1 */
59 static void test_case_mesh_pmtu_01(void **state) {
60         execute_test(test_steps_mesh_pmtu_01, state);
61 }
62
63 /* Test Steps for meshlink_get_pmtu Test Case # 1
64
65     Test Steps:
66     1. Create node instance & get self handle
67     2. Obtain MTU size
68
69     Expected Result:
70     meshlink_get_pmtu should return valid MTU size of a node
71 */
72 static bool test_steps_mesh_pmtu_01(void) {
73         meshlink_handle_t *mesh = meshlink_open("pmtu_conf", "foo", "test", DEV_CLASS_STATIONARY);
74         assert(mesh != NULL);
75
76         assert(meshlink_start(mesh));
77         meshlink_node_t *dest_node = meshlink_get_self(mesh);
78         assert(dest_node != NULL);
79
80         ssize_t pmtu = meshlink_get_pmtu(mesh, dest_node);
81         assert_int_not_equal(pmtu, -1);
82
83         meshlink_close(mesh);
84         assert(meshlink_destroy("pmtu_conf"));
85         return true;
86 }
87
88 /* Execute meshlink_get_pmtu Test Case # 2
89
90     Test Steps:
91     1. Create node instance & get self handle
92     2. Try to obtain MTU size by passing NULL as mesh handle to API
93
94     Expected Result:
95     meshlink_get_pmtu should return -1 reporting the error
96 */
97 static void test_case_mesh_pmtu_02(void **state) {
98         execute_test(test_steps_mesh_pmtu_02, state);
99 }
100
101 /* Test Steps for meshlink_get_pmtu Test Case # 2*/
102 static bool test_steps_mesh_pmtu_02(void) {
103         meshlink_handle_t *mesh = meshlink_open("pmtu_conf", "foo", "test", DEV_CLASS_STATIONARY);
104         assert(mesh != NULL);
105
106         assert(meshlink_start(mesh));
107         meshlink_node_t *dest_node = meshlink_get_self(mesh);
108         assert(dest_node != NULL);
109
110         ssize_t pmtu = meshlink_get_pmtu(NULL, dest_node);
111         assert_int_equal(pmtu, -1);
112
113         meshlink_close(mesh);
114         assert(meshlink_destroy("pmtu_conf"));
115         return true;
116 }
117
118 /* Execute meshlink_get_pmtu Test Case # 3 */
119 static void test_case_mesh_pmtu_03(void **state) {
120         execute_test(test_steps_mesh_pmtu_03, state);
121 }
122
123 /* Test Steps for meshlink_get_pmtu Test Case # 3
124
125     Test Steps:
126     1. Create node instance & get self handle
127     2. Try to obtain MTU size by passing NULL as node handle to API
128
129     Expected Result:
130     meshlink_get_pmtu should return -1 reporting the error
131 */
132 static bool test_steps_mesh_pmtu_03(void) {
133         meshlink_handle_t *mesh = meshlink_open("pmtu_conf", "foo", "test", DEV_CLASS_STATIONARY);
134         assert(mesh != NULL);
135
136         assert(meshlink_start(mesh));
137
138         ssize_t pmtu = meshlink_get_pmtu(mesh, NULL);
139         assert_int_equal(pmtu, -1);
140
141         meshlink_close(mesh);
142         assert(meshlink_destroy("pmtu_conf"));
143         return true;
144 }
145
146 int test_meshlink_pmtu(void) {
147         const struct CMUnitTest blackbox_pmtu_tests[] = {
148                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_pmtu_01, NULL, NULL,
149                                 (void *)&test_mesh_pmtu_01_state),
150                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_pmtu_02, NULL, NULL,
151                                 (void *)&test_mesh_pmtu_02_state),
152                 cmocka_unit_test_prestate_setup_teardown(test_case_mesh_pmtu_03, NULL, NULL,
153                                 (void *)&test_mesh_pmtu_03_state)
154         };
155
156         total_tests += sizeof(blackbox_pmtu_tests) / sizeof(blackbox_pmtu_tests[0]);
157
158         return cmocka_run_group_tests(blackbox_pmtu_tests, NULL, NULL);
159 }