]> git.meshlink.io Git - meshlink/blob - test/blackbox/run_blackbox_tests/test_cases_export.c
Fix __warn_unused_result__, add more of it and fix the resulting warnings.
[meshlink] / test / blackbox / run_blackbox_tests / test_cases_export.c
1 /*
2     test_cases_export.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_export.h"
26 #include "../common/containers.h"
27 #include "../common/test_step.h"
28 #include "../common/common_handlers.h"
29 #include <assert.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include <stdarg.h>
33 #include <setjmp.h>
34 #include <cmocka.h>
35
36
37 /* Modify this to change the logging level of Meshlink */
38 #define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG
39
40 static void test_case_export_01(void **state);
41 static bool test_export_01(void);
42 static void test_case_export_02(void **state);
43 static bool test_export_02(void);
44
45 /* State structure for export API Test Case #1 */
46 static black_box_state_t test_case_export_01_state = {
47         .test_case_name = "test_case_export_01",
48 };
49 /* State structure for export API Test Case #2 */
50 static black_box_state_t test_case_export_02_state = {
51         .test_case_name = "test_case_export_02",
52 };
53
54
55 /* Execute export Test Case # 1 - valid case*/
56 static void test_case_export_01(void **state) {
57         execute_test(test_export_01, state);
58 }
59 /* Test Steps for export Test Case # 1 - Valid case
60     Test Steps:
61     1. Run NUT
62     2. Export mesh
63
64     Expected Result:
65     API returns a NULL terminated string containing meta data of NUT.
66 */
67 static bool test_export_01(void) {
68         assert(meshlink_destroy("exportconf"));
69         meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
70
71         /* Create meshlink instance */
72         meshlink_handle_t *mesh_handle = meshlink_open("exportconf", "nut", "node_sim", 1);
73         assert(mesh_handle);
74         meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
75
76         char *expo = meshlink_export(mesh_handle);
77         assert_int_not_equal(expo, NULL);
78
79         meshlink_close(mesh_handle);
80         assert(meshlink_destroy("exportconf"));
81
82         return true;
83 }
84
85 /* Execute export Test Case # 2 - Invalid case*/
86 static void test_case_export_02(void **state) {
87         execute_test(test_export_02, state);
88 }
89 /* Test Steps for export Test Case # 2 - Invalid case
90     Test Steps:
91     1. Run NUT
92     2. calling meshlink_export by passing NULL as mesh handle
93
94     Expected Result:
95     API returns NULL reporting error when NULL being passed as mesh handle.
96 */
97 static bool test_export_02(void) {
98         // Calling export API with NULL as mesh handle
99         char *expo = meshlink_export(NULL);
100         assert_int_equal(expo, NULL);
101
102         return true;
103 }
104
105
106 int test_meshlink_export(void) {
107         const struct CMUnitTest blackbox_export_tests[] = {
108                 cmocka_unit_test_prestate_setup_teardown(test_case_export_01, NULL, NULL,
109                                 (void *)&test_case_export_01_state),
110                 cmocka_unit_test_prestate_setup_teardown(test_case_export_02, NULL, NULL,
111                                 (void *)&test_case_export_02_state)
112         };
113
114         total_tests += sizeof(blackbox_export_tests) / sizeof(blackbox_export_tests[0]);
115
116         return cmocka_run_group_tests(blackbox_export_tests, NULL, NULL);
117 }
118