2 This file is part of GNUnet.
3 Copyright (C) 2012 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
16 * @file namecache/test_plugin_namecache.c
17 * @brief Test for the namecache plugins
18 * @author Christian Grothoff
21 #include "gnunet_util_lib.h"
22 #include "gnunet_namecache_plugin.h"
23 #include "gnunet_testing_lib.h"
29 * Name of plugin under test.
31 static const char *plugin_name;
35 * Function called when the service shuts down. Unloads our namecache
38 * @param api api to unload
41 unload_plugin (struct GNUNET_NAMECACHE_PluginFunctions *api)
45 GNUNET_asprintf (&libname, "libgnunet_plugin_namecache_%s", plugin_name);
46 GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api));
47 GNUNET_free (libname);
52 * Load the namecache plugin.
54 * @param cfg configuration to pass
55 * @return NULL on error
57 static struct GNUNET_NAMECACHE_PluginFunctions *
58 load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
60 struct GNUNET_NAMECACHE_PluginFunctions *ret;
63 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' namecache plugin\n"),
65 GNUNET_asprintf (&libname, "libgnunet_plugin_namecache_%s", plugin_name);
66 if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void*) cfg)))
68 FPRINTF (stderr, "Failed to load plugin `%s'!\n", plugin_name);
69 GNUNET_free (libname);
72 GNUNET_free (libname);
78 run (void *cls, char *const *args, const char *cfgfile,
79 const struct GNUNET_CONFIGURATION_Handle *cfg)
81 struct GNUNET_NAMECACHE_PluginFunctions *nsp;
84 nsp = load_plugin (cfg);
89 "Failed to initialize namecache. Database likely not setup, skipping test.\n");
98 main (int argc, char *argv[])
101 char *const xargv[] = {
102 "test-plugin-namecache",
107 struct GNUNET_GETOPT_CommandLineOption options[] = {
108 GNUNET_GETOPT_OPTION_END
111 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namecache-sqlite");
112 GNUNET_log_setup ("test-plugin-namecache",
115 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
116 GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_plugin_namecache_%s.conf",
118 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
119 "test-plugin-namecache", "nohelp", options, &run, NULL);
121 FPRINTF (stderr, "Missed some testcases: %d\n", ok);
122 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namecache-sqlite");
126 /* end of test_plugin_namecache.c */