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 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_namestore_plugin.h"
28 #include "gnunet_testing_lib.h"
29 #include "gnunet_dnsparser_lib.h"
31 #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
36 * Name of plugin under test.
38 static const char *plugin_name;
42 * Function called when the service shuts down. Unloads our namestore
45 * @param api api to unload
48 unload_plugin (struct GNUNET_NAMESTORE_PluginFunctions *api)
52 GNUNET_asprintf (&libname,
53 "libgnunet_plugin_namestore_%s",
56 GNUNET_PLUGIN_unload (libname,
58 GNUNET_free (libname);
63 * Load the namestore plugin.
65 * @param cfg configuration to pass
66 * @return NULL on error
68 static struct GNUNET_NAMESTORE_PluginFunctions *
69 load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
71 struct GNUNET_NAMESTORE_PluginFunctions *ret;
74 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
75 _("Loading `%s' namestore plugin\n"),
77 GNUNET_asprintf (&libname,
78 "libgnunet_plugin_namestore_%s",
80 if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void*) cfg)))
83 "Failed to load plugin `%s'!\n",
85 GNUNET_free (libname);
88 GNUNET_free (libname);
94 test_record (void *cls,
96 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key,
98 unsigned int rd_count,
99 const struct GNUNET_GNSRECORD_Data *rd)
103 struct GNUNET_CRYPTO_EcdsaPrivateKey tzone_private_key;
105 unsigned int trd_count = 1 + (id % 1024);
107 GNUNET_snprintf (tname,
111 for (unsigned int i=0;i<trd_count;i++)
113 GNUNET_assert (rd[i].data_size == id % 10);
114 GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10));
115 GNUNET_assert (rd[i].record_type == TEST_RECORD_TYPE);
116 GNUNET_assert (rd[i].flags == 0);
118 memset (&tzone_private_key,
120 sizeof (tzone_private_key));
121 GNUNET_assert (0 == strcmp (label, tname));
122 GNUNET_assert (0 == memcmp (&tzone_private_key,
124 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)));
129 get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp,
132 GNUNET_assert (GNUNET_OK ==
133 nsp->iterate_records (nsp->cls,
143 put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp,
146 struct GNUNET_CRYPTO_EcdsaPrivateKey zone_private_key;
148 unsigned int rd_count = 1 + (id % 1024);
149 struct GNUNET_GNSRECORD_Data rd[rd_count];
150 struct GNUNET_CRYPTO_EcdsaSignature signature;
152 GNUNET_snprintf (label, sizeof (label),
153 "a%u", (unsigned int ) id);
154 for (unsigned int i=0;i<rd_count;i++)
156 rd[i].data = "Hello World";
157 rd[i].data_size = id % 10;
158 rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES).abs_value_us;
159 rd[i].record_type = TEST_RECORD_TYPE;
162 memset (&zone_private_key, (id % 241), sizeof (zone_private_key));
163 memset (&signature, (id % 243), sizeof (signature));
164 GNUNET_assert (GNUNET_OK ==
165 nsp->store_records (nsp->cls,
177 const struct GNUNET_CONFIGURATION_Handle *cfg)
179 struct GNUNET_NAMESTORE_PluginFunctions *nsp;
182 nsp = load_plugin (cfg);
187 "Failed to initialize namestore. Database likely not setup, skipping test.\n");
202 char *const xargv[] = {
203 "test-plugin-namestore",
208 struct GNUNET_GETOPT_CommandLineOption options[] = {
209 GNUNET_GETOPT_OPTION_END
212 GNUNET_log_setup ("test-plugin-namestore",
215 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
216 GNUNET_snprintf (cfg_name,
218 "test_plugin_namestore_%s.conf",
220 GNUNET_DISK_purge_cfg_dir (cfg_name,
222 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
224 "test-plugin-namestore",
229 GNUNET_DISK_purge_cfg_dir (cfg_name,
233 "Missed some testcases: %d\n",
238 /* end of test_plugin_namestore.c */