From f1e0e16b67eb8d38c7829397a957eef636497d07 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Wed, 29 Jan 2014 20:59:50 -0500 Subject: A bit of tests added. --- auto_tests/onion_test.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) (limited to 'auto_tests') 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 @@ #include "../toxcore/onion.h" #include "../toxcore/onion_announce.h" +#include "../toxcore/onion_client.h" #include "../toxcore/util.h" #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) @@ -218,6 +219,7 @@ END_TEST typedef struct { Onion *onion; Onion_Announce *onion_a; + Onion_Client *onion_c; } Onions; Onions *new_onions(uint16_t port) @@ -229,14 +231,22 @@ Onions *new_onions(uint16_t port) DHT *dht = new_DHT(new_net_crypto(new_networking(ip, port))); on->onion = new_onion(dht); on->onion_a = new_onion_announce(dht); + on->onion_c = new_onion_client(dht); - if (on->onion && on->onion_a) + if (on->onion && on->onion_a && on->onion_c) return on; return NULL; } -#define NUM_ONIONS 64 +void do_onions(Onions *on) +{ + networking_poll(on->onion->net); + do_DHT(on->onion->dht); + do_onion_client(on->onion_c); +} + +#define NUM_ONIONS 24 START_TEST(test_announce) { @@ -248,7 +258,42 @@ START_TEST(test_announce) ck_assert_msg(onions[i] != 0, "Failed to create onions. %u"); } + IP ip; + ip_init(&ip, 1); + ip.ip6.uint8[15] = 1; + + for (i = 1; i < NUM_ONIONS; ++i) { + IP_Port ip_port = {ip, onions[i - 1]->onion->net->port}; + DHT_bootstrap(onions[i]->onion->dht, ip_port, onions[i - 1]->onion->dht->self_public_key); + } + + uint32_t connected = 0; + + while (connected != NUM_ONIONS) { + connected = 0; + + for (i = 0; i < NUM_ONIONS; ++i) { + do_onions(onions[i]); + connected += DHT_isconnected(onions[i]->onion->dht); + } + } + + /* + onion_addfriend(onions[7]->onion_c, onions[23]->onion->dht->c->self_public_key); + int frnum = onion_addfriend(onions[23]->onion_c, onions[7]->onion->dht->c->self_public_key); + + uint32_t ok = 0; + + while (ok != 1) { + for (i = 0; i < NUM_ONIONS; ++i) { + do_onions(onions[i]); + } + + IP_Port ip_port; + ok = onion_getfriendip(onions[23]->onion_c, frnum, &ip_port); + c_sleep(50); + }*/ } END_TEST @@ -265,7 +310,7 @@ Suite *onion_suite(void) Suite *s = suite_create("Onion"); DEFTESTCASE_SLOW(basic, 5); - DEFTESTCASE_SLOW(announce, 5); + DEFTESTCASE_SLOW(announce, 40); return s; } -- cgit v1.2.3 From a13e30e8bb59f60b4971b0d46dd573ffe7b44104 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 30 Jan 2014 14:59:31 -0500 Subject: Test passes now, uncommented it. --- auto_tests/onion_test.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'auto_tests') diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index bdafa638..73f69744 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c @@ -246,7 +246,7 @@ void do_onions(Onions *on) do_onion_client(on->onion_c); } -#define NUM_ONIONS 24 +#define NUM_ONIONS 50 START_TEST(test_announce) { @@ -278,22 +278,21 @@ START_TEST(test_announce) } } - /* - onion_addfriend(onions[7]->onion_c, onions[23]->onion->dht->c->self_public_key); - int frnum = onion_addfriend(onions[23]->onion_c, onions[7]->onion->dht->c->self_public_key); + onion_addfriend(onions[7]->onion_c, onions[23]->onion->dht->c->self_public_key); + int frnum = onion_addfriend(onions[23]->onion_c, onions[7]->onion->dht->c->self_public_key); - uint32_t ok = 0; + uint32_t ok = 0; - while (ok != 1) { - for (i = 0; i < NUM_ONIONS; ++i) { - do_onions(onions[i]); - } + while (ok != 1) { + for (i = 0; i < NUM_ONIONS; ++i) { + do_onions(onions[i]); + } - IP_Port ip_port; - ok = onion_getfriendip(onions[23]->onion_c, frnum, &ip_port); + IP_Port ip_port; + ok = onion_getfriendip(onions[23]->onion_c, frnum, &ip_port); - c_sleep(50); - }*/ + c_sleep(50); + } } END_TEST @@ -310,7 +309,7 @@ Suite *onion_suite(void) Suite *s = suite_create("Onion"); DEFTESTCASE_SLOW(basic, 5); - DEFTESTCASE_SLOW(announce, 40); + DEFTESTCASE_SLOW(announce, 80); return s; } -- cgit v1.2.3