Debian Codegraph @

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

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 /*
3 * License: GPLv3+
4 * Copyright (c) 2016 Davide Madrisan <[email protected]>
5 *
6 * Unit test for lib/messages.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 "messages.h"
24 #include "testutils.h"
25
26 typedef struct test_data
27 {
28 char *state;
29 nagstatus value;
30 nagstatus expect_value;
31 } test_data;
32
33 static int
34 test_nagios_state_string (const void *tdata)
35 {
36 const struct test_data *data = tdata;
37 int ret = 0;
38
39 TEST_ASSERT_EQUAL_STRING (state_text (data->value), data->state);
40 TEST_ASSERT_EQUAL_NUMERIC (data->value, data->expect_value);
41 return ret;
42 }
43
44 static int
45 mymain (void)
46 {
47 int ret = 0;
48
49 #define STR(S) #S
50 #define DO_TEST(TYPE, EXPECT_VALUE) \
51 do \
52 { \
53 test_data data = { \
54 .state = STR(TYPE), \
55 .value = STATE_##TYPE, \
56 .expect_value = EXPECT_VALUE, \
57 }; \
58 if (test_run("check nagios state " STR(TYPE), \
59 test_nagios_state_string, (&data)) < 0) \
60 ret = -1; \
61 } \
62 while (0)
63
64 DO_TEST (OK, 0);
65 DO_TEST (WARNING, 1);
66 DO_TEST (CRITICAL, 2);
67 DO_TEST (UNKNOWN, 3);
68 DO_TEST (DEPENDENT, 4);
69
70 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
71 }
72
73 TEST_MAIN (mymain);