summaryrefslogtreecommitdiff
path: root/auto_tests/messenger_test.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-12-19 15:27:46 +0000
committeriphydf <iphydf@users.noreply.github.com>2016-12-22 10:26:59 +0000
commit2328cb74abccd563f0cd8d14d30e5314822d321e (patch)
treeb61581536d448a8846dc333b44c9b56e24605a1f /auto_tests/messenger_test.c
parentce29c8e7ec91d95167b2dea3aee9fd1ae1aac254 (diff)
Improve documentation of crypto_core.
Diffstat (limited to 'auto_tests/messenger_test.c')
-rw-r--r--auto_tests/messenger_test.c34
1 files changed, 22 insertions, 12 deletions
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
36static bool enable_broken_tests = false;
37
29static const char *friend_id_str = "e4b3d5030bc99494605aecc33ceec8875640c1d74aa32790e821b17e98771c4a00000000f1db"; 38static 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}
122END_TEST 131END_TEST
123 132
124#if 0
125START_TEST(test_m_addfriend) 133START_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}
159END_TEST 167END_TEST
160#endif
161 168
162START_TEST(test_setname) 169START_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
197START_TEST(test_m_copy_userstatus) 204START_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}
205END_TEST 212END_TEST
206*/ 213#endif
207 214
208START_TEST(test_getname) 215START_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);