Line data Source code
1 : /*
2 : This file is part of TALER
3 : (C) 2015-2020 Taler Systems SA
4 :
5 : TALER is free software; you can redistribute it and/or modify it under the
6 : terms of the GNU General Public License as published by the Free Software
7 : Foundation; either version 3, or (at your option) any later version.
8 :
9 : TALER is distributed in the hope that it will be useful, but WITHOUT ANY
10 : WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 : A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 :
13 : You should have received a copy of the GNU General Public License along with
14 : TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
15 : */
16 :
17 : /**
18 : * @file util/test_url.c
19 : * @brief Tests for url helpers
20 : * @author Florian Dold
21 : */
22 : #include "taler/taler_util.h"
23 :
24 :
25 : /**
26 : * Check and free result.
27 : *
28 : * @param input to check and free
29 : * @param expected expected input
30 : */
31 : static void
32 15 : cf (char *input,
33 : const char *expected)
34 : {
35 15 : if (0 != strcmp (input,
36 : expected))
37 : {
38 0 : printf ("got '%s' but expected '%s'\n",
39 : input,
40 : expected);
41 0 : GNUNET_assert (0);
42 : }
43 15 : GNUNET_free (input);
44 15 : }
45 :
46 :
47 : int
48 1 : main (int argc,
49 : const char *const argv[])
50 : {
51 : (void) argc;
52 : (void) argv;
53 1 : cf (TALER_urlencode (""), "");
54 1 : cf (TALER_urlencode ("abc"), "abc");
55 1 : cf (TALER_urlencode ("~~"), "~~");
56 1 : cf (TALER_urlencode ("foo bar"), "foo%20bar");
57 1 : cf (TALER_urlencode ("foo bar "), "foo%20bar%20");
58 1 : cf (TALER_urlencode ("% % "), "%25%20%25%20");
59 :
60 1 : cf (TALER_url_join ("https://taler.net/", "foo", NULL),
61 : "https://taler.net/foo");
62 1 : cf (TALER_url_join ("https://taler.net/", "foo", NULL),
63 : "https://taler.net/foo");
64 :
65 1 : cf (TALER_url_join ("https://taler.net/", "foo", "x", "42", NULL),
66 : "https://taler.net/foo?x=42");
67 1 : cf (TALER_url_join ("https://taler.net/", "foo", "x", "42", "y", "bla", NULL),
68 : "https://taler.net/foo?x=42&y=bla");
69 1 : cf (TALER_url_join ("https://taler.net/", "foo", "x", NULL, "y", "bla", NULL),
70 : "https://taler.net/foo?y=bla");
71 1 : cf (TALER_url_join ("https://taler.net/", "foo", "x", "", "y", "1", NULL),
72 : "https://taler.net/foo?x=&y=1");
73 :
74 1 : cf (TALER_url_join ("https://taler.net/", "foo/bar", "x", "a&b", NULL),
75 : "https://taler.net/foo/bar?x=a%26b");
76 :
77 : /* Path component is not encoded! */
78 1 : cf (TALER_url_join ("https://taler.net/", "foo/bar?spam=eggs&quux=", NULL),
79 : "https://taler.net/foo/bar?spam=eggs&quux=");
80 :
81 1 : cf (TALER_url_absolute_raw ("https", "taler.net", "foo/bar", "baz",
82 : "x", "a&b",
83 : "c", "d",
84 : "e", "",
85 : NULL),
86 : "https://taler.net/foo/bar/baz?x=a%26b&c=d&e=");
87 :
88 1 : return 0;
89 : }
90 :
91 :
92 : /* end of test_url.c */
|