aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_payto.c
blob: 62ba7d28e47f94e58a548790d58d071221277425 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
  This file is part of TALER
  (C) 2020 Taler Systems SA

  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_payto.c
 * @brief Tests for payto helpers
 * @author Christian Grothoff
 */
#include "platform.h"
#include "taler_util.h"

#define CHECK(a,b) do { \
          GNUNET_assert (a != NULL); \
          GNUNET_assert (b != NULL); \
          if (0 != strcmp (a,b)) {   \
            GNUNET_break (0); \
            fprintf (stderr, "Got %s, wanted %s\n", b, a); \
            GNUNET_free (b); \
            return 1; \
          } else { \
            GNUNET_free (b); \
          }  \
} while (0)


int
main (int argc,
      const char *const argv[])
{
  char *r;

  (void) argc;
  (void) argv;
  GNUNET_log_setup ("test-payto",
                    "WARNING",
                    NULL);
  GNUNET_assert (NULL ==
                 TALER_iban_validate ("FR1420041010050500013M02606"));
  GNUNET_assert (NULL ==
                 TALER_iban_validate ("DE89370400440532013000"));
  r = TALER_payto_validate (
    "payto://x-taler-bank/hostname/username?receiver-name=foo");
  GNUNET_assert (NULL == r);
  r = TALER_payto_validate (
    "payto://x-taler-bank/hostname/~path/username?receiver-name=foo");
  GNUNET_assert (NULL == r);
  r = TALER_payto_validate (
    "payto://x-taler-bank/hostname/~path/username?receiver-name=fo/o");
  GNUNET_assert (NULL == r);
  r = TALER_payto_validate (
    "payto://x-taler-bank/hostname/path/username?receiver-name=foo");
  GNUNET_assert (NULL == r);
  r = TALER_payto_validate (
    "payto://x-taler-bank/https://hostname/username?receiver-name=foo");
  GNUNET_assert (NULL != r);
  GNUNET_free (r);
  r = TALER_payto_validate (
    "payto://x-taler-bank/hostname:4a2/path/username?receiver-name=foo");
  GNUNET_assert (NULL != r);
  GNUNET_free (r);
  r = TALER_payto_validate (
    "payto://x-taler-bank/-hostname/username?receiver-name=foo");
  GNUNET_assert (NULL != r);
  GNUNET_free (r);
  r = TALER_payto_validate (
    "payto://x-taler-bank/domain..name/username?receiver-name=foo");
  GNUNET_assert (NULL != r);
  GNUNET_free (r);
  r = TALER_payto_validate (
    "payto://x-taler-bank/domain..name/?receiver-name=foo");
  GNUNET_assert (NULL != r);
  GNUNET_free (r);
  r = TALER_payto_validate (
    "payto://x-taler-bank/domain.name/username");
  GNUNET_assert (NULL != r);
  GNUNET_free (r);
  r = TALER_xtalerbank_account_from_payto (
    "payto://x-taler-bank/localhost:1080/alice");
  CHECK ("alice",
         r);
  r = TALER_xtalerbank_account_from_payto (
    "payto://x-taler-bank/localhost:1080/path/alice");
  CHECK ("alice",
         r);
  r = TALER_xtalerbank_account_from_payto (
    "payto://x-taler-bank/localhost:1080/path/alice?receiver-name=ali/cia");
  CHECK ("alice",
         r);
  r = TALER_xtalerbank_account_from_payto (
    "payto://x-taler-bank/localhost:1080/alice?subject=hello&amount=EUR:1");
  CHECK ("alice",
         r);

  r = TALER_payto_get_subject (
    "payto://x-taler-bank/localhost:1080/alice?subject=hello&amount=EUR:1");
  CHECK ("hello",
         r);

  r = TALER_payto_get_subject (
    "payto://x-taler-bank/localhost:1080/alice");
  GNUNET_assert (r == NULL);
  return 0;
}


/* end of test_payto.c */