aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_namestore_api_zone_iteration_nick.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/test_namestore_api_zone_iteration_nick.c')
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_nick.c146
1 files changed, 41 insertions, 105 deletions
diff --git a/src/namestore/test_namestore_api_zone_iteration_nick.c b/src/namestore/test_namestore_api_zone_iteration_nick.c
index 867f5acae..9df6c98cc 100644
--- a/src/namestore/test_namestore_api_zone_iteration_nick.c
+++ b/src/namestore/test_namestore_api_zone_iteration_nick.c
@@ -37,8 +37,6 @@
37 37
38static struct GNUNET_NAMESTORE_Handle * nsh; 38static struct GNUNET_NAMESTORE_Handle * nsh;
39 39
40static struct GNUNET_SCHEDULER_Task * endbadly_task;
41
42static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey; 40static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey;
43 41
44static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey2; 42static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey2;
@@ -71,7 +69,7 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
71 * @param tc scheduler context 69 * @param tc scheduler context
72 */ 70 */
73static void 71static void
74endbadly (void *cls) 72end (void *cls)
75{ 73{
76 if (NULL != zi) 74 if (NULL != zi)
77 { 75 {
@@ -83,9 +81,9 @@ endbadly (void *cls)
83 GNUNET_NAMESTORE_disconnect (nsh); 81 GNUNET_NAMESTORE_disconnect (nsh);
84 nsh = NULL; 82 nsh = NULL;
85 } 83 }
86 GNUNET_free_non_null(s_name_1); 84 GNUNET_free_non_null (s_name_1);
87 GNUNET_free_non_null(s_name_2); 85 GNUNET_free_non_null (s_name_2);
88 GNUNET_free_non_null(s_name_3); 86 GNUNET_free_non_null (s_name_3);
89 87
90 if (s_rd_1 != NULL) 88 if (s_rd_1 != NULL)
91 { 89 {
@@ -104,99 +102,50 @@ endbadly (void *cls)
104 } 102 }
105 103
106 if (privkey != NULL) 104 if (privkey != NULL)
107 GNUNET_free (privkey);
108 privkey = NULL;
109
110 if (privkey2 != NULL)
111 GNUNET_free (privkey2);
112 privkey2 = NULL;
113 res = 1;
114}
115
116
117static void
118end (void *cls)
119{
120 if (NULL != zi)
121 {
122 GNUNET_NAMESTORE_zone_iteration_stop (zi);
123 zi = NULL;
124 }
125 if (endbadly_task != NULL)
126 { 105 {
127 GNUNET_SCHEDULER_cancel (endbadly_task);
128 endbadly_task = NULL;
129 }
130
131 if (privkey != NULL)
132 GNUNET_free (privkey); 106 GNUNET_free (privkey);
133 privkey = NULL; 107 privkey = NULL;
134
135 if (privkey2 != NULL)
136 GNUNET_free (privkey2);
137 privkey2 = NULL;
138
139 GNUNET_free (s_name_1);
140 GNUNET_free (s_name_2);
141 GNUNET_free (s_name_3);
142 if (s_rd_1 != NULL)
143 {
144 GNUNET_free ((void *)s_rd_1->data);
145 GNUNET_free (s_rd_1);
146 }
147 if (s_rd_2 != NULL)
148 {
149 GNUNET_free ((void *)s_rd_2->data);
150 GNUNET_free (s_rd_2);
151 } 108 }
152 if (s_rd_3 != NULL) 109 if (privkey2 != NULL)
153 { 110 {
154 GNUNET_free ((void *)s_rd_3->data); 111 GNUNET_free (privkey2);
155 GNUNET_free (s_rd_3); 112 privkey2 = NULL;
156 } 113 }
157 if (nsh != NULL)
158 GNUNET_NAMESTORE_disconnect (nsh);
159 nsh = NULL;
160} 114}
161 115
162 116
163static int 117static int
164check_zone_1 (const char *label, unsigned int rd_count, 118check_zone_1 (const char *label, unsigned int rd_count,
165 const struct GNUNET_GNSRECORD_Data *rd) 119 const struct GNUNET_GNSRECORD_Data *rd)
166{ 120{
167 int failed = GNUNET_NO; 121 for (unsigned int c = 0; c< rd_count ; c++)
168 int c;
169 for (c = 0; c< rd_count ; c++)
170 { 122 {
171 if (rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) 123 if ( (rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) &&
172 if (0 != strcmp (rd[c].data, ZONE_NICK_1)) 124 (0 != strcmp (rd[c].data, ZONE_NICK_1)) )
173 { 125 {
174 GNUNET_break (0); 126 GNUNET_break (0);
175 return GNUNET_YES; 127 return GNUNET_YES;
176 } 128 }
177 } 129 }
178 return failed; 130 return GNUNET_NO;
179} 131}
180 132
133
181static int 134static int
182check_zone_2 (const char *label, 135check_zone_2 (const char *label,
183 unsigned int rd_count, 136 unsigned int rd_count,
184 const struct GNUNET_GNSRECORD_Data *rd) 137 const struct GNUNET_GNSRECORD_Data *rd)
185{ 138{
186 int failed = GNUNET_NO; 139 for (unsigned int c = 0; c< rd_count ; c++)
187 int c;
188
189 for (c = 0; c< rd_count ; c++)
190 { 140 {
191 if (rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) 141 if ( (rd[c].record_type == GNUNET_GNSRECORD_TYPE_NICK) &&
192 if (0 != strcmp (rd[c].data, ZONE_NICK_2)) 142 (0 != strcmp (rd[c].data, ZONE_NICK_2)) )
193 { 143 {
194 GNUNET_break (0); 144 GNUNET_break (0);
195 return GNUNET_YES; 145 return GNUNET_YES;
196 } 146 }
197 } 147 }
198 148 return GNUNET_NO;
199 return failed;
200} 149}
201 150
202 151
@@ -208,7 +157,7 @@ zone_proc_end (void *cls)
208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
209 "Received last result, iteration done after receing %u results\n", 158 "Received last result, iteration done after receing %u results\n",
210 returned_records); 159 returned_records);
211 GNUNET_SCHEDULER_add_now (&end, NULL); 160 GNUNET_SCHEDULER_shutdown ();
212} 161}
213 162
214 163
@@ -254,7 +203,7 @@ zone_proc (void *cls,
254 { 203 {
255 GNUNET_break (0); 204 GNUNET_break (0);
256 res = 1; 205 res = 1;
257 GNUNET_SCHEDULER_add_now (&end, NULL); 206 GNUNET_SCHEDULER_shutdown ();
258 } 207 }
259} 208}
260 209
@@ -283,9 +232,7 @@ put_cont (void *cls,
283 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", 232 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n",
284 emsg); 233 emsg);
285 GNUNET_break (0); 234 GNUNET_break (0);
286 if (NULL != endbadly_task) 235 GNUNET_SCHEDULER_shutdown ();
287 GNUNET_SCHEDULER_cancel (endbadly_task);
288 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
289 return; 236 return;
290 } 237 }
291 238
@@ -306,9 +253,7 @@ put_cont (void *cls,
306 { 253 {
307 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); 254 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n");
308 GNUNET_break (0); 255 GNUNET_break (0);
309 if (NULL != endbadly_task) 256 GNUNET_SCHEDULER_shutdown ();
310 GNUNET_SCHEDULER_cancel (endbadly_task);
311 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
312 return; 257 return;
313 } 258 }
314 } 259 }
@@ -406,9 +351,7 @@ empty_zone_proc (void *cls,
406 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 351 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
407 _("Expected empty zone but received zone private key\n")); 352 _("Expected empty zone but received zone private key\n"));
408 GNUNET_break (0); 353 GNUNET_break (0);
409 if (endbadly_task != NULL) 354 GNUNET_SCHEDULER_shutdown ();
410 GNUNET_SCHEDULER_cancel (endbadly_task);
411 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
412 return; 355 return;
413 } 356 }
414 if ((NULL != label) || (NULL != rd) || (0 != rd_count)) 357 if ((NULL != label) || (NULL != rd) || (0 != rd_count))
@@ -416,9 +359,7 @@ empty_zone_proc (void *cls,
416 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
417 _("Expected no zone content but received data\n")); 360 _("Expected no zone content but received data\n"));
418 GNUNET_break (0); 361 GNUNET_break (0);
419 if (endbadly_task != NULL) 362 GNUNET_SCHEDULER_shutdown ();
420 GNUNET_SCHEDULER_cancel (endbadly_task);
421 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
422 return; 363 return;
423 } 364 }
424 GNUNET_assert (0); 365 GNUNET_assert (0);
@@ -454,12 +395,10 @@ run (void *cls,
454 const struct GNUNET_CONFIGURATION_Handle *cfg, 395 const struct GNUNET_CONFIGURATION_Handle *cfg,
455 struct GNUNET_TESTING_Peer *peer) 396 struct GNUNET_TESTING_Peer *peer)
456{ 397{
457 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
458 &endbadly,
459 NULL);
460 nsh = GNUNET_NAMESTORE_connect (cfg); 398 nsh = GNUNET_NAMESTORE_connect (cfg);
461 GNUNET_break (NULL != nsh); 399 GNUNET_break (NULL != nsh);
462 400 GNUNET_SCHEDULER_add_shutdown (&end,
401 NULL);
463 /* first, iterate over empty namestore */ 402 /* first, iterate over empty namestore */
464 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, 403 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
465 NULL, 404 NULL,
@@ -474,25 +413,22 @@ run (void *cls,
474 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 413 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
475 "Failed to create zone iterator\n"); 414 "Failed to create zone iterator\n");
476 GNUNET_break (0); 415 GNUNET_break (0);
477 GNUNET_SCHEDULER_cancel (endbadly_task); 416 GNUNET_SCHEDULER_shutdown ();
478 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
479 } 417 }
480} 418}
481 419
482 420
421#include "test_common.c"
422
423
483int 424int
484main (int argc, char *argv[]) 425main (int argc, char *argv[])
485{ 426{
486 const char *plugin_name; 427 const char *plugin_name;
487 char *cfg_name; 428 char *cfg_name;
488 429
489 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 430 SETUP_CFG (plugin_name, cfg_name);
490 GNUNET_asprintf (&cfg_name,
491 "test_namestore_api_%s.conf",
492 plugin_name);
493 res = 1; 431 res = 1;
494 GNUNET_DISK_purge_cfg_dir (cfg_name,
495 "GNUNET_TEST_HOME");
496 if (0 != 432 if (0 !=
497 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-nick", 433 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-nick",
498 cfg_name, 434 cfg_name,