diff options
author | slvr <slvr@unsafeio.com> | 2013-08-12 23:08:48 +0100 |
---|---|---|
committer | slvr <slvr@unsafeio.com> | 2013-08-12 23:08:48 +0100 |
commit | be840b46b961080aee8871a1278d9383affa6f4f (patch) | |
tree | 2fb12430cdb2bd4d1aac6b4c87505363d0387c3e /auto_tests/friends_test.c | |
parent | a56d87cd3f7e20939e7f877a5c6419f28d9b8b24 (diff) | |
parent | f9bfb42504ffb56fdcc028efbe1177fe1d45a26c (diff) |
Merge remote-tracking branch 'upstream/master' into timer
Conflicts:
core/Messenger.c
Diffstat (limited to 'auto_tests/friends_test.c')
-rwxr-xr-x | auto_tests/friends_test.c | 38 |
1 files changed, 22 insertions, 16 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; |