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.
16 * @file namestore/test_plugin_namestore.c
17 * @brief Test for the namestore plugins
18 * @author Christian Grothoff
21 #include "gnunet_util_lib.h"
22 #include "gnunet_namestore_plugin.h"
23 #include "gnunet_testing_lib.h"
24 #include "gnunet_dnsparser_lib.h"
26 #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
31 * Name of plugin under test.
33 static const char *plugin_name;
37 * Function called when the service shuts down. Unloads our namestore
40 * @param api api to unload
43 unload_plugin (struct GNUNET_NAMESTORE_PluginFunctions *api)
47 GNUNET_asprintf (&libname,
48 "libgnunet_plugin_namestore_%s",
51 GNUNET_PLUGIN_unload (libname,
53 GNUNET_free (libname);
58 * Load the namestore plugin.
60 * @param cfg configuration to pass
61 * @return NULL on error
63 static struct GNUNET_NAMESTORE_PluginFunctions *
64 load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
66 struct GNUNET_NAMESTORE_PluginFunctions *ret;
69 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
70 _("Loading `%s' namestore plugin\n"),
72 GNUNET_asprintf (&libname,
73 "libgnunet_plugin_namestore_%s",
75 if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void*) cfg)))
78 "Failed to load plugin `%s'!\n",
80 GNUNET_free (libname);
83 GNUNET_free (libname);
89 test_record (void *cls,
91 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key,
93 unsigned int rd_count,
94 const struct GNUNET_GNSRECORD_Data *rd)
98 struct GNUNET_CRYPTO_EcdsaPrivateKey tzone_private_key;
100 unsigned int trd_count = 1 + (id % 1024);
102 GNUNET_snprintf (tname,
106 for (unsigned int i=0;i<trd_count;i++)
108 GNUNET_assert (rd[i].data_size == id % 10);
109 GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10));
110 GNUNET_assert (rd[i].record_type == TEST_RECORD_TYPE);
111 GNUNET_assert (rd[i].flags == 0);
113 memset (&tzone_private_key,
115 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 = TEST_RECORD_TYPE;
157 memset (&zone_private_key, (id % 241), sizeof (zone_private_key));
158 memset (&signature, (id % 243), sizeof (signature));
159 GNUNET_assert (GNUNET_OK ==
160 nsp->store_records (nsp->cls,
172 const struct GNUNET_CONFIGURATION_Handle *cfg)
174 struct GNUNET_NAMESTORE_PluginFunctions *nsp;
177 nsp = load_plugin (cfg);
182 "Failed to initialize namestore. Database likely not setup, skipping test.\n");
197 char *const xargv[] = {
198 "test-plugin-namestore",
203 struct GNUNET_GETOPT_CommandLineOption options[] = {
204 GNUNET_GETOPT_OPTION_END
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_DISK_purge_cfg_dir (cfg_name,
217 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
219 "test-plugin-namestore",
224 GNUNET_DISK_purge_cfg_dir (cfg_name,
228 "Missed some testcases: %d\n",
233 /* end of test_plugin_namestore.c */