diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-09 22:34:49 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-09 22:34:49 +0000 |
commit | c0b81510ffe194dc662c3a6267d5e66a69873c4b (patch) | |
tree | 5ad5cc473d6993523be80bcf1430230e224d9216 /src/transport/test_transport_api.c | |
parent | a7345f7436c421fd15e18e87ec399ea93b6dde03 (diff) | |
download | gnunet-c0b81510ffe194dc662c3a6267d5e66a69873c4b.tar.gz gnunet-c0b81510ffe194dc662c3a6267d5e66a69873c4b.zip |
-start to refactor testcases for sanity
Diffstat (limited to 'src/transport/test_transport_api.c')
-rw-r--r-- | src/transport/test_transport_api.c | 58 |
1 files changed, 25 insertions, 33 deletions
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c index 91d129e24..9983356de 100644 --- a/src/transport/test_transport_api.c +++ b/src/transport/test_transport_api.c | |||
@@ -62,15 +62,15 @@ static struct GNUNET_SCHEDULER_Task * die_task; | |||
62 | 62 | ||
63 | static struct GNUNET_SCHEDULER_Task * send_task; | 63 | static struct GNUNET_SCHEDULER_Task * send_task; |
64 | 64 | ||
65 | static struct PeerContext *p1; | 65 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; |
66 | 66 | ||
67 | static struct PeerContext *p2; | 67 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; |
68 | 68 | ||
69 | static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc; | 69 | static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc; |
70 | 70 | ||
71 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | 71 | static struct GNUNET_TRANSPORT_TransmitHandle *th; |
72 | 72 | ||
73 | static struct GNUNET_TRANSPORT_TESTING_handle *tth; | 73 | static struct GNUNET_TRANSPORT_TESTING_Handle *tth; |
74 | 74 | ||
75 | static char *cfg_file_p1; | 75 | static char *cfg_file_p1; |
76 | 76 | ||
@@ -92,8 +92,8 @@ end () | |||
92 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 92 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
93 | th = NULL; | 93 | th = NULL; |
94 | 94 | ||
95 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); | 95 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); |
96 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); | 96 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
@@ -111,7 +111,7 @@ end_badly (void *cls) | |||
111 | if (cc != NULL) | 111 | if (cc != NULL) |
112 | { | 112 | { |
113 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n")); | 113 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n")); |
114 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); | 114 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); |
115 | cc = NULL; | 115 | cc = NULL; |
116 | } | 116 | } |
117 | 117 | ||
@@ -138,11 +138,11 @@ end_badly (void *cls) | |||
138 | th = NULL; | 138 | th = NULL; |
139 | 139 | ||
140 | if (p1 != NULL) | 140 | if (p1 != NULL) |
141 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); | 141 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); |
142 | else | 142 | else |
143 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer 1 was not started\n")); | 143 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer 1 was not started\n")); |
144 | if (p2 != NULL) | 144 | if (p2 != NULL) |
145 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); | 145 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); |
146 | else | 146 | else |
147 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer 2 was not started\n")); | 147 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer 2 was not started\n")); |
148 | 148 | ||
@@ -154,8 +154,8 @@ static void | |||
154 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | 154 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, |
155 | const struct GNUNET_MessageHeader *message) | 155 | const struct GNUNET_MessageHeader *message) |
156 | { | 156 | { |
157 | struct PeerContext *p = cls; | 157 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; |
158 | struct PeerContext *t = NULL; | 158 | struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; |
159 | 159 | ||
160 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) | 160 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) |
161 | t = p1; | 161 | t = p1; |
@@ -189,7 +189,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
189 | static size_t | 189 | static size_t |
190 | notify_ready (void *cls, size_t size, void *buf) | 190 | notify_ready (void *cls, size_t size, void *buf) |
191 | { | 191 | { |
192 | struct PeerContext *p = cls; | 192 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; |
193 | struct GNUNET_MessageHeader *hdr; | 193 | struct GNUNET_MessageHeader *hdr; |
194 | 194 | ||
195 | th = NULL; | 195 | th = NULL; |
@@ -249,8 +249,8 @@ notify_connect (void *cls, | |||
249 | static int c; | 249 | static int c; |
250 | 250 | ||
251 | c++; | 251 | c++; |
252 | struct PeerContext *p = cls; | 252 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; |
253 | struct PeerContext *t = NULL; | 253 | struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; |
254 | 254 | ||
255 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) | 255 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) |
256 | t = p1; | 256 | t = p1; |
@@ -271,7 +271,7 @@ static void | |||
271 | notify_disconnect (void *cls, | 271 | notify_disconnect (void *cls, |
272 | const struct GNUNET_PeerIdentity *peer) | 272 | const struct GNUNET_PeerIdentity *peer) |
273 | { | 273 | { |
274 | struct PeerContext *p = cls; | 274 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; |
275 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | 275 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); |
276 | 276 | ||
277 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 277 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -290,9 +290,7 @@ notify_disconnect (void *cls, | |||
290 | 290 | ||
291 | 291 | ||
292 | static void | 292 | static void |
293 | testing_connect_cb (struct PeerContext *p1, | 293 | testing_connect_cb (void *cls) |
294 | struct PeerContext *p2, | ||
295 | void *cls) | ||
296 | { | 294 | { |
297 | cc = NULL; | 295 | cc = NULL; |
298 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | 296 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); |
@@ -307,7 +305,7 @@ testing_connect_cb (struct PeerContext *p1, | |||
307 | 305 | ||
308 | 306 | ||
309 | static void | 307 | static void |
310 | start_cb (struct PeerContext *p, | 308 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, |
311 | void *cls) | 309 | void *cls) |
312 | { | 310 | { |
313 | static int started; | 311 | static int started; |
@@ -329,8 +327,7 @@ start_cb (struct PeerContext *p, | |||
329 | p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); | 327 | p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); |
330 | GNUNET_free (sender_c); | 328 | GNUNET_free (sender_c); |
331 | } | 329 | } |
332 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, | 330 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, |
333 | p1, | ||
334 | p2, | 331 | p2, |
335 | &testing_connect_cb, | 332 | &testing_connect_cb, |
336 | NULL); | 333 | NULL); |
@@ -406,25 +403,20 @@ main (int argc, char *argv[]) | |||
406 | { | 403 | { |
407 | int ret; | 404 | int ret; |
408 | 405 | ||
409 | GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], | 406 | test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]); |
410 | &test_name); | 407 | test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__); |
411 | GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, | 408 | test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], |
412 | &test_source); | 409 | test_source); |
413 | GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], | ||
414 | test_source, | ||
415 | &test_plugin); | ||
416 | 410 | ||
417 | GNUNET_log_setup (test_name, | 411 | GNUNET_log_setup (test_name, |
418 | "WARNING", | 412 | "WARNING", |
419 | NULL); | 413 | NULL); |
420 | tth = GNUNET_TRANSPORT_TESTING_init (); | 414 | tth = GNUNET_TRANSPORT_TESTING_init (); |
421 | 415 | ||
422 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], | 416 | cfg_file_p1 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], |
423 | &cfg_file_p1, | 417 | 1); |
424 | 1); | 418 | cfg_file_p2 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], |
425 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], | 419 | 2); |
426 | &cfg_file_p2, | ||
427 | 2); | ||
428 | 420 | ||
429 | ret = check (); | 421 | ret = check (); |
430 | 422 | ||