summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-07-16 22:46:02 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-07-21 20:44:26 +0000
commit7245ac11ef9be2420c8356c12acc79f93ea211bb (patch)
treee971c5c6e10c2310afe4b2cd80212feac9839f2a
parent7c2b95ef5e4ccdae01bd104aa7400294c9ea391b (diff)
Avoid implementations in .h files or #including .c files.
Also, avoid the need for putting `_XOPEN_SOURCE` in every test file.
-rw-r--r--.travis.yml1
-rw-r--r--CMakeLists.txt15
-rw-r--r--auto_tests/BUILD.bazel20
-rw-r--r--auto_tests/Makefile.inc2
-rw-r--r--auto_tests/TCP_test.c16
-rw-r--r--auto_tests/bootstrap_test.c13
-rw-r--r--auto_tests/conference_double_invite_test.c4
-rw-r--r--auto_tests/conference_peer_nick_test.c13
-rw-r--r--auto_tests/conference_simple_test.c18
-rw-r--r--auto_tests/conference_test.c20
-rw-r--r--auto_tests/conference_two_test.c8
-rw-r--r--auto_tests/crypto_test.c9
-rw-r--r--auto_tests/dht_test.c13
-rw-r--r--auto_tests/encryptsave_test.c18
-rw-r--r--auto_tests/file_saving_test.c12
-rw-r--r--auto_tests/file_transfer_test.c11
-rw-r--r--auto_tests/friend_connection_test.c4
-rw-r--r--auto_tests/friend_request_test.c11
-rw-r--r--auto_tests/helpers.h88
-rw-r--r--auto_tests/invalid_proxy_test.c14
-rw-r--r--auto_tests/invalid_tcp_proxy_test.c14
-rw-r--r--auto_tests/lan_discovery_test.c10
-rw-r--r--auto_tests/lossless_packet_test.c11
-rw-r--r--auto_tests/lossy_packet_test.c13
-rw-r--r--auto_tests/messenger_test.c13
-rw-r--r--auto_tests/monolith_test.cc1
-rw-r--r--auto_tests/network_test.c11
-rw-r--r--auto_tests/onion_test.c14
-rw-r--r--auto_tests/overflow_recvq_test.c4
-rw-r--r--auto_tests/overflow_sendq_test.c4
-rw-r--r--auto_tests/run_auto_test.h2
-rw-r--r--auto_tests/save_friend_test.c22
-rw-r--r--auto_tests/save_load_test.c11
-rw-r--r--auto_tests/send_message_test.c5
-rw-r--r--auto_tests/set_name_test.c11
-rw-r--r--auto_tests/set_status_message_test.c11
-rw-r--r--auto_tests/skeleton_test.c8
-rw-r--r--auto_tests/tcp_relay_test.c15
-rw-r--r--auto_tests/tox_many_tcp_test.c13
-rw-r--r--auto_tests/tox_many_test.c11
-rw-r--r--auto_tests/tox_one_test.c10
-rw-r--r--auto_tests/tox_strncasecmp_test.c12
-rw-r--r--auto_tests/toxav_basic_test.c12
-rw-r--r--auto_tests/toxav_many_test.c18
-rw-r--r--auto_tests/typing_test.c10
-rw-r--r--auto_tests/version_test.c7
-rw-r--r--build/Makefile.am1
-rw-r--r--other/BUILD.bazel1
-rw-r--r--other/DHT_bootstrap.c10
-rw-r--r--other/Makefile.inc1
-rw-r--r--other/fun/cracker.c11
-rw-r--r--other/fun/sign.c4
-rw-r--r--testing/BUILD.bazel17
-rw-r--r--testing/DHT_test.c15
-rw-r--r--testing/Makefile.inc15
-rw-r--r--testing/Messenger_test.c15
-rw-r--r--testing/misc_tools.c97
-rw-r--r--testing/misc_tools.h29
-rw-r--r--testing/random_testing.cc4
59 files changed, 364 insertions, 439 deletions
diff --git a/.travis.yml b/.travis.yml
index ea1ffea7..67af3416 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -46,6 +46,7 @@ matrix:
46 - libcv-dev # For av_test. 46 - libcv-dev # For av_test.
47 - libhighgui-dev # For av_test. 47 - libhighgui-dev # For av_test.
48 - libopencv-contrib-dev # For av_test. 48 - libopencv-contrib-dev # For av_test.
49 - libsndfile1-dev # For av_test.
49 - portaudio19-dev # For av_test. 50 - portaudio19-dev # For av_test.
50 before_install: 51 before_install:
51 # Clear bazel installation. 52 # Clear bazel installation.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cd0e9944..181d4155 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -371,6 +371,11 @@ unit_test(toxcore util)
371# 371#
372################################################################################ 372################################################################################
373 373
374add_library(misc_tools
375 testing/misc_tools.c
376 testing/misc_tools.h)
377target_link_modules(misc_tools toxcore)
378
374set(TEST_TIMEOUT_SECONDS "" CACHE STRING "Limit runtime of each test to the number of seconds specified") 379set(TEST_TIMEOUT_SECONDS "" CACHE STRING "Limit runtime of each test to the number of seconds specified")
375 380
376if(ANDROID_CPU_FEATURES) 381if(ANDROID_CPU_FEATURES)
@@ -389,7 +394,7 @@ function(auto_test target)
389 if(NOT (MSVC AND ARGV1 STREQUAL "MSVC_DONT_BUILD")) 394 if(NOT (MSVC AND ARGV1 STREQUAL "MSVC_DONT_BUILD"))
390 add_executable(auto_${target}_test ${CPUFEATURES} 395 add_executable(auto_${target}_test ${CPUFEATURES}
391 auto_tests/${target}_test.c) 396 auto_tests/${target}_test.c)
392 target_link_modules(auto_${target}_test toxcore) 397 target_link_modules(auto_${target}_test toxcore misc_tools)
393 if(NOT ARGV1 STREQUAL "DONT_RUN") 398 if(NOT ARGV1 STREQUAL "DONT_RUN")
394 add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} auto_${target}_test) 399 add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} auto_${target}_test)
395 set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}") 400 set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}")
@@ -459,7 +464,7 @@ if(DHT_BOOTSTRAP)
459 add_executable(DHT_bootstrap ${CPUFEATURES} 464 add_executable(DHT_bootstrap ${CPUFEATURES}
460 other/DHT_bootstrap.c 465 other/DHT_bootstrap.c
461 other/bootstrap_node_packets.c) 466 other/bootstrap_node_packets.c)
462 target_link_modules(DHT_bootstrap toxcore) 467 target_link_modules(DHT_bootstrap toxcore misc_tools)
463endif() 468endif()
464 469
465option(BOOTSTRAP_DAEMON "Enable building of tox-bootstrapd" ON) 470option(BOOTSTRAP_DAEMON "Enable building of tox-bootstrapd" ON)
@@ -519,12 +524,12 @@ endif()
519 524
520add_executable(DHT_test ${CPUFEATURES} 525add_executable(DHT_test ${CPUFEATURES}
521 testing/DHT_test.c) 526 testing/DHT_test.c)
522target_link_modules(DHT_test toxcore) 527target_link_modules(DHT_test toxcore misc_tools)
523 528
524add_executable(Messenger_test ${CPUFEATURES} 529add_executable(Messenger_test ${CPUFEATURES}
525 testing/Messenger_test.c) 530 testing/Messenger_test.c)
526target_link_modules(Messenger_test toxcore) 531target_link_modules(Messenger_test toxcore misc_tools)
527 532
528add_executable(random_testing ${CPUFEATURES} 533add_executable(random_testing ${CPUFEATURES}
529 testing/random_testing.cc) 534 testing/random_testing.cc)
530target_link_modules(random_testing toxcore) 535target_link_modules(random_testing toxcore misc_tools)
diff --git a/auto_tests/BUILD.bazel b/auto_tests/BUILD.bazel
index a9c0c20d..21c403ab 100644
--- a/auto_tests/BUILD.bazel
+++ b/auto_tests/BUILD.bazel
@@ -1,11 +1,13 @@
1cc_library( 1cc_library(
2 name = "helpers", 2 name = "check_compat",
3 testonly = True, 3 testonly = True,
4 hdrs = [ 4 hdrs = ["check_compat.h"],
5 "check_compat.h", 5)
6 "helpers.h", 6
7 "run_auto_test.h", 7cc_library(
8 ], 8 name = "run_auto_test",
9 testonly = True,
10 hdrs = ["run_auto_test.h"],
9) 11)
10 12
11test_sizes = { 13test_sizes = {
@@ -21,7 +23,8 @@ test_sizes = {
21 srcs = [src], 23 srcs = [src],
22 copts = ["-Wno-sign-compare"], 24 copts = ["-Wno-sign-compare"],
23 deps = [ 25 deps = [
24 ":helpers", 26 ":check_compat",
27 ":run_auto_test",
25 "//c-toxcore/other:monolith", 28 "//c-toxcore/other:monolith",
26 "//c-toxcore/testing:misc_tools", 29 "//c-toxcore/testing:misc_tools",
27 "//c-toxcore/toxav", 30 "//c-toxcore/toxav",
@@ -44,8 +47,9 @@ cc_test(
44 srcs = ["monolith_test.cc"], 47 srcs = ["monolith_test.cc"],
45 copts = ["-Wno-sign-compare"], 48 copts = ["-Wno-sign-compare"],
46 deps = [ 49 deps = [
47 ":helpers", 50 ":check_compat",
48 ":monolith", 51 ":monolith",
52 ":run_auto_test",
49 "//c-toxcore/other:monolith", 53 "//c-toxcore/other:monolith",
50 "//c-toxcore/testing:misc_tools", 54 "//c-toxcore/testing:misc_tools",
51 ], 55 ],
diff --git a/auto_tests/Makefile.inc b/auto_tests/Makefile.inc
index 94762969..67c72016 100644
--- a/auto_tests/Makefile.inc
+++ b/auto_tests/Makefile.inc
@@ -10,6 +10,7 @@ AUTOTEST_CFLAGS = \
10AUTOTEST_LDADD = \ 10AUTOTEST_LDADD = \
11 $(LIBSODIUM_LDFLAGS) \ 11 $(LIBSODIUM_LDFLAGS) \
12 $(NACL_LDFLAGS) \ 12 $(NACL_LDFLAGS) \
13 libmisc_tools.la \
13 libtoxcore.la \ 14 libtoxcore.la \
14 libtoxencryptsave.la \ 15 libtoxencryptsave.la \
15 $(LIBSODIUM_LIBS) \ 16 $(LIBSODIUM_LIBS) \
@@ -115,4 +116,3 @@ tox_strncasecmp_test_LDADD = $(AUTOTEST_LDADD)
115 116
116 117
117EXTRA_DIST += $(top_srcdir)/auto_tests/check_compat.h 118EXTRA_DIST += $(top_srcdir)/auto_tests/check_compat.h
118EXTRA_DIST += $(top_srcdir)/auto_tests/helpers.h
diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c
index f5bc2471..07266543 100644
--- a/auto_tests/TCP_test.c
+++ b/auto_tests/TCP_test.c
@@ -1,27 +1,17 @@
1#ifndef _XOPEN_SOURCE
2#define _XOPEN_SOURCE 600
3#endif
4
5#ifdef HAVE_CONFIG_H 1#ifdef HAVE_CONFIG_H
6#include "config.h" 2#include "config.h"
7#endif 3#endif
8 4
9#include "check_compat.h"
10
11#include <stdint.h>
12#include <stdlib.h> 5#include <stdlib.h>
13#include <string.h> 6#include <string.h>
14#include <sys/types.h>
15#include <time.h>
16 7
8#include "../testing/misc_tools.h"
17#include "../toxcore/TCP_client.h" 9#include "../toxcore/TCP_client.h"
18#include "../toxcore/TCP_server.h" 10#include "../toxcore/TCP_server.h"
19
20#include "../toxcore/crypto_core.h" 11#include "../toxcore/crypto_core.h"
21#include "../toxcore/mono_time.h" 12#include "../toxcore/mono_time.h"
22#include "../toxcore/util.h" 13#include "../toxcore/util.h"
23 14#include "check_compat.h"
24#include "helpers.h"
25 15
26#define NUM_PORTS 3 16#define NUM_PORTS 3
27 17
@@ -836,8 +826,6 @@ int main(void)
836{ 826{
837 setvbuf(stdout, nullptr, _IONBF, 0); 827 setvbuf(stdout, nullptr, _IONBF, 0);
838 828
839 srand((unsigned int) time(nullptr));
840
841 Suite *TCP = TCP_suite(); 829 Suite *TCP = TCP_suite();
842 SRunner *test_runner = srunner_create(TCP); 830 SRunner *test_runner = srunner_create(TCP);
843 831
diff --git a/auto_tests/bootstrap_test.c b/auto_tests/bootstrap_test.c
index d6138855..cbe81ebc 100644
--- a/auto_tests/bootstrap_test.c
+++ b/auto_tests/bootstrap_test.c
@@ -1,8 +1,11 @@
1#ifndef _XOPEN_SOURCE 1#ifdef HAVE_CONFIG_H
2#define _XOPEN_SOURCE 600 2#include "config.h"
3#endif 3#endif
4 4
5#include "helpers.h" 5#include <stdio.h>
6
7#include "../testing/misc_tools.h"
8#include "check_compat.h"
6 9
7static uint8_t const key[] = { 10static uint8_t const key[] = {
8 0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD, 11 0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD,
@@ -29,7 +32,9 @@ int main(void)
29 c_sleep(ITERATION_INTERVAL); 32 c_sleep(ITERATION_INTERVAL);
30 } 33 }
31 34
32 assert(tox_self_get_connection_status(tox_udp) == TOX_CONNECTION_UDP); 35 const TOX_CONNECTION status = tox_self_get_connection_status(tox_udp);
36 ck_assert_msg(status == TOX_CONNECTION_UDP,
37 "expected connection status to be UDP, but got %d", status);
33 printf("Connection (UDP): %d\n", tox_self_get_connection_status(tox_udp)); 38 printf("Connection (UDP): %d\n", tox_self_get_connection_status(tox_udp));
34 39
35 tox_kill(tox_udp); 40 tox_kill(tox_udp);
diff --git a/auto_tests/conference_double_invite_test.c b/auto_tests/conference_double_invite_test.c
index 7b646726..55aabfb6 100644
--- a/auto_tests/conference_double_invite_test.c
+++ b/auto_tests/conference_double_invite_test.c
@@ -1,5 +1,5 @@
1#ifndef _XOPEN_SOURCE 1#ifdef HAVE_CONFIG_H
2#define _XOPEN_SOURCE 600 2#include "config.h"
3#endif 3#endif
4 4
5#include <stdbool.h> 5#include <stdbool.h>
diff --git a/auto_tests/conference_peer_nick_test.c b/auto_tests/conference_peer_nick_test.c
index a1b33e9f..4d54f1fb 100644
--- a/auto_tests/conference_peer_nick_test.c
+++ b/auto_tests/conference_peer_nick_test.c
@@ -1,5 +1,5 @@
1#ifndef _XOPEN_SOURCE 1#ifdef HAVE_CONFIG_H
2#define _XOPEN_SOURCE 600 2#include "config.h"
3#endif 3#endif
4 4
5#include <stdbool.h> 5#include <stdbool.h>
@@ -57,15 +57,18 @@ static void rebuild_peer_list(Tox *tox)
57 ++conference_number) { 57 ++conference_number) {
58 TOX_ERR_CONFERENCE_PEER_QUERY err; 58 TOX_ERR_CONFERENCE_PEER_QUERY err;
59 uint32_t const count = tox_conference_peer_count(tox, conference_number, &err); 59 uint32_t const count = tox_conference_peer_count(tox, conference_number, &err);
60 assert(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK); 60 ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
61 "failed to get conference peer count for conference %u: err = %d", conference_number, err);
61 62
62 for (uint32_t peer_number = 0; peer_number < count; peer_number++) { 63 for (uint32_t peer_number = 0; peer_number < count; peer_number++) {
63 size_t size = tox_conference_peer_get_name_size(tox, conference_number, peer_number, &err); 64 size_t size = tox_conference_peer_get_name_size(tox, conference_number, peer_number, &err);
64 assert(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK); 65 ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
66 "failed to get conference peer %u's name size (conference = %u): err = %d", peer_number, conference_number, err);
65 67
66 uint8_t *const name = malloc(size); 68 uint8_t *const name = malloc(size);
67 tox_conference_peer_get_name(tox, conference_number, peer_number, name, &err); 69 tox_conference_peer_get_name(tox, conference_number, peer_number, name, &err);
68 assert(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK); 70 ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
71 "failed to get conference peer %u's name (conference = %u): err = %d", peer_number, conference_number, err);
69 free(name); 72 free(name);
70 } 73 }
71 } 74 }
diff --git a/auto_tests/conference_simple_test.c b/auto_tests/conference_simple_test.c
index 3e2f0f94..8d95bba8 100644
--- a/auto_tests/conference_simple_test.c
+++ b/auto_tests/conference_simple_test.c
@@ -1,13 +1,13 @@
1#ifndef _XOPEN_SOURCE 1#ifdef HAVE_CONFIG_H
2#define _XOPEN_SOURCE 600 2#include "config.h"
3#endif 3#endif
4 4
5#include "../toxcore/tox.h" 5#include <stdio.h>
6
7#include <assert.h>
8#include <stdlib.h> 6#include <stdlib.h>
9 7
10#include "helpers.h" 8#include "../testing/misc_tools.h"
9#include "../toxcore/tox.h"
10#include "check_compat.h"
11 11
12typedef struct State { 12typedef struct State {
13 uint32_t id; 13 uint32_t id;
@@ -51,7 +51,7 @@ static void handle_conference_invite(Tox *tox, uint32_t friend_number, TOX_CONFE
51 { 51 {
52 TOX_ERR_CONFERENCE_JOIN err; 52 TOX_ERR_CONFERENCE_JOIN err;
53 state->conference = tox_conference_join(tox, friend_number, cookie, length, &err); 53 state->conference = tox_conference_join(tox, friend_number, cookie, length, &err);
54 assert(err == TOX_ERR_CONFERENCE_JOIN_OK); 54 ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "failed to join a conference: err = %d", err);
55 fprintf(stderr, "tox%d Joined conference %d\n", state->id, state->conference); 55 fprintf(stderr, "tox%d Joined conference %d\n", state->id, state->conference);
56 state->joined = true; 56 state->joined = true;
57 } 57 }
@@ -186,7 +186,7 @@ int main(void)
186 TOX_ERR_CONFERENCE_NEW err; 186 TOX_ERR_CONFERENCE_NEW err;
187 state1.conference = tox_conference_new(tox1, &err); 187 state1.conference = tox_conference_new(tox1, &err);
188 state1.joined = true; 188 state1.joined = true;
189 assert(err == TOX_ERR_CONFERENCE_NEW_OK); 189 ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "failed to create a conference: err = %d", err);
190 fprintf(stderr, "Created conference: id=%d\n", state1.conference); 190 fprintf(stderr, "Created conference: id=%d\n", state1.conference);
191 } 191 }
192 192
@@ -194,7 +194,7 @@ int main(void)
194 // Invite friend. 194 // Invite friend.
195 TOX_ERR_CONFERENCE_INVITE err; 195 TOX_ERR_CONFERENCE_INVITE err;
196 tox_conference_invite(tox1, 0, state1.conference, &err); 196 tox_conference_invite(tox1, 0, state1.conference, &err);
197 assert(err == TOX_ERR_CONFERENCE_INVITE_OK); 197 ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "failed to invite a friend: err = %d", err);
198 fprintf(stderr, "tox1 invited tox2\n"); 198 fprintf(stderr, "tox1 invited tox2\n");
199 } 199 }
200 200
diff --git a/auto_tests/conference_test.c b/auto_tests/conference_test.c
index 706dad38..92e805c9 100644
--- a/auto_tests/conference_test.c
+++ b/auto_tests/conference_test.c
@@ -1,25 +1,19 @@
1/* Auto Tests: Conferences. 1/* Auto Tests: Conferences.
2 */ 2 */
3 3
4#ifndef _XOPEN_SOURCE
5#define _XOPEN_SOURCE 600
6#endif
7
8#ifdef HAVE_CONFIG_H 4#ifdef HAVE_CONFIG_H
9#include "config.h" 5#include "config.h"
10#endif 6#endif
11 7
12#include "check_compat.h"
13
14#include <inttypes.h>
15#include <stdlib.h> 8#include <stdlib.h>
9#include <string.h>
16#include <time.h> 10#include <time.h>
17 11
12#include "../testing/misc_tools.h"
18#include "../toxcore/crypto_core.h" 13#include "../toxcore/crypto_core.h"
19#include "../toxcore/tox.h" 14#include "../toxcore/tox.h"
20#include "../toxcore/util.h" 15#include "../toxcore/util.h"
21 16#include "check_compat.h"
22#include "helpers.h"
23 17
24#define NUM_GROUP_TOX 5 18#define NUM_GROUP_TOX 5
25#define GROUP_MESSAGE "Install Gentoo" 19#define GROUP_MESSAGE "Install Gentoo"
@@ -125,8 +119,8 @@ static void run_conference_tests(Tox **toxes, uint32_t *tox_index)
125 for (uint16_t i = 0; i < k - 1; ++i) { 119 for (uint16_t i = 0; i < k - 1; ++i) {
126 uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr); 120 uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr);
127 ck_assert_msg(peer_count == (k - 1), "\n\tBad number of group peers (post check)." 121 ck_assert_msg(peer_count == (k - 1), "\n\tBad number of group peers (post check)."
128 "\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n", 122 "\n\t\t\tExpected: %u but tox_instance(%u) only has: %u\n\n",
129 (k - 1), i, peer_count); 123 k - 1, i, (unsigned)peer_count);
130 } 124 }
131 } 125 }
132} 126}
@@ -240,8 +234,8 @@ static void test_many_group(void)
240 uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr); 234 uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr);
241 235
242 ck_assert_msg(peer_count == NUM_GROUP_TOX, "\n\tBad number of group peers (pre check)." 236 ck_assert_msg(peer_count == NUM_GROUP_TOX, "\n\tBad number of group peers (pre check)."
243 "\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n", 237 "\n\t\t\tExpected: %u but tox_instance(%u) only has: %u\n\n",
244 NUM_GROUP_TOX, i, peer_count); 238 NUM_GROUP_TOX, i, (unsigned)peer_count);
245 239
246 uint8_t title[2048]; 240 uint8_t title[2048];
247 size_t ret = tox_conference_get_title_size(toxes[i], 0, nullptr); 241 size_t ret = tox_conference_get_title_size(toxes[i], 0, nullptr);
diff --git a/auto_tests/conference_two_test.c b/auto_tests/conference_two_test.c
index c3036165..c6c3aa03 100644
--- a/auto_tests/conference_two_test.c
+++ b/auto_tests/conference_two_test.c
@@ -2,14 +2,14 @@
2// 2//
3// This test triggers a different code path than if we only allocate a single 3// This test triggers a different code path than if we only allocate a single
4// conference. This is the simplest test possible that triggers it. 4// conference. This is the simplest test possible that triggers it.
5#ifndef _XOPEN_SOURCE 5
6#define _XOPEN_SOURCE 600 6#ifdef HAVE_CONFIG_H
7#include "config.h"
7#endif 8#endif
8 9
10#include "../testing/misc_tools.h"
9#include "../toxcore/tox.h" 11#include "../toxcore/tox.h"
10
11#include "check_compat.h" 12#include "check_compat.h"
12#include "helpers.h"
13 13
14int main(void) 14int main(void)
15{ 15{
diff --git a/auto_tests/crypto_test.c b/auto_tests/crypto_test.c
index c87ffa54..8f8a786c 100644
--- a/auto_tests/crypto_test.c
+++ b/auto_tests/crypto_test.c
@@ -2,18 +2,14 @@
2#include "config.h" 2#include "config.h"
3#endif 3#endif
4 4
5#include "check_compat.h"
6
7#include <stdint.h> 5#include <stdint.h>
8#include <stdlib.h> 6#include <stdlib.h>
9#include <string.h> 7#include <string.h>
10#include <sys/types.h>
11#include <time.h>
12
13#include "helpers.h"
14 8
9#include "../testing/misc_tools.h"
15#include "../toxcore/crypto_core.h" 10#include "../toxcore/crypto_core.h"
16#include "../toxcore/net_crypto.h" 11#include "../toxcore/net_crypto.h"
12#include "check_compat.h"
17 13
18static void rand_bytes(uint8_t *b, size_t blen) 14static void rand_bytes(uint8_t *b, size_t blen)
19{ 15{
@@ -356,7 +352,6 @@ static Suite *crypto_suite(void)
356int main(void) 352int main(void)
357{ 353{
358 setvbuf(stdout, nullptr, _IONBF, 0); 354 setvbuf(stdout, nullptr, _IONBF, 0);
359 srand((unsigned int) time(nullptr));
360 355
361 Suite *crypto = crypto_suite(); 356 Suite *crypto = crypto_suite();
362 SRunner *test_runner = srunner_create(crypto); 357 SRunner *test_runner = srunner_create(crypto);
diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c
index f57d706b..8b96f09a 100644
--- a/auto_tests/dht_test.c
+++ b/auto_tests/dht_test.c
@@ -1,19 +1,11 @@
1#ifndef _XOPEN_SOURCE
2#define _XOPEN_SOURCE 600
3#endif
4
5#ifdef HAVE_CONFIG_H 1#ifdef HAVE_CONFIG_H
6#include "config.h" 2#include "config.h"
7#endif 3#endif
8 4
9#include "check_compat.h" 5#include "check_compat.h"
10 6#include "../testing/misc_tools.h"
11#include <sys/param.h>
12#include <time.h>
13
14#include "helpers.h"
15
16#include "../toxcore/crypto_core.h" 7#include "../toxcore/crypto_core.h"
8
17#ifndef DHT_C_INCLUDED 9#ifndef DHT_C_INCLUDED
18#include "../toxcore/DHT.c" 10#include "../toxcore/DHT.c"
19#endif // DHT_C_INCLUDED 11#endif // DHT_C_INCLUDED
@@ -819,7 +811,6 @@ static Suite *dht_suite(void)
819int main(void) 811int main(void)
820{ 812{
821 setvbuf(stdout, nullptr, _IONBF, 0); 813 setvbuf(stdout, nullptr, _IONBF, 0);
822 srand((unsigned int) time(nullptr));
823 814
824 Suite *dht = dht_suite(); 815 Suite *dht = dht_suite();
825 SRunner *test_runner = srunner_create(dht); 816 SRunner *test_runner = srunner_create(dht);
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c
index 48a43c86..365a9dbb 100644
--- a/auto_tests/encryptsave_test.c
+++ b/auto_tests/encryptsave_test.c
@@ -2,27 +2,24 @@
2#include "config.h" 2#include "config.h"
3#endif 3#endif
4 4
5#include "check_compat.h"
6
7#include <stdint.h> 5#include <stdint.h>
8#include <stdlib.h> 6#include <stdlib.h>
9#include <string.h> 7#include <string.h>
10#include <sys/types.h> 8#include <sys/types.h>
11#include <time.h>
12 9
13#include "helpers.h"
14
15#include "../toxcore/tox.h"
16
17#include "../toxcore/ccompat.h"
18#include "../toxcore/crypto_core.h"
19#include "../toxencryptsave/toxencryptsave.h"
20#ifdef VANILLA_NACL 10#ifdef VANILLA_NACL
21#include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h" 11#include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h"
22#else 12#else
23#include <sodium.h> 13#include <sodium.h>
24#endif 14#endif
25 15
16#include "../testing/misc_tools.h"
17#include "../toxcore/ccompat.h"
18#include "../toxcore/crypto_core.h"
19#include "../toxcore/tox.h"
20#include "../toxencryptsave/toxencryptsave.h"
21#include "check_compat.h"
22
26static 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}; 23static 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};
27static 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}; 24static 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};
28static const char *pw = "hunter2"; 25static const char *pw = "hunter2";
@@ -207,7 +204,6 @@ static Suite *encryptsave_suite(void)
207int main(void) 204int main(void)
208{ 205{
209 setvbuf(stdout, nullptr, _IONBF, 0); 206 setvbuf(stdout, nullptr, _IONBF, 0);
210 srand((unsigned int) time(nullptr));
211 207
212 Suite *encryptsave = encryptsave_suite(); 208 Suite *encryptsave = encryptsave_suite();
213 SRunner *test_runner = srunner_create(encryptsave); 209 SRunner *test_runner = srunner_create(encryptsave);
diff --git a/auto_tests/file_saving_test.c b/auto_tests/file_saving_test.c
index 23a4c701..0f27f1d6 100644
--- a/auto_tests/file_saving_test.c
+++ b/auto_tests/file_saving_test.c
@@ -23,15 +23,21 @@
23 * along with Tox. If not, see <http://www.gnu.org/licenses/>. 23 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
24 */ 24 */
25 25
26#ifdef HAVE_CONFIG_H
27#include "config.h"
28#endif
29
26#include <stdio.h> 30#include <stdio.h>
27#include <stdlib.h> 31#include <stdlib.h>
28#include <string.h> 32#include <string.h>
29 33
30#include "helpers.h" 34#include "../testing/misc_tools.h"
31 35#include "../toxcore/ccompat.h"
32#include "../toxencryptsave/toxencryptsave.h" 36#include "../toxencryptsave/toxencryptsave.h"
33 37
34static const char *pphrase = "bar", *name = "foo", *savefile = "./save"; 38static const char *pphrase = "bar";
39static const char *name = "foo";
40static const char *savefile = "./save";
35 41
36static void save_data_encrypted(void) 42static void save_data_encrypted(void)
37{ 43{
diff --git a/auto_tests/file_transfer_test.c b/auto_tests/file_transfer_test.c
index 6e8a3c53..a6e45431 100644
--- a/auto_tests/file_transfer_test.c
+++ b/auto_tests/file_transfer_test.c
@@ -1,25 +1,20 @@
1/* File transfer test. 1/* File transfer test.
2 */ 2 */
3 3
4#ifndef _XOPEN_SOURCE
5#define _XOPEN_SOURCE 600
6#endif
7
8#ifdef HAVE_CONFIG_H 4#ifdef HAVE_CONFIG_H
9#include "config.h" 5#include "config.h"
10#endif 6#endif
11 7
12#include "check_compat.h"
13
14#include <stdio.h> 8#include <stdio.h>
15#include <stdlib.h> 9#include <stdlib.h>
10#include <string.h>
16#include <time.h> 11#include <time.h>
17 12
13#include "../testing/misc_tools.h"
18#include "../toxcore/ccompat.h" 14#include "../toxcore/ccompat.h"
19#include "../toxcore/tox.h" 15#include "../toxcore/tox.h"
20#include "../toxcore/util.h" 16#include "../toxcore/util.h"
21 17#include "check_compat.h"
22#include "helpers.h"
23 18
24/* The Travis-CI container responds poorly to ::1 as a localhost address 19/* The Travis-CI container responds poorly to ::1 as a localhost address
25 * You're encouraged to -D FORCE_TESTS_IPV6 on a local test */ 20 * You're encouraged to -D FORCE_TESTS_IPV6 on a local test */
diff --git a/auto_tests/friend_connection_test.c b/auto_tests/friend_connection_test.c
index 13d08b65..a165678c 100644
--- a/auto_tests/friend_connection_test.c
+++ b/auto_tests/friend_connection_test.c
@@ -5,8 +5,8 @@
5 * features. 5 * features.
6 */ 6 */
7 7
8#ifndef _XOPEN_SOURCE 8#ifdef HAVE_CONFIG_H
9#define _XOPEN_SOURCE 600 9#include "config.h"
10#endif 10#endif
11 11
12#include <stdint.h> 12#include <stdint.h>
diff --git a/auto_tests/friend_request_test.c b/auto_tests/friend_request_test.c
index 2fbc2166..eefcb056 100644
--- a/auto_tests/friend_request_test.c
+++ b/auto_tests/friend_request_test.c
@@ -1,25 +1,20 @@
1/* Tests that we can add friends. 1/* Tests that we can add friends.
2 */ 2 */
3 3
4#ifndef _XOPEN_SOURCE
5#define _XOPEN_SOURCE 600
6#endif
7
8#ifdef HAVE_CONFIG_H 4#ifdef HAVE_CONFIG_H
9#include "config.h" 5#include "config.h"
10#endif 6#endif
11 7
12#include "check_compat.h"
13
14#include <stdio.h> 8#include <stdio.h>
15#include <stdlib.h> 9#include <stdlib.h>
10#include <string.h>
16#include <time.h> 11#include <time.h>
17 12
18#include "../toxcore/ccompat.h" 13#include "../toxcore/ccompat.h"
19#include "../toxcore/tox.h" 14#include "../toxcore/tox.h"
20#include "../toxcore/util.h" 15#include "../toxcore/util.h"
21 16#include "../testing/misc_tools.h"
22#include "helpers.h" 17#include "check_compat.h"
23 18
24#define FR_MESSAGE "Gentoo" 19#define FR_MESSAGE "Gentoo"
25 20
diff --git a/auto_tests/helpers.h b/auto_tests/helpers.h
deleted file mode 100644
index 7af127f5..00000000
--- a/auto_tests/helpers.h
+++ /dev/null
@@ -1,88 +0,0 @@
1#ifndef TOXCORE_TEST_HELPERS_H
2#define TOXCORE_TEST_HELPERS_H
3
4#include "../toxcore/tox.h"
5
6#include "../toxcore/ccompat.h"
7
8#include <assert.h>
9#include <stdio.h>
10#include <string.h>
11
12#ifndef c_sleep
13#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
14#include <windows.h>
15#define c_sleep(x) Sleep(x)
16#else
17#include <unistd.h>
18#define c_sleep(x) usleep(1000 * (x))
19#endif
20#endif
21
22#define ITERATION_INTERVAL 200
23
24Tox *tox_new_log(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data);
25
26static const char *tox_log_level_name(TOX_LOG_LEVEL level)
27{
28 switch (level) {
29 case TOX_LOG_LEVEL_TRACE:
30 return "TRACE";
31
32 case TOX_LOG_LEVEL_DEBUG:
33 return "DEBUG";
34
35 case TOX_LOG_LEVEL_INFO:
36 return "INFO";
37
38 case TOX_LOG_LEVEL_WARNING:
39 return "WARNING";
40
41 case TOX_LOG_LEVEL_ERROR:
42 return "ERROR";
43 }
44
45 return "<unknown>";
46}
47
48static void print_debug_log(Tox *m, TOX_LOG_LEVEL level, const char *file, uint32_t line, const char *func,
49 const char *message, void *user_data)
50{
51 if (level == TOX_LOG_LEVEL_TRACE) {
52 return;
53 }
54
55 uint32_t index = user_data ? *(uint32_t *)user_data : 0;
56 fprintf(stderr, "[#%d] %s %s:%d\t%s:\t%s\n", index, tox_log_level_name(level), file, line, func, message);
57}
58
59static Tox *tox_new_log_lan(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data, bool lan_discovery)
60{
61 struct Tox_Options *log_options = options;
62
63 if (log_options == nullptr) {
64 log_options = tox_options_new(nullptr);
65 }
66
67 assert(log_options != nullptr);
68
69 tox_options_set_local_discovery_enabled(log_options, lan_discovery);
70 tox_options_set_start_port(log_options, 33445);
71 tox_options_set_end_port(log_options, 33445 + 2000);
72 tox_options_set_log_callback(log_options, &print_debug_log);
73 tox_options_set_log_user_data(log_options, log_user_data);
74 Tox *tox = tox_new(log_options, err);
75
76 if (options == nullptr) {
77 tox_options_free(log_options);
78 }
79
80 return tox;
81}
82
83Tox *tox_new_log(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data)
84{
85 return tox_new_log_lan(options, err, log_user_data, false);
86}
87
88#endif // TOXCORE_TEST_HELPERS_H
diff --git a/auto_tests/invalid_proxy_test.c b/auto_tests/invalid_proxy_test.c
index 600efa9e..3e729b5a 100644
--- a/auto_tests/invalid_proxy_test.c
+++ b/auto_tests/invalid_proxy_test.c
@@ -1,10 +1,14 @@
1// Test that if UDP is enabled, and a proxy is provided that does not support 1// Test that if UDP is enabled, and a proxy is provided that does not support
2// UDP proxying, we disable UDP. 2// UDP proxying, we disable UDP.
3#ifndef _XOPEN_SOURCE 3
4#define _XOPEN_SOURCE 600 4#ifdef HAVE_CONFIG_H
5#include "config.h"
5#endif 6#endif
6 7
7#include "helpers.h" 8#include <stdio.h>
9
10#include "../testing/misc_tools.h"
11#include "check_compat.h"
8 12
9static uint8_t const key[] = { 13static uint8_t const key[] = {
10 0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD, 14 0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD,
@@ -37,7 +41,9 @@ int main(void)
37 tox_iterate(tox, nullptr); 41 tox_iterate(tox, nullptr);
38 c_sleep(ITERATION_INTERVAL); 42 c_sleep(ITERATION_INTERVAL);
39 // None of the iterations should have a connection. 43 // None of the iterations should have a connection.
40 assert(tox_self_get_connection_status(tox) == TOX_CONNECTION_NONE); 44 const TOX_CONNECTION status = tox_self_get_connection_status(tox);
45 ck_assert_msg(status == TOX_CONNECTION_NONE,
46 "unexpectedly got a connection (%d)", status);
41 } 47 }
42 48
43 tox_kill(tox); 49 tox_kill(tox);
diff --git a/auto_tests/invalid_tcp_proxy_test.c b/auto_tests/invalid_tcp_proxy_test.c
index edbc3237..211b04eb 100644
--- a/auto_tests/invalid_tcp_proxy_test.c
+++ b/auto_tests/invalid_tcp_proxy_test.c
@@ -1,10 +1,14 @@
1// Test to make sure that when UDP is disabled, and we set an invalid proxy, 1// Test to make sure that when UDP is disabled, and we set an invalid proxy,
2// i.e. one that doesn't run a proxy server, then we don't get any connection. 2// i.e. one that doesn't run a proxy server, then we don't get any connection.
3#ifndef _XOPEN_SOURCE 3
4#define _XOPEN_SOURCE 600 4#ifdef HAVE_CONFIG_H
5#include "config.h"
5#endif 6#endif
6 7
7#include "helpers.h" 8#include <stdio.h>
9
10#include "../testing/misc_tools.h"
11#include "check_compat.h"
8 12
9static uint8_t const key[] = { 13static uint8_t const key[] = {
10 0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD, 14 0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD,
@@ -37,7 +41,9 @@ int main(void)
37 tox_iterate(tox, nullptr); 41 tox_iterate(tox, nullptr);
38 c_sleep(ITERATION_INTERVAL); 42 c_sleep(ITERATION_INTERVAL);
39 // None of the iterations should have a connection. 43 // None of the iterations should have a connection.
40 assert(tox_self_get_connection_status(tox) == TOX_CONNECTION_NONE); 44 const TOX_CONNECTION status = tox_self_get_connection_status(tox);
45 ck_assert_msg(status == TOX_CONNECTION_NONE,
46 "unexpectedly got a connection (%d)", status);
41 } 47 }
42 48
43 tox_kill(tox); 49 tox_kill(tox);
diff --git a/auto_tests/lan_discovery_test.c b/auto_tests/lan_discovery_test.c
index 3192fc28..28a5ddf0 100644
--- a/auto_tests/lan_discovery_test.c
+++ b/auto_tests/lan_discovery_test.c
@@ -1,8 +1,12 @@
1#ifndef _XOPEN_SOURCE 1#ifdef HAVE_CONFIG_H
2#define _XOPEN_SOURCE 600 2#include "config.h"
3#endif 3#endif
4 4
5#include "helpers.h" 5#include <stdio.h>
6#include <string.h>
7
8#include "../testing/misc_tools.h"
9#include "../toxcore/ccompat.h"
6 10
7int main(void) 11int main(void)
8{ 12{
diff --git a/auto_tests/lossless_packet_test.c b/auto_tests/lossless_packet_test.c
index 05d56c4d..dfe713a8 100644
--- a/auto_tests/lossless_packet_test.c
+++ b/auto_tests/lossless_packet_test.c
@@ -1,25 +1,20 @@
1/* Tests that we can send lossless packets. 1/* Tests that we can send lossless packets.
2 */ 2 */
3 3
4#ifndef _XOPEN_SOURCE
5#define _XOPEN_SOURCE 600
6#endif
7
8#ifdef HAVE_CONFIG_H 4#ifdef HAVE_CONFIG_H
9#include "config.h" 5#include "config.h"
10#endif 6#endif
11 7
12#include "check_compat.h"
13
14#include <stdio.h> 8#include <stdio.h>
15#include <stdlib.h> 9#include <stdlib.h>
10#include <string.h>
16#include <time.h> 11#include <time.h>
17 12
13#include "../testing/misc_tools.h"
18#include "../toxcore/ccompat.h" 14#include "../toxcore/ccompat.h"
19#include "../toxcore/tox.h" 15#include "../toxcore/tox.h"
20#include "../toxcore/util.h" 16#include "../toxcore/util.h"
21 17#include "check_compat.h"
22#include "helpers.h"
23 18
24#define LOSSLESS_PACKET_FILLER 160 19#define LOSSLESS_PACKET_FILLER 160
25 20
diff --git a/auto_tests/lossy_packet_test.c b/auto_tests/lossy_packet_test.c
index c0af148f..71f45149 100644
--- a/auto_tests/lossy_packet_test.c
+++ b/auto_tests/lossy_packet_test.c
@@ -1,25 +1,18 @@
1/* Tests that we can send lossy packets. 1/* Tests that we can send lossy packets.
2 */ 2 */
3 3
4#ifndef _XOPEN_SOURCE
5#define _XOPEN_SOURCE 600
6#endif
7
8#ifdef HAVE_CONFIG_H 4#ifdef HAVE_CONFIG_H
9#include "config.h" 5#include "config.h"
10#endif 6#endif
11 7
12#include "check_compat.h"
13
14#include <stdio.h> 8#include <stdio.h>
15#include <stdlib.h> 9#include <stdlib.h>
10#include <string.h>
16#include <time.h> 11#include <time.h>
17 12
18#include "../toxcore/ccompat.h" 13#include "../testing/misc_tools.h"
19#include "../toxcore/tox.h"
20#include "../toxcore/util.h" 14#include "../toxcore/util.h"
21 15#include "check_compat.h"
22#include "helpers.h"
23 16
24#define LOSSY_PACKET_FILLER 200 17#define LOSSY_PACKET_FILLER 200
25 18
diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c
index d7f2b9e7..b8fbbc1f 100644
--- a/auto_tests/messenger_test.c
+++ b/auto_tests/messenger_test.c
@@ -14,16 +14,7 @@
14#include "config.h" 14#include "config.h"
15#endif 15#endif
16 16
17#include "check_compat.h"
18
19#include "helpers.h"
20
21#include "../testing/misc_tools.c" // hex_string_to_bin
22#include "../toxcore/Messenger.h"
23
24#include <stdint.h>
25#include <string.h> 17#include <string.h>
26#include <sys/types.h>
27 18
28#ifdef VANILLA_NACL 19#ifdef VANILLA_NACL
29#include <crypto_box.h> // crypto_box_PUBLICKEYBYTES and other defines. 20#include <crypto_box.h> // crypto_box_PUBLICKEYBYTES and other defines.
@@ -31,6 +22,10 @@
31#include <sodium.h> 22#include <sodium.h>
32#endif 23#endif
33 24
25#include "check_compat.h"
26#include "../testing/misc_tools.h"
27#include "../toxcore/Messenger.h"
28
34#define REALLY_BIG_NUMBER ((1) << (sizeof(uint16_t) * 7)) 29#define REALLY_BIG_NUMBER ((1) << (sizeof(uint16_t) * 7))
35 30
36static bool enable_broken_tests = false; 31static bool enable_broken_tests = false;
diff --git a/auto_tests/monolith_test.cc b/auto_tests/monolith_test.cc
index 5c3a1cce..5b1b910d 100644
--- a/auto_tests/monolith_test.cc
+++ b/auto_tests/monolith_test.cc
@@ -21,7 +21,6 @@
21 21
22#include "../testing/misc_tools.c" 22#include "../testing/misc_tools.c"
23#include "check_compat.h" 23#include "check_compat.h"
24#include "helpers.h"
25 24
26#include <ctype.h> 25#include <ctype.h>
27 26
diff --git a/auto_tests/network_test.c b/auto_tests/network_test.c
index dc67e0c0..78f41195 100644
--- a/auto_tests/network_test.c
+++ b/auto_tests/network_test.c
@@ -2,18 +2,12 @@
2#include "config.h" 2#include "config.h"
3#endif 3#endif
4 4
5#include "check_compat.h"
6
7#include <errno.h>
8#include <stdint.h>
9#include <stdlib.h> 5#include <stdlib.h>
10#include <string.h> 6#include <string.h>
11#include <sys/types.h>
12#include <time.h>
13 7
8#include "../testing/misc_tools.h"
14#include "../toxcore/network.h" 9#include "../toxcore/network.h"
15 10#include "check_compat.h"
16#include "helpers.h"
17 11
18#ifndef USE_IPV6 12#ifndef USE_IPV6
19#define USE_IPV6 1 13#define USE_IPV6 1
@@ -181,7 +175,6 @@ static Suite *network_suite(void)
181int main(void) 175int main(void)
182{ 176{
183 setvbuf(stdout, nullptr, _IONBF, 0); 177 setvbuf(stdout, nullptr, _IONBF, 0);
184 srand((unsigned int) time(nullptr));
185 178
186 Suite *network = network_suite(); 179 Suite *network = network_suite();
187 SRunner *test_runner = srunner_create(network); 180 SRunner *test_runner = srunner_create(network);
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c
index 45679205..18b7b523 100644
--- a/auto_tests/onion_test.c
+++ b/auto_tests/onion_test.c
@@ -1,26 +1,17 @@
1#ifndef _XOPEN_SOURCE
2#define _XOPEN_SOURCE 600
3#endif
4
5#ifdef HAVE_CONFIG_H 1#ifdef HAVE_CONFIG_H
6#include "config.h" 2#include "config.h"
7#endif 3#endif
8 4
9#include "check_compat.h"
10
11#include <stdint.h>
12#include <stdlib.h> 5#include <stdlib.h>
13#include <string.h> 6#include <string.h>
14#include <sys/types.h>
15#include <time.h>
16 7
8#include "../testing/misc_tools.h"
17#include "../toxcore/mono_time.h" 9#include "../toxcore/mono_time.h"
18#include "../toxcore/onion.h" 10#include "../toxcore/onion.h"
19#include "../toxcore/onion_announce.h" 11#include "../toxcore/onion_announce.h"
20#include "../toxcore/onion_client.h" 12#include "../toxcore/onion_client.h"
21#include "../toxcore/util.h" 13#include "../toxcore/util.h"
22 14#include "check_compat.h"
23#include "helpers.h"
24 15
25#ifndef USE_IPV6 16#ifndef USE_IPV6
26#define USE_IPV6 1 17#define USE_IPV6 1
@@ -570,7 +561,6 @@ static Suite *onion_suite(void)
570int main(void) 561int main(void)
571{ 562{
572 setvbuf(stdout, nullptr, _IONBF, 0); 563 setvbuf(stdout, nullptr, _IONBF, 0);
573 srand((unsigned int) time(nullptr));
574 564
575 Suite *onion = onion_suite(); 565 Suite *onion = onion_suite();
576 SRunner *test_runner = srunner_create(onion); 566 SRunner *test_runner = srunner_create(onion);
diff --git a/auto_tests/overflow_recvq_test.c b/auto_tests/overflow_recvq_test.c
index cdad2442..55f9e459 100644
--- a/auto_tests/overflow_recvq_test.c
+++ b/auto_tests/overflow_recvq_test.c
@@ -1,8 +1,8 @@
1/* Try to overflow the net_crypto packet buffer. 1/* Try to overflow the net_crypto packet buffer.
2 */ 2 */
3 3
4#ifndef _XOPEN_SOURCE 4#ifdef HAVE_CONFIG_H
5#define _XOPEN_SOURCE 600 5#include "config.h"
6#endif 6#endif
7 7
8#include <stdint.h> 8#include <stdint.h>
diff --git a/auto_tests/overflow_sendq_test.c b/auto_tests/overflow_sendq_test.c
index cc6eeda9..0bdc6073 100644
--- a/auto_tests/overflow_sendq_test.c
+++ b/auto_tests/overflow_sendq_test.c
@@ -1,8 +1,8 @@
1/* Try to overflow the net_crypto packet buffer. 1/* Try to overflow the net_crypto packet buffer.
2 */ 2 */
3 3
4#ifndef _XOPEN_SOURCE 4#ifdef HAVE_CONFIG_H
5#define _XOPEN_SOURCE 600 5#include "config.h"
6#endif 6#endif
7 7
8#include <stdint.h> 8#include <stdint.h>
diff --git a/auto_tests/run_auto_test.h b/auto_tests/run_auto_test.h
index a4c638ff..04d24791 100644
--- a/auto_tests/run_auto_test.h
+++ b/auto_tests/run_auto_test.h
@@ -1,7 +1,7 @@
1#include <stdlib.h> // calloc, free 1#include <stdlib.h> // calloc, free
2 2
3#include "check_compat.h" 3#include "check_compat.h"
4#include "helpers.h" 4#include "../testing/misc_tools.h"
5 5
6static bool all_connected(uint32_t tox_count, Tox **toxes) 6static bool all_connected(uint32_t tox_count, Tox **toxes)
7{ 7{
diff --git a/auto_tests/save_friend_test.c b/auto_tests/save_friend_test.c
index 1e90e692..07753127 100644
--- a/auto_tests/save_friend_test.c
+++ b/auto_tests/save_friend_test.c
@@ -1,20 +1,20 @@
1/* Auto Tests: Save and load friends. 1/* Auto Tests: Save and load friends.
2 */ 2 */
3 3
4#ifndef _XOPEN_SOURCE 4#ifdef HAVE_CONFIG_H
5#define _XOPEN_SOURCE 600 5#include "config.h"
6#endif 6#endif
7 7
8#include "helpers.h"
9#include "../toxcore/ccompat.h"
10#include "../toxcore/crypto_core.h"
11#include "../toxcore/tox.h"
12
13#include <assert.h>
14#include <stdio.h> 8#include <stdio.h>
15#include <stdlib.h> 9#include <stdlib.h>
16#include <string.h> 10#include <string.h>
17 11
12#include "../testing/misc_tools.h"
13#include "../toxcore/ccompat.h"
14#include "../toxcore/crypto_core.h"
15#include "../toxcore/tox.h"
16#include "check_compat.h"
17
18struct test_data { 18struct test_data {
19 uint8_t name[TOX_MAX_NAME_LENGTH]; 19 uint8_t name[TOX_MAX_NAME_LENGTH];
20 uint8_t status_message[TOX_MAX_STATUS_MESSAGE_LENGTH]; 20 uint8_t status_message[TOX_MAX_STATUS_MESSAGE_LENGTH];
@@ -124,8 +124,10 @@ int main(void)
124 tox_friend_get_name(tox_to_compare, 0, to_compare.name, nullptr); 124 tox_friend_get_name(tox_to_compare, 0, to_compare.name, nullptr);
125 tox_friend_get_status_message(tox_to_compare, 0, to_compare.status_message, nullptr); 125 tox_friend_get_status_message(tox_to_compare, 0, to_compare.status_message, nullptr);
126 126
127 assert(memcmp(reference_name, to_compare.name, TOX_MAX_NAME_LENGTH) == 0); 127 ck_assert_msg(memcmp(reference_name, to_compare.name, TOX_MAX_NAME_LENGTH) == 0,
128 assert(memcmp(reference_status, to_compare.status_message, TOX_MAX_STATUS_MESSAGE_LENGTH) == 0); 128 "incorrect name: should be all zeroes");
129 ck_assert_msg(memcmp(reference_status, to_compare.status_message, TOX_MAX_STATUS_MESSAGE_LENGTH) == 0,
130 "incorrect status message: should be all zeroes");
129 131
130 tox_options_free(options); 132 tox_options_free(options);
131 tox_kill(tox1); 133 tox_kill(tox1);
diff --git a/auto_tests/save_load_test.c b/auto_tests/save_load_test.c
index 50facb2c..90d0263f 100644
--- a/auto_tests/save_load_test.c
+++ b/auto_tests/save_load_test.c
@@ -1,25 +1,20 @@
1/* Tests that we can save and load Tox data. 1/* Tests that we can save and load Tox data.
2 */ 2 */
3 3
4#ifndef _XOPEN_SOURCE
5#define _XOPEN_SOURCE 600
6#endif
7
8#ifdef HAVE_CONFIG_H 4#ifdef HAVE_CONFIG_H
9#include "config.h" 5#include "config.h"
10#endif 6#endif
11 7
12#include "check_compat.h"
13
14#include <stdio.h> 8#include <stdio.h>
15#include <stdlib.h> 9#include <stdlib.h>
10#include <string.h>
16#include <time.h> 11#include <time.h>
17 12
13#include "../testing/misc_tools.h"
18#include "../toxcore/ccompat.h" 14#include "../toxcore/ccompat.h"
19#include "../toxcore/tox.h" 15#include "../toxcore/tox.h"
20#include "../toxcore/util.h" 16#include "../toxcore/util.h"
21 17#include "check_compat.h"
22#include "helpers.h"
23 18
24static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) 19static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
25{ 20{
diff --git a/auto_tests/send_message_test.c b/auto_tests/send_message_test.c
index 822ea64f..d7747ebe 100644
--- a/auto_tests/send_message_test.c
+++ b/auto_tests/send_message_test.c
@@ -1,12 +1,13 @@
1/* Tests that we can send messages to friends. 1/* Tests that we can send messages to friends.
2 */ 2 */
3 3
4#ifndef _XOPEN_SOURCE 4#ifdef HAVE_CONFIG_H
5#define _XOPEN_SOURCE 600 5#include "config.h"
6#endif 6#endif
7 7
8#include <stdbool.h> 8#include <stdbool.h>
9#include <stdint.h> 9#include <stdint.h>
10#include <string.h>
10 11
11typedef struct State { 12typedef struct State {
12 uint32_t index; 13 uint32_t index;
diff --git a/auto_tests/set_name_test.c b/auto_tests/set_name_test.c
index 20fb0a67..6f467bdb 100644
--- a/auto_tests/set_name_test.c
+++ b/auto_tests/set_name_test.c
@@ -1,25 +1,20 @@
1/* Tests that we can set our name. 1/* Tests that we can set our name.
2 */ 2 */
3 3
4#ifndef _XOPEN_SOURCE
5#define _XOPEN_SOURCE 600
6#endif
7
8#ifdef HAVE_CONFIG_H 4#ifdef HAVE_CONFIG_H
9#include "config.h" 5#include "config.h"
10#endif 6#endif
11 7
12#include "check_compat.h"
13
14#include <stdio.h> 8#include <stdio.h>
15#include <stdlib.h> 9#include <stdlib.h>
10#include <string.h>
16#include <time.h> 11#include <time.h>
17 12
13#include "../testing/misc_tools.h"
18#include "../toxcore/ccompat.h" 14#include "../toxcore/ccompat.h"
19#include "../toxcore/tox.h" 15#include "../toxcore/tox.h"
20#include "../toxcore/util.h" 16#include "../toxcore/util.h"
21 17#include "check_compat.h"
22#include "helpers.h"
23 18
24#define NICKNAME "Gentoo" 19#define NICKNAME "Gentoo"
25 20
diff --git a/auto_tests/set_status_message_test.c b/auto_tests/set_status_message_test.c
index fd6c3558..3ffdd3c4 100644
--- a/auto_tests/set_status_message_test.c
+++ b/auto_tests/set_status_message_test.c
@@ -1,25 +1,20 @@
1/* Tests that we can set our status message 1/* Tests that we can set our status message
2 */ 2 */
3 3
4#ifndef _XOPEN_SOURCE
5#define _XOPEN_SOURCE 600
6#endif
7
8#ifdef HAVE_CONFIG_H 4#ifdef HAVE_CONFIG_H
9#include "config.h" 5#include "config.h"
10#endif 6#endif
11 7
12#include "check_compat.h"
13
14#include <stdio.h> 8#include <stdio.h>
15#include <stdlib.h> 9#include <stdlib.h>
10#include <string.h>
16#include <time.h> 11#include <time.h>
17 12
13#include "../testing/misc_tools.h"
18#include "../toxcore/ccompat.h" 14#include "../toxcore/ccompat.h"
19#include "../toxcore/tox.h" 15#include "../toxcore/tox.h"
20#include "../toxcore/util.h" 16#include "../toxcore/util.h"
21 17#include "check_compat.h"
22#include "helpers.h"
23 18
24#define STATUS_MESSAGE "Installing Gentoo" 19#define STATUS_MESSAGE "Installing Gentoo"
25 20
diff --git a/auto_tests/skeleton_test.c b/auto_tests/skeleton_test.c
index 1d391a86..30fb185c 100644
--- a/auto_tests/skeleton_test.c
+++ b/auto_tests/skeleton_test.c
@@ -2,12 +2,10 @@
2#include "config.h" 2#include "config.h"
3#endif 3#endif
4 4
5#include "check_compat.h"
6
7#include <stdlib.h> 5#include <stdlib.h>
8#include <time.h>
9 6
10#include "helpers.h" 7#include "../testing/misc_tools.h"
8#include "check_compat.h"
11 9
12/* 10/*
13#include "../<stuff to test>" 11#include "../<stuff to test>"
@@ -33,8 +31,6 @@ int main(void)
33{ 31{
34 setvbuf(stdout, nullptr, _IONBF, 0); 32 setvbuf(stdout, nullptr, _IONBF, 0);
35 33
36 srand((unsigned int) time(nullptr));
37
38 Suite *creativesuitenamegoeshere = creativesuitenamegoeshere_suite(); 34 Suite *creativesuitenamegoeshere = creativesuitenamegoeshere_suite();
39 SRunner *test_runner = srunner_create(creativesuitenamegoeshere); 35 SRunner *test_runner = srunner_create(creativesuitenamegoeshere);
40 36
diff --git a/auto_tests/tcp_relay_test.c b/auto_tests/tcp_relay_test.c
index d0c70934..54a28e4a 100644
--- a/auto_tests/tcp_relay_test.c
+++ b/auto_tests/tcp_relay_test.c
@@ -1,8 +1,11 @@
1#ifndef _XOPEN_SOURCE 1#ifdef HAVE_CONFIG_H
2#define _XOPEN_SOURCE 600 2#include "config.h"
3#endif 3#endif
4 4
5#include "helpers.h" 5#include <stdio.h>
6
7#include "../testing/misc_tools.h"
8#include "check_compat.h"
6 9
7static uint8_t const key[] = { 10static uint8_t const key[] = {
8 0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD, 11 0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD,
@@ -33,8 +36,10 @@ int main(void)
33 c_sleep(ITERATION_INTERVAL); 36 c_sleep(ITERATION_INTERVAL);
34 } 37 }
35 38
36 assert(tox_self_get_connection_status(tox_tcp) == TOX_CONNECTION_TCP); 39 const TOX_CONNECTION status = tox_self_get_connection_status(tox_tcp);
37 printf("Connection (TCP): %d\n", tox_self_get_connection_status(tox_tcp)); 40 ck_assert_msg(status == TOX_CONNECTION_TCP,
41 "expected TCP connection, but got %d", status);
42 printf("Connection (TCP): %d\n", status);
38 43
39 tox_kill(tox_tcp); 44 tox_kill(tox_tcp);
40 return 0; 45 return 0;
diff --git a/auto_tests/tox_many_tcp_test.c b/auto_tests/tox_many_tcp_test.c
index 34b01d16..7ce2c9a5 100644
--- a/auto_tests/tox_many_tcp_test.c
+++ b/auto_tests/tox_many_tcp_test.c
@@ -1,25 +1,20 @@
1/* Auto Tests: Many TCP. 1/* Auto Tests: Many TCP.
2 */ 2 */
3 3
4#ifndef _XOPEN_SOURCE
5#define _XOPEN_SOURCE 600
6#endif
7
8#ifdef HAVE_CONFIG_H 4#ifdef HAVE_CONFIG_H
9#include "config.h" 5#include "config.h"
10#endif 6#endif
11 7
12#include "check_compat.h"
13
14#include <stdio.h> 8#include <stdio.h>
15#include <stdlib.h> 9#include <stdlib.h>
10#include <string.h>
16#include <time.h> 11#include <time.h>
17 12
13#include "../testing/misc_tools.h"
18#include "../toxcore/crypto_core.h" 14#include "../toxcore/crypto_core.h"
19#include "../toxcore/tox.h" 15#include "../toxcore/tox.h"
20#include "../toxcore/util.h" 16#include "../toxcore/util.h"
21 17#include "check_compat.h"
22#include "helpers.h"
23 18
24/* The Travis-CI container responds poorly to ::1 as a localhost address 19/* The Travis-CI container responds poorly to ::1 as a localhost address
25 * You're encouraged to -D FORCE_TESTS_IPV6 on a local test */ 20 * You're encouraged to -D FORCE_TESTS_IPV6 on a local test */
@@ -255,8 +250,6 @@ int main(void)
255{ 250{
256 setvbuf(stdout, nullptr, _IONBF, 0); 251 setvbuf(stdout, nullptr, _IONBF, 0);
257 252
258 srand((unsigned int) time(nullptr));
259
260 Suite *tox = tox_suite(); 253 Suite *tox = tox_suite();
261 SRunner *test_runner = srunner_create(tox); 254 SRunner *test_runner = srunner_create(tox);
262 255
diff --git a/auto_tests/tox_many_test.c b/auto_tests/tox_many_test.c
index 4318b29b..ff217e87 100644
--- a/auto_tests/tox_many_test.c
+++ b/auto_tests/tox_many_test.c
@@ -1,25 +1,20 @@
1/* Auto Tests: Many clients. 1/* Auto Tests: Many clients.
2 */ 2 */
3 3
4#ifndef _XOPEN_SOURCE
5#define _XOPEN_SOURCE 600
6#endif
7
8#ifdef HAVE_CONFIG_H 4#ifdef HAVE_CONFIG_H
9#include "config.h" 5#include "config.h"
10#endif 6#endif
11 7
12#include "check_compat.h"
13
14#include <stdio.h> 8#include <stdio.h>
15#include <stdlib.h> 9#include <stdlib.h>
10#include <string.h>
16#include <time.h> 11#include <time.h>
17 12
13#include "../testing/misc_tools.h"
18#include "../toxcore/crypto_core.h" 14#include "../toxcore/crypto_core.h"
19#include "../toxcore/tox.h" 15#include "../toxcore/tox.h"
20#include "../toxcore/util.h" 16#include "../toxcore/util.h"
21 17#include "check_compat.h"
22#include "helpers.h"
23 18
24static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) 19static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
25{ 20{
diff --git a/auto_tests/tox_one_test.c b/auto_tests/tox_one_test.c
index 48e2f791..69ec4461 100644
--- a/auto_tests/tox_one_test.c
+++ b/auto_tests/tox_one_test.c
@@ -5,17 +5,15 @@
5#include "config.h" 5#include "config.h"
6#endif 6#endif
7 7
8#include "check_compat.h"
9
10#include <stdlib.h> 8#include <stdlib.h>
11#include <time.h> 9#include <string.h>
12 10
11#include "../testing/misc_tools.h"
13#include "../toxcore/ccompat.h" 12#include "../toxcore/ccompat.h"
14#include "../toxcore/crypto_core.h" 13#include "../toxcore/crypto_core.h"
15#include "../toxcore/tox.h" 14#include "../toxcore/tox.h"
16#include "../toxcore/util.h" 15#include "../toxcore/util.h"
17 16#include "check_compat.h"
18#include "helpers.h"
19 17
20static void set_random_name_and_status_message(Tox *tox, uint8_t *name, uint8_t *status_message) 18static void set_random_name_and_status_message(Tox *tox, uint8_t *name, uint8_t *status_message)
21{ 19{
@@ -146,8 +144,6 @@ int main(void)
146{ 144{
147 setvbuf(stdout, nullptr, _IONBF, 0); 145 setvbuf(stdout, nullptr, _IONBF, 0);
148 146
149 srand((unsigned int) time(nullptr));
150
151 Suite *tox = tox_suite(); 147 Suite *tox = tox_suite();
152 SRunner *test_runner = srunner_create(tox); 148 SRunner *test_runner = srunner_create(tox);
153 149
diff --git a/auto_tests/tox_strncasecmp_test.c b/auto_tests/tox_strncasecmp_test.c
index 377ec2e3..7209facf 100644
--- a/auto_tests/tox_strncasecmp_test.c
+++ b/auto_tests/tox_strncasecmp_test.c
@@ -2,17 +2,11 @@
2#include "config.h" 2#include "config.h"
3#endif 3#endif
4 4
5#include "check_compat.h"
6
7#include <stdint.h>
8#include <stdlib.h> 5#include <stdlib.h>
9#include <string.h> 6#include <string.h>
10#include <sys/types.h>
11#include <time.h>
12
13#include "helpers.h"
14 7
15#include "../testing/misc_tools.c" 8#include "../testing/misc_tools.h"
9#include "check_compat.h"
16 10
17typedef enum { 11typedef enum {
18 NEGATIVE, 12 NEGATIVE,
@@ -181,8 +175,6 @@ int main(void)
181{ 175{
182 setvbuf(stdout, nullptr, _IONBF, 0); 176 setvbuf(stdout, nullptr, _IONBF, 0);
183 177
184 srand((unsigned int) time(nullptr));
185
186 Suite *s = tox_strncasecmp_suite(); 178 Suite *s = tox_strncasecmp_suite();
187 SRunner *test_runner = srunner_create(s); 179 SRunner *test_runner = srunner_create(s);
188 180
diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c
index b2b92255..859c7a0c 100644
--- a/auto_tests/toxav_basic_test.c
+++ b/auto_tests/toxav_basic_test.c
@@ -1,29 +1,21 @@
1#ifndef _XOPEN_SOURCE
2#define _XOPEN_SOURCE 600
3#endif
4
5#ifdef HAVE_CONFIG_H 1#ifdef HAVE_CONFIG_H
6#include "config.h" 2#include "config.h"
7#endif 3#endif
8 4
9#include "check_compat.h"
10
11#include <stdint.h>
12#include <stdio.h> 5#include <stdio.h>
13#include <stdlib.h> 6#include <stdlib.h>
14#include <string.h> 7#include <string.h>
15#include <sys/types.h>
16#include <time.h> 8#include <time.h>
17 9
18#include <vpx/vpx_image.h> 10#include <vpx/vpx_image.h>
19 11
12#include "../testing/misc_tools.h"
20#include "../toxav/toxav.h" 13#include "../toxav/toxav.h"
21#include "../toxcore/crypto_core.h" 14#include "../toxcore/crypto_core.h"
22#include "../toxcore/logger.h" 15#include "../toxcore/logger.h"
23#include "../toxcore/tox.h" 16#include "../toxcore/tox.h"
24#include "../toxcore/util.h" 17#include "../toxcore/util.h"
25 18#include "check_compat.h"
26#include "helpers.h"
27 19
28#define TEST_REGULAR_AV 1 20#define TEST_REGULAR_AV 1
29#define TEST_REGULAR_A 1 21#define TEST_REGULAR_A 1
diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c
index 94183421..ed005e2f 100644
--- a/auto_tests/toxav_many_test.c
+++ b/auto_tests/toxav_many_test.c
@@ -1,13 +1,7 @@
1#ifndef _XOPEN_SOURCE
2#define _XOPEN_SOURCE 600
3#endif
4
5#ifdef HAVE_CONFIG_H 1#ifdef HAVE_CONFIG_H
6#include "config.h" 2#include "config.h"
7#endif 3#endif
8 4
9#include "check_compat.h"
10
11#include <stdint.h> 5#include <stdint.h>
12#include <stdio.h> 6#include <stdio.h>
13#include <stdlib.h> 7#include <stdlib.h>
@@ -15,19 +9,19 @@
15#include <sys/types.h> 9#include <sys/types.h>
16#include <time.h> 10#include <time.h>
17 11
12#if !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32)
13#include <pthread.h>
14#endif
15
18#include <vpx/vpx_image.h> 16#include <vpx/vpx_image.h>
19 17
18#include "../testing/misc_tools.h"
20#include "../toxav/toxav.h" 19#include "../toxav/toxav.h"
21#include "../toxcore/crypto_core.h" 20#include "../toxcore/crypto_core.h"
22#include "../toxcore/logger.h" 21#include "../toxcore/logger.h"
23#include "../toxcore/tox.h" 22#include "../toxcore/tox.h"
24#include "../toxcore/util.h" 23#include "../toxcore/util.h"
25 24#include "check_compat.h"
26#include "helpers.h"
27
28#if !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32)
29#include <pthread.h>
30#endif
31 25
32typedef struct { 26typedef struct {
33 bool incoming; 27 bool incoming;
diff --git a/auto_tests/typing_test.c b/auto_tests/typing_test.c
index 1262fa3d..041e0b25 100644
--- a/auto_tests/typing_test.c
+++ b/auto_tests/typing_test.c
@@ -1,25 +1,19 @@
1/* Tests that our typing notifications work. 1/* Tests that our typing notifications work.
2 */ 2 */
3 3
4#ifndef _XOPEN_SOURCE
5#define _XOPEN_SOURCE 600
6#endif
7
8#ifdef HAVE_CONFIG_H 4#ifdef HAVE_CONFIG_H
9#include "config.h" 5#include "config.h"
10#endif 6#endif
11 7
12#include "check_compat.h"
13
14#include <stdio.h> 8#include <stdio.h>
15#include <stdlib.h> 9#include <stdlib.h>
16#include <time.h> 10#include <time.h>
17 11
12#include "../testing/misc_tools.h"
18#include "../toxcore/ccompat.h" 13#include "../toxcore/ccompat.h"
19#include "../toxcore/tox.h" 14#include "../toxcore/tox.h"
20#include "../toxcore/util.h" 15#include "../toxcore/util.h"
21 16#include "check_compat.h"
22#include "helpers.h"
23 17
24static void typing_callback(Tox *m, uint32_t friendnumber, bool typing, void *userdata) 18static void typing_callback(Tox *m, uint32_t friendnumber, bool typing, void *userdata)
25{ 19{
diff --git a/auto_tests/version_test.c b/auto_tests/version_test.c
index 7509397a..aa59fdd8 100644
--- a/auto_tests/version_test.c
+++ b/auto_tests/version_test.c
@@ -1,9 +1,10 @@
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4
1#include "../toxcore/tox.h" 5#include "../toxcore/tox.h"
2#include "check_compat.h" 6#include "check_compat.h"
3 7
4#include <stdio.h>
5#include <stdlib.h>
6
7#define check(major, minor, patch, expected) \ 8#define check(major, minor, patch, expected) \
8 do_check(TOX_VERSION_MAJOR, TOX_VERSION_MINOR, TOX_VERSION_PATCH, \ 9 do_check(TOX_VERSION_MAJOR, TOX_VERSION_MINOR, TOX_VERSION_PATCH, \
9 major, minor, patch, \ 10 major, minor, patch, \
diff --git a/build/Makefile.am b/build/Makefile.am
index c5c170a3..d9d2911e 100644
--- a/build/Makefile.am
+++ b/build/Makefile.am
@@ -1,5 +1,6 @@
1bin_PROGRAMS = 1bin_PROGRAMS =
2noinst_PROGRAMS = 2noinst_PROGRAMS =
3noinst_LTLIBRARIES =
3lib_LTLIBRARIES = 4lib_LTLIBRARIES =
4noinst_bindir = $(top_builddir)/build 5noinst_bindir = $(top_builddir)/build
5EXTRA_DIST= 6EXTRA_DIST=
diff --git a/other/BUILD.bazel b/other/BUILD.bazel
index beec2397..8bcdc4b4 100644
--- a/other/BUILD.bazel
+++ b/other/BUILD.bazel
@@ -5,6 +5,7 @@ cc_library(
5 hdrs = ["monolith.h"], 5 hdrs = ["monolith.h"],
6 visibility = ["//c-toxcore/auto_tests:__pkg__"], 6 visibility = ["//c-toxcore/auto_tests:__pkg__"],
7 deps = [ 7 deps = [
8 "//c-toxcore/testing:monolith",
8 "//c-toxcore/toxav:monolith", 9 "//c-toxcore/toxav:monolith",
9 "//c-toxcore/toxcore:monolith", 10 "//c-toxcore/toxcore:monolith",
10 "//c-toxcore/toxencryptsave:monolith", 11 "//c-toxcore/toxencryptsave:monolith",
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c
index b71ab0b1..347e5c82 100644
--- a/other/DHT_bootstrap.c
+++ b/other/DHT_bootstrap.c
@@ -23,11 +23,9 @@
23 * You should have received a copy of the GNU General Public License 23 * You should have received a copy of the GNU General Public License
24 * along with Tox. If not, see <http://www.gnu.org/licenses/>. 24 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
25 */ 25 */
26#define _XOPEN_SOURCE 600 26#include <stdio.h>
27 27#include <stdlib.h>
28#ifdef HAVE_CONFIG_H 28#include <string.h>
29#include "config.h"
30#endif
31 29
32#include "../toxcore/DHT.h" 30#include "../toxcore/DHT.h"
33#include "../toxcore/LAN_discovery.h" 31#include "../toxcore/LAN_discovery.h"
@@ -43,7 +41,7 @@
43#include "../toxcore/TCP_server.h" 41#include "../toxcore/TCP_server.h"
44#endif 42#endif
45 43
46#include "../testing/misc_tools.c" 44#include "../testing/misc_tools.h"
47 45
48#ifdef DHT_NODE_EXTRA_PACKETS 46#ifdef DHT_NODE_EXTRA_PACKETS
49#include "./bootstrap_node_packets.h" 47#include "./bootstrap_node_packets.h"
diff --git a/other/Makefile.inc b/other/Makefile.inc
index 10cd48b4..6d4ec593 100644
--- a/other/Makefile.inc
+++ b/other/Makefile.inc
@@ -14,6 +14,7 @@ DHT_bootstrap_CFLAGS = -I$(top_srcdir)/other \
14 14
15DHT_bootstrap_LDADD = $(LIBSODIUM_LDFLAGS) \ 15DHT_bootstrap_LDADD = $(LIBSODIUM_LDFLAGS) \
16 $(NACL_LDFLAGS) \ 16 $(NACL_LDFLAGS) \
17 libmisc_tools.la \
17 libtoxcore.la \ 18 libtoxcore.la \
18 $(LIBSODIUM_LIBS) \ 19 $(LIBSODIUM_LIBS) \
19 $(NACL_OBJECTS) \ 20 $(NACL_OBJECTS) \
diff --git a/other/fun/cracker.c b/other/fun/cracker.c
index 9cfe96d7..502a8af0 100644
--- a/other/fun/cracker.c
+++ b/other/fun/cracker.c
@@ -9,15 +9,16 @@
9 * Will try to find a public key starting with: ABCDEF 9 * Will try to find a public key starting with: ABCDEF
10 */ 10 */
11 11
12#include "../../testing/misc_tools.c" 12#include <stdlib.h>
13#include <time.h> 13#include <stdio.h>
14#include <string.h>
14 15
15/* NaCl includes*/ 16/* Sodium includes*/
16#include <sodium/crypto_scalarmult_curve25519.h> 17#include <sodium/crypto_scalarmult_curve25519.h>
17#include <sodium/randombytes.h> 18#include <sodium/randombytes.h>
18 19
19/* Sodium include*/ 20#include "../../testing/misc_tools.h"
20//#include <sodium.h> 21#include "../../toxcore/ccompat.h"
21 22
22void print_key(uint8_t *client_id) 23void print_key(uint8_t *client_id)
23{ 24{
diff --git a/other/fun/sign.c b/other/fun/sign.c
index 369bc848..007d19a0 100644
--- a/other/fun/sign.c
+++ b/other/fun/sign.c
@@ -15,10 +15,12 @@
15 * 15 *
16 * NOTE: The signature is appended to the end of the file. 16 * NOTE: The signature is appended to the end of the file.
17 */ 17 */
18#include "../../testing/misc_tools.c" // hex_string_to_bin
19#include <sodium.h> 18#include <sodium.h>
20#include <string.h> 19#include <string.h>
21 20
21#include "../../testing/misc_tools.h" // hex_string_to_bin
22#include "../../toxcore/ccompat.h"
23
22int load_file(char *filename, char **result) 24int load_file(char *filename, char **result)
23{ 25{
24 int size = 0; 26 int size = 0;
diff --git a/testing/BUILD.bazel b/testing/BUILD.bazel
index 117eb69d..4d0674b4 100644
--- a/testing/BUILD.bazel
+++ b/testing/BUILD.bazel
@@ -2,11 +2,10 @@ load("//tools:no_undefined.bzl", "cc_library")
2 2
3cc_library( 3cc_library(
4 name = "misc_tools", 4 name = "misc_tools",
5 hdrs = [ 5 srcs = ["misc_tools.c"],
6 "misc_tools.c", 6 hdrs = ["misc_tools.h"],
7 ],
8 visibility = ["//c-toxcore:__subpackages__"], 7 visibility = ["//c-toxcore:__subpackages__"],
9 deps = ["//c-toxcore/toxcore:ccompat"], 8 deps = ["//c-toxcore/toxcore"],
10) 9)
11 10
12cc_binary( 11cc_binary(
@@ -53,3 +52,13 @@ cc_binary(
53 "//c-toxcore/toxcore", 52 "//c-toxcore/toxcore",
54 ], 53 ],
55) 54)
55
56cc_library(
57 name = "monolith",
58 hdrs = [
59 "misc_tools.c",
60 "misc_tools.h",
61 ],
62 visibility = ["//c-toxcore/other:__pkg__"],
63 deps = ["//c-toxcore/toxcore"],
64)
diff --git a/testing/DHT_test.c b/testing/DHT_test.c
index 336e7e18..c242953a 100644
--- a/testing/DHT_test.c
+++ b/testing/DHT_test.c
@@ -30,21 +30,18 @@
30 */ 30 */
31#define _XOPEN_SOURCE 600 31#define _XOPEN_SOURCE 600
32 32
33#ifdef HAVE_CONFIG_H 33#include <stdlib.h>
34#include "config.h" 34#include <stdio.h>
35#endif
36
37//#include "../core/network.h"
38#include "../toxcore/DHT.h"
39#include "../toxcore/friend_requests.h"
40#include "misc_tools.c"
41
42#include <string.h> 35#include <string.h>
43 36
44#if !defined(_WIN32) && !defined(__WIN32__) && !defined (WIN32) 37#if !defined(_WIN32) && !defined(__WIN32__) && !defined (WIN32)
45#include <arpa/inet.h> 38#include <arpa/inet.h>
46#endif 39#endif
47 40
41#include "../toxcore/DHT.h"
42#include "../toxcore/friend_requests.h"
43#include "misc_tools.h"
44
48#define PORT 33445 45#define PORT 33445
49 46
50static uint8_t zeroes_cid[CRYPTO_PUBLIC_KEY_SIZE]; 47static uint8_t zeroes_cid[CRYPTO_PUBLIC_KEY_SIZE];
diff --git a/testing/Makefile.inc b/testing/Makefile.inc
index f4ed568c..fa1c1029 100644
--- a/testing/Makefile.inc
+++ b/testing/Makefile.inc
@@ -1,3 +1,13 @@
1if BUILD_TESTS
2TEST_LIB = misc_tools
3endif
4if BUILD_TESTING
5TEST_LIB = misc_tools
6endif
7
8noinst_LTLIBRARIES += libmisc_tools.la
9libmisc_tools_la_SOURCES = ../testing/misc_tools.c ../testing/misc_tools.h
10
1if BUILD_TESTING 11if BUILD_TESTING
2 12
3noinst_PROGRAMS += DHT_test \ 13noinst_PROGRAMS += DHT_test \
@@ -10,6 +20,7 @@ DHT_test_CFLAGS = $(LIBSODIUM_CFLAGS) \
10 20
11DHT_test_LDADD = $(LIBSODIUM_LDFLAGS) \ 21DHT_test_LDADD = $(LIBSODIUM_LDFLAGS) \
12 $(NACL_LDFLAGS) \ 22 $(NACL_LDFLAGS) \
23 libmisc_tools.la \
13 libtoxcore.la \ 24 libtoxcore.la \
14 $(LIBSODIUM_LIBS) \ 25 $(LIBSODIUM_LIBS) \
15 $(NACL_OBJECTS) \ 26 $(NACL_OBJECTS) \
@@ -25,13 +36,11 @@ Messenger_test_CFLAGS = $(LIBSODIUM_CFLAGS) \
25 36
26Messenger_test_LDADD = $(LIBSODIUM_LDFLAGS) \ 37Messenger_test_LDADD = $(LIBSODIUM_LDFLAGS) \
27 $(NACL_LDFLAGS) \ 38 $(NACL_LDFLAGS) \
39 libmisc_tools.la \
28 libtoxcore.la \ 40 libtoxcore.la \
29 $(LIBSODIUM_LIBS) \ 41 $(LIBSODIUM_LIBS) \
30 $(NACL_OBJECTS) \ 42 $(NACL_OBJECTS) \
31 $(NACL_LIBS) \ 43 $(NACL_LIBS) \
32 $(WINSOCK2_LIBS) 44 $(WINSOCK2_LIBS)
33 45
34
35EXTRA_DIST += $(top_srcdir)/testing/misc_tools.c
36
37endif 46endif
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c
index 7885779b..a3380a09 100644
--- a/testing/Messenger_test.c
+++ b/testing/Messenger_test.c
@@ -38,20 +38,17 @@
38 * You should have received a copy of the GNU General Public License 38 * You should have received a copy of the GNU General Public License
39 * along with Tox. If not, see <http://www.gnu.org/licenses/>. 39 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
40 */ 40 */
41#define _XOPEN_SOURCE 600 41#include <stdio.h>
42 42#include <stdlib.h>
43#ifdef HAVE_CONFIG_H 43#include <string.h>
44#include "config.h"
45#endif
46
47#include "../toxcore/Messenger.h"
48#include "misc_tools.c"
49 44
50#if !defined(_WIN32) && !defined(__WIN32__) && !defined (WIN32) 45#if !defined(_WIN32) && !defined(__WIN32__) && !defined (WIN32)
51#include <arpa/inet.h> 46#include <arpa/inet.h>
52
53#endif 47#endif
54 48
49#include "../toxcore/Messenger.h"
50#include "misc_tools.h"
51
55static void print_message(Messenger *m, uint32_t friendnumber, unsigned int type, const uint8_t *string, size_t length, 52static void print_message(Messenger *m, uint32_t friendnumber, unsigned int type, const uint8_t *string, size_t length,
56 void *userdata) 53 void *userdata)
57{ 54{
diff --git a/testing/misc_tools.c b/testing/misc_tools.c
index 9b0d9956..8683830d 100644
--- a/testing/misc_tools.c
+++ b/testing/misc_tools.c
@@ -21,35 +21,40 @@
21 * You should have received a copy of the GNU General Public License 21 * You should have received a copy of the GNU General Public License
22 * along with Tox. If not, see <http://www.gnu.org/licenses/>. 22 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
23 */ 23 */
24#ifndef MISC_TOOLS_C 24#ifndef _POSIX_C_SOURCE
25#define MISC_TOOLS_C 25// For nanosleep().
26 26#define _POSIX_C_SOURCE 199309L
27#ifdef HAVE_CONFIG_H
28#include "config.h"
29#endif 27#endif
30 28
29#include "misc_tools.h"
30
31#include <assert.h>
31#include <ctype.h> 32#include <ctype.h>
32#include <stdint.h> 33#include <stdint.h>
33#include <stdio.h> 34#include <stdio.h>
34#include <stdlib.h> 35#include <stdlib.h>
35#include <string.h> 36#include <string.h>
36 37
37//Sleep function (x = milliseconds) 38#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
38#ifndef c_sleep
39#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
40#include <windows.h> 39#include <windows.h>
41#define c_sleep(x) Sleep(x)
42#else 40#else
43#include <unistd.h> 41#include <time.h>
44#define c_sleep(x) usleep(1000*(x))
45#endif
46#endif 42#endif
47 43
48#include "../toxcore/ccompat.h" 44#include "../toxcore/ccompat.h"
45#include "../toxcore/tox.h"
49 46
50uint8_t *hex_string_to_bin(const char *hex_string); 47void c_sleep(uint32_t x)
51int tox_strncasecmp(const char *s1, const char *s2, size_t n); 48{
52int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled); 49#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
50 Sleep(x);
51#else
52 struct timespec req;
53 req.tv_sec = x / 1000;
54 req.tv_nsec = (long)x % 1000 * 1000 * 1000;
55 nanosleep(&req, nullptr);
56#endif
57}
53 58
54// You are responsible for freeing the return value! 59// You are responsible for freeing the return value!
55uint8_t *hex_string_to_bin(const char *hex_string) 60uint8_t *hex_string_to_bin(const char *hex_string)
@@ -123,4 +128,64 @@ int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled)
123 return argvoffset; 128 return argvoffset;
124} 129}
125 130
126#endif // MISC_TOOLS_C 131static const char *tox_log_level_name(TOX_LOG_LEVEL level)
132{
133 switch (level) {
134 case TOX_LOG_LEVEL_TRACE:
135 return "TRACE";
136
137 case TOX_LOG_LEVEL_DEBUG:
138 return "DEBUG";
139
140 case TOX_LOG_LEVEL_INFO:
141 return "INFO";
142
143 case TOX_LOG_LEVEL_WARNING:
144 return "WARNING";
145
146 case TOX_LOG_LEVEL_ERROR:
147 return "ERROR";
148 }
149
150 return "<unknown>";
151}
152
153void print_debug_log(Tox *m, TOX_LOG_LEVEL level, const char *file, uint32_t line, const char *func,
154 const char *message, void *user_data)
155{
156 if (level == TOX_LOG_LEVEL_TRACE) {
157 return;
158 }
159
160 uint32_t index = user_data ? *(uint32_t *)user_data : 0;
161 fprintf(stderr, "[#%u] %s %s:%u\t%s:\t%s\n", index, tox_log_level_name(level), file, line, func, message);
162}
163
164Tox *tox_new_log_lan(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data, bool lan_discovery)
165{
166 struct Tox_Options *log_options = options;
167
168 if (log_options == nullptr) {
169 log_options = tox_options_new(nullptr);
170 }
171
172 assert(log_options != nullptr);
173
174 tox_options_set_local_discovery_enabled(log_options, lan_discovery);
175 tox_options_set_start_port(log_options, 33445);
176 tox_options_set_end_port(log_options, 33445 + 2000);
177 tox_options_set_log_callback(log_options, &print_debug_log);
178 tox_options_set_log_user_data(log_options, log_user_data);
179 Tox *tox = tox_new(log_options, err);
180
181 if (options == nullptr) {
182 tox_options_free(log_options);
183 }
184
185 return tox;
186}
187
188Tox *tox_new_log(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data)
189{
190 return tox_new_log_lan(options, err, log_user_data, false);
191}
diff --git a/testing/misc_tools.h b/testing/misc_tools.h
new file mode 100644
index 00000000..deaa177d
--- /dev/null
+++ b/testing/misc_tools.h
@@ -0,0 +1,29 @@
1#ifndef C_TOXCORE_TESTING_MISC_TOOLS_H
2#define C_TOXCORE_TESTING_MISC_TOOLS_H
3
4#include "../toxcore/tox.h"
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10// Amount of time in milliseconds to wait between tox_iterate calls.
11#define ITERATION_INTERVAL 200
12
13void c_sleep(uint32_t x);
14
15uint8_t *hex_string_to_bin(const char *hex_string);
16int tox_strncasecmp(const char *s1, const char *s2, size_t n);
17int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled);
18
19void print_debug_log(Tox *m, TOX_LOG_LEVEL level, const char *file, uint32_t line, const char *func,
20 const char *message, void *user_data);
21
22Tox *tox_new_log(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data);
23Tox *tox_new_log_lan(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data, bool lan_discovery);
24
25#ifdef __cplusplus
26}
27#endif
28
29#endif
diff --git a/testing/random_testing.cc b/testing/random_testing.cc
index f4175675..bcdb8e70 100644
--- a/testing/random_testing.cc
+++ b/testing/random_testing.cc
@@ -11,7 +11,7 @@
11#include <vector> 11#include <vector>
12 12
13#include "../toxcore/tox.h" 13#include "../toxcore/tox.h"
14#include "misc_tools.c" 14#include "misc_tools.h"
15 15
16namespace { 16namespace {
17 17
@@ -32,8 +32,6 @@ constexpr uint32_t MAX_ACTIONS = 10000;
32constexpr uint32_t MAX_ACTION_ATTEMPTS = 100; 32constexpr uint32_t MAX_ACTION_ATTEMPTS = 100;
33// Number of tox_iterate calls between each action. 33// Number of tox_iterate calls between each action.
34constexpr uint32_t ITERATIONS_PER_ACTION = 1; 34constexpr uint32_t ITERATIONS_PER_ACTION = 1;
35// Amount of time in milliseconds to wait between tox_iterate calls.
36constexpr uint32_t ITERATION_INTERVAL = 5;
37 35
38struct Tox_Options_Deleter { 36struct Tox_Options_Deleter {
39 void operator()(Tox_Options *options) const { tox_options_free(options); } 37 void operator()(Tox_Options *options) const { tox_options_free(options); }