2014-08-08 04:59:47 +08:00
|
|
|
#ifndef TOXCORE_TEST_HELPERS_H
|
|
|
|
#define TOXCORE_TEST_HELPERS_H
|
|
|
|
|
2016-11-06 00:52:41 +08:00
|
|
|
#include "../toxcore/tox.h"
|
|
|
|
|
2016-12-22 18:44:33 +08:00
|
|
|
#include <assert.h>
|
2014-08-08 04:59:47 +08:00
|
|
|
#include <check.h>
|
2016-11-06 00:52:41 +08:00
|
|
|
#include <stdio.h>
|
2014-08-08 04:59:47 +08:00
|
|
|
|
|
|
|
#define DEFTESTCASE(NAME) \
|
|
|
|
TCase *tc_##NAME = tcase_create(#NAME); \
|
|
|
|
tcase_add_test(tc_##NAME, test_##NAME); \
|
|
|
|
suite_add_tcase(s, tc_##NAME);
|
|
|
|
|
|
|
|
#define DEFTESTCASE_SLOW(NAME, TIMEOUT) \
|
|
|
|
DEFTESTCASE(NAME) \
|
|
|
|
tcase_set_timeout(tc_##NAME, TIMEOUT);
|
|
|
|
|
2016-11-06 00:52:41 +08:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_debug_log(Tox *m, TOX_LOG_LEVEL level, const char *path, 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;
|
|
|
|
const char *file = strrchr(path, '/');
|
|
|
|
file = file ? file + 1 : path;
|
|
|
|
printf("[#%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)
|
|
|
|
{
|
2016-12-23 08:26:46 +08:00
|
|
|
struct Tox_Options *log_options = options;
|
2016-11-06 00:52:41 +08:00
|
|
|
|
2016-12-23 08:26:46 +08:00
|
|
|
if (log_options == NULL) {
|
|
|
|
log_options = tox_options_new(NULL);
|
2016-11-06 00:52:41 +08:00
|
|
|
}
|
|
|
|
|
2016-12-23 08:26:46 +08:00
|
|
|
assert(log_options != NULL);
|
|
|
|
|
2016-12-22 18:44:33 +08:00
|
|
|
tox_options_set_log_callback(log_options, &print_debug_log);
|
|
|
|
tox_options_set_log_user_data(log_options, log_user_data);
|
2016-12-23 08:26:46 +08:00
|
|
|
Tox *tox = tox_new(log_options, err);
|
|
|
|
|
|
|
|
if (options == NULL) {
|
|
|
|
tox_options_free(log_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
return tox;
|
2016-11-06 00:52:41 +08:00
|
|
|
}
|
|
|
|
|
2014-08-10 05:35:23 +08:00
|
|
|
#endif // TOXCORE_TEST_HELPERS_H
|