summaryrefslogtreecommitdiff
path: root/auto_tests/friends_test.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-08-12 03:39:18 -0700
committerirungentoo <irungentoo@gmail.com>2013-08-12 03:39:18 -0700
commit33e104f32ff2852da31dbcff1441ea4bdc47fe95 (patch)
tree035448a709db7cab74d9d40fcfec641694f375ec /auto_tests/friends_test.c
parent139d915482c82f2a4aa87b444008afffef728561 (diff)
parent4293c4b1e66e9547f88c86bd580b9a4c79ca7ace (diff)
Merge pull request #438 from mkfifo/master
Messenger refactor - redid work from pull request 79
Diffstat (limited to 'auto_tests/friends_test.c')
-rwxr-xr-xauto_tests/friends_test.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/auto_tests/friends_test.c b/auto_tests/friends_test.c
index 0ba42b61..317714d6 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
47static Messenger *m;
48
47uint8_t *parent_id = NULL; 49uint8_t *parent_id = NULL;
48uint8_t *child_id = NULL; 50uint8_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
66void parent_confirm_message(int num, uint8_t *data, uint16_t length) 68void parent_confirm_message(Messenger *m, int num, uint8_t *data, uint16_t length)
67{ 69{
68 puts("OK"); 70 puts("OK");
69 request_flags |= SECOND_FLAG; 71 request_flags |= SECOND_FLAG;
70} 72}
71 73
72void parent_confirm_status(int num, uint8_t *data, uint16_t length) 74void parent_confirm_status(Messenger *m, int num, uint8_t *data, uint16_t length)
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++) {
@@ -110,11 +112,11 @@ void child_got_request(uint8_t *public_key, uint8_t *data, uint16_t length)
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
117void child_got_statuschange(int friend_num, uint8_t *string, uint16_t length) 119void child_got_statuschange(Messenger *m, int friend_num, uint8_t *string, uint16_t length)
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);
176 m_callback_statusmessage(child_got_statuschange); 179 m_callback_statusmessage(m, child_got_statuschange);
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);
204 m_callback_friendmessage(parent_confirm_message); 211 m_callback_friendmessage(m, parent_confirm_message);
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;