Debian Codegraph @

madrisan-nagios-plugins-linux/nagios-plugins-linux/tests/tslibfiles_hiddenfile.c

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 /*
3 * License: GPLv3+
4 * Copyright (c) 2022 Davide Madrisan <[email protected]>
5 *
6 * Unit test for lib/files.c
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23 #include "testutils.h"
24
25 # define NPL_TESTING
26 # include "../lib/files.c"
27 # undef NPL_TESTING
28
29 typedef struct test_data
30 {
31 char *value;
32 bool expect_value;
33 } test_data;
34
35 static int
36 test_files_is_hidden (const void *tdata)
37 {
38 const struct test_data *data = tdata;
39 int ret = 0;
40
41 bool check = files_is_hidden (data->value);
42 TEST_ASSERT_EQUAL_NUMERIC (check, data->expect_value);
43 return ret;
44 }
45
46 static int
47 mymain (void)
48 {
49 int ret = 0;
50
51 # define DO_TEST(VALUE, EXPECT_VALUE) \
52 do \
53 { \
54 test_data data = { \
55 .value = VALUE, \
56 .expect_value = EXPECT_VALUE, \
57 }; \
58 if (test_run("check function files_is_hidden against " VALUE, \
59 test_files_is_hidden, (&data)) < 0) \
60 ret = -1; \
61 } \
62 while (0)
63
64 /* test the function files_is_hidden() */
65
66 DO_TEST (".hiddenfile", true);
67 DO_TEST ("anotherfile", false);
68
69 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
70 }
71
72 TEST_MAIN (mymain)