From 3c1025d2dc07b41fd5c0b621e68be3a7c85611d8 Mon Sep 17 00:00:00 2001 From: iphydf Date: Sat, 7 Jul 2018 10:18:55 +0000 Subject: [PATCH] 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. --- CMakeLists.txt | 2 +- ...erence_test.c => conference_simple_test.c} | 0 auto_tests/conference_test.c | 106 ++++++++++-------- auto_tests/monolith_test.cc | 8 +- 4 files changed, 63 insertions(+), 53 deletions(-) rename auto_tests/{simple_conference_test.c => conference_simple_test.c} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85231351..502a6172 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -389,6 +389,7 @@ auto_test(bootstrap) auto_test(conference) auto_test(conference_double_invite) auto_test(conference_peer_nick) +auto_test(conference_simple) auto_test(conference_two) auto_test(crypto MSVC_DONT_BUILD) auto_test(dht MSVC_DONT_BUILD) @@ -411,7 +412,6 @@ auto_test(save_load) auto_test(send_message) auto_test(set_name) auto_test(set_status_message) -auto_test(simple_conference) auto_test(skeleton) auto_test(tcp_relay) auto_test(tox_many) diff --git a/auto_tests/simple_conference_test.c b/auto_tests/conference_simple_test.c similarity index 100% rename from auto_tests/simple_conference_test.c rename to auto_tests/conference_simple_test.c diff --git a/auto_tests/conference_test.c b/auto_tests/conference_test.c index 9f8352a3..caa00356 100644 --- a/auto_tests/conference_test.c +++ b/auto_tests/conference_test.c @@ -24,7 +24,8 @@ #define NUM_GROUP_TOX 5 #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; @@ -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, - void *user_data) +static void handle_friend_connection_status( + Tox *tox, uint32_t friendnumber, TOX_CONNECTION connection_status, void *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, - size_t length, void *user_data) +static void handle_conference_invite( + 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; 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 void handle_conference_message(Tox *tox, uint32_t groupnumber, uint32_t peernumber, TOX_MESSAGE_TYPE type, - const uint8_t *message, size_t length, void *user_data) +static void handle_conference_message( + 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) { ++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) { 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)); - for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) { - tox_callback_conference_message(toxes[i], &handle_conference_message); - } + run_conference_tests(toxes, tox_index); - 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); - } - } + printf("tearing down toxes\n"); for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) { tox_kill(toxes[i]); diff --git a/auto_tests/monolith_test.cc b/auto_tests/monolith_test.cc index d89c7625..45d55958 100644 --- a/auto_tests/monolith_test.cc +++ b/auto_tests/monolith_test.cc @@ -33,6 +33,10 @@ namespace bootstrap_test { int main(void); #include "bootstrap_test.c" } // namespace bootstrap_test +namespace conference_simple_test { +int main(void); +#include "conference_simple_test.c" +} // namespace conference_simple_test namespace conference_test { int main(void); #include "conference_test.c" @@ -101,10 +105,6 @@ namespace set_status_message_test { int main(void); #include "set_status_message_test.c" } // namespace set_status_message_test -namespace simple_conference_test { -int main(void); -#include "simple_conference_test.c" -} // namespace simple_conference_test namespace skeleton_test { int main(void); #include "skeleton_test.c"