aboutsummaryrefslogtreecommitdiff
path: root/src/wire
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-01-25 12:51:04 +0100
committerChristian Grothoff <christian@grothoff.org>2016-01-25 12:51:04 +0100
commitfc5791353087812db6df374d1e453a387c57550c (patch)
tree1ce61d6d83e84cf6685878229ec058ac4fe453ff /src/wire
parente5c5dc9cae56bdea02f7661c1c8a8cacfbe99f1c (diff)
move wireformat test to plugin
Diffstat (limited to 'src/wire')
-rw-r--r--src/wire/Makefile.am17
-rw-r--r--src/wire/test_sepa_wireformat.c92
2 files changed, 89 insertions, 20 deletions
diff --git a/src/wire/Makefile.am b/src/wire/Makefile.am
index a8bc4af69..528d91014 100644
--- a/src/wire/Makefile.am
+++ b/src/wire/Makefile.am
@@ -45,3 +45,20 @@ libtaler_plugin_wire_template_la_LDFLAGS = \
$(TALER_PLUGIN_LDFLAGS) \
$(top_builddir)/src/util/libtalerutil.la \
-lgnunetutil $(XLIB)
+
+
+
+TESTS = \
+ test_sepa_wireformat
+
+check_PROGRAMS= \
+ test_sepa_wireformat
+
+
+
+test_sepa_wireformat_SOURCES = \
+ test_sepa_wireformat.c
+test_sepa_wireformat_LDADD = \
+ -lgnunetutil \
+ -ljansson \
+ $(top_builddir)/src/util/libtalerutil.la
diff --git a/src/wire/test_sepa_wireformat.c b/src/wire/test_sepa_wireformat.c
index b41abb802..d00228dd1 100644
--- a/src/wire/test_sepa_wireformat.c
+++ b/src/wire/test_sepa_wireformat.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2014 GNUnet e.V.
+ (C) 2015, 2016 GNUnet e.V.
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
@@ -15,14 +15,15 @@
*/
/**
- * @file util/test_wireformats.c
- * @brief Tests for JSON validations
+ * @file wire/test_sepa_wireformat.c
+ * @brief Tests for JSON SEPA format validation
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
*/
#include "platform.h"
#include "taler_util.h"
-#include "taler_json_lib.h"
+#include "taler_wire_plugin.h"
+
/* Valid SEPA data */
static const char * const valid_wire_str =
@@ -61,37 +62,88 @@ static const char * const unsupported_wire_str =
\"address\": \"foobar\"}";
+/**
+ * Initialize the plugin.
+ *
+ * @param cfg configuration to use
+ * @return #GNUNET_OK on success
+ */
+static struct TALER_WIRE_Plugin *
+wire_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *plugin_name)
+{
+ char *lib_name;
+ struct TALER_WIRE_Plugin *plugin;
+
+ (void) GNUNET_asprintf (&lib_name,
+ "libtaler_plugin_wire_%s",
+ plugin_name);
+ plugin = GNUNET_PLUGIN_load (lib_name,
+ (void *) cfg);
+ if (NULL != plugin)
+ plugin->library_name = lib_name;
+ else
+ GNUNET_free (lib_name);
+ return plugin;
+}
+
+
+/**
+ * Shutdown the plugin.
+ *
+ * @param plugin the plugin to unload
+ */
+static void
+wire_plugin_unload (struct TALER_WIRE_Plugin *plugin)
+{
+ char *lib_name;
+
+ if (NULL == plugin)
+ return;
+ lib_name = plugin->library_name;
+ GNUNET_assert (NULL == GNUNET_PLUGIN_unload (lib_name,
+ plugin));
+ GNUNET_free (lib_name);
+}
+
+
int
main(int argc,
const char *const argv[])
{
- const char *unsupported[] = {
- "unsupported",
- NULL
- };
- const char *sepa[] = {
- "SEPA",
- NULL
- };
json_t *wire;
json_error_t error;
int ret;
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+ struct TALER_WIRE_Plugin *plugin;
- GNUNET_log_setup ("test-json-validations", "WARNING", NULL);
+ GNUNET_log_setup ("test-sepa-wireformats",
+ "WARNING",
+ NULL);
+ cfg = GNUNET_CONFIGURATION_create ();
+ GNUNET_CONFIGURATION_set_value_string (cfg,
+ "mint",
+ "currency",
+ "EUR");
+ plugin = wire_plugin_load (cfg,
+ "sepa");
+ GNUNET_assert (NULL != plugin);
(void) memset(&error, 0, sizeof(error));
GNUNET_assert (NULL != (wire = json_loads (unsupported_wire_str, 0, NULL)));
- GNUNET_assert (1 != TALER_json_validate_wireformat (unsupported, wire));
+ GNUNET_assert (GNUNET_NO == plugin->wire_validate (wire));
json_decref (wire);
GNUNET_assert (NULL != (wire = json_loads (invalid_wire_str, 0, NULL)));
- GNUNET_assert (1 != TALER_json_validate_wireformat (sepa, wire));
+ GNUNET_assert (GNUNET_NO == plugin->wire_validate (wire));
json_decref (wire);
GNUNET_assert (NULL != (wire = json_loads (invalid_wire_str2, 0, NULL)));
- GNUNET_assert (1 != TALER_json_validate_wireformat (sepa, wire));
+ GNUNET_assert (GNUNET_NO == plugin->wire_validate (wire));
json_decref (wire);
GNUNET_assert (NULL != (wire = json_loads (valid_wire_str, 0, &error)));
- ret = TALER_json_validate_wireformat (sepa, wire);
+ ret = plugin->wire_validate (wire);
json_decref (wire);
- if (1 == ret)
- return 0;
- return 1;
+ wire_plugin_unload (plugin);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ if (GNUNET_NO == ret)
+ return 1;
+ return 0;
}