diff --git a/auto_tests/auto_test_support.c b/auto_tests/auto_test_support.c index 2a45d0ca0..5d7208b8d 100644 --- a/auto_tests/auto_test_support.c +++ b/auto_tests/auto_test_support.c @@ -1,3 +1,4 @@ +#include // assert #include // calloc, free #include "check_compat.h" @@ -323,3 +324,70 @@ void run_auto_test(struct Tox_Options *options, uint32_t tox_count, void test(Au free(autotoxes); } + +static const char *tox_log_level_name(Tox_Log_Level level) +{ + switch (level) { + case TOX_LOG_LEVEL_TRACE: + return "TRACE"; + + case TOX_LOG_LEVEL_DEBUG: + return "DEBUG"; + + case TOX_LOG_LEVEL_INFO: + return "INFO"; + + case TOX_LOG_LEVEL_WARNING: + return "WARNING"; + + case TOX_LOG_LEVEL_ERROR: + return "ERROR"; + } + + return ""; +} + +void print_debug_log(Tox *m, Tox_Log_Level level, const char *file, uint32_t line, const char *func, + const char *message, void *user_data) +{ + if (level == TOX_LOG_LEVEL_TRACE) { + return; + } + + uint32_t index = user_data ? *(uint32_t *)user_data : 0; + fprintf(stderr, "[#%u] %s %s:%u\t%s:\t%s\n", index, tox_log_level_name(level), file, line, func, message); + + if (level == TOX_LOG_LEVEL_ERROR) { + fputs("Aborting test program\n", stderr); + abort(); + } +} + +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); + } + + assert(log_options != nullptr); + + tox_options_set_local_discovery_enabled(log_options, lan_discovery); + tox_options_set_start_port(log_options, 33445); + tox_options_set_end_port(log_options, 33445 + 2000); + 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); + + if (options == nullptr) { + tox_options_free(log_options); + } + + 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); +} diff --git a/auto_tests/auto_test_support.h b/auto_tests/auto_test_support.h index f0296c1fc..3ba00a1d4 100644 --- a/auto_tests/auto_test_support.h +++ b/auto_tests/auto_test_support.h @@ -50,4 +50,10 @@ void run_auto_test(struct Tox_Options *options, uint32_t tox_count, void test(Au void bootstrap_tox_live_network(Tox *tox, bool enable_tcp); +void print_debug_log(Tox *m, Tox_Log_Level level, const char *file, uint32_t line, const char *func, + const char *message, void *user_data); + +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); + #endif diff --git a/auto_tests/conference_simple_test.c b/auto_tests/conference_simple_test.c index 9dafd862c..2c445d4b4 100644 --- a/auto_tests/conference_simple_test.c +++ b/auto_tests/conference_simple_test.c @@ -3,6 +3,7 @@ #include "../testing/misc_tools.h" #include "../toxcore/tox.h" +#include "auto_test_support.h" #include "check_compat.h" typedef struct State { diff --git a/auto_tests/conference_two_test.c b/auto_tests/conference_two_test.c index 4509fbe4a..3a8b102ce 100644 --- a/auto_tests/conference_two_test.c +++ b/auto_tests/conference_two_test.c @@ -5,6 +5,7 @@ #include "../testing/misc_tools.h" #include "../toxcore/tox.h" +#include "auto_test_support.h" #include "check_compat.h" int main(void) diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c index 5b25f270b..2644e4fdb 100644 --- a/auto_tests/dht_test.c +++ b/auto_tests/dht_test.c @@ -1,3 +1,4 @@ +#include "auto_test_support.h" #include "check_compat.h" #include "../testing/misc_tools.h" #include "../toxcore/crypto_core.h" diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index 30812875c..138817053 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c @@ -11,6 +11,7 @@ #include "../toxcore/crypto_core.h" #include "../toxcore/tox.h" #include "../toxencryptsave/toxencryptsave.h" +#include "auto_test_support.h" #include "check_compat.h" static unsigned char test_salt[TOX_PASS_SALT_LENGTH] = {0xB1, 0xC2, 0x09, 0xEE, 0x50, 0x6C, 0xF0, 0x20, 0xC4, 0xD6, 0xEB, 0xC0, 0x44, 0x51, 0x3B, 0x60, 0x4B, 0x39, 0x4A, 0xCF, 0x09, 0x53, 0x4F, 0xEA, 0x08, 0x41, 0xFA, 0xCA, 0x66, 0xD2, 0x68, 0x7F}; diff --git a/auto_tests/file_saving_test.c b/auto_tests/file_saving_test.c index 09031dee4..7dfba68c6 100644 --- a/auto_tests/file_saving_test.c +++ b/auto_tests/file_saving_test.c @@ -15,6 +15,7 @@ #include "../testing/misc_tools.h" #include "../toxcore/ccompat.h" +#include "auto_test_support.h" #include "check_compat.h" #include "../toxencryptsave/toxencryptsave.h" diff --git a/auto_tests/file_transfer_test.c b/auto_tests/file_transfer_test.c index 52f84973c..cf87b8298 100644 --- a/auto_tests/file_transfer_test.c +++ b/auto_tests/file_transfer_test.c @@ -10,6 +10,7 @@ #include "../toxcore/ccompat.h" #include "../toxcore/tox.h" #include "../toxcore/util.h" +#include "auto_test_support.h" #include "check_compat.h" /* The Travis-CI container responds poorly to ::1 as a localhost address diff --git a/auto_tests/friend_request_test.c b/auto_tests/friend_request_test.c index fa71b6bff..8fe8f2923 100644 --- a/auto_tests/friend_request_test.c +++ b/auto_tests/friend_request_test.c @@ -10,6 +10,7 @@ #include "../toxcore/tox.h" #include "../toxcore/util.h" #include "../testing/misc_tools.h" +#include "auto_test_support.h" #include "check_compat.h" #define FR_MESSAGE "Gentoo" diff --git a/auto_tests/invalid_tcp_proxy_test.c b/auto_tests/invalid_tcp_proxy_test.c index 1b8afa97e..08869c592 100644 --- a/auto_tests/invalid_tcp_proxy_test.c +++ b/auto_tests/invalid_tcp_proxy_test.c @@ -4,6 +4,7 @@ #include #include "../testing/misc_tools.h" +#include "auto_test_support.h" #include "check_compat.h" static uint8_t const key[] = { diff --git a/auto_tests/invalid_udp_proxy_test.c b/auto_tests/invalid_udp_proxy_test.c index 5bb8667ce..cf24be465 100644 --- a/auto_tests/invalid_udp_proxy_test.c +++ b/auto_tests/invalid_udp_proxy_test.c @@ -4,6 +4,7 @@ #include #include "../testing/misc_tools.h" +#include "auto_test_support.h" #include "check_compat.h" static uint8_t const key[] = { diff --git a/auto_tests/lan_discovery_test.c b/auto_tests/lan_discovery_test.c index 38d413590..e51efd32e 100644 --- a/auto_tests/lan_discovery_test.c +++ b/auto_tests/lan_discovery_test.c @@ -3,6 +3,7 @@ #include "../testing/misc_tools.h" #include "../toxcore/ccompat.h" +#include "auto_test_support.h" int main(void) { diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c index 3219da96c..fe20e6b7d 100644 --- a/auto_tests/messenger_test.c +++ b/auto_tests/messenger_test.c @@ -18,6 +18,7 @@ #include #endif +#include "auto_test_support.h" #include "check_compat.h" #include "../testing/misc_tools.h" #include "../toxcore/Messenger.h" diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index c245f756d..782187aac 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c @@ -7,6 +7,7 @@ #include "../toxcore/onion_announce.h" #include "../toxcore/onion_client.h" #include "../toxcore/util.h" +#include "auto_test_support.h" #include "check_compat.h" #ifndef USE_IPV6 diff --git a/auto_tests/save_compatibility_test.c b/auto_tests/save_compatibility_test.c index 437f3971a..8ef5185ae 100644 --- a/auto_tests/save_compatibility_test.c +++ b/auto_tests/save_compatibility_test.c @@ -2,6 +2,7 @@ #include "../testing/misc_tools.h" #include "../toxcore/tox.h" +#include "auto_test_support.h" #include "check_compat.h" #include diff --git a/auto_tests/save_friend_test.c b/auto_tests/save_friend_test.c index 6f50beda0..715fa006f 100644 --- a/auto_tests/save_friend_test.c +++ b/auto_tests/save_friend_test.c @@ -9,6 +9,7 @@ #include "../toxcore/ccompat.h" #include "../toxcore/crypto_core.h" #include "../toxcore/tox.h" +#include "auto_test_support.h" #include "check_compat.h" struct test_data { diff --git a/auto_tests/save_load_test.c b/auto_tests/save_load_test.c index 5dee55bc1..001b34e17 100644 --- a/auto_tests/save_load_test.c +++ b/auto_tests/save_load_test.c @@ -10,6 +10,7 @@ #include "../toxcore/ccompat.h" #include "../toxcore/tox.h" #include "../toxcore/util.h" +#include "auto_test_support.h" #include "check_compat.h" /* The Travis-CI container responds poorly to ::1 as a localhost address diff --git a/auto_tests/set_name_test.c b/auto_tests/set_name_test.c index 1dba7d103..9ad7946c4 100644 --- a/auto_tests/set_name_test.c +++ b/auto_tests/set_name_test.c @@ -10,6 +10,7 @@ #include "../toxcore/ccompat.h" #include "../toxcore/tox.h" #include "../toxcore/util.h" +#include "auto_test_support.h" #include "check_compat.h" #define NICKNAME "Gentoo" diff --git a/auto_tests/set_status_message_test.c b/auto_tests/set_status_message_test.c index 19e50a1f4..435d2239c 100644 --- a/auto_tests/set_status_message_test.c +++ b/auto_tests/set_status_message_test.c @@ -10,6 +10,7 @@ #include "../toxcore/ccompat.h" #include "../toxcore/tox.h" #include "../toxcore/util.h" +#include "auto_test_support.h" #include "check_compat.h" #define STATUS_MESSAGE "Installing Gentoo" diff --git a/auto_tests/tox_dispatch_test.c b/auto_tests/tox_dispatch_test.c index 0224aea80..9bcf508a1 100644 --- a/auto_tests/tox_dispatch_test.c +++ b/auto_tests/tox_dispatch_test.c @@ -10,6 +10,7 @@ #include "../toxcore/tox.h" #include "../toxcore/tox_dispatch.h" #include "../toxcore/tox_events.h" +#include "auto_test_support.h" #include "check_compat.h" // Set to true to produce an msgpack file at /tmp/test.mp. diff --git a/auto_tests/tox_events_test.c b/auto_tests/tox_events_test.c index 807880a10..52978628d 100644 --- a/auto_tests/tox_events_test.c +++ b/auto_tests/tox_events_test.c @@ -9,6 +9,7 @@ #include "../testing/misc_tools.h" #include "../toxcore/tox.h" #include "../toxcore/tox_events.h" +#include "auto_test_support.h" #include "check_compat.h" static bool await_message(Tox **toxes) diff --git a/auto_tests/tox_many_tcp_test.c b/auto_tests/tox_many_tcp_test.c index 058109f7f..39b25de0a 100644 --- a/auto_tests/tox_many_tcp_test.c +++ b/auto_tests/tox_many_tcp_test.c @@ -10,6 +10,7 @@ #include "../toxcore/crypto_core.h" #include "../toxcore/tox.h" #include "../toxcore/util.h" +#include "auto_test_support.h" #include "check_compat.h" /* The Travis-CI container responds poorly to ::1 as a localhost address diff --git a/auto_tests/tox_many_test.c b/auto_tests/tox_many_test.c index 7381ced5f..7ae319e67 100644 --- a/auto_tests/tox_many_test.c +++ b/auto_tests/tox_many_test.c @@ -10,6 +10,7 @@ #include "../toxcore/crypto_core.h" #include "../toxcore/tox.h" #include "../toxcore/util.h" +#include "auto_test_support.h" #include "check_compat.h" static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) diff --git a/auto_tests/tox_one_test.c b/auto_tests/tox_one_test.c index a44f5a5fd..3a14d1e38 100644 --- a/auto_tests/tox_one_test.c +++ b/auto_tests/tox_one_test.c @@ -9,6 +9,7 @@ #include "../toxcore/crypto_core.h" #include "../toxcore/tox.h" #include "../toxcore/util.h" +#include "auto_test_support.h" #include "check_compat.h" static void set_random_name_and_status_message(Tox *tox, uint8_t *name, uint8_t *status_message) diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index 5f3b73c08..ab97579a6 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c @@ -11,6 +11,7 @@ #include "../toxcore/logger.h" #include "../toxcore/tox.h" #include "../toxcore/util.h" +#include "auto_test_support.h" #include "check_compat.h" #define TEST_REGULAR_AV 1 diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index 34e11fb7f..2918da8da 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c @@ -17,6 +17,7 @@ #include "../toxcore/logger.h" #include "../toxcore/tox.h" #include "../toxcore/util.h" +#include "auto_test_support.h" #include "check_compat.h" typedef struct { diff --git a/testing/misc_tools.c b/testing/misc_tools.c index 1ff75153c..6e2f07f91 100644 --- a/testing/misc_tools.c +++ b/testing/misc_tools.c @@ -136,73 +136,6 @@ int cmdline_parsefor_ipv46(int argc, char **argv, bool *ipv6enabled) return argvoffset; } -static const char *tox_log_level_name(Tox_Log_Level level) -{ - switch (level) { - case TOX_LOG_LEVEL_TRACE: - return "TRACE"; - - case TOX_LOG_LEVEL_DEBUG: - return "DEBUG"; - - case TOX_LOG_LEVEL_INFO: - return "INFO"; - - case TOX_LOG_LEVEL_WARNING: - return "WARNING"; - - case TOX_LOG_LEVEL_ERROR: - return "ERROR"; - } - - return ""; -} - -void print_debug_log(Tox *m, Tox_Log_Level level, const char *file, uint32_t line, const char *func, - const char *message, void *user_data) -{ - if (level == TOX_LOG_LEVEL_TRACE) { - return; - } - - uint32_t index = user_data ? *(uint32_t *)user_data : 0; - fprintf(stderr, "[#%u] %s %s:%u\t%s:\t%s\n", index, tox_log_level_name(level), file, line, func, message); - - if (level == TOX_LOG_LEVEL_ERROR) { - fputs("Aborting test program\n", stderr); - abort(); - } -} - -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); - } - - assert(log_options != nullptr); - - tox_options_set_local_discovery_enabled(log_options, lan_discovery); - tox_options_set_start_port(log_options, 33445); - tox_options_set_end_port(log_options, 33445 + 2000); - 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); - - if (options == nullptr) { - tox_options_free(log_options); - } - - 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); -} - #ifndef VANILLA_NACL static const char *test_rng_name(void) diff --git a/testing/misc_tools.h b/testing/misc_tools.h index b9c3ca3e3..92fc95478 100644 --- a/testing/misc_tools.h +++ b/testing/misc_tools.h @@ -17,12 +17,6 @@ void to_hex(char *out, uint8_t *in, int size); int tox_strncasecmp(const char *s1, const char *s2, size_t n); int cmdline_parsefor_ipv46(int argc, char **argv, bool *ipv6enabled); -void print_debug_log(Tox *m, Tox_Log_Level level, const char *file, uint32_t line, const char *func, - const char *message, void *user_data); - -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); - int use_test_rng(uint32_t seed); #ifdef __cplusplus