merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit e24dd4856b91c4958df7c578275f60cdc11401f2
parent f641e252f0ae2e6ebc0cb5520363f69b65427c8b
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
Date:   Mon, 29 Jun 2020 16:10:14 -0400

get reserve and tip testing commands use variadic args

Diffstat:
Msrc/include/taler_merchant_testing_lib.h | 13+++++++++----
Msrc/testing/test_merchant_api.c | 14+++++++-------
Msrc/testing/testing_api_cmd_get_reserve.c | 43+++++++++++++++++++++++++++++++------------
Msrc/testing/testing_api_cmd_merchant_get_tip.c | 45++++++++++++++++++++++++++++++++-------------
4 files changed, 79 insertions(+), 36 deletions(-)

diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h @@ -749,7 +749,9 @@ TALER_TESTING_cmd_merchant_get_reserve (const char *label, * @param http_status expected HTTP response code. * @param reserve_reference reference to a "POST /reserves" that provides the * information we are expecting. - * @param tip_refs a NULL-terminated list of references to tips + * @param ... NULL-terminated list of labels (const char *) of + * tip (commands) we expect to be returned in the list + * (assuming @a http_code is #MHD_HTTP_OK) * @return the command. */ struct TALER_TESTING_Command @@ -757,7 +759,7 @@ TALER_TESTING_cmd_merchant_get_reserve_with_tips (const char *label, const char *merchant_url, unsigned int http_status, const char *reserve_reference, - const char *tip_refs[]); + ...); /** @@ -852,13 +854,16 @@ TALER_TESTING_cmd_merchant_get_tip (const char *label, * @param pickup_refs a NULL-terminated list of pickup commands * associated with the tip. * @param http_status expected HTTP response code for the request. + * @param ... NULL-terminated list of labels (const char *) of + * pickup (commands) we expect to be returned in the list + * (assuming @a http_code is #MHD_HTTP_OK) */ struct TALER_TESTING_Command TALER_TESTING_cmd_merchant_get_tip_with_pickups (const char *label, const char *merchant_url, const char *tip_reference, - const char *pickup_refs[], - unsigned int http_status); + unsigned int http_status, + ...); /** * Define a GET /tips/$TIP_ID CMD. diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c @@ -49,14 +49,10 @@ */ #define EXCHANGE_URL "http://localhost:8081/" -static const char *tip_refs[] = {"authorize-tip-1", "authorize-tip-2", NULL}; - static const char *pickup_amounts_1[] = {"EUR:5", NULL}; static const char *pickup_amounts_2[] = {"EUR:0.01", NULL}; -static const char *pickup_refs[] = {"pickup-tip-1", "pickup-tip-4", NULL}; - /** * Payto URI of the customer (payer). */ @@ -762,7 +758,9 @@ run (void *cls, merchant_url, MHD_HTTP_OK, "create-reserve-tip-1", - tip_refs), + "authorize-tip-1", + "authorize-tip-2", + NULL), TALER_TESTING_cmd_tip_pickup ("pickup-tip-1", merchant_url, MHD_HTTP_OK, @@ -794,8 +792,10 @@ run (void *cls, TALER_TESTING_cmd_merchant_get_tip_with_pickups ("merchant-get-tip-2", merchant_url, "authorize-tip-1", - pickup_refs, - MHD_HTTP_OK), + MHD_HTTP_OK, + "pickup-tip-1", + "pickup-tip-4", + NULL), /* This command tests the authorization of tip * against a reserve that does not exist. This is diff --git a/src/testing/testing_api_cmd_get_reserve.c b/src/testing/testing_api_cmd_get_reserve.c @@ -62,9 +62,14 @@ struct GetReserveState bool fetch_tips; /** + * Length of @e tips. + */ + unsigned int tips_length; + + /** * The list of references to tips. */ - const char **tip_refs; + const char **tips; }; @@ -118,19 +123,19 @@ get_reserve_cb (void *cls, return; } } + if (tips_length != grs->tips_length) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Number of tips authorized does not match\n"); + TALER_TESTING_interpreter_fail (grs->is); + return; + } for (unsigned int i = 0; i < tips_length; ++i) { const struct TALER_TESTING_Command *tip_cmd; - if (NULL == grs->tip_refs[i]) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Number of tips authorized does not match\n"); - TALER_TESTING_interpreter_fail (grs->is); - return; - } tip_cmd = TALER_TESTING_interpreter_lookup_command (grs->is, - grs->tip_refs[i]); + grs->tips[i]); { const struct GNUNET_HashCode *tip_id; @@ -301,7 +306,9 @@ TALER_TESTING_cmd_merchant_get_reserve (const char *label, * @param http_status expected HTTP response code. * @param reserve_reference reference to a "POST /reserves" that provides the * information we are expecting. - * @param tip_refs a NULL-terminated list of references to tips + * @param ... NULL-terminated list of labels (const char *) of + * tip (commands) we expect to be returned in the list + * (assuming @a http_code is #MHD_HTTP_OK) * @return the command. */ struct TALER_TESTING_Command @@ -309,7 +316,7 @@ TALER_TESTING_cmd_merchant_get_reserve_with_tips (const char *label, const char *merchant_url, unsigned int http_status, const char *reserve_reference, - const char *tip_refs[]) + ...) { struct GetReserveState *grs; @@ -318,7 +325,19 @@ TALER_TESTING_cmd_merchant_get_reserve_with_tips (const char *label, grs->http_status = http_status; grs->reserve_reference = reserve_reference; grs->fetch_tips = true; - grs->tip_refs = tip_refs; + { + const char *clabel; + va_list ap; + + va_start (ap, reserve_reference); + while (NULL != (clabel = va_arg (ap, const char *))) + { + GNUNET_array_append (grs->tips, + grs->tips_length, + clabel); + } + va_end (ap); + } { struct TALER_TESTING_Command cmd = { .cls = grs, diff --git a/src/testing/testing_api_cmd_merchant_get_tip.c b/src/testing/testing_api_cmd_merchant_get_tip.c @@ -49,9 +49,14 @@ struct MerchantTipGetState bool fetch_pickups; /** + * The length of @e pickups. + */ + unsigned int pickups_length; + + /** * The NULL-terminated list of pickup commands associated with the tip. */ - const char **pickup_refs; + const char **pickups; /** * The handle to the current GET /tips/$TIP_ID request. @@ -169,21 +174,20 @@ merchant_get_tip_cb (void *cls, return; } } + if (pickups_length != gts->pickups_length) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Length of pickups array does not match\n"); + TALER_TESTING_interpreter_fail (gts->is); + return; + } { for (unsigned int i = 0; i < pickups_length; ++i) { const struct TALER_TESTING_Command *pickup_cmd; - if (NULL == gts->pickup_refs[i]) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Length of pickup array does not match\n"); - TALER_TESTING_interpreter_fail (gts->is); - return; - } pickup_cmd = TALER_TESTING_interpreter_lookup_command (gts->is, - gts->pickup_refs[ - i]); + gts->pickups[i]); { const uint64_t *num_planchets; @@ -348,13 +352,16 @@ TALER_TESTING_cmd_merchant_get_tip (const char *label, * @param pickup_refs a NULL-terminated list of pickup commands * associated with the tip. * @param http_status expected HTTP response code for the request. + * @param ... NULL-terminated list of labels (const char *) of + * pickup (commands) we expect to be returned in the list + * (assuming @a http_code is #MHD_HTTP_OK) */ struct TALER_TESTING_Command TALER_TESTING_cmd_merchant_get_tip_with_pickups (const char *label, const char *merchant_url, const char *tip_reference, - const char *pickup_refs[], - unsigned int http_status) + unsigned int http_status, + ...) { struct MerchantTipGetState *tgs; @@ -362,9 +369,21 @@ TALER_TESTING_cmd_merchant_get_tip_with_pickups (const char *label, tgs->merchant_url = merchant_url; tgs->tip_reference = tip_reference; tgs->fetch_pickups = true; - tgs->pickup_refs = pickup_refs; tgs->http_status = http_status; { + const char *clabel; + va_list ap; + + va_start (ap, http_status); + while (NULL != (clabel = va_arg (ap, const char *))) + { + GNUNET_array_append (tgs->pickups, + tgs->pickups_length, + clabel); + } + va_end (ap); + } + { struct TALER_TESTING_Command cmd = { .cls = tgs, .label = label,