2018-01-31 18:16:59 +01:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
2020-01-14 15:57:36 +01:00
|
|
|
(C) 2015-2020 Taler Systems SA
|
2018-01-31 18:16:59 +01:00
|
|
|
|
|
|
|
TALER is free software; you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 3, or (at your option) any later version.
|
|
|
|
|
|
|
|
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file util/test_url.c
|
|
|
|
* @brief Tests for url helpers
|
|
|
|
* @author Florian Dold
|
|
|
|
*/
|
|
|
|
#include "platform.h"
|
|
|
|
#include "taler_util.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check and free result.
|
|
|
|
*
|
|
|
|
* @param input to check and free
|
|
|
|
* @param expected expected input
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
cf (char *input, char *expected)
|
|
|
|
{
|
2019-10-17 15:50:15 +02:00
|
|
|
if (0 != strcmp (input, expected))
|
|
|
|
{
|
|
|
|
printf ("got '%s' but expected '%s'\n", input, expected);
|
|
|
|
GNUNET_assert (0);
|
|
|
|
}
|
2018-01-31 18:16:59 +01:00
|
|
|
GNUNET_free (input);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc,
|
|
|
|
const char *const argv[])
|
|
|
|
{
|
2020-03-27 17:28:33 +01:00
|
|
|
(void) argc;
|
|
|
|
(void) argv;
|
2018-01-31 18:16:59 +01:00
|
|
|
cf (TALER_urlencode (""), "");
|
|
|
|
cf (TALER_urlencode ("abc"), "abc");
|
|
|
|
cf (TALER_urlencode ("~~"), "~~");
|
|
|
|
cf (TALER_urlencode ("foo bar"), "foo%20bar");
|
|
|
|
cf (TALER_urlencode ("foo bar "), "foo%20bar%20");
|
|
|
|
cf (TALER_urlencode ("% % "), "%25%20%25%20");
|
|
|
|
|
2019-08-25 16:18:24 +02:00
|
|
|
cf (TALER_url_join ("https://taler.net/", "foo", NULL),
|
|
|
|
"https://taler.net/foo");
|
2019-09-23 17:23:54 +02:00
|
|
|
cf (TALER_url_join ("https://taler.net/", "foo", NULL),
|
2019-08-25 16:18:24 +02:00
|
|
|
"https://taler.net/foo");
|
2018-01-31 18:16:59 +01:00
|
|
|
|
|
|
|
cf (TALER_url_join ("https://taler.net/", "foo", "x", "42", NULL),
|
|
|
|
"https://taler.net/foo?x=42");
|
|
|
|
cf (TALER_url_join ("https://taler.net/", "foo", "x", "42", "y", "bla", NULL),
|
|
|
|
"https://taler.net/foo?x=42&y=bla");
|
|
|
|
cf (TALER_url_join ("https://taler.net/", "foo", "x", NULL, "y", "bla", NULL),
|
|
|
|
"https://taler.net/foo?y=bla");
|
|
|
|
cf (TALER_url_join ("https://taler.net/", "foo", "x", "", "y", "1", NULL),
|
|
|
|
"https://taler.net/foo?x=&y=1");
|
|
|
|
|
2019-09-23 17:23:54 +02:00
|
|
|
cf (TALER_url_join ("https://taler.net/", "foo/bar", "x", "a&b", NULL),
|
2018-01-31 18:16:59 +01:00
|
|
|
"https://taler.net/foo/bar?x=a%26b");
|
|
|
|
|
|
|
|
/* Path component is not encoded! */
|
2019-09-23 17:23:54 +02:00
|
|
|
cf (TALER_url_join ("https://taler.net/", "foo/bar?spam=eggs&quux=", NULL),
|
2018-01-31 18:16:59 +01:00
|
|
|
"https://taler.net/foo/bar?spam=eggs&quux=");
|
|
|
|
|
|
|
|
cf (TALER_url_absolute_raw ("https", "taler.net", "foo/bar", "baz",
|
|
|
|
"x", "a&b",
|
|
|
|
"c", "d",
|
|
|
|
"e", "",
|
|
|
|
NULL),
|
|
|
|
"https://taler.net/foo/bar/baz?x=a%26b&c=d&e=");
|
|
|
|
|
2021-04-20 21:02:31 +02:00
|
|
|
return 1; // fault injection to test buildbot...
|
2018-01-31 18:16:59 +01:00
|
|
|
}
|
|
|
|
|
2019-10-31 12:59:50 +01:00
|
|
|
|
2018-01-31 18:16:59 +01:00
|
|
|
/* end of test_url.c */
|