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 Affero 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.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @file namecache/test_plugin_namecache.c
20 * @brief Test for the namecache plugins
21 * @author Christian Grothoff
24 #include "gnunet_util_lib.h"
25 #include "gnunet_namecache_plugin.h"
26 #include "gnunet_testing_lib.h"
32 * Name of plugin under test.
34 static const char *plugin_name;
38 * Function called when the service shuts down. Unloads our namecache
41 * @param api api to unload
44 unload_plugin (struct GNUNET_NAMECACHE_PluginFunctions *api)
48 GNUNET_asprintf (&libname, "libgnunet_plugin_namecache_%s", plugin_name);
49 GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api));
50 GNUNET_free (libname);
55 * Load the namecache plugin.
57 * @param cfg configuration to pass
58 * @return NULL on error
60 static struct GNUNET_NAMECACHE_PluginFunctions *
61 load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
63 struct GNUNET_NAMECACHE_PluginFunctions *ret;
66 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' namecache plugin\n"),
68 GNUNET_asprintf (&libname, "libgnunet_plugin_namecache_%s", plugin_name);
69 if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void*) cfg)))
71 FPRINTF (stderr, "Failed to load plugin `%s'!\n", plugin_name);
72 GNUNET_free (libname);
75 GNUNET_free (libname);
81 run (void *cls, char *const *args, const char *cfgfile,
82 const struct GNUNET_CONFIGURATION_Handle *cfg)
84 struct GNUNET_NAMECACHE_PluginFunctions *nsp;
87 nsp = load_plugin (cfg);
92 "Failed to initialize namecache. Database likely not setup, skipping test.\n");
101 main (int argc, char *argv[])
104 char *const xargv[] = {
105 "test-plugin-namecache",
110 struct GNUNET_GETOPT_CommandLineOption options[] = {
111 GNUNET_GETOPT_OPTION_END
114 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namecache-sqlite");
115 GNUNET_log_setup ("test-plugin-namecache",
118 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
119 GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_plugin_namecache_%s.conf",
121 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
122 "test-plugin-namecache", "nohelp", options, &run, NULL);
124 FPRINTF (stderr, "Missed some testcases: %d\n", ok);
125 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namecache-sqlite");
129 /* end of test_plugin_namecache.c */