Squashed 'external/toxcore/c-toxcore/' changes from e29e185c03..f1df709b87
f1df709b87 feat: add ngc events 1b6c907235 refactor: Make event dispatch ordered by receive time. b7f9367f6f test: Upgrade cppcheck, fix some warnings. 766e62bc89 chore: Use `pkg_search_module` directly in cmake. 00ff078f91 cleanup: Use target_link_libraries directly in cmake. c58928cc89 chore: Add `IMPORTED_TARGET` to pkg-config packages. 895a6af122 cleanup: Remove NaCl support. 41dfb1c1c0 fix: unpack enum function names in event impl generator 447666d1a1 chore: Disable targets for cross-compilation. 572924e924 chore: Build a docker image with coverage info in it. 415cb78f5e cleanup: Some portability/warning fixes for Windows builds. 425216d9ec fix: Correct a use-after-free and fix some memory leaks. 4b1cfa3e08 refactor: Change all enum-like `#define` sequences into enums. d3c2704fa9 chore: Fix make_single_file to support core-only. 0ce46b644e refactor: Change the `TCP_PACKET_*` defines into an enum. 22cd38ad50 adopt event impl generation tool to #2392 f31ea1088a add the event impl generation tool 4e603bb613 refactor: Use `enum-from-int` rule from tokstyle. 19d8f180d6 chore: Update github actions `uses`. 6a895be0c7 test: Make esp32 build actually try to instantiate tox. 65d09c9bfb cleanup: Remove test net support. REVERT: e29e185c03 feat: add ngc events git-subtree-dir: external/toxcore/c-toxcore git-subtree-split: f1df709b8792da4c0e946d826b11df77d565064d
This commit is contained in:
@ -3,18 +3,26 @@ set(TEST_TIMEOUT_SECONDS "" CACHE STRING "Limit runtime of each test to the numb
|
||||
add_library(auto_test_support
|
||||
auto_test_support.c
|
||||
auto_test_support.h)
|
||||
target_link_modules(auto_test_support toxcore misc_tools)
|
||||
target_link_libraries(auto_test_support PRIVATE misc_tools)
|
||||
if(TARGET toxcore_static)
|
||||
target_link_libraries(auto_test_support PRIVATE toxcore_static)
|
||||
else()
|
||||
target_link_libraries(auto_test_support PRIVATE toxcore_shared)
|
||||
endif()
|
||||
|
||||
function(auto_test target)
|
||||
if(AUTOTEST AND NOT (MSVC AND ARGV1 STREQUAL "MSVC_DONT_BUILD"))
|
||||
add_executable(auto_${target}_test ${target}_test.c)
|
||||
target_link_modules(auto_${target}_test toxcore misc_tools auto_test_support)
|
||||
if(NOT ARGV1 STREQUAL "DONT_RUN")
|
||||
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} auto_${target}_test)
|
||||
set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}")
|
||||
# add the source dir as environment variable, so the testdata can be found
|
||||
set_tests_properties(${target} PROPERTIES ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw;srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
endif()
|
||||
add_executable(auto_${target}_test ${target}_test.c)
|
||||
target_link_libraries(auto_${target}_test PRIVATE misc_tools auto_test_support)
|
||||
if(TARGET toxcore_static)
|
||||
target_link_libraries(auto_${target}_test PRIVATE toxcore_static)
|
||||
else()
|
||||
target_link_libraries(auto_${target}_test PRIVATE toxcore_shared)
|
||||
endif()
|
||||
if(NOT ARGV1 STREQUAL "DONT_RUN")
|
||||
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} auto_${target}_test)
|
||||
set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}")
|
||||
# add the source dir as environment variable, so the testdata can be found
|
||||
set_tests_properties(${target} PROPERTIES ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw;srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
@ -69,17 +77,28 @@ auto_test(typing)
|
||||
auto_test(version)
|
||||
auto_test(save_compatibility)
|
||||
|
||||
target_include_directories(auto_encryptsave_test SYSTEM PRIVATE ${LIBSODIUM_INCLUDE_DIRS})
|
||||
|
||||
if(NON_HERMETIC_TESTS)
|
||||
auto_test(bootstrap)
|
||||
auto_test(tcp_relay)
|
||||
endif()
|
||||
|
||||
if(BUILD_TOXAV)
|
||||
auto_test(conference_av MSVC_DONT_BUILD)
|
||||
auto_test(conference_av)
|
||||
auto_test(toxav_basic)
|
||||
auto_test(toxav_many)
|
||||
endif()
|
||||
|
||||
target_link_libraries(auto_toxav_basic_test PRIVATE ${VPX_LIBRARIES})
|
||||
target_link_directories(auto_toxav_basic_test PRIVATE ${VPX_LIBRARY_DIRS})
|
||||
target_include_directories(auto_toxav_basic_test SYSTEM PRIVATE ${VPX_INCLUDE_DIRS})
|
||||
target_compile_options(auto_toxav_basic_test PRIVATE ${VPX_CFLAGS_OTHER})
|
||||
|
||||
target_link_libraries(auto_toxav_many_test PRIVATE ${VPX_LIBRARIES})
|
||||
target_link_directories(auto_toxav_many_test PRIVATE ${VPX_LIBRARY_DIRS})
|
||||
target_include_directories(auto_toxav_many_test SYSTEM PRIVATE ${VPX_INCLUDE_DIRS})
|
||||
target_compile_options(auto_toxav_many_test PRIVATE ${VPX_CFLAGS_OTHER})
|
||||
endif()
|
||||
|
||||
if(PROXY_TEST)
|
||||
auto_test(proxy)
|
||||
|
@ -5,7 +5,7 @@ libauto_test_support_la_SOURCES = ../auto_tests/auto_test_support.c ../auto_test
|
||||
libauto_test_support_la_LIBADD = libmisc_tools.la libtoxcore.la
|
||||
|
||||
TESTS = \
|
||||
announce_test \
|
||||
announce_test \
|
||||
conference_double_invite_test \
|
||||
conference_invite_merge_test \
|
||||
conference_peer_nick_test \
|
||||
@ -13,6 +13,8 @@ TESTS = \
|
||||
conference_test \
|
||||
conference_two_test \
|
||||
crypto_test \
|
||||
encryptsave_test \
|
||||
file_saving_test \
|
||||
file_transfer_test \
|
||||
forwarding_test \
|
||||
friend_connection_test \
|
||||
@ -34,34 +36,24 @@ TESTS = \
|
||||
set_name_test \
|
||||
set_status_message_test \
|
||||
TCP_test \
|
||||
tox_events_test \
|
||||
tox_dispatch_test \
|
||||
tox_events_test \
|
||||
tox_many_tcp_test \
|
||||
tox_many_test \
|
||||
tox_strncasecmp_test \
|
||||
typing_test \
|
||||
version_test
|
||||
|
||||
if !WITH_NACL
|
||||
TESTS += \
|
||||
encryptsave_test \
|
||||
file_saving_test
|
||||
endif
|
||||
|
||||
AUTOTEST_CFLAGS = \
|
||||
$(LIBSODIUM_CFLAGS) \
|
||||
$(NACL_CFLAGS)
|
||||
$(LIBSODIUM_CFLAGS)
|
||||
|
||||
AUTOTEST_LDADD = \
|
||||
$(LIBSODIUM_LDFLAGS) \
|
||||
$(NACL_LDFLAGS) \
|
||||
libmisc_tools.la \
|
||||
libauto_test_support.la \
|
||||
libtoxcore.la \
|
||||
libtoxencryptsave.la \
|
||||
$(LIBSODIUM_LIBS) \
|
||||
$(NACL_OBJECTS) \
|
||||
$(NACL_LIBS)
|
||||
$(LIBSODIUM_LIBS)
|
||||
|
||||
|
||||
if BUILD_AV
|
||||
|
@ -61,9 +61,13 @@ static void test_store_data(void)
|
||||
ck_assert(log != nullptr);
|
||||
logger_callback_log(log, print_debug_logger, nullptr, nullptr);
|
||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
ck_assert(mono_time != nullptr);
|
||||
Networking_Core *net = new_networking_no_udp(log, mem, ns);
|
||||
ck_assert(net != nullptr);
|
||||
DHT *dht = new_dht(log, mem, rng, ns, mono_time, net, true, true);
|
||||
ck_assert(dht != nullptr);
|
||||
Forwarding *forwarding = new_forwarding(log, rng, mono_time, dht);
|
||||
ck_assert(forwarding != nullptr);
|
||||
Announcements *announce = new_announcements(log, mem, rng, mono_time, forwarding);
|
||||
ck_assert(announce != nullptr);
|
||||
|
||||
|
@ -28,7 +28,6 @@ static const struct BootstrapNodes {
|
||||
uint16_t port;
|
||||
const uint8_t key[32];
|
||||
} bootstrap_nodes[] = {
|
||||
#ifndef USE_TEST_NETWORK
|
||||
{
|
||||
"tox.abilinski.com", 33445,
|
||||
0x10, 0xC0, 0x0E, 0xB2, 0x50, 0xC3, 0x23, 0x3E,
|
||||
@ -57,22 +56,6 @@ static const struct BootstrapNodes {
|
||||
0x6D, 0xC9, 0xD0, 0xA3, 0x00, 0xE6, 0xC3, 0x57,
|
||||
0x63, 0x4E, 0xE2, 0xDA, 0x88, 0xC3, 0x54, 0x63,
|
||||
},
|
||||
#else
|
||||
{
|
||||
"172.93.52.70", 33445,
|
||||
0x79, 0xCA, 0xDA, 0x49, 0x74, 0xB0, 0x92, 0x6F,
|
||||
0x28, 0x6F, 0x02, 0x5C, 0xD5, 0xFF, 0xDF, 0x3E,
|
||||
0x65, 0x4A, 0x37, 0x58, 0xC5, 0x3E, 0x02, 0x73,
|
||||
0xEC, 0xFC, 0x4D, 0x12, 0xC2, 0x1D, 0xCA, 0x48,
|
||||
},
|
||||
{
|
||||
"tox.plastiras.org", 38445,
|
||||
0x5E, 0x47, 0xBA, 0x1D, 0xC3, 0x91, 0x3E, 0xB2,
|
||||
0xCB, 0xF2, 0xD6, 0x4C, 0xE4, 0xF2, 0x3D, 0x8B,
|
||||
0xFE, 0x53, 0x91, 0xBF, 0xAB, 0xE5, 0xC4, 0x3C,
|
||||
0x5B, 0xAD, 0x13, 0xF0, 0xA4, 0x14, 0xCD, 0x77,
|
||||
},
|
||||
#endif // USE_TEST_NETWORK
|
||||
{ nullptr, 0, 0 },
|
||||
};
|
||||
|
||||
@ -332,7 +315,7 @@ static void bootstrap_autotoxes(struct Tox_Options *options, uint32_t tox_count,
|
||||
for (uint32_t i = 1; i < tox_count; ++i) {
|
||||
Tox_Err_Bootstrap err;
|
||||
tox_bootstrap(autotoxes[i].tox, "localhost", dht_port, dht_key, &err);
|
||||
ck_assert(err == TOX_ERR_BOOTSTRAP_OK);
|
||||
ck_assert_msg(err == TOX_ERR_BOOTSTRAP_OK, "bootstrap error for port %d: %d", dht_port, err);
|
||||
}
|
||||
|
||||
if (!udp_enabled) {
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifndef VANILLA_NACL
|
||||
#include <sodium.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
@ -232,9 +231,3 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else // VANILLA_NACL
|
||||
int main(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -259,7 +259,6 @@ static void group_peer_status_handler(Tox *tox, uint32_t groupnumber, uint32_t p
|
||||
|
||||
static void group_announce_test(AutoTox *autotoxes)
|
||||
{
|
||||
#ifndef VANILLA_NACL
|
||||
ck_assert_msg(NUM_GROUP_TOXES == 2, "NUM_GROUP_TOXES needs to be 2");
|
||||
|
||||
Tox *tox0 = autotoxes[0].tox;
|
||||
@ -436,7 +435,6 @@ static void group_announce_test(AutoTox *autotoxes)
|
||||
ck_assert(num_groups1 == num_groups2 && num_groups2 == 0);
|
||||
|
||||
printf("All tests passed!\n");
|
||||
#endif // VANILLA_NACL
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
@ -102,7 +102,6 @@ static void group_peer_join_handler(Tox *tox, uint32_t group_number, uint32_t pe
|
||||
|
||||
static void group_invite_test(AutoTox *autotoxes)
|
||||
{
|
||||
#ifndef VANILLA_NACL
|
||||
ck_assert_msg(NUM_GROUP_TOXES > 7, "NUM_GROUP_TOXES is too small: %d", NUM_GROUP_TOXES);
|
||||
|
||||
for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) {
|
||||
@ -260,8 +259,6 @@ static void group_invite_test(AutoTox *autotoxes)
|
||||
}
|
||||
|
||||
printf("All tests passed!\n");
|
||||
|
||||
#endif // VANILLA_NACL
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
@ -350,7 +350,6 @@ static void group_message_handler_wraparound_test(Tox *tox, uint32_t groupnumber
|
||||
|
||||
static void group_message_test(AutoTox *autotoxes)
|
||||
{
|
||||
#ifndef VANILLA_NACL
|
||||
ck_assert_msg(NUM_GROUP_TOXES >= 2, "NUM_GROUP_TOXES is too small: %d", NUM_GROUP_TOXES);
|
||||
|
||||
const Random *rng = system_random();
|
||||
@ -544,7 +543,6 @@ static void group_message_test(AutoTox *autotoxes)
|
||||
}
|
||||
|
||||
fprintf(stderr, "All tests passed!\n");
|
||||
#endif // VANILLA_NACL
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
@ -432,7 +432,6 @@ static void check_voice_state(AutoTox *autotoxes, uint32_t num_toxes)
|
||||
|
||||
static void group_moderation_test(AutoTox *autotoxes)
|
||||
{
|
||||
#ifndef VANILLA_NACL
|
||||
ck_assert_msg(NUM_GROUP_TOXES >= 4, "NUM_GROUP_TOXES is too small: %d", NUM_GROUP_TOXES);
|
||||
ck_assert_msg(NUM_GROUP_TOXES < 10, "NUM_GROUP_TOXES is too big: %d", NUM_GROUP_TOXES);
|
||||
|
||||
@ -634,7 +633,6 @@ static void group_moderation_test(AutoTox *autotoxes)
|
||||
}
|
||||
|
||||
fprintf(stderr, "All tests passed!\n");
|
||||
#endif // VANILLA_NACL
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
@ -148,7 +148,6 @@ static int has_correct_self_state(const Tox *tox, uint32_t group_number, const u
|
||||
|
||||
static void group_save_test(AutoTox *autotoxes)
|
||||
{
|
||||
#ifndef VANILLA_NACL
|
||||
ck_assert_msg(NUM_GROUP_TOXES > 1, "NUM_GROUP_TOXES is too small: %d", NUM_GROUP_TOXES);
|
||||
|
||||
for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) {
|
||||
@ -270,8 +269,6 @@ static void group_save_test(AutoTox *autotoxes)
|
||||
tox_kill(new_tox);
|
||||
|
||||
printf("All tests passed!\n");
|
||||
|
||||
#endif // VANILLA_NACL
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
@ -238,7 +238,6 @@ static void set_group_state(Tox *tox, uint32_t groupnumber, uint32_t peer_limit,
|
||||
|
||||
static void group_state_test(AutoTox *autotoxes)
|
||||
{
|
||||
#ifndef VANILLA_NACL
|
||||
ck_assert_msg(NUM_GROUP_TOXES >= 3, "NUM_GROUP_TOXES is too small: %d", NUM_GROUP_TOXES);
|
||||
|
||||
for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) {
|
||||
@ -318,8 +317,6 @@ static void group_state_test(AutoTox *autotoxes)
|
||||
}
|
||||
|
||||
fprintf(stderr, "All tests passed!\n");
|
||||
|
||||
#endif /* VANILLA_NACL */
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
@ -330,7 +330,6 @@ static void topic_spam(const Random *rng, AutoTox *autotoxes, uint32_t num_peers
|
||||
|
||||
static void group_sync_test(AutoTox *autotoxes)
|
||||
{
|
||||
#ifndef VANILLA_NACL
|
||||
ck_assert(NUM_GROUP_TOXES >= 5);
|
||||
const Random *rng = system_random();
|
||||
ck_assert(rng != nullptr);
|
||||
@ -443,8 +442,6 @@ static void group_sync_test(AutoTox *autotoxes)
|
||||
}
|
||||
|
||||
fprintf(stderr, "All tests passed!\n");
|
||||
|
||||
#endif // VANILLA_NACL
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
@ -8,8 +8,6 @@
|
||||
|
||||
#include "auto_test_support.h"
|
||||
|
||||
#ifdef USE_TEST_NETWORK
|
||||
|
||||
#define NUM_GROUP_TOXES 2
|
||||
#define CODEWORD "RONALD MCDONALD"
|
||||
#define CODEWORD_LEN (sizeof(CODEWORD) - 1)
|
||||
@ -129,7 +127,6 @@ static bool all_peers_got_code(AutoTox *autotoxes)
|
||||
|
||||
static void group_tcp_test(AutoTox *autotoxes)
|
||||
{
|
||||
#ifndef VANILLA_NACL
|
||||
ck_assert(NUM_GROUP_TOXES >= 2);
|
||||
|
||||
State *state0 = (State *)autotoxes[0].state;
|
||||
@ -222,34 +219,29 @@ static void group_tcp_test(AutoTox *autotoxes)
|
||||
}
|
||||
|
||||
printf("Test passed!\n");
|
||||
|
||||
#endif // VANILLA_NACL
|
||||
}
|
||||
#endif // USE_TEST_NETWORK
|
||||
|
||||
int main(void)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#ifdef USE_TEST_NETWORK // TODO(Jfreegman): Enable this test when the mainnet works with DHT groupchats
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
struct Tox_Options *options = (struct Tox_Options *)calloc(1, sizeof(struct Tox_Options));
|
||||
struct Tox_Options *options = tox_options_new(nullptr);
|
||||
ck_assert(options != nullptr);
|
||||
|
||||
tox_options_default(options);
|
||||
tox_options_set_udp_enabled(options, false);
|
||||
|
||||
Run_Auto_Options autotest_opts = default_run_auto_options();
|
||||
autotest_opts.graph = GRAPH_COMPLETE;
|
||||
|
||||
run_auto_test(options, NUM_GROUP_TOXES, group_tcp_test, sizeof(State), &autotest_opts);
|
||||
// TODO(JFreegman): Fix this test and remove the "if".
|
||||
if (argc > 2) {
|
||||
run_auto_test(options, NUM_GROUP_TOXES, group_tcp_test, sizeof(State), &autotest_opts);
|
||||
}
|
||||
|
||||
tox_options_free(options);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef USE_TEST_NETWORK
|
||||
#undef NUM_GROUP_TOXES
|
||||
#undef CODEWORD_LEN
|
||||
#undef CODEWORD
|
||||
#endif // USE_TEST_NETWORK
|
||||
#undef NUM_GROUP_TOXES
|
||||
|
@ -203,7 +203,6 @@ static uint32_t set_topic_all_peers(const Random *rng, AutoTox *autotoxes, size_
|
||||
|
||||
static void group_topic_test(AutoTox *autotoxes)
|
||||
{
|
||||
#ifndef VANILLA_NACL
|
||||
ck_assert_msg(NUM_GROUP_TOXES >= 3, "NUM_GROUP_TOXES is too small: %d", NUM_GROUP_TOXES);
|
||||
|
||||
const Random *rng = system_random();
|
||||
@ -318,8 +317,6 @@ static void group_topic_test(AutoTox *autotoxes)
|
||||
}
|
||||
|
||||
fprintf(stderr, "All tests passed!\n");
|
||||
|
||||
#endif /* VANILLA_NACL */
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
@ -7,15 +7,8 @@
|
||||
#include "auto_test_support.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
static uint8_t const key[] = {
|
||||
0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD,
|
||||
0xDF, 0x0E, 0xBA, 0x05, 0x7D, 0xAB, 0xB4, 0x9F,
|
||||
0xE1, 0x5F, 0x38, 0x03, 0xB1, 0xBF, 0xF0, 0x65,
|
||||
0x36, 0xAE, 0x2E, 0x5B, 0xA5, 0xE4, 0x69, 0x0E,
|
||||
};
|
||||
|
||||
// Try to bootstrap for 30 seconds.
|
||||
#define NUM_ITERATIONS (unsigned)(30.0 / (ITERATION_INTERVAL / 1000.0))
|
||||
// Try to bootstrap for 20 seconds.
|
||||
#define NUM_ITERATIONS (unsigned)(20.0 / (ITERATION_INTERVAL / 1000.0))
|
||||
|
||||
int main(void)
|
||||
{
|
||||
@ -24,13 +17,12 @@ int main(void)
|
||||
struct Tox_Options *opts = tox_options_new(nullptr);
|
||||
tox_options_set_udp_enabled(opts, false);
|
||||
tox_options_set_proxy_type(opts, TOX_PROXY_TYPE_SOCKS5);
|
||||
tox_options_set_proxy_host(opts, "localhost");
|
||||
tox_options_set_proxy_host(opts, "127.0.0.1");
|
||||
tox_options_set_proxy_port(opts, 51724);
|
||||
Tox *tox = tox_new_log(opts, nullptr, nullptr);
|
||||
tox_options_free(opts);
|
||||
|
||||
tox_add_tcp_relay(tox, "tox.ngc.zone", 33445, key, nullptr);
|
||||
tox_bootstrap(tox, "tox.ngc.zone", 33445, key, nullptr);
|
||||
bootstrap_tox_live_network(tox, true);
|
||||
|
||||
printf("Waiting for connection...\n");
|
||||
|
||||
|
@ -7,15 +7,8 @@
|
||||
#include "auto_test_support.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
static uint8_t const key[] = {
|
||||
0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD,
|
||||
0xDF, 0x0E, 0xBA, 0x05, 0x7D, 0xAB, 0xB4, 0x9F,
|
||||
0xE1, 0x5F, 0x38, 0x03, 0xB1, 0xBF, 0xF0, 0x65,
|
||||
0x36, 0xAE, 0x2E, 0x5B, 0xA5, 0xE4, 0x69, 0x0E,
|
||||
};
|
||||
|
||||
// Try to bootstrap for 30 seconds.
|
||||
#define NUM_ITERATIONS (unsigned)(30.0 / (ITERATION_INTERVAL / 1000.0))
|
||||
// Try to bootstrap for 20 seconds.
|
||||
#define NUM_ITERATIONS (unsigned)(20.0 / (ITERATION_INTERVAL / 1000.0))
|
||||
|
||||
int main(void)
|
||||
{
|
||||
@ -24,13 +17,12 @@ int main(void)
|
||||
struct Tox_Options *opts = tox_options_new(nullptr);
|
||||
tox_options_set_udp_enabled(opts, true);
|
||||
tox_options_set_proxy_type(opts, TOX_PROXY_TYPE_SOCKS5);
|
||||
tox_options_set_proxy_host(opts, "localhost");
|
||||
tox_options_set_proxy_host(opts, "127.0.0.1");
|
||||
tox_options_set_proxy_port(opts, 51724);
|
||||
Tox *tox = tox_new_log(opts, nullptr, nullptr);
|
||||
tox_options_free(opts);
|
||||
|
||||
tox_add_tcp_relay(tox, "tox.ngc.zone", 33445, key, nullptr);
|
||||
tox_bootstrap(tox, "tox.ngc.zone", 33445, key, nullptr);
|
||||
bootstrap_tox_live_network(tox, true);
|
||||
|
||||
printf("Waiting for connection...");
|
||||
|
||||
|
@ -42,6 +42,7 @@ static void send_message_test(AutoTox *autotoxes)
|
||||
|
||||
const size_t msgs_len = tox_max_message_length() + 1;
|
||||
uint8_t *msgs = (uint8_t *)malloc(msgs_len);
|
||||
ck_assert(msgs != nullptr);
|
||||
memset(msgs, MESSAGE_FILLER, msgs_len);
|
||||
|
||||
Tox_Err_Friend_Send_Message errm;
|
||||
|
@ -31,31 +31,36 @@ static void handle_events_friend_message(Tox *tox, const Tox_Event_Friend_Messag
|
||||
|
||||
static void dump_events(const char *path, const Tox_Events *events)
|
||||
{
|
||||
if (want_dump_events) {
|
||||
FILE *fh = fopen(path, "w");
|
||||
ck_assert(fh != nullptr);
|
||||
const uint32_t len = tox_events_bytes_size(events);
|
||||
uint8_t *buf = (uint8_t *)malloc(len);
|
||||
ck_assert(buf != nullptr);
|
||||
tox_events_get_bytes(events, buf);
|
||||
fwrite(buf, 1, len, fh);
|
||||
free(buf);
|
||||
fclose(fh);
|
||||
}
|
||||
FILE *fh = fopen(path, "w");
|
||||
ck_assert(fh != nullptr);
|
||||
const uint32_t len = tox_events_bytes_size(events);
|
||||
uint8_t *buf = (uint8_t *)malloc(len);
|
||||
ck_assert(buf != nullptr);
|
||||
ck_assert(tox_events_get_bytes(events, buf));
|
||||
fwrite(buf, 1, len, fh);
|
||||
free(buf);
|
||||
fclose(fh);
|
||||
}
|
||||
|
||||
static void print_events(const Tox_System *sys, Tox_Events *events)
|
||||
{
|
||||
const uint32_t size = tox_events_bytes_size(events);
|
||||
|
||||
uint8_t *bytes = (uint8_t *)malloc(size);
|
||||
ck_assert(bytes != nullptr);
|
||||
uint8_t *bytes1 = (uint8_t *)malloc(size);
|
||||
uint8_t *bytes2 = (uint8_t *)malloc(size);
|
||||
ck_assert(bytes1 != nullptr);
|
||||
ck_assert(bytes2 != nullptr);
|
||||
|
||||
tox_events_get_bytes(events, bytes);
|
||||
ck_assert(tox_events_get_bytes(events, bytes1));
|
||||
ck_assert(tox_events_get_bytes(events, bytes2));
|
||||
|
||||
Tox_Events *events_copy = tox_events_load(sys, bytes, size);
|
||||
// Make sure get_bytes is deterministic.
|
||||
ck_assert(memcmp(bytes1, bytes2, size) == 0);
|
||||
|
||||
Tox_Events *events_copy = tox_events_load(sys, bytes1, size);
|
||||
ck_assert(events_copy != nullptr);
|
||||
free(bytes);
|
||||
free(bytes1);
|
||||
free(bytes2);
|
||||
|
||||
ck_assert(tox_events_equal(sys, events, events_copy));
|
||||
|
||||
@ -73,7 +78,9 @@ static bool await_message(Tox **toxes, const Tox_Dispatch *dispatch)
|
||||
// Check if tox 2 got the message from tox 1.
|
||||
Tox_Events *events = tox_events_iterate(toxes[1], false, nullptr);
|
||||
|
||||
dump_events("/tmp/test.mp", events);
|
||||
if (want_dump_events) {
|
||||
dump_events("/tmp/test.mp", events);
|
||||
}
|
||||
|
||||
bool success = false;
|
||||
tox_dispatch_invoke(dispatch, events, toxes[1], &success);
|
||||
@ -164,13 +171,13 @@ static void test_tox_events(void)
|
||||
static void fake_test_unpack(void)
|
||||
{
|
||||
// TODO(Green-Sky): add proper unpack tests and/or implement ngc events
|
||||
(void)tox_unpack_group_privacy_state;
|
||||
(void)tox_unpack_group_privacy_state;
|
||||
(void)tox_unpack_group_voice_state;
|
||||
(void)tox_unpack_group_topic_lock;
|
||||
(void)tox_unpack_group_join_fail;
|
||||
(void)tox_unpack_group_mod_event;
|
||||
(void)tox_unpack_group_exit_type;
|
||||
(void)tox_group_privacy_state_unpack;
|
||||
(void)tox_group_privacy_state_unpack;
|
||||
(void)tox_group_voice_state_unpack;
|
||||
(void)tox_group_topic_lock_unpack;
|
||||
(void)tox_group_join_fail_unpack;
|
||||
(void)tox_group_mod_event_unpack;
|
||||
(void)tox_group_exit_type_unpack;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
@ -28,6 +28,15 @@ static bool await_message(Tox **toxes)
|
||||
const uint8_t *msg = tox_event_friend_message_get_message(msg_event);
|
||||
ck_assert_msg(memcmp(msg, "hello", sizeof("hello")) == 0,
|
||||
"message was not expected 'hello' but '%s'", (const char *)msg);
|
||||
|
||||
const uint32_t event_count = tox_events_get_size(events);
|
||||
for (uint32_t j = 0; j < event_count; ++j) {
|
||||
const Tox_Event *event = tox_events_get(events, j);
|
||||
if (tox_event_get_type(event) == TOX_EVENT_FRIEND_MESSAGE) {
|
||||
ck_assert(tox_event_get_friend_message(event) == msg_event);
|
||||
}
|
||||
}
|
||||
|
||||
tox_events_free(events);
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user