gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant] 266/277: get reserve and tip testing commands use varia


From: gnunet
Subject: [taler-merchant] 266/277: get reserve and tip testing commands use variadic args
Date: Sun, 05 Jul 2020 20:52:59 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository merchant.

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

    get reserve and tip testing commands use variadic args
---
 src/include/taler_merchant_testing_lib.h       | 13 +++++---
 src/testing/test_merchant_api.c                | 14 ++++----
 src/testing/testing_api_cmd_get_reserve.c      | 43 +++++++++++++++++-------
 src/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
index 219997d..5b4b835 100644
--- 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
index adae22d..2f30ca7 100644
--- 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
index 8c626f8..06ebb47 100644
--- a/src/testing/testing_api_cmd_get_reserve.c
+++ b/src/testing/testing_api_cmd_get_reserve.c
@@ -61,10 +61,15 @@ 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
index 085f957..6695d3b 100644
--- a/src/testing/testing_api_cmd_merchant_get_tip.c
+++ b/src/testing/testing_api_cmd_merchant_get_tip.c
@@ -48,10 +48,15 @@ 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,8 +369,20 @@ 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,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]