summaryrefslogtreecommitdiff
path: root/auto_tests/onion_test.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-01-29 20:59:50 -0500
committerirungentoo <irungentoo@gmail.com>2014-01-29 20:59:50 -0500
commitf1e0e16b67eb8d38c7829397a957eef636497d07 (patch)
treedd32a95ef04f928216cad4f55d108daee72e40cc /auto_tests/onion_test.c
parent8f3966ad9884d5fe308711c980ffa24aca150751 (diff)
A bit of tests added.
Diffstat (limited to 'auto_tests/onion_test.c')
-rw-r--r--auto_tests/onion_test.c51
1 files changed, 48 insertions, 3 deletions
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c
index 4dae2136..bdafa638 100644
--- a/auto_tests/onion_test.c
+++ b/auto_tests/onion_test.c
@@ -11,6 +11,7 @@
11 11
12#include "../toxcore/onion.h" 12#include "../toxcore/onion.h"
13#include "../toxcore/onion_announce.h" 13#include "../toxcore/onion_announce.h"
14#include "../toxcore/onion_client.h"
14#include "../toxcore/util.h" 15#include "../toxcore/util.h"
15 16
16#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) 17#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
@@ -218,6 +219,7 @@ END_TEST
218typedef struct { 219typedef struct {
219 Onion *onion; 220 Onion *onion;
220 Onion_Announce *onion_a; 221 Onion_Announce *onion_a;
222 Onion_Client *onion_c;
221} Onions; 223} Onions;
222 224
223Onions *new_onions(uint16_t port) 225Onions *new_onions(uint16_t port)
@@ -229,14 +231,22 @@ Onions *new_onions(uint16_t port)
229 DHT *dht = new_DHT(new_net_crypto(new_networking(ip, port))); 231 DHT *dht = new_DHT(new_net_crypto(new_networking(ip, port)));
230 on->onion = new_onion(dht); 232 on->onion = new_onion(dht);
231 on->onion_a = new_onion_announce(dht); 233 on->onion_a = new_onion_announce(dht);
234 on->onion_c = new_onion_client(dht);
232 235
233 if (on->onion && on->onion_a) 236 if (on->onion && on->onion_a && on->onion_c)
234 return on; 237 return on;
235 238
236 return NULL; 239 return NULL;
237} 240}
238 241
239#define NUM_ONIONS 64 242void do_onions(Onions *on)
243{
244 networking_poll(on->onion->net);
245 do_DHT(on->onion->dht);
246 do_onion_client(on->onion_c);
247}
248
249#define NUM_ONIONS 24
240 250
241START_TEST(test_announce) 251START_TEST(test_announce)
242{ 252{
@@ -248,7 +258,42 @@ START_TEST(test_announce)
248 ck_assert_msg(onions[i] != 0, "Failed to create onions. %u"); 258 ck_assert_msg(onions[i] != 0, "Failed to create onions. %u");
249 } 259 }
250 260
261 IP ip;
262 ip_init(&ip, 1);
263 ip.ip6.uint8[15] = 1;
264
265 for (i = 1; i < NUM_ONIONS; ++i) {
266 IP_Port ip_port = {ip, onions[i - 1]->onion->net->port};
267 DHT_bootstrap(onions[i]->onion->dht, ip_port, onions[i - 1]->onion->dht->self_public_key);
268 }
269
270 uint32_t connected = 0;
271
272 while (connected != NUM_ONIONS) {
273 connected = 0;
274
275 for (i = 0; i < NUM_ONIONS; ++i) {
276 do_onions(onions[i]);
277 connected += DHT_isconnected(onions[i]->onion->dht);
278 }
279 }
280
281 /*
282 onion_addfriend(onions[7]->onion_c, onions[23]->onion->dht->c->self_public_key);
283 int frnum = onion_addfriend(onions[23]->onion_c, onions[7]->onion->dht->c->self_public_key);
284
285 uint32_t ok = 0;
286
287 while (ok != 1) {
288 for (i = 0; i < NUM_ONIONS; ++i) {
289 do_onions(onions[i]);
290 }
291
292 IP_Port ip_port;
293 ok = onion_getfriendip(onions[23]->onion_c, frnum, &ip_port);
251 294
295 c_sleep(50);
296 }*/
252} 297}
253END_TEST 298END_TEST
254 299
@@ -265,7 +310,7 @@ Suite *onion_suite(void)
265 Suite *s = suite_create("Onion"); 310 Suite *s = suite_create("Onion");
266 311
267 DEFTESTCASE_SLOW(basic, 5); 312 DEFTESTCASE_SLOW(basic, 5);
268 DEFTESTCASE_SLOW(announce, 5); 313 DEFTESTCASE_SLOW(announce, 40);
269 return s; 314 return s;
270} 315}
271 316