aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_api_bidirectional_connect.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-09 22:34:49 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-09 22:34:49 +0000
commitc0b81510ffe194dc662c3a6267d5e66a69873c4b (patch)
tree5ad5cc473d6993523be80bcf1430230e224d9216 /src/transport/test_transport_api_bidirectional_connect.c
parenta7345f7436c421fd15e18e87ec399ea93b6dde03 (diff)
downloadgnunet-c0b81510ffe194dc662c3a6267d5e66a69873c4b.tar.gz
gnunet-c0b81510ffe194dc662c3a6267d5e66a69873c4b.zip
-start to refactor testcases for sanity
Diffstat (limited to 'src/transport/test_transport_api_bidirectional_connect.c')
-rw-r--r--src/transport/test_transport_api_bidirectional_connect.c78
1 files changed, 44 insertions, 34 deletions
diff --git a/src/transport/test_transport_api_bidirectional_connect.c b/src/transport/test_transport_api_bidirectional_connect.c
index a5d6b6b71..10b20e21e 100644
--- a/src/transport/test_transport_api_bidirectional_connect.c
+++ b/src/transport/test_transport_api_bidirectional_connect.c
@@ -53,16 +53,16 @@ static struct GNUNET_SCHEDULER_Task * die_task;
53 53
54static struct GNUNET_SCHEDULER_Task * send_task; 54static struct GNUNET_SCHEDULER_Task * send_task;
55 55
56static struct PeerContext *p1; 56static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1;
57 57
58static struct PeerContext *p2; 58static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2;
59 59
60static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc1; 60static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc1;
61static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc2; 61static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc2;
62 62
63static struct GNUNET_TRANSPORT_TransmitHandle *th; 63static struct GNUNET_TRANSPORT_TransmitHandle *th;
64 64
65static struct GNUNET_TRANSPORT_TESTING_handle *tth; 65static struct GNUNET_TRANSPORT_TESTING_Handle *tth;
66 66
67static char *cfg_file_p1; 67static char *cfg_file_p1;
68 68
@@ -89,8 +89,8 @@ end ()
89 th = NULL; 89 th = NULL;
90 } 90 }
91 91
92 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); 92 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
93 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); 93 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
94} 94}
95 95
96 96
@@ -108,13 +108,13 @@ end_badly (void *cls)
108 if (NULL != cc2) 108 if (NULL != cc2)
109 { 109 {
110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n")); 110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n"));
111 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc2); 111 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc2);
112 cc2 = NULL; 112 cc2 = NULL;
113 } 113 }
114 if (NULL != cc1) 114 if (NULL != cc1)
115 { 115 {
116 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n")); 116 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n"));
117 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc1); 117 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc1);
118 cc1 = NULL; 118 cc1 = NULL;
119 } 119 }
120 if (NULL != th) 120 if (NULL != th)
@@ -123,9 +123,9 @@ end_badly (void *cls)
123 th = NULL; 123 th = NULL;
124 } 124 }
125 if (p1 != NULL) 125 if (p1 != NULL)
126 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); 126 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
127 if (p2 != NULL) 127 if (p2 != NULL)
128 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); 128 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
129 129
130 ok = GNUNET_SYSERR; 130 ok = GNUNET_SYSERR;
131} 131}
@@ -135,8 +135,8 @@ static void
135notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 135notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
136 const struct GNUNET_MessageHeader *message) 136 const struct GNUNET_MessageHeader *message)
137{ 137{
138 struct PeerContext *p = cls; 138 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
139 struct PeerContext *t = NULL; 139 struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL;
140 140
141 if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) 141 if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
142 t = p1; 142 t = p1;
@@ -168,7 +168,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
168static size_t 168static size_t
169notify_ready (void *cls, size_t size, void *buf) 169notify_ready (void *cls, size_t size, void *buf)
170{ 170{
171 struct PeerContext *p = cls; 171 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
172 struct GNUNET_MessageHeader *hdr; 172 struct GNUNET_MessageHeader *hdr;
173 173
174 th = NULL; 174 th = NULL;
@@ -231,8 +231,8 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
231 static int c; 231 static int c;
232 232
233 c++; 233 c++;
234 struct PeerContext *p = cls; 234 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
235 struct PeerContext *t = NULL; 235 struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL;
236 236
237 if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) 237 if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
238 t = p1; 238 t = p1;
@@ -257,7 +257,7 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
257static void 257static void
258notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 258notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
259{ 259{
260 struct PeerContext *p = cls; 260 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
261 261
262 { 262 {
263 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); 263 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
@@ -284,17 +284,17 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
284 284
285 285
286static void 286static void
287testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) 287testing_connect_cb (void *cls)
288{ 288{
289 static int connected = GNUNET_NO; 289 static int connected = GNUNET_NO;
290 290
291 if ((cls == cc1) && (NULL != cc2)) 291 if ((cls == cc1) && (NULL != cc2))
292 { 292 {
293 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc2); 293 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc2);
294 } 294 }
295 if ((cls == cc2) && (NULL != cc1)) 295 if ((cls == cc2) && (NULL != cc1))
296 { 296 {
297 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc1); 297 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc1);
298 } 298 }
299 cc1 = NULL; 299 cc1 = NULL;
300 cc2 = NULL; 300 cc2 = NULL;
@@ -321,7 +321,7 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
321 321
322 322
323static void 323static void
324start_cb (struct PeerContext *p, void *cls) 324start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls)
325{ 325{
326 static int started; 326 static int started;
327 327
@@ -342,10 +342,14 @@ start_cb (struct PeerContext *p, void *cls)
342 p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); 342 p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id));
343 GNUNET_free (sender_c); 343 GNUNET_free (sender_c);
344 cc1 = 344 cc1 =
345 GNUNET_TRANSPORT_TESTING_connect_peers (tth, p2, p1, &testing_connect_cb, 345 GNUNET_TRANSPORT_TESTING_connect_peers (p2,
346 p1,
347 &testing_connect_cb,
346 cc1); 348 cc1);
347 cc2 = 349 cc2 =
348 GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, 350 GNUNET_TRANSPORT_TESTING_connect_peers (p1,
351 p2,
352 &testing_connect_cb,
349 cc2); 353 cc2);
350} 354}
351 355
@@ -356,14 +360,21 @@ run (void *cls, char *const *args, const char *cfgfile,
356{ 360{
357 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 361 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
358 362
359 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, 363 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
360 &notify_receive, &notify_connect, 364 cfg_file_p1, 1,
361 &notify_disconnect, &start_cb, 365 &notify_receive,
366 &notify_connect,
367 &notify_disconnect,
368 &start_cb,
362 NULL); 369 NULL);
363 370
364 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, 371 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
365 &notify_receive, &notify_connect, 372 cfg_file_p2,
366 &notify_disconnect, &start_cb, 373 2,
374 &notify_receive,
375 &notify_connect,
376 &notify_disconnect,
377 &start_cb,
367 NULL); 378 NULL);
368 379
369 if ((p1 == NULL) || (p2 == NULL)) 380 if ((p1 == NULL) || (p2 == NULL))
@@ -406,20 +417,19 @@ main (int argc, char *argv[])
406{ 417{
407 int ret; 418 int ret;
408 419
409 GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name); 420 test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]);
410
411 GNUNET_log_setup (test_name, 421 GNUNET_log_setup (test_name,
412 "WARNING", 422 "WARNING",
413 NULL); 423 NULL);
414 424
415 GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source); 425 test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__);
416 GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source, 426 test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0],
417 &test_plugin); 427 test_source);
418 428
419 tth = GNUNET_TRANSPORT_TESTING_init (); 429 tth = GNUNET_TRANSPORT_TESTING_init ();
420 430
421 GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1); 431 cfg_file_p1 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 1);
422 GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2); 432 cfg_file_p2 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 2);
423 433
424 ret = check (); 434 ret = check ();
425 435