Debian Codegraph @

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

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 /*
3 * License: GPLv3+
4 * Copyright (c) 2017 Davide Madrisan <[email protected]>
5 *
6 * Unit test for testutils.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 <stdlib.h>
24 #include "testutils.h"
25
26 typedef struct test_data
27 {
28 char * filename;
29 size_t expect_size;
30 } test_data;
31
32 static int
33 test_fstringify_bufsize (const void *tdata)
34 {
35 int ret = 0;
36 const struct test_data *data = tdata;
37
38 char * buffer = test_fstringify (data->filename);
39 if (NULL == buffer)
40 return -1;
41
42 TEST_ASSERT_EQUAL_NUMERIC (data->expect_size, strlen (buffer));
43
44 free (buffer);
45 return ret;
46 }
47
48 static int
49 mymain (void)
50 {
51 int ret = 0;
52 char *filename = NPL_TEST_PATH_CONTAINER_JSON;
53
54 #define DO_TEST(MSG, FILENAME, EXPECT_SIZE) \
55 do \
56 { \
57 test_data data = { \
58 .filename = FILENAME, \
59 .expect_size = EXPECT_SIZE, \
60 }; \
61 if (test_run(MSG, test_fstringify_bufsize, &data) < 0) \
62 ret = -1; \
63 } \
64 while (0)
65
66 DO_TEST ("checking test_fstringify ()", filename, 3832);
67
68 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
69 }
70
71 TEST_MAIN (mymain)