LCOV - code coverage report
Current view: top level - util - test_url.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 91.3 % 23 21
Test Date: 2026-01-04 22:17:00 Functions: 100.0 % 2 2

            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/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           15 : cf (char *input,
      34              :     const char *expected)
      35              : {
      36           15 :   if (0 != strcmp (input,
      37              :                    expected))
      38              :   {
      39            0 :     printf ("got '%s' but expected '%s'\n",
      40              :             input,
      41              :             expected);
      42            0 :     GNUNET_assert (0);
      43              :   }
      44           15 :   GNUNET_free (input);
      45           15 : }
      46              : 
      47              : 
      48              : int
      49            1 : main (int argc,
      50              :       const char *const argv[])
      51              : {
      52              :   (void) argc;
      53              :   (void) argv;
      54            1 :   cf (TALER_urlencode (""), "");
      55            1 :   cf (TALER_urlencode ("abc"), "abc");
      56            1 :   cf (TALER_urlencode ("~~"), "~~");
      57            1 :   cf (TALER_urlencode ("foo bar"), "foo%20bar");
      58            1 :   cf (TALER_urlencode ("foo bar "), "foo%20bar%20");
      59            1 :   cf (TALER_urlencode ("% % "), "%25%20%25%20");
      60              : 
      61            1 :   cf (TALER_url_join ("https://taler.net/", "foo", NULL),
      62              :       "https://taler.net/foo");
      63            1 :   cf (TALER_url_join ("https://taler.net/", "foo", NULL),
      64              :       "https://taler.net/foo");
      65              : 
      66            1 :   cf (TALER_url_join ("https://taler.net/", "foo", "x", "42", NULL),
      67              :       "https://taler.net/foo?x=42");
      68            1 :   cf (TALER_url_join ("https://taler.net/", "foo", "x", "42", "y", "bla", NULL),
      69              :       "https://taler.net/foo?x=42&y=bla");
      70            1 :   cf (TALER_url_join ("https://taler.net/", "foo", "x", NULL, "y", "bla", NULL),
      71              :       "https://taler.net/foo?y=bla");
      72            1 :   cf (TALER_url_join ("https://taler.net/", "foo", "x", "", "y", "1", NULL),
      73              :       "https://taler.net/foo?x=&y=1");
      74              : 
      75            1 :   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            1 :   cf (TALER_url_join ("https://taler.net/", "foo/bar?spam=eggs&quux=", NULL),
      80              :       "https://taler.net/foo/bar?spam=eggs&quux=");
      81              : 
      82            1 :   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            1 :   return 0;
      90              : }
      91              : 
      92              : 
      93              : /* end of test_url.c */
        

Generated by: LCOV version 2.0-1