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,
93 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key,
95 unsigned int rd_count,
96 const struct GNUNET_GNSRECORD_Data *rd)
100 struct GNUNET_CRYPTO_EcdsaPrivateKey tzone_private_key;
102 unsigned int trd_count = 1 + (id % 1024);
104 GNUNET_snprintf (tname,
108 for (unsigned int i=0;i<trd_count;i++)
110 GNUNET_assert (rd[i].data_size == id % 10);
111 GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10));
112 GNUNET_assert (rd[i].record_type == 1 + (id % 13));
113 GNUNET_assert (rd[i].flags == 0);
115 memset (&tzone_private_key, (id % 241), sizeof (tzone_private_key));
116 GNUNET_assert (0 == strcmp (label, tname));
117 GNUNET_assert (0 == memcmp (&tzone_private_key,
119 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)));
124 get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp,
127 GNUNET_assert (GNUNET_OK ==
128 nsp->iterate_records (nsp->cls,
138 put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp,
141 struct GNUNET_CRYPTO_EcdsaPrivateKey zone_private_key;
143 unsigned int rd_count = 1 + (id % 1024);
144 struct GNUNET_GNSRECORD_Data rd[rd_count];
145 struct GNUNET_CRYPTO_EcdsaSignature signature;
147 GNUNET_snprintf (label, sizeof (label),
148 "a%u", (unsigned int ) id);
149 for (unsigned int i=0;i<rd_count;i++)
151 rd[i].data = "Hello World";
152 rd[i].data_size = id % 10;
153 rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES).abs_value_us;
154 rd[i].record_type = 1 + (id % 13);
157 memset (&zone_private_key, (id % 241), sizeof (zone_private_key));
158 memset (&signature, (id % 243), sizeof (signature));
159 GNUNET_assert (GNUNET_OK == nsp->store_records (nsp->cls,
171 const struct GNUNET_CONFIGURATION_Handle *cfg)
173 struct GNUNET_NAMESTORE_PluginFunctions *nsp;
176 nsp = load_plugin (cfg);
181 "Failed to initialize namestore. Database likely not setup, skipping test.\n");
196 char *const xargv[] = {
197 "test-plugin-namestore",
202 struct GNUNET_GETOPT_CommandLineOption options[] = {
203 GNUNET_GETOPT_OPTION_END
206 //GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namestore-sqlite");
207 GNUNET_log_setup ("test-plugin-namestore",
210 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
211 GNUNET_snprintf (cfg_name,
213 "test_plugin_namestore_%s.conf",
215 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
217 "test-plugin-namestore",
224 "Missed some testcases: %d\n",
226 //GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namestore-sqlite");
230 /* end of test_plugin_namestore.c */