summaryrefslogtreecommitdiff
path: root/auto_tests/messenger_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'auto_tests/messenger_test.c')
-rw-r--r--auto_tests/messenger_test.c50
1 files changed, 28 insertions, 22 deletions
diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c
index af902083..64b44d5f 100644
--- a/auto_tests/messenger_test.c
+++ b/auto_tests/messenger_test.c
@@ -34,6 +34,8 @@ unsigned char *bad_id = NULL;
34 34
35int friend_id_num = 0; 35int friend_id_num = 0;
36 36
37Messenger *m;
38
37unsigned char * hex_string_to_bin(char hex_string[]) 39unsigned char * hex_string_to_bin(char hex_string[])
38{ 40{
39 size_t len = strlen(hex_string); 41 size_t len = strlen(hex_string);
@@ -52,22 +54,22 @@ START_TEST(test_m_sendmesage)
52 int bad_len = MAX_DATA_SIZE; 54 int bad_len = MAX_DATA_SIZE;
53 55
54 56
55 ck_assert(m_sendmessage(-1, (uint8_t *)message, good_len) == 0); 57 ck_assert(m_sendmessage(m, -1, (uint8_t *)message, good_len) == 0);
56 ck_assert(m_sendmessage(REALLY_BIG_NUMBER, (uint8_t *)message, good_len) == 0); 58 ck_assert(m_sendmessage(m, REALLY_BIG_NUMBER, (uint8_t *)message, good_len) == 0);
57 ck_assert(m_sendmessage(17, (uint8_t *)message, good_len) == 0); 59 ck_assert(m_sendmessage(m, 17, (uint8_t *)message, good_len) == 0);
58 ck_assert(m_sendmessage(friend_id_num, (uint8_t *)message, bad_len) == 0); 60 ck_assert(m_sendmessage(m, friend_id_num, (uint8_t *)message, bad_len) == 0);
59} 61}
60END_TEST 62END_TEST
61 63
62START_TEST(test_m_get_userstatus_size) 64START_TEST(test_m_get_userstatus_size)
63{ 65{
64 int rc = 0; 66 int rc = 0;
65 ck_assert_msg((m_get_statusmessage_size(-1) == -1), 67 ck_assert_msg((m_get_statusmessage_size(m, -1) == -1),
66 "m_get_statusmessage_size did NOT catch an argument of -1"); 68 "m_get_statusmessage_size did NOT catch an argument of -1");
67 ck_assert_msg((m_get_statusmessage_size(REALLY_BIG_NUMBER) == -1), 69 ck_assert_msg((m_get_statusmessage_size(m, REALLY_BIG_NUMBER) == -1),
68 "m_get_statusmessage_size did NOT catch the following argument: %d\n", 70 "m_get_statusmessage_size did NOT catch the following argument: %d\n",
69 REALLY_BIG_NUMBER); 71 REALLY_BIG_NUMBER);
70 rc = m_get_statusmessage_size(friend_id_num); 72 rc = m_get_statusmessage_size(m, friend_id_num);
71 73
72 /* this WILL error if the original m_addfriend_norequest() failed */ 74 /* this WILL error if the original m_addfriend_norequest() failed */
73 ck_assert_msg((rc > 0 && rc <= MAX_STATUSMESSAGE_LENGTH), 75 ck_assert_msg((rc > 0 && rc <= MAX_STATUSMESSAGE_LENGTH),
@@ -83,11 +85,11 @@ START_TEST(test_m_set_userstatus)
83 uint16_t good_length = strlen(status); 85 uint16_t good_length = strlen(status);
84 uint16_t bad_length = REALLY_BIG_NUMBER; 86 uint16_t bad_length = REALLY_BIG_NUMBER;
85 87
86 if(m_set_statusmessage((uint8_t *)status, bad_length) != -1) 88 if(m_set_statusmessage(m, (uint8_t *)status, bad_length) != -1)
87 ck_abort_msg("m_set_userstatus did NOT catch the following length: %d\n", 89 ck_abort_msg("m_set_userstatus did NOT catch the following length: %d\n",
88 REALLY_BIG_NUMBER); 90 REALLY_BIG_NUMBER);
89 91
90 if((m_set_statusmessage((uint8_t *)status, good_length)) != 0) 92 if((m_set_statusmessage(m, (uint8_t *)status, good_length)) != 0)
91 ck_abort_msg("m_set_userstatus did NOT return 0 on the following length: %d\n" 93 ck_abort_msg("m_set_userstatus did NOT return 0 on the following length: %d\n"
92 "MAX_STATUSMESSAGE_LENGTH: %d\n", good_length, MAX_STATUSMESSAGE_LENGTH); 94 "MAX_STATUSMESSAGE_LENGTH: %d\n", good_length, MAX_STATUSMESSAGE_LENGTH);
93} 95}
@@ -95,9 +97,9 @@ END_TEST
95 97
96START_TEST(test_m_friendstatus) 98START_TEST(test_m_friendstatus)
97{ 99{
98 ck_assert_msg((m_friendstatus(-1) == NOFRIEND), 100 ck_assert_msg((m_friendstatus(m, -1) == NOFRIEND),
99 "m_friendstatus did NOT catch an argument of -1.\n"); 101 "m_friendstatus did NOT catch an argument of -1.\n");
100 ck_assert_msg((m_friendstatus(REALLY_BIG_NUMBER) == NOFRIEND), 102 ck_assert_msg((m_friendstatus(m, REALLY_BIG_NUMBER) == NOFRIEND),
101 "m_friendstatus did NOT catch an argument of %d.\n", 103 "m_friendstatus did NOT catch an argument of %d.\n",
102 REALLY_BIG_NUMBER); 104 REALLY_BIG_NUMBER);
103} 105}
@@ -105,9 +107,9 @@ END_TEST
105 107
106START_TEST(test_m_delfriend) 108START_TEST(test_m_delfriend)
107{ 109{
108 ck_assert_msg((m_delfriend(-1) == -1), 110 ck_assert_msg((m_delfriend(m, -1) == -1),
109 "m_delfriend did NOT catch an argument of -1\n"); 111 "m_delfriend did NOT catch an argument of -1\n");
110 ck_assert_msg((m_delfriend(REALLY_BIG_NUMBER) == -1), 112 ck_assert_msg((m_delfriend(m, REALLY_BIG_NUMBER) == -1),
111 "m_delfriend did NOT catch the following number: %d\n", 113 "m_delfriend did NOT catch the following number: %d\n",
112 REALLY_BIG_NUMBER); 114 REALLY_BIG_NUMBER);
113} 115}
@@ -124,16 +126,16 @@ START_TEST(test_m_addfriend)
124 - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES 126 - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES
125 + crypto_box_ZEROBYTES + 100); 127 + crypto_box_ZEROBYTES + 100);
126 128
127 if(m_addfriend((uint8_t *)friend_id, (uint8_t *)good_data, really_bad_len) != FAERR_TOOLONG) 129 if(m_addfriend(m, (uint8_t *)friend_id, (uint8_t *)good_data, really_bad_len) != FAERR_TOOLONG)
128 ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", really_bad_len); 130 ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", really_bad_len);
129 131
130 /* this will error if the original m_addfriend_norequest() failed */ 132 /* this will error if the original m_addfriend_norequest() failed */
131 if(m_addfriend((uint8_t *)friend_id, (uint8_t *)good_data, good_len) != FAERR_ALREADYSENT) 133 if(m_addfriend(m, (uint8_t *)friend_id, (uint8_t *)good_data, good_len) != FAERR_ALREADYSENT)
132 ck_abort_msg("m_addfriend did NOT catch adding a friend we already have.\n" 134 ck_abort_msg("m_addfriend did NOT catch adding a friend we already have.\n"
133 "(this can be caused by the error of m_addfriend_norequest in" 135 "(this can be caused by the error of m_addfriend_norequest in"
134 " the beginning of the suite)\n"); 136 " the beginning of the suite)\n");
135 137
136 if(m_addfriend((uint8_t *)good_id_b, (uint8_t *)bad_data, bad_len) != FAERR_NOMESSAGE) 138 if(m_addfriend(m, (uint8_t *)good_id_b, (uint8_t *)bad_data, bad_len) != FAERR_NOMESSAGE)
137 ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", bad_len); 139 ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", bad_len);
138 140
139 /* this should REALLY error */ 141 /* this should REALLY error */
@@ -152,10 +154,10 @@ START_TEST(test_setname)
152 int good_length = strlen(good_name); 154 int good_length = strlen(good_name);
153 int bad_length = REALLY_BIG_NUMBER; 155 int bad_length = REALLY_BIG_NUMBER;
154 156
155 if(setname((uint8_t *)good_name, bad_length) != -1) 157 if(setname(m, (uint8_t *)good_name, bad_length) != -1)
156 ck_abort_msg("setname() did NOT error on %d as a length argument!\n", 158 ck_abort_msg("setname() did NOT error on %d as a length argument!\n",
157 bad_length); 159 bad_length);
158 if(setname((uint8_t *)good_name, good_length) != 0) 160 if(setname(m, (uint8_t *)good_name, good_length) != 0)
159 ck_abort_msg("setname() did NOT return 0 on good arguments!\n"); 161 ck_abort_msg("setname() did NOT return 0 on good arguments!\n");
160} 162}
161END_TEST 163END_TEST
@@ -166,8 +168,8 @@ START_TEST(test_getself_name)
166 int len = strlen(nickname); 168 int len = strlen(nickname);
167 char nick_check[len]; 169 char nick_check[len];
168 170
169 setname((uint8_t *)nickname, len); 171 setname(m, (uint8_t *)nickname, len);
170 getself_name((uint8_t *)nick_check); 172 getself_name(m, (uint8_t *)nick_check);
171 173
172 ck_assert_msg((!STRINGS_EQUAL(nickname, nick_check)), 174 ck_assert_msg((!STRINGS_EQUAL(nickname, nick_check)),
173 "getself_name failed to return the known name!\n" 175 "getself_name failed to return the known name!\n"
@@ -256,13 +258,15 @@ int main(int argc, char *argv[])
256 good_id_b = hex_string_to_bin(good_id_b_str); 258 good_id_b = hex_string_to_bin(good_id_b_str);
257 bad_id = hex_string_to_bin(bad_id_str); 259 bad_id = hex_string_to_bin(bad_id_str);
258 260
261 m = initMessenger();
262
259 /* setup a default friend and friendnum */ 263 /* setup a default friend and friendnum */
260 if(m_addfriend_norequest((uint8_t *)friend_id) < 0) 264 if(m_addfriend_norequest(m, (uint8_t *)friend_id) < 0)
261 fputs("m_addfriend_norequest() failed on a valid ID!\n" 265 fputs("m_addfriend_norequest() failed on a valid ID!\n"
262 "this was CRITICAL to the test, and the build WILL fail.\n" 266 "this was CRITICAL to the test, and the build WILL fail.\n"
263 "the tests will continue now...\n\n", stderr); 267 "the tests will continue now...\n\n", stderr);
264 268
265 if((friend_id_num = getfriend_id((uint8_t *)friend_id)) < 0) 269 if((friend_id_num = getfriend_id(m, (uint8_t *)friend_id)) < 0)
266 fputs("getfriend_id() failed on a valid ID!\n" 270 fputs("getfriend_id() failed on a valid ID!\n"
267 "this was CRITICAL to the test, and the build WILL fail.\n" 271 "this was CRITICAL to the test, and the build WILL fail.\n"
268 "the tests will continue now...\n\n", stderr); 272 "the tests will continue now...\n\n", stderr);
@@ -276,5 +280,7 @@ int main(int argc, char *argv[])
276 free(good_id_b); 280 free(good_id_b);
277 free(bad_id); 281 free(bad_id);
278 282
283 cleanupMessenger(m);
284
279 return number_failed; 285 return number_failed;
280} 286}