summaryrefslogtreecommitdiff
path: root/protocols/Tox/toxcore/auto_tests
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-08-10 12:10:17 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-08-10 12:10:17 +0000
commit254f7c0601c1972e016e0afb7989b27c9e432239 (patch)
tree0d41f0e2db16b3b943fa588a780f8a30b63dabf9 /protocols/Tox/toxcore/auto_tests
parent5867abd3dae59bcb8ea93d77ee3ad9e203ecff79 (diff)
not needed
git-svn-id: http://svn.miranda-ng.org/main/trunk@10143 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox/toxcore/auto_tests')
-rw-r--r--protocols/Tox/toxcore/auto_tests/Makefile.inc95
-rw-r--r--protocols/Tox/toxcore/auto_tests/TCP_test.c525
-rw-r--r--protocols/Tox/toxcore/auto_tests/assoc_test.c168
-rw-r--r--protocols/Tox/toxcore/auto_tests/crypto_test.c310
-rw-r--r--protocols/Tox/toxcore/auto_tests/friends_test.c238
-rw-r--r--protocols/Tox/toxcore/auto_tests/messenger_test.c366
-rw-r--r--protocols/Tox/toxcore/auto_tests/network_test.c174
-rw-r--r--protocols/Tox/toxcore/auto_tests/onion_test.c369
-rw-r--r--protocols/Tox/toxcore/auto_tests/skeleton_test.c53
-rw-r--r--protocols/Tox/toxcore/auto_tests/tox_test.c395
-rw-r--r--protocols/Tox/toxcore/auto_tests/toxav_basic_test.c599
-rw-r--r--protocols/Tox/toxcore/auto_tests/toxav_many_test.c402
12 files changed, 0 insertions, 3694 deletions
diff --git a/protocols/Tox/toxcore/auto_tests/Makefile.inc b/protocols/Tox/toxcore/auto_tests/Makefile.inc
deleted file mode 100644
index ecf3f31f7a..0000000000
--- a/protocols/Tox/toxcore/auto_tests/Makefile.inc
+++ /dev/null
@@ -1,95 +0,0 @@
-if BUILD_TESTS
-
-TESTS = messenger_autotest crypto_test network_test assoc_test onion_test TCP_test tox_test
-check_PROGRAMS = messenger_autotest crypto_test network_test assoc_test onion_test TCP_test tox_test
-
-AUTOTEST_CFLAGS = \
- $(LIBSODIUM_CFLAGS) \
- $(NACL_CFLAGS) \
- $(CHECK_CFLAGS)
-
-AUTOTEST_LDADD = \
- $(LIBSODIUM_LDFLAGS) \
- $(NACL_LDFLAGS) \
- libtoxcore.la \
- $(LIBSODIUM_LIBS) \
- $(NACL_OBJECTS) \
- $(NACL_LIBS) \
- $(CHECK_LIBS)
-
-
-
-if BUILD_AV
-TESTS += toxav_basic_test toxav_many_test
-check_PROGRAMS += toxav_basic_test toxav_many_test
-AUTOTEST_LDADD += libtoxav.la
-endif
-
-messenger_autotest_SOURCES = ../auto_tests/messenger_test.c
-
-messenger_autotest_CFLAGS = $(AUTOTEST_CFLAGS)
-
-messenger_autotest_LDADD = $(AUTOTEST_LDADD)
-
-
-crypto_test_SOURCES = ../auto_tests/crypto_test.c
-
-crypto_test_CFLAGS = $(AUTOTEST_CFLAGS)
-
-crypto_test_LDADD = $(AUTOTEST_LDADD)
-
-
-network_test_SOURCES = ../auto_tests/network_test.c
-
-network_test_CFLAGS = $(AUTOTEST_CFLAGS)
-
-network_test_LDADD = $(AUTOTEST_LDADD)
-
-
-assoc_test_SOURCES = ../auto_tests/assoc_test.c
-
-assoc_test_CFLAGS = $(AUTOTEST_CFLAGS)
-
-assoc_test_LDADD = $(AUTOTEST_LDADD)
-
-
-onion_test_SOURCES = ../auto_tests/onion_test.c
-
-onion_test_CFLAGS = $(AUTOTEST_CFLAGS)
-
-onion_test_LDADD = $(AUTOTEST_LDADD)
-
-
-TCP_test_SOURCES = ../auto_tests/TCP_test.c
-
-TCP_test_CFLAGS = $(AUTOTEST_CFLAGS)
-
-TCP_test_LDADD = $(AUTOTEST_LDADD)
-
-
-tox_test_SOURCES = ../auto_tests/tox_test.c
-
-tox_test_CFLAGS = $(AUTOTEST_CFLAGS)
-
-tox_test_LDADD = $(AUTOTEST_LDADD)
-
-
-
-if BUILD_AV
-toxav_basic_test_SOURCES = ../auto_tests/toxav_basic_test.c
-
-toxav_basic_test_CFLAGS = $(AUTOTEST_CFLAGS)
-
-toxav_basic_test_LDADD = $(AUTOTEST_LDADD) $(AV_LIBS)
-
-
-toxav_many_test_SOURCES = ../auto_tests/toxav_many_test.c
-
-toxav_many_test_CFLAGS = $(AUTOTEST_CFLAGS)
-
-toxav_many_test_LDADD = $(AUTOTEST_LDADD)
-endif
-
-endif
-
-EXTRA_DIST += $(top_srcdir)/auto_tests/friends_test.c \ No newline at end of file
diff --git a/protocols/Tox/toxcore/auto_tests/TCP_test.c b/protocols/Tox/toxcore/auto_tests/TCP_test.c
deleted file mode 100644
index 8e75fae0c7..0000000000
--- a/protocols/Tox/toxcore/auto_tests/TCP_test.c
+++ /dev/null
@@ -1,525 +0,0 @@
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <sys/types.h>
-#include <stdint.h>
-#include <string.h>
-#include <check.h>
-#include <stdlib.h>
-#include <time.h>
-
-#include "../toxcore/TCP_server.h"
-#include "../toxcore/TCP_client.h"
-
-#include "../toxcore/util.h"
-
-#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
-#define c_sleep(x) Sleep(1*x)
-#else
-#include <unistd.h>
-#define c_sleep(x) usleep(1000*x)
-#endif
-
-#define NUM_PORTS 3
-
-uint16_t ports[NUM_PORTS] = {1234, 33445, 25643};
-
-START_TEST(test_basic)
-{
- uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
- uint8_t self_secret_key[crypto_box_SECRETKEYBYTES];
- crypto_box_keypair(self_public_key, self_secret_key);
- TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_public_key, self_secret_key, NULL);
- ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server");
- ck_assert_msg(tcp_s->num_listening_socks == NUM_PORTS, "Failed to bind to all ports");
-
- sock_t sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
- struct sockaddr_in6 addr6_loopback = {0};
- addr6_loopback.sin6_family = AF_INET6;
- addr6_loopback.sin6_port = htons(ports[rand() % NUM_PORTS]);
- addr6_loopback.sin6_addr = in6addr_loopback;
-
- int ret = connect(sock, (struct sockaddr *)&addr6_loopback, sizeof(addr6_loopback));
- ck_assert_msg(ret == 0, "Failed to connect to TCP relay server");
-
- uint8_t f_public_key[crypto_box_PUBLICKEYBYTES];
- uint8_t f_secret_key[crypto_box_SECRETKEYBYTES];
- uint8_t f_nonce[crypto_box_NONCEBYTES];
- crypto_box_keypair(f_public_key, f_secret_key);
- random_nonce(f_nonce);
-
- uint8_t t_secret_key[crypto_box_SECRETKEYBYTES];
- uint8_t handshake_plain[TCP_HANDSHAKE_PLAIN_SIZE];
- crypto_box_keypair(handshake_plain, t_secret_key);
- memcpy(handshake_plain + crypto_box_PUBLICKEYBYTES, f_nonce, crypto_box_NONCEBYTES);
- uint8_t handshake[TCP_CLIENT_HANDSHAKE_SIZE];
- memcpy(handshake, f_public_key, crypto_box_PUBLICKEYBYTES);
- new_nonce(handshake + crypto_box_PUBLICKEYBYTES);
-
- ret = encrypt_data(self_public_key, f_secret_key, handshake + crypto_box_PUBLICKEYBYTES, handshake_plain,
- TCP_HANDSHAKE_PLAIN_SIZE, handshake + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES);
- ck_assert_msg(ret == TCP_CLIENT_HANDSHAKE_SIZE - (crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES),
- "Encrypt failed.");
- ck_assert_msg(send(sock, handshake, TCP_CLIENT_HANDSHAKE_SIZE - 1, 0) == TCP_CLIENT_HANDSHAKE_SIZE - 1, "send Failed.");
- c_sleep(50);
- do_TCP_server(tcp_s);
- c_sleep(50);
- do_TCP_server(tcp_s);
- c_sleep(50);
- ck_assert_msg(send(sock, handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1), 1, 0) == 1, "send Failed.");
- c_sleep(50);
- do_TCP_server(tcp_s);
- c_sleep(50);
- do_TCP_server(tcp_s);
- c_sleep(50);
- uint8_t response[TCP_SERVER_HANDSHAKE_SIZE];
- uint8_t response_plain[TCP_HANDSHAKE_PLAIN_SIZE];
- ck_assert_msg(recv(sock, response, TCP_SERVER_HANDSHAKE_SIZE, 0) == TCP_SERVER_HANDSHAKE_SIZE, "recv Failed.");
- ret = decrypt_data(self_public_key, f_secret_key, response, response + crypto_box_NONCEBYTES,
- TCP_SERVER_HANDSHAKE_SIZE - crypto_box_NONCEBYTES, response_plain);
- ck_assert_msg(ret == TCP_HANDSHAKE_PLAIN_SIZE, "Decrypt Failed.");
- uint8_t f_nonce_r[crypto_box_NONCEBYTES];
- uint8_t f_shared_key[crypto_box_BEFORENMBYTES];
- encrypt_precompute(response_plain, t_secret_key, f_shared_key);
- memcpy(f_nonce_r, response_plain + crypto_box_BEFORENMBYTES, crypto_box_NONCEBYTES);
-
- uint8_t r_req_p[1 + crypto_box_PUBLICKEYBYTES] = {0};
- memcpy(r_req_p + 1, f_public_key, crypto_box_PUBLICKEYBYTES);
- uint8_t r_req[2 + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES];
- uint16_t size = 1 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES;
- size = htons(size);
- ret = encrypt_data_symmetric(f_shared_key, f_nonce, r_req_p, 1 + crypto_box_PUBLICKEYBYTES, r_req + 2);
- increment_nonce(f_nonce);
- memcpy(r_req, &size, 2);
- uint32_t i;
-
- for (i = 0; i < sizeof(r_req); ++i) {
- ck_assert_msg(send(sock, r_req + i, 1, 0) == 1, "send Failed.");
- //ck_assert_msg(send(sock, r_req, sizeof(r_req), 0) == sizeof(r_req), "send Failed.");
- do_TCP_server(tcp_s);
- c_sleep(50);
- }
-
- do_TCP_server(tcp_s);
- c_sleep(50);
- uint8_t packet_resp[4096];
- int recv_data_len;
- ck_assert_msg((recv_data_len = recv(sock, packet_resp, 2 + 2 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES,
- 0)) == 2 + 2 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES, "recv Failed. %u", recv_data_len);
- memcpy(&size, packet_resp, 2);
- ck_assert_msg(ntohs(size) == 2 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES, "Wrong packet size.");
- uint8_t packet_resp_plain[4096];
- ret = decrypt_data_symmetric(f_shared_key, f_nonce_r, packet_resp + 2, recv_data_len - 2, packet_resp_plain);
- ck_assert_msg(ret != -1, "decryption failed");
- increment_nonce(f_nonce_r);
- ck_assert_msg(packet_resp_plain[0] == 1, "wrong packet id %u", packet_resp_plain[0]);
- ck_assert_msg(packet_resp_plain[1] == 0, "connection not refused %u", packet_resp_plain[1]);
- ck_assert_msg(memcmp(packet_resp_plain + 2, f_public_key, crypto_box_PUBLICKEYBYTES) == 0, "key in packet wrong");
-}
-END_TEST
-
-struct sec_TCP_con {
- sock_t sock;
- uint8_t public_key[crypto_box_PUBLICKEYBYTES];
- uint8_t recv_nonce[crypto_box_NONCEBYTES];
- uint8_t sent_nonce[crypto_box_NONCEBYTES];
- uint8_t shared_key[crypto_box_BEFORENMBYTES];
-};
-
-struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s)
-{
- struct sec_TCP_con *sec_c = malloc(sizeof(struct sec_TCP_con));
- sock_t sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
- struct sockaddr_in6 addr6_loopback = {0};
- addr6_loopback.sin6_family = AF_INET6;
- addr6_loopback.sin6_port = htons(ports[rand() % NUM_PORTS]);
- addr6_loopback.sin6_addr = in6addr_loopback;
-
- int ret = connect(sock, (struct sockaddr *)&addr6_loopback, sizeof(addr6_loopback));
- ck_assert_msg(ret == 0, "Failed to connect to TCP relay server");
-
- uint8_t f_secret_key[crypto_box_SECRETKEYBYTES];
- crypto_box_keypair(sec_c->public_key, f_secret_key);
- random_nonce(sec_c->sent_nonce);
-
- uint8_t t_secret_key[crypto_box_SECRETKEYBYTES];
- uint8_t handshake_plain[TCP_HANDSHAKE_PLAIN_SIZE];
- crypto_box_keypair(handshake_plain, t_secret_key);
- memcpy(handshake_plain + crypto_box_PUBLICKEYBYTES, sec_c->sent_nonce, crypto_box_NONCEBYTES);
- uint8_t handshake[TCP_CLIENT_HANDSHAKE_SIZE];
- memcpy(handshake, sec_c->public_key, crypto_box_PUBLICKEYBYTES);
- new_nonce(handshake + crypto_box_PUBLICKEYBYTES);
-
- ret = encrypt_data(tcp_s->public_key, f_secret_key, handshake + crypto_box_PUBLICKEYBYTES, handshake_plain,
- TCP_HANDSHAKE_PLAIN_SIZE, handshake + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES);
- ck_assert_msg(ret == TCP_CLIENT_HANDSHAKE_SIZE - (crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES),
- "Encrypt failed.");
- ck_assert_msg(send(sock, handshake, TCP_CLIENT_HANDSHAKE_SIZE - 1, 0) == TCP_CLIENT_HANDSHAKE_SIZE - 1, "send Failed.");
- do_TCP_server(tcp_s);
- c_sleep(50);
- ck_assert_msg(send(sock, handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1), 1, 0) == 1, "send Failed.");
- c_sleep(50);
- do_TCP_server(tcp_s);
- uint8_t response[TCP_SERVER_HANDSHAKE_SIZE];
- uint8_t response_plain[TCP_HANDSHAKE_PLAIN_SIZE];
- ck_assert_msg(recv(sock, response, TCP_SERVER_HANDSHAKE_SIZE, 0) == TCP_SERVER_HANDSHAKE_SIZE, "recv Failed.");
- ret = decrypt_data(tcp_s->public_key, f_secret_key, response, response + crypto_box_NONCEBYTES,
- TCP_SERVER_HANDSHAKE_SIZE - crypto_box_NONCEBYTES, response_plain);
- ck_assert_msg(ret == TCP_HANDSHAKE_PLAIN_SIZE, "Decrypt Failed.");
- encrypt_precompute(response_plain, t_secret_key, sec_c->shared_key);
- memcpy(sec_c->recv_nonce, response_plain + crypto_box_BEFORENMBYTES, crypto_box_NONCEBYTES);
- sec_c->sock = sock;
- return sec_c;
-}
-
-int write_packet_TCP_secure_connection(struct sec_TCP_con *con, uint8_t *data, uint16_t length)
-{
- uint8_t packet[sizeof(uint16_t) + length + crypto_box_MACBYTES];
-
- uint16_t c_length = htons(length + crypto_box_MACBYTES);
- memcpy(packet, &c_length, sizeof(uint16_t));
- int len = encrypt_data_symmetric(con->shared_key, con->sent_nonce, data, length, packet + sizeof(uint16_t));
-
- if ((unsigned int)len != (sizeof(packet) - sizeof(uint16_t)))
- return -1;
-
- increment_nonce(con->sent_nonce);
-
- ck_assert_msg(send(con->sock, packet, sizeof(packet), 0) == sizeof(packet), "send failed");
- return 0;
-}
-
-int read_packet_sec_TCP(struct sec_TCP_con *con, uint8_t *data, uint16_t length)
-{
- int len;
- ck_assert_msg((len = recv(con->sock, data, length, 0)) == length, "wrong len %i\n", len);
- ck_assert_msg((len = decrypt_data_symmetric(con->shared_key, con->recv_nonce, data + 2, length - 2, data)) != -1,
- "Decrypt failed");
- increment_nonce(con->recv_nonce);
- return len;
-}
-
-START_TEST(test_some)
-{
- uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
- uint8_t self_secret_key[crypto_box_SECRETKEYBYTES];
- crypto_box_keypair(self_public_key, self_secret_key);
- TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_public_key, self_secret_key, NULL);
- ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server");
- ck_assert_msg(tcp_s->num_listening_socks == NUM_PORTS, "Failed to bind to all ports");
-
- struct sec_TCP_con *con1 = new_TCP_con(tcp_s);
- struct sec_TCP_con *con2 = new_TCP_con(tcp_s);
- struct sec_TCP_con *con3 = new_TCP_con(tcp_s);
-
- uint8_t requ_p[1 + crypto_box_PUBLICKEYBYTES];
- requ_p[0] = 0;
- memcpy(requ_p + 1, con3->public_key, crypto_box_PUBLICKEYBYTES);
- write_packet_TCP_secure_connection(con1, requ_p, sizeof(requ_p));
- memcpy(requ_p + 1, con1->public_key, crypto_box_PUBLICKEYBYTES);
- write_packet_TCP_secure_connection(con3, requ_p, sizeof(requ_p));
- do_TCP_server(tcp_s);
- c_sleep(50);
- uint8_t data[2048];
- int len = read_packet_sec_TCP(con1, data, 2 + 1 + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES);
- ck_assert_msg(len == 1 + 1 + crypto_box_PUBLICKEYBYTES, "wrong len %u", len);
- ck_assert_msg(data[0] == 1, "wrong packet id %u", data[0]);
- ck_assert_msg(data[1] == 16, "connection not refused %u", data[1]);
- ck_assert_msg(memcmp(data + 2, con3->public_key, crypto_box_PUBLICKEYBYTES) == 0, "key in packet wrong");
- len = read_packet_sec_TCP(con3, data, 2 + 1 + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES);
- ck_assert_msg(len == 1 + 1 + crypto_box_PUBLICKEYBYTES, "wrong len %u", len);
- ck_assert_msg(data[0] == 1, "wrong packet id %u", data[0]);
- ck_assert_msg(data[1] == 16, "connection not refused %u", data[1]);
- ck_assert_msg(memcmp(data + 2, con1->public_key, crypto_box_PUBLICKEYBYTES) == 0, "key in packet wrong");
-
- uint8_t test_packet[512] = {16, 17, 16, 86, 99, 127, 255, 189, 78};
- write_packet_TCP_secure_connection(con3, test_packet, sizeof(test_packet));
- write_packet_TCP_secure_connection(con3, test_packet, sizeof(test_packet));
- write_packet_TCP_secure_connection(con3, test_packet, sizeof(test_packet));
- c_sleep(50);
- do_TCP_server(tcp_s);
- c_sleep(50);
- len = read_packet_sec_TCP(con1, data, 2 + 2 + crypto_box_MACBYTES);
- ck_assert_msg(len == 2, "wrong len %u", len);
- ck_assert_msg(data[0] == 2, "wrong packet id %u", data[0]);
- ck_assert_msg(data[1] == 16, "wrong peer id %u", data[1]);
- len = read_packet_sec_TCP(con3, data, 2 + 2 + crypto_box_MACBYTES);
- ck_assert_msg(len == 2, "wrong len %u", len);
- ck_assert_msg(data[0] == 2, "wrong packet id %u", data[0]);
- ck_assert_msg(data[1] == 16, "wrong peer id %u", data[1]);
- len = read_packet_sec_TCP(con1, data, 2 + sizeof(test_packet) + crypto_box_MACBYTES);
- ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len);
- ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
- data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
- len = read_packet_sec_TCP(con1, data, 2 + sizeof(test_packet) + crypto_box_MACBYTES);
- ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len);
- ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
- data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
- len = read_packet_sec_TCP(con1, data, 2 + sizeof(test_packet) + crypto_box_MACBYTES);
- ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len);
- ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
- data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
- write_packet_TCP_secure_connection(con1, test_packet, sizeof(test_packet));
- write_packet_TCP_secure_connection(con1, test_packet, sizeof(test_packet));
- write_packet_TCP_secure_connection(con1, test_packet, sizeof(test_packet));
- c_sleep(50);
- do_TCP_server(tcp_s);
- c_sleep(50);
- len = read_packet_sec_TCP(con3, data, 2 + sizeof(test_packet) + crypto_box_MACBYTES);
- ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len);
- ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
- data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
- len = read_packet_sec_TCP(con3, data, 2 + sizeof(test_packet) + crypto_box_MACBYTES);
- ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len);
- ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
- data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
- len = read_packet_sec_TCP(con3, data, 2 + sizeof(test_packet) + crypto_box_MACBYTES);
- ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len);
- ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
- data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
-
- uint8_t ping_packet[1 + sizeof(uint64_t)] = {4, 8, 6, 9, 67};
- write_packet_TCP_secure_connection(con1, ping_packet, sizeof(ping_packet));
- c_sleep(50);
- do_TCP_server(tcp_s);
- c_sleep(50);
- len = read_packet_sec_TCP(con1, data, 2 + sizeof(ping_packet) + crypto_box_MACBYTES);
- ck_assert_msg(len == sizeof(ping_packet), "wrong len %u", len);
- ck_assert_msg(data[0] == 5, "wrong packet id %u", data[0]);
- ck_assert_msg(memcmp(ping_packet + 1, data + 1, sizeof(uint64_t)) == 0, "wrong packet data");
-}
-END_TEST
-
-static int response_callback_good;
-static uint8_t response_callback_connection_id;
-static uint8_t response_callback_public_key[crypto_box_PUBLICKEYBYTES];
-static int response_callback(void *object, uint8_t connection_id, const uint8_t *public_key)
-{
- if (set_tcp_connection_number(object - 2, connection_id, 7) != 0)
- return 1;
-
- response_callback_connection_id = connection_id;
- memcpy(response_callback_public_key, public_key, crypto_box_PUBLICKEYBYTES);
- response_callback_good++;
- return 0;
-}
-static int status_callback_good;
-static uint8_t status_callback_connection_id;
-static uint8_t status_callback_status;
-static int status_callback(void *object, uint32_t number, uint8_t connection_id, uint8_t status)
-{
- if (object != (void *)2)
- return 1;
-
- if (number != 7)
- return 1;
-
- status_callback_connection_id = connection_id;
- status_callback_status = status;
- status_callback_good++;
- return 0;
-}
-static int data_callback_good;
-static int data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length)
-{
- if (object != (void *)3)
- return 1;
-
- if (number != 7)
- return 1;
-
- if (length != 5)
- return 1;
-
- if (data[0] == 1 && data[1] == 2 && data[2] == 3 && data[3] == 4 && data[4] == 5) {
- data_callback_good++;
- return 0;
- }
-
- return 1;
-}
-
-static int oob_data_callback_good;
-static uint8_t oob_pubkey[crypto_box_PUBLICKEYBYTES];
-static int oob_data_callback(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length)
-{
- if (object != (void *)4)
- return 1;
-
- if (length != 5)
- return 1;
-
- if (memcmp(public_key, oob_pubkey, crypto_box_PUBLICKEYBYTES) != 0)
- return 1;
-
- if (data[0] == 1 && data[1] == 2 && data[2] == 3 && data[3] == 4 && data[4] == 5) {
- oob_data_callback_good++;
- return 0;
- }
-
- return 1;
-}
-
-START_TEST(test_client)
-{
- unix_time_update();
- uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
- uint8_t self_secret_key[crypto_box_SECRETKEYBYTES];
- crypto_box_keypair(self_public_key, self_secret_key);
- TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_public_key, self_secret_key, NULL);
- ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server");
- ck_assert_msg(tcp_s->num_listening_socks == NUM_PORTS, "Failed to bind to all ports");
-
- uint8_t f_public_key[crypto_box_PUBLICKEYBYTES];
- uint8_t f_secret_key[crypto_box_SECRETKEYBYTES];
- crypto_box_keypair(f_public_key, f_secret_key);
- IP_Port ip_port_tcp_s;
-
- ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]);
- ip_port_tcp_s.ip.family = AF_INET6;
- ip_port_tcp_s.ip.ip6.in6_addr = in6addr_loopback;
- TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key);
- c_sleep(50);
- do_TCP_connection(conn);
- ck_assert_msg(conn->status == TCP_CLIENT_UNCONFIRMED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_UNCONFIRMED,
- conn->status);
- c_sleep(50);
- do_TCP_server(tcp_s);
- c_sleep(50);
- do_TCP_connection(conn);
- ck_assert_msg(conn->status == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONFIRMED,
- conn->status);
- c_sleep(500);
- do_TCP_connection(conn);
- ck_assert_msg(conn->status == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONFIRMED,
- conn->status);
- c_sleep(500);
- do_TCP_connection(conn);
- ck_assert_msg(conn->status == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONFIRMED,
- conn->status);
- do_TCP_server(tcp_s);
- c_sleep(50);
- ck_assert_msg(conn->status == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONFIRMED,
- conn->status);
-
- uint8_t f2_public_key[crypto_box_PUBLICKEYBYTES];
- uint8_t f2_secret_key[crypto_box_SECRETKEYBYTES];
- crypto_box_keypair(f2_public_key, f2_secret_key);
- TCP_Client_Connection *conn2 = new_TCP_connection(ip_port_tcp_s, self_public_key, f2_public_key, f2_secret_key);
- routing_response_handler(conn, response_callback, ((void *)conn) + 2);
- routing_status_handler(conn, status_callback, (void *)2);
- routing_data_handler(conn, data_callback, (void *)3);
- oob_data_handler(conn, oob_data_callback, (void *)4);
- oob_data_callback_good = response_callback_good = status_callback_good = data_callback_good = 0;
- c_sleep(50);
- do_TCP_connection(conn);
- do_TCP_connection(conn2);
- c_sleep(50);
- do_TCP_server(tcp_s);
- c_sleep(50);
- do_TCP_connection(conn);
- do_TCP_connection(conn2);
- c_sleep(50);
- uint8_t data[5] = {1, 2, 3, 4, 5};
- memcpy(oob_pubkey, f2_public_key, crypto_box_PUBLICKEYBYTES);
- send_oob_packet(conn2, f_public_key, data, 5);
- send_routing_request(conn, f2_public_key);
- send_routing_request(conn2, f_public_key);
- c_sleep(50);
- do_TCP_server(tcp_s);
- c_sleep(50);
- do_TCP_connection(conn);
- do_TCP_connection(conn2);
- ck_assert_msg(oob_data_callback_good == 1, "oob callback not called");
- ck_assert_msg(response_callback_good == 1, "response callback not called");
- ck_assert_msg(memcmp(response_callback_public_key, f2_public_key, crypto_box_PUBLICKEYBYTES) == 0, "wrong public key");
- ck_assert_msg(status_callback_good == 1, "status callback not called");
- ck_assert_msg(status_callback_status == 2, "wrong status");
- ck_assert_msg(status_callback_connection_id == response_callback_connection_id, "connection ids not equal");
- c_sleep(50);
- do_TCP_server(tcp_s);
- ck_assert_msg(send_data(conn2, 0, data, 5) == 1, "send data failed");
- c_sleep(50);
- do_TCP_server(tcp_s);
- c_sleep(50);
- do_TCP_connection(conn);
- do_TCP_connection(conn2);
- ck_assert_msg(data_callback_good == 1, "data callback not called");
- status_callback_good = 0;
- send_disconnect_request(conn2, 0);
- c_sleep(50);
- do_TCP_server(tcp_s);
- c_sleep(50);
- do_TCP_connection(conn);
- do_TCP_connection(conn2);
- ck_assert_msg(status_callback_good == 1, "status callback not called");
- ck_assert_msg(status_callback_status == 1, "wrong status");
-}
-END_TEST
-
-START_TEST(test_client_invalid)
-{
- unix_time_update();
- uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
- uint8_t self_secret_key[crypto_box_SECRETKEYBYTES];
- crypto_box_keypair(self_public_key, self_secret_key);
-
- uint8_t f_public_key[crypto_box_PUBLICKEYBYTES];
- uint8_t f_secret_key[crypto_box_SECRETKEYBYTES];
- crypto_box_keypair(f_public_key, f_secret_key);
- IP_Port ip_port_tcp_s;
-
- ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]);
- ip_port_tcp_s.ip.family = AF_INET6;
- ip_port_tcp_s.ip.ip6.in6_addr = in6addr_loopback;
- TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key);
- c_sleep(50);
- do_TCP_connection(conn);
- ck_assert_msg(conn->status == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONNECTING,
- conn->status);
- c_sleep(5000);
- do_TCP_connection(conn);
- ck_assert_msg(conn->status == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONNECTING,
- conn->status);
- c_sleep(6000);
- do_TCP_connection(conn);
- ck_assert_msg(conn->status == TCP_CLIENT_DISCONNECTED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_DISCONNECTED,
- conn->status);
-}
-END_TEST
-
-#define DEFTESTCASE(NAME) \
- TCase *tc_##NAME = tcase_create(#NAME); \
- tcase_add_test(tc_##NAME, test_##NAME); \
- suite_add_tcase(s, tc_##NAME);
-
-#define DEFTESTCASE_SLOW(NAME, TIMEOUT) \
- DEFTESTCASE(NAME) \
- tcase_set_timeout(tc_##NAME, TIMEOUT);
-Suite *TCP_suite(void)
-{
- Suite *s = suite_create("TCP");
-
- DEFTESTCASE_SLOW(basic, 5);
- DEFTESTCASE_SLOW(some, 10);
- DEFTESTCASE_SLOW(client, 10);
- DEFTESTCASE_SLOW(client_invalid, 15);
- return s;
-}
-
-int main(int argc, char *argv[])
-{
- srand((unsigned int) time(NULL));
-
- Suite *TCP = TCP_suite();
- SRunner *test_runner = srunner_create(TCP);
-
- int number_failed = 0;
- srunner_run_all(test_runner, CK_NORMAL);
- number_failed = srunner_ntests_failed(test_runner);
-
- srunner_free(test_runner);
-
- return number_failed;
-}
diff --git a/protocols/Tox/toxcore/auto_tests/assoc_test.c b/protocols/Tox/toxcore/auto_tests/assoc_test.c
deleted file mode 100644
index 5f496ececb..0000000000
--- a/protocols/Tox/toxcore/auto_tests/assoc_test.c
+++ /dev/null
@@ -1,168 +0,0 @@
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#define AUTO_TEST
-#include "../toxcore/DHT.h"
-#include "../toxcore/assoc.h"
-#include "../toxcore/util.h"
-
-#include <sys/types.h>
-#include <stdint.h>
-#include <string.h>
-
-#include <check.h>
-
-START_TEST(test_basics)
-{
- /* TODO: real test */
- uint8_t id[CLIENT_ID_SIZE];
- Assoc *assoc = new_Assoc_default(id);
- ck_assert_msg(assoc != NULL, "failed to create default assoc");
-
- kill_Assoc(assoc);
- assoc = new_Assoc(17, 4, id); /* results in an assoc of 16/3 */
- ck_assert_msg(assoc != NULL, "failed to create customized assoc");
-
- IP_Port ipp;
- ipp.ip.family = AF_INET;
- ipp.ip.ip4.uint8[0] = 1;
- ipp.port = htons(12345);
-
- IPPTs ippts_send;
- ippts_send.ip_port = ipp;
- ippts_send.timestamp = unix_time();
- IP_Port ipp_recv = ipp;
-
- uint8_t res = Assoc_add_entry(assoc, id, &ippts_send, &ipp_recv, 0);
- ck_assert_msg(res == 0, "stored self as entry: expected %u, got %u", 0, res);
-
- id[0]++;
-
- res = Assoc_add_entry(assoc, id, &ippts_send, &ipp_recv, 0);
- ck_assert_msg(res == 1, "failed to store entry: expected %u, got %u", 1, res);
-
- Assoc_close_entries close_entries;
- memset(&close_entries, 0, sizeof(close_entries));
- close_entries.count = 4;
- close_entries.count_good = 2;
- close_entries.wanted_id = id;
-
- Client_data *entries[close_entries.count];
- close_entries.result = entries;
-
- uint8_t found = Assoc_get_close_entries(assoc, &close_entries);
- ck_assert_msg(found == 1, "get_close_entries(): expected %u, got %u", 1, found);
-}
-END_TEST
-
-START_TEST(test_fillup)
-{
- /* TODO: real test */
- int i, j;
- uint8_t id[CLIENT_ID_SIZE];
- //uint32_t a = current_time();
- uint32_t a = 2710106197;
- srand(a);
-
- for (i = 0; i < CLIENT_ID_SIZE; ++i) {
- id[i] = rand();
- }
-
- Assoc *assoc = new_Assoc(6, 15, id);
- ck_assert_msg(assoc != NULL, "failed to create default assoc");
- struct entry {
- uint8_t id[CLIENT_ID_SIZE];
- IPPTs ippts_send;
- IP_Port ipp_recv;
- };
- unsigned int fail = 0;
- struct entry entries[128];
- struct entry closest[8];
-
- for (j = 0; j < 128; ++j) {
-
- for (i = 0; i < CLIENT_ID_SIZE; ++i) {
- entries[j].id[i] = rand();
- }
-
- IP_Port ipp;
- ipp.ip.family = AF_INET;
- ipp.ip.ip4.uint32 = rand();
- ipp.port = rand();
- entries[j].ippts_send.ip_port = ipp;
- entries[j].ippts_send.timestamp = unix_time();
- ipp.ip.ip4.uint32 = rand();
- ipp.port = rand();
- entries[j].ipp_recv = ipp;
-
- if (j % 16 == 0) {
- memcpy(entries[j].id, id, CLIENT_ID_SIZE - 30);
- memcpy(&closest[j / 16], &entries[j], sizeof(struct entry));
-
- }
-
- uint8_t res = Assoc_add_entry(assoc, entries[j].id, &entries[j].ippts_send, &entries[j].ipp_recv, 1);
- ck_assert_msg(res == 1, "failed to store entry: expected %u, got %u, j = %u", 1, res, j);
- }
-
- int good = 0;
- Assoc_close_entries close_entries;
- memset(&close_entries, 0, sizeof(close_entries));
- close_entries.count = 8;
- close_entries.count_good = 8;
- close_entries.wanted_id = id;
-
- Client_data *entri[close_entries.count];
- close_entries.result = entri;
-
- uint8_t found = Assoc_get_close_entries(assoc, &close_entries);
- ck_assert_msg(found == 8, "get_close_entries(): expected %u, got %u", 1, found);
-
- for (i = 0; i < 8; ++i) {
- for (j = 0; j < 8; ++j) {
- if (id_equal(entri[j]->client_id, closest[i].id))
- ++good;
- }
- }
-
- ck_assert_msg(good == 8, "Entries found were not the closest ones. Only %u/8 were.", good);
- //printf("good: %u %u %u\n", good, a, ((uint32_t)current_time() - a));
-}
-END_TEST
-
-#define DEFTESTCASE(NAME) \
- TCase *tc_##NAME = tcase_create(#NAME); \
- tcase_add_test(tc_##NAME, test_##NAME); \
- suite_add_tcase(s, tc_##NAME);
-
-#define DEFTESTCASE_SLOW(NAME, TIMEOUT) \
- DEFTESTCASE(NAME) \
- tcase_set_timeout(tc_##NAME, TIMEOUT);
-
-Suite *Assoc_suite(void)
-{
- Suite *s = suite_create("Assoc");
-
- DEFTESTCASE(basics);
- DEFTESTCASE(fillup);
- return s;
-}
-
-int main(int argc, char *argv[])
-{
- unix_time_update();
- Suite *Assoc = Assoc_suite();
- SRunner *test_runner = srunner_create(Assoc);
-
- srunner_set_fork_status(test_runner, CK_NOFORK);
-
- srunner_run_all(test_runner, CK_NORMAL);
-
- int number_failed = srunner_ntests_failed(test_runner);
-
- srunner_free(test_runner);
-
- return number_failed;
-}
diff --git a/protocols/Tox/toxcore/auto_tests/crypto_test.c b/protocols/Tox/toxcore/auto_tests/crypto_test.c
deleted file mode 100644
index 252f727591..0000000000
--- a/protocols/Tox/toxcore/auto_tests/crypto_test.c
+++ /dev/null
@@ -1,310 +0,0 @@
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "../toxcore/net_crypto.h"
-#include <sys/types.h>
-#include <stdint.h>
-#include <string.h>
-#include <check.h>
-#include <stdlib.h>
-#include <time.h>
-
-void rand_bytes(uint8_t *b, size_t blen)
-{
- size_t i;
-
- for (i = 0; i < blen; i++) {
- b[i] = rand();
- }
-}
-
-// These test vectors are from libsodium's test suite
-
-unsigned char alicesk[32] = {
- 0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d,
- 0x3c, 0x16, 0xc1, 0x72, 0x51, 0xb2, 0x66, 0x45,
- 0xdf, 0x4c, 0x2f, 0x87, 0xeb, 0xc0, 0x99, 0x2a,
- 0xb1, 0x77, 0xfb, 0xa5, 0x1d, 0xb9, 0x2c, 0x2a
-};
-
-unsigned char bobpk[32] = {
- 0xde, 0x9e, 0xdb, 0x7d, 0x7b, 0x7d, 0xc1, 0xb4,
- 0xd3, 0x5b, 0x61, 0xc2, 0xec, 0xe4, 0x35, 0x37,
- 0x3f, 0x83, 0x43, 0xc8, 0x5b, 0x78, 0x67, 0x4d,
- 0xad, 0xfc, 0x7e, 0x14, 0x6f, 0x88, 0x2b, 0x4f
-};
-
-unsigned char nonce[24] = {
- 0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6, 0x2b, 0x73,
- 0xcd, 0x62, 0xbd, 0xa8, 0x75, 0xfc, 0x73, 0xd6,
- 0x82, 0x19, 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37
-};
-
-unsigned char test_m[131] = {
- 0xbe, 0x07, 0x5f, 0xc5, 0x3c, 0x81, 0xf2, 0xd5,
- 0xcf, 0x14, 0x13, 0x16, 0xeb, 0xeb, 0x0c, 0x7b,
- 0x52, 0x28, 0xc5, 0x2a, 0x4c, 0x62, 0xcb, 0xd4,
- 0x4b, 0x66, 0x84, 0x9b, 0x64, 0x24, 0x4f, 0xfc,
- 0xe5, 0xec, 0xba, 0xaf, 0x33, 0xbd, 0x75, 0x1a,
- 0x1a, 0xc7, 0x28, 0xd4, 0x5e, 0x6c, 0x61, 0x29,
- 0x6c, 0xdc, 0x3c, 0x01, 0x23, 0x35, 0x61, 0xf4,
- 0x1d, 0xb6, 0x6c, 0xce, 0x31, 0x4a, 0xdb, 0x31,
- 0x0e, 0x3b, 0xe8, 0x25, 0x0c, 0x46, 0xf0, 0x6d,
- 0xce, 0xea, 0x3a, 0x7f, 0xa1, 0x34, 0x80, 0x57,
- 0xe2, 0xf6, 0x55, 0x6a, 0xd6, 0xb1, 0x31, 0x8a,
- 0x02, 0x4a, 0x83, 0x8f, 0x21, 0xaf, 0x1f, 0xde,
- 0x04, 0x89, 0x77, 0xeb, 0x48, 0xf5, 0x9f, 0xfd,
- 0x49, 0x24, 0xca, 0x1c, 0x60, 0x90, 0x2e, 0x52,
- 0xf0, 0xa0, 0x89, 0xbc, 0x76, 0x89, 0x70, 0x40,
- 0xe0, 0x82, 0xf9, 0x37, 0x76, 0x38, 0x48, 0x64,
- 0x5e, 0x07, 0x05
-};
-
-unsigned char test_c[147] = {
- 0xf3, 0xff, 0xc7, 0x70, 0x3f, 0x94, 0x00, 0xe5,
- 0x2a, 0x7d, 0xfb, 0x4b, 0x3d, 0x33, 0x05, 0xd9,
- 0x8e, 0x99, 0x3b, 0x9f, 0x48, 0x68, 0x12, 0x73,
- 0xc2, 0x96, 0x50, 0xba, 0x32, 0xfc, 0x76, 0xce,
- 0x48, 0x33, 0x2e, 0xa7, 0x16, 0x4d, 0x96, 0xa4,
- 0x47, 0x6f, 0xb8, 0xc5, 0x31, 0xa1, 0x18, 0x6a,
- 0xc0, 0xdf, 0xc1, 0x7c, 0x98, 0xdc, 0xe8, 0x7b,
- 0x4d, 0xa7, 0xf0, 0x11, 0xec, 0x48, 0xc9, 0x72,
- 0x71, 0xd2, 0xc2, 0x0f, 0x9b, 0x92, 0x8f, 0xe2,
- 0x27, 0x0d, 0x6f, 0xb8, 0x63, 0xd5, 0x17, 0x38,
- 0xb4, 0x8e, 0xee, 0xe3, 0x14, 0xa7, 0xcc, 0x8a,
- 0xb9, 0x32, 0x16, 0x45, 0x48, 0xe5, 0x26, 0xae,
- 0x90, 0x22, 0x43, 0x68, 0x51, 0x7a, 0xcf, 0xea,
- 0xbd, 0x6b, 0xb3, 0x73, 0x2b, 0xc0, 0xe9, 0xda,
- 0x99, 0x83, 0x2b, 0x61, 0xca, 0x01, 0xb6, 0xde,
- 0x56, 0x24, 0x4a, 0x9e, 0x88, 0xd5, 0xf9, 0xb3,
- 0x79, 0x73, 0xf6, 0x22, 0xa4, 0x3d, 0x14, 0xa6,
- 0x59, 0x9b, 0x1f, 0x65, 0x4c, 0xb4, 0x5a, 0x74,
- 0xe3, 0x55, 0xa5
-};
-
-START_TEST(test_known)
-{
- unsigned char c[147];
- unsigned char m[131];
- int clen, mlen;
-
- ck_assert_msg(sizeof(c) == sizeof(m) + crypto_box_MACBYTES * sizeof(unsigned char),
- "cyphertext should be crypto_box_MACBYTES bytes longer than plaintext");
- ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed");
- ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed");
-
- clen = encrypt_data(bobpk, alicesk, nonce, test_m, sizeof(test_m) / sizeof(unsigned char), c);
-
- ck_assert_msg(memcmp(test_c, c, sizeof(c)) == 0, "cyphertext doesn't match test vector");
- ck_assert_msg(clen == sizeof(c) / sizeof(unsigned char), "wrong ciphertext length");
-
- mlen = decrypt_data(bobpk, alicesk, nonce, test_c, sizeof(test_c) / sizeof(unsigned char), m);
-
- ck_assert_msg(memcmp(test_m, m, sizeof(m)) == 0, "decrypted text doesn't match test vector");
- ck_assert_msg(mlen == sizeof(m) / sizeof(unsigned char), "wrong plaintext length");
-}
-END_TEST
-
-START_TEST(test_fast_known)
-{
- unsigned char k[crypto_box_BEFORENMBYTES];
- unsigned char c[147];
- unsigned char m[131];
- int clen, mlen;
-
- encrypt_precompute(bobpk, alicesk, k);
-
- ck_assert_msg(sizeof(c) == sizeof(m) + crypto_box_MACBYTES * sizeof(unsigned char),
- "cyphertext should be crypto_box_MACBYTES bytes longer than plaintext");
- ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed");
- ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed");
-
- clen = encrypt_data_symmetric(k, nonce, test_m, sizeof(test_m) / sizeof(unsigned char), c);
-
- ck_assert_msg(memcmp(test_c, c, sizeof(c)) == 0, "cyphertext doesn't match test vector");
- ck_assert_msg(clen == sizeof(c) / sizeof(unsigned char), "wrong ciphertext length");
-
- mlen = decrypt_data_symmetric(k, nonce, test_c, sizeof(test_c) / sizeof(unsigned char), m);
-
- ck_assert_msg(memcmp(test_m, m, sizeof(m)) == 0, "decrypted text doesn't match test vector");
- ck_assert_msg(mlen == sizeof(m) / sizeof(unsigned char), "wrong plaintext length");
-
-}
-END_TEST
-
-START_TEST(test_endtoend)
-{
- unsigned char pk1[crypto_box_PUBLICKEYBYTES];
- unsigned char sk1[crypto_box_SECRETKEYBYTES];
- unsigned char pk2[crypto_box_PUBLICKEYBYTES];
- unsigned char sk2[crypto_box_SECRETKEYBYTES];
- unsigned char k1[crypto_box_BEFORENMBYTES];
- unsigned char k2[crypto_box_BEFORENMBYTES];
-
- unsigned char n[crypto_box_NONCEBYTES];
-
- unsigned char m[500];
- unsigned char c1[sizeof(m) + crypto_box_MACBYTES];
- unsigned char c2[sizeof(m) + crypto_box_MACBYTES];
- unsigned char c3[sizeof(m) + crypto_box_MACBYTES];
- unsigned char c4[sizeof(m) + crypto_box_MACBYTES];
- unsigned char m1[sizeof(m)];
- unsigned char m2[sizeof(m)];
- unsigned char m3[sizeof(m)];
- unsigned char m4[sizeof(m)];
-
- int mlen;
- int c1len, c2len, c3len, c4len;
- int m1len, m2len, m3len, m4len;
-
- int testno;
-
- // Test 100 random messages and keypairs
- for (testno = 0; testno < 100; testno++) {
- //Generate random message (random length from 100 to 500)
- mlen = (rand() % 400) + 100;
- rand_bytes(m, mlen);
- rand_bytes(n, crypto_box_NONCEBYTES);
-
- //Generate keypairs
- crypto_box_keypair(pk1, sk1);
- crypto_box_keypair(pk2, sk2);
-
- //Precompute shared keys
- encrypt_precompute(pk2, sk1, k1);
- encrypt_precompute(pk1, sk2, k2);
-
- ck_assert_msg(memcmp(k1, k2, crypto_box_BEFORENMBYTES) == 0, "encrypt_precompute: bad");
-
- //Encrypt all four ways
- c1len = encrypt_data(pk2, sk1, n, m, mlen, c1);
- c2len = encrypt_data(pk1, sk2, n, m, mlen, c2);
- c3len = encrypt_data_symmetric(k1, n, m, mlen, c3);
- c4len = encrypt_data_symmetric(k2, n, m, mlen, c4);
-
- ck_assert_msg(c1len == c2len && c1len == c3len && c1len == c4len, "cyphertext lengths differ");
- ck_assert_msg(c1len == mlen + (int)crypto_box_MACBYTES, "wrong cyphertext length");
- ck_assert_msg(memcmp(c1, c2, c1len) == 0 && memcmp(c1, c3, c1len) == 0
- && memcmp(c1, c4, c1len) == 0, "crypertexts differ");
-
- //Decrypt all four ways
- m1len = decrypt_data(pk2, sk1, n, c1, c1len, m1);
- m2len = decrypt_data(pk1, sk2, n, c1, c1len, m2);
- m3len = decrypt_data_symmetric(k1, n, c1, c1len, m3);
- m4len = decrypt_data_symmetric(k2, n, c1, c1len, m4);
-
- ck_assert_msg(m1len == m2len && m1len == m3len && m1len == m4len, "decrypted text lengths differ");
- ck_assert_msg(m1len == mlen, "wrong decrypted text length");
- ck_assert_msg(memcmp(m1, m2, mlen) == 0 && memcmp(m1, m3, mlen) == 0
- && memcmp(m1, m4, mlen) == 0, "decrypted texts differ");
- ck_assert_msg(memcmp(m1, m, mlen) == 0, "wrong decrypted text");
- }
-}
-END_TEST
-
-START_TEST(test_large_data)
-{
- unsigned char k[crypto_box_BEFORENMBYTES];
-
- unsigned char n[crypto_box_NONCEBYTES];
-
- unsigned char m1[MAX_CRYPTO_PACKET_SIZE - crypto_box_MACBYTES];
- unsigned char c1[sizeof(m1) + crypto_box_MACBYTES];
- unsigned char m1prime[sizeof(m1)];
-
- unsigned char m2[MAX_CRYPTO_PACKET_SIZE];
- unsigned char c2[sizeof(m2) + crypto_box_MACBYTES];
-
- int c1len, c2len;
- int m1plen;
-
- //Generate random messages
- rand_bytes(m1, sizeof(m1));
- rand_bytes(m2, sizeof(m2));
- rand_bytes(n, crypto_box_NONCEBYTES);
-
- //Generate key
- rand_bytes(k, crypto_box_BEFORENMBYTES);
-
- c1len = encrypt_data_symmetric(k, n, m1, sizeof(m1), c1);
- c2len = encrypt_data_symmetric(k, n, m2, sizeof(m2), c2);
-
- ck_assert_msg(c1len == sizeof(m1) + crypto_box_MACBYTES, "could not encrypt");
- ck_assert_msg(c2len == sizeof(m2) + crypto_box_MACBYTES, "could not encrypt");
-
- m1plen = decrypt_data_symmetric(k, n, c1, c1len, m1prime);
-
- ck_assert_msg(m1plen == sizeof(m1), "decrypted text lengths differ");
- ck_assert_msg(memcmp(m1prime, m1, sizeof(m1)) == 0, "decrypted texts differ");
-}
-END_TEST
-
-START_TEST(test_large_data_symmetric)
-{
- unsigned char k[crypto_box_KEYBYTES];
-
- unsigned char n[crypto_box_NONCEBYTES];
-
- unsigned char m1[16 * 16 * 16];
- unsigned char c1[sizeof(m1) + crypto_box_MACBYTES];
- unsigned char m1prime[sizeof(m1)];
-
- int c1len;
- int m1plen;
-
- //Generate random messages
- rand_bytes(m1, sizeof(m1));
- rand_bytes(n, crypto_box_NONCEBYTES);
-
- //Generate key
- new_symmetric_key(k);
-
- c1len = encrypt_data_symmetric(k, n, m1, sizeof(m1), c1);
- ck_assert_msg(c1len == sizeof(m1) + crypto_box_MACBYTES, "could not encrypt data");
-
- m1plen = decrypt_data_symmetric(k, n, c1, c1len, m1prime);
-
- ck_assert_msg(m1plen == sizeof(m1), "decrypted text lengths differ");
- ck_assert_msg(memcmp(m1prime, m1, sizeof(m1)) == 0, "decrypted texts differ");
-}
-END_TEST
-
-
-#define DEFTESTCASE(NAME) \
- TCase *NAME = tcase_create(#NAME); \
- tcase_add_test(NAME, test_##NAME); \
- suite_add_tcase(s, NAME);
-
-#define DEFTESTCASE_SLOW(NAME, TIMEOUT) \
- DEFTESTCASE(NAME) \
- tcase_set_timeout(NAME, TIMEOUT);
-
-Suite *crypto_suite(void)
-{
- Suite *s = suite_create("Crypto");
-
- DEFTESTCASE(known);
- DEFTESTCASE(fast_known);
- DEFTESTCASE_SLOW(endtoend, 15); /* waiting up to 15 seconds */
- DEFTESTCASE(large_data);
- DEFTESTCASE(large_data_symmetric);
-
- return s;
-}
-
-int main(int argc, char *argv[])
-{
- srand((unsigned int) time(NULL));
-
- Suite *crypto = crypto_suite();
- SRunner *test_runner = srunner_create(crypto);
- int number_failed = 0;
-
- srunner_run_all(test_runner, CK_NORMAL);
- number_failed = srunner_ntests_failed(test_runner);
-
- srunner_free(test_runner);
-
- return number_failed;
-}
diff --git a/protocols/Tox/toxcore/auto_tests/friends_test.c b/protocols/Tox/toxcore/auto_tests/friends_test.c
deleted file mode 100644
index 2448f97c34..0000000000
--- a/protocols/Tox/toxcore/auto_tests/friends_test.c
+++ /dev/null
@@ -1,238 +0,0 @@
-/* Unit testing for friend requests, statuses, and messages.
- * Purpose: Check that messaging functions actually do what
- * they're supposed to by setting up two local clients.
- *
- * Design: (Subject to change.)
- * 1. Parent sends a friend request, and waits for a response.
- * It it doesn't get one, it kills the child.
- * 2. Child gets friend request, accepts, then waits for a status change.
- * 3. The parent waits on a status change, killing the child if it takes
- * too long.
- * 4. The child gets the status change, then sends a message. After that,
- * it returns. If if doesn't get the status change, it just loops forever.
- * 5. After getting the status change, the parent waits for a message, on getting
- * one, it waits on the child to return, then returns 0.
- *
- * Note about "waiting":
- * Wait time is decided by WAIT_COUNT and WAIT_TIME. c_sleep(WAIT_TIME) WAIT_COUNT
- * times. This is used both to ensure that we don't loop forever on a broken build,
- * and that we don't get too slow with messaging. The current time is 15 seconds. */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "../toxcore/friend_requests.h"
-#include "../toxcore/Messenger.h"
-#include <assert.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <signal.h>
-#include <sys/wait.h>
-
-#define WAIT_COUNT 30
-#define WAIT_TIME 500
-
-#ifndef MAP_ANONYMOUS
-#define MAP_ANONYMOUS MAP_ANON
-#endif
-
-/* first step, second step */
-#define FIRST_FLAG 0x1
-#define SECOND_FLAG 0x2
-
-/* ensure that we sleep in milliseconds */
-#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
-#define c_sleep(x) Sleep(x)
-#else
-#define c_sleep(x) usleep(1000*x)
-#endif
-
-#define PORT 33445
-
-static Messenger *m;
-
-uint8_t *parent_id = NULL;
-uint8_t *child_id = NULL;
-
-pid_t child_pid = 0;
-int request_flags = 0;
-
-void do_tox(DHT *dht)
-{
- static int dht_on = 0;
-
- if (!dht_on && DHT_isconnected(dht)) {
- dht_on = 1;
- } else if (dht_on && !DHT_isconnected(dht)) {
- dht_on = 0;
- }
-
- doMessenger(m);
-}
-
-void parent_confirm_message(Messenger *m, int num, uint8_t *data, uint16_t length, void *userdata)
-{
- puts("OK");
- request_flags |= SECOND_FLAG;
-}
-
-void parent_confirm_status(Messenger *m, int num, uint8_t *data, uint16_t length, void *userdata)
-{
- puts("OK");
- request_flags |= FIRST_FLAG;
-}
-
-int parent_friend_request(DHT *dht)
-{
- char *message = "Watson, come here, I need you.";
- int len = strlen(message);
- int i = 0;
-
- fputs("Sending child request.", stdout);
- fflush(stdout);
-
- m_addfriend(m, child_id, (uint8_t *)message, len);
-
- /* wait on the status change */
- for (i = 0; i < WAIT_COUNT; i++) {
- do_tox(dht);
-
- if (request_flags & FIRST_FLAG)
- break;
-
- fputs(".", stdout);
- fflush(stdout);
- c_sleep(WAIT_TIME);
- }
-
- if (!(request_flags & FIRST_FLAG)) {
- fputs("\nfriends_test: The child took to long to respond!\n"
- "Friend requests may be broken, failing build!\n", stderr);
- kill(child_pid, SIGKILL);
- return -1;
- }
-
- return 0;
-}
-
-void child_got_request(Messenger *m, uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
-{
- fputs("OK\nsending status to parent", stdout);
- fflush(stdout);
- m_addfriend_norequest(m, public_key);
- request_flags |= FIRST_FLAG;
-}
-
-void child_got_statuschange(Messenger *m, int friend_num, uint8_t *string, uint16_t length, void *userdata)
-{
- request_flags |= SECOND_FLAG;
-}
-
-int parent_wait_for_message(DHT *dht)
-{
- int i = 0;
-
- fputs("Parent waiting for message.", stdout);
- fflush(stdout);
-
- for (i = 0; i < WAIT_COUNT; i++) {
- do_tox(dht);
-
- if (request_flags & SECOND_FLAG)
- break;
-
- fputs(".", stdout);
- fflush(stdout);
- c_sleep(WAIT_TIME);
- }
-
- if (!(request_flags & SECOND_FLAG)) {
- fputs("\nParent hasn't received the message yet!\n"
- "Messaging may be broken, failing the build!\n", stderr);
- kill(child_pid, SIGKILL);
- return -1;
- }
-
- return 0;
-}
-
-void cleanup(void)
-{
- munmap(parent_id, crypto_box_PUBLICKEYBYTES);
- munmap(child_id, crypto_box_PUBLICKEYBYTES);
- puts("============= END TEST =============");
-}
-
-int main(int argc, char *argv[])
-{
- puts("=========== FRIENDS_TEST ===========");
-
- /* set up the global memory */
- parent_id = mmap(NULL, crypto_box_PUBLICKEYBYTES, PROT_READ | PROT_WRITE,
- MAP_SHARED | MAP_ANONYMOUS, -1, 0);
- child_id = mmap(NULL, crypto_box_PUBLICKEYBYTES, PROT_READ | PROT_WRITE,
- MAP_SHARED | MAP_ANONYMOUS, -1, 0);
-
- fputs("friends_test: Starting test...\n", stdout);
-
- if ((child_pid = fork()) == 0) {
- /* child */
- int i = 0;
- char *message = "Y-yes Mr. Watson?";
-
- m = initMessenger();
-
- Messenger_save(m, child_id);
- msync(child_id, crypto_box_PUBLICKEYBYTES, MS_SYNC);
-
- m_callback_friendrequest(m, child_got_request, NULL);
- m_callback_statusmessage(m, child_got_statuschange, NULL);
-
- /* wait on the friend request */
- while (!(request_flags & FIRST_FLAG))
- do_tox(m->dht);
-
- /* wait for the status change */
- while (!(request_flags & SECOND_FLAG))
- do_tox(m->dht);
-
- for (i = 0; i < 6; i++) {
- /* send the message six times, just to be sure */
- m_sendmessage(m, 0, (uint8_t *)message, strlen(message));
- do_tox(m->dht);
- }
-
- cleanupMessenger(m);
-
- return 0;
- }
-
- /* parent */
- if (atexit(cleanup) != 0) {
- fputs("friends_test: atexit() failed!\nFailing build...\n", stderr);
- kill(child_pid, SIGKILL);
- return -1;
- }
-
- m = initMessenger();
-
- msync(parent_id, crypto_box_PUBLICKEYBYTES, MS_SYNC);
- m_callback_statusmessage(m, parent_confirm_status, NULL);
- m_callback_friendmessage(m, parent_confirm_message, NULL);
-
- /* hacky way to give the child time to set up */
- c_sleep(50);
-
- Messenger_save(m, parent_id);
-
- if (parent_friend_request(m->dht) == -1)
- return -1;
-
- if (parent_wait_for_message(m->dht) == -1)
- return -1;
-
- wait(NULL);
- fputs("friends_test: Build passed!\n", stdout);
- return 0;
-}
diff --git a/protocols/Tox/toxcore/auto_tests/messenger_test.c b/protocols/Tox/toxcore/auto_tests/messenger_test.c
deleted file mode 100644
index 7ab7d67452..0000000000
--- a/protocols/Tox/toxcore/auto_tests/messenger_test.c
+++ /dev/null
@@ -1,366 +0,0 @@
-/* unit tests for /core/Messenger.c
- * Design:
- * Just call every non-static function in Messenger.c, checking that
- * they return as they should with check calls. "Bad" calls of the type
- * function(bad_data, good_length) are _not_ checked for, this type
- * of call is the fault of the client code.
- *
- * Note:
- * None of the functions here test things that rely on the network, i.e.
- * checking that status changes are received, messages can be sent, etc.
- * All of that is done in a separate test, with two local clients running. */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "../testing/misc_tools.c" // hex_string_to_bin
-#include "../toxcore/Messenger.h"
-#include <sys/types.h>
-#include <stdint.h>
-#include <string.h>
-#include <check.h>
-
-#define REALLY_BIG_NUMBER ((1) << (sizeof(uint16_t) * 7))
-#define STRINGS_EQUAL(X, Y) (strcmp(X, Y) == 0)
-
-char *friend_id_str = "e4b3d5030bc99494605aecc33ceec8875640c1d74aa32790e821b17e98771c4a00000000f1db";
-
-/* in case we need more than one ID for a test */
-char *good_id_a_str = "DB9B569D14850ED8364C3744CAC2C8FF78985D213E980C7C508D0E91E8E45441";
-char *good_id_b_str = "d3f14b6d384d8f5f2a66cff637e69f28f539c5de61bc29744785291fa4ef4d64";
-
-char *bad_id_str = "9B569D14ff637e69f2";
-
-unsigned char *friend_id = NULL;
-unsigned char *good_id_a = NULL;
-unsigned char *good_id_b = NULL;
-unsigned char *bad_id = NULL;
-
-int friend_id_num = 0;
-
-Messenger *m;
-
-START_TEST(test_m_sendmesage)
-{
- char *message = "h-hi :3";
- int good_len = strlen(message);
- int bad_len = MAX_CRYPTO_PACKET_SIZE;
-
-
- ck_assert(m_sendmessage(m, -1, (uint8_t *)message, good_len) == 0);
- ck_assert(m_sendmessage(m, REALLY_BIG_NUMBER, (uint8_t *)message, good_len) == 0);
- ck_assert(m_sendmessage(m, 17, (uint8_t *)message, good_len) == 0);
- ck_assert(m_sendmessage(m, friend_id_num, (uint8_t *)message, bad_len) == 0);
-}
-END_TEST
-
-START_TEST(test_m_get_userstatus_size)
-{
- int rc = 0;
- ck_assert_msg((m_get_statusmessage_size(m, -1) == -1),
- "m_get_statusmessage_size did NOT catch an argument of -1");
- ck_assert_msg((m_get_statusmessage_size(m, REALLY_BIG_NUMBER) == -1),
- "m_get_statusmessage_size did NOT catch the following argument: %d\n",
- REALLY_BIG_NUMBER);
- rc = m_get_statusmessage_size(m, friend_id_num);
-
- /* this WILL error if the original m_addfriend_norequest() failed */
- ck_assert_msg((rc > 0 && rc <= MAX_STATUSMESSAGE_LENGTH),
- "m_get_statusmessage_size is returning out of range values!\n"
- "(this can be caused by the error of m_addfriend_norequest"
- " in the beginning of the suite)\n");
-}
-END_TEST
-
-START_TEST(test_m_set_userstatus)
-{
- char *status = "online!";
- uint16_t good_length = strlen(status);
- uint16_t bad_length = REALLY_BIG_NUMBER;
-
- ck_assert_msg((m_set_statusmessage(m, (uint8_t *)status, bad_length) == -1),
- "m_set_userstatus did NOT catch the following length: %d\n",
- REALLY_BIG_NUMBER);
-
- ck_assert_msg((m_set_statusmessage(m, (uint8_t *)status, good_length) == 0),
- "m_set_userstatus did NOT return 0 on the following length: %d\n"
- "MAX_STATUSMESSAGE_LENGTH: %d\n", good_length, MAX_STATUSMESSAGE_LENGTH);
-}
-END_TEST
-
-START_TEST(test_m_get_friend_connectionstatus)
-{
- ck_assert_msg((m_get_friend_connectionstatus(m, -1) == -1),
- "m_get_friend_connectionstatus did NOT catch an argument of -1.\n");
- ck_assert_msg((m_get_friend_connectionstatus(m, REALLY_BIG_NUMBER) == -1),
- "m_get_friend_connectionstatus did NOT catch an argument of %d.\n",
- REALLY_BIG_NUMBER);
-}
-END_TEST
-
-START_TEST(test_m_friend_exists)
-{
- ck_assert_msg((m_friend_exists(m, -1) == 0),
- "m_friend_exists did NOT catch an argument of -1.\n");
- ck_assert_msg((m_friend_exists(m, REALLY_BIG_NUMBER) == 0),
- "m_friend_exists did NOT catch an argument of %d.\n",
- REALLY_BIG_NUMBER);
-}
-END_TEST
-
-START_TEST(test_m_delfriend)
-{
- ck_assert_msg((m_delfriend(m, -1) == -1),
- "m_delfriend did NOT catch an argument of -1\n");
- ck_assert_msg((m_delfriend(m, REALLY_BIG_NUMBER) == -1),
- "m_delfriend did NOT catch the following number: %d\n",
- REALLY_BIG_NUMBER);
-}
-END_TEST
-/*
-START_TEST(test_m_addfriend)
-{
- char *good_data = "test";
- char *bad_data = "";
-
- int good_len = strlen(good_data);
- int bad_len = strlen(bad_data);
- int really_bad_len = (MAX_CRYPTO_PACKET_SIZE - crypto_box_PUBLICKEYBYTES
- - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES
- + crypto_box_ZEROBYTES + 100); */
-/* TODO: Update this properly to latest master
- if(m_addfriend(m, (uint8_t *)friend_id, (uint8_t *)good_data, really_bad_len) != FAERR_TOOLONG)
- ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", really_bad_len);
-*/
-/* this will error if the original m_addfriend_norequest() failed */
-/* if(m_addfriend(m, (uint8_t *)friend_id, (uint8_t *)good_data, good_len) != FAERR_ALREADYSENT)
- ck_abort_msg("m_addfriend did NOT catch adding a friend we already have.\n"
- "(this can be caused by the error of m_addfriend_norequest in"
- " the beginning of the suite)\n");
-
- if(m_addfriend(m, (uint8_t *)good_id_b, (uint8_t *)bad_data, bad_len) != FAERR_NOMESSAGE)
- ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", bad_len);
-*/
-/* this should REALLY error */
-/*
- * TODO: validate client_id in m_addfriend?
-if(m_addfriend((uint8_t *)bad_id, (uint8_t *)good_data, good_len) >= 0)
- ck_abort_msg("The following ID passed through "
- "m_addfriend without an error:\n'%s'\n", bad_id_str);
-
-}
-END_TEST */
-
-START_TEST(test_setname)
-{
- char *good_name = "consensualCorn";
- int good_length = strlen(good_name);
- int bad_length = REALLY_BIG_NUMBER;
-
- ck_assert_msg((setname(m, (uint8_t *)good_name, bad_length) == -1),
- "setname() did NOT error on %d as a length argument!\n", bad_length);
-
- ck_assert_msg((setname(m, (uint8_t *)good_name, good_length) == 0),
- "setname() did NOT return 0 on good arguments!\n");
-}
-END_TEST
-
-START_TEST(test_getself_name)
-{
- char *nickname = "testGallop";
- int len = strlen(nickname);
- char nick_check[len];
-
- setname(m, (uint8_t *)nickname, len);
- getself_name(m, (uint8_t *)nick_check);
-
- ck_assert_msg((memcmp(nickname, nick_check, len) == 0),
- "getself_name failed to return the known name!\n"
- "known name: %s\nreturned: %s\n", nickname, nick_check);
-}
-END_TEST
-
-/* this test is excluded for now, due to lack of a way
- * to set a friend's status for now.
- * ideas:
- * if we have access to the friends list, we could
- * just add a status manually ourselves. */
-/*
-START_TEST(test_m_copy_userstatus)
-{
- assert(m_copy_userstatus(-1, buf, MAX_USERSTATUS_LENGTH) == -1);
- assert(m_copy_userstatus(REALLY_BIG_NUMBER, buf, MAX_USERSTATUS_LENGTH) == -1);
- m_copy_userstatus(friend_id_num, buf, MAX_USERSTATUS_LENGTH + 6);
-
- assert(STRINGS_EQUAL(name_buf, friend_id_status));
-}
-END_TEST
-*/
-
-START_TEST(test_getname)
-{
- uint8_t name_buf[MAX_NAME_LENGTH];
- uint8_t test_name[] = {'f', 'o', 'o'};
-
- ck_assert(getname(m, -1, name_buf) == -1);
- ck_assert(getname(m, REALLY_BIG_NUMBER, name_buf) == -1);
-
- memcpy(m->friendlist[0].name, &test_name[0], 3);
- m->friendlist[0].name_length = 4;
- ck_assert(getname(m, 0, &name_buf[0]) == 4);
-
- ck_assert(strcmp((char *)&name_buf[0], "foo") == 0);
-}
-END_TEST
-
-START_TEST(test_dht_state_saveloadsave)
-{
- /* validate that:
- * a) saving stays within the confined space
- * b) a save()d state can be load()ed back successfully
- * c) a second save() is of equal size
- * d) the second save() is of equal content */
- size_t i, extra = 64;
- size_t size = DHT_size(m->dht);
- uint8_t buffer[size + 2 * extra];
- memset(buffer, 0xCD, extra);
- memset(buffer + extra + size, 0xCD, extra);
- DHT_save(m->dht, buffer + extra);
-
- for (i = 0; i < extra; i++) {
- ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from DHT_save() @%u", i);
- ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from DHT_save() @%u", i);
- }
-
- int res = DHT_load(m->dht, buffer + extra, size);
-
- if (res == -1)
- ck_assert_msg(res == 0, "Failed to load back stored buffer: res == -1");
- else {
- char msg[128];
- size_t offset = res >> 4;
- uint8_t *ptr = buffer + extra + offset;
- sprintf(msg, "Failed to load back stored buffer: 0x%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx @%zu/%zu, code %d",
- ptr[-2], ptr[-1], ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], offset, size, res & 0x0F);
- ck_assert_msg(res == 0, msg);
- }
-
- size_t size2 = DHT_size(m->dht);
- ck_assert_msg(size == size2, "Messenger \"grew\" in size from a store/load cycle: %u -> %u", size, size2);
-
- uint8_t buffer2[size2];
- DHT_save(m->dht, buffer2);
-
- ck_assert_msg(!memcmp(buffer + extra, buffer2, size), "DHT state changed by store/load/store cycle");
-}
-END_TEST
-
-START_TEST(test_messenger_state_saveloadsave)
-{
- /* validate that:
- * a) saving stays within the confined space
- * b) a save()d state can be load()ed back successfully
- * c) a second save() is of equal size
- * d) the second save() is of equal content */
- size_t i, extra = 64;
- size_t size = messenger_size(m);
- uint8_t buffer[size + 2 * extra];
- memset(buffer, 0xCD, extra);
- memset(buffer + extra + size, 0xCD, extra);
- messenger_save(m, buffer + extra);
-
- for (i = 0; i < extra; i++) {
- ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from messenger_save() @%u", i);
- ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from messenger_save() @%u", i);
- }
-
- int res = messenger_load(m, buffer + extra, size);
-
- if (res == -1)
- ck_assert_msg(res == 0, "Failed to load back stored buffer: res == -1");
- else {
- char msg[128];
- size_t offset = res >> 4;
- uint8_t *ptr = buffer + extra + offset;
- sprintf(msg, "Failed to load back stored buffer: 0x%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx @%zu/%zu, code %d",
- ptr[-2], ptr[-1], ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], offset, size, res & 0x0F);
- ck_assert_msg(res == 0, msg);
- }
-
- size_t size2 = messenger_size(m);
- ck_assert_msg(size == size2, "Messenger \"grew\" in size from a store/load cycle: %u -> %u", size, size2);
-
- uint8_t buffer2[size2];
- messenger_save(m, buffer2);
-
- ck_assert_msg(!memcmp(buffer + extra, buffer2, size), "Messenger state changed by store/load/store cycle");
-}
-END_TEST
-
-#define DEFTESTCASE(NAME) \
- TCase *tc_##NAME = tcase_create(#NAME); \
- tcase_add_test(tc_##NAME, test_##NAME); \
- suite_add_tcase(s, tc_##NAME);
-
-Suite *messenger_suite(void)
-{
- Suite *s = suite_create("Messenger");
-
- DEFTESTCASE(dht_state_saveloadsave);
- DEFTESTCASE(messenger_state_saveloadsave);
-
- DEFTESTCASE(getself_name);
- DEFTESTCASE(m_get_userstatus_size);
- DEFTESTCASE(m_set_userstatus);
-
- /* DEFTESTCASE(m_addfriend); */
- DEFTESTCASE(m_friend_exists);
- DEFTESTCASE(m_get_friend_connectionstatus);
- DEFTESTCASE(m_delfriend);
-
- DEFTESTCASE(setname);
- DEFTESTCASE(getname);
- DEFTESTCASE(m_sendmesage);
-
- return s;
-}
-
-int main(int argc, char *argv[])
-{
- Suite *messenger = messenger_suite();
- SRunner *test_runner = srunner_create(messenger);
- int number_failed = 0;
-
- friend_id = hex_string_to_bin(friend_id_str);
- good_id_a = hex_string_to_bin(good_id_a_str);
- good_id_b = hex_string_to_bin(good_id_b_str);
- bad_id = hex_string_to_bin(bad_id_str);
-
- /* IPv6 status from global define */
- m = new_messenger(TOX_ENABLE_IPV6_DEFAULT);
-
- /* setup a default friend and friendnum */
- if (m_addfriend_norequest(m, (uint8_t *)friend_id) < 0)
- fputs("m_addfriend_norequest() failed on a valid ID!\n"
- "this was CRITICAL to the test, and the build WILL fail.\n"
- "the tests will continue now...\n\n", stderr);
-
- if ((friend_id_num = getfriend_id(m, (uint8_t *)friend_id)) < 0)
- fputs("getfriend_id() failed on a valid ID!\n"
- "this was CRITICAL to the test, and the build WILL fail.\n"
- "the tests will continue now...\n\n", stderr);
-
- srunner_run_all(test_runner, CK_NORMAL);
- number_failed = srunner_ntests_failed(test_runner);
-
- srunner_free(test_runner);
- free(friend_id);
- free(good_id_a);
- free(good_id_b);
- free(bad_id);
-
- kill_messenger(m);
-
- return number_failed;
-}
diff --git a/protocols/Tox/toxcore/auto_tests/network_test.c b/protocols/Tox/toxcore/auto_tests/network_test.c
deleted file mode 100644
index afd90e7a06..0000000000
--- a/protocols/Tox/toxcore/auto_tests/network_test.c
+++ /dev/null
@@ -1,174 +0,0 @@
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <sys/types.h>
-#include <stdint.h>
-#include <string.h>
-#include <check.h>
-#include <stdlib.h>
-#include <time.h>
-
-#include "../toxcore/network.h"
-
-START_TEST(test_addr_resolv_localhost)
-{
-#ifdef __CYGWIN__
- /* force initialization of network stack
- * normally this should happen automatically
- * cygwin doesn't do it for every network related function though
- * e.g. not for getaddrinfo... */
- socket(0, 0, 0);
- errno = 0;
-#endif
-
- const char localhost[] = "localhost";
- int localhost_split = 0;
-
- IP ip;
- ip_init(&ip, 0);
-
- int res = addr_resolve(localhost, &ip, NULL);
-
- ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno));
-
- if (res > 0) {
- ck_assert_msg(ip.family == AF_INET, "Expected family AF_INET, got %u.", ip.family);
- ck_assert_msg(ip.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(ip.ip4.in_addr));
- }
-
- ip_init(&ip, 1);
- res = addr_resolve(localhost, &ip, NULL);
-
- if (res < 1) {
- res = addr_resolve("ip6-localhost", &ip, NULL);
- localhost_split = 1;
- }
-
- ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno));
-
- if (res > 0) {
- ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6, got %u.", ip.family);
- ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip));
- }
-
- if (!localhost_split) {
- ip_init(&ip, 1);
- ip.family = AF_UNSPEC;
- IP extra;
- ip_reset(&extra);
- res = addr_resolve(localhost, &ip, &extra);
- ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno));
-
- if (res > 0) {
- ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6, got %u.", ip.family);
- ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip));
-
- ck_assert_msg(extra.family == AF_INET, "Expected family AF_INET, got %u.", extra.family);
- ck_assert_msg(extra.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(extra.ip4.in_addr));
- }
- } else {
- printf("Localhost seems to be split in two.\n");
- }
-}
-END_TEST
-
-START_TEST(test_ip_equal)
-{
- int res;
- IP ip1, ip2;
- ip_reset(&ip1);
- ip_reset(&ip2);
-
- res = ip_equal(NULL, NULL);
- ck_assert_msg(res == 0, "ip_equal(NULL, NULL): expected result 0, got %u.", res);
-
- res = ip_equal(&ip1, NULL);
- ck_assert_msg(res == 0, "ip_equal(PTR, NULL): expected result 0, got %u.", res);
-
- res = ip_equal(NULL, &ip1);
- ck_assert_msg(res == 0, "ip_equal(NULL, PTR): expected result 0, got %u.", res);
-
- ip1.family = AF_INET;
- ip1.ip4.uint32 = htonl(0x7F000001);
-
- res = ip_equal(&ip1, &ip2);
- ck_assert_msg(res == 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_UNSPEC, 0} ): expected result 0, got %u.", res);
-
- ip2.family = AF_INET;
- ip2.ip4.uint32 = htonl(0x7F000001);
-
- res = ip_equal(&ip1, &ip2);
- ck_assert_msg(res != 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET, 127.0.0.1} ): expected result != 0, got 0.");
-
- ip2.ip4.uint32 = htonl(0x7F000002);
-
- res = ip_equal(&ip1, &ip2);
- ck_assert_msg(res == 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET, 127.0.0.2} ): expected result 0, got %u.", res);
-
- ip2.family = AF_INET6;
- ip2.ip6.uint32[0] = 0;
- ip2.ip6.uint32[1] = 0;
- ip2.ip6.uint32[2] = htonl(0xFFFF);
- ip2.ip6.uint32[3] = htonl(0x7F000001);
-
- ck_assert_msg(IN6_IS_ADDR_V4MAPPED(&ip2.ip6.in6_addr) != 0,
- "IN6_IS_ADDR_V4MAPPED(::ffff:127.0.0.1): expected != 0, got 0.");
-
- res = ip_equal(&ip1, &ip2);
- ck_assert_msg(res != 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET6, ::ffff:127.0.0.1} ): expected result != 0, got 0.");
-
- memcpy(&ip2.ip6, &in6addr_loopback, sizeof(IP6));
- res = ip_equal(&ip1, &ip2);
- ck_assert_msg(res == 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET6, ::1} ): expected result 0, got %u.", res);
-
- memcpy(&ip1, &ip2, sizeof(IP));
- res = ip_equal(&ip1, &ip2);
- ck_assert_msg(res != 0, "ip_equal( {AF_INET6, ::1}, {AF_INET6, ::1} ): expected result != 0, got 0.");
-
- ip2.ip6.uint8[15]++;
- res = ip_equal(&ip1, &ip2);
- ck_assert_msg(res == 0, "ip_equal( {AF_INET6, ::1}, {AF_INET6, ::2} ): expected result 0, got %res.", res);
-}
-END_TEST
-
-START_TEST(test_struct_sizes)
-{
- ck_assert_msg(sizeof(IP4) == 4, "sizeof(IP4): expected result 4, got %u.", sizeof(IP4));
- ck_assert_msg(sizeof(IP6) == 16, "sizeof(IP6): expected result 16, got %u.", sizeof(IP6));
- ck_assert_msg(sizeof(IP) == 17, "sizeof(IP): expected result 17, got %u.", sizeof(IP));
- ck_assert_msg(sizeof(IP_Port) == 19, "sizeof(IP_Port): expected result 19, got %u.", sizeof(IP_Port));
-}
-END_TEST
-
-#define DEFTESTCASE(NAME) \
- TCase *tc_##NAME = tcase_create(#NAME); \
- tcase_add_test(tc_##NAME, test_##NAME); \
- suite_add_tcase(s, tc_##NAME);
-
-Suite *network_suite(void)
-{
- Suite *s = suite_create("Network");
-
- DEFTESTCASE(addr_resolv_localhost);
- DEFTESTCASE(ip_equal);
- DEFTESTCASE(struct_sizes);
-
- return s;
-}
-
-int main(int argc, char *argv[])
-{
- srand((unsigned int) time(NULL));
-
- Suite *network = network_suite();
- SRunner *test_runner = srunner_create(network);
- int number_failed = 0;
-
- srunner_run_all(test_runner, CK_NORMAL);
- number_failed = srunner_ntests_failed(test_runner);
-
- srunner_free(test_runner);
-
- return number_failed;
-}
diff --git a/protocols/Tox/toxcore/auto_tests/onion_test.c b/protocols/Tox/toxcore/auto_tests/onion_test.c
deleted file mode 100644
index 2394e03daf..0000000000
--- a/protocols/Tox/toxcore/auto_tests/onion_test.c
+++ /dev/null
@@ -1,369 +0,0 @@
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <sys/types.h>
-#include <stdint.h>
-#include <string.h>
-#include <check.h>
-#include <stdlib.h>
-#include <time.h>
-
-#include "../toxcore/onion.h"
-#include "../toxcore/onion_announce.h"
-#include "../toxcore/onion_client.h"
-#include "../toxcore/util.h"
-
-#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
-#define c_sleep(x) Sleep(1*x)
-#else
-#include <unistd.h>
-#define c_sleep(x) usleep(1000*x)
-#endif
-
-void do_onion(Onion *onion)
-{
- networking_poll(onion->net);
- do_DHT(onion->dht);
-}
-
-static int handled_test_1;
-static int handle_test_1(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
-{
- Onion *onion = object;
-
- if (memcmp(packet, "Install Gentoo", sizeof("Install Gentoo")) != 0)
- return 1;
-
- if (send_onion_response(onion->net, source, (uint8_t *)"install gentoo", sizeof("install gentoo"),
- packet + sizeof("Install Gentoo")) == -1)
- return 1;
-
- handled_test_1 = 1;
- return 0;
-}
-
-static int handled_test_2;
-static int handle_test_2(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
-{
- if (length != sizeof("install Gentoo"))
- return 1;
-
- if (memcmp(packet, (uint8_t *)"install gentoo", sizeof("install gentoo")) != 0)
- return 1;
-
- handled_test_2 = 1;
- return 0;
-}
-/*
-void print_client_id(uint8_t *client_id, uint32_t length)
-{
- uint32_t j;
-
- for (j = 0; j < length; j++) {
- printf("%02hhX", client_id[j]);
- }
- printf("\n");
-}
-*/
-uint8_t sb_data[ONION_ANNOUNCE_SENDBACK_DATA_LENGTH];
-static int handled_test_3;
-uint8_t test_3_pub_key[crypto_box_PUBLICKEYBYTES];
-uint8_t test_3_ping_id[crypto_hash_sha256_BYTES];
-static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
-{
- Onion *onion = object;
-
- if (length != (1 + crypto_box_NONCEBYTES + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + 1 + crypto_hash_sha256_BYTES +
- crypto_box_MACBYTES))
- return 1;
-
- uint8_t plain[1 + crypto_hash_sha256_BYTES];
- //print_client_id(packet, length);
- int len = decrypt_data(test_3_pub_key, onion->dht->self_secret_key, packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH,
- packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_box_NONCEBYTES,
- 1 + crypto_hash_sha256_BYTES + crypto_box_MACBYTES, plain);
-
- if (len == -1)
- return 1;
-
-
- if (memcmp(packet + 1, sb_data, ONION_ANNOUNCE_SENDBACK_DATA_LENGTH) != 0)
- return 1;
-
- memcpy(test_3_ping_id, plain + 1, crypto_hash_sha256_BYTES);
- //print_client_id(test_3_ping_id, sizeof(test_3_ping_id));
- handled_test_3 = 1;
- return 0;
-}
-
-uint8_t nonce[crypto_box_NONCEBYTES];
-static int handled_test_4;
-static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
-{
- Onion *onion = object;
-
- if (length != (1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + sizeof("Install gentoo") + crypto_box_MACBYTES))
- return 1;
-
- uint8_t plain[sizeof("Install gentoo")] = {0};
-
- if (memcmp(nonce, packet + 1, crypto_box_NONCEBYTES) != 0)
- return 1;
-
- int len = decrypt_data(packet + 1 + crypto_box_NONCEBYTES, onion->dht->self_secret_key, packet + 1,
- packet + 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES, sizeof("Install gentoo") + crypto_box_MACBYTES, plain);
-
- if (len == -1)
- return 1;
-
- if (memcmp(plain, "Install gentoo", sizeof("Install gentoo")) != 0)
- return 1;
-
- handled_test_4 = 1;
- return 0;
-}
-
-START_TEST(test_basic)
-{
- IP ip;
- ip_init(&ip, 1);
- ip.ip6.uint8[15] = 1;
- Onion *onion1 = new_onion(new_DHT(new_networking(ip, 34567)));
- Onion *onion2 = new_onion(new_DHT(new_networking(ip, 34568)));
- ck_assert_msg((onion1 != NULL) && (onion2 != NULL), "Onion failed initializing.");
- networking_registerhandler(onion2->net, 'I', &handle_test_1, onion2);
-
- IP_Port on1 = {ip, onion1->net->port};
- Node_format n1;
- memcpy(n1.client_id, onion1->dht->self_public_key, crypto_box_PUBLICKEYBYTES);
- n1.ip_port = on1;
-
- IP_Port on2 = {ip, onion2->net->port};
- Node_format n2;
- memcpy(n2.client_id, onion2->dht->self_public_key, crypto_box_PUBLICKEYBYTES);
- n2.ip_port = on2;
-
- Node_format nodes[4];
- nodes[0] = n1;
- nodes[1] = n2;
- nodes[2] = n1;
- nodes[3] = n2;
- Onion_Path path;
- create_onion_path(onion1->dht, &path, nodes);
- int ret = send_onion_packet(onion1->net, &path, nodes[3].ip_port, (uint8_t *)"Install Gentoo",
- sizeof("Install Gentoo"));
- ck_assert_msg(ret == 0, "Failed to create/send onion packet.");
-
- handled_test_1 = 0;
-
- while (handled_test_1 == 0) {
- do_onion(onion1);
- do_onion(onion2);
- }
-
- networking_registerhandler(onion1->net, 'i', &handle_test_2, onion1);
- handled_test_2 = 0;
-
- while (handled_test_2 == 0) {
- do_onion(onion1);
- do_onion(onion2);
- }
-
- Onion_Announce *onion1_a = new_onion_announce(onion1->dht);
- Onion_Announce *onion2_a = new_onion_announce(onion2->dht);
- networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_test_3, onion1);
- ck_assert_msg((onion1_a != NULL) && (onion2_a != NULL), "Onion_Announce failed initializing.");
- uint8_t zeroes[64] = {0};
- randombytes(sb_data, sizeof(sb_data));
- uint64_t s;
- memcpy(&s, sb_data, sizeof(uint64_t));
- memcpy(test_3_pub_key, nodes[3].client_id, crypto_box_PUBLICKEYBYTES);
- ret = send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key,
- onion1->dht->self_secret_key,
- zeroes, onion1->dht->self_public_key, onion1->dht->self_public_key, s);
- ck_assert_msg(ret == 0, "Failed to create/send onion announce_request packet.");
- handled_test_3 = 0;
-
- while (handled_test_3 == 0) {
- do_onion(onion1);
- do_onion(onion2);
- c_sleep(50);
- }
-
- randombytes(sb_data, sizeof(sb_data));
- memcpy(&s, sb_data, sizeof(uint64_t));
- memcpy(onion2_a->entries[1].public_key, onion2->dht->self_public_key, crypto_box_PUBLICKEYBYTES);
- onion2_a->entries[1].time = unix_time();
- networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1);
- send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key, onion1->dht->self_secret_key,
- test_3_ping_id, onion1->dht->self_public_key, onion1->dht->self_public_key, s);
-
- while (memcmp(onion2_a->entries[ONION_ANNOUNCE_MAX_ENTRIES - 2].public_key, onion1->dht->self_public_key,
- crypto_box_PUBLICKEYBYTES) != 0) {
- do_onion(onion1);
- do_onion(onion2);
- c_sleep(50);
- }
-
- c_sleep(1000);
- Onion *onion3 = new_onion(new_DHT(new_networking(ip, 34569)));
- ck_assert_msg((onion3 != NULL), "Onion failed initializing.");
-
- new_nonce(nonce);
- ret = send_data_request(onion3->net, &path, nodes[3].ip_port, onion1->dht->self_public_key,
- onion1->dht->self_public_key,
- nonce, (uint8_t *)"Install gentoo", sizeof("Install gentoo"));
- ck_assert_msg(ret == 0, "Failed to create/send onion data_request packet.");
- handled_test_4 = 0;
-
- while (handled_test_4 == 0) {
- do_onion(onion1);
- do_onion(onion2);
- c_sleep(50);
- }
-}
-END_TEST
-
-typedef struct {
- Onion *onion;
- Onion_Announce *onion_a;
- Onion_Client *onion_c;
-} Onions;
-
-Onions *new_onions(uint16_t port)
-{
- IP ip;
- ip_init(&ip, 1);
- ip.ip6.uint8[15] = 1;
- Onions *on = malloc(sizeof(Onions));
- DHT *dht = new_DHT(new_networking(ip, port));
- on->onion = new_onion(dht);
- on->onion_a = new_onion_announce(dht);
- on->onion_c = new_onion_client(new_net_crypto(dht));
-
- if (on->onion && on->onion_a && on->onion_c)
- return on;
-
- return NULL;
-}
-
-void do_onions(Onions *on)
-{
- networking_poll(on->onion->net);
- do_DHT(on->onion->dht);
- do_onion_client(on->onion_c);
-}
-
-#define NUM_ONIONS 50
-
-START_TEST(test_announce)
-{
- uint32_t i, j;
- Onions *onions[NUM_ONIONS];
-
- for (i = 0; i < NUM_ONIONS; ++i) {
- onions[i] = new_onions(i + 34655);
- ck_assert_msg(onions[i] != 0, "Failed to create onions. %u");
- }
-
- IP ip;
- ip_init(&ip, 1);
- ip.ip6.uint8[15] = 1;
-
- for (i = 3; i < NUM_ONIONS; ++i) {
- IP_Port ip_port = {ip, onions[i - 1]->onion->net->port};
- DHT_bootstrap(onions[i]->onion->dht, ip_port, onions[i - 1]->onion->dht->self_public_key);
- IP_Port ip_port1 = {ip, onions[i - 2]->onion->net->port};
- DHT_bootstrap(onions[i]->onion->dht, ip_port1, onions[i - 2]->onion->dht->self_public_key);
- IP_Port ip_port2 = {ip, onions[i - 3]->onion->net->port};
- DHT_bootstrap(onions[i]->onion->dht, ip_port2, onions[i - 3]->onion->dht->self_public_key);
- }
-
- uint32_t connected = 0;
-
- while (connected != NUM_ONIONS) {
- connected = 0;
-
- for (i = 0; i < NUM_ONIONS; ++i) {
- do_onions(onions[i]);
- connected += DHT_isconnected(onions[i]->onion->dht);
- }
-
- c_sleep(50);
- }
-
- for (i = 0; i < 25 * 2; ++i) {
- for (j = 0; j < NUM_ONIONS; ++j) {
- do_onions(onions[j]);
- }
-
- c_sleep(50);
- }
-
- onion_addfriend(onions[7]->onion_c, onions[37]->onion_c->c->self_public_key);
- int frnum = onion_addfriend(onions[37]->onion_c, onions[7]->onion_c->c->self_public_key);
-
- int ok = -1;
-
- IP_Port ip_port;
-
- while (ok == -1) {
- for (i = 0; i < NUM_ONIONS; ++i) {
- networking_poll(onions[i]->onion->net);
- do_onion_client(onions[i]->onion_c);
- }
-
- ok = onion_getfriendip(onions[37]->onion_c, frnum, &ip_port);
-
- c_sleep(50);
- }
-
- printf("id discovered\n");
-
- while (ok != 1) {
- for (i = 0; i < NUM_ONIONS; ++i) {
- do_onions(onions[i]);
- }
-
- ok = onion_getfriendip(onions[37]->onion_c, frnum, &ip_port);
-
- c_sleep(50);
- }
-
- ck_assert_msg(ip_port.port == onions[7]->onion->net->port, "Port in returned ip not correct.");
-}
-END_TEST
-
-#define DEFTESTCASE(NAME) \
- TCase *tc_##NAME = tcase_create(#NAME); \
- tcase_add_test(tc_##NAME, test_##NAME); \
- suite_add_tcase(s, tc_##NAME);
-
-#define DEFTESTCASE_SLOW(NAME, TIMEOUT) \
- DEFTESTCASE(NAME) \
- tcase_set_timeout(tc_##NAME, TIMEOUT);
-Suite *onion_suite(void)
-{
- Suite *s = suite_create("Onion");
-
- DEFTESTCASE_SLOW(basic, 5);
- DEFTESTCASE_SLOW(announce, 200);
- return s;
-}
-
-int main(int argc, char *argv[])
-{
- srand((unsigned int) time(NULL));
-
- Suite *onion = onion_suite();
- SRunner *test_runner = srunner_create(onion);
-
- int number_failed = 0;
- srunner_run_all(test_runner, CK_NORMAL);
- number_failed = srunner_ntests_failed(test_runner);
-
- srunner_free(test_runner);
-
- return number_failed;
-}
diff --git a/protocols/Tox/toxcore/auto_tests/skeleton_test.c b/protocols/Tox/toxcore/auto_tests/skeleton_test.c
deleted file mode 100644
index 89ef1b8bd6..0000000000
--- a/protocols/Tox/toxcore/auto_tests/skeleton_test.c
+++ /dev/null
@@ -1,53 +0,0 @@
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <sys/types.h>
-#include <stdint.h>
-#include <string.h>
-#include <check.h>
-#include <stdlib.h>
-#include <time.h>
-
-/*
-#include "../<stuff to test>"
-*/
-
-START_TEST(test_creativetestnamegoeshere)
-{
- uint8_t test = 0;
- ck_assert_msg(test == 0, "test: expected result 0, got %u.", test);
-}
-END_TEST
-
-
-#define DEFTESTCASE(NAME) \
- TCase *tc_##NAME = tcase_create(#NAME); \
- tcase_add_test(tc_##NAME, test_##NAME); \
- suite_add_tcase(s, tc_##NAME);
-
-Suite *creativesuitenamegoeshere_suite(void)
-{
- Suite *s = suite_create("creativesuitedescritptiongoeshere");
-
- DEFTESTCASE(/* remove test_ from test function names */ creativetestnamegoeshere);
-
- return s;
-}
-
-int main(int argc, char *argv[])
-{
- srand((unsigned int) time(NULL));
-
- Suite *creativesuitenamegoeshere = creativesuitenamegoeshere_suite();
- SRunner *test_runner = srunner_create(creativesuitenamegoeshere);
-
- int number_failed = 0;
- srunner_run_all(test_runner, CK_NORMAL);
- number_failed = srunner_ntests_failed(test_runner);
-
- srunner_free(test_runner);
-
- return number_failed;
-}
-
diff --git a/protocols/Tox/toxcore/auto_tests/tox_test.c b/protocols/Tox/toxcore/auto_tests/tox_test.c
deleted file mode 100644
index 43fb7a1cd2..0000000000
--- a/protocols/Tox/toxcore/auto_tests/tox_test.c
+++ /dev/null
@@ -1,395 +0,0 @@
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <sys/types.h>
-#include <stdint.h>
-#include <string.h>
-#include <stdio.h>
-#include <check.h>
-#include <stdlib.h>
-#include <time.h>
-
-#include "../toxcore/tox.h"
-
-#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
-#define c_sleep(x) Sleep(1*x)
-#else
-#include <unistd.h>
-#define c_sleep(x) usleep(1000*x)
-#endif
-
-void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
-{
- if (*((uint32_t *)userdata) != 974536)
- return;
-
- if (length == 7 && memcmp("Gentoo", data, 7) == 0) {
- tox_add_friend_norequest(m, public_key);
- }
-}
-uint32_t messages_received;
-
-void print_message(Tox *m, int friendnumber, const uint8_t *string, uint16_t length, void *userdata)
-{
- if (*((uint32_t *)userdata) != 974536)
- return;
-
- uint8_t cmp_msg[TOX_MAX_MESSAGE_LENGTH];
- memset(cmp_msg, 'G', sizeof(cmp_msg));
-
- if (length == TOX_MAX_MESSAGE_LENGTH && memcmp(string, cmp_msg, sizeof(cmp_msg)) == 0)
- ++messages_received;
-}
-
-uint32_t name_changes;
-
-void print_nickchange(Tox *m, int friendnumber, const uint8_t *string, uint16_t length, void *userdata)
-{
- if (*((uint32_t *)userdata) != 974536)
- return;
-
- if (length == sizeof("Gentoo") && memcmp(string, "Gentoo", sizeof("Gentoo")) == 0)
- ++name_changes;
-}
-
-uint32_t typing_changes;
-
-void print_typingchange(Tox *m, int friendnumber, uint8_t typing, void *userdata)
-{
- if (*((uint32_t *)userdata) != 974536)
- return;
-
- if (!typing)
- typing_changes = 1;
- else
- typing_changes = 2;
-}
-
-uint8_t filenum;
-uint32_t file_accepted;
-uint64_t file_size;
-void file_request_accept(Tox *m, int friendnumber, uint8_t filenumber, uint64_t filesize, const uint8_t *filename,
- uint16_t filename_length, void *userdata)
-{
- if (*((uint32_t *)userdata) != 974536)
- return;
-
- if (filename_length == sizeof("Gentoo.exe") && memcmp(filename, "Gentoo.exe", sizeof("Gentoo.exe")) == 0)
- ++file_accepted;
-
- file_size = filesize;
- tox_file_send_control(m, friendnumber, 1, filenumber, TOX_FILECONTROL_ACCEPT, NULL, 0);
-}
-
-uint32_t file_sent;
-uint32_t sendf_ok;
-void file_print_control(Tox *m, int friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type,
- const uint8_t *data, uint16_t length, void *userdata)
-{
- if (*((uint32_t *)userdata) != 974536)
- return;
-
- if (receive_send == 0 && control_type == TOX_FILECONTROL_FINISHED)
- tox_file_send_control(m, friendnumber, 1, filenumber, TOX_FILECONTROL_FINISHED, NULL, 0);
-
- if (receive_send == 1 && control_type == TOX_FILECONTROL_FINISHED)
- file_sent = 1;
-
- if (receive_send == 1 && control_type == TOX_FILECONTROL_ACCEPT)
- sendf_ok = 1;
-
-}
-
-uint64_t size_recv;
-uint8_t num;
-void write_file(Tox *m, int friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length, void *userdata)
-{
- if (*((uint32_t *)userdata) != 974536)
- return;
-
- uint8_t *f_data = malloc(length);
- memset(f_data, num, length);
- ++num;
-
- if (memcmp(f_data, data, length) == 0) {
- size_recv += length;
- } else {
- printf("FILE_CORRUPTED\n");
- }
-}
-
-START_TEST(test_few_clients)
-{
- long long unsigned int con_time, cur_time = time(NULL);
- Tox *tox1 = tox_new(TOX_ENABLE_IPV6_DEFAULT);
- Tox *tox2 = tox_new(TOX_ENABLE_IPV6_DEFAULT);
- Tox *tox3 = tox_new(TOX_ENABLE_IPV6_DEFAULT);
- ck_assert_msg(tox1 || tox2 || tox3, "Failed to create 3 tox instances");
- uint32_t to_compare = 974536;
- tox_callback_friend_request(tox2, accept_friend_request, &to_compare);
- uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
- tox_get_address(tox2, address);
- int test = tox_add_friend(tox3, address, (uint8_t *)"Gentoo", 7);
- ck_assert_msg(test == 0, "Failed to add friend error code: %i", test);
-
- uint8_t off = 1;
-
- while (1) {
- tox_do(tox1);
- tox_do(tox2);
- tox_do(tox3);
-
- if (tox_isconnected(tox1) && tox_isconnected(tox2) && tox_isconnected(tox3) && off) {
- printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time);
- con_time = time(NULL);
- off = 0;
- }
-
-
- if (tox_get_friend_connection_status(tox2, 0) == 1 && tox_get_friend_connection_status(tox3, 0) == 1)
- break;
-
- c_sleep(50);
- }
-
- printf("tox clients connected took %llu seconds\n", time(NULL) - con_time);
- to_compare = 974536;
- tox_callback_friend_message(tox3, print_message, &to_compare);
- uint8_t msgs[TOX_MAX_MESSAGE_LENGTH + 1];
- memset(msgs, 'G', sizeof(msgs));
- ck_assert_msg(tox_send_message(tox2, 0, msgs, TOX_MAX_MESSAGE_LENGTH + 1) == 0,
- "TOX_MAX_MESSAGE_LENGTH is too small\n");
- ck_assert_msg(tox_send_message(tox2, 0, msgs, TOX_MAX_MESSAGE_LENGTH) != 0, "TOX_MAX_MESSAGE_LENGTH is too big\n");
-
- while (1) {
- messages_received = 0;
- tox_do(tox1);
- tox_do(tox2);
- tox_do(tox3);
-
- if (messages_received)
- break;
-
- c_sleep(50);
- }
-
- printf("tox clients messaging succeeded\n");
-
- tox_callback_name_change(tox3, print_nickchange, &to_compare);
- tox_set_name(tox2, (uint8_t *)"Gentoo", sizeof("Gentoo"));
-
- while (1) {
- name_changes = 0;
- tox_do(tox1);
- tox_do(tox2);
- tox_do(tox3);
-
- if (name_changes)
- break;
-
- c_sleep(50);
- }
-
- uint8_t temp_name[sizeof("Gentoo")];
- tox_get_name(tox3, 0, temp_name);
- ck_assert_msg(memcmp(temp_name, "Gentoo", sizeof("Gentoo")) == 0, "Name not correct");
-
- tox_callback_typing_change(tox2, &print_typingchange, &to_compare);
- tox_set_user_is_typing(tox3, 0, 1);
-
- while (1) {
- typing_changes = 0;
- tox_do(tox1);
- tox_do(tox2);
- tox_do(tox3);
-
-
- if (typing_changes == 2)
- break;
- else
- ck_assert_msg(typing_changes == 0, "Typing fail");
-
- c_sleep(50);
- }
-
- ck_assert_msg(tox_get_is_typing(tox2, 0) == 1, "Typing fail");
- tox_set_user_is_typing(tox3, 0, 0);
-
- while (1) {
- typing_changes = 0;
- tox_do(tox1);
- tox_do(tox2);
- tox_do(tox3);
-
- if (typing_changes == 1)
- break;
- else
- ck_assert_msg(typing_changes == 0, "Typing fail");
-
- c_sleep(50);
- }
-
- ck_assert_msg(tox_get_is_typing(tox2, 0) == 0, "Typing fail");
-
- filenum = file_accepted = file_size = file_sent = sendf_ok = size_recv = 0;
- long long unsigned int f_time = time(NULL);
- tox_callback_file_data(tox3, write_file, &to_compare);
- tox_callback_file_control(tox2, file_print_control, &to_compare);
- tox_callback_file_control(tox3, file_print_control, &to_compare);
- tox_callback_file_send_request(tox3, file_request_accept, &to_compare);
- uint64_t totalf_size = 100 * 1024 * 1024;
- int fnum = tox_new_file_sender(tox2, 0, totalf_size, (uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"));
- ck_assert_msg(fnum != -1, "tox_new_file_sender fail");
- int fpiece_size = tox_file_data_size(tox2, 0);
- uint8_t *f_data = malloc(fpiece_size);
- uint8_t num = 0;
- memset(f_data, num, fpiece_size);
-
- while (1) {
- file_sent = 0;
- tox_do(tox1);
- tox_do(tox2);
- tox_do(tox3);
-
- if (sendf_ok)
- while (tox_file_send_data(tox2, 0, fnum, f_data, fpiece_size < totalf_size ? fpiece_size : totalf_size) == 0) {
- if (totalf_size <= fpiece_size) {
- sendf_ok = 0;
- tox_file_send_control(tox2, 0, 0, fnum, TOX_FILECONTROL_FINISHED, NULL, 0);
- }
-
- ++num;
- memset(f_data, num, fpiece_size);
-
- totalf_size -= fpiece_size;
- }
-
- if (file_sent && size_recv == file_size)
- break;
-
- uint32_t tox1_interval = tox_do_interval(tox1);
- uint32_t tox2_interval = tox_do_interval(tox2);
- uint32_t tox3_interval = tox_do_interval(tox3);
-
- if (tox2_interval > tox3_interval) {
- c_sleep(tox3_interval);
- } else {
- c_sleep(tox2_interval);
- }
- }
-
- printf("100MB file sent in %llu seconds\n", time(NULL) - f_time);
-
- printf("test_few_clients succeeded, took %llu seconds\n", time(NULL) - cur_time);
-
- tox_kill(tox1);
- tox_kill(tox2);
- tox_kill(tox3);
-}
-END_TEST
-
-#define NUM_TOXES 66
-#define NUM_FRIENDS 20
-
-START_TEST(test_many_clients)
-{
- long long unsigned int cur_time = time(NULL);
- Tox *toxes[NUM_TOXES];
- uint32_t i, j;
- uint32_t to_comp = 974536;
-
- for (i = 0; i < NUM_TOXES; ++i) {
- toxes[i] = tox_new(TOX_ENABLE_IPV6_DEFAULT);
- ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i);
- tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp);
- }
-
- struct {
- uint16_t tox1;
- uint16_t tox2;
- } pairs[NUM_FRIENDS];
-
- uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
-
- for (i = 0; i < NUM_FRIENDS; ++i) {
-loop_top:
- pairs[i].tox1 = rand() % NUM_TOXES;
- pairs[i].tox2 = (pairs[i].tox1 + rand() % (NUM_TOXES - 1) + 1) % NUM_TOXES;
-
- for (j = 0; j < i; ++j) {
- if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2)
- goto loop_top;
- }
-
- tox_get_address(toxes[pairs[i].tox1], address);
- int test = tox_add_friend(toxes[pairs[i].tox2], address, (uint8_t *)"Gentoo", 7);
-
- if (test == TOX_FAERR_ALREADYSENT) {
- goto loop_top;
- }
-
- ck_assert_msg(test >= 0, "Failed to add friend error code: %i", test);
- }
-
- while (1) {
- uint16_t counter = 0;
-
- for (i = 0; i < NUM_TOXES; ++i) {
- for (j = 0; j < tox_count_friendlist(toxes[i]); ++j)
- if (tox_get_friend_connection_status(toxes[i], j) == 1)
- ++counter;
- }
-
- if (counter == NUM_FRIENDS * 2) {
- break;
- }
-
- for (i = 0; i < NUM_TOXES; ++i) {
- tox_do(toxes[i]);
- }
-
- c_sleep(50);
- }
-
- printf("test_many_clients succeeded, took %llu seconds\n", time(NULL) - cur_time);
-
- for (i = 0; i < NUM_TOXES; ++i) {
- tox_kill(toxes[i]);
- }
-}
-END_TEST
-
-#define DEFTESTCASE(NAME) \
- TCase *tc_##NAME = tcase_create(#NAME); \
- tcase_add_test(tc_##NAME, test_##NAME); \
- suite_add_tcase(s, tc_##NAME);
-
-#define DEFTESTCASE_SLOW(NAME, TIMEOUT) \
- DEFTESTCASE(NAME) \
- tcase_set_timeout(tc_##NAME, TIMEOUT);
-Suite *tox_suite(void)
-{
- Suite *s = suite_create("Tox");
-
- DEFTESTCASE_SLOW(few_clients, 50);
- DEFTESTCASE_SLOW(many_clients, 150);
- return s;
-}
-
-int main(int argc, char *argv[])
-{
- srand((unsigned int) time(NULL));
-
- Suite *tox = tox_suite();
- SRunner *test_runner = srunner_create(tox);
-
- int number_failed = 0;
- srunner_run_all(test_runner, CK_NORMAL);
- number_failed = srunner_ntests_failed(test_runner);
-
- srunner_free(test_runner);
-
- return number_failed;
-}
-
diff --git a/protocols/Tox/toxcore/auto_tests/toxav_basic_test.c b/protocols/Tox/toxcore/auto_tests/toxav_basic_test.c
deleted file mode 100644
index 57685bfca7..0000000000
--- a/protocols/Tox/toxcore/auto_tests/toxav_basic_test.c
+++ /dev/null
@@ -1,599 +0,0 @@
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <sys/types.h>
-#include <stdint.h>
-#include <string.h>
-#include <stdio.h>
-#include <check.h>
-#include <stdlib.h>
-#include <time.h>
-#include <assert.h>
-
-#include "../toxcore/tox.h"
-#include "../toxcore/logger.h"
-#include "../toxcore/crypto_core.h"
-#include "../toxav/toxav.h"
-
-#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
-#define c_sleep(x) Sleep(1*x)
-#else
-#include <unistd.h>
-#define c_sleep(x) usleep(1000*x)
-#endif
-
-
-
-typedef enum _CallStatus {
- none,
- InCall,
- Ringing,
- Ended,
- Rejected,
- Cancel,
- TimedOut
-
-} CallStatus;
-
-typedef struct _Party {
- CallStatus status;
- ToxAv *av;
- time_t *CallStarted;
- int call_index;
-} Party;
-
-typedef struct _Status {
- Party Alice;
- Party Bob;
-} Status;
-
-/* My default settings */
-static ToxAvCSettings muhcaps;
-
-void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
-{
- if (length == 7 && memcmp("gentoo", data, 7) == 0) {
- tox_add_friend_norequest(m, public_key);
- }
-}
-
-
-/******************************************************************************/
-void callback_recv_invite ( void *av, int32_t call_index, void *_arg )
-{
- Status *cast = _arg;
-
- /* Bob always receives invite */
- cast->Bob.status = Ringing;
- cast->Bob.call_index = call_index;
-}
-void callback_recv_ringing ( void *av, int32_t call_index, void *_arg )
-{
- Status *cast = _arg;
-
- /* Alice always sends invite */
- cast->Alice.status = Ringing;
-}
-void callback_recv_starting ( void *av, int32_t call_index, void *_arg )
-{
- Status *cast = _arg;
-
- /* Alice always sends invite */
- printf("Call started on Alice side...\n");
- cast->Alice.status = InCall;
- toxav_prepare_transmission(av, call_index, av_jbufdc, av_VADd, 1);
-}
-void callback_recv_ending ( void *av, int32_t call_index, void *_arg )
-{
- Status *cast = _arg;
-
- if ( cast->Alice.status == Rejected) {
- printf ( "Call ended for Bob!\n" );
- cast->Bob.status = Ended;
- } else {
- printf ( "Call ended for Alice!\n" );
- cast->Alice.status = Ended;
- }
-}
-
-
-void callback_call_started ( void *av, int32_t call_index, void *_arg )
-{
- Status *cast = _arg;
-
- /* Alice always sends invite */
- printf("Call started on Bob side...\n");
- cast->Bob.status = InCall;
- toxav_prepare_transmission(av, call_index, av_jbufdc, av_VADd, 1);
-}
-void callback_call_canceled ( void *av, int32_t call_index, void *_arg )
-{
- Status *cast = _arg;
-
- printf ( "Call Canceled for Bob!\n" );
- cast->Bob.status = Cancel;
-}
-void callback_call_rejected ( void *av, int32_t call_index, void *_arg )
-{
- Status *cast = _arg;
-
- printf ( "Call rejected by Bob!\n"
- "Call ended for Alice!\n" );
- /* If Bob rejects, call is ended for alice and she sends ending */
- cast->Alice.status = Rejected;
-}
-void callback_call_ended ( void *av, int32_t call_index, void *_arg )
-{
- Status *cast = _arg;
-
- printf ( "Call ended for Bob!\n" );
- cast->Bob.status = Ended;
-}
-
-void callback_call_type_change ( void *av, int32_t call_index, void *_arg )
-{
- ToxAvCSettings csettings;
- toxav_get_peer_csettings(av, call_index, 0, &csettings);
-
- printf("New settings: \n"
- "Type: %u \n"
- "Video bitrate: %u \n"
- "Video height: %u \n"
- "Video width: %u \n"
- "Audio bitrate: %u \n"
- "Audio framedur: %u \n"
- "Audio sample rate: %u \n"
- "Audio channels: %u \n",
- csettings.call_type,
- csettings.video_bitrate,
- csettings.max_video_height,
- csettings.max_video_width,
- csettings.audio_bitrate,
- csettings.audio_frame_duration,
- csettings.audio_sample_rate,
- csettings.audio_channels
- );
-}
-
-void callback_requ_timeout ( void *av, int32_t call_index, void *_arg )
-{
- Status *cast = _arg;
- printf("Call timed-out!\n");
- cast->Alice.status = TimedOut;
-}
-
-static void callback_audio(ToxAv *av, int32_t call_index, int16_t *data, int length, void *userdata)
-{
-}
-
-static void callback_video(ToxAv *av, int32_t call_index, vpx_image_t *img, void *userdata)
-{
-}
-
-void register_callbacks(ToxAv *av, void *data)
-{
- toxav_register_callstate_callback(av, callback_call_started, av_OnStart, data);
- toxav_register_callstate_callback(av, callback_call_canceled, av_OnCancel, data);
- toxav_register_callstate_callback(av, callback_call_rejected, av_OnReject, data);
- toxav_register_callstate_callback(av, callback_call_ended, av_OnEnd, data);
- toxav_register_callstate_callback(av, callback_recv_invite, av_OnInvite, data);
-
- toxav_register_callstate_callback(av, callback_recv_ringing, av_OnRinging, data);
- toxav_register_callstate_callback(av, callback_recv_starting, av_OnStarting, data);
- toxav_register_callstate_callback(av, callback_recv_ending, av_OnEnding, data);
-
- toxav_register_callstate_callback(av, callback_requ_timeout, av_OnRequestTimeout, data);
- toxav_register_callstate_callback(av, callback_call_type_change, av_OnMediaChange, data);
-
-
- toxav_register_audio_recv_callback(av, callback_audio, NULL);
- toxav_register_video_recv_callback(av, callback_video, NULL);
-}
-
-
-/*************************************************************************************************/
-
-/* Alice calls bob and the call starts.
- * What happens during the call is defined after. To quit the loop use: step++;
- */
-#define CALL_AND_START_LOOP(AliceCallType, BobCallType) \
-{ int step = 0, running = 1; while (running) {\
- tox_do(bootstrap_node); tox_do(Alice); tox_do(Bob); \
- switch ( step ) {\
- case 0: /* Alice */ printf("Alice is calling...\n");\
- toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, &muhcaps, 10); step++; break;\
- case 1: /* Bob */ if (status_control.Bob.status == Ringing) { printf("Bob answers...\n");\
- cur_time = time(NULL); toxav_answer(status_control.Bob.av, status_control.Bob.call_index, &muhcaps); step++; } break; \
- case 2: /* Rtp transmission */ \
- if (status_control.Bob.status == InCall && status_control.Alice.status == InCall)
-
-
-#define TERMINATE_SCOPE() break;\
-case 3: /* Wait for Both to have status ended */\
-if (status_control.Alice.status == Ended && status_control.Bob.status == Ended) running = 0; break; } c_sleep(20); } } printf("\n");
-
-START_TEST(test_AV_flows)
-// int test_AV_flows()
-{
- long long unsigned int cur_time = time(NULL);
- Tox *bootstrap_node = tox_new(0);
- Tox *Alice = tox_new(0);
- Tox *Bob = tox_new(0);
-
- ck_assert_msg(bootstrap_node || Alice || Bob, "Failed to create 3 tox instances");
-
- uint32_t to_compare = 974536;
- tox_callback_friend_request(Alice, accept_friend_request, &to_compare);
- uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
- tox_get_address(Alice, address);
- int test = tox_add_friend(Bob, address, (uint8_t *)"gentoo", 7);
-
- ck_assert_msg(test == 0, "Failed to add friend error code: %i", test);
-
- uint8_t off = 1;
-
- while (1) {
- tox_do(bootstrap_node);
- tox_do(Alice);
- tox_do(Bob);
-
- if (tox_isconnected(bootstrap_node) && tox_isconnected(Alice) && tox_isconnected(Bob) && off) {
- printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time);
- off = 0;
- }
-
- if (tox_get_friend_connection_status(Alice, 0) == 1 && tox_get_friend_connection_status(Bob, 0) == 1)
- break;
-
- c_sleep(20);
- }
-
- printf("All set after %llu seconds! Starting call...\n", time(NULL) - cur_time);
-
- muhcaps = av_DefaultSettings;
- muhcaps.max_video_height = muhcaps.max_video_width = 128;
-
- Status status_control = {
- {none, toxav_new(Alice, 1), NULL, -1},
- {none, toxav_new(Bob, 1), NULL, -1},
- };
-
- ck_assert_msg(status_control.Alice.av || status_control.Bob.av, "Failed to create 2 toxav instances");
-
-
- register_callbacks(status_control.Alice.av, &status_control);
- register_callbacks(status_control.Bob.av, &status_control);
-
- const int frame_size = (av_DefaultSettings.audio_sample_rate * av_DefaultSettings.audio_frame_duration / 1000);
- int16_t sample_payload[frame_size];
- randombytes((uint8_t *)sample_payload, sizeof(int16_t) * frame_size);
-
- uint8_t prepared_payload[RTP_PAYLOAD_SIZE];
- int payload_size;
-
- vpx_image_t *sample_image = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, 128, 128, 1);
-
- memcpy(sample_image->planes[VPX_PLANE_Y], sample_payload, 10);
- memcpy(sample_image->planes[VPX_PLANE_U], sample_payload, 10);
- memcpy(sample_image->planes[VPX_PLANE_V], sample_payload, 10);
-
-
- /*************************************************************************************************
- * Successful flows (when call starts)
- */
-
- /*
- * Call with audio only on both sides. Alice calls Bob.
- */
-
-
- CALL_AND_START_LOOP(TypeAudio, TypeAudio) {
- /* Both send */
- payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload,
- 1000, sample_payload, frame_size);
-
- if ( payload_size < 0 ) {
- ck_assert_msg ( 0, "Failed to encode payload" );
- }
-
- toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
-
- payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000,
- sample_payload, frame_size);
-
- if ( payload_size < 0 ) {
- ck_assert_msg ( 0, "Failed to encode payload" );
- }
-
- toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
-
- if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */
- step++; /* This terminates the loop */
- toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index);
- toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index);
-
- /* Call over Alice hangs up */
- toxav_hangup(status_control.Alice.av, status_control.Alice.call_index);
- }
- }
- TERMINATE_SCOPE()
-
-
- /*
- * Call with audio on both sides and video on one side. Alice calls Bob.
- */
- CALL_AND_START_LOOP(TypeAudio, TypeVideo) {
- /* Both send */
- payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload,
- 1000, sample_payload, frame_size);
-
- if ( payload_size < 0 ) {
- ck_assert_msg ( 0, "Failed to encode payload" );
- }
-
- toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
-
- payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000,
- sample_payload, frame_size);
-
- if ( payload_size < 0 ) {
- ck_assert_msg ( 0, "Failed to encode payload" );
- }
-
- toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
-
-// toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image);
-
- if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */
- step++; /* This terminates the loop */
- toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index);
- toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index);
-
- /* Call over Alice hangs up */
- toxav_hangup(status_control.Alice.av, status_control.Alice.call_index);
- }
- }
- TERMINATE_SCOPE()
-
-
- /*
- * Call with audio and video on both sides. Alice calls Bob.
- */
- CALL_AND_START_LOOP(TypeVideo, TypeVideo) {
- /* Both send */
-
- payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload,
- 1000, sample_payload, frame_size);
-
- if ( payload_size < 0 ) {
- ck_assert_msg ( 0, "Failed to encode payload" );
- }
-
- toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
-
- payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000,
- sample_payload, frame_size);
-
- if ( payload_size < 0 ) {
- ck_assert_msg ( 0, "Failed to encode payload" );
- }
-
- toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
-
-// toxav_send_video(status_control.Alice.av, status_control.Alice.call_index, sample_image);
-// toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image);
-
-
- if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */
- step++; /* This terminates the loop */
- toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index);
- toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index);
-
- /* Call over Alice hangs up */
- toxav_hangup(status_control.Alice.av, status_control.Alice.call_index);
- }
- }
- TERMINATE_SCOPE()
-
-
- uint64_t times_they_are_a_changin = time(NULL);
- /* Media change */
- CALL_AND_START_LOOP(TypeAudio, TypeAudio) {
- /* Both send */
- payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload,
- 1000, sample_payload, frame_size);
-
- if ( payload_size < 0 ) {
- ck_assert_msg ( 0, "Failed to encode payload" );
- }
-
- toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
-
- payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000,
- sample_payload, frame_size);
-
- if ( payload_size < 0 ) {
- ck_assert_msg ( 0, "Failed to encode payload" );
- }
-
- toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
-
- /* Wait 2 seconds and change transmission type */
- if (time(NULL) - times_they_are_a_changin > 2) {
- times_they_are_a_changin = time(NULL);
- muhcaps.audio_bitrate ++;
- toxav_change_settings(status_control.Alice.av, status_control.Alice.call_index, &muhcaps);
- }
-
- if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */
- step++; /* This terminates the loop */
- toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index);
- toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index);
-
- /* Call over Alice hangs up */
- toxav_hangup(status_control.Alice.av, status_control.Alice.call_index);
- }
- }
- TERMINATE_SCOPE()
-
-
- /*************************************************************************************************
- * Other flows
- */
-
- /*
- * Call and reject
- */
- {
- int step = 0;
- int running = 1;
-
- while (running) {
- tox_do(bootstrap_node);
- tox_do(Alice);
- tox_do(Bob);
-
- switch ( step ) {
- case 0: /* Alice */
- printf("Alice is calling...\n");
- toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, &muhcaps, 10);
- step++;
- break;
-
- case 1: /* Bob */
- if (status_control.Bob.status == Ringing) {
- printf("Bob rejects...\n");
- toxav_reject(status_control.Bob.av, status_control.Bob.call_index, "Who likes D's anyway?");
- step++;
- }
-
- break;
-
- case 2: /* Wait for Both to have status ended */
- if (status_control.Alice.status == Rejected && status_control.Bob.status == Ended) running = 0;
-
- break;
- }
-
- c_sleep(20);
- }
-
- printf("\n");
- }
-
-
- /*
- * Call and cancel
- */
- {
- int step = 0;
- int running = 1;
-
- while (running) {
- tox_do(bootstrap_node);
- tox_do(Alice);
- tox_do(Bob);
-
- switch ( step ) {
- case 0: /* Alice */
- printf("Alice is calling...\n");
- toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, &muhcaps, 10);
- step++;
- break;
-
-
- case 1: /* Alice again */
- if (status_control.Bob.status == Ringing) {
- printf("Alice cancels...\n");
- toxav_cancel(status_control.Alice.av, status_control.Alice.call_index, 0, "Who likes D's anyway?");
- step++;
- }
-
- break;
-
- case 2: /* Wait for Both to have status ended */
- if (status_control.Bob.status == Cancel) running = 0;
-
- break;
- }
-
- c_sleep(20);
- }
-
- printf("\n");
- }
-
- /*
- * Timeout
- */
- {
- int step = 0;
- int running = 1;
-
- while (running) {
- tox_do(bootstrap_node);
- tox_do(Alice);
- tox_do(Bob);
-
- switch ( step ) {
- case 0:
- printf("Alice is calling...\n");
- toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, &muhcaps, 10);
- step++;
- break;
-
- case 1:
- if (status_control.Alice.status == TimedOut) running = 0;
-
- break;
- }
-
- c_sleep(20);
- }
-
- printf("\n");
- }
-
-
-
-
- printf("Calls ended!\n");
-}
-END_TEST
-
-/*************************************************************************************************/
-
-
-/*************************************************************************************************/
-
-/*************************************************************************************************/
-
-
-Suite *tox_suite(void)
-{
- Suite *s = suite_create("ToxAV");
-
- TCase *tc_av_flows = tcase_create("AV_flows");
- tcase_add_test(tc_av_flows, test_AV_flows);
- tcase_set_timeout(tc_av_flows, 200);
- suite_add_tcase(s, tc_av_flows);
-
- return s;
-}
-int main(int argc, char *argv[])
-{
- Suite *tox = tox_suite();
- SRunner *test_runner = srunner_create(tox);
-
- setbuf(stdout, NULL);
-
- srunner_run_all(test_runner, CK_NORMAL);
- int number_failed = srunner_ntests_failed(test_runner);
-
- srunner_free(test_runner);
-
- return number_failed;
-
-// return test_AV_flows();
-}
diff --git a/protocols/Tox/toxcore/auto_tests/toxav_many_test.c b/protocols/Tox/toxcore/auto_tests/toxav_many_test.c
deleted file mode 100644
index d9c588f728..0000000000
--- a/protocols/Tox/toxcore/auto_tests/toxav_many_test.c
+++ /dev/null
@@ -1,402 +0,0 @@
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <sys/types.h>
-#include <stdint.h>
-#include <string.h>
-#include <stdio.h>
-#include <check.h>
-#include <stdlib.h>
-#include <time.h>
-#include <assert.h>
-
-#include "../toxcore/tox.h"
-#include "../toxcore/logger.h"
-#include "../toxcore/crypto_core.h"
-#include "../toxav/toxav.h"
-
-#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
-#define c_sleep(x) Sleep(1*x)
-#else
-#include <unistd.h>
-#include <pthread.h>
-#define c_sleep(x) usleep(1000*x)
-#endif
-
-pthread_mutex_t muhmutex;
-
-typedef enum _CallStatus {
- none,
- InCall,
- Ringing,
- Ended,
- Rejected,
- Cancel
-
-} CallStatus;
-
-typedef struct _Party {
- CallStatus status;
- ToxAv *av;
- int id;
-} Party;
-
-typedef struct _ACall {
- pthread_t tid;
- int idx;
-
- Party Caller;
- Party Callee;
-} ACall;
-
-typedef struct _Status {
- ACall calls[3]; /* Make 3 calls for this test */
-} Status;
-
-Status status_control;
-
-void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
-{
- if (length == 7 && memcmp("gentoo", data, 7) == 0) {
- tox_add_friend_norequest(m, public_key);
- }
-}
-
-
-/******************************************************************************/
-void callback_recv_invite ( void *av, int32_t call_index, void *_arg )
-{
- /*
- Status *cast = _arg;
-
- cast->calls[call_index].Callee.status = Ringing;*/
-}
-void callback_recv_ringing ( void *av, int32_t call_index, void *_arg )
-{
- Status *cast = _arg;
- cast->calls[call_index].Caller.status = Ringing;
-}
-void callback_recv_starting ( void *av, int32_t call_index, void *_arg )
-{
- Status *cast = _arg;
- cast->calls[call_index].Caller.status = InCall;
-}
-void callback_recv_ending ( void *av, int32_t call_index, void *_arg )
-{
- Status *cast = _arg;
- cast->calls[call_index].Caller.status = Ended;
-}
-
-void callback_call_started ( void *av, int32_t call_index, void *_arg )
-{
- /*
- Status *cast = _arg;
-
- cast->calls[call_index].Callee.status = InCall;*/
-}
-void callback_call_canceled ( void *av, int32_t call_index, void *_arg )
-{
- /*
- Status *cast = _arg;
-
- cast->calls[call_index].Callee.status = Cancel;*/
-}
-void callback_call_rejected ( void *av, int32_t call_index, void *_arg )
-{
- Status *cast = _arg;
- cast->calls[call_index].Caller.status = Rejected;
-}
-void callback_call_ended ( void *av, int32_t call_index, void *_arg )
-{
- /*
- Status *cast = _arg;
-
- cast->calls[call_index].Callee.status = Ended;*/
-}
-
-void callback_requ_timeout ( void *av, int32_t call_index, void *_arg )
-{
- //ck_assert_msg(0, "No answer!");
-}
-
-static void callback_audio(ToxAv *av, int32_t call_index, int16_t *data, int length, void *userdata)
-{
-}
-
-static void callback_video(ToxAv *av, int32_t call_index, vpx_image_t *img, void *userdata)
-{
-}
-
-void register_callbacks(ToxAv *av, void *data)
-{
- toxav_register_callstate_callback(av, callback_call_started, av_OnStart, data);
- toxav_register_callstate_callback(av, callback_call_canceled, av_OnCancel, data);
- toxav_register_callstate_callback(av, callback_call_rejected, av_OnReject, data);
- toxav_register_callstate_callback(av, callback_call_ended, av_OnEnd, data);
- toxav_register_callstate_callback(av, callback_recv_invite, av_OnInvite, data);
-
- toxav_register_callstate_callback(av, callback_recv_ringing, av_OnRinging, data);
- toxav_register_callstate_callback(av, callback_recv_starting, av_OnStarting, data);
- toxav_register_callstate_callback(av, callback_recv_ending, av_OnEnding, data);
-
- toxav_register_callstate_callback(av, callback_requ_timeout, av_OnRequestTimeout, data);
-
-
- toxav_register_audio_recv_callback(av, callback_audio, NULL);
- toxav_register_video_recv_callback(av, callback_video, NULL);
-}
-/*************************************************************************************************/
-
-int call_running[3];
-
-void *in_thread_call (void *arg)
-{
-#define call_print(call, what, args...) printf("[%d] " what "\n", call, ##args)
-
- ACall *this_call = arg;
- uint64_t start = 0;
- int step = 0;
- int call_idx;
-
- call_running[this_call->idx] = 1;
-
- const int frame_size = (av_DefaultSettings.audio_sample_rate * av_DefaultSettings.audio_frame_duration / 1000);
- int16_t sample_payload[frame_size];
- randombytes((uint8_t *)sample_payload, sizeof(int16_t) * frame_size);
-
- uint8_t prepared_payload[RTP_PAYLOAD_SIZE];
-
- register_callbacks(this_call->Caller.av, &status_control);
- register_callbacks(this_call->Callee.av, arg);
-
- /* NOTE: CALLEE WILL ALWAHYS NEED CALL_IDX == 0 */
- while (call_running[this_call->idx]) {
-
- switch ( step ) {
- case 0: /* CALLER */
- toxav_call(this_call->Caller.av, &call_idx, this_call->Callee.id, &av_DefaultSettings, 10);
- call_print(call_idx, "Calling ...");
- step++;
- break;
-
- case 1: /* CALLEE */
- if (this_call->Caller.status == Ringing) {
- call_print(call_idx, "Callee answers ...");
- toxav_answer(this_call->Callee.av, 0, &av_DefaultSettings);
- step++;
- start = time(NULL);
- }
-
- break;
-
- case 2: /* Rtp transmission */
- if (this_call->Caller.status == InCall) { /* I think this is okay */
- call_print(call_idx, "Sending rtp ...");
-
- c_sleep(1000); /* We have race condition here */
- toxav_prepare_transmission(this_call->Callee.av, 0, 3, 0, 1);
- toxav_prepare_transmission(this_call->Caller.av, call_idx, 3, 0, 1);
-
- int payload_size = toxav_prepare_audio_frame(this_call->Caller.av, call_idx, prepared_payload, RTP_PAYLOAD_SIZE,
- sample_payload, frame_size);
-
- if ( payload_size < 0 ) {
- //ck_assert_msg ( 0, "Failed to encode payload" );
- }
-
-
- while (time(NULL) - start < 10) { /* 10 seconds */
- /* Both send */
- toxav_send_audio(this_call->Caller.av, call_idx, prepared_payload, payload_size);
-
- toxav_send_audio(this_call->Callee.av, 0, prepared_payload, payload_size);
-
- /* Both receive */
- int16_t storage[RTP_PAYLOAD_SIZE];
- int recved;
-
- c_sleep(20);
- }
-
- step++; /* This terminates the loop */
-
- pthread_mutex_lock(&muhmutex);
- toxav_kill_transmission(this_call->Callee.av, 0);
- toxav_kill_transmission(this_call->Caller.av, call_idx);
- pthread_mutex_unlock(&muhmutex);
-
- /* Call over CALLER hangs up */
- toxav_hangup(this_call->Caller.av, call_idx);
- call_print(call_idx, "Hanging up ...");
- }
-
- break;
-
- case 3: /* Wait for Both to have status ended */
- if (this_call->Caller.status == Ended) {
- c_sleep(1000); /* race condition */
- this_call->Callee.status = Ended;
- call_running[this_call->idx] = 0;
- }
-
- break;
-
- }
-
- c_sleep(20);
- }
-
- call_print(call_idx, "Call ended successfully!");
- pthread_exit(NULL);
-}
-
-
-
-
-
-// START_TEST(test_AV_three_calls)
-void test_AV_three_calls()
-{
- long long unsigned int cur_time = time(NULL);
- Tox *bootstrap_node = tox_new(0);
- Tox *caller = tox_new(0);
- Tox *callees[3] = {
- tox_new(0),
- tox_new(0),
- tox_new(0),
- };
-
-
- //ck_assert_msg(bootstrap_node != NULL, "Failed to create bootstrap node");
-
- int i = 0;
-
- for (; i < 3; i ++) {
- //ck_assert_msg(callees[i] != NULL, "Failed to create 3 tox instances");
- }
-
- for ( i = 0; i < 3; i ++ ) {
- uint32_t to_compare = 974536;
- tox_callback_friend_request(callees[i], accept_friend_request, &to_compare);
- uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
- tox_get_address(callees[i], address);
-
- int test = tox_add_friend(caller, address, (uint8_t *)"gentoo", 7);
- //ck_assert_msg( test == i, "Failed to add friend error code: %i", test);
- }
-
- uint8_t off = 1;
-
- while (1) {
- tox_do(bootstrap_node);
- tox_do(caller);
-
- for (i = 0; i < 3; i ++) {
- tox_do(callees[i]);
- }
-
-
- if (tox_isconnected(bootstrap_node) &&
- tox_isconnected(caller) &&
- tox_isconnected(callees[0]) &&
- tox_isconnected(callees[1]) &&
- tox_isconnected(callees[2]) && off) {
- printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time);
- off = 0;
- }
-
-
- if (tox_get_friend_connection_status(caller, 0) == 1 &&
- tox_get_friend_connection_status(caller, 1) == 1 &&
- tox_get_friend_connection_status(caller, 2) == 1 )
- break;
-
- c_sleep(20);
- }
-
- printf("All set after %llu seconds! Starting call...\n", time(NULL) - cur_time);
-
- ToxAv *uniqcallerav = toxav_new(caller, 3);
-
- for (i = 0; i < 3; i ++) {
- status_control.calls[i].idx = i;
-
- status_control.calls[i].Caller.av = uniqcallerav;
- status_control.calls[i].Caller.id = 0;
- status_control.calls[i].Caller.status = none;
-
- status_control.calls[i].Callee.av = toxav_new(callees[i], 1);
- status_control.calls[i].Callee.id = i;
- status_control.calls[i].Callee.status = none;
- }
-
- pthread_mutex_init(&muhmutex, NULL);
-
- for ( i = 0; i < 3; i++ )
- pthread_create(&status_control.calls[i].tid, NULL, in_thread_call, &status_control.calls[i]);
-
- /* Now start 3 calls and they'll run for 10 s */
-
- for ( i = 0; i < 3; i++ )
- pthread_detach(status_control.calls[i].tid);
-
- while (call_running[0] || call_running[1] || call_running[2]) {
- pthread_mutex_lock(&muhmutex);
-
- tox_do(bootstrap_node);
- tox_do(caller);
- tox_do(callees[0]);
- tox_do(callees[1]);
- tox_do(callees[2]);
-
- pthread_mutex_unlock(&muhmutex);
- c_sleep(20);
- }
-
- toxav_kill(status_control.calls[0].Caller.av);
- toxav_kill(status_control.calls[0].Callee.av);
- toxav_kill(status_control.calls[1].Callee.av);
- toxav_kill(status_control.calls[2].Callee.av);
-
- tox_kill(bootstrap_node);
- tox_kill(caller);
-
- for ( i = 0; i < 3; i ++)
- tox_kill(callees[i]);
-
-}
-// END_TEST
-
-
-
-
-Suite *tox_suite(void)
-{
- Suite *s = suite_create("ToxAV");
-
- TCase *tc_av_three_calls = tcase_create("AV_three_calls");
- tcase_add_test(tc_av_three_calls, test_AV_three_calls);
- tcase_set_timeout(tc_av_three_calls, 150);
- suite_add_tcase(s, tc_av_three_calls);
-
- return s;
-}
-int main(int argc, char *argv[])
-{
-// Suite *tox = tox_suite();
-// SRunner *test_runner = srunner_create(tox);
-//
-// setbuf(stdout, NULL);
-//
-// srunner_run_all(test_runner, CK_NORMAL);
-// int number_failed = srunner_ntests_failed(test_runner);
-//
-// srunner_free(test_runner);
-//
-// return number_failed;
-
- test_AV_three_calls();
-
- return 0;
-}