diff options
-rw-r--r-- | src/util/Makefile.am | 14 | ||||
-rw-r--r-- | src/util/plugin.c | 3 | ||||
-rw-r--r-- | src/wire/Makefile.am | 17 | ||||
-rw-r--r-- | src/wire/test_sepa_wireformat.c | 92 |
4 files changed, 95 insertions, 31 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index eaf3a4827..8efc3987a 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -33,6 +33,7 @@ libtalerutil_la_SOURCES = \ util.c \ json.c \ os_installation.c \ + plugin.c \ wireformats.c libtalerutil_la_LIBADD = \ @@ -48,14 +49,12 @@ libtalerutil_la_LDFLAGS = \ TESTS = \ test_amount \ test_crypto \ - test_json \ - test_wireformats + test_json check_PROGRAMS= \ test_amount \ test_crypto \ - test_json \ - test_wireformats + test_json test_amount_SOURCES = \ @@ -76,10 +75,3 @@ test_json_LDADD = \ -lgnunetutil \ -ljansson \ libtalerutil.la - -test_wireformats_SOURCES = \ - test_wireformats.c -test_wireformats_LDADD = \ - -lgnunetutil \ - -ljansson \ - libtalerutil.la diff --git a/src/util/plugin.c b/src/util/plugin.c index d76dfa781..6f8e03df6 100644 --- a/src/util/plugin.c +++ b/src/util/plugin.c @@ -19,6 +19,9 @@ * @author Christian Grothoff * @author Sree Harsha Totakura <sreeharsha@totakura.in> */ +#include "platform.h" +#include "taler_util.h" +#include <ltdl.h> /** * Libtool search path before we started. 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; } |