diff options
Diffstat (limited to 'auto_tests')
25 files changed, 202 insertions, 226 deletions
diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c index 2ae94618..b14f53f2 100644 --- a/auto_tests/TCP_test.c +++ b/auto_tests/TCP_test.c | |||
@@ -771,6 +771,8 @@ static Suite *TCP_suite(void) | |||
771 | 771 | ||
772 | int main(int argc, char *argv[]) | 772 | int main(int argc, char *argv[]) |
773 | { | 773 | { |
774 | setvbuf(stdout, nullptr, _IONBF, 0); | ||
775 | |||
774 | srand((unsigned int) time(nullptr)); | 776 | srand((unsigned int) time(nullptr)); |
775 | 777 | ||
776 | Suite *TCP = TCP_suite(); | 778 | Suite *TCP = TCP_suite(); |
diff --git a/auto_tests/bootstrap_test.c b/auto_tests/bootstrap_test.c index 488bd48e..12cfabcf 100644 --- a/auto_tests/bootstrap_test.c +++ b/auto_tests/bootstrap_test.c | |||
@@ -13,22 +13,24 @@ static uint8_t const key[] = { | |||
13 | 13 | ||
14 | int main(void) | 14 | int main(void) |
15 | { | 15 | { |
16 | Tox *tox = tox_new_log(nullptr, nullptr, nullptr); | 16 | setvbuf(stdout, nullptr, _IONBF, 0); |
17 | 17 | ||
18 | tox_bootstrap(tox, "node.tox.biribiri.org", 33445, key, nullptr); | 18 | Tox *tox_udp = tox_new_log(nullptr, nullptr, nullptr); |
19 | |||
20 | tox_bootstrap(tox_udp, "node.tox.biribiri.org", 33445, key, nullptr); | ||
19 | 21 | ||
20 | printf("Waiting for connection"); | 22 | printf("Waiting for connection"); |
21 | 23 | ||
22 | while (tox_self_get_connection_status(tox) == TOX_CONNECTION_NONE) { | 24 | while (tox_self_get_connection_status(tox_udp) == TOX_CONNECTION_NONE) { |
23 | printf("."); | 25 | printf("."); |
24 | fflush(stdout); | 26 | fflush(stdout); |
25 | 27 | ||
26 | tox_iterate(tox, nullptr); | 28 | tox_iterate(tox_udp, nullptr); |
27 | c_sleep(1000); | 29 | c_sleep(ITERATION_INTERVAL); |
28 | } | 30 | } |
29 | 31 | ||
30 | printf("Connection: %d\n", tox_self_get_connection_status(tox)); | 32 | printf("Connection (UDP): %d\n", tox_self_get_connection_status(tox_udp)); |
31 | 33 | ||
32 | tox_kill(tox); | 34 | tox_kill(tox_udp); |
33 | return 0; | 35 | return 0; |
34 | } | 36 | } |
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 | ||
25 | static void handle_self_connection_status(Tox *tox, TOX_CONNECTION connection_status, void *user_data) | 26 | static 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 | |||
36 | static void handle_friend_connection_status(Tox *tox, uint32_t friendnumber, TOX_CONNECTION connection_status, | 37 | static 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 | |||
48 | static void handle_conference_invite(Tox *tox, uint32_t friendnumber, TOX_CONFERENCE_TYPE type, const uint8_t *data, | 49 | static 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; | |||
75 | static void handle_conference_message(Tox *tox, uint32_t groupnumber, uint32_t peernumber, TOX_MESSAGE_TYPE type, | 76 | static 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 | ||
83 | START_TEST(test_many_group) | 84 | static 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 | } |
253 | END_TEST | ||
254 | |||
255 | static 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 | ||
264 | int main(int argc, char *argv[]) | 255 | int 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 | } |
diff --git a/auto_tests/crypto_test.c b/auto_tests/crypto_test.c index 045cd7ab..e2c4e307 100644 --- a/auto_tests/crypto_test.c +++ b/auto_tests/crypto_test.c | |||
@@ -356,6 +356,7 @@ static Suite *crypto_suite(void) | |||
356 | 356 | ||
357 | int main(int argc, char *argv[]) | 357 | int main(int argc, char *argv[]) |
358 | { | 358 | { |
359 | setvbuf(stdout, nullptr, _IONBF, 0); | ||
359 | srand((unsigned int) time(nullptr)); | 360 | srand((unsigned int) time(nullptr)); |
360 | 361 | ||
361 | Suite *crypto = crypto_suite(); | 362 | Suite *crypto = crypto_suite(); |
diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c index 10c9c7bf..516e1a8e 100644 --- a/auto_tests/dht_test.c +++ b/auto_tests/dht_test.c | |||
@@ -801,6 +801,7 @@ static Suite *dht_suite(void) | |||
801 | 801 | ||
802 | int main(int argc, char *argv[]) | 802 | int main(int argc, char *argv[]) |
803 | { | 803 | { |
804 | setvbuf(stdout, nullptr, _IONBF, 0); | ||
804 | srand((unsigned int) time(nullptr)); | 805 | srand((unsigned int) time(nullptr)); |
805 | 806 | ||
806 | Suite *dht = dht_suite(); | 807 | Suite *dht = dht_suite(); |
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index 61b00992..41769dad 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c | |||
@@ -206,6 +206,7 @@ static Suite *encryptsave_suite(void) | |||
206 | 206 | ||
207 | int main(int argc, char *argv[]) | 207 | int main(int argc, char *argv[]) |
208 | { | 208 | { |
209 | setvbuf(stdout, nullptr, _IONBF, 0); | ||
209 | srand((unsigned int) time(nullptr)); | 210 | srand((unsigned int) time(nullptr)); |
210 | 211 | ||
211 | Suite *encryptsave = encryptsave_suite(); | 212 | Suite *encryptsave = encryptsave_suite(); |
diff --git a/auto_tests/file_saving_test.c b/auto_tests/file_saving_test.c index 5ed74c9f..11c81ad2 100644 --- a/auto_tests/file_saving_test.c +++ b/auto_tests/file_saving_test.c | |||
@@ -27,17 +27,16 @@ | |||
27 | #include <stdlib.h> | 27 | #include <stdlib.h> |
28 | #include <string.h> | 28 | #include <string.h> |
29 | 29 | ||
30 | #include "../toxcore/tox.h" | 30 | #include "helpers.h" |
31 | #include "../toxencryptsave/toxencryptsave.h" | ||
32 | 31 | ||
33 | #include "../toxcore/ccompat.h" | 32 | #include "../toxencryptsave/toxencryptsave.h" |
34 | 33 | ||
35 | static const char *pphrase = "bar", *name = "foo", *savefile = "./save"; | 34 | static const char *pphrase = "bar", *name = "foo", *savefile = "./save"; |
36 | 35 | ||
37 | static void save_data_encrypted(void) | 36 | static void save_data_encrypted(void) |
38 | { | 37 | { |
39 | struct Tox_Options *options = tox_options_new(nullptr); | 38 | struct Tox_Options *options = tox_options_new(nullptr); |
40 | Tox *t = tox_new(options, nullptr); | 39 | Tox *t = tox_new_log(options, nullptr, nullptr); |
41 | tox_options_free(options); | 40 | tox_options_free(options); |
42 | 41 | ||
43 | tox_self_set_name(t, (const uint8_t *)name, strlen(name), nullptr); | 42 | tox_self_set_name(t, (const uint8_t *)name, strlen(name), nullptr); |
@@ -97,7 +96,7 @@ static void load_data_decrypted(void) | |||
97 | 96 | ||
98 | TOX_ERR_NEW err; | 97 | TOX_ERR_NEW err; |
99 | 98 | ||
100 | Tox *t = tox_new(options, &err); | 99 | Tox *t = tox_new_log(options, &err, nullptr); |
101 | 100 | ||
102 | tox_options_free(options); | 101 | tox_options_free(options); |
103 | 102 | ||
@@ -123,6 +122,7 @@ static void load_data_decrypted(void) | |||
123 | 122 | ||
124 | int main(void) | 123 | int main(void) |
125 | { | 124 | { |
125 | setvbuf(stdout, nullptr, _IONBF, 0); | ||
126 | save_data_encrypted(); | 126 | save_data_encrypted(); |
127 | load_data_decrypted(); | 127 | load_data_decrypted(); |
128 | 128 | ||
diff --git a/auto_tests/helpers.h b/auto_tests/helpers.h index 72f57ead..c5a4686d 100644 --- a/auto_tests/helpers.h +++ b/auto_tests/helpers.h | |||
@@ -54,17 +54,17 @@ static void print_debug_log(Tox *m, TOX_LOG_LEVEL level, const char *path, uint3 | |||
54 | fprintf(stderr, "[#%d] %s %s:%d\t%s:\t%s\n", index, tox_log_level_name(level), file, line, func, message); | 54 | fprintf(stderr, "[#%d] %s %s:%d\t%s:\t%s\n", index, tox_log_level_name(level), file, line, func, message); |
55 | } | 55 | } |
56 | 56 | ||
57 | Tox *tox_new_log(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data) | 57 | Tox *tox_new_log_lan(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data, bool lan_discovery) |
58 | { | 58 | { |
59 | struct Tox_Options *log_options = options; | 59 | struct Tox_Options *log_options = options; |
60 | 60 | ||
61 | if (log_options == nullptr) { | 61 | if (log_options == nullptr) { |
62 | log_options = tox_options_new(nullptr); | 62 | log_options = tox_options_new(nullptr); |
63 | // tox_options_set_local_discovery_enabled(log_options, false); | ||
64 | } | 63 | } |
65 | 64 | ||
66 | assert(log_options != nullptr); | 65 | assert(log_options != nullptr); |
67 | 66 | ||
67 | tox_options_set_local_discovery_enabled(log_options, lan_discovery); | ||
68 | tox_options_set_log_callback(log_options, &print_debug_log); | 68 | tox_options_set_log_callback(log_options, &print_debug_log); |
69 | tox_options_set_log_user_data(log_options, log_user_data); | 69 | tox_options_set_log_user_data(log_options, log_user_data); |
70 | Tox *tox = tox_new(log_options, err); | 70 | Tox *tox = tox_new(log_options, err); |
@@ -76,4 +76,9 @@ Tox *tox_new_log(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_d | |||
76 | return tox; | 76 | return tox; |
77 | } | 77 | } |
78 | 78 | ||
79 | Tox *tox_new_log(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data) | ||
80 | { | ||
81 | return tox_new_log_lan(options, err, log_user_data, false); | ||
82 | } | ||
83 | |||
79 | #endif // TOXCORE_TEST_HELPERS_H | 84 | #endif // TOXCORE_TEST_HELPERS_H |
diff --git a/auto_tests/lan_discovery_test.c b/auto_tests/lan_discovery_test.c index 6918c232..237b51bb 100644 --- a/auto_tests/lan_discovery_test.c +++ b/auto_tests/lan_discovery_test.c | |||
@@ -6,8 +6,9 @@ | |||
6 | 6 | ||
7 | int main(void) | 7 | int main(void) |
8 | { | 8 | { |
9 | Tox *tox1 = tox_new_log(nullptr, nullptr, nullptr); | 9 | setvbuf(stdout, nullptr, _IONBF, 0); |
10 | Tox *tox2 = tox_new_log(nullptr, nullptr, nullptr); | 10 | Tox *tox1 = tox_new_log_lan(nullptr, nullptr, nullptr, /* lan_discovery */true); |
11 | Tox *tox2 = tox_new_log_lan(nullptr, nullptr, nullptr, /* lan_discovery */true); | ||
11 | 12 | ||
12 | printf("Waiting for LAN discovery"); | 13 | printf("Waiting for LAN discovery"); |
13 | 14 | ||
diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c index de5aa7dd..9d797b55 100644 --- a/auto_tests/messenger_test.c +++ b/auto_tests/messenger_test.c | |||
@@ -348,6 +348,8 @@ static Suite *messenger_suite(void) | |||
348 | 348 | ||
349 | int main(int argc, char *argv[]) | 349 | int main(int argc, char *argv[]) |
350 | { | 350 | { |
351 | setvbuf(stdout, nullptr, _IONBF, 0); | ||
352 | |||
351 | friend_id = hex_string_to_bin(friend_id_str); | 353 | friend_id = hex_string_to_bin(friend_id_str); |
352 | good_id_a = hex_string_to_bin(good_id_a_str); | 354 | good_id_a = hex_string_to_bin(good_id_a_str); |
353 | good_id_b = hex_string_to_bin(good_id_b_str); | 355 | good_id_b = hex_string_to_bin(good_id_b_str); |
diff --git a/auto_tests/network_test.c b/auto_tests/network_test.c index f05f0dbd..15757d4d 100644 --- a/auto_tests/network_test.c +++ b/auto_tests/network_test.c | |||
@@ -165,6 +165,7 @@ static Suite *network_suite(void) | |||
165 | 165 | ||
166 | int main(void) | 166 | int main(void) |
167 | { | 167 | { |
168 | setvbuf(stdout, nullptr, _IONBF, 0); | ||
168 | srand((unsigned int) time(nullptr)); | 169 | srand((unsigned int) time(nullptr)); |
169 | 170 | ||
170 | Suite *network = network_suite(); | 171 | Suite *network = network_suite(); |
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index aa505a0b..760a7800 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c | |||
@@ -538,6 +538,7 @@ static Suite *onion_suite(void) | |||
538 | 538 | ||
539 | int main(int argc, char *argv[]) | 539 | int main(int argc, char *argv[]) |
540 | { | 540 | { |
541 | setvbuf(stdout, nullptr, _IONBF, 0); | ||
541 | srand((unsigned int) time(nullptr)); | 542 | srand((unsigned int) time(nullptr)); |
542 | 543 | ||
543 | Suite *onion = onion_suite(); | 544 | Suite *onion = onion_suite(); |
diff --git a/auto_tests/resource_leak_test.c b/auto_tests/resource_leak_test.c index 65a6dbb8..1bb70d9a 100644 --- a/auto_tests/resource_leak_test.c +++ b/auto_tests/resource_leak_test.c | |||
@@ -21,12 +21,12 @@ | |||
21 | 21 | ||
22 | int main(void) | 22 | int main(void) |
23 | { | 23 | { |
24 | int i; | 24 | setvbuf(stdout, nullptr, _IONBF, 0); |
25 | 25 | ||
26 | puts("Warming up: creating/deleting 10 tox instances"); | 26 | puts("Warming up: creating/deleting 10 tox instances"); |
27 | 27 | ||
28 | // Warm-up. | 28 | // Warm-up. |
29 | for (i = 0; i < 10; i++) { | 29 | for (int i = 0; i < 10; i++) { |
30 | Tox *tox = tox_new(nullptr, nullptr); | 30 | Tox *tox = tox_new(nullptr, nullptr); |
31 | tox_iterate(tox, nullptr); | 31 | tox_iterate(tox, nullptr); |
32 | tox_kill(tox); | 32 | tox_kill(tox); |
@@ -38,7 +38,7 @@ int main(void) | |||
38 | #endif | 38 | #endif |
39 | printf("Creating/deleting %d tox instances\n", ITERATIONS); | 39 | printf("Creating/deleting %d tox instances\n", ITERATIONS); |
40 | 40 | ||
41 | for (i = 0; i < ITERATIONS; i++) { | 41 | for (int i = 0; i < ITERATIONS; i++) { |
42 | Tox *tox = tox_new(nullptr, nullptr); | 42 | Tox *tox = tox_new(nullptr, nullptr); |
43 | tox_iterate(tox, nullptr); | 43 | tox_iterate(tox, nullptr); |
44 | tox_kill(tox); | 44 | tox_kill(tox); |
diff --git a/auto_tests/save_friend_test.c b/auto_tests/save_friend_test.c index a7a62c87..ad4bd338 100644 --- a/auto_tests/save_friend_test.c +++ b/auto_tests/save_friend_test.c | |||
@@ -49,10 +49,19 @@ void statuschange_callback(Tox *tox, uint32_t friend_number, const uint8_t *mess | |||
49 | 49 | ||
50 | int main(int argc, char *argv[]) | 50 | int main(int argc, char *argv[]) |
51 | { | 51 | { |
52 | Tox *tox1 = tox_new_log(nullptr, nullptr, nullptr); | 52 | setvbuf(stdout, nullptr, _IONBF, 0); |
53 | Tox *tox2 = tox_new_log(nullptr, nullptr, nullptr); | ||
54 | 53 | ||
55 | struct test_data to_compare = { { 0 } }; | 54 | Tox *const tox1 = tox_new_log(nullptr, nullptr, nullptr); |
55 | Tox *const tox2 = tox_new_log(nullptr, nullptr, nullptr); | ||
56 | |||
57 | printf("bootstrapping tox2 off tox1\n"); | ||
58 | uint8_t dht_key[TOX_PUBLIC_KEY_SIZE]; | ||
59 | tox_self_get_dht_id(tox1, dht_key); | ||
60 | const uint16_t dht_port = tox_self_get_udp_port(tox1, nullptr); | ||
61 | |||
62 | tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr); | ||
63 | |||
64 | struct test_data to_compare = {{0}}; | ||
56 | 65 | ||
57 | uint8_t public_key[TOX_PUBLIC_KEY_SIZE]; | 66 | uint8_t public_key[TOX_PUBLIC_KEY_SIZE]; |
58 | tox_self_get_public_key(tox1, public_key); | 67 | tox_self_get_public_key(tox1, public_key); |
@@ -104,11 +113,11 @@ int main(int argc, char *argv[]) | |||
104 | VLA(uint8_t, savedata, save_size); | 113 | VLA(uint8_t, savedata, save_size); |
105 | tox_get_savedata(tox1, savedata); | 114 | tox_get_savedata(tox1, savedata); |
106 | 115 | ||
107 | struct Tox_Options *options = tox_options_new(nullptr); | 116 | struct Tox_Options *const options = tox_options_new(nullptr); |
108 | tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE); | 117 | tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE); |
109 | tox_options_set_savedata_data(options, savedata, save_size); | 118 | tox_options_set_savedata_data(options, savedata, save_size); |
110 | 119 | ||
111 | Tox *tox_to_compare = tox_new(options, nullptr); | 120 | Tox *const tox_to_compare = tox_new_log(options, nullptr, nullptr); |
112 | 121 | ||
113 | tox_friend_get_name(tox_to_compare, 0, to_compare.name, nullptr); | 122 | tox_friend_get_name(tox_to_compare, 0, to_compare.name, nullptr); |
114 | tox_friend_get_status_message(tox_to_compare, 0, to_compare.status_message, nullptr); | 123 | tox_friend_get_status_message(tox_to_compare, 0, to_compare.status_message, nullptr); |
diff --git a/auto_tests/self_conference_title_change_test.c b/auto_tests/self_conference_title_change_test.c index a8ba7aab..706c1338 100644 --- a/auto_tests/self_conference_title_change_test.c +++ b/auto_tests/self_conference_title_change_test.c | |||
@@ -48,13 +48,15 @@ static void cbtitlechange(Tox *tox, uint32_t conference_number, uint32_t peer_nu | |||
48 | 48 | ||
49 | int main(void) | 49 | int main(void) |
50 | { | 50 | { |
51 | setvbuf(stdout, nullptr, _IONBF, 0); | ||
52 | |||
51 | uint32_t conference_number; | 53 | uint32_t conference_number; |
52 | struct Tox_Options *to = tox_options_new(nullptr); | 54 | struct Tox_Options *to = tox_options_new(nullptr); |
53 | Tox *t; | 55 | Tox *t; |
54 | TOX_ERR_CONFERENCE_NEW conference_err; | 56 | TOX_ERR_CONFERENCE_NEW conference_err; |
55 | TOX_ERR_CONFERENCE_TITLE title_err; | 57 | TOX_ERR_CONFERENCE_TITLE title_err; |
56 | 58 | ||
57 | t = tox_new(to, nullptr); | 59 | t = tox_new_log(to, nullptr, nullptr); |
58 | tox_options_free(to); | 60 | tox_options_free(to); |
59 | 61 | ||
60 | tox_callback_conference_title(t, &cbtitlechange); | 62 | tox_callback_conference_title(t, &cbtitlechange); |
diff --git a/auto_tests/selfname_change_conference_test.c b/auto_tests/selfname_change_conference_test.c index cd2c2b22..c4e004de 100644 --- a/auto_tests/selfname_change_conference_test.c +++ b/auto_tests/selfname_change_conference_test.c | |||
@@ -59,12 +59,14 @@ static void cbconfmembers(Tox *tox, uint32_t conference_number, uint32_t peer_nu | |||
59 | 59 | ||
60 | int main(void) | 60 | int main(void) |
61 | { | 61 | { |
62 | setvbuf(stdout, nullptr, _IONBF, 0); | ||
63 | |||
62 | struct Tox_Options *to = tox_options_new(nullptr); | 64 | struct Tox_Options *to = tox_options_new(nullptr); |
63 | Tox *t; | 65 | Tox *t; |
64 | TOX_ERR_CONFERENCE_NEW conference_err; | 66 | TOX_ERR_CONFERENCE_NEW conference_err; |
65 | TOX_ERR_SET_INFO name_err; | 67 | TOX_ERR_SET_INFO name_err; |
66 | 68 | ||
67 | t = tox_new(to, nullptr); | 69 | t = tox_new_log(to, nullptr, nullptr); |
68 | tox_options_free(to); | 70 | tox_options_free(to); |
69 | 71 | ||
70 | tox_callback_conference_namelist_change(t, cbconfmembers); | 72 | tox_callback_conference_namelist_change(t, cbconfmembers); |
diff --git a/auto_tests/simple_conference_test.c b/auto_tests/simple_conference_test.c index b6c19d13..ad17d02e 100644 --- a/auto_tests/simple_conference_test.c +++ b/auto_tests/simple_conference_test.c | |||
@@ -103,6 +103,8 @@ static void handle_conference_namelist_change(Tox *tox, uint32_t conference_numb | |||
103 | 103 | ||
104 | int main() | 104 | int main() |
105 | { | 105 | { |
106 | setvbuf(stdout, nullptr, _IONBF, 0); | ||
107 | |||
106 | State state1 = {1}; | 108 | State state1 = {1}; |
107 | State state2 = {2}; | 109 | State state2 = {2}; |
108 | State state3 = {3}; | 110 | State state3 = {3}; |
@@ -123,6 +125,14 @@ int main() | |||
123 | tox_self_get_public_key(tox2, key); | 125 | tox_self_get_public_key(tox2, key); |
124 | tox_friend_add_norequest(tox3, key, nullptr); // tox3 -> tox2 | 126 | tox_friend_add_norequest(tox3, key, nullptr); // tox3 -> tox2 |
125 | 127 | ||
128 | printf("bootstrapping tox2 and tox3 off tox1\n"); | ||
129 | uint8_t dht_key[TOX_PUBLIC_KEY_SIZE]; | ||
130 | tox_self_get_dht_id(tox1, dht_key); | ||
131 | const uint16_t dht_port = tox_self_get_udp_port(tox1, nullptr); | ||
132 | |||
133 | tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr); | ||
134 | tox_bootstrap(tox3, "localhost", dht_port, dht_key, nullptr); | ||
135 | |||
126 | // Connection callbacks. | 136 | // Connection callbacks. |
127 | tox_callback_self_connection_status(tox1, handle_self_connection_status); | 137 | tox_callback_self_connection_status(tox1, handle_self_connection_status); |
128 | tox_callback_self_connection_status(tox2, handle_self_connection_status); | 138 | tox_callback_self_connection_status(tox2, handle_self_connection_status); |
diff --git a/auto_tests/skeleton_test.c b/auto_tests/skeleton_test.c index d52faba4..ac9291d0 100644 --- a/auto_tests/skeleton_test.c +++ b/auto_tests/skeleton_test.c | |||
@@ -31,6 +31,8 @@ static Suite *creativesuitenamegoeshere_suite(void) | |||
31 | 31 | ||
32 | int main(int argc, char *argv[]) | 32 | int main(int argc, char *argv[]) |
33 | { | 33 | { |
34 | setvbuf(stdout, nullptr, _IONBF, 0); | ||
35 | |||
34 | srand((unsigned int) time(nullptr)); | 36 | srand((unsigned int) time(nullptr)); |
35 | 37 | ||
36 | Suite *creativesuitenamegoeshere = creativesuitenamegoeshere_suite(); | 38 | Suite *creativesuitenamegoeshere = creativesuitenamegoeshere_suite(); |
diff --git a/auto_tests/tcp_relay_test.c b/auto_tests/tcp_relay_test.c new file mode 100644 index 00000000..4cda94f2 --- /dev/null +++ b/auto_tests/tcp_relay_test.c | |||
@@ -0,0 +1,40 @@ | |||
1 | #ifndef _XOPEN_SOURCE | ||
2 | #define _XOPEN_SOURCE 600 | ||
3 | #endif | ||
4 | |||
5 | #include "helpers.h" | ||
6 | |||
7 | static uint8_t const key[] = { | ||
8 | 0xF4, 0x04, 0xAB, 0xAA, 0x1C, 0x99, 0xA9, 0xD3, | ||
9 | 0x7D, 0x61, 0xAB, 0x54, 0x89, 0x8F, 0x56, 0x79, | ||
10 | 0x3E, 0x1D, 0xEF, 0x8B, 0xD4, 0x6B, 0x10, 0x38, | ||
11 | 0xB9, 0xD8, 0x22, 0xE8, 0x46, 0x0F, 0xAB, 0x67, | ||
12 | }; | ||
13 | |||
14 | int main(void) | ||
15 | { | ||
16 | setvbuf(stdout, nullptr, _IONBF, 0); | ||
17 | |||
18 | struct Tox_Options *opts = tox_options_new(nullptr); | ||
19 | tox_options_set_udp_enabled(opts, false); | ||
20 | Tox *tox_tcp = tox_new_log(opts, nullptr, nullptr); | ||
21 | tox_options_free(opts); | ||
22 | |||
23 | tox_bootstrap(tox_tcp, "node.tox.biribiri.org", 33445, key, nullptr); | ||
24 | tox_add_tcp_relay(tox_tcp, "node.tox.biribiri.org", 33445, key, nullptr); | ||
25 | |||
26 | printf("Waiting for connection"); | ||
27 | |||
28 | while (tox_self_get_connection_status(tox_tcp) == TOX_CONNECTION_NONE) { | ||
29 | printf("."); | ||
30 | fflush(stdout); | ||
31 | |||
32 | tox_iterate(tox_tcp, nullptr); | ||
33 | c_sleep(ITERATION_INTERVAL); | ||
34 | } | ||
35 | |||
36 | printf("Connection (TCP): %d\n", tox_self_get_connection_status(tox_tcp)); | ||
37 | |||
38 | tox_kill(tox_tcp); | ||
39 | return 0; | ||
40 | } | ||
diff --git a/auto_tests/tox_many_tcp_test.c b/auto_tests/tox_many_tcp_test.c index e4309db7..dc993987 100644 --- a/auto_tests/tox_many_tcp_test.c +++ b/auto_tests/tox_many_tcp_test.c | |||
@@ -274,6 +274,8 @@ static Suite *tox_suite(void) | |||
274 | 274 | ||
275 | int main(int argc, char *argv[]) | 275 | int main(int argc, char *argv[]) |
276 | { | 276 | { |
277 | setvbuf(stdout, nullptr, _IONBF, 0); | ||
278 | |||
277 | srand((unsigned int) time(nullptr)); | 279 | srand((unsigned int) time(nullptr)); |
278 | 280 | ||
279 | Suite *tox = tox_suite(); | 281 | Suite *tox = tox_suite(); |
diff --git a/auto_tests/tox_many_test.c b/auto_tests/tox_many_test.c index bacaaff8..a797d99c 100644 --- a/auto_tests/tox_many_test.c +++ b/auto_tests/tox_many_test.c | |||
@@ -22,10 +22,6 @@ | |||
22 | 22 | ||
23 | static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) | 23 | static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) |
24 | { | 24 | { |
25 | if (*((uint32_t *)userdata) != 974536) { | ||
26 | return; | ||
27 | } | ||
28 | |||
29 | if (length == 7 && memcmp("Gentoo", data, 7) == 0) { | 25 | if (length == 7 && memcmp("Gentoo", data, 7) == 0) { |
30 | tox_friend_add_norequest(m, public_key, nullptr); | 26 | tox_friend_add_norequest(m, public_key, nullptr); |
31 | } | 27 | } |
@@ -35,29 +31,19 @@ static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8 | |||
35 | #define NUM_TOXES 90 | 31 | #define NUM_TOXES 90 |
36 | #define NUM_FRIENDS 50 | 32 | #define NUM_FRIENDS 50 |
37 | 33 | ||
38 | START_TEST(test_many_clients) | 34 | static void test_many_clients(void) |
39 | { | 35 | { |
40 | long long unsigned int cur_time = time(nullptr); | 36 | time_t cur_time = time(nullptr); |
41 | Tox *toxes[NUM_TOXES]; | 37 | Tox *toxes[NUM_TOXES]; |
42 | uint32_t index[NUM_TOXES]; | 38 | uint32_t index[NUM_TOXES]; |
43 | uint32_t i, j; | ||
44 | uint32_t to_comp = 974536; | ||
45 | 39 | ||
46 | for (i = 0; i < NUM_TOXES; ++i) { | 40 | for (uint32_t i = 0; i < NUM_TOXES; ++i) { |
47 | index[i] = i + 1; | 41 | index[i] = i + 1; |
48 | toxes[i] = tox_new_log(nullptr, nullptr, &index[i]); | 42 | toxes[i] = tox_new_log(nullptr, nullptr, &index[i]); |
49 | ck_assert_msg(toxes[i] != nullptr, "Failed to create tox instances %u", i); | 43 | ck_assert_msg(toxes[i] != nullptr, "failed to create tox instances %u", i); |
50 | tox_callback_friend_request(toxes[i], accept_friend_request); | 44 | tox_callback_friend_request(toxes[i], accept_friend_request); |
51 | } | 45 | } |
52 | 46 | ||
53 | { | ||
54 | TOX_ERR_GET_PORT error; | ||
55 | uint16_t port = tox_self_get_udp_port(toxes[0], &error); | ||
56 | ck_assert_msg(33445 <= port && port <= 33545, | ||
57 | "First Tox instance did not bind to udp port inside [33445, 33545].\n"); | ||
58 | ck_assert_msg(error == TOX_ERR_GET_PORT_OK, "wrong error"); | ||
59 | } | ||
60 | |||
61 | struct { | 47 | struct { |
62 | uint16_t tox1; | 48 | uint16_t tox1; |
63 | uint16_t tox2; | 49 | uint16_t tox2; |
@@ -65,20 +51,20 @@ START_TEST(test_many_clients) | |||
65 | 51 | ||
66 | uint8_t address[TOX_ADDRESS_SIZE]; | 52 | uint8_t address[TOX_ADDRESS_SIZE]; |
67 | 53 | ||
68 | unsigned int num_f = 0; | 54 | uint32_t num_f = 0; |
69 | 55 | ||
70 | for (i = 0; i < NUM_TOXES; ++i) { | 56 | for (uint32_t i = 0; i < NUM_TOXES; ++i) { |
71 | num_f += tox_self_get_friend_list_size(toxes[i]); | 57 | num_f += tox_self_get_friend_list_size(toxes[i]); |
72 | } | 58 | } |
73 | 59 | ||
74 | ck_assert_msg(num_f == 0, "bad num friends: %u", num_f); | 60 | ck_assert_msg(num_f == 0, "bad num friends: %u", num_f); |
75 | 61 | ||
76 | for (i = 0; i < NUM_FRIENDS; ++i) { | 62 | for (uint32_t i = 0; i < NUM_FRIENDS; ++i) { |
77 | loop_top: | 63 | loop_top: |
78 | pairs[i].tox1 = rand() % NUM_TOXES; | 64 | pairs[i].tox1 = rand() % NUM_TOXES; |
79 | pairs[i].tox2 = (pairs[i].tox1 + rand() % (NUM_TOXES - 1) + 1) % NUM_TOXES; | 65 | pairs[i].tox2 = (pairs[i].tox1 + rand() % (NUM_TOXES - 1) + 1) % NUM_TOXES; |
80 | 66 | ||
81 | for (j = 0; j < i; ++j) { | 67 | for (uint32_t j = 0; j < i; ++j) { |
82 | if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2) { | 68 | if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2) { |
83 | goto loop_top; | 69 | goto loop_top; |
84 | } | 70 | } |
@@ -93,10 +79,16 @@ loop_top: | |||
93 | goto loop_top; | 79 | goto loop_top; |
94 | } | 80 | } |
95 | 81 | ||
96 | ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "Failed to add friend error code: %i", test); | 82 | uint8_t dht_key[TOX_PUBLIC_KEY_SIZE]; |
83 | tox_self_get_dht_id(toxes[pairs[i].tox1], dht_key); | ||
84 | const uint16_t dht_port = tox_self_get_udp_port(toxes[pairs[i].tox1], nullptr); | ||
85 | |||
86 | tox_bootstrap(toxes[pairs[i].tox2], "localhost", dht_port, dht_key, nullptr); | ||
87 | |||
88 | ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "failed to add friend error code: %i", test); | ||
97 | } | 89 | } |
98 | 90 | ||
99 | for (i = 0; i < NUM_TOXES; ++i) { | 91 | for (uint32_t i = 0; i < NUM_TOXES; ++i) { |
100 | num_f += tox_self_get_friend_list_size(toxes[i]); | 92 | num_f += tox_self_get_friend_list_size(toxes[i]); |
101 | } | 93 | } |
102 | 94 | ||
@@ -107,8 +99,8 @@ loop_top: | |||
107 | while (1) { | 99 | while (1) { |
108 | uint16_t counter = 0; | 100 | uint16_t counter = 0; |
109 | 101 | ||
110 | for (i = 0; i < NUM_TOXES; ++i) { | 102 | for (uint32_t i = 0; i < NUM_TOXES; ++i) { |
111 | for (j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j) { | 103 | for (uint32_t j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j) { |
112 | if (tox_friend_get_connection_status(toxes[i], j, nullptr) == TOX_CONNECTION_UDP) { | 104 | if (tox_friend_get_connection_status(toxes[i], j, nullptr) == TOX_CONNECTION_UDP) { |
113 | ++counter; | 105 | ++counter; |
114 | } | 106 | } |
@@ -124,42 +116,24 @@ loop_top: | |||
124 | break; | 116 | break; |
125 | } | 117 | } |
126 | 118 | ||
127 | for (i = 0; i < NUM_TOXES; ++i) { | 119 | for (uint32_t i = 0; i < NUM_TOXES; ++i) { |
128 | tox_iterate(toxes[i], &to_comp); | 120 | tox_iterate(toxes[i], nullptr); |
129 | } | 121 | } |
130 | 122 | ||
131 | c_sleep(50); | 123 | c_sleep(50); |
132 | } | 124 | } |
133 | 125 | ||
134 | for (i = 0; i < NUM_TOXES; ++i) { | 126 | for (uint32_t i = 0; i < NUM_TOXES; ++i) { |
135 | tox_kill(toxes[i]); | 127 | tox_kill(toxes[i]); |
136 | } | 128 | } |
137 | 129 | ||
138 | printf("test_many_clients succeeded, took %llu seconds\n", time(nullptr) - cur_time); | 130 | printf("test_many_clients succeeded, took %ld seconds\n", time(nullptr) - cur_time); |
139 | } | ||
140 | END_TEST | ||
141 | |||
142 | static Suite *tox_suite(void) | ||
143 | { | ||
144 | Suite *s = suite_create("Tox"); | ||
145 | |||
146 | DEFTESTCASE(many_clients); | ||
147 | |||
148 | return s; | ||
149 | } | 131 | } |
150 | 132 | ||
151 | int main(int argc, char *argv[]) | 133 | int main(int argc, char *argv[]) |
152 | { | 134 | { |
153 | srand((unsigned int) time(nullptr)); | 135 | setvbuf(stdout, nullptr, _IONBF, 0); |
154 | |||
155 | Suite *tox = tox_suite(); | ||
156 | SRunner *test_runner = srunner_create(tox); | ||
157 | |||
158 | int number_failed = 0; | ||
159 | srunner_run_all(test_runner, CK_NORMAL); | ||
160 | number_failed = srunner_ntests_failed(test_runner); | ||
161 | |||
162 | srunner_free(test_runner); | ||
163 | 136 | ||
164 | return number_failed; | 137 | test_many_clients(); |
138 | return 0; | ||
165 | } | 139 | } |
diff --git a/auto_tests/tox_one_test.c b/auto_tests/tox_one_test.c index 2f70fae6..750ba2fd 100644 --- a/auto_tests/tox_one_test.c +++ b/auto_tests/tox_one_test.c | |||
@@ -151,6 +151,8 @@ static Suite *tox_suite(void) | |||
151 | 151 | ||
152 | int main(int argc, char *argv[]) | 152 | int main(int argc, char *argv[]) |
153 | { | 153 | { |
154 | setvbuf(stdout, nullptr, _IONBF, 0); | ||
155 | |||
154 | srand((unsigned int) time(nullptr)); | 156 | srand((unsigned int) time(nullptr)); |
155 | 157 | ||
156 | Suite *tox = tox_suite(); | 158 | Suite *tox = tox_suite(); |
diff --git a/auto_tests/tox_strncasecmp_test.c b/auto_tests/tox_strncasecmp_test.c index fc0d2fc8..27105eca 100644 --- a/auto_tests/tox_strncasecmp_test.c +++ b/auto_tests/tox_strncasecmp_test.c | |||
@@ -179,6 +179,8 @@ static Suite *tox_strncasecmp_suite(void) | |||
179 | 179 | ||
180 | int main(int argc, char *argv[]) | 180 | int main(int argc, char *argv[]) |
181 | { | 181 | { |
182 | setvbuf(stdout, nullptr, _IONBF, 0); | ||
183 | |||
182 | srand((unsigned int) time(nullptr)); | 184 | srand((unsigned int) time(nullptr)); |
183 | 185 | ||
184 | Suite *s = tox_strncasecmp_suite(); | 186 | Suite *s = tox_strncasecmp_suite(); |
diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index c192f556..5c27e11f 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c | |||
@@ -57,41 +57,25 @@ typedef struct { | |||
57 | */ | 57 | */ |
58 | static void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) | 58 | static void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) |
59 | { | 59 | { |
60 | (void) av; | ||
61 | (void) friend_number; | ||
62 | (void) audio_enabled; | ||
63 | (void) video_enabled; | ||
64 | |||
65 | printf("Handling CALL callback\n"); | 60 | printf("Handling CALL callback\n"); |
66 | ((CallControl *)user_data)->incoming = true; | 61 | ((CallControl *)user_data)->incoming = true; |
67 | } | 62 | } |
63 | |||
68 | static void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) | 64 | static void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) |
69 | { | 65 | { |
70 | (void) av; | ||
71 | (void) friend_number; | ||
72 | |||
73 | printf("Handling CALL STATE callback: %d\n", state); | 66 | printf("Handling CALL STATE callback: %d\n", state); |
74 | ((CallControl *)user_data)->state = state; | 67 | ((CallControl *)user_data)->state = state; |
75 | } | 68 | } |
69 | |||
76 | static void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, | 70 | static void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, |
77 | uint16_t width, uint16_t height, | 71 | uint16_t width, uint16_t height, |
78 | uint8_t const *y, uint8_t const *u, uint8_t const *v, | 72 | uint8_t const *y, uint8_t const *u, uint8_t const *v, |
79 | int32_t ystride, int32_t ustride, int32_t vstride, | 73 | int32_t ystride, int32_t ustride, int32_t vstride, |
80 | void *user_data) | 74 | void *user_data) |
81 | { | 75 | { |
82 | (void) av; | ||
83 | (void) friend_number; | ||
84 | (void) width; | ||
85 | (void) height; | ||
86 | (void) y; | ||
87 | (void) u; | ||
88 | (void) v; | ||
89 | (void) ystride; | ||
90 | (void) ustride; | ||
91 | (void) vstride; | ||
92 | (void) user_data; | ||
93 | printf("Received video payload\n"); | 76 | printf("Received video payload\n"); |
94 | } | 77 | } |
78 | |||
95 | static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, | 79 | static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, |
96 | int16_t const *pcm, | 80 | int16_t const *pcm, |
97 | size_t sample_count, | 81 | size_t sample_count, |
@@ -99,20 +83,12 @@ static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, | |||
99 | uint32_t sampling_rate, | 83 | uint32_t sampling_rate, |
100 | void *user_data) | 84 | void *user_data) |
101 | { | 85 | { |
102 | (void) av; | ||
103 | (void) friend_number; | ||
104 | (void) pcm; | ||
105 | (void) sample_count; | ||
106 | (void) channels; | ||
107 | (void) sampling_rate; | ||
108 | (void) user_data; | ||
109 | printf("Received audio payload\n"); | 86 | printf("Received audio payload\n"); |
110 | } | 87 | } |
88 | |||
111 | static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, | 89 | static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, |
112 | void *userdata) | 90 | void *userdata) |
113 | { | 91 | { |
114 | (void) userdata; | ||
115 | |||
116 | if (length == 7 && memcmp("gentoo", data, 7) == 0) { | 92 | if (length == 7 && memcmp("gentoo", data, 7) == 0) { |
117 | ck_assert(tox_friend_add_norequest(m, public_key, nullptr) != (uint32_t) ~0); | 93 | ck_assert(tox_friend_add_norequest(m, public_key, nullptr) != (uint32_t) ~0); |
118 | } | 94 | } |
@@ -122,19 +98,15 @@ static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const | |||
122 | /** | 98 | /** |
123 | * Iterate helper | 99 | * Iterate helper |
124 | */ | 100 | */ |
125 | static int iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob) | 101 | static void iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob) |
126 | { | 102 | { |
127 | c_sleep(100); | 103 | c_sleep(100); |
128 | tox_iterate(bootstrap, nullptr); | 104 | tox_iterate(bootstrap, nullptr); |
129 | tox_iterate(Alice, nullptr); | 105 | tox_iterate(Alice, nullptr); |
130 | tox_iterate(Bob, nullptr); | 106 | tox_iterate(Bob, nullptr); |
131 | |||
132 | return MIN(tox_iteration_interval(Alice), tox_iteration_interval(Bob)); | ||
133 | } | 107 | } |
134 | 108 | ||
135 | 109 | static void test_av_flows(void) | |
136 | |||
137 | START_TEST(test_AV_flows) | ||
138 | { | 110 | { |
139 | Tox *Alice, *Bob, *bootstrap; | 111 | Tox *Alice, *Bob, *bootstrap; |
140 | ToxAV *AliceAV, *BobAV; | 112 | ToxAV *AliceAV, *BobAV; |
@@ -164,6 +136,13 @@ START_TEST(test_AV_flows) | |||
164 | tox_callback_friend_request(Alice, t_accept_friend_request_cb); | 136 | tox_callback_friend_request(Alice, t_accept_friend_request_cb); |
165 | tox_self_get_address(Alice, address); | 137 | tox_self_get_address(Alice, address); |
166 | 138 | ||
139 | printf("bootstrapping Alice and Bob off a third bootstrap node\n"); | ||
140 | uint8_t dht_key[TOX_PUBLIC_KEY_SIZE]; | ||
141 | tox_self_get_dht_id(bootstrap, dht_key); | ||
142 | const uint16_t dht_port = tox_self_get_udp_port(bootstrap, nullptr); | ||
143 | |||
144 | tox_bootstrap(Alice, "localhost", dht_port, dht_key, nullptr); | ||
145 | tox_bootstrap(Bob, "localhost", dht_port, dht_key, nullptr); | ||
167 | 146 | ||
168 | ck_assert(tox_friend_add(Bob, address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0); | 147 | ck_assert(tox_friend_add(Bob, address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0); |
169 | 148 | ||
@@ -579,29 +558,11 @@ START_TEST(test_AV_flows) | |||
579 | 558 | ||
580 | printf("\nTest successful!\n"); | 559 | printf("\nTest successful!\n"); |
581 | } | 560 | } |
582 | END_TEST | ||
583 | 561 | ||
584 | static Suite *tox_suite(void) | ||
585 | { | ||
586 | Suite *s = suite_create("ToxAV"); | ||
587 | |||
588 | DEFTESTCASE_SLOW(AV_flows, 200); | ||
589 | return s; | ||
590 | } | ||
591 | int main(int argc, char *argv[]) | 562 | int main(int argc, char *argv[]) |
592 | { | 563 | { |
593 | (void) argc; | 564 | setvbuf(stdout, nullptr, _IONBF, 0); |
594 | (void) argv; | ||
595 | |||
596 | Suite *tox = tox_suite(); | ||
597 | SRunner *test_runner = srunner_create(tox); | ||
598 | |||
599 | setbuf(stdout, nullptr); | ||
600 | |||
601 | srunner_run_all(test_runner, CK_NORMAL); | ||
602 | int number_failed = srunner_ntests_failed(test_runner); | ||
603 | |||
604 | srunner_free(test_runner); | ||
605 | 565 | ||
606 | return number_failed; | 566 | test_av_flows(); |
567 | return 0; | ||
607 | } | 568 | } |
diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index 02215098..4de1a867 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c | |||
@@ -47,36 +47,24 @@ typedef struct { | |||
47 | */ | 47 | */ |
48 | static void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) | 48 | static void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) |
49 | { | 49 | { |
50 | (void) av; | ||
51 | (void) audio_enabled; | ||
52 | (void) video_enabled; | ||
53 | |||
54 | printf("Handling CALL callback\n"); | 50 | printf("Handling CALL callback\n"); |
55 | ((CallControl *)user_data)[friend_number].incoming = true; | 51 | ((CallControl *)user_data)[friend_number].incoming = true; |
56 | } | 52 | } |
53 | |||
57 | static void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) | 54 | static void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) |
58 | { | 55 | { |
59 | printf("Handling CALL STATE callback: %d %p\n", state, (void *)av); | 56 | printf("Handling CALL STATE callback: %d %p\n", state, (void *)av); |
60 | ((CallControl *)user_data)[friend_number].state = state; | 57 | ((CallControl *)user_data)[friend_number].state = state; |
61 | } | 58 | } |
59 | |||
62 | static void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, | 60 | static void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, |
63 | uint16_t width, uint16_t height, | 61 | uint16_t width, uint16_t height, |
64 | uint8_t const *y, uint8_t const *u, uint8_t const *v, | 62 | uint8_t const *y, uint8_t const *u, uint8_t const *v, |
65 | int32_t ystride, int32_t ustride, int32_t vstride, | 63 | int32_t ystride, int32_t ustride, int32_t vstride, |
66 | void *user_data) | 64 | void *user_data) |
67 | { | 65 | { |
68 | (void) av; | ||
69 | (void) friend_number; | ||
70 | (void) width; | ||
71 | (void) height; | ||
72 | (void) y; | ||
73 | (void) u; | ||
74 | (void) v; | ||
75 | (void) ystride; | ||
76 | (void) ustride; | ||
77 | (void) vstride; | ||
78 | (void) user_data; | ||
79 | } | 66 | } |
67 | |||
80 | static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, | 68 | static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, |
81 | int16_t const *pcm, | 69 | int16_t const *pcm, |
82 | size_t sample_count, | 70 | size_t sample_count, |
@@ -84,19 +72,11 @@ static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, | |||
84 | uint32_t sampling_rate, | 72 | uint32_t sampling_rate, |
85 | void *user_data) | 73 | void *user_data) |
86 | { | 74 | { |
87 | (void) av; | ||
88 | (void) friend_number; | ||
89 | (void) pcm; | ||
90 | (void) sample_count; | ||
91 | (void) channels; | ||
92 | (void) sampling_rate; | ||
93 | (void) user_data; | ||
94 | } | 75 | } |
76 | |||
95 | static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, | 77 | static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, |
96 | void *userdata) | 78 | void *userdata) |
97 | { | 79 | { |
98 | (void) userdata; | ||
99 | |||
100 | if (length == 7 && memcmp("gentoo", data, 7) == 0) { | 80 | if (length == 7 && memcmp("gentoo", data, 7) == 0) { |
101 | ck_assert(tox_friend_add_norequest(m, public_key, nullptr) != (uint32_t) ~0); | 81 | ck_assert(tox_friend_add_norequest(m, public_key, nullptr) != (uint32_t) ~0); |
102 | } | 82 | } |
@@ -120,6 +100,7 @@ static ToxAV *setup_av_instance(Tox *tox, CallControl *CC) | |||
120 | 100 | ||
121 | return av; | 101 | return av; |
122 | } | 102 | } |
103 | |||
123 | static void *call_thread(void *pd) | 104 | static void *call_thread(void *pd) |
124 | { | 105 | { |
125 | ToxAV *AliceAV = ((thread_data *) pd)->AliceAV; | 106 | ToxAV *AliceAV = ((thread_data *) pd)->AliceAV; |
@@ -197,8 +178,7 @@ static void *call_thread(void *pd) | |||
197 | pthread_exit(nullptr); | 178 | pthread_exit(nullptr); |
198 | } | 179 | } |
199 | 180 | ||
200 | 181 | static void test_av_three_calls(void) | |
201 | START_TEST(test_AV_three_calls) | ||
202 | { | 182 | { |
203 | uint32_t index[] = { 1, 2, 3, 4, 5 }; | 183 | uint32_t index[] = { 1, 2, 3, 4, 5 }; |
204 | Tox *Alice, *bootstrap, *Bobs[3]; | 184 | Tox *Alice, *bootstrap, *Bobs[3]; |
@@ -228,13 +208,23 @@ START_TEST(test_AV_three_calls) | |||
228 | 208 | ||
229 | printf("Created 5 instances of Tox\n"); | 209 | printf("Created 5 instances of Tox\n"); |
230 | printf("Preparing network...\n"); | 210 | printf("Preparing network...\n"); |
231 | long long unsigned int cur_time = time(nullptr); | 211 | time_t cur_time = time(nullptr); |
232 | 212 | ||
233 | uint8_t address[TOX_ADDRESS_SIZE]; | 213 | uint8_t address[TOX_ADDRESS_SIZE]; |
234 | 214 | ||
235 | tox_callback_friend_request(Alice, t_accept_friend_request_cb); | 215 | tox_callback_friend_request(Alice, t_accept_friend_request_cb); |
236 | tox_self_get_address(Alice, address); | 216 | tox_self_get_address(Alice, address); |
237 | 217 | ||
218 | printf("bootstrapping Alice and the %zd Bobs off a third bootstrap node\n", | ||
219 | sizeof(Bobs) / sizeof(Bobs[0])); | ||
220 | uint8_t dht_key[TOX_PUBLIC_KEY_SIZE]; | ||
221 | tox_self_get_dht_id(bootstrap, dht_key); | ||
222 | const uint16_t dht_port = tox_self_get_udp_port(bootstrap, nullptr); | ||
223 | |||
224 | tox_bootstrap(Alice, "localhost", dht_port, dht_key, nullptr); | ||
225 | tox_bootstrap(Bobs[0], "localhost", dht_port, dht_key, nullptr); | ||
226 | tox_bootstrap(Bobs[1], "localhost", dht_port, dht_key, nullptr); | ||
227 | tox_bootstrap(Bobs[2], "localhost", dht_port, dht_key, nullptr); | ||
238 | 228 | ||
239 | ck_assert(tox_friend_add(Bobs[0], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0); | 229 | ck_assert(tox_friend_add(Bobs[0], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0); |
240 | ck_assert(tox_friend_add(Bobs[1], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0); | 230 | ck_assert(tox_friend_add(Bobs[1], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0); |
@@ -254,7 +244,7 @@ START_TEST(test_AV_three_calls) | |||
254 | tox_self_get_connection_status(Bobs[0]) && | 244 | tox_self_get_connection_status(Bobs[0]) && |
255 | tox_self_get_connection_status(Bobs[1]) && | 245 | tox_self_get_connection_status(Bobs[1]) && |
256 | tox_self_get_connection_status(Bobs[2]) && off) { | 246 | tox_self_get_connection_status(Bobs[2]) && off) { |
257 | printf("Toxes are online, took %llu seconds\n", time(nullptr) - cur_time); | 247 | printf("Toxes are online, took %ld seconds\n", time(nullptr) - cur_time); |
258 | off = 0; | 248 | off = 0; |
259 | } | 249 | } |
260 | 250 | ||
@@ -276,7 +266,7 @@ START_TEST(test_AV_three_calls) | |||
276 | BobsAV[2] = setup_av_instance(Bobs[2], BobsCC + 2); | 266 | BobsAV[2] = setup_av_instance(Bobs[2], BobsCC + 2); |
277 | 267 | ||
278 | printf("Created 4 instances of ToxAV\n"); | 268 | printf("Created 4 instances of ToxAV\n"); |
279 | printf("All set after %llu seconds!\n", time(nullptr) - cur_time); | 269 | printf("All set after %ld seconds!\n", time(nullptr) - cur_time); |
280 | 270 | ||
281 | thread_data tds[3]; | 271 | thread_data tds[3]; |
282 | tds[0].AliceAV = AliceAV; | 272 | tds[0].AliceAV = AliceAV; |
@@ -305,6 +295,7 @@ START_TEST(test_AV_three_calls) | |||
305 | time_t start_time = time(nullptr); | 295 | time_t start_time = time(nullptr); |
306 | 296 | ||
307 | while (time(nullptr) - start_time < 5) { | 297 | while (time(nullptr) - start_time < 5) { |
298 | tox_iterate(bootstrap, nullptr); | ||
308 | tox_iterate(Alice, nullptr); | 299 | tox_iterate(Alice, nullptr); |
309 | tox_iterate(Bobs[0], nullptr); | 300 | tox_iterate(Bobs[0], nullptr); |
310 | tox_iterate(Bobs[1], nullptr); | 301 | tox_iterate(Bobs[1], nullptr); |
@@ -322,44 +313,23 @@ START_TEST(test_AV_three_calls) | |||
322 | ck_assert(retval == nullptr); | 313 | ck_assert(retval == nullptr); |
323 | 314 | ||
324 | printf("Killing all instances\n"); | 315 | printf("Killing all instances\n"); |
325 | toxav_kill(BobsAV[0]); | ||
326 | toxav_kill(BobsAV[1]); | ||
327 | toxav_kill(BobsAV[2]); | 316 | toxav_kill(BobsAV[2]); |
317 | toxav_kill(BobsAV[1]); | ||
318 | toxav_kill(BobsAV[0]); | ||
328 | toxav_kill(AliceAV); | 319 | toxav_kill(AliceAV); |
329 | tox_kill(Bobs[0]); | ||
330 | tox_kill(Bobs[1]); | ||
331 | tox_kill(Bobs[2]); | 320 | tox_kill(Bobs[2]); |
321 | tox_kill(Bobs[1]); | ||
322 | tox_kill(Bobs[0]); | ||
332 | tox_kill(Alice); | 323 | tox_kill(Alice); |
333 | tox_kill(bootstrap); | 324 | tox_kill(bootstrap); |
334 | 325 | ||
335 | printf("\nTest successful!\n"); | 326 | printf("\nTest successful!\n"); |
336 | } | 327 | } |
337 | END_TEST | ||
338 | |||
339 | |||
340 | static Suite *tox_suite(void) | ||
341 | { | ||
342 | Suite *s = suite_create("ToxAV"); | ||
343 | |||
344 | DEFTESTCASE(AV_three_calls); | ||
345 | |||
346 | return s; | ||
347 | } | ||
348 | 328 | ||
349 | int main(int argc, char *argv[]) | 329 | int main(int argc, char *argv[]) |
350 | { | 330 | { |
351 | (void) argc; | 331 | setvbuf(stdout, nullptr, _IONBF, 0); |
352 | (void) argv; | ||
353 | |||
354 | Suite *tox = tox_suite(); | ||
355 | SRunner *test_runner = srunner_create(tox); | ||
356 | |||
357 | setbuf(stdout, nullptr); | ||
358 | |||
359 | srunner_run_all(test_runner, CK_NORMAL); | ||
360 | int number_failed = srunner_ntests_failed(test_runner); | ||
361 | |||
362 | srunner_free(test_runner); | ||
363 | 332 | ||
364 | return number_failed; | 333 | test_av_three_calls(); |
334 | return 0; | ||
365 | } | 335 | } |