move wireformat test to plugin
This commit is contained in:
parent
e5c5dc9cae
commit
fc57913530
@ -33,6 +33,7 @@ libtalerutil_la_SOURCES = \
|
|||||||
util.c \
|
util.c \
|
||||||
json.c \
|
json.c \
|
||||||
os_installation.c \
|
os_installation.c \
|
||||||
|
plugin.c \
|
||||||
wireformats.c
|
wireformats.c
|
||||||
|
|
||||||
libtalerutil_la_LIBADD = \
|
libtalerutil_la_LIBADD = \
|
||||||
@ -48,14 +49,12 @@ libtalerutil_la_LDFLAGS = \
|
|||||||
TESTS = \
|
TESTS = \
|
||||||
test_amount \
|
test_amount \
|
||||||
test_crypto \
|
test_crypto \
|
||||||
test_json \
|
test_json
|
||||||
test_wireformats
|
|
||||||
|
|
||||||
check_PROGRAMS= \
|
check_PROGRAMS= \
|
||||||
test_amount \
|
test_amount \
|
||||||
test_crypto \
|
test_crypto \
|
||||||
test_json \
|
test_json
|
||||||
test_wireformats
|
|
||||||
|
|
||||||
|
|
||||||
test_amount_SOURCES = \
|
test_amount_SOURCES = \
|
||||||
@ -76,10 +75,3 @@ test_json_LDADD = \
|
|||||||
-lgnunetutil \
|
-lgnunetutil \
|
||||||
-ljansson \
|
-ljansson \
|
||||||
libtalerutil.la
|
libtalerutil.la
|
||||||
|
|
||||||
test_wireformats_SOURCES = \
|
|
||||||
test_wireformats.c
|
|
||||||
test_wireformats_LDADD = \
|
|
||||||
-lgnunetutil \
|
|
||||||
-ljansson \
|
|
||||||
libtalerutil.la
|
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
* @author Christian Grothoff
|
* @author Christian Grothoff
|
||||||
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
|
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
|
||||||
*/
|
*/
|
||||||
|
#include "platform.h"
|
||||||
|
#include "taler_util.h"
|
||||||
|
#include <ltdl.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Libtool search path before we started.
|
* Libtool search path before we started.
|
||||||
|
@ -45,3 +45,20 @@ libtaler_plugin_wire_template_la_LDFLAGS = \
|
|||||||
$(TALER_PLUGIN_LDFLAGS) \
|
$(TALER_PLUGIN_LDFLAGS) \
|
||||||
$(top_builddir)/src/util/libtalerutil.la \
|
$(top_builddir)/src/util/libtalerutil.la \
|
||||||
-lgnunetutil $(XLIB)
|
-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
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
This file is part of TALER
|
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
|
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
|
terms of the GNU General Public License as published by the Free Software
|
||||||
@ -15,14 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file util/test_wireformats.c
|
* @file wire/test_sepa_wireformat.c
|
||||||
* @brief Tests for JSON validations
|
* @brief Tests for JSON SEPA format validation
|
||||||
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
|
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "taler_util.h"
|
#include "taler_util.h"
|
||||||
#include "taler_json_lib.h"
|
#include "taler_wire_plugin.h"
|
||||||
|
|
||||||
|
|
||||||
/* Valid SEPA data */
|
/* Valid SEPA data */
|
||||||
static const char * const valid_wire_str =
|
static const char * const valid_wire_str =
|
||||||
@ -61,37 +62,88 @@ static const char * const unsupported_wire_str =
|
|||||||
\"address\": \"foobar\"}";
|
\"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
|
int
|
||||||
main(int argc,
|
main(int argc,
|
||||||
const char *const argv[])
|
const char *const argv[])
|
||||||
{
|
{
|
||||||
const char *unsupported[] = {
|
|
||||||
"unsupported",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
const char *sepa[] = {
|
|
||||||
"SEPA",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
json_t *wire;
|
json_t *wire;
|
||||||
json_error_t error;
|
json_error_t error;
|
||||||
int ret;
|
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));
|
(void) memset(&error, 0, sizeof(error));
|
||||||
GNUNET_assert (NULL != (wire = json_loads (unsupported_wire_str, 0, NULL)));
|
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);
|
json_decref (wire);
|
||||||
GNUNET_assert (NULL != (wire = json_loads (invalid_wire_str, 0, NULL)));
|
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);
|
json_decref (wire);
|
||||||
GNUNET_assert (NULL != (wire = json_loads (invalid_wire_str2, 0, NULL)));
|
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);
|
json_decref (wire);
|
||||||
GNUNET_assert (NULL != (wire = json_loads (valid_wire_str, 0, &error)));
|
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);
|
json_decref (wire);
|
||||||
if (1 == ret)
|
wire_plugin_unload (plugin);
|
||||||
return 0;
|
GNUNET_CONFIGURATION_destroy (cfg);
|
||||||
|
if (GNUNET_NO == ret)
|
||||||
return 1;
|
return 1;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user