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.
24 #include "execute_tests.h"
25 #include "test_cases_destroy.h"
26 #include "../common/containers.h"
27 #include "../common/test_step.h"
28 #include "../common/common_handlers.h"
35 #include <sys/types.h>
39 /* Modify this to change the logging level of Meshlink */
40 #define TEST_MESHLINK_LOG_LEVEL MESHLINK_DEBUG
42 static void test_case_meshlink_destroy_01(void **state);
43 static bool test_meshlink_destroy_01(void);
44 static void test_case_meshlink_destroy_02(void **state);
45 static bool test_meshlink_destroy_02(void);
46 static void test_case_meshlink_destroy_03(void **state);
47 static bool test_meshlink_destroy_03(void);
49 static black_box_state_t test_case_meshlink_destroy_01_state = {
50 .test_case_name = "test_case_meshlink_destroy_01",
52 static black_box_state_t test_case_meshlink_destroy_02_state = {
53 .test_case_name = "test_case_meshlink_destroy_02",
55 static black_box_state_t test_case_meshlink_destroy_03_state = {
56 .test_case_name = "test_case_meshlink_destroy_03",
60 /* Execute destroy Test Case # 1 - valid case*/
61 static void test_case_meshlink_destroy_01(void **state) {
62 execute_test(test_meshlink_destroy_01, state);
65 /* Test Steps for destroy Test Case # 1 - Valid case
67 1. Open instance for NUT
68 2. Close NUT, and destroy the confbase
69 3. Open the same confbase directory
72 confbase should be deleted
74 static bool test_meshlink_destroy_01(void) {
75 meshlink_set_log_cb(NULL, TEST_MESHLINK_LOG_LEVEL, meshlink_callback_logger);
77 // Create meshlink instance
78 char *confbase = "destroyconf";
79 mesh_handle = meshlink_open(confbase, "nut", "node_sim", 1);
82 meshlink_close(mesh_handle);
84 // Destroying NUT's confbase
85 bool result = meshlink_destroy(confbase);
86 assert_int_equal(result, true);
88 // Verify whether confbase is removed or not
89 DIR *dir = opendir(confbase);
90 assert_int_equal(dir, NULL);
95 /* Execute destroy Test Case # 2 - passing NULL argument to the API */
96 static void test_case_meshlink_destroy_02(void **state) {
97 execute_test(test_meshlink_destroy_02, state);
100 /* Test Steps for destroy Test Case # 2 - Invalid case
102 1. Just passing NULL as argument to the API
105 Return false reporting failure
107 static bool test_meshlink_destroy_02(void) {
108 // Passing NULL as an argument to meshlink_destroy
109 bool result = meshlink_destroy(NULL);
110 assert_int_equal(result, false);
115 /* Execute status Test Case # 3 - destroying non existing file */
116 static void test_case_meshlink_destroy_03(void **state) {
117 execute_test(test_meshlink_destroy_03, state);
119 /* Test Steps for destroy Test Case # 3 - Invalid case
121 1. unlink if there's any such test file
122 2. Call API with that file name
125 Return false reporting failure
127 static bool test_meshlink_destroy_03(void) {
130 // Deletes if there is any file named 'non_existing' already
131 unlink("non_existing");
133 // Passing non-existing file as an argument to meshlink_destroy
134 result = meshlink_destroy("non_existing");
135 assert_int_equal(result, false);
141 int test_meshlink_destroy(void) {
142 const struct CMUnitTest blackbox_destroy_tests[] = {
143 cmocka_unit_test_prestate_setup_teardown(test_case_meshlink_destroy_01, NULL, NULL,
144 (void *)&test_case_meshlink_destroy_01_state),
145 cmocka_unit_test_prestate_setup_teardown(test_case_meshlink_destroy_02, NULL, NULL,
146 (void *)&test_case_meshlink_destroy_02_state),
147 cmocka_unit_test_prestate_setup_teardown(test_case_meshlink_destroy_03, NULL, NULL,
148 (void *)&test_case_meshlink_destroy_03_state)
151 total_tests += sizeof(blackbox_destroy_tests) / sizeof(blackbox_destroy_tests[0]);
153 return cmocka_run_group_tests(blackbox_destroy_tests, NULL, NULL);