mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Disable lan discovery in most tests.
This commit is contained in:
parent
d016eb3f0e
commit
3dc8cf6df8
|
@ -457,6 +457,7 @@ auto_test(set_name)
|
|||
auto_test(set_status_message)
|
||||
auto_test(simple_conference)
|
||||
auto_test(skeleton)
|
||||
auto_test(tcp_relay)
|
||||
auto_test(tox_many)
|
||||
auto_test(tox_many_tcp)
|
||||
auto_test(tox_one)
|
||||
|
|
|
@ -771,6 +771,8 @@ static Suite *TCP_suite(void)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *TCP = TCP_suite();
|
||||
|
|
|
@ -13,22 +13,24 @@ static uint8_t const key[] = {
|
|||
|
||||
int main(void)
|
||||
{
|
||||
Tox *tox = tox_new_log(nullptr, nullptr, nullptr);
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
tox_bootstrap(tox, "node.tox.biribiri.org", 33445, key, nullptr);
|
||||
Tox *tox_udp = tox_new_log(nullptr, nullptr, nullptr);
|
||||
|
||||
tox_bootstrap(tox_udp, "node.tox.biribiri.org", 33445, key, nullptr);
|
||||
|
||||
printf("Waiting for connection");
|
||||
|
||||
while (tox_self_get_connection_status(tox) == TOX_CONNECTION_NONE) {
|
||||
while (tox_self_get_connection_status(tox_udp) == TOX_CONNECTION_NONE) {
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
|
||||
tox_iterate(tox, nullptr);
|
||||
c_sleep(1000);
|
||||
tox_iterate(tox_udp, nullptr);
|
||||
c_sleep(ITERATION_INTERVAL);
|
||||
}
|
||||
|
||||
printf("Connection: %d\n", tox_self_get_connection_status(tox));
|
||||
printf("Connection (UDP): %d\n", tox_self_get_connection_status(tox_udp));
|
||||
|
||||
tox_kill(tox);
|
||||
tox_kill(tox_udp);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -21,10 +21,11 @@
|
|||
#include "helpers.h"
|
||||
|
||||
#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)
|
||||
{
|
||||
int id = *(int *)user_data;
|
||||
const int id = *(int *)user_data;
|
||||
|
||||
if (connection_status != TOX_CONNECTION_NONE) {
|
||||
printf("tox #%d: is now connected\n", id);
|
||||
|
@ -36,7 +37,7 @@ 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)
|
||||
{
|
||||
int id = *(int *)user_data;
|
||||
const int id = *(int *)user_data;
|
||||
|
||||
if (connection_status != TOX_CONNECTION_NONE) {
|
||||
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
|
|||
static void handle_conference_invite(Tox *tox, uint32_t friendnumber, TOX_CONFERENCE_TYPE type, const uint8_t *data,
|
||||
size_t length, void *user_data)
|
||||
{
|
||||
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);
|
||||
|
||||
TOX_ERR_CONFERENCE_JOIN err;
|
||||
|
@ -75,12 +76,12 @@ 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)
|
||||
{
|
||||
if (length == (sizeof("Install Gentoo") - 1) && memcmp(message, "Install Gentoo", sizeof("Install Gentoo") - 1) == 0) {
|
||||
if (length == (sizeof(GROUP_MESSAGE) - 1) && memcmp(message, GROUP_MESSAGE, sizeof(GROUP_MESSAGE) - 1) == 0) {
|
||||
++num_recv;
|
||||
}
|
||||
}
|
||||
|
||||
START_TEST(test_many_group)
|
||||
static void test_many_group(void)
|
||||
{
|
||||
const time_t test_start_time = time(nullptr);
|
||||
|
||||
|
@ -102,18 +103,18 @@ START_TEST(test_many_group)
|
|||
tox_callback_self_connection_status(toxes[i], &handle_self_connection_status);
|
||||
tox_callback_friend_connection_status(toxes[i], &handle_friend_connection_status);
|
||||
tox_callback_conference_invite(toxes[i], &handle_conference_invite);
|
||||
|
||||
if (i != 0) {
|
||||
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
|
||||
tox_self_get_dht_id(toxes[0], dht_key);
|
||||
const uint16_t dht_port = tox_self_get_udp_port(toxes[0], nullptr);
|
||||
|
||||
tox_bootstrap(toxes[i], "localhost", dht_port, dht_key, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
tox_options_free(opts);
|
||||
|
||||
{
|
||||
TOX_ERR_GET_PORT error;
|
||||
const uint16_t port = tox_self_get_udp_port(toxes[0], &error);
|
||||
ck_assert_msg(33445 <= port && port <= 33545,
|
||||
"First Tox instance did not bind to udp port inside [33445, 33545].\n");
|
||||
ck_assert_msg(error == TOX_ERR_GET_PORT_OK, "wrong error");
|
||||
}
|
||||
|
||||
printf("creating a chain of friends\n");
|
||||
|
||||
for (unsigned i = 1; i < NUM_GROUP_TOX; ++i) {
|
||||
|
@ -208,8 +209,8 @@ START_TEST(test_many_group)
|
|||
TOX_ERR_CONFERENCE_SEND_MESSAGE err;
|
||||
ck_assert_msg(
|
||||
tox_conference_send_message(
|
||||
toxes[rand() % NUM_GROUP_TOX], 0, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)"Install Gentoo",
|
||||
sizeof("Install Gentoo") - 1, &err) != 0, "Failed to send group message.");
|
||||
toxes[rand() % 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;
|
||||
|
@ -236,7 +237,7 @@ START_TEST(test_many_group)
|
|||
c_sleep(50);
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < (k - 1); ++i) {
|
||||
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",
|
||||
|
@ -250,29 +251,11 @@ START_TEST(test_many_group)
|
|||
|
||||
printf("test_many_group succeeded, took %d seconds\n", (int)(time(nullptr) - test_start_time));
|
||||
}
|
||||
END_TEST
|
||||
|
||||
static Suite *tox_suite(void)
|
||||
{
|
||||
Suite *s = suite_create("Tox conference");
|
||||
|
||||
DEFTESTCASE_SLOW(many_group, 80);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
srand((unsigned int) time(nullptr));
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
Suite *tox = tox_suite();
|
||||
SRunner *test_runner = srunner_create(tox);
|
||||
|
||||
int number_failed = 0;
|
||||
srunner_run_all(test_runner, CK_NORMAL);
|
||||
number_failed = srunner_ntests_failed(test_runner);
|
||||
|
||||
srunner_free(test_runner);
|
||||
|
||||
return number_failed;
|
||||
test_many_group();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -356,6 +356,7 @@ static Suite *crypto_suite(void)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *crypto = crypto_suite();
|
||||
|
|
|
@ -801,6 +801,7 @@ static Suite *dht_suite(void)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *dht = dht_suite();
|
||||
|
|
|
@ -206,6 +206,7 @@ static Suite *encryptsave_suite(void)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *encryptsave = encryptsave_suite();
|
||||
|
|
|
@ -27,17 +27,16 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../toxencryptsave/toxencryptsave.h"
|
||||
#include "helpers.h"
|
||||
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "../toxencryptsave/toxencryptsave.h"
|
||||
|
||||
static const char *pphrase = "bar", *name = "foo", *savefile = "./save";
|
||||
|
||||
static void save_data_encrypted(void)
|
||||
{
|
||||
struct Tox_Options *options = tox_options_new(nullptr);
|
||||
Tox *t = tox_new(options, nullptr);
|
||||
Tox *t = tox_new_log(options, nullptr, nullptr);
|
||||
tox_options_free(options);
|
||||
|
||||
tox_self_set_name(t, (const uint8_t *)name, strlen(name), nullptr);
|
||||
|
@ -97,7 +96,7 @@ static void load_data_decrypted(void)
|
|||
|
||||
TOX_ERR_NEW err;
|
||||
|
||||
Tox *t = tox_new(options, &err);
|
||||
Tox *t = tox_new_log(options, &err, nullptr);
|
||||
|
||||
tox_options_free(options);
|
||||
|
||||
|
@ -123,6 +122,7 @@ static void load_data_decrypted(void)
|
|||
|
||||
int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
save_data_encrypted();
|
||||
load_data_decrypted();
|
||||
|
||||
|
|
|
@ -54,17 +54,17 @@ static void print_debug_log(Tox *m, TOX_LOG_LEVEL level, const char *path, uint3
|
|||
fprintf(stderr, "[#%d] %s %s:%d\t%s:\t%s\n", index, tox_log_level_name(level), file, line, func, message);
|
||||
}
|
||||
|
||||
Tox *tox_new_log(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data)
|
||||
Tox *tox_new_log_lan(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data, bool lan_discovery)
|
||||
{
|
||||
struct Tox_Options *log_options = options;
|
||||
|
||||
if (log_options == nullptr) {
|
||||
log_options = tox_options_new(nullptr);
|
||||
// tox_options_set_local_discovery_enabled(log_options, false);
|
||||
}
|
||||
|
||||
assert(log_options != nullptr);
|
||||
|
||||
tox_options_set_local_discovery_enabled(log_options, lan_discovery);
|
||||
tox_options_set_log_callback(log_options, &print_debug_log);
|
||||
tox_options_set_log_user_data(log_options, log_user_data);
|
||||
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
|
|||
return tox;
|
||||
}
|
||||
|
||||
Tox *tox_new_log(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data)
|
||||
{
|
||||
return tox_new_log_lan(options, err, log_user_data, false);
|
||||
}
|
||||
|
||||
#endif // TOXCORE_TEST_HELPERS_H
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
|
||||
int main(void)
|
||||
{
|
||||
Tox *tox1 = tox_new_log(nullptr, nullptr, nullptr);
|
||||
Tox *tox2 = tox_new_log(nullptr, nullptr, nullptr);
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
Tox *tox1 = tox_new_log_lan(nullptr, nullptr, nullptr, /* lan_discovery */true);
|
||||
Tox *tox2 = tox_new_log_lan(nullptr, nullptr, nullptr, /* lan_discovery */true);
|
||||
|
||||
printf("Waiting for LAN discovery");
|
||||
|
||||
|
|
|
@ -348,6 +348,8 @@ static Suite *messenger_suite(void)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
friend_id = hex_string_to_bin(friend_id_str);
|
||||
good_id_a = hex_string_to_bin(good_id_a_str);
|
||||
good_id_b = hex_string_to_bin(good_id_b_str);
|
||||
|
|
|
@ -165,6 +165,7 @@ static Suite *network_suite(void)
|
|||
|
||||
int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *network = network_suite();
|
||||
|
|
|
@ -538,6 +538,7 @@ static Suite *onion_suite(void)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *onion = onion_suite();
|
||||
|
|
|
@ -21,12 +21,12 @@
|
|||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
puts("Warming up: creating/deleting 10 tox instances");
|
||||
|
||||
// Warm-up.
|
||||
for (i = 0; i < 10; i++) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Tox *tox = tox_new(nullptr, nullptr);
|
||||
tox_iterate(tox, nullptr);
|
||||
tox_kill(tox);
|
||||
|
@ -38,7 +38,7 @@ int main(void)
|
|||
#endif
|
||||
printf("Creating/deleting %d tox instances\n", ITERATIONS);
|
||||
|
||||
for (i = 0; i < ITERATIONS; i++) {
|
||||
for (int i = 0; i < ITERATIONS; i++) {
|
||||
Tox *tox = tox_new(nullptr, nullptr);
|
||||
tox_iterate(tox, nullptr);
|
||||
tox_kill(tox);
|
||||
|
|
|
@ -49,10 +49,19 @@ void statuschange_callback(Tox *tox, uint32_t friend_number, const uint8_t *mess
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Tox *tox1 = tox_new_log(nullptr, nullptr, nullptr);
|
||||
Tox *tox2 = tox_new_log(nullptr, nullptr, nullptr);
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
struct test_data to_compare = { { 0 } };
|
||||
Tox *const tox1 = tox_new_log(nullptr, nullptr, nullptr);
|
||||
Tox *const tox2 = tox_new_log(nullptr, nullptr, nullptr);
|
||||
|
||||
printf("bootstrapping tox2 off tox1\n");
|
||||
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
|
||||
tox_self_get_dht_id(tox1, dht_key);
|
||||
const uint16_t dht_port = tox_self_get_udp_port(tox1, nullptr);
|
||||
|
||||
tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr);
|
||||
|
||||
struct test_data to_compare = {{0}};
|
||||
|
||||
uint8_t public_key[TOX_PUBLIC_KEY_SIZE];
|
||||
tox_self_get_public_key(tox1, public_key);
|
||||
|
@ -104,11 +113,11 @@ int main(int argc, char *argv[])
|
|||
VLA(uint8_t, savedata, save_size);
|
||||
tox_get_savedata(tox1, savedata);
|
||||
|
||||
struct Tox_Options *options = tox_options_new(nullptr);
|
||||
struct Tox_Options *const options = tox_options_new(nullptr);
|
||||
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
|
||||
tox_options_set_savedata_data(options, savedata, save_size);
|
||||
|
||||
Tox *tox_to_compare = tox_new(options, nullptr);
|
||||
Tox *const tox_to_compare = tox_new_log(options, nullptr, nullptr);
|
||||
|
||||
tox_friend_get_name(tox_to_compare, 0, to_compare.name, nullptr);
|
||||
tox_friend_get_status_message(tox_to_compare, 0, to_compare.status_message, nullptr);
|
||||
|
|
|
@ -48,13 +48,15 @@ static void cbtitlechange(Tox *tox, uint32_t conference_number, uint32_t peer_nu
|
|||
|
||||
int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
uint32_t conference_number;
|
||||
struct Tox_Options *to = tox_options_new(nullptr);
|
||||
Tox *t;
|
||||
TOX_ERR_CONFERENCE_NEW conference_err;
|
||||
TOX_ERR_CONFERENCE_TITLE title_err;
|
||||
|
||||
t = tox_new(to, nullptr);
|
||||
t = tox_new_log(to, nullptr, nullptr);
|
||||
tox_options_free(to);
|
||||
|
||||
tox_callback_conference_title(t, &cbtitlechange);
|
||||
|
|
|
@ -59,12 +59,14 @@ static void cbconfmembers(Tox *tox, uint32_t conference_number, uint32_t peer_nu
|
|||
|
||||
int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
struct Tox_Options *to = tox_options_new(nullptr);
|
||||
Tox *t;
|
||||
TOX_ERR_CONFERENCE_NEW conference_err;
|
||||
TOX_ERR_SET_INFO name_err;
|
||||
|
||||
t = tox_new(to, nullptr);
|
||||
t = tox_new_log(to, nullptr, nullptr);
|
||||
tox_options_free(to);
|
||||
|
||||
tox_callback_conference_namelist_change(t, cbconfmembers);
|
||||
|
|
|
@ -103,6 +103,8 @@ static void handle_conference_namelist_change(Tox *tox, uint32_t conference_numb
|
|||
|
||||
int main()
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
State state1 = {1};
|
||||
State state2 = {2};
|
||||
State state3 = {3};
|
||||
|
@ -123,6 +125,14 @@ int main()
|
|||
tox_self_get_public_key(tox2, key);
|
||||
tox_friend_add_norequest(tox3, key, nullptr); // tox3 -> tox2
|
||||
|
||||
printf("bootstrapping tox2 and tox3 off tox1\n");
|
||||
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
|
||||
tox_self_get_dht_id(tox1, dht_key);
|
||||
const uint16_t dht_port = tox_self_get_udp_port(tox1, nullptr);
|
||||
|
||||
tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr);
|
||||
tox_bootstrap(tox3, "localhost", dht_port, dht_key, nullptr);
|
||||
|
||||
// Connection callbacks.
|
||||
tox_callback_self_connection_status(tox1, handle_self_connection_status);
|
||||
tox_callback_self_connection_status(tox2, handle_self_connection_status);
|
||||
|
|
|
@ -31,6 +31,8 @@ static Suite *creativesuitenamegoeshere_suite(void)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *creativesuitenamegoeshere = creativesuitenamegoeshere_suite();
|
||||
|
|
40
auto_tests/tcp_relay_test.c
Normal file
40
auto_tests/tcp_relay_test.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#include "helpers.h"
|
||||
|
||||
static uint8_t const key[] = {
|
||||
0xF4, 0x04, 0xAB, 0xAA, 0x1C, 0x99, 0xA9, 0xD3,
|
||||
0x7D, 0x61, 0xAB, 0x54, 0x89, 0x8F, 0x56, 0x79,
|
||||
0x3E, 0x1D, 0xEF, 0x8B, 0xD4, 0x6B, 0x10, 0x38,
|
||||
0xB9, 0xD8, 0x22, 0xE8, 0x46, 0x0F, 0xAB, 0x67,
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
struct Tox_Options *opts = tox_options_new(nullptr);
|
||||
tox_options_set_udp_enabled(opts, false);
|
||||
Tox *tox_tcp = tox_new_log(opts, nullptr, nullptr);
|
||||
tox_options_free(opts);
|
||||
|
||||
tox_bootstrap(tox_tcp, "node.tox.biribiri.org", 33445, key, nullptr);
|
||||
tox_add_tcp_relay(tox_tcp, "node.tox.biribiri.org", 33445, key, nullptr);
|
||||
|
||||
printf("Waiting for connection");
|
||||
|
||||
while (tox_self_get_connection_status(tox_tcp) == TOX_CONNECTION_NONE) {
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
|
||||
tox_iterate(tox_tcp, nullptr);
|
||||
c_sleep(ITERATION_INTERVAL);
|
||||
}
|
||||
|
||||
printf("Connection (TCP): %d\n", tox_self_get_connection_status(tox_tcp));
|
||||
|
||||
tox_kill(tox_tcp);
|
||||
return 0;
|
||||
}
|
|
@ -274,6 +274,8 @@ static Suite *tox_suite(void)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *tox = tox_suite();
|
||||
|
|
|
@ -22,10 +22,6 @@
|
|||
|
||||
static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
|
||||
{
|
||||
if (*((uint32_t *)userdata) != 974536) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (length == 7 && memcmp("Gentoo", data, 7) == 0) {
|
||||
tox_friend_add_norequest(m, public_key, nullptr);
|
||||
}
|
||||
|
@ -35,29 +31,19 @@ static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8
|
|||
#define NUM_TOXES 90
|
||||
#define NUM_FRIENDS 50
|
||||
|
||||
START_TEST(test_many_clients)
|
||||
static void test_many_clients(void)
|
||||
{
|
||||
long long unsigned int cur_time = time(nullptr);
|
||||
time_t cur_time = time(nullptr);
|
||||
Tox *toxes[NUM_TOXES];
|
||||
uint32_t index[NUM_TOXES];
|
||||
uint32_t i, j;
|
||||
uint32_t to_comp = 974536;
|
||||
|
||||
for (i = 0; i < NUM_TOXES; ++i) {
|
||||
for (uint32_t i = 0; i < NUM_TOXES; ++i) {
|
||||
index[i] = i + 1;
|
||||
toxes[i] = tox_new_log(nullptr, nullptr, &index[i]);
|
||||
ck_assert_msg(toxes[i] != nullptr, "Failed to create tox instances %u", i);
|
||||
ck_assert_msg(toxes[i] != nullptr, "failed to create tox instances %u", i);
|
||||
tox_callback_friend_request(toxes[i], accept_friend_request);
|
||||
}
|
||||
|
||||
{
|
||||
TOX_ERR_GET_PORT error;
|
||||
uint16_t port = tox_self_get_udp_port(toxes[0], &error);
|
||||
ck_assert_msg(33445 <= port && port <= 33545,
|
||||
"First Tox instance did not bind to udp port inside [33445, 33545].\n");
|
||||
ck_assert_msg(error == TOX_ERR_GET_PORT_OK, "wrong error");
|
||||
}
|
||||
|
||||
struct {
|
||||
uint16_t tox1;
|
||||
uint16_t tox2;
|
||||
|
@ -65,20 +51,20 @@ START_TEST(test_many_clients)
|
|||
|
||||
uint8_t address[TOX_ADDRESS_SIZE];
|
||||
|
||||
unsigned int num_f = 0;
|
||||
uint32_t num_f = 0;
|
||||
|
||||
for (i = 0; i < NUM_TOXES; ++i) {
|
||||
for (uint32_t i = 0; i < NUM_TOXES; ++i) {
|
||||
num_f += tox_self_get_friend_list_size(toxes[i]);
|
||||
}
|
||||
|
||||
ck_assert_msg(num_f == 0, "bad num friends: %u", num_f);
|
||||
|
||||
for (i = 0; i < NUM_FRIENDS; ++i) {
|
||||
for (uint32_t i = 0; i < NUM_FRIENDS; ++i) {
|
||||
loop_top:
|
||||
pairs[i].tox1 = rand() % NUM_TOXES;
|
||||
pairs[i].tox2 = (pairs[i].tox1 + rand() % (NUM_TOXES - 1) + 1) % NUM_TOXES;
|
||||
|
||||
for (j = 0; j < i; ++j) {
|
||||
for (uint32_t j = 0; j < i; ++j) {
|
||||
if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2) {
|
||||
goto loop_top;
|
||||
}
|
||||
|
@ -93,10 +79,16 @@ loop_top:
|
|||
goto loop_top;
|
||||
}
|
||||
|
||||
ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "Failed to add friend error code: %i", test);
|
||||
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
|
||||
tox_self_get_dht_id(toxes[pairs[i].tox1], dht_key);
|
||||
const uint16_t dht_port = tox_self_get_udp_port(toxes[pairs[i].tox1], nullptr);
|
||||
|
||||
tox_bootstrap(toxes[pairs[i].tox2], "localhost", dht_port, dht_key, nullptr);
|
||||
|
||||
ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "failed to add friend error code: %i", test);
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_TOXES; ++i) {
|
||||
for (uint32_t i = 0; i < NUM_TOXES; ++i) {
|
||||
num_f += tox_self_get_friend_list_size(toxes[i]);
|
||||
}
|
||||
|
||||
|
@ -107,8 +99,8 @@ loop_top:
|
|||
while (1) {
|
||||
uint16_t counter = 0;
|
||||
|
||||
for (i = 0; i < NUM_TOXES; ++i) {
|
||||
for (j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j) {
|
||||
for (uint32_t i = 0; i < NUM_TOXES; ++i) {
|
||||
for (uint32_t j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j) {
|
||||
if (tox_friend_get_connection_status(toxes[i], j, nullptr) == TOX_CONNECTION_UDP) {
|
||||
++counter;
|
||||
}
|
||||
|
@ -124,42 +116,24 @@ loop_top:
|
|||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_TOXES; ++i) {
|
||||
tox_iterate(toxes[i], &to_comp);
|
||||
for (uint32_t i = 0; i < NUM_TOXES; ++i) {
|
||||
tox_iterate(toxes[i], nullptr);
|
||||
}
|
||||
|
||||
c_sleep(50);
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_TOXES; ++i) {
|
||||
for (uint32_t i = 0; i < NUM_TOXES; ++i) {
|
||||
tox_kill(toxes[i]);
|
||||
}
|
||||
|
||||
printf("test_many_clients succeeded, took %llu seconds\n", time(nullptr) - cur_time);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
static Suite *tox_suite(void)
|
||||
{
|
||||
Suite *s = suite_create("Tox");
|
||||
|
||||
DEFTESTCASE(many_clients);
|
||||
|
||||
return s;
|
||||
printf("test_many_clients succeeded, took %ld seconds\n", time(nullptr) - cur_time);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
srand((unsigned int) time(nullptr));
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
Suite *tox = tox_suite();
|
||||
SRunner *test_runner = srunner_create(tox);
|
||||
|
||||
int number_failed = 0;
|
||||
srunner_run_all(test_runner, CK_NORMAL);
|
||||
number_failed = srunner_ntests_failed(test_runner);
|
||||
|
||||
srunner_free(test_runner);
|
||||
|
||||
return number_failed;
|
||||
test_many_clients();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -151,6 +151,8 @@ static Suite *tox_suite(void)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *tox = tox_suite();
|
||||
|
|
|
@ -179,6 +179,8 @@ static Suite *tox_strncasecmp_suite(void)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *s = tox_strncasecmp_suite();
|
||||
|
|
|
@ -57,41 +57,25 @@ typedef struct {
|
|||
*/
|
||||
static void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data)
|
||||
{
|
||||
(void) av;
|
||||
(void) friend_number;
|
||||
(void) audio_enabled;
|
||||
(void) video_enabled;
|
||||
|
||||
printf("Handling CALL callback\n");
|
||||
((CallControl *)user_data)->incoming = true;
|
||||
}
|
||||
|
||||
static void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data)
|
||||
{
|
||||
(void) av;
|
||||
(void) friend_number;
|
||||
|
||||
printf("Handling CALL STATE callback: %d\n", state);
|
||||
((CallControl *)user_data)->state = state;
|
||||
}
|
||||
|
||||
static void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number,
|
||||
uint16_t width, uint16_t height,
|
||||
uint8_t const *y, uint8_t const *u, uint8_t const *v,
|
||||
int32_t ystride, int32_t ustride, int32_t vstride,
|
||||
void *user_data)
|
||||
{
|
||||
(void) av;
|
||||
(void) friend_number;
|
||||
(void) width;
|
||||
(void) height;
|
||||
(void) y;
|
||||
(void) u;
|
||||
(void) v;
|
||||
(void) ystride;
|
||||
(void) ustride;
|
||||
(void) vstride;
|
||||
(void) user_data;
|
||||
printf("Received video payload\n");
|
||||
}
|
||||
|
||||
static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number,
|
||||
int16_t const *pcm,
|
||||
size_t sample_count,
|
||||
|
@ -99,20 +83,12 @@ static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number,
|
|||
uint32_t sampling_rate,
|
||||
void *user_data)
|
||||
{
|
||||
(void) av;
|
||||
(void) friend_number;
|
||||
(void) pcm;
|
||||
(void) sample_count;
|
||||
(void) channels;
|
||||
(void) sampling_rate;
|
||||
(void) user_data;
|
||||
printf("Received audio payload\n");
|
||||
}
|
||||
|
||||
static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length,
|
||||
void *userdata)
|
||||
{
|
||||
(void) userdata;
|
||||
|
||||
if (length == 7 && memcmp("gentoo", data, 7) == 0) {
|
||||
ck_assert(tox_friend_add_norequest(m, public_key, nullptr) != (uint32_t) ~0);
|
||||
}
|
||||
|
@ -122,19 +98,15 @@ static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const
|
|||
/**
|
||||
* Iterate helper
|
||||
*/
|
||||
static int iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob)
|
||||
static void iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob)
|
||||
{
|
||||
c_sleep(100);
|
||||
tox_iterate(bootstrap, nullptr);
|
||||
tox_iterate(Alice, nullptr);
|
||||
tox_iterate(Bob, nullptr);
|
||||
|
||||
return MIN(tox_iteration_interval(Alice), tox_iteration_interval(Bob));
|
||||
}
|
||||
|
||||
|
||||
|
||||
START_TEST(test_AV_flows)
|
||||
static void test_av_flows(void)
|
||||
{
|
||||
Tox *Alice, *Bob, *bootstrap;
|
||||
ToxAV *AliceAV, *BobAV;
|
||||
|
@ -164,6 +136,13 @@ START_TEST(test_AV_flows)
|
|||
tox_callback_friend_request(Alice, t_accept_friend_request_cb);
|
||||
tox_self_get_address(Alice, address);
|
||||
|
||||
printf("bootstrapping Alice and Bob off a third bootstrap node\n");
|
||||
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
|
||||
tox_self_get_dht_id(bootstrap, dht_key);
|
||||
const uint16_t dht_port = tox_self_get_udp_port(bootstrap, nullptr);
|
||||
|
||||
tox_bootstrap(Alice, "localhost", dht_port, dht_key, nullptr);
|
||||
tox_bootstrap(Bob, "localhost", dht_port, dht_key, nullptr);
|
||||
|
||||
ck_assert(tox_friend_add(Bob, address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0);
|
||||
|
||||
|
@ -579,29 +558,11 @@ START_TEST(test_AV_flows)
|
|||
|
||||
printf("\nTest successful!\n");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
static Suite *tox_suite(void)
|
||||
{
|
||||
Suite *s = suite_create("ToxAV");
|
||||
|
||||
DEFTESTCASE_SLOW(AV_flows, 200);
|
||||
return s;
|
||||
}
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
Suite *tox = tox_suite();
|
||||
SRunner *test_runner = srunner_create(tox);
|
||||
|
||||
setbuf(stdout, nullptr);
|
||||
|
||||
srunner_run_all(test_runner, CK_NORMAL);
|
||||
int number_failed = srunner_ntests_failed(test_runner);
|
||||
|
||||
srunner_free(test_runner);
|
||||
|
||||
return number_failed;
|
||||
test_av_flows();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -47,36 +47,24 @@ typedef struct {
|
|||
*/
|
||||
static void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data)
|
||||
{
|
||||
(void) av;
|
||||
(void) audio_enabled;
|
||||
(void) video_enabled;
|
||||
|
||||
printf("Handling CALL callback\n");
|
||||
((CallControl *)user_data)[friend_number].incoming = true;
|
||||
}
|
||||
|
||||
static void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data)
|
||||
{
|
||||
printf("Handling CALL STATE callback: %d %p\n", state, (void *)av);
|
||||
((CallControl *)user_data)[friend_number].state = state;
|
||||
}
|
||||
|
||||
static void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number,
|
||||
uint16_t width, uint16_t height,
|
||||
uint8_t const *y, uint8_t const *u, uint8_t const *v,
|
||||
int32_t ystride, int32_t ustride, int32_t vstride,
|
||||
void *user_data)
|
||||
{
|
||||
(void) av;
|
||||
(void) friend_number;
|
||||
(void) width;
|
||||
(void) height;
|
||||
(void) y;
|
||||
(void) u;
|
||||
(void) v;
|
||||
(void) ystride;
|
||||
(void) ustride;
|
||||
(void) vstride;
|
||||
(void) user_data;
|
||||
}
|
||||
|
||||
static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number,
|
||||
int16_t const *pcm,
|
||||
size_t sample_count,
|
||||
|
@ -84,19 +72,11 @@ static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number,
|
|||
uint32_t sampling_rate,
|
||||
void *user_data)
|
||||
{
|
||||
(void) av;
|
||||
(void) friend_number;
|
||||
(void) pcm;
|
||||
(void) sample_count;
|
||||
(void) channels;
|
||||
(void) sampling_rate;
|
||||
(void) user_data;
|
||||
}
|
||||
|
||||
static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length,
|
||||
void *userdata)
|
||||
{
|
||||
(void) userdata;
|
||||
|
||||
if (length == 7 && memcmp("gentoo", data, 7) == 0) {
|
||||
ck_assert(tox_friend_add_norequest(m, public_key, nullptr) != (uint32_t) ~0);
|
||||
}
|
||||
|
@ -120,6 +100,7 @@ static ToxAV *setup_av_instance(Tox *tox, CallControl *CC)
|
|||
|
||||
return av;
|
||||
}
|
||||
|
||||
static void *call_thread(void *pd)
|
||||
{
|
||||
ToxAV *AliceAV = ((thread_data *) pd)->AliceAV;
|
||||
|
@ -197,8 +178,7 @@ static void *call_thread(void *pd)
|
|||
pthread_exit(nullptr);
|
||||
}
|
||||
|
||||
|
||||
START_TEST(test_AV_three_calls)
|
||||
static void test_av_three_calls(void)
|
||||
{
|
||||
uint32_t index[] = { 1, 2, 3, 4, 5 };
|
||||
Tox *Alice, *bootstrap, *Bobs[3];
|
||||
|
@ -228,13 +208,23 @@ START_TEST(test_AV_three_calls)
|
|||
|
||||
printf("Created 5 instances of Tox\n");
|
||||
printf("Preparing network...\n");
|
||||
long long unsigned int cur_time = time(nullptr);
|
||||
time_t cur_time = time(nullptr);
|
||||
|
||||
uint8_t address[TOX_ADDRESS_SIZE];
|
||||
|
||||
tox_callback_friend_request(Alice, t_accept_friend_request_cb);
|
||||
tox_self_get_address(Alice, address);
|
||||
|
||||
printf("bootstrapping Alice and the %zd Bobs off a third bootstrap node\n",
|
||||
sizeof(Bobs) / sizeof(Bobs[0]));
|
||||
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
|
||||
tox_self_get_dht_id(bootstrap, dht_key);
|
||||
const uint16_t dht_port = tox_self_get_udp_port(bootstrap, nullptr);
|
||||
|
||||
tox_bootstrap(Alice, "localhost", dht_port, dht_key, nullptr);
|
||||
tox_bootstrap(Bobs[0], "localhost", dht_port, dht_key, nullptr);
|
||||
tox_bootstrap(Bobs[1], "localhost", dht_port, dht_key, nullptr);
|
||||
tox_bootstrap(Bobs[2], "localhost", dht_port, dht_key, nullptr);
|
||||
|
||||
ck_assert(tox_friend_add(Bobs[0], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0);
|
||||
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)
|
|||
tox_self_get_connection_status(Bobs[0]) &&
|
||||
tox_self_get_connection_status(Bobs[1]) &&
|
||||
tox_self_get_connection_status(Bobs[2]) && off) {
|
||||
printf("Toxes are online, took %llu seconds\n", time(nullptr) - cur_time);
|
||||
printf("Toxes are online, took %ld seconds\n", time(nullptr) - cur_time);
|
||||
off = 0;
|
||||
}
|
||||
|
||||
|
@ -276,7 +266,7 @@ START_TEST(test_AV_three_calls)
|
|||
BobsAV[2] = setup_av_instance(Bobs[2], BobsCC + 2);
|
||||
|
||||
printf("Created 4 instances of ToxAV\n");
|
||||
printf("All set after %llu seconds!\n", time(nullptr) - cur_time);
|
||||
printf("All set after %ld seconds!\n", time(nullptr) - cur_time);
|
||||
|
||||
thread_data tds[3];
|
||||
tds[0].AliceAV = AliceAV;
|
||||
|
@ -305,6 +295,7 @@ START_TEST(test_AV_three_calls)
|
|||
time_t start_time = time(nullptr);
|
||||
|
||||
while (time(nullptr) - start_time < 5) {
|
||||
tox_iterate(bootstrap, nullptr);
|
||||
tox_iterate(Alice, nullptr);
|
||||
tox_iterate(Bobs[0], nullptr);
|
||||
tox_iterate(Bobs[1], nullptr);
|
||||
|
@ -322,44 +313,23 @@ START_TEST(test_AV_three_calls)
|
|||
ck_assert(retval == nullptr);
|
||||
|
||||
printf("Killing all instances\n");
|
||||
toxav_kill(BobsAV[0]);
|
||||
toxav_kill(BobsAV[1]);
|
||||
toxav_kill(BobsAV[2]);
|
||||
toxav_kill(BobsAV[1]);
|
||||
toxav_kill(BobsAV[0]);
|
||||
toxav_kill(AliceAV);
|
||||
tox_kill(Bobs[0]);
|
||||
tox_kill(Bobs[1]);
|
||||
tox_kill(Bobs[2]);
|
||||
tox_kill(Bobs[1]);
|
||||
tox_kill(Bobs[0]);
|
||||
tox_kill(Alice);
|
||||
tox_kill(bootstrap);
|
||||
|
||||
printf("\nTest successful!\n");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
||||
static Suite *tox_suite(void)
|
||||
{
|
||||
Suite *s = suite_create("ToxAV");
|
||||
|
||||
DEFTESTCASE(AV_three_calls);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
Suite *tox = tox_suite();
|
||||
SRunner *test_runner = srunner_create(tox);
|
||||
|
||||
setbuf(stdout, nullptr);
|
||||
|
||||
srunner_run_all(test_runner, CK_NORMAL);
|
||||
int number_failed = srunner_ntests_failed(test_runner);
|
||||
|
||||
srunner_free(test_runner);
|
||||
|
||||
return number_failed;
|
||||
test_av_three_calls();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user