2 test_cases_destroy.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_destroy.h"
21 #include "../common/containers.h"
22 #include "../common/test_step.h"
23 #include "../common/common_handlers.h"
30 #include <sys/types.h>
34 /* Modify this to change the logging level of Meshlink */
35 #define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG
37 static void test_case_meshlink_destroy_01(void **state);
38 static bool test_meshlink_destroy_01(void);
39 static void test_case_meshlink_destroy_02(void **state);
40 static bool test_meshlink_destroy_02(void);
41 static void test_case_meshlink_destroy_03(void **state);
42 static bool test_meshlink_destroy_03(void);
44 static black_box_state_t test_case_meshlink_destroy_01_state = {
45 .test_case_name = "test_case_meshlink_destroy_01",
47 static black_box_state_t test_case_meshlink_destroy_02_state = {
48 .test_case_name = "test_case_meshlink_destroy_02",
50 static black_box_state_t test_case_meshlink_destroy_03_state = {
51 .test_case_name = "test_case_meshlink_destroy_03",
55 /* Execute destroy Test Case # 1 - valid case*/
56 static void test_case_meshlink_destroy_01(void **state) {
57 execute_test(test_meshlink_destroy_01, state);
60 /* Test Steps for destroy Test Case # 1 - Valid case
62 1. Open instance for NUT
63 2. Close NUT, and destroy the confbase
64 3. Open the same confbase directory
67 confbase should be deleted
69 static bool test_meshlink_destroy_01(void) {
70 meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
72 // Create meshlink instance
73 char *confbase = "destroyconf";
74 mesh_handle = meshlink_open(confbase, "nut", "node_sim", 1);
77 meshlink_close(mesh_handle);
79 // Destroying NUT's confbase
80 bool result = meshlink_destroy(confbase);
81 assert_int_equal(result, true);
83 // Verify whether confbase is removed or not
84 DIR *dir = opendir(confbase);
85 assert_int_equal(dir, NULL);
90 /* Execute destroy Test Case # 2 - passing NULL argument to the API */
91 static void test_case_meshlink_destroy_02(void **state) {
92 execute_test(test_meshlink_destroy_02, state);
95 /* Test Steps for destroy Test Case # 2 - Invalid case
97 1. Just passing NULL as argument to the API
100 Return false reporting failure
102 static bool test_meshlink_destroy_02(void) {
103 // Passing NULL as an argument to meshlink_destroy
104 bool result = meshlink_destroy(NULL);
105 assert_int_equal(result, false);
110 /* Execute status Test Case # 3 - destroying non existing file */
111 static void test_case_meshlink_destroy_03(void **state) {
112 execute_test(test_meshlink_destroy_03, state);
114 /* Test Steps for destroy Test Case # 3 - Invalid case
116 1. unlink if there's any such test file
117 2. Call API with that file name
120 Return false reporting failure
122 static bool test_meshlink_destroy_03(void) {
125 // Deletes if there is any file named 'non_existing' already
126 unlink("non_existing");
128 // Passing non-existing file as an argument to meshlink_destroy
129 result = meshlink_destroy("non_existing");
130 assert_int_equal(result, false);
136 int test_meshlink_destroy(void) {
137 const struct CMUnitTest blackbox_destroy_tests[] = {
138 cmocka_unit_test_prestate_setup_teardown(test_case_meshlink_destroy_01, NULL, NULL,
139 (void *)&test_case_meshlink_destroy_01_state),
140 cmocka_unit_test_prestate_setup_teardown(test_case_meshlink_destroy_02, NULL, NULL,
141 (void *)&test_case_meshlink_destroy_02_state),
142 cmocka_unit_test_prestate_setup_teardown(test_case_meshlink_destroy_03, NULL, NULL,
143 (void *)&test_case_meshlink_destroy_03_state)
146 total_tests += sizeof(blackbox_destroy_tests) / sizeof(blackbox_destroy_tests[0]);
148 return cmocka_run_group_tests(blackbox_destroy_tests, NULL, NULL);