Debian Codegraph @

madrisan-nagios-plugins-linux/nagios-plugins-linux/tests/tslibfiles_size.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 int64_t size;
32 off_t filesize;
33 bool expect_value;
34 } test_data;
35
36 static int
37 test_files_check_size (const void *tdata)
38 {
39 const struct test_data *data = tdata;
40 int ret = 0;
41
42 bool check = files_check_size (data->size, data->filesize);
43 TEST_ASSERT_EQUAL_NUMERIC (check, data->expect_value);
44 return ret;
45 }
46
47 static int
48 mymain (void)
49 {
50 int ret = 0;
51
52 # define DO_TEST(SIZE, FILESIZE, EXPECT_VALUE) \
53 do \
54 { \
55 test_data data = { \
56 .size = SIZE, \
57 .filesize = FILESIZE, \
58 .expect_value = EXPECT_VALUE, \
59 }; \
60 if (test_run("check function files_check_size", \
61 test_files_check_size, (&data)) < 0) \
62 ret = -1; \
63 } \
64 while (0)
65
66 /* test the function files_check_size() */
67
68 int64_t size = 1024; /* 1024 bytes */
69
70 DO_TEST (0, 2048, true);
71 DO_TEST (+size, size + 1, true);
72 DO_TEST (+size, size - 1, false);
73 DO_TEST (-size, size + 1, false);
74 DO_TEST (-size, size - 1, true);
75
76 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
77 }
78
79 TEST_MAIN (mymain)