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
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @file namestore/test_plugin_namestore.c
22 * @brief Test for the namestore plugins
23 * @author Christian Grothoff
26 #include "gnunet_util_lib.h"
27 #include "gnunet_peerstore_plugin.h"
28 #include "gnunet_testing_lib.h"
34 * Name of plugin under test.
36 static const char *plugin_name;
39 static struct GNUNET_PEERSTORE_PluginFunctions *psp;
41 static struct GNUNET_PeerIdentity p1;
45 * Function called when the service shuts down. Unloads our namestore
48 * @param api api to unload
51 unload_plugin (struct GNUNET_PEERSTORE_PluginFunctions *api)
55 GNUNET_asprintf (&libname,
56 "libgnunet_plugin_peer_%s",
59 GNUNET_PLUGIN_unload (libname,
61 GNUNET_free (libname);
66 * Load the namestore plugin.
68 * @param cfg configuration to pass
69 * @return NULL on error
71 static struct GNUNET_PEERSTORE_PluginFunctions *
72 load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
74 struct GNUNET_PEERSTORE_PluginFunctions *ret;
77 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
78 _("Loading `%s' peer plugin\n"),
80 GNUNET_asprintf (&libname,
81 "libgnunet_plugin_peerstore_%s",
83 if (NULL == (ret = GNUNET_PLUGIN_load (libname,
87 "Failed to load plugin `%s'!\n",
89 GNUNET_free (libname);
92 GNUNET_free (libname);
98 test_record (void *cls,
99 const struct GNUNET_PEERSTORE_Record *record,
102 const struct GNUNET_PeerIdentity *id = cls;
103 const char* testval = "test_val";
110 GNUNET_assert (0 == memcmp (&record->peer,
112 sizeof (struct GNUNET_PeerIdentity)));
113 GNUNET_assert (0 == strcmp ("subsys",
114 record->sub_system));
115 GNUNET_assert (0 == strcmp ("key",
117 GNUNET_assert (0 == memcmp (testval,
125 get_record (struct GNUNET_PEERSTORE_PluginFunctions *psp,
126 const struct GNUNET_PeerIdentity *identity)
128 GNUNET_assert (GNUNET_OK ==
129 psp->iterate_records (psp->cls,
139 store_cont (void *cls,
142 GNUNET_assert (GNUNET_OK == status);
149 put_record (struct GNUNET_PEERSTORE_PluginFunctions *psp,
150 const struct GNUNET_PeerIdentity *identity)
152 GNUNET_assert (GNUNET_OK ==
153 psp->store_record (psp->cls,
158 strlen ("test_value"),
159 GNUNET_TIME_absolute_get (),
160 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
170 const struct GNUNET_CONFIGURATION_Handle *cfg)
174 psp = load_plugin (cfg);
179 "Failed to initialize peerstore. Database likely not setup, skipping test.\n");
182 memset (&p1, 1, sizeof (p1));
189 main (int argc, char *argv[])
192 char *const xargv[] = {
193 "test-plugin-peerstore",
198 struct GNUNET_GETOPT_CommandLineOption options[] = {
199 GNUNET_GETOPT_OPTION_END
202 GNUNET_log_setup ("test-plugin-peerstore",
205 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
206 GNUNET_snprintf (cfg_name,
208 "test_plugin_peerstore_%s.conf",
210 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
212 "test-plugin-peerstore",
219 "Missed some testcases: %d\n",
224 /* end of test_plugin_peerstore.c */