2 This file is part of GNUnet.
3 Copyright (C) 2015 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 namestore/test_plugin_namestore.c
20 * @brief Test for the namestore plugins
21 * @author Christian Grothoff
24 #include "gnunet_util_lib.h"
25 #include "gnunet_peerstore_plugin.h"
26 #include "gnunet_testing_lib.h"
32 * Name of plugin under test.
34 static const char *plugin_name;
37 static struct GNUNET_PEERSTORE_PluginFunctions *psp;
39 static struct GNUNET_PeerIdentity p1;
43 * Function called when the service shuts down. Unloads our namestore
46 * @param api api to unload
49 unload_plugin (struct GNUNET_PEERSTORE_PluginFunctions *api)
53 GNUNET_asprintf (&libname,
54 "libgnunet_plugin_peer_%s",
57 GNUNET_PLUGIN_unload (libname,
59 GNUNET_free (libname);
64 * Load the namestore plugin.
66 * @param cfg configuration to pass
67 * @return NULL on error
69 static struct GNUNET_PEERSTORE_PluginFunctions *
70 load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
72 struct GNUNET_PEERSTORE_PluginFunctions *ret;
75 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
76 _("Loading `%s' peer plugin\n"),
78 GNUNET_asprintf (&libname,
79 "libgnunet_plugin_peerstore_%s",
81 if (NULL == (ret = GNUNET_PLUGIN_load (libname,
85 "Failed to load plugin `%s'!\n",
87 GNUNET_free (libname);
90 GNUNET_free (libname);
96 test_record (void *cls,
97 const struct GNUNET_PEERSTORE_Record *record,
100 const struct GNUNET_PeerIdentity *id = cls;
101 const char* testval = "test_val";
108 GNUNET_assert (0 == memcmp (&record->peer,
110 sizeof (struct GNUNET_PeerIdentity)));
111 GNUNET_assert (0 == strcmp ("subsys",
112 record->sub_system));
113 GNUNET_assert (0 == strcmp ("key",
115 GNUNET_assert (0 == memcmp (testval,
123 get_record (struct GNUNET_PEERSTORE_PluginFunctions *psp,
124 const struct GNUNET_PeerIdentity *identity)
126 GNUNET_assert (GNUNET_OK ==
127 psp->iterate_records (psp->cls,
137 store_cont (void *cls,
140 GNUNET_assert (GNUNET_OK == status);
147 put_record (struct GNUNET_PEERSTORE_PluginFunctions *psp,
148 const struct GNUNET_PeerIdentity *identity)
150 GNUNET_assert (GNUNET_OK ==
151 psp->store_record (psp->cls,
156 strlen ("test_value"),
157 GNUNET_TIME_absolute_get (),
158 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
168 const struct GNUNET_CONFIGURATION_Handle *cfg)
172 psp = load_plugin (cfg);
177 "Failed to initialize peerstore. Database likely not setup, skipping test.\n");
180 memset (&p1, 1, sizeof (p1));
187 main (int argc, char *argv[])
190 char *const xargv[] = {
191 "test-plugin-peerstore",
196 struct GNUNET_GETOPT_CommandLineOption options[] = {
197 GNUNET_GETOPT_OPTION_END
200 GNUNET_log_setup ("test-plugin-peerstore",
203 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
204 GNUNET_snprintf (cfg_name,
206 "test_plugin_peerstore_%s.conf",
208 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
210 "test-plugin-peerstore",
217 "Missed some testcases: %d\n",
222 /* end of test_plugin_peerstore.c */