Debian Codegraph @

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

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 /*
3 * License: GPLv3+
4 * Copyright (c) 2018 Davide Madrisan <[email protected]>
5 *
6 * Unit test for lib/url_encode.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
25 #include "testutils.h"
26 #include "url_encode.h"
27
28 #define NPL_TESTING
29
30 #include "../lib/url_encode.c"
31
32 typedef struct test_data
33 {
34 char * url;
35 char * expect_value;
36 } test_data;
37
38 static int
39 test_url_encoding (const void *tdata)
40 {
41 const struct test_data *data = tdata;
42 int ret = 0;
43 char *encoded_url = url_encode (data->url);
44
45 TEST_ASSERT_EQUAL_STRING (encoded_url, data->expect_value);
46 free (encoded_url);
47 return ret;
48 }
49
50 static int
51 mymain (void)
52 {
53 int ret = 0;
54
55 #define DO_TEST(URL, EXPECT_VALUE) \
56 do \
57 { \
58 test_data data = { \
59 .url = URL, \
60 .expect_value = EXPECT_VALUE, \
61 }; \
62 if (test_run("check url encoding for " URL, \
63 test_url_encoding, (&data)) < 0) \
64 ret = -1; \
65 } \
66 while (0)
67
68 DO_TEST ("?test=true", "%3ftest%3dtrue");
69 DO_TEST ("?test=true&debug=false", "%3ftest%3dtrue%26debug%3dfalse");
70 DO_TEST ("{\"status\":{\"running\":true}}",
71 "%7b%22status%22%3a%7b%22running%22%3atrue%7d%7d");
72
73 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
74 }
75
76 TEST_MAIN (mymain);