mirror of
https://github.com/TokTok/c-toxcore
synced 2026-04-27 06:25:40 +00:00
refactor: Move tox_new_log to auto_test_support.
This is only used in auto tests.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include <assert.h> // assert
|
||||
#include <stdlib.h> // 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 "<unknown>";
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "auto_test_support.h"
|
||||
#include "check_compat.h"
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/crypto_core.h"
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "auto_test_support.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
static uint8_t const key[] = {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "auto_test_support.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
static uint8_t const key[] = {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "auto_test_support.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <sodium.h>
|
||||
#endif
|
||||
|
||||
#include "auto_test_support.h"
|
||||
#include "check_compat.h"
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/Messenger.h"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "auto_test_support.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 "<unknown>";
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user