test_merchant_api_common.c (6033B)
1 /* 2 This file is part of TALER 3 (C) 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_merchant_api_common.c 19 * @brief Unit test for test_merchant_api_common.c 20 * @author Florian Dold 21 */ 22 #include "platform.h" 23 #include "taler_merchant_service.h" 24 25 26 int 27 main (int argc, 28 const char *const argv[]) 29 { 30 struct TALER_MERCHANT_PayUriData pd; 31 struct TALER_MERCHANT_RefundUriData rd; 32 33 (void) argc; 34 (void) argv; 35 GNUNET_log_setup ("test_merchant_api_common", 36 "WARNING", 37 NULL); 38 /* test pay parser */ 39 GNUNET_assert (GNUNET_SYSERR == 40 TALER_MERCHANT_parse_pay_uri ( 41 "http://pay/localhost/my-order", 42 &pd)); 43 GNUNET_assert (GNUNET_SYSERR == 44 TALER_MERCHANT_parse_pay_uri ( 45 "taler://pay/localhost/my-order", 46 &pd)); 47 GNUNET_assert (GNUNET_SYSERR == 48 TALER_MERCHANT_parse_pay_uri ( 49 "taler://refund/localhost/my-order/", 50 &pd)); 51 GNUNET_assert (GNUNET_OK == 52 TALER_MERCHANT_parse_pay_uri ( 53 "taler://PAY/localhost/my-order/", 54 &pd)); 55 GNUNET_assert (0 == strcmp (pd.merchant_host, 56 "localhost")); 57 GNUNET_assert (NULL == pd.merchant_prefix_path); 58 GNUNET_assert (0 == strcmp (pd.order_id, 59 "my-order")); 60 GNUNET_assert (NULL == pd.session_id); 61 GNUNET_assert (NULL == pd.claim_token); 62 GNUNET_assert (NULL == pd.ssid); 63 GNUNET_assert (! pd.use_http); 64 TALER_MERCHANT_parse_pay_uri_free (&pd); 65 66 GNUNET_assert (GNUNET_OK == 67 TALER_MERCHANT_parse_pay_uri ( 68 "taler://pay/localhost/my-order/#myssid", 69 &pd)); 70 GNUNET_assert (0 == strcmp (pd.merchant_host, 71 "localhost")); 72 GNUNET_assert (0 == strcmp (pd.order_id, 73 "my-order")); 74 GNUNET_assert (NULL == pd.session_id); 75 GNUNET_assert (NULL == pd.claim_token); 76 GNUNET_assert (0 == strcmp (pd.ssid, 77 "myssid")); 78 GNUNET_assert (! pd.use_http); 79 TALER_MERCHANT_parse_pay_uri_free (&pd); 80 81 GNUNET_assert (GNUNET_OK == 82 TALER_MERCHANT_parse_pay_uri ( 83 "taler+http://pay/localhost/instance/foo/my-order/my-session#myssid", 84 &pd)); 85 GNUNET_assert (0 == strcmp (pd.merchant_host, 86 "localhost")); 87 GNUNET_assert (0 == strcmp (pd.merchant_prefix_path, 88 "instance/foo")); 89 GNUNET_assert (0 == strcmp (pd.order_id, 90 "my-order")); 91 GNUNET_assert (0 == strcmp (pd.session_id, 92 "my-session")); 93 GNUNET_assert (NULL == pd.claim_token); 94 GNUNET_assert (0 == strcmp (pd.ssid, 95 "myssid")); 96 GNUNET_assert (pd.use_http); 97 TALER_MERCHANT_parse_pay_uri_free (&pd); 98 99 GNUNET_assert (GNUNET_OK == 100 TALER_MERCHANT_parse_pay_uri ( 101 "taler+http://pay/localhost/my-order/my-session?c=3QV8F3W34Y1FX6R8P2JZNMQ2JQ#myssid", 102 &pd)); 103 GNUNET_assert (0 == strcmp (pd.merchant_host, 104 "localhost")); 105 GNUNET_assert (NULL == pd.merchant_prefix_path); 106 GNUNET_assert (0 == strcmp (pd.order_id, 107 "my-order")); 108 GNUNET_assert (0 == strcmp (pd.session_id, 109 "my-session")); 110 GNUNET_assert (NULL != pd.claim_token); 111 GNUNET_assert (0 == strcmp (pd.ssid, 112 "myssid")); 113 GNUNET_assert (pd.use_http); 114 TALER_MERCHANT_parse_pay_uri_free (&pd); 115 116 117 /* test refund parser */ 118 GNUNET_assert (GNUNET_SYSERR == 119 TALER_MERCHANT_parse_refund_uri ( 120 "http://refund/localhost/my-order/", 121 &rd)); 122 GNUNET_assert (GNUNET_SYSERR == 123 TALER_MERCHANT_parse_refund_uri ( 124 "taler://refund/localhost/my-order", 125 &rd)); 126 GNUNET_assert (GNUNET_SYSERR == 127 TALER_MERCHANT_parse_refund_uri ( 128 "taler://pay/localhost/my-order/", 129 &rd)); 130 131 GNUNET_assert (GNUNET_OK == 132 TALER_MERCHANT_parse_refund_uri ( 133 "taler://refund/localhost/my-order/#myssid", 134 &rd)); 135 GNUNET_assert (0 == strcmp (rd.merchant_host, 136 "localhost")); 137 GNUNET_assert (NULL == pd.merchant_prefix_path); 138 GNUNET_assert (0 == strcmp (rd.order_id, 139 "my-order")); 140 GNUNET_assert (0 == strcmp (rd.ssid, 141 "myssid")); 142 GNUNET_assert (! rd.use_http); 143 TALER_MERCHANT_parse_refund_uri_free (&rd); 144 145 GNUNET_assert (GNUNET_OK == 146 TALER_MERCHANT_parse_refund_uri ( 147 "taler+http://REFUND/localhost/instance/foo/my-order/", 148 &rd)); 149 GNUNET_assert (0 == strcmp (rd.merchant_host, 150 "localhost")); 151 GNUNET_assert (0 == strcmp ("instance/foo", 152 rd.merchant_prefix_path)); 153 GNUNET_assert (0 == strcmp (rd.order_id, 154 "my-order")); 155 GNUNET_assert (NULL == rd.ssid); 156 GNUNET_assert (rd.use_http); 157 TALER_MERCHANT_parse_refund_uri_free (&rd); 158 159 return 0; 160 } 161 162 163 /* end of test_merchant_api_common.c */