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
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_namestore_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 namestore
43 * @param api api to unload
46 unload_plugin (struct GNUNET_NAMESTORE_PluginFunctions *api)
50 GNUNET_asprintf (&libname,
51 "libgnunet_plugin_namestore_%s",
54 GNUNET_PLUGIN_unload (libname,
56 GNUNET_free (libname);
61 * Load the namestore plugin.
63 * @param cfg configuration to pass
64 * @return NULL on error
66 static struct GNUNET_NAMESTORE_PluginFunctions *
67 load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
69 struct GNUNET_NAMESTORE_PluginFunctions *ret;
72 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
73 _("Loading `%s' namestore plugin\n"),
75 GNUNET_asprintf (&libname,
76 "libgnunet_plugin_namestore_%s",
78 if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void*) cfg)))
81 "Failed to load plugin `%s'!\n",
83 GNUNET_free (libname);
86 GNUNET_free (libname);
92 test_record (void *cls,
94 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key,
96 unsigned int rd_count,
97 const struct GNUNET_GNSRECORD_Data *rd)
101 struct GNUNET_CRYPTO_EcdsaPrivateKey tzone_private_key;
103 unsigned int trd_count = 1 + (id % 1024);
105 GNUNET_snprintf (tname,
109 for (unsigned int i=0;i<trd_count;i++)
111 GNUNET_assert (rd[i].data_size == id % 10);
112 GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10));
113 GNUNET_assert (rd[i].record_type == 1 + (id % 13));
114 GNUNET_assert (rd[i].flags == 0);
116 memset (&tzone_private_key,
118 sizeof (tzone_private_key));
119 GNUNET_assert (0 == strcmp (label, tname));
120 GNUNET_assert (0 == memcmp (&tzone_private_key,
122 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)));
127 get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp,
130 GNUNET_assert (GNUNET_OK ==
131 nsp->iterate_records (nsp->cls,
141 put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp,
144 struct GNUNET_CRYPTO_EcdsaPrivateKey zone_private_key;
146 unsigned int rd_count = 1 + (id % 1024);
147 struct GNUNET_GNSRECORD_Data rd[rd_count];
148 struct GNUNET_CRYPTO_EcdsaSignature signature;
150 GNUNET_snprintf (label, sizeof (label),
151 "a%u", (unsigned int ) id);
152 for (unsigned int i=0;i<rd_count;i++)
154 rd[i].data = "Hello World";
155 rd[i].data_size = id % 10;
156 rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES).abs_value_us;
157 rd[i].record_type = 1 + (id % 13);
160 memset (&zone_private_key, (id % 241), sizeof (zone_private_key));
161 memset (&signature, (id % 243), sizeof (signature));
162 GNUNET_assert (GNUNET_OK ==
163 nsp->store_records (nsp->cls,
175 const struct GNUNET_CONFIGURATION_Handle *cfg)
177 struct GNUNET_NAMESTORE_PluginFunctions *nsp;
180 nsp = load_plugin (cfg);
185 "Failed to initialize namestore. Database likely not setup, skipping test.\n");
200 char *const xargv[] = {
201 "test-plugin-namestore",
206 struct GNUNET_GETOPT_CommandLineOption options[] = {
207 GNUNET_GETOPT_OPTION_END
210 GNUNET_log_setup ("test-plugin-namestore",
213 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
214 GNUNET_snprintf (cfg_name,
216 "test_plugin_namestore_%s.conf",
218 GNUNET_DISK_purge_cfg_dir (cfg_name,
220 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
222 "test-plugin-namestore",
227 GNUNET_DISK_purge_cfg_dir (cfg_name,
231 "Missed some testcases: %d\n",
236 /* end of test_plugin_namestore.c */