mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Added new tox autotest.
This commit is contained in:
parent
7092303823
commit
a576e451ab
|
@ -55,6 +55,65 @@ START_TEST(test_few_clients)
|
|||
}
|
||||
END_TEST
|
||||
|
||||
#define NUM_TOXES 66
|
||||
#define NUM_FRIENDS 20
|
||||
|
||||
START_TEST(test_many_clients)
|
||||
{
|
||||
long long unsigned int cur_time = time(NULL);
|
||||
Tox *toxes[NUM_TOXES];
|
||||
uint32_t i, j;
|
||||
|
||||
for (i = 0; i < NUM_TOXES; ++i) {
|
||||
toxes[i] = tox_new(TOX_ENABLE_IPV6_DEFAULT);
|
||||
ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i);
|
||||
tox_callback_friend_request(toxes[i], accept_friend_request, toxes[i]);
|
||||
}
|
||||
|
||||
struct {
|
||||
uint16_t tox1;
|
||||
uint16_t tox2;
|
||||
} pairs[NUM_FRIENDS];
|
||||
|
||||
uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
|
||||
|
||||
for (i = 0; i < NUM_FRIENDS; ++i) {
|
||||
loop_top:
|
||||
pairs[i].tox1 = rand() % NUM_TOXES;
|
||||
pairs[i].tox2 = (pairs[i].tox1 + rand() % (NUM_TOXES - 1) + 1) % NUM_TOXES;
|
||||
tox_get_address(toxes[pairs[i].tox1], address);
|
||||
int test = tox_add_friend(toxes[pairs[i].tox2], address, "Gentoo", 7);
|
||||
|
||||
if (test == TOX_FAERR_ALREADYSENT) {
|
||||
goto loop_top;
|
||||
}
|
||||
|
||||
ck_assert_msg(test >= 0, "Failed to add friend error code: %i", test);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
uint16_t counter = 0;
|
||||
|
||||
for (i = 0; i < NUM_TOXES; ++i) {
|
||||
for (j = 0; j < tox_count_friendlist(toxes[i]); ++j)
|
||||
if (tox_get_friend_connection_status(toxes[i], j) == 1)
|
||||
++counter;
|
||||
}
|
||||
|
||||
if (counter == NUM_FRIENDS * 2) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_TOXES; ++i) {
|
||||
tox_do(toxes[i]);
|
||||
}
|
||||
|
||||
c_sleep(50);
|
||||
}
|
||||
|
||||
printf("test_many_clients succeeded, took %llu seconds\n", time(NULL) - cur_time);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
#define DEFTESTCASE(NAME) \
|
||||
TCase *tc_##NAME = tcase_create(#NAME); \
|
||||
|
@ -69,7 +128,7 @@ Suite *tox_suite(void)
|
|||
Suite *s = suite_create("Tox");
|
||||
|
||||
DEFTESTCASE_SLOW(few_clients, 30);
|
||||
|
||||
DEFTESTCASE_SLOW(many_clients, 240);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user