test_url.c (2799B)
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/platform.h" 23 #include "taler/taler_util.h" 24 25 26 /** 27 * Check and free result. 28 * 29 * @param input to check and free 30 * @param expected expected input 31 */ 32 static void 33 cf (char *input, 34 const char *expected) 35 { 36 if (0 != strcmp (input, 37 expected)) 38 { 39 printf ("got '%s' but expected '%s'\n", 40 input, 41 expected); 42 GNUNET_assert (0); 43 } 44 GNUNET_free (input); 45 } 46 47 48 int 49 main (int argc, 50 const char *const argv[]) 51 { 52 (void) argc; 53 (void) argv; 54 cf (TALER_urlencode (""), ""); 55 cf (TALER_urlencode ("abc"), "abc"); 56 cf (TALER_urlencode ("~~"), "~~"); 57 cf (TALER_urlencode ("foo bar"), "foo%20bar"); 58 cf (TALER_urlencode ("foo bar "), "foo%20bar%20"); 59 cf (TALER_urlencode ("% % "), "%25%20%25%20"); 60 61 cf (TALER_url_join ("https://taler.net/", "foo", NULL), 62 "https://taler.net/foo"); 63 cf (TALER_url_join ("https://taler.net/", "foo", NULL), 64 "https://taler.net/foo"); 65 66 cf (TALER_url_join ("https://taler.net/", "foo", "x", "42", NULL), 67 "https://taler.net/foo?x=42"); 68 cf (TALER_url_join ("https://taler.net/", "foo", "x", "42", "y", "bla", NULL), 69 "https://taler.net/foo?x=42&y=bla"); 70 cf (TALER_url_join ("https://taler.net/", "foo", "x", NULL, "y", "bla", NULL), 71 "https://taler.net/foo?y=bla"); 72 cf (TALER_url_join ("https://taler.net/", "foo", "x", "", "y", "1", NULL), 73 "https://taler.net/foo?x=&y=1"); 74 75 cf (TALER_url_join ("https://taler.net/", "foo/bar", "x", "a&b", NULL), 76 "https://taler.net/foo/bar?x=a%26b"); 77 78 /* Path component is not encoded! */ 79 cf (TALER_url_join ("https://taler.net/", "foo/bar?spam=eggs&quux=", NULL), 80 "https://taler.net/foo/bar?spam=eggs&quux="); 81 82 cf (TALER_url_absolute_raw ("https", "taler.net", "foo/bar", "baz", 83 "x", "a&b", 84 "c", "d", 85 "e", "", 86 NULL), 87 "https://taler.net/foo/bar/baz?x=a%26b&c=d&e="); 88 89 return 0; 90 } 91 92 93 /* end of test_url.c */