summaryrefslogtreecommitdiff
path: root/auto_tests/conference_test.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-02-18 17:50:50 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-02-18 21:32:28 +0000
commit3dc8cf6df8b80f213526884cafbbd493486366e5 (patch)
tree553b36ecd451c72ad85c7782ebbfd6a3ae41aaa7 /auto_tests/conference_test.c
parentd016eb3f0e808ce4b4736b5056bcd3daf9514f99 (diff)
Disable lan discovery in most tests.
Diffstat (limited to 'auto_tests/conference_test.c')
-rw-r--r--auto_tests/conference_test.c57
1 files changed, 20 insertions, 37 deletions
diff --git a/auto_tests/conference_test.c b/auto_tests/conference_test.c
index bd3ea8d0..72c81de3 100644
--- a/auto_tests/conference_test.c
+++ b/auto_tests/conference_test.c
@@ -21,10 +21,11 @@
21#include "helpers.h" 21#include "helpers.h"
22 22
23#define NUM_GROUP_TOX 5 23#define NUM_GROUP_TOX 5
24#define GROUP_MESSAGE "Install Gentoo"
24 25
25static void handle_self_connection_status(Tox *tox, TOX_CONNECTION connection_status, void *user_data) 26static void handle_self_connection_status(Tox *tox, TOX_CONNECTION connection_status, void *user_data)
26{ 27{
27 int id = *(int *)user_data; 28 const int id = *(int *)user_data;
28 29
29 if (connection_status != TOX_CONNECTION_NONE) { 30 if (connection_status != TOX_CONNECTION_NONE) {
30 printf("tox #%d: is now connected\n", id); 31 printf("tox #%d: is now connected\n", id);
@@ -36,7 +37,7 @@ static void handle_self_connection_status(Tox *tox, TOX_CONNECTION connection_st
36static void handle_friend_connection_status(Tox *tox, uint32_t friendnumber, TOX_CONNECTION connection_status, 37static void handle_friend_connection_status(Tox *tox, uint32_t friendnumber, TOX_CONNECTION connection_status,
37 void *user_data) 38 void *user_data)
38{ 39{
39 int id = *(int *)user_data; 40 const int id = *(int *)user_data;
40 41
41 if (connection_status != TOX_CONNECTION_NONE) { 42 if (connection_status != TOX_CONNECTION_NONE) {
42 printf("tox #%d: is now connected to friend %d\n", id, friendnumber); 43 printf("tox #%d: is now connected to friend %d\n", id, friendnumber);
@@ -48,7 +49,7 @@ static void handle_friend_connection_status(Tox *tox, uint32_t friendnumber, TOX
48static void handle_conference_invite(Tox *tox, uint32_t friendnumber, TOX_CONFERENCE_TYPE type, const uint8_t *data, 49static void handle_conference_invite(Tox *tox, uint32_t friendnumber, TOX_CONFERENCE_TYPE type, const uint8_t *data,
49 size_t length, void *user_data) 50 size_t length, void *user_data)
50{ 51{
51 int id = *(int *)user_data; 52 const int id = *(int *)user_data;
52 ck_assert_msg(type == TOX_CONFERENCE_TYPE_TEXT, "tox #%d: wrong conference type: %d", id, type); 53 ck_assert_msg(type == TOX_CONFERENCE_TYPE_TEXT, "tox #%d: wrong conference type: %d", id, type);
53 54
54 TOX_ERR_CONFERENCE_JOIN err; 55 TOX_ERR_CONFERENCE_JOIN err;
@@ -75,12 +76,12 @@ static unsigned int num_recv;
75static void handle_conference_message(Tox *tox, uint32_t groupnumber, uint32_t peernumber, TOX_MESSAGE_TYPE type, 76static void handle_conference_message(Tox *tox, uint32_t groupnumber, uint32_t peernumber, TOX_MESSAGE_TYPE type,
76 const uint8_t *message, size_t length, void *user_data) 77 const uint8_t *message, size_t length, void *user_data)
77{ 78{
78 if (length == (sizeof("Install Gentoo") - 1) && memcmp(message, "Install Gentoo", sizeof("Install Gentoo") - 1) == 0) { 79 if (length == (sizeof(GROUP_MESSAGE) - 1) && memcmp(message, GROUP_MESSAGE, sizeof(GROUP_MESSAGE) - 1) == 0) {
79 ++num_recv; 80 ++num_recv;
80 } 81 }
81} 82}
82 83
83START_TEST(test_many_group) 84static void test_many_group(void)
84{ 85{
85 const time_t test_start_time = time(nullptr); 86 const time_t test_start_time = time(nullptr);
86 87
@@ -102,18 +103,18 @@ START_TEST(test_many_group)
102 tox_callback_self_connection_status(toxes[i], &handle_self_connection_status); 103 tox_callback_self_connection_status(toxes[i], &handle_self_connection_status);
103 tox_callback_friend_connection_status(toxes[i], &handle_friend_connection_status); 104 tox_callback_friend_connection_status(toxes[i], &handle_friend_connection_status);
104 tox_callback_conference_invite(toxes[i], &handle_conference_invite); 105 tox_callback_conference_invite(toxes[i], &handle_conference_invite);
105 }
106 106
107 tox_options_free(opts); 107 if (i != 0) {
108 uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
109 tox_self_get_dht_id(toxes[0], dht_key);
110 const uint16_t dht_port = tox_self_get_udp_port(toxes[0], nullptr);
108 111
109 { 112 tox_bootstrap(toxes[i], "localhost", dht_port, dht_key, nullptr);
110 TOX_ERR_GET_PORT error; 113 }
111 const uint16_t port = tox_self_get_udp_port(toxes[0], &error);
112 ck_assert_msg(33445 <= port && port <= 33545,
113 "First Tox instance did not bind to udp port inside [33445, 33545].\n");
114 ck_assert_msg(error == TOX_ERR_GET_PORT_OK, "wrong error");
115 } 114 }
116 115
116 tox_options_free(opts);
117
117 printf("creating a chain of friends\n"); 118 printf("creating a chain of friends\n");
118 119
119 for (unsigned i = 1; i < NUM_GROUP_TOX; ++i) { 120 for (unsigned i = 1; i < NUM_GROUP_TOX; ++i) {
@@ -208,8 +209,8 @@ START_TEST(test_many_group)
208 TOX_ERR_CONFERENCE_SEND_MESSAGE err; 209 TOX_ERR_CONFERENCE_SEND_MESSAGE err;
209 ck_assert_msg( 210 ck_assert_msg(
210 tox_conference_send_message( 211 tox_conference_send_message(
211 toxes[rand() % NUM_GROUP_TOX], 0, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)"Install Gentoo", 212 toxes[rand() % NUM_GROUP_TOX], 0, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)GROUP_MESSAGE,
212 sizeof("Install Gentoo") - 1, &err) != 0, "Failed to send group message."); 213 sizeof(GROUP_MESSAGE) - 1, &err) != 0, "Failed to send group message.");
213 ck_assert_msg( 214 ck_assert_msg(
214 err == TOX_ERR_CONFERENCE_SEND_MESSAGE_OK, "Failed to send group message."); 215 err == TOX_ERR_CONFERENCE_SEND_MESSAGE_OK, "Failed to send group message.");
215 num_recv = 0; 216 num_recv = 0;
@@ -236,7 +237,7 @@ START_TEST(test_many_group)
236 c_sleep(50); 237 c_sleep(50);
237 } 238 }
238 239
239 for (unsigned i = 0; i < (k - 1); ++i) { 240 for (unsigned i = 0; i < k - 1; ++i) {
240 uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr); 241 uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr);
241 ck_assert_msg(peer_count == (k - 1), "\n\tBad number of group peers (post check)." 242 ck_assert_msg(peer_count == (k - 1), "\n\tBad number of group peers (post check)."
242 "\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n", 243 "\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n",
@@ -250,29 +251,11 @@ START_TEST(test_many_group)
250 251
251 printf("test_many_group succeeded, took %d seconds\n", (int)(time(nullptr) - test_start_time)); 252 printf("test_many_group succeeded, took %d seconds\n", (int)(time(nullptr) - test_start_time));
252} 253}
253END_TEST
254
255static Suite *tox_suite(void)
256{
257 Suite *s = suite_create("Tox conference");
258
259 DEFTESTCASE_SLOW(many_group, 80);
260
261 return s;
262}
263 254
264int main(int argc, char *argv[]) 255int main(int argc, char *argv[])
265{ 256{
266 srand((unsigned int) time(nullptr)); 257 setvbuf(stdout, nullptr, _IONBF, 0);
267
268 Suite *tox = tox_suite();
269 SRunner *test_runner = srunner_create(tox);
270
271 int number_failed = 0;
272 srunner_run_all(test_runner, CK_NORMAL);
273 number_failed = srunner_ntests_failed(test_runner);
274
275 srunner_free(test_runner);
276 258
277 return number_failed; 259 test_many_group();
260 return 0;
278} 261}