mirror of
https://github.com/TokTok/c-toxcore
synced 2026-10-23 10:52:21 +00:00
Avoid implementations in .h files or #including .c files.
Also, avoid the need for putting `_XOPEN_SOURCE` in every test file.
This commit is contained in:
59 files changed
+364
-439
No files matched your search
@@ -46,6 +46,7 @@ matrix:
|
||||
- libcv-dev # For av_test.
|
||||
- libhighgui-dev # For av_test.
|
||||
- libopencv-contrib-dev # For av_test.
|
||||
- libsndfile1-dev # For av_test.
|
||||
- portaudio19-dev # For av_test.
|
||||
before_install:
|
||||
# Clear bazel installation.
|
||||
|
||||
+10
-5
@@ -371,6 +371,11 @@ unit_test(toxcore util)
|
||||
#
|
||||
################################################################################
|
||||
|
||||
add_library(misc_tools
|
||||
testing/misc_tools.c
|
||||
testing/misc_tools.h)
|
||||
target_link_modules(misc_tools toxcore)
|
||||
|
||||
set(TEST_TIMEOUT_SECONDS "" CACHE STRING "Limit runtime of each test to the number of seconds specified")
|
||||
|
||||
if(ANDROID_CPU_FEATURES)
|
||||
@@ -389,7 +394,7 @@ function(auto_test target)
|
||||
if(NOT (MSVC AND ARGV1 STREQUAL "MSVC_DONT_BUILD"))
|
||||
add_executable(auto_${target}_test ${CPUFEATURES}
|
||||
auto_tests/${target}_test.c)
|
||||
target_link_modules(auto_${target}_test toxcore)
|
||||
target_link_modules(auto_${target}_test toxcore misc_tools)
|
||||
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}")
|
||||
@@ -459,7 +464,7 @@ if(DHT_BOOTSTRAP)
|
||||
add_executable(DHT_bootstrap ${CPUFEATURES}
|
||||
other/DHT_bootstrap.c
|
||||
other/bootstrap_node_packets.c)
|
||||
target_link_modules(DHT_bootstrap toxcore)
|
||||
target_link_modules(DHT_bootstrap toxcore misc_tools)
|
||||
endif()
|
||||
|
||||
option(BOOTSTRAP_DAEMON "Enable building of tox-bootstrapd" ON)
|
||||
@@ -519,12 +524,12 @@ endif()
|
||||
|
||||
add_executable(DHT_test ${CPUFEATURES}
|
||||
testing/DHT_test.c)
|
||||
target_link_modules(DHT_test toxcore)
|
||||
target_link_modules(DHT_test toxcore misc_tools)
|
||||
|
||||
add_executable(Messenger_test ${CPUFEATURES}
|
||||
testing/Messenger_test.c)
|
||||
target_link_modules(Messenger_test toxcore)
|
||||
target_link_modules(Messenger_test toxcore misc_tools)
|
||||
|
||||
add_executable(random_testing ${CPUFEATURES}
|
||||
testing/random_testing.cc)
|
||||
target_link_modules(random_testing toxcore)
|
||||
target_link_modules(random_testing toxcore misc_tools)
|
||||
+12
-8
@@ -1,11 +1,13 @@
|
||||
cc_library(
|
||||
name = "helpers",
|
||||
name = "check_compat",
|
||||
testonly = True,
|
||||
hdrs = [
|
||||
"check_compat.h",
|
||||
"helpers.h",
|
||||
"run_auto_test.h",
|
||||
],
|
||||
hdrs = ["check_compat.h"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "run_auto_test",
|
||||
testonly = True,
|
||||
hdrs = ["run_auto_test.h"],
|
||||
)
|
||||
|
||||
test_sizes = {
|
||||
@@ -21,7 +23,8 @@ test_sizes = {
|
||||
srcs = [src],
|
||||
copts = ["-Wno-sign-compare"],
|
||||
deps = [
|
||||
":helpers",
|
||||
":check_compat",
|
||||
":run_auto_test",
|
||||
"//c-toxcore/other:monolith",
|
||||
"//c-toxcore/testing:misc_tools",
|
||||
"//c-toxcore/toxav",
|
||||
@@ -44,8 +47,9 @@ cc_test(
|
||||
srcs = ["monolith_test.cc"],
|
||||
copts = ["-Wno-sign-compare"],
|
||||
deps = [
|
||||
":helpers",
|
||||
":check_compat",
|
||||
":monolith",
|
||||
":run_auto_test",
|
||||
"//c-toxcore/other:monolith",
|
||||
"//c-toxcore/testing:misc_tools",
|
||||
],
|
||||
|
||||
@@ -10,6 +10,7 @@ AUTOTEST_CFLAGS = \
|
||||
AUTOTEST_LDADD = \
|
||||
$(LIBSODIUM_LDFLAGS) \
|
||||
$(NACL_LDFLAGS) \
|
||||
libmisc_tools.la \
|
||||
libtoxcore.la \
|
||||
libtoxencryptsave.la \
|
||||
$(LIBSODIUM_LIBS) \
|
||||
@@ -115,4 +116,3 @@ tox_strncasecmp_test_LDADD = $(AUTOTEST_LDADD)
|
||||
|
||||
|
||||
EXTRA_DIST += $(top_srcdir)/auto_tests/check_compat.h
|
||||
EXTRA_DIST += $(top_srcdir)/auto_tests/helpers.h
|
||||
+2
-14
@@ -1,27 +1,17 @@
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/TCP_client.h"
|
||||
#include "../toxcore/TCP_server.h"
|
||||
|
||||
#include "../toxcore/crypto_core.h"
|
||||
#include "../toxcore/mono_time.h"
|
||||
#include "../toxcore/util.h"
|
||||
|
||||
#include "helpers.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
#define NUM_PORTS 3
|
||||
|
||||
@@ -836,8 +826,6 @@ int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *TCP = TCP_suite();
|
||||
SRunner *test_runner = srunner_create(TCP);
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "helpers.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
static uint8_t const key[] = {
|
||||
0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD,
|
||||
@@ -29,7 +32,9 @@ int main(void)
|
||||
c_sleep(ITERATION_INTERVAL);
|
||||
}
|
||||
|
||||
assert(tox_self_get_connection_status(tox_udp) == TOX_CONNECTION_UDP);
|
||||
const TOX_CONNECTION status = tox_self_get_connection_status(tox_udp);
|
||||
ck_assert_msg(status == TOX_CONNECTION_UDP,
|
||||
"expected connection status to be UDP, but got %d", status);
|
||||
printf("Connection (UDP): %d\n", tox_self_get_connection_status(tox_udp));
|
||||
|
||||
tox_kill(tox_udp);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
@@ -57,15 +57,18 @@ static void rebuild_peer_list(Tox *tox)
|
||||
++conference_number) {
|
||||
TOX_ERR_CONFERENCE_PEER_QUERY err;
|
||||
uint32_t const count = tox_conference_peer_count(tox, conference_number, &err);
|
||||
assert(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK);
|
||||
ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
|
||||
"failed to get conference peer count for conference %u: err = %d", conference_number, err);
|
||||
|
||||
for (uint32_t peer_number = 0; peer_number < count; peer_number++) {
|
||||
size_t size = tox_conference_peer_get_name_size(tox, conference_number, peer_number, &err);
|
||||
assert(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK);
|
||||
ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
|
||||
"failed to get conference peer %u's name size (conference = %u): err = %d", peer_number, conference_number, err);
|
||||
|
||||
uint8_t *const name = malloc(size);
|
||||
tox_conference_peer_get_name(tox, conference_number, peer_number, name, &err);
|
||||
assert(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK);
|
||||
ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
|
||||
"failed to get conference peer %u's name (conference = %u): err = %d", peer_number, conference_number, err);
|
||||
free(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "../toxcore/tox.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "helpers.h"
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
typedef struct State {
|
||||
uint32_t id;
|
||||
@@ -51,7 +51,7 @@ static void handle_conference_invite(Tox *tox, uint32_t friend_number, TOX_CONFE
|
||||
{
|
||||
TOX_ERR_CONFERENCE_JOIN err;
|
||||
state->conference = tox_conference_join(tox, friend_number, cookie, length, &err);
|
||||
assert(err == TOX_ERR_CONFERENCE_JOIN_OK);
|
||||
ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "failed to join a conference: err = %d", err);
|
||||
fprintf(stderr, "tox%d Joined conference %d\n", state->id, state->conference);
|
||||
state->joined = true;
|
||||
}
|
||||
@@ -186,7 +186,7 @@ int main(void)
|
||||
TOX_ERR_CONFERENCE_NEW err;
|
||||
state1.conference = tox_conference_new(tox1, &err);
|
||||
state1.joined = true;
|
||||
assert(err == TOX_ERR_CONFERENCE_NEW_OK);
|
||||
ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "failed to create a conference: err = %d", err);
|
||||
fprintf(stderr, "Created conference: id=%d\n", state1.conference);
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ int main(void)
|
||||
// Invite friend.
|
||||
TOX_ERR_CONFERENCE_INVITE err;
|
||||
tox_conference_invite(tox1, 0, state1.conference, &err);
|
||||
assert(err == TOX_ERR_CONFERENCE_INVITE_OK);
|
||||
ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "failed to invite a friend: err = %d", err);
|
||||
fprintf(stderr, "tox1 invited tox2\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,19 @@
|
||||
/* Auto Tests: Conferences.
|
||||
*/
|
||||
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/crypto_core.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../toxcore/util.h"
|
||||
|
||||
#include "helpers.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
#define NUM_GROUP_TOX 5
|
||||
#define GROUP_MESSAGE "Install Gentoo"
|
||||
@@ -125,8 +119,8 @@ static void run_conference_tests(Tox **toxes, uint32_t *tox_index)
|
||||
for (uint16_t 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",
|
||||
(k - 1), i, peer_count);
|
||||
"\n\t\t\tExpected: %u but tox_instance(%u) only has: %u\n\n",
|
||||
k - 1, i, (unsigned)peer_count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,8 +234,8 @@ static void test_many_group(void)
|
||||
uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr);
|
||||
|
||||
ck_assert_msg(peer_count == NUM_GROUP_TOX, "\n\tBad number of group peers (pre check)."
|
||||
"\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n",
|
||||
NUM_GROUP_TOX, i, peer_count);
|
||||
"\n\t\t\tExpected: %u but tox_instance(%u) only has: %u\n\n",
|
||||
NUM_GROUP_TOX, i, (unsigned)peer_count);
|
||||
|
||||
uint8_t title[2048];
|
||||
size_t ret = tox_conference_get_title_size(toxes[i], 0, nullptr);
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
//
|
||||
// This test triggers a different code path than if we only allocate a single
|
||||
// conference. This is the simplest test possible that triggers it.
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/tox.h"
|
||||
|
||||
#include "check_compat.h"
|
||||
#include "helpers.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
@@ -2,18 +2,14 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "helpers.h"
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/crypto_core.h"
|
||||
#include "../toxcore/net_crypto.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
static void rand_bytes(uint8_t *b, size_t blen)
|
||||
{
|
||||
@@ -356,7 +352,6 @@ static Suite *crypto_suite(void)
|
||||
int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *crypto = crypto_suite();
|
||||
SRunner *test_runner = srunner_create(crypto);
|
||||
|
||||
+2
-11
@@ -1,19 +1,11 @@
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "helpers.h"
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/crypto_core.h"
|
||||
|
||||
#ifndef DHT_C_INCLUDED
|
||||
#include "../toxcore/DHT.c"
|
||||
#endif // DHT_C_INCLUDED
|
||||
@@ -819,7 +811,6 @@ static Suite *dht_suite(void)
|
||||
int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *dht = dht_suite();
|
||||
SRunner *test_runner = srunner_create(dht);
|
||||
|
||||
@@ -2,27 +2,24 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "helpers.h"
|
||||
|
||||
#include "../toxcore/tox.h"
|
||||
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "../toxcore/crypto_core.h"
|
||||
#include "../toxencryptsave/toxencryptsave.h"
|
||||
#ifdef VANILLA_NACL
|
||||
#include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h"
|
||||
#else
|
||||
#include <sodium.h>
|
||||
#endif
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "../toxcore/crypto_core.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../toxencryptsave/toxencryptsave.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};
|
||||
static unsigned char known_key[TOX_PASS_KEY_LENGTH] = {0x29, 0x36, 0x1c, 0x9e, 0x65, 0xbb, 0x46, 0x8b, 0xde, 0xa1, 0xac, 0xf, 0xd5, 0x11, 0x81, 0xc8, 0x29, 0x28, 0x17, 0x23, 0xa6, 0xc3, 0x6b, 0x77, 0x2e, 0xd7, 0xd3, 0x10, 0xeb, 0xd2, 0xf7, 0xc8};
|
||||
static const char *pw = "hunter2";
|
||||
@@ -207,7 +204,6 @@ static Suite *encryptsave_suite(void)
|
||||
int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *encryptsave = encryptsave_suite();
|
||||
SRunner *test_runner = srunner_create(encryptsave);
|
||||
|
||||
@@ -23,15 +23,21 @@
|
||||
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "helpers.h"
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "../toxencryptsave/toxencryptsave.h"
|
||||
|
||||
static const char *pphrase = "bar", *name = "foo", *savefile = "./save";
|
||||
static const char *pphrase = "bar";
|
||||
static const char *name = "foo";
|
||||
static const char *savefile = "./save";
|
||||
|
||||
static void save_data_encrypted(void)
|
||||
{
|
||||
|
||||
@@ -1,25 +1,20 @@
|
||||
/* File transfer test.
|
||||
*/
|
||||
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../toxcore/util.h"
|
||||
|
||||
#include "helpers.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
/* The Travis-CI container responds poorly to ::1 as a localhost address
|
||||
* You're encouraged to -D FORCE_TESTS_IPV6 on a local test */
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
* features.
|
||||
*/
|
||||
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -1,25 +1,20 @@
|
||||
/* Tests that we can add friends.
|
||||
*/
|
||||
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../toxcore/util.h"
|
||||
|
||||
#include "helpers.h"
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
#define FR_MESSAGE "Gentoo"
|
||||
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
#ifndef TOXCORE_TEST_HELPERS_H
|
||||
#define TOXCORE_TEST_HELPERS_H
|
||||
|
||||
#include "../toxcore/tox.h"
|
||||
|
||||
#include "../toxcore/ccompat.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef c_sleep
|
||||
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
||||
#include <windows.h>
|
||||
#define c_sleep(x) Sleep(x)
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#define c_sleep(x) usleep(1000 * (x))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define ITERATION_INTERVAL 200
|
||||
|
||||
Tox *tox_new_log(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data);
|
||||
|
||||
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>";
|
||||
}
|
||||
|
||||
static 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, "[#%d] %s %s:%d\t%s:\t%s\n", index, tox_log_level_name(level), file, line, func, message);
|
||||
}
|
||||
|
||||
static 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);
|
||||
}
|
||||
|
||||
#endif // TOXCORE_TEST_HELPERS_H
|
||||
@@ -1,10 +1,14 @@
|
||||
// Test that if UDP is enabled, and a proxy is provided that does not support
|
||||
// UDP proxying, we disable UDP.
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "helpers.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
static uint8_t const key[] = {
|
||||
0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD,
|
||||
@@ -37,7 +41,9 @@ int main(void)
|
||||
tox_iterate(tox, nullptr);
|
||||
c_sleep(ITERATION_INTERVAL);
|
||||
// None of the iterations should have a connection.
|
||||
assert(tox_self_get_connection_status(tox) == TOX_CONNECTION_NONE);
|
||||
const TOX_CONNECTION status = tox_self_get_connection_status(tox);
|
||||
ck_assert_msg(status == TOX_CONNECTION_NONE,
|
||||
"unexpectedly got a connection (%d)", status);
|
||||
}
|
||||
|
||||
tox_kill(tox);
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
// Test to make sure that when UDP is disabled, and we set an invalid proxy,
|
||||
// i.e. one that doesn't run a proxy server, then we don't get any connection.
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "helpers.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
static uint8_t const key[] = {
|
||||
0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD,
|
||||
@@ -37,7 +41,9 @@ int main(void)
|
||||
tox_iterate(tox, nullptr);
|
||||
c_sleep(ITERATION_INTERVAL);
|
||||
// None of the iterations should have a connection.
|
||||
assert(tox_self_get_connection_status(tox) == TOX_CONNECTION_NONE);
|
||||
const TOX_CONNECTION status = tox_self_get_connection_status(tox);
|
||||
ck_assert_msg(status == TOX_CONNECTION_NONE,
|
||||
"unexpectedly got a connection (%d)", status);
|
||||
}
|
||||
|
||||
tox_kill(tox);
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "helpers.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/ccompat.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
@@ -1,25 +1,20 @@
|
||||
/* Tests that we can send lossless packets.
|
||||
*/
|
||||
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../toxcore/util.h"
|
||||
|
||||
#include "helpers.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
#define LOSSLESS_PACKET_FILLER 160
|
||||
|
||||
|
||||
@@ -1,25 +1,18 @@
|
||||
/* Tests that we can send lossy packets.
|
||||
*/
|
||||
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/util.h"
|
||||
|
||||
#include "helpers.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
#define LOSSY_PACKET_FILLER 200
|
||||
|
||||
|
||||
@@ -14,16 +14,7 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include "helpers.h"
|
||||
|
||||
#include "../testing/misc_tools.c" // hex_string_to_bin
|
||||
#include "../toxcore/Messenger.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef VANILLA_NACL
|
||||
#include <crypto_box.h> // crypto_box_PUBLICKEYBYTES and other defines.
|
||||
@@ -31,6 +22,10 @@
|
||||
#include <sodium.h>
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/Messenger.h"
|
||||
|
||||
#define REALLY_BIG_NUMBER ((1) << (sizeof(uint16_t) * 7))
|
||||
|
||||
static bool enable_broken_tests = false;
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
#include "../testing/misc_tools.c"
|
||||
#include "check_compat.h"
|
||||
#include "helpers.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
@@ -2,18 +2,12 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/network.h"
|
||||
|
||||
#include "helpers.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
#ifndef USE_IPV6
|
||||
#define USE_IPV6 1
|
||||
@@ -181,7 +175,6 @@ static Suite *network_suite(void)
|
||||
int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *network = network_suite();
|
||||
SRunner *test_runner = srunner_create(network);
|
||||
|
||||
+2
-12
@@ -1,26 +1,17 @@
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/mono_time.h"
|
||||
#include "../toxcore/onion.h"
|
||||
#include "../toxcore/onion_announce.h"
|
||||
#include "../toxcore/onion_client.h"
|
||||
#include "../toxcore/util.h"
|
||||
|
||||
#include "helpers.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
#ifndef USE_IPV6
|
||||
#define USE_IPV6 1
|
||||
@@ -570,7 +561,6 @@ static Suite *onion_suite(void)
|
||||
int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *onion = onion_suite();
|
||||
SRunner *test_runner = srunner_create(onion);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* Try to overflow the net_crypto packet buffer.
|
||||
*/
|
||||
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* Try to overflow the net_crypto packet buffer.
|
||||
*/
|
||||
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <stdlib.h> // calloc, free
|
||||
|
||||
#include "check_compat.h"
|
||||
#include "helpers.h"
|
||||
#include "../testing/misc_tools.h"
|
||||
|
||||
static bool all_connected(uint32_t tox_count, Tox **toxes)
|
||||
{
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/* Auto Tests: Save and load friends.
|
||||
*/
|
||||
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "helpers.h"
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "../toxcore/crypto_core.h"
|
||||
#include "../toxcore/tox.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "../toxcore/crypto_core.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
struct test_data {
|
||||
uint8_t name[TOX_MAX_NAME_LENGTH];
|
||||
uint8_t status_message[TOX_MAX_STATUS_MESSAGE_LENGTH];
|
||||
@@ -124,8 +124,10 @@ int main(void)
|
||||
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);
|
||||
|
||||
assert(memcmp(reference_name, to_compare.name, TOX_MAX_NAME_LENGTH) == 0);
|
||||
assert(memcmp(reference_status, to_compare.status_message, TOX_MAX_STATUS_MESSAGE_LENGTH) == 0);
|
||||
ck_assert_msg(memcmp(reference_name, to_compare.name, TOX_MAX_NAME_LENGTH) == 0,
|
||||
"incorrect name: should be all zeroes");
|
||||
ck_assert_msg(memcmp(reference_status, to_compare.status_message, TOX_MAX_STATUS_MESSAGE_LENGTH) == 0,
|
||||
"incorrect status message: should be all zeroes");
|
||||
|
||||
tox_options_free(options);
|
||||
tox_kill(tox1);
|
||||
|
||||
@@ -1,25 +1,20 @@
|
||||
/* Tests that we can save and load Tox data.
|
||||
*/
|
||||
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../toxcore/util.h"
|
||||
|
||||
#include "helpers.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)
|
||||
{
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
/* Tests that we can send messages to friends.
|
||||
*/
|
||||
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct State {
|
||||
uint32_t index;
|
||||
|
||||
@@ -1,25 +1,20 @@
|
||||
/* Tests that we can set our name.
|
||||
*/
|
||||
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../toxcore/util.h"
|
||||
|
||||
#include "helpers.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
#define NICKNAME "Gentoo"
|
||||
|
||||
|
||||
@@ -1,25 +1,20 @@
|
||||
/* Tests that we can set our status message
|
||||
*/
|
||||
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../toxcore/util.h"
|
||||
|
||||
#include "helpers.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
#define STATUS_MESSAGE "Installing Gentoo"
|
||||
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "helpers.h"
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
/*
|
||||
#include "../<stuff to test>"
|
||||
@@ -33,8 +31,6 @@ int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *creativesuitenamegoeshere = creativesuitenamegoeshere_suite();
|
||||
SRunner *test_runner = srunner_create(creativesuitenamegoeshere);
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "helpers.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
static uint8_t const key[] = {
|
||||
0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD,
|
||||
@@ -33,8 +36,10 @@ int main(void)
|
||||
c_sleep(ITERATION_INTERVAL);
|
||||
}
|
||||
|
||||
assert(tox_self_get_connection_status(tox_tcp) == TOX_CONNECTION_TCP);
|
||||
printf("Connection (TCP): %d\n", tox_self_get_connection_status(tox_tcp));
|
||||
const TOX_CONNECTION status = tox_self_get_connection_status(tox_tcp);
|
||||
ck_assert_msg(status == TOX_CONNECTION_TCP,
|
||||
"expected TCP connection, but got %d", status);
|
||||
printf("Connection (TCP): %d\n", status);
|
||||
|
||||
tox_kill(tox_tcp);
|
||||
return 0;
|
||||
|
||||
@@ -1,25 +1,20 @@
|
||||
/* Auto Tests: Many TCP.
|
||||
*/
|
||||
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/crypto_core.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../toxcore/util.h"
|
||||
|
||||
#include "helpers.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
/* The Travis-CI container responds poorly to ::1 as a localhost address
|
||||
* You're encouraged to -D FORCE_TESTS_IPV6 on a local test */
|
||||
@@ -255,8 +250,6 @@ int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *tox = tox_suite();
|
||||
SRunner *test_runner = srunner_create(tox);
|
||||
|
||||
|
||||
@@ -1,25 +1,20 @@
|
||||
/* Auto Tests: Many clients.
|
||||
*/
|
||||
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/crypto_core.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../toxcore/util.h"
|
||||
|
||||
#include "helpers.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)
|
||||
{
|
||||
|
||||
@@ -5,17 +5,15 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "../toxcore/crypto_core.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../toxcore/util.h"
|
||||
|
||||
#include "helpers.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
static void set_random_name_and_status_message(Tox *tox, uint8_t *name, uint8_t *status_message)
|
||||
{
|
||||
@@ -146,8 +144,6 @@ int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *tox = tox_suite();
|
||||
SRunner *test_runner = srunner_create(tox);
|
||||
|
||||
|
||||
@@ -2,17 +2,11 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "helpers.h"
|
||||
|
||||
#include "../testing/misc_tools.c"
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
typedef enum {
|
||||
NEGATIVE,
|
||||
@@ -181,8 +175,6 @@ int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
|
||||
srand((unsigned int) time(nullptr));
|
||||
|
||||
Suite *s = tox_strncasecmp_suite();
|
||||
SRunner *test_runner = srunner_create(s);
|
||||
|
||||
|
||||
@@ -1,29 +1,21 @@
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <vpx/vpx_image.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxav/toxav.h"
|
||||
#include "../toxcore/crypto_core.h"
|
||||
#include "../toxcore/logger.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../toxcore/util.h"
|
||||
|
||||
#include "helpers.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
#define TEST_REGULAR_AV 1
|
||||
#define TEST_REGULAR_A 1
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -15,19 +9,19 @@
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#if !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32)
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include <vpx/vpx_image.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxav/toxav.h"
|
||||
#include "../toxcore/crypto_core.h"
|
||||
#include "../toxcore/logger.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../toxcore/util.h"
|
||||
|
||||
#include "helpers.h"
|
||||
|
||||
#if !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32)
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
#include "check_compat.h"
|
||||
|
||||
typedef struct {
|
||||
bool incoming;
|
||||
|
||||
@@ -1,25 +1,19 @@
|
||||
/* Tests that our typing notifications work.
|
||||
*/
|
||||
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 600
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../toxcore/util.h"
|
||||
|
||||
#include "helpers.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
static void typing_callback(Tox *m, uint32_t friendnumber, bool typing, void *userdata)
|
||||
{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "../toxcore/tox.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define check(major, minor, patch, expected) \
|
||||
do_check(TOX_VERSION_MAJOR, TOX_VERSION_MINOR, TOX_VERSION_PATCH, \
|
||||
major, minor, patch, \
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
bin_PROGRAMS =
|
||||
noinst_PROGRAMS =
|
||||
noinst_LTLIBRARIES =
|
||||
lib_LTLIBRARIES =
|
||||
noinst_bindir = $(top_builddir)/build
|
||||
EXTRA_DIST=
|
||||
|
||||
@@ -5,6 +5,7 @@ cc_library(
|
||||
hdrs = ["monolith.h"],
|
||||
visibility = ["//c-toxcore/auto_tests:__pkg__"],
|
||||
deps = [
|
||||
"//c-toxcore/testing:monolith",
|
||||
"//c-toxcore/toxav:monolith",
|
||||
"//c-toxcore/toxcore:monolith",
|
||||
"//c-toxcore/toxencryptsave:monolith",
|
||||
|
||||
@@ -23,11 +23,9 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../toxcore/DHT.h"
|
||||
#include "../toxcore/LAN_discovery.h"
|
||||
@@ -43,7 +41,7 @@
|
||||
#include "../toxcore/TCP_server.h"
|
||||
#endif
|
||||
|
||||
#include "../testing/misc_tools.c"
|
||||
#include "../testing/misc_tools.h"
|
||||
|
||||
#ifdef DHT_NODE_EXTRA_PACKETS
|
||||
#include "./bootstrap_node_packets.h"
|
||||
|
||||
@@ -14,6 +14,7 @@ DHT_bootstrap_CFLAGS = -I$(top_srcdir)/other \
|
||||
|
||||
DHT_bootstrap_LDADD = $(LIBSODIUM_LDFLAGS) \
|
||||
$(NACL_LDFLAGS) \
|
||||
libmisc_tools.la \
|
||||
libtoxcore.la \
|
||||
$(LIBSODIUM_LIBS) \
|
||||
$(NACL_OBJECTS) \
|
||||
|
||||
+6
-5
@@ -9,15 +9,16 @@
|
||||
* Will try to find a public key starting with: ABCDEF
|
||||
*/
|
||||
|
||||
#include "../../testing/misc_tools.c"
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/* NaCl includes*/
|
||||
/* Sodium includes*/
|
||||
#include <sodium/crypto_scalarmult_curve25519.h>
|
||||
#include <sodium/randombytes.h>
|
||||
|
||||
/* Sodium include*/
|
||||
//#include <sodium.h>
|
||||
#include "../../testing/misc_tools.h"
|
||||
#include "../../toxcore/ccompat.h"
|
||||
|
||||
void print_key(uint8_t *client_id)
|
||||
{
|
||||
|
||||
+3
-1
@@ -15,10 +15,12 @@
|
||||
*
|
||||
* NOTE: The signature is appended to the end of the file.
|
||||
*/
|
||||
#include "../../testing/misc_tools.c" // hex_string_to_bin
|
||||
#include <sodium.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../../testing/misc_tools.h" // hex_string_to_bin
|
||||
#include "../../toxcore/ccompat.h"
|
||||
|
||||
int load_file(char *filename, char **result)
|
||||
{
|
||||
int size = 0;
|
||||
|
||||
+13
-4
@@ -2,11 +2,10 @@ load("//tools:no_undefined.bzl", "cc_library")
|
||||
|
||||
cc_library(
|
||||
name = "misc_tools",
|
||||
hdrs = [
|
||||
"misc_tools.c",
|
||||
],
|
||||
srcs = ["misc_tools.c"],
|
||||
hdrs = ["misc_tools.h"],
|
||||
visibility = ["//c-toxcore:__subpackages__"],
|
||||
deps = ["//c-toxcore/toxcore:ccompat"],
|
||||
deps = ["//c-toxcore/toxcore"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
@@ -53,3 +52,13 @@ cc_binary(
|
||||
"//c-toxcore/toxcore",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "monolith",
|
||||
hdrs = [
|
||||
"misc_tools.c",
|
||||
"misc_tools.h",
|
||||
],
|
||||
visibility = ["//c-toxcore/other:__pkg__"],
|
||||
deps = ["//c-toxcore/toxcore"],
|
||||
)
|
||||
+6
-9
@@ -30,21 +30,18 @@
|
||||
*/
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
//#include "../core/network.h"
|
||||
#include "../toxcore/DHT.h"
|
||||
#include "../toxcore/friend_requests.h"
|
||||
#include "misc_tools.c"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(_WIN32) && !defined(__WIN32__) && !defined (WIN32)
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include "../toxcore/DHT.h"
|
||||
#include "../toxcore/friend_requests.h"
|
||||
#include "misc_tools.h"
|
||||
|
||||
#define PORT 33445
|
||||
|
||||
static uint8_t zeroes_cid[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
|
||||
+12
-3
@@ -1,3 +1,13 @@
|
||||
if BUILD_TESTS
|
||||
TEST_LIB = misc_tools
|
||||
endif
|
||||
if BUILD_TESTING
|
||||
TEST_LIB = misc_tools
|
||||
endif
|
||||
|
||||
noinst_LTLIBRARIES += libmisc_tools.la
|
||||
libmisc_tools_la_SOURCES = ../testing/misc_tools.c ../testing/misc_tools.h
|
||||
|
||||
if BUILD_TESTING
|
||||
|
||||
noinst_PROGRAMS += DHT_test \
|
||||
@@ -10,6 +20,7 @@ DHT_test_CFLAGS = $(LIBSODIUM_CFLAGS) \
|
||||
|
||||
DHT_test_LDADD = $(LIBSODIUM_LDFLAGS) \
|
||||
$(NACL_LDFLAGS) \
|
||||
libmisc_tools.la \
|
||||
libtoxcore.la \
|
||||
$(LIBSODIUM_LIBS) \
|
||||
$(NACL_OBJECTS) \
|
||||
@@ -25,13 +36,11 @@ Messenger_test_CFLAGS = $(LIBSODIUM_CFLAGS) \
|
||||
|
||||
Messenger_test_LDADD = $(LIBSODIUM_LDFLAGS) \
|
||||
$(NACL_LDFLAGS) \
|
||||
libmisc_tools.la \
|
||||
libtoxcore.la \
|
||||
$(LIBSODIUM_LIBS) \
|
||||
$(NACL_OBJECTS) \
|
||||
$(NACL_LIBS) \
|
||||
$(WINSOCK2_LIBS)
|
||||
|
||||
|
||||
EXTRA_DIST += $(top_srcdir)/testing/misc_tools.c
|
||||
|
||||
endif
|
||||
@@ -38,20 +38,17 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "../toxcore/Messenger.h"
|
||||
#include "misc_tools.c"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(_WIN32) && !defined(__WIN32__) && !defined (WIN32)
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include "../toxcore/Messenger.h"
|
||||
#include "misc_tools.h"
|
||||
|
||||
static void print_message(Messenger *m, uint32_t friendnumber, unsigned int type, const uint8_t *string, size_t length,
|
||||
void *userdata)
|
||||
{
|
||||
|
||||
+81
-16
@@ -21,35 +21,40 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef MISC_TOOLS_C
|
||||
#define MISC_TOOLS_C
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#ifndef _POSIX_C_SOURCE
|
||||
// For nanosleep().
|
||||
#define _POSIX_C_SOURCE 199309L
|
||||
#endif
|
||||
|
||||
#include "misc_tools.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
//Sleep function (x = milliseconds)
|
||||
#ifndef c_sleep
|
||||
#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
|
||||
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
||||
#include <windows.h>
|
||||
#define c_sleep(x) Sleep(x)
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#define c_sleep(x) usleep(1000*(x))
|
||||
#endif
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "../toxcore/tox.h"
|
||||
|
||||
uint8_t *hex_string_to_bin(const char *hex_string);
|
||||
int tox_strncasecmp(const char *s1, const char *s2, size_t n);
|
||||
int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled);
|
||||
void c_sleep(uint32_t x)
|
||||
{
|
||||
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
||||
Sleep(x);
|
||||
#else
|
||||
struct timespec req;
|
||||
req.tv_sec = x / 1000;
|
||||
req.tv_nsec = (long)x % 1000 * 1000 * 1000;
|
||||
nanosleep(&req, nullptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
// You are responsible for freeing the return value!
|
||||
uint8_t *hex_string_to_bin(const char *hex_string)
|
||||
@@ -123,4 +128,64 @@ int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled)
|
||||
return argvoffset;
|
||||
}
|
||||
|
||||
#endif // MISC_TOOLS_C
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef C_TOXCORE_TESTING_MISC_TOOLS_H
|
||||
#define C_TOXCORE_TESTING_MISC_TOOLS_H
|
||||
|
||||
#include "../toxcore/tox.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Amount of time in milliseconds to wait between tox_iterate calls.
|
||||
#define ITERATION_INTERVAL 200
|
||||
|
||||
void c_sleep(uint32_t x);
|
||||
|
||||
uint8_t *hex_string_to_bin(const char *hex_string);
|
||||
int tox_strncasecmp(const char *s1, const char *s2, size_t n);
|
||||
int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "../toxcore/tox.h"
|
||||
#include "misc_tools.c"
|
||||
#include "misc_tools.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -32,8 +32,6 @@ constexpr uint32_t MAX_ACTIONS = 10000;
|
||||
constexpr uint32_t MAX_ACTION_ATTEMPTS = 100;
|
||||
// Number of tox_iterate calls between each action.
|
||||
constexpr uint32_t ITERATIONS_PER_ACTION = 1;
|
||||
// Amount of time in milliseconds to wait between tox_iterate calls.
|
||||
constexpr uint32_t ITERATION_INTERVAL = 5;
|
||||
|
||||
struct Tox_Options_Deleter {
|
||||
void operator()(Tox_Options *options) const { tox_options_free(options); }
|
||||
|
||||
Reference in new issue
Block a user