diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-12-19 15:27:46 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-12-22 10:26:59 +0000 |
commit | 2328cb74abccd563f0cd8d14d30e5314822d321e (patch) | |
tree | b61581536d448a8846dc333b44c9b56e24605a1f /auto_tests | |
parent | ce29c8e7ec91d95167b2dea3aee9fd1ae1aac254 (diff) |
Improve documentation of crypto_core.
Diffstat (limited to 'auto_tests')
-rw-r--r-- | auto_tests/dht_test.c | 10 | ||||
-rw-r--r-- | auto_tests/messenger_test.c | 34 | ||||
-rw-r--r-- | auto_tests/toxav_basic_test.c | 3 | ||||
-rw-r--r-- | auto_tests/toxav_many_test.c | 3 |
4 files changed, 33 insertions, 17 deletions
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 @@ | |||
2 | #include "config.h" | 2 | #include "config.h" |
3 | #endif | 3 | #endif |
4 | 4 | ||
5 | #include <sys/param.h> | 5 | #include "helpers.h" |
6 | #include <time.h> | ||
7 | 6 | ||
8 | #include "../toxcore/DHT.c" | 7 | #include "../toxcore/DHT.c" |
9 | #include "../toxcore/tox.h" | 8 | #include "../toxcore/tox.h" |
10 | 9 | ||
11 | #include "helpers.h" | 10 | #include <sys/param.h> |
11 | #include <time.h> | ||
12 | 12 | ||
13 | 13 | ||
14 | // These tests currently fail. | 14 | // These tests currently fail. |
@@ -299,6 +299,10 @@ static void test_addto_lists_good(DHT *dht, | |||
299 | ck_assert_msg(client_in_list(list, length, public_key) == -1, "Good client id is in the list"); | 299 | ck_assert_msg(client_in_list(list, length, public_key) == -1, "Good client id is in the list"); |
300 | } | 300 | } |
301 | 301 | ||
302 | #ifndef MAX | ||
303 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) | ||
304 | #endif | ||
305 | |||
302 | static void test_addto_lists(IP ip) | 306 | static void test_addto_lists(IP ip) |
303 | { | 307 | { |
304 | Networking_Core *net = new_networking(NULL, ip, TOX_PORT_DEFAULT); | 308 | 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 @@ | |||
14 | #include "config.h" | 14 | #include "config.h" |
15 | #endif | 15 | #endif |
16 | 16 | ||
17 | #include "helpers.h" | ||
18 | |||
17 | #include "../testing/misc_tools.c" // hex_string_to_bin | 19 | #include "../testing/misc_tools.c" // hex_string_to_bin |
18 | #include "../toxcore/Messenger.h" | 20 | #include "../toxcore/Messenger.h" |
21 | |||
19 | #include <check.h> | 22 | #include <check.h> |
20 | #include <stdint.h> | 23 | #include <stdint.h> |
21 | #include <string.h> | 24 | #include <string.h> |
22 | #include <sys/types.h> | 25 | #include <sys/types.h> |
23 | 26 | ||
24 | #include "helpers.h" | 27 | #if VANILLA_NACL |
28 | #include <crypto_box.h> // crypto_box_PUBLICKEYBYTES and other defines. | ||
29 | #else | ||
30 | #include <sodium.h> | ||
31 | #endif | ||
25 | 32 | ||
26 | #define REALLY_BIG_NUMBER ((1) << (sizeof(uint16_t) * 7)) | 33 | #define REALLY_BIG_NUMBER ((1) << (sizeof(uint16_t) * 7)) |
27 | #define STRINGS_EQUAL(X, Y) (strcmp(X, Y) == 0) | 34 | #define STRINGS_EQUAL(X, Y) (strcmp(X, Y) == 0) |
28 | 35 | ||
36 | static bool enable_broken_tests = false; | ||
37 | |||
29 | static const char *friend_id_str = "e4b3d5030bc99494605aecc33ceec8875640c1d74aa32790e821b17e98771c4a00000000f1db"; | 38 | static const char *friend_id_str = "e4b3d5030bc99494605aecc33ceec8875640c1d74aa32790e821b17e98771c4a00000000f1db"; |
30 | 39 | ||
31 | /* in case we need more than one ID for a test */ | 40 | /* in case we need more than one ID for a test */ |
@@ -121,11 +130,10 @@ START_TEST(test_m_delfriend) | |||
121 | } | 130 | } |
122 | END_TEST | 131 | END_TEST |
123 | 132 | ||
124 | #if 0 | ||
125 | START_TEST(test_m_addfriend) | 133 | START_TEST(test_m_addfriend) |
126 | { | 134 | { |
127 | char *good_data = "test"; | 135 | const char *good_data = "test"; |
128 | char *bad_data = ""; | 136 | const char *bad_data = ""; |
129 | 137 | ||
130 | int good_len = strlen(good_data); | 138 | int good_len = strlen(good_data); |
131 | int bad_len = strlen(bad_data); | 139 | int bad_len = strlen(bad_data); |
@@ -134,30 +142,29 @@ START_TEST(test_m_addfriend) | |||
134 | + crypto_box_ZEROBYTES + 100); | 142 | + crypto_box_ZEROBYTES + 100); |
135 | 143 | ||
136 | /* TODO(irungentoo): Update this properly to latest master */ | 144 | /* TODO(irungentoo): Update this properly to latest master */ |
137 | if (m_addfriend(m, (uint8_t *)friend_id, (uint8_t *)good_data, really_bad_len) != FAERR_TOOLONG) { | 145 | if (m_addfriend(m, (const uint8_t *)friend_id, (const uint8_t *)good_data, really_bad_len) != FAERR_TOOLONG) { |
138 | ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", really_bad_len); | 146 | ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", really_bad_len); |
139 | } | 147 | } |
140 | 148 | ||
141 | /* this will return an error if the original m_addfriend_norequest() failed */ | 149 | /* this will return an error if the original m_addfriend_norequest() failed */ |
142 | if (m_addfriend(m, (uint8_t *)friend_id, (uint8_t *)good_data, good_len) != FAERR_ALREADYSENT) { | 150 | if (m_addfriend(m, (const uint8_t *)friend_id, (const uint8_t *)good_data, good_len) != FAERR_ALREADYSENT) { |
143 | ck_abort_msg("m_addfriend did NOT catch adding a friend we already have.\n" | 151 | ck_abort_msg("m_addfriend did NOT catch adding a friend we already have.\n" |
144 | "(this can be caused by the error of m_addfriend_norequest in" | 152 | "(this can be caused by the error of m_addfriend_norequest in" |
145 | " the beginning of the suite)\n"); | 153 | " the beginning of the suite)\n"); |
146 | } | 154 | } |
147 | 155 | ||
148 | if (m_addfriend(m, (uint8_t *)good_id_b, (uint8_t *)bad_data, bad_len) != FAERR_NOMESSAGE) { | 156 | if (m_addfriend(m, (const uint8_t *)good_id_b, (const uint8_t *)bad_data, bad_len) != FAERR_NOMESSAGE) { |
149 | ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", bad_len); | 157 | ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", bad_len); |
150 | } | 158 | } |
151 | 159 | ||
152 | /* this should REALLY return an error */ | 160 | /* this should REALLY return an error */ |
153 | /* TODO(irungentoo): validate client_id in m_addfriend? */ | 161 | /* TODO(irungentoo): validate client_id in m_addfriend? */ |
154 | if (m_addfriend((uint8_t *)bad_id, (uint8_t *)good_data, good_len) >= 0) { | 162 | if (m_addfriend(m, (const uint8_t *)bad_id, (const uint8_t *)good_data, good_len) >= 0) { |
155 | ck_abort_msg("The following ID passed through " | 163 | ck_abort_msg("The following ID passed through " |
156 | "m_addfriend without an error:\n'%s'\n", bad_id_str); | 164 | "m_addfriend without an error:\n'%s'\n", bad_id_str); |
157 | } | 165 | } |
158 | } | 166 | } |
159 | END_TEST | 167 | END_TEST |
160 | #endif | ||
161 | 168 | ||
162 | START_TEST(test_setname) | 169 | START_TEST(test_setname) |
163 | { | 170 | { |
@@ -193,7 +200,7 @@ END_TEST | |||
193 | * ideas: | 200 | * ideas: |
194 | * if we have access to the friends list, we could | 201 | * if we have access to the friends list, we could |
195 | * just add a status manually ourselves. */ | 202 | * just add a status manually ourselves. */ |
196 | /* | 203 | #if 0 |
197 | START_TEST(test_m_copy_userstatus) | 204 | START_TEST(test_m_copy_userstatus) |
198 | { | 205 | { |
199 | assert(m_copy_userstatus(-1, buf, MAX_USERSTATUS_LENGTH) == -1); | 206 | assert(m_copy_userstatus(-1, buf, MAX_USERSTATUS_LENGTH) == -1); |
@@ -203,7 +210,7 @@ START_TEST(test_m_copy_userstatus) | |||
203 | assert(STRINGS_EQUAL(name_buf, friend_id_status)); | 210 | assert(STRINGS_EQUAL(name_buf, friend_id_status)); |
204 | } | 211 | } |
205 | END_TEST | 212 | END_TEST |
206 | */ | 213 | #endif |
207 | 214 | ||
208 | START_TEST(test_getname) | 215 | START_TEST(test_getname) |
209 | { | 216 | { |
@@ -316,7 +323,10 @@ static Suite *messenger_suite(void) | |||
316 | DEFTESTCASE(m_get_userstatus_size); | 323 | DEFTESTCASE(m_get_userstatus_size); |
317 | DEFTESTCASE(m_set_userstatus); | 324 | DEFTESTCASE(m_set_userstatus); |
318 | 325 | ||
319 | /* DEFTESTCASE(m_addfriend); */ | 326 | if (enable_broken_tests) { |
327 | DEFTESTCASE(m_addfriend); | ||
328 | } | ||
329 | |||
320 | DEFTESTCASE(m_friend_exists); | 330 | DEFTESTCASE(m_friend_exists); |
321 | DEFTESTCASE(m_get_friend_connectionstatus); | 331 | DEFTESTCASE(m_get_friend_connectionstatus); |
322 | DEFTESTCASE(m_delfriend); | 332 | 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 @@ | |||
20 | #include "../toxcore/util.h" | 20 | #include "../toxcore/util.h" |
21 | 21 | ||
22 | 22 | ||
23 | #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) | 23 | #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) |
24 | #include <windows.h> | ||
24 | #define c_sleep(x) Sleep(1*x) | 25 | #define c_sleep(x) Sleep(1*x) |
25 | #else | 26 | #else |
26 | #include <unistd.h> | 27 | #include <unistd.h> |
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 @@ | |||
19 | #include "../toxcore/tox.h" | 19 | #include "../toxcore/tox.h" |
20 | #include "../toxcore/util.h" | 20 | #include "../toxcore/util.h" |
21 | 21 | ||
22 | #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) | 22 | #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) |
23 | #include <windows.h> | ||
23 | #define c_sleep(x) Sleep(1*x) | 24 | #define c_sleep(x) Sleep(1*x) |
24 | #else | 25 | #else |
25 | #include <pthread.h> | 26 | #include <pthread.h> |