2 test_cases_export.c -- Execution of specific meshlink black box test cases
3 Copyright (C) 2018 Guus Sliepen <guus@meshlink.io>
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.
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.
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.
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"
37 /* Modify this to change the logging level of Meshlink */
38 #define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG
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);
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",
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",
55 /* Execute export Test Case # 1 - valid case*/
56 static void test_case_export_01(void **state) {
57 execute_test(test_export_01, state);
59 /* Test Steps for export Test Case # 1 - Valid case
65 API returns a NULL terminated string containing meta data of NUT.
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);
71 /* Create meshlink instance */
72 meshlink_handle_t *mesh_handle = meshlink_open("exportconf", "nut", "node_sim", 1);
74 meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
76 char *expo = meshlink_export(mesh_handle);
77 assert_int_not_equal(expo, NULL);
79 meshlink_close(mesh_handle);
80 assert(meshlink_destroy("exportconf"));
85 /* Execute export Test Case # 2 - Invalid case*/
86 static void test_case_export_02(void **state) {
87 execute_test(test_export_02, state);
89 /* Test Steps for export Test Case # 2 - Invalid case
92 2. calling meshlink_export by passing NULL as mesh handle
95 API returns NULL reporting error when NULL being passed as mesh handle.
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);
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)
114 total_tests += sizeof(blackbox_export_tests) / sizeof(blackbox_export_tests[0]);
116 return cmocka_run_group_tests(blackbox_export_tests, NULL, NULL);