summaryrefslogtreecommitdiff
path: root/src/exchange-lib/testing_api_loop.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-01-21 19:57:09 +0100
committerChristian Grothoff <christian@grothoff.org>2018-01-21 19:57:09 +0100
commit652bb0f9c4d9527c409db6a99a7e550c57328adf (patch)
treee77e6e2e18dd9a8ee786d76477eafa8f9e7a4c01 /src/exchange-lib/testing_api_loop.c
parent8013c4b66a1926a9f49673a125f9822bf40dbd94 (diff)
downloadexchange-652bb0f9c4d9527c409db6a99a7e550c57328adf.tar.gz
exchange-652bb0f9c4d9527c409db6a99a7e550c57328adf.tar.bz2
exchange-652bb0f9c4d9527c409db6a99a7e550c57328adf.zip
finish simplifying main by adding more helpers and macros
Diffstat (limited to 'src/exchange-lib/testing_api_loop.c')
-rw-r--r--src/exchange-lib/testing_api_loop.c54
1 files changed, 52 insertions, 2 deletions
diff --git a/src/exchange-lib/testing_api_loop.c b/src/exchange-lib/testing_api_loop.c
index 47175fe47..8c2364984 100644
--- a/src/exchange-lib/testing_api_loop.c
+++ b/src/exchange-lib/testing_api_loop.c
@@ -26,6 +26,8 @@
#include "exchange_api_handle.h"
#include "taler_signatures.h"
#include "taler_testing_lib.h"
+#include "taler_fakebank_lib.h"
+
/**
* Global state of the interpreter, used by a command
@@ -61,6 +63,12 @@ struct TALER_TESTING_Interpreter
struct GNUNET_CURL_RescheduleContext *rc;
/**
+ * Handle to our fakebank, if #TALER_TESTING_run_with_fakebank() was used.
+ * Otherwise NULL.
+ */
+ struct TALER_FAKEBANK_Handle *fakebank;
+
+ /**
* Task run on timeout.
*/
struct GNUNET_SCHEDULER_Task *timeout_task;
@@ -123,9 +131,46 @@ TALER_TESTING_interpreter_lookup_command (struct TALER_TESTING_Interpreter *is,
* Obtain main execution context for the main loop.
*/
struct GNUNET_CURL_Context *
-TALER_TESTING_interpreter_get_context (struct TALER_TESTING_Interpreter *i)
+TALER_TESTING_interpreter_get_context (struct TALER_TESTING_Interpreter *is)
+{
+ return is->ctx;
+}
+
+
+struct TALER_FAKEBANK_Handle *
+TALER_TESTING_interpreter_get_fakebank (struct TALER_TESTING_Interpreter *is)
+{
+ return is->fakebank;
+}
+
+
+void
+TALER_TESTING_run_with_fakebank (struct TALER_TESTING_Interpreter *is,
+ struct TALER_TESTING_Command *commands,
+ const char *bank_url)
{
- return i->ctx;
+ const char *port;
+ long pnum;
+
+ port = strrchr (bank_url,
+ (unsigned char) ':');
+ if (NULL == port)
+ pnum = 80;
+ else
+ pnum = strtol (port + 1, NULL, 10);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Staring Fakebank on port %u (%s)\n",
+ (unsigned int) pnum,
+ bank_url);
+ is->fakebank = TALER_FAKEBANK_start ((uint16_t) pnum);
+ if (NULL == is->fakebank)
+ {
+ GNUNET_break (0);
+ is->result = GNUNET_SYSERR;
+ return;
+ }
+ TALER_TESTING_run (is,
+ commands);
}
@@ -258,6 +303,11 @@ do_shutdown (void *cls)
GNUNET_SCHEDULER_cancel (is->child_death_task);
is->child_death_task = NULL;
}
+ if (NULL != is->fakebank)
+ {
+ TALER_FAKEBANK_stop (is->fakebank);
+ is->fakebank = NULL;
+ }
GNUNET_free_non_null (is->commands);
}