diff options
Diffstat (limited to 'auto_tests')
-rwxr-xr-x | auto_tests/friends_test.c | 38 | ||||
-rw-r--r-- | auto_tests/messenger_test.c | 50 |
2 files changed, 50 insertions, 38 deletions
diff --git a/auto_tests/friends_test.c b/auto_tests/friends_test.c index 0ba42b61..3c15b35b 100755 --- a/auto_tests/friends_test.c +++ b/auto_tests/friends_test.c | |||
@@ -44,6 +44,8 @@ | |||
44 | #define c_sleep(x) usleep(1000*x) | 44 | #define c_sleep(x) usleep(1000*x) |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | static Messenger *m; | ||
48 | |||
47 | uint8_t *parent_id = NULL; | 49 | uint8_t *parent_id = NULL; |
48 | uint8_t *child_id = NULL; | 50 | uint8_t *child_id = NULL; |
49 | 51 | ||
@@ -60,16 +62,16 @@ void do_tox(void) | |||
60 | dht_on = 0; | 62 | dht_on = 0; |
61 | } | 63 | } |
62 | 64 | ||
63 | doMessenger(); | 65 | doMessenger(m); |
64 | } | 66 | } |
65 | 67 | ||
66 | void parent_confirm_message(int num, uint8_t *data, uint16_t length) | 68 | void parent_confirm_message(Messenger *m, int num, uint8_t *data, uint16_t length, void* userdata) |
67 | { | 69 | { |
68 | puts("OK"); | 70 | puts("OK"); |
69 | request_flags |= SECOND_FLAG; | 71 | request_flags |= SECOND_FLAG; |
70 | } | 72 | } |
71 | 73 | ||
72 | void parent_confirm_status(int num, uint8_t *data, uint16_t length) | 74 | void parent_confirm_status(Messenger *m, int num, uint8_t *data, uint16_t length, void* userdata) |
73 | { | 75 | { |
74 | puts("OK"); | 76 | puts("OK"); |
75 | request_flags |= FIRST_FLAG; | 77 | request_flags |= FIRST_FLAG; |
@@ -84,7 +86,7 @@ int parent_friend_request(void) | |||
84 | fputs("Sending child request.", stdout); | 86 | fputs("Sending child request.", stdout); |
85 | fflush(stdout); | 87 | fflush(stdout); |
86 | 88 | ||
87 | m_addfriend(child_id, (uint8_t *)message, len); | 89 | m_addfriend(m, child_id, (uint8_t *)message, len); |
88 | 90 | ||
89 | /* wait on the status change */ | 91 | /* wait on the status change */ |
90 | for(i = 0; i < WAIT_COUNT; i++) { | 92 | for(i = 0; i < WAIT_COUNT; i++) { |
@@ -106,15 +108,15 @@ int parent_friend_request(void) | |||
106 | return 0; | 108 | return 0; |
107 | } | 109 | } |
108 | 110 | ||
109 | void child_got_request(uint8_t *public_key, uint8_t *data, uint16_t length) | 111 | void child_got_request(uint8_t *public_key, uint8_t *data, uint16_t length, void* userdata) |
110 | { | 112 | { |
111 | fputs("OK\nsending status to parent", stdout); | 113 | fputs("OK\nsending status to parent", stdout); |
112 | fflush(stdout); | 114 | fflush(stdout); |
113 | m_addfriend_norequest(public_key); | 115 | m_addfriend_norequest(m, public_key); |
114 | request_flags |= FIRST_FLAG; | 116 | request_flags |= FIRST_FLAG; |
115 | } | 117 | } |
116 | 118 | ||
117 | void child_got_statuschange(int friend_num, uint8_t *string, uint16_t length) | 119 | void child_got_statuschange(Messenger *m, int friend_num, uint8_t *string, uint16_t length, void* userdata) |
118 | { | 120 | { |
119 | request_flags |= SECOND_FLAG; | 121 | request_flags |= SECOND_FLAG; |
120 | } | 122 | } |
@@ -168,12 +170,13 @@ int main(int argc, char *argv[]) | |||
168 | int i = 0; | 170 | int i = 0; |
169 | char *message = "Y-yes Mr. Watson?"; | 171 | char *message = "Y-yes Mr. Watson?"; |
170 | 172 | ||
171 | initMessenger(); | 173 | m = initMessenger(); |
172 | Messenger_save(child_id); | 174 | |
175 | Messenger_save(m, child_id); | ||
173 | msync(child_id, crypto_box_PUBLICKEYBYTES, MS_SYNC); | 176 | msync(child_id, crypto_box_PUBLICKEYBYTES, MS_SYNC); |
174 | 177 | ||
175 | m_callback_friendrequest(child_got_request); | 178 | m_callback_friendrequest(m, child_got_request, NULL); |
176 | m_callback_statusmessage(child_got_statuschange); | 179 | m_callback_statusmessage(m, child_got_statuschange, NULL); |
177 | 180 | ||
178 | /* wait on the friend request */ | 181 | /* wait on the friend request */ |
179 | while(!(request_flags & FIRST_FLAG)) | 182 | while(!(request_flags & FIRST_FLAG)) |
@@ -185,10 +188,12 @@ int main(int argc, char *argv[]) | |||
185 | 188 | ||
186 | for(i = 0; i < 6; i++) { | 189 | for(i = 0; i < 6; i++) { |
187 | /* send the message six times, just to be sure */ | 190 | /* send the message six times, just to be sure */ |
188 | m_sendmessage(0, (uint8_t *)message, strlen(message)); | 191 | m_sendmessage(m, 0, (uint8_t *)message, strlen(message)); |
189 | do_tox(); | 192 | do_tox(); |
190 | } | 193 | } |
191 | 194 | ||
195 | cleanupMessenger(m); | ||
196 | |||
192 | return 0; | 197 | return 0; |
193 | } | 198 | } |
194 | 199 | ||
@@ -199,15 +204,16 @@ int main(int argc, char *argv[]) | |||
199 | return -1; | 204 | return -1; |
200 | } | 205 | } |
201 | 206 | ||
207 | m = initMessenger(); | ||
208 | |||
202 | msync(parent_id, crypto_box_PUBLICKEYBYTES, MS_SYNC); | 209 | msync(parent_id, crypto_box_PUBLICKEYBYTES, MS_SYNC); |
203 | m_callback_statusmessage(parent_confirm_status); | 210 | m_callback_statusmessage(m, parent_confirm_status, NULL); |
204 | m_callback_friendmessage(parent_confirm_message); | 211 | m_callback_friendmessage(m, parent_confirm_message, NULL); |
205 | 212 | ||
206 | /* hacky way to give the child time to set up */ | 213 | /* hacky way to give the child time to set up */ |
207 | c_sleep(50); | 214 | c_sleep(50); |
208 | 215 | ||
209 | initMessenger(); | 216 | Messenger_save(m, parent_id); |
210 | Messenger_save(parent_id); | ||
211 | 217 | ||
212 | if(parent_friend_request() == -1) | 218 | if(parent_friend_request() == -1) |
213 | return -1; | 219 | return -1; |
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 | ||
35 | int friend_id_num = 0; | 35 | int friend_id_num = 0; |
36 | 36 | ||
37 | Messenger *m; | ||
38 | |||
37 | unsigned char * hex_string_to_bin(char hex_string[]) | 39 | unsigned 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 | } |
60 | END_TEST | 62 | END_TEST |
61 | 63 | ||
62 | START_TEST(test_m_get_userstatus_size) | 64 | START_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 | ||
96 | START_TEST(test_m_friendstatus) | 98 | START_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 | ||
106 | START_TEST(test_m_delfriend) | 108 | START_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 | } |
161 | END_TEST | 163 | END_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 | } |