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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @file namecache/test_plugin_namecache.c
22 * @brief Test for the namecache plugins
23 * @author Christian Grothoff
26 #include "gnunet_util_lib.h"
27 #include "gnunet_namecache_plugin.h"
28 #include "gnunet_testing_lib.h"
34 * Name of plugin under test.
36 static const char *plugin_name;
40 * Function called when the service shuts down. Unloads our namecache
43 * @param api api to unload
46 unload_plugin (struct GNUNET_NAMECACHE_PluginFunctions *api)
50 GNUNET_asprintf (&libname, "libgnunet_plugin_namecache_%s", plugin_name);
51 GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api));
52 GNUNET_free (libname);
57 * Load the namecache plugin.
59 * @param cfg configuration to pass
60 * @return NULL on error
62 static struct GNUNET_NAMECACHE_PluginFunctions *
63 load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
65 struct GNUNET_NAMECACHE_PluginFunctions *ret;
68 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' namecache plugin\n"),
70 GNUNET_asprintf (&libname, "libgnunet_plugin_namecache_%s", plugin_name);
71 if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void*) cfg)))
73 FPRINTF (stderr, "Failed to load plugin `%s'!\n", plugin_name);
74 GNUNET_free (libname);
77 GNUNET_free (libname);
83 run (void *cls, char *const *args, const char *cfgfile,
84 const struct GNUNET_CONFIGURATION_Handle *cfg)
86 struct GNUNET_NAMECACHE_PluginFunctions *nsp;
89 nsp = load_plugin (cfg);
94 "Failed to initialize namecache. Database likely not setup, skipping test.\n");
103 main (int argc, char *argv[])
105 char cfg_name[PATH_MAX];
106 char *const xargv[] = {
107 "test-plugin-namecache",
112 struct GNUNET_GETOPT_CommandLineOption options[] = {
113 GNUNET_GETOPT_OPTION_END
116 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namecache-sqlite");
117 GNUNET_log_setup ("test-plugin-namecache",
120 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
121 GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_plugin_namecache_%s.conf",
123 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
124 "test-plugin-namecache", "nohelp", options, &run, NULL);
126 FPRINTF (stderr, "Missed some testcases: %d\n", ok);
127 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namecache-sqlite");
131 /* end of test_plugin_namecache.c */