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.
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"
32 /* Modify this to change the logging level of Meshlink */
33 #define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG
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);
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",
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",
50 /* Execute export Test Case # 1 - valid case*/
51 static void test_case_export_01(void **state) {
52 execute_test(test_export_01, state);
54 /* Test Steps for export Test Case # 1 - Valid case
60 API returns a NULL terminated string containing meta data of NUT.
62 static bool test_export_01(void) {
63 meshlink_destroy("exportconf");
64 meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
66 /* Create meshlink instance */
67 meshlink_handle_t *mesh_handle = meshlink_open("exportconf", "nut", "node_sim", 1);
69 meshlink_set_log_cb(mesh_handle, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
71 char *expo = meshlink_export(mesh_handle);
72 assert_int_not_equal(expo, NULL);
74 meshlink_close(mesh_handle);
75 meshlink_destroy("exportconf");
80 /* Execute export Test Case # 2 - Invalid case*/
81 static void test_case_export_02(void **state) {
82 execute_test(test_export_02, state);
84 /* Test Steps for export Test Case # 2 - Invalid case
87 2. calling meshlink_export by passing NULL as mesh handle
90 API returns NULL reporting error when NULL being passed as mesh handle.
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);
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)
109 total_tests += sizeof(blackbox_export_tests) / sizeof(blackbox_export_tests[0]);
111 return cmocka_run_group_tests(blackbox_export_tests, NULL, NULL);