Test now works with large groups.

This commit is contained in:
irungentoo 2014-12-05 22:37:02 -05:00
parent 5112156953
commit 422f228921
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98

View File

@ -430,7 +430,7 @@ loop_top:
} }
END_TEST END_TEST
#define NUM_GROUP_TOX 6 #define NUM_GROUP_TOX 32
void g_accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata) void g_accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
{ {
@ -442,6 +442,9 @@ void g_accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *d
} }
} }
static Tox *invite_tox;
static unsigned int invite_counter;
void print_group_invite_callback(Tox *tox, int32_t friendnumber, uint8_t type, const uint8_t *data, uint16_t length, void print_group_invite_callback(Tox *tox, int32_t friendnumber, uint8_t type, const uint8_t *data, uint16_t length,
void *userdata) void *userdata)
{ {
@ -457,8 +460,8 @@ void print_group_invite_callback(Tox *tox, int32_t friendnumber, uint8_t type, c
ck_assert_msg(tox_join_groupchat(tox, friendnumber, data, length) == -1, ck_assert_msg(tox_join_groupchat(tox, friendnumber, data, length) == -1,
"Joining groupchat twice should be impossible."); "Joining groupchat twice should be impossible.");
if (tox_invite_friend(tox, 0, g_num) == -1) invite_tox = tox;
return; invite_counter = 4;
} }
static unsigned int num_recv; static unsigned int num_recv;
@ -521,24 +524,32 @@ START_TEST(test_many_group)
ck_assert_msg(tox_add_groupchat(toxes[0]) != -1, "Failed to create group"); ck_assert_msg(tox_add_groupchat(toxes[0]) != -1, "Failed to create group");
ck_assert_msg(tox_invite_friend(toxes[0], 0, 0) == 0, "Failed to invite friend"); ck_assert_msg(tox_invite_friend(toxes[0], 0, 0) == 0, "Failed to invite friend");
invite_counter = ~0;
unsigned int done = ~0;
done -= 5;
while (1) { while (1) {
for (i = 0; i < NUM_GROUP_TOX; ++i) {
if (tox_group_number_peers(toxes[i], 0) != NUM_GROUP_TOX) {
break;
}
}
if (i == NUM_GROUP_TOX)
break;
for (i = 0; i < NUM_GROUP_TOX; ++i) { for (i = 0; i < NUM_GROUP_TOX; ++i) {
tox_do(toxes[i]); tox_do(toxes[i]);
} }
if (!invite_counter) {
ck_assert_msg(tox_invite_friend(invite_tox, 0, 0) == 0, "Failed to invite friend");
}
if (done == invite_counter) {
break;
}
--invite_counter;
c_sleep(50); c_sleep(50);
} }
for (i = 0; i < NUM_GROUP_TOX; ++i) {
ck_assert_msg(tox_group_number_peers(toxes[i], 0) == NUM_GROUP_TOX, "Bad number of group peers.");
}
printf("group connected\n"); printf("group connected\n");
for (i = 0; i < NUM_GROUP_TOX; ++i) { for (i = 0; i < NUM_GROUP_TOX; ++i) {