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