aboutsummaryrefslogtreecommitdiff
path: root/src/set
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-06-04 14:07:27 +0200
committerChristian Grothoff <christian@grothoff.org>2019-06-04 14:07:38 +0200
commitb544508d067006323c6f51d84adfaf8adbcd4ee8 (patch)
treedb8125bb9b026c9c97440ad4cf8fdd9e4e4c0c9a /src/set
parentccb1a77bc02fcd60278127da864ca325acc1fa7c (diff)
downloadgnunet-b544508d067006323c6f51d84adfaf8adbcd4ee8.tar.gz
gnunet-b544508d067006323c6f51d84adfaf8adbcd4ee8.zip
check return value
Diffstat (limited to 'src/set')
-rw-r--r--src/set/test_set_api.c149
1 files changed, 52 insertions, 97 deletions
diff --git a/src/set/test_set_api.c b/src/set/test_set_api.c
index 7fd69a752..0f2b20a01 100644
--- a/src/set/test_set_api.c
+++ b/src/set/test_set_api.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
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
@@ -61,14 +61,12 @@ result_cb_set1 (void *cls,
61 switch (status) 61 switch (status)
62 { 62 {
63 case GNUNET_SET_STATUS_OK: 63 case GNUNET_SET_STATUS_OK:
64 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 64 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 1: got element\n");
65 "set 1: got element\n");
66 break; 65 break;
67 case GNUNET_SET_STATUS_FAILURE: 66 case GNUNET_SET_STATUS_FAILURE:
68 GNUNET_break (0); 67 GNUNET_break (0);
69 oh1 = NULL; 68 oh1 = NULL;
70 fprintf (stderr, 69 fprintf (stderr, "set 1: received failure status!\n");
71 "set 1: received failure status!\n");
72 ret = 1; 70 ret = 1;
73 if (NULL != tt) 71 if (NULL != tt)
74 { 72 {
@@ -78,8 +76,7 @@ result_cb_set1 (void *cls,
78 GNUNET_SCHEDULER_shutdown (); 76 GNUNET_SCHEDULER_shutdown ();
79 break; 77 break;
80 case GNUNET_SET_STATUS_DONE: 78 case GNUNET_SET_STATUS_DONE:
81 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 79 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 1: done\n");
82 "set 1: done\n");
83 oh1 = NULL; 80 oh1 = NULL;
84 if (NULL != set1) 81 if (NULL != set1)
85 { 82 {
@@ -108,21 +105,18 @@ result_cb_set2 (void *cls,
108 switch (status) 105 switch (status)
109 { 106 {
110 case GNUNET_SET_STATUS_OK: 107 case GNUNET_SET_STATUS_OK:
111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 2: got element\n");
112 "set 2: got element\n");
113 break; 109 break;
114 case GNUNET_SET_STATUS_FAILURE: 110 case GNUNET_SET_STATUS_FAILURE:
115 GNUNET_break (0); 111 GNUNET_break (0);
116 oh2 = NULL; 112 oh2 = NULL;
117 fprintf (stderr, 113 fprintf (stderr, "set 2: received failure status\n");
118 "set 2: received failure status\n");
119 GNUNET_SCHEDULER_shutdown (); 114 GNUNET_SCHEDULER_shutdown ();
120 ret = 1; 115 ret = 1;
121 break; 116 break;
122 case GNUNET_SET_STATUS_DONE: 117 case GNUNET_SET_STATUS_DONE:
123 oh2 = NULL; 118 oh2 = NULL;
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "set 2: done\n");
125 "set 2: done\n");
126 GNUNET_SET_destroy (set2); 120 GNUNET_SET_destroy (set2);
127 set2 = NULL; 121 set2 = NULL;
128 if (NULL == set1) 122 if (NULL == set1)
@@ -146,15 +140,13 @@ listen_cb (void *cls,
146{ 140{
147 GNUNET_assert (NULL != context_msg); 141 GNUNET_assert (NULL != context_msg);
148 GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY); 142 GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_DUMMY);
149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "listen cb called\n");
150 "listen cb called\n");
151 oh2 = GNUNET_SET_accept (request, 144 oh2 = GNUNET_SET_accept (request,
152 GNUNET_SET_RESULT_ADDED, 145 GNUNET_SET_RESULT_ADDED,
153 (struct GNUNET_SET_Option[]) { 0 }, 146 (struct GNUNET_SET_Option[]){0},
154 &result_cb_set2, 147 &result_cb_set2,
155 NULL); 148 NULL);
156 GNUNET_SET_commit (oh2, 149 GNUNET_SET_commit (oh2, set2);
157 set2);
158} 150}
159 151
160 152
@@ -168,8 +160,7 @@ start (void *cls)
168{ 160{
169 struct GNUNET_MessageHeader context_msg; 161 struct GNUNET_MessageHeader context_msg;
170 162
171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting reconciliation\n");
172 "Starting reconciliation\n");
173 context_msg.size = htons (sizeof context_msg); 164 context_msg.size = htons (sizeof context_msg);
174 context_msg.type = htons (GNUNET_MESSAGE_TYPE_DUMMY); 165 context_msg.type = htons (GNUNET_MESSAGE_TYPE_DUMMY);
175 listen_handle = GNUNET_SET_listen (config, 166 listen_handle = GNUNET_SET_listen (config,
@@ -181,11 +172,10 @@ start (void *cls)
181 &app_id, 172 &app_id,
182 &context_msg, 173 &context_msg,
183 GNUNET_SET_RESULT_ADDED, 174 GNUNET_SET_RESULT_ADDED,
184 (struct GNUNET_SET_Option[]) { 0 }, 175 (struct GNUNET_SET_Option[]){0},
185 &result_cb_set1, 176 &result_cb_set1,
186 NULL); 177 NULL);
187 GNUNET_SET_commit (oh1, 178 GNUNET_SET_commit (oh1, set1);
188 set1);
189} 179}
190 180
191 181
@@ -199,25 +189,18 @@ init_set2 (void *cls)
199{ 189{
200 struct GNUNET_SET_Element element; 190 struct GNUNET_SET_Element element;
201 191
202 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 192 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initializing set 2\n");
203 "initializing set 2\n");
204 193
205 element.element_type = 0; 194 element.element_type = 0;
206 element.data = "hello"; 195 element.data = "hello";
207 element.size = strlen(element.data); 196 element.size = strlen (element.data);
208 GNUNET_SET_add_element (set2, 197 GNUNET_SET_add_element (set2, &element, NULL, NULL);
209 &element,
210 NULL, NULL);
211 element.data = "quux"; 198 element.data = "quux";
212 element.size = strlen(element.data); 199 element.size = strlen (element.data);
213 GNUNET_SET_add_element (set2, 200 GNUNET_SET_add_element (set2, &element, NULL, NULL);
214 &element,
215 NULL, NULL);
216 element.data = "baz"; 201 element.data = "baz";
217 element.size = strlen(element.data); 202 element.size = strlen (element.data);
218 GNUNET_SET_add_element (set2, 203 GNUNET_SET_add_element (set2, &element, &start, NULL);
219 &element,
220 &start, NULL);
221} 204}
222 205
223 206
@@ -231,24 +214,17 @@ init_set1 (void)
231 214
232 element.element_type = 0; 215 element.element_type = 0;
233 element.data = "hello"; 216 element.data = "hello";
234 element.size = strlen(element.data); 217 element.size = strlen (element.data);
235 GNUNET_SET_add_element (set1, 218 GNUNET_SET_add_element (set1, &element, NULL, NULL);
236 &element,
237 NULL, NULL);
238 element.data = "bar"; 219 element.data = "bar";
239 element.size = strlen(element.data); 220 element.size = strlen (element.data);
240 GNUNET_SET_add_element (set1, 221 GNUNET_SET_add_element (set1, &element, &init_set2, NULL);
241 &element, 222 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized set 1\n");
242 &init_set2,
243 NULL);
244 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
245 "initialized set 1\n");
246} 223}
247 224
248 225
249static int 226static int
250iter_cb (void *cls, 227iter_cb (void *cls, const struct GNUNET_SET_Element *element)
251 const struct GNUNET_SET_Element *element)
252{ 228{
253 struct GNUNET_SET_Handle *set = cls; 229 struct GNUNET_SET_Handle *set = cls;
254 230
@@ -262,9 +238,7 @@ iter_cb (void *cls,
262 return GNUNET_YES; 238 return GNUNET_YES;
263 } 239 }
264 iter_count++; 240 iter_count++;
265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "iter: got element %u\n", iter_count);
266 "iter: got element %u\n",
267 iter_count);
268 return GNUNET_YES; 242 return GNUNET_YES;
269} 243}
270 244
@@ -275,31 +249,22 @@ test_iter ()
275 struct GNUNET_SET_Element element; 249 struct GNUNET_SET_Element element;
276 struct GNUNET_SET_Handle *iter_set; 250 struct GNUNET_SET_Handle *iter_set;
277 251
278 iter_set = GNUNET_SET_create (config, 252 iter_set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION);
279 GNUNET_SET_OPERATION_UNION);
280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
281 "Testing iteration over 3 elements on set %p\n", 254 "Testing iteration over 3 elements on set %p\n",
282 iter_set); 255 iter_set);
283 element.element_type = 0; 256 element.element_type = 0;
284 257
285 element.data = "hello"; 258 element.data = "hello";
286 element.size = strlen(element.data); 259 element.size = strlen (element.data);
287 GNUNET_SET_add_element (iter_set, 260 GNUNET_SET_add_element (iter_set, &element, NULL, NULL);
288 &element,
289 NULL, NULL);
290 element.data = "bar"; 261 element.data = "bar";
291 element.size = strlen(element.data); 262 element.size = strlen (element.data);
292 GNUNET_SET_add_element (iter_set, 263 GNUNET_SET_add_element (iter_set, &element, NULL, NULL);
293 &element,
294 NULL, NULL);
295 element.data = "quux"; 264 element.data = "quux";
296 element.size = strlen(element.data); 265 element.size = strlen (element.data);
297 GNUNET_SET_add_element (iter_set, 266 GNUNET_SET_add_element (iter_set, &element, NULL, NULL);
298 &element, 267 GNUNET_SET_iterate (iter_set, &iter_cb, iter_set);
299 NULL, NULL);
300 GNUNET_SET_iterate (iter_set,
301 &iter_cb,
302 iter_set);
303} 268}
304 269
305 270
@@ -312,8 +277,7 @@ static void
312timeout_fail (void *cls) 277timeout_fail (void *cls)
313{ 278{
314 tt = NULL; 279 tt = NULL;
315 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 280 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Testcase failed with timeout\n");
316 "Testcase failed with timeout\n");
317 GNUNET_SCHEDULER_shutdown (); 281 GNUNET_SCHEDULER_shutdown ();
318 ret = 1; 282 ret = 1;
319} 283}
@@ -376,16 +340,15 @@ run (void *cls,
376 340
377 struct GNUNET_SET_OperationHandle *my_oh; 341 struct GNUNET_SET_OperationHandle *my_oh;
378 342
379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 343 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running preparatory tests\n");
380 "Running preparatory tests\n"); 344 tt = GNUNET_SCHEDULER_add_delayed (
381 tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), 345 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
382 &timeout_fail, 346 &timeout_fail,
383 NULL); 347 NULL);
384 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 348 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
385 NULL);
386 349
387 config = cfg; 350 config = cfg;
388 GNUNET_CRYPTO_get_peer_identity (cfg, &local_id); 351 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_get_peer_identity (cfg, &local_id));
389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 352 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
390 "my id (from CRYPTO): %s\n", 353 "my id (from CRYPTO): %s\n",
391 GNUNET_i2s (&local_id)); 354 GNUNET_i2s (&local_id));
@@ -395,16 +358,13 @@ run (void *cls,
395 GNUNET_i2s (&local_id)); 358 GNUNET_i2s (&local_id));
396 test_iter (); 359 test_iter ();
397 360
398 set1 = GNUNET_SET_create (cfg, 361 set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION);
399 GNUNET_SET_OPERATION_UNION); 362 set2 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION);
400 set2 = GNUNET_SET_create (cfg,
401 GNUNET_SET_OPERATION_UNION);
402 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
403 "Created sets %p and %p for union operation\n", 364 "Created sets %p and %p for union operation\n",
404 set1, 365 set1,
405 set2); 366 set2);
406 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, 367 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &app_id);
407 &app_id);
408 368
409 /* test if canceling an uncommited request works! */ 369 /* test if canceling an uncommited request works! */
410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -413,14 +373,13 @@ run (void *cls,
413 &app_id, 373 &app_id,
414 NULL, 374 NULL,
415 GNUNET_SET_RESULT_ADDED, 375 GNUNET_SET_RESULT_ADDED,
416 (struct GNUNET_SET_Option[]) { 0 }, 376 (struct GNUNET_SET_Option[]){0},
417 NULL, 377 NULL,
418 NULL); 378 NULL);
419 GNUNET_SET_operation_cancel (my_oh); 379 GNUNET_SET_operation_cancel (my_oh);
420 380
421 /* test the real set reconciliation */ 381 /* test the real set reconciliation */
422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running real set-reconciliation\n");
423 "Running real set-reconciliation\n");
424 init_set1 (); 383 init_set1 ();
425} 384}
426 385
@@ -428,14 +387,10 @@ run (void *cls,
428int 387int
429main (int argc, char **argv) 388main (int argc, char **argv)
430{ 389{
431 GNUNET_log_setup ("test_set_api", 390 GNUNET_log_setup ("test_set_api", "WARNING", NULL);
432 "WARNING", 391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching peer\n");
433 NULL); 392 if (0 !=
434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 393 GNUNET_TESTING_peer_run ("test_set_api", "test_set.conf", &run, NULL))
435 "Launching peer\n");
436 if (0 != GNUNET_TESTING_peer_run ("test_set_api",
437 "test_set.conf",
438 &run, NULL))
439 { 394 {
440 return 1; 395 return 1;
441 } 396 }