gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] 04/05: Introducing "rewind" CMD.


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] 04/05: Introducing "rewind" CMD.
Date: Wed, 09 May 2018 16:24:39 +0200

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

marcello pushed a commit to branch master
in repository merchant.

commit d30f4e1d34dd993ca0d32b08483e18095e196a18
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed May 9 16:01:54 2018 +0200

    Introducing "rewind" CMD.
    
    It allows one to point to the next desired
    CMD to execute into the interpreter.
---
 src/include/taler_merchant_testing_lib.h           | 18 +++++
 src/lib/Makefile.am                                |  1 +
 src/lib/testing_api_cmd_rewind.c                   | 92 ++++++++++++++++++++++
 src/merchant-tools/Makefile.am                     |  2 +-
 .../taler-merchant-generate-payments_new.c         |  4 +-
 5 files changed, 115 insertions(+), 2 deletions(-)

diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index 8394fc4..304a16b 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -581,5 +581,23 @@ TALER_TESTING_cmd_tip_pickup
    const char **amounts,
    struct TALER_EXCHANGE_Handle *exchange);
 
+/**
+ * Make the instruction pointer point to @a new_ip
+ * only if @a counter is greater than zero.
+ *
+ * @param label command label
+ * @param new_ip new instruction pointer's value.  Note that,
+ * when the next instruction will be called, the interpreter
+ * will increment the ip under the hood so this value must be
+ * set to the index of the instruction we want to execute next
+ * MINUS one.
+ * @param counter counts how many times the rewinding has
+ * to happen.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_rewind_ip
+  (const char *label,
+   int new_ip,
+   unsigned int *counter);
 
 #endif
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 39acd3a..6e88568 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -47,6 +47,7 @@ libtalermerchanttesting_la_SOURCES = \
   testing_api_cmd_tip.c \
   testing_api_cmd_track.c \
   testing_api_cmd_history.c \
+  testing_api_cmd_rewind.c \
   testing_api_helpers.c \
   testing_api_trait_merchant_sig.c \
   testing_api_trait_string.c \
diff --git a/src/lib/testing_api_cmd_rewind.c b/src/lib/testing_api_cmd_rewind.c
new file mode 100644
index 0000000..3e51f00
--- /dev/null
+++ b/src/lib/testing_api_cmd_rewind.c
@@ -0,0 +1,92 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2014-2018 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 lib/testing_api_cmd_rewind.c
+ * @brief command to rewind the instruction pointer.
+ * @author Marcello Stanisci
+ */
+
+#include "platform.h"
+#include <taler/taler_exchange_service.h>
+#include <taler/taler_testing_lib.h>
+#include "taler_merchant_service.h"
+#include "taler_merchant_testing_lib.h"
+
+struct RewindIpState
+{
+  unsigned int new_ip;
+  unsigned int *counter;
+};
+
+static void
+rewind_ip_cleanup (void *cls,
+                   const struct TALER_TESTING_Command *cmd)
+{}
+
+static void
+rewind_ip_run (void *cls,
+               const struct TALER_TESTING_Command *cmd,
+               struct TALER_TESTING_Interpreter *is)
+{
+  struct RewindIpState *ris = cls;
+
+  if (1 < *ris->counter)
+  {
+    is->ip = ris->new_ip;
+    *ris->counter -= 1; 
+  }
+
+  TALER_TESTING_interpreter_next (is);
+}
+
+/**
+ * Make the instruction pointer point to @a new_ip
+ * only if @a counter is greater than zero.
+ *
+ * @param label command label
+ * @param new_ip new instruction pointer's value.  Note that,
+ * when the next instruction will be called, the interpreter
+ * will increment the ip under the hood so this value must be
+ * set to the index of the instruction we want to execute next
+ * MINUS one.
+ * @param counter counts how many times the rewinding has
+ * to happen.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_rewind_ip
+  (const char *label,
+   int new_ip,
+   unsigned int *counter)
+{
+  struct RewindIpState *ris;
+  struct TALER_TESTING_Command cmd;
+
+  ris = GNUNET_new (struct RewindIpState);
+  ris->new_ip = new_ip;
+  ris->counter = counter;
+
+  cmd.cls = ris;
+  cmd.label = label;
+  cmd.run = &rewind_ip_run;
+  cmd.cleanup = &rewind_ip_cleanup;
+
+  return cmd;
+}
+
diff --git a/src/merchant-tools/Makefile.am b/src/merchant-tools/Makefile.am
index be51a7c..69354cd 100644
--- a/src/merchant-tools/Makefile.am
+++ b/src/merchant-tools/Makefile.am
@@ -21,9 +21,9 @@ taler_merchant_generate_payments_new_SOURCES = \
 taler_merchant_generate_payments_new_LDADD = \
   $(top_srcdir)/src/backenddb/libtalermerchantdb.la \
   $(top_srcdir)/src/lib/libtalermerchant.la \
+  $(top_srcdir)/src/lib/libtalermerchanttesting.la \
   $(LIBGCRYPT_LIBS) \
   -ltalertesting \
-  -ltalermerchanttesting \
   -ltalerfakebank \
   -ltalerbank \
   -ltalerbanktesting \
diff --git a/src/merchant-tools/taler-merchant-generate-payments_new.c 
b/src/merchant-tools/taler-merchant-generate-payments_new.c
index 09c42dd..0233f1e 100644
--- a/src/merchant-tools/taler-merchant-generate-payments_new.c
+++ b/src/merchant-tools/taler-merchant-generate-payments_new.c
@@ -78,7 +78,7 @@ static struct GNUNET_OS_Process *merchantd;
 /**
  * How many payments we want to generate.
  */
-static unsigned int payments_number;
+static unsigned int payments_number = 1;
 
 /**
  * How many /tracks operation we want to perform.
@@ -116,6 +116,8 @@ run (void *cls,
                               "USD:10.02"),
     TALER_TESTING_cmd_exec_wirewatch ("wirewatch-1",
                                       default_config_file),
+    TALER_TESTING_cmd_rewind_ip ("rew-payments", -1,
+                                 &payments_number),
     TALER_TESTING_cmd_end ()
   };
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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