mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Factor out the actual test code from conference_test.
Also, renamed simple_conference_test to conference_simple_test so it's sorted together with the other conference tests. Next step is to use run_auto_test.h for the conference test.
This commit is contained in:
parent
9d5c55b4b3
commit
3c1025d2dc
|
@ -389,6 +389,7 @@ auto_test(bootstrap)
|
||||||
auto_test(conference)
|
auto_test(conference)
|
||||||
auto_test(conference_double_invite)
|
auto_test(conference_double_invite)
|
||||||
auto_test(conference_peer_nick)
|
auto_test(conference_peer_nick)
|
||||||
|
auto_test(conference_simple)
|
||||||
auto_test(conference_two)
|
auto_test(conference_two)
|
||||||
auto_test(crypto MSVC_DONT_BUILD)
|
auto_test(crypto MSVC_DONT_BUILD)
|
||||||
auto_test(dht MSVC_DONT_BUILD)
|
auto_test(dht MSVC_DONT_BUILD)
|
||||||
|
@ -411,7 +412,6 @@ auto_test(save_load)
|
||||||
auto_test(send_message)
|
auto_test(send_message)
|
||||||
auto_test(set_name)
|
auto_test(set_name)
|
||||||
auto_test(set_status_message)
|
auto_test(set_status_message)
|
||||||
auto_test(simple_conference)
|
|
||||||
auto_test(skeleton)
|
auto_test(skeleton)
|
||||||
auto_test(tcp_relay)
|
auto_test(tcp_relay)
|
||||||
auto_test(tox_many)
|
auto_test(tox_many)
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
#define NUM_GROUP_TOX 5
|
#define NUM_GROUP_TOX 5
|
||||||
#define GROUP_MESSAGE "Install Gentoo"
|
#define GROUP_MESSAGE "Install Gentoo"
|
||||||
|
|
||||||
static void handle_self_connection_status(Tox *tox, TOX_CONNECTION connection_status, void *user_data)
|
static void handle_self_connection_status(
|
||||||
|
Tox *tox, TOX_CONNECTION connection_status, void *user_data)
|
||||||
{
|
{
|
||||||
const int id = *(int *)user_data;
|
const int id = *(int *)user_data;
|
||||||
|
|
||||||
|
@ -35,8 +36,8 @@ static void handle_self_connection_status(Tox *tox, TOX_CONNECTION connection_st
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_friend_connection_status(Tox *tox, uint32_t friendnumber, TOX_CONNECTION connection_status,
|
static void handle_friend_connection_status(
|
||||||
void *user_data)
|
Tox *tox, uint32_t friendnumber, TOX_CONNECTION connection_status, void *user_data)
|
||||||
{
|
{
|
||||||
const int id = *(int *)user_data;
|
const int id = *(int *)user_data;
|
||||||
|
|
||||||
|
@ -47,8 +48,9 @@ static void handle_friend_connection_status(Tox *tox, uint32_t friendnumber, TOX
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_conference_invite(Tox *tox, uint32_t friendnumber, TOX_CONFERENCE_TYPE type, const uint8_t *data,
|
static void handle_conference_invite(
|
||||||
size_t length, void *user_data)
|
Tox *tox, uint32_t friendnumber, TOX_CONFERENCE_TYPE type,
|
||||||
|
const uint8_t *data, size_t length, void *user_data)
|
||||||
{
|
{
|
||||||
const int id = *(int *)user_data;
|
const int id = *(int *)user_data;
|
||||||
ck_assert_msg(type == TOX_CONFERENCE_TYPE_TEXT, "tox #%d: wrong conference type: %d", id, type);
|
ck_assert_msg(type == TOX_CONFERENCE_TYPE_TEXT, "tox #%d: wrong conference type: %d", id, type);
|
||||||
|
@ -74,14 +76,61 @@ static void handle_conference_invite(Tox *tox, uint32_t friendnumber, TOX_CONFER
|
||||||
|
|
||||||
static unsigned int num_recv;
|
static unsigned int num_recv;
|
||||||
|
|
||||||
static void handle_conference_message(Tox *tox, uint32_t groupnumber, uint32_t peernumber, TOX_MESSAGE_TYPE type,
|
static void handle_conference_message(
|
||||||
const uint8_t *message, size_t length, void *user_data)
|
Tox *tox, uint32_t groupnumber, uint32_t peernumber, TOX_MESSAGE_TYPE type,
|
||||||
|
const uint8_t *message, size_t length, void *user_data)
|
||||||
{
|
{
|
||||||
if (length == (sizeof(GROUP_MESSAGE) - 1) && memcmp(message, GROUP_MESSAGE, sizeof(GROUP_MESSAGE) - 1) == 0) {
|
if (length == (sizeof(GROUP_MESSAGE) - 1) && memcmp(message, GROUP_MESSAGE, sizeof(GROUP_MESSAGE) - 1) == 0) {
|
||||||
++num_recv;
|
++num_recv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void run_conference_tests(Tox **toxes, uint32_t *tox_index)
|
||||||
|
{
|
||||||
|
for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
|
||||||
|
tox_callback_conference_message(toxes[i], &handle_conference_message);
|
||||||
|
}
|
||||||
|
|
||||||
|
TOX_ERR_CONFERENCE_SEND_MESSAGE err;
|
||||||
|
ck_assert_msg(
|
||||||
|
tox_conference_send_message(
|
||||||
|
toxes[random_u32() % NUM_GROUP_TOX], 0, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)GROUP_MESSAGE,
|
||||||
|
sizeof(GROUP_MESSAGE) - 1, &err) != 0, "Failed to send group message.");
|
||||||
|
ck_assert_msg(
|
||||||
|
err == TOX_ERR_CONFERENCE_SEND_MESSAGE_OK, "Failed to send group message.");
|
||||||
|
num_recv = 0;
|
||||||
|
|
||||||
|
for (unsigned j = 0; j < 20; ++j) {
|
||||||
|
for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
|
||||||
|
tox_iterate(toxes[i], &tox_index[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
c_sleep(25);
|
||||||
|
}
|
||||||
|
|
||||||
|
c_sleep(25);
|
||||||
|
ck_assert_msg(num_recv == NUM_GROUP_TOX, "Failed to recv group messages.");
|
||||||
|
|
||||||
|
for (unsigned k = NUM_GROUP_TOX; k != 0 ; --k) {
|
||||||
|
tox_conference_delete(toxes[k - 1], 0, nullptr);
|
||||||
|
|
||||||
|
for (unsigned j = 0; j < 10; ++j) {
|
||||||
|
for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
|
||||||
|
tox_iterate(toxes[i], &tox_index[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
c_sleep(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < k - 1; ++i) {
|
||||||
|
uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr);
|
||||||
|
ck_assert_msg(peer_count == (k - 1), "\n\tBad number of group peers (post check)."
|
||||||
|
"\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n",
|
||||||
|
(k - 1), i, peer_count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void test_many_group(void)
|
static void test_many_group(void)
|
||||||
{
|
{
|
||||||
const time_t test_start_time = time(nullptr);
|
const time_t test_start_time = time(nullptr);
|
||||||
|
@ -203,48 +252,9 @@ static void test_many_group(void)
|
||||||
|
|
||||||
printf("group connected, took %d seconds\n", (int)(time(nullptr) - cur_time));
|
printf("group connected, took %d seconds\n", (int)(time(nullptr) - cur_time));
|
||||||
|
|
||||||
for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
|
run_conference_tests(toxes, tox_index);
|
||||||
tox_callback_conference_message(toxes[i], &handle_conference_message);
|
|
||||||
}
|
|
||||||
|
|
||||||
TOX_ERR_CONFERENCE_SEND_MESSAGE err;
|
printf("tearing down toxes\n");
|
||||||
ck_assert_msg(
|
|
||||||
tox_conference_send_message(
|
|
||||||
toxes[random_u32() % NUM_GROUP_TOX], 0, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)GROUP_MESSAGE,
|
|
||||||
sizeof(GROUP_MESSAGE) - 1, &err) != 0, "Failed to send group message.");
|
|
||||||
ck_assert_msg(
|
|
||||||
err == TOX_ERR_CONFERENCE_SEND_MESSAGE_OK, "Failed to send group message.");
|
|
||||||
num_recv = 0;
|
|
||||||
|
|
||||||
for (unsigned j = 0; j < 20; ++j) {
|
|
||||||
for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
|
|
||||||
tox_iterate(toxes[i], &tox_index[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
c_sleep(25);
|
|
||||||
}
|
|
||||||
|
|
||||||
c_sleep(25);
|
|
||||||
ck_assert_msg(num_recv == NUM_GROUP_TOX, "Failed to recv group messages.");
|
|
||||||
|
|
||||||
for (unsigned k = NUM_GROUP_TOX; k != 0 ; --k) {
|
|
||||||
tox_conference_delete(toxes[k - 1], 0, nullptr);
|
|
||||||
|
|
||||||
for (unsigned j = 0; j < 10; ++j) {
|
|
||||||
for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
|
|
||||||
tox_iterate(toxes[i], &tox_index[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
c_sleep(50);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < k - 1; ++i) {
|
|
||||||
uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr);
|
|
||||||
ck_assert_msg(peer_count == (k - 1), "\n\tBad number of group peers (post check)."
|
|
||||||
"\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n",
|
|
||||||
(k - 1), i, peer_count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
|
for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
|
||||||
tox_kill(toxes[i]);
|
tox_kill(toxes[i]);
|
||||||
|
|
|
@ -33,6 +33,10 @@ namespace bootstrap_test {
|
||||||
int main(void);
|
int main(void);
|
||||||
#include "bootstrap_test.c"
|
#include "bootstrap_test.c"
|
||||||
} // namespace bootstrap_test
|
} // namespace bootstrap_test
|
||||||
|
namespace conference_simple_test {
|
||||||
|
int main(void);
|
||||||
|
#include "conference_simple_test.c"
|
||||||
|
} // namespace conference_simple_test
|
||||||
namespace conference_test {
|
namespace conference_test {
|
||||||
int main(void);
|
int main(void);
|
||||||
#include "conference_test.c"
|
#include "conference_test.c"
|
||||||
|
@ -101,10 +105,6 @@ namespace set_status_message_test {
|
||||||
int main(void);
|
int main(void);
|
||||||
#include "set_status_message_test.c"
|
#include "set_status_message_test.c"
|
||||||
} // namespace set_status_message_test
|
} // namespace set_status_message_test
|
||||||
namespace simple_conference_test {
|
|
||||||
int main(void);
|
|
||||||
#include "simple_conference_test.c"
|
|
||||||
} // namespace simple_conference_test
|
|
||||||
namespace skeleton_test {
|
namespace skeleton_test {
|
||||||
int main(void);
|
int main(void);
|
||||||
#include "skeleton_test.c"
|
#include "skeleton_test.c"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user