aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_plugin_namestore.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/test_plugin_namestore.c')
-rw-r--r--src/namestore/test_plugin_namestore.c176
1 files changed, 88 insertions, 88 deletions
diff --git a/src/namestore/test_plugin_namestore.c b/src/namestore/test_plugin_namestore.c
index b4ed4c70d..8fb30b651 100644
--- a/src/namestore/test_plugin_namestore.c
+++ b/src/namestore/test_plugin_namestore.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/* 20/*
21 * @file namestore/test_plugin_namestore.c 21 * @file namestore/test_plugin_namestore.c
22 * @brief Test for the namestore plugins 22 * @brief Test for the namestore plugins
@@ -45,13 +45,13 @@ static const char *plugin_name;
45 * @param api api to unload 45 * @param api api to unload
46 */ 46 */
47static void 47static void
48unload_plugin (struct GNUNET_NAMESTORE_PluginFunctions *api) 48unload_plugin(struct GNUNET_NAMESTORE_PluginFunctions *api)
49{ 49{
50 char *libname; 50 char *libname;
51 51
52 GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name); 52 GNUNET_asprintf(&libname, "libgnunet_plugin_namestore_%s", plugin_name);
53 GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api)); 53 GNUNET_break(NULL == GNUNET_PLUGIN_unload(libname, api));
54 GNUNET_free (libname); 54 GNUNET_free(libname);
55} 55}
56 56
57 57
@@ -62,33 +62,33 @@ unload_plugin (struct GNUNET_NAMESTORE_PluginFunctions *api)
62 * @return NULL on error 62 * @return NULL on error
63 */ 63 */
64static struct GNUNET_NAMESTORE_PluginFunctions * 64static struct GNUNET_NAMESTORE_PluginFunctions *
65load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) 65load_plugin(const struct GNUNET_CONFIGURATION_Handle *cfg)
66{ 66{
67 struct GNUNET_NAMESTORE_PluginFunctions *ret; 67 struct GNUNET_NAMESTORE_PluginFunctions *ret;
68 char *libname; 68 char *libname;
69 69
70 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 70 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
71 _ ("Loading `%s' namestore plugin\n"), 71 _("Loading `%s' namestore plugin\n"),
72 plugin_name); 72 plugin_name);
73 GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name); 73 GNUNET_asprintf(&libname, "libgnunet_plugin_namestore_%s", plugin_name);
74 if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void *) cfg))) 74 if (NULL == (ret = GNUNET_PLUGIN_load(libname, (void *)cfg)))
75 { 75 {
76 fprintf (stderr, "Failed to load plugin `%s'!\n", plugin_name); 76 fprintf(stderr, "Failed to load plugin `%s'!\n", plugin_name);
77 GNUNET_free (libname); 77 GNUNET_free(libname);
78 return NULL; 78 return NULL;
79 } 79 }
80 GNUNET_free (libname); 80 GNUNET_free(libname);
81 return ret; 81 return ret;
82} 82}
83 83
84 84
85static void 85static void
86test_record (void *cls, 86test_record(void *cls,
87 uint64_t seq, 87 uint64_t seq,
88 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, 88 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key,
89 const char *label, 89 const char *label,
90 unsigned int rd_count, 90 unsigned int rd_count,
91 const struct GNUNET_GNSRECORD_Data *rd) 91 const struct GNUNET_GNSRECORD_Data *rd)
92{ 92{
93 int *idp = cls; 93 int *idp = cls;
94 int id = *idp; 94 int id = *idp;
@@ -96,106 +96,106 @@ test_record (void *cls,
96 char tname[64]; 96 char tname[64];
97 unsigned int trd_count = 1 + (id % 1024); 97 unsigned int trd_count = 1 + (id % 1024);
98 98
99 GNUNET_snprintf (tname, sizeof (tname), "a%u", (unsigned int) id); 99 GNUNET_snprintf(tname, sizeof(tname), "a%u", (unsigned int)id);
100 GNUNET_assert (trd_count == rd_count); 100 GNUNET_assert(trd_count == rd_count);
101 for (unsigned int i = 0; i < trd_count; i++) 101 for (unsigned int i = 0; i < trd_count; i++)
102 { 102 {
103 GNUNET_assert (rd[i].data_size == id % 10); 103 GNUNET_assert(rd[i].data_size == id % 10);
104 GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10)); 104 GNUNET_assert(0 == memcmp("Hello World", rd[i].data, id % 10));
105 GNUNET_assert (rd[i].record_type == TEST_RECORD_TYPE); 105 GNUNET_assert(rd[i].record_type == TEST_RECORD_TYPE);
106 GNUNET_assert (rd[i].flags == 0); 106 GNUNET_assert(rd[i].flags == 0);
107 } 107 }
108 memset (&tzone_private_key, (id % 241), sizeof (tzone_private_key)); 108 memset(&tzone_private_key, (id % 241), sizeof(tzone_private_key));
109 GNUNET_assert (0 == strcmp (label, tname)); 109 GNUNET_assert(0 == strcmp(label, tname));
110 GNUNET_assert (0 == GNUNET_memcmp (&tzone_private_key, private_key)); 110 GNUNET_assert(0 == GNUNET_memcmp(&tzone_private_key, private_key));
111} 111}
112 112
113 113
114static void 114static void
115get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) 115get_record(struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
116{ 116{
117 GNUNET_assert ( 117 GNUNET_assert(
118 GNUNET_OK == 118 GNUNET_OK ==
119 nsp->iterate_records (nsp->cls, NULL, 0, 1, &test_record, &id)); 119 nsp->iterate_records(nsp->cls, NULL, 0, 1, &test_record, &id));
120} 120}
121 121
122 122
123static void 123static void
124put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) 124put_record(struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
125{ 125{
126 struct GNUNET_CRYPTO_EcdsaPrivateKey zone_private_key; 126 struct GNUNET_CRYPTO_EcdsaPrivateKey zone_private_key;
127 char label[64]; 127 char label[64];
128 unsigned int rd_count = 1 + (id % 1024); 128 unsigned int rd_count = 1 + (id % 1024);
129 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)]; 129 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
130 struct GNUNET_CRYPTO_EcdsaSignature signature; 130 struct GNUNET_CRYPTO_EcdsaSignature signature;
131 131
132 GNUNET_snprintf (label, sizeof (label), "a%u", (unsigned int) id); 132 GNUNET_snprintf(label, sizeof(label), "a%u", (unsigned int)id);
133 for (unsigned int i = 0; i < rd_count; i++) 133 for (unsigned int i = 0; i < rd_count; i++)
134 { 134 {
135 rd[i].data = "Hello World"; 135 rd[i].data = "Hello World";
136 rd[i].data_size = id % 10; 136 rd[i].data_size = id % 10;
137 rd[i].expiration_time = 137 rd[i].expiration_time =
138 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES).abs_value_us; 138 GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES).abs_value_us;
139 rd[i].record_type = TEST_RECORD_TYPE; 139 rd[i].record_type = TEST_RECORD_TYPE;
140 rd[i].flags = 0; 140 rd[i].flags = 0;
141 } 141 }
142 memset (&zone_private_key, (id % 241), sizeof (zone_private_key)); 142 memset(&zone_private_key, (id % 241), sizeof(zone_private_key));
143 memset (&signature, (id % 243), sizeof (signature)); 143 memset(&signature, (id % 243), sizeof(signature));
144 GNUNET_assert ( 144 GNUNET_assert(
145 GNUNET_OK == 145 GNUNET_OK ==
146 nsp->store_records (nsp->cls, &zone_private_key, label, rd_count, rd)); 146 nsp->store_records(nsp->cls, &zone_private_key, label, rd_count, rd));
147} 147}
148 148
149 149
150static void 150static void
151run (void *cls, 151run(void *cls,
152 char *const *args, 152 char *const *args,
153 const char *cfgfile, 153 const char *cfgfile,
154 const struct GNUNET_CONFIGURATION_Handle *cfg) 154 const struct GNUNET_CONFIGURATION_Handle *cfg)
155{ 155{
156 struct GNUNET_NAMESTORE_PluginFunctions *nsp; 156 struct GNUNET_NAMESTORE_PluginFunctions *nsp;
157 157
158 ok = 0; 158 ok = 0;
159 nsp = load_plugin (cfg); 159 nsp = load_plugin(cfg);
160 if (NULL == nsp) 160 if (NULL == nsp)
161 { 161 {
162 fprintf ( 162 fprintf(
163 stderr, 163 stderr,
164 "%s", 164 "%s",
165 "Failed to initialize namestore. Database likely not setup, skipping test.\n"); 165 "Failed to initialize namestore. Database likely not setup, skipping test.\n");
166 return; 166 return;
167 } 167 }
168 put_record (nsp, 1); 168 put_record(nsp, 1);
169 get_record (nsp, 1); 169 get_record(nsp, 1);
170 170
171 unload_plugin (nsp); 171 unload_plugin(nsp);
172} 172}
173 173
174 174
175int 175int
176main (int argc, char *argv[]) 176main(int argc, char *argv[])
177{ 177{
178 char cfg_name[PATH_MAX]; 178 char cfg_name[PATH_MAX];
179 char *const xargv[] = {"test-plugin-namestore", "-c", cfg_name, NULL}; 179 char *const xargv[] = { "test-plugin-namestore", "-c", cfg_name, NULL };
180 struct GNUNET_GETOPT_CommandLineOption options[] = {GNUNET_GETOPT_OPTION_END}; 180 struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END };
181 181
182 GNUNET_log_setup ("test-plugin-namestore", "WARNING", NULL); 182 GNUNET_log_setup("test-plugin-namestore", "WARNING", NULL);
183 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 183 plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]);
184 GNUNET_snprintf (cfg_name, 184 GNUNET_snprintf(cfg_name,
185 sizeof (cfg_name), 185 sizeof(cfg_name),
186 "test_plugin_namestore_%s.conf", 186 "test_plugin_namestore_%s.conf",
187 plugin_name); 187 plugin_name);
188 GNUNET_DISK_purge_cfg_dir (cfg_name, "GNUNET_TMP"); 188 GNUNET_DISK_purge_cfg_dir(cfg_name, "GNUNET_TMP");
189 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, 189 GNUNET_PROGRAM_run((sizeof(xargv) / sizeof(char *)) - 1,
190 xargv, 190 xargv,
191 "test-plugin-namestore", 191 "test-plugin-namestore",
192 "nohelp", 192 "nohelp",
193 options, 193 options,
194 &run, 194 &run,
195 NULL); 195 NULL);
196 GNUNET_DISK_purge_cfg_dir (cfg_name, "GNUNET_TMP"); 196 GNUNET_DISK_purge_cfg_dir(cfg_name, "GNUNET_TMP");
197 if (ok != 0) 197 if (ok != 0)
198 fprintf (stderr, "Missed some testcases: %d\n", ok); 198 fprintf(stderr, "Missed some testcases: %d\n", ok);
199 return ok; 199 return ok;
200} 200}
201 201