From 2328cb74abccd563f0cd8d14d30e5314822d321e Mon Sep 17 00:00:00 2001 From: iphydf Date: Mon, 19 Dec 2016 15:27:46 +0000 Subject: Improve documentation of crypto_core. --- auto_tests/dht_test.c | 10 +++++++--- auto_tests/messenger_test.c | 34 ++++++++++++++++++++++------------ auto_tests/toxav_basic_test.c | 3 ++- auto_tests/toxav_many_test.c | 3 ++- 4 files changed, 33 insertions(+), 17 deletions(-) (limited to 'auto_tests') diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c index 7734e64a..9cec1643 100644 --- a/auto_tests/dht_test.c +++ b/auto_tests/dht_test.c @@ -2,13 +2,13 @@ #include "config.h" #endif -#include -#include +#include "helpers.h" #include "../toxcore/DHT.c" #include "../toxcore/tox.h" -#include "helpers.h" +#include +#include // These tests currently fail. @@ -299,6 +299,10 @@ static void test_addto_lists_good(DHT *dht, ck_assert_msg(client_in_list(list, length, public_key) == -1, "Good client id is in the list"); } +#ifndef MAX +#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#endif + static void test_addto_lists(IP ip) { Networking_Core *net = new_networking(NULL, ip, TOX_PORT_DEFAULT); diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c index eed52a31..03697ce6 100644 --- a/auto_tests/messenger_test.c +++ b/auto_tests/messenger_test.c @@ -14,18 +14,27 @@ #include "config.h" #endif +#include "helpers.h" + #include "../testing/misc_tools.c" // hex_string_to_bin #include "../toxcore/Messenger.h" + #include #include #include #include -#include "helpers.h" +#if VANILLA_NACL +#include // crypto_box_PUBLICKEYBYTES and other defines. +#else +#include +#endif #define REALLY_BIG_NUMBER ((1) << (sizeof(uint16_t) * 7)) #define STRINGS_EQUAL(X, Y) (strcmp(X, Y) == 0) +static bool enable_broken_tests = false; + static const char *friend_id_str = "e4b3d5030bc99494605aecc33ceec8875640c1d74aa32790e821b17e98771c4a00000000f1db"; /* in case we need more than one ID for a test */ @@ -121,11 +130,10 @@ START_TEST(test_m_delfriend) } END_TEST -#if 0 START_TEST(test_m_addfriend) { - char *good_data = "test"; - char *bad_data = ""; + const char *good_data = "test"; + const char *bad_data = ""; int good_len = strlen(good_data); int bad_len = strlen(bad_data); @@ -134,30 +142,29 @@ START_TEST(test_m_addfriend) + crypto_box_ZEROBYTES + 100); /* TODO(irungentoo): Update this properly to latest master */ - if (m_addfriend(m, (uint8_t *)friend_id, (uint8_t *)good_data, really_bad_len) != FAERR_TOOLONG) { + if (m_addfriend(m, (const uint8_t *)friend_id, (const 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 return an error if the original m_addfriend_norequest() failed */ - if (m_addfriend(m, (uint8_t *)friend_id, (uint8_t *)good_data, good_len) != FAERR_ALREADYSENT) { + if (m_addfriend(m, (const uint8_t *)friend_id, (const 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) { + if (m_addfriend(m, (const uint8_t *)good_id_b, (const 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 return an error */ /* TODO(irungentoo): validate client_id in m_addfriend? */ - if (m_addfriend((uint8_t *)bad_id, (uint8_t *)good_data, good_len) >= 0) { + if (m_addfriend(m, (const uint8_t *)bad_id, (const 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 -#endif START_TEST(test_setname) { @@ -193,7 +200,7 @@ END_TEST * ideas: * if we have access to the friends list, we could * just add a status manually ourselves. */ -/* +#if 0 START_TEST(test_m_copy_userstatus) { assert(m_copy_userstatus(-1, buf, MAX_USERSTATUS_LENGTH) == -1); @@ -203,7 +210,7 @@ START_TEST(test_m_copy_userstatus) assert(STRINGS_EQUAL(name_buf, friend_id_status)); } END_TEST -*/ +#endif START_TEST(test_getname) { @@ -316,7 +323,10 @@ static Suite *messenger_suite(void) DEFTESTCASE(m_get_userstatus_size); DEFTESTCASE(m_set_userstatus); - /* DEFTESTCASE(m_addfriend); */ + if (enable_broken_tests) { + DEFTESTCASE(m_addfriend); + } + DEFTESTCASE(m_friend_exists); DEFTESTCASE(m_get_friend_connectionstatus); DEFTESTCASE(m_delfriend); diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index b5028da4..767fca87 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c @@ -20,7 +20,8 @@ #include "../toxcore/util.h" -#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) +#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) +#include #define c_sleep(x) Sleep(1*x) #else #include diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index 59e4f94b..b33b93c8 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c @@ -19,7 +19,8 @@ #include "../toxcore/tox.h" #include "../toxcore/util.h" -#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) +#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) +#include #define c_sleep(x) Sleep(1*x) #else #include -- cgit v1.2.3