summaryrefslogtreecommitdiff
path: root/auto_tests/toxav_many_test.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-02-18 17:50:50 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-02-18 21:32:28 +0000
commit3dc8cf6df8b80f213526884cafbbd493486366e5 (patch)
tree553b36ecd451c72ad85c7782ebbfd6a3ae41aaa7 /auto_tests/toxav_many_test.c
parentd016eb3f0e808ce4b4736b5056bcd3daf9514f99 (diff)
Disable lan discovery in most tests.
Diffstat (limited to 'auto_tests/toxav_many_test.c')
-rw-r--r--auto_tests/toxav_many_test.c84
1 files changed, 27 insertions, 57 deletions
diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c
index 02215098..4de1a867 100644
--- a/auto_tests/toxav_many_test.c
+++ b/auto_tests/toxav_many_test.c
@@ -47,36 +47,24 @@ typedef struct {
47 */ 47 */
48static void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) 48static void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data)
49{ 49{
50 (void) av;
51 (void) audio_enabled;
52 (void) video_enabled;
53
54 printf("Handling CALL callback\n"); 50 printf("Handling CALL callback\n");
55 ((CallControl *)user_data)[friend_number].incoming = true; 51 ((CallControl *)user_data)[friend_number].incoming = true;
56} 52}
53
57static void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) 54static void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data)
58{ 55{
59 printf("Handling CALL STATE callback: %d %p\n", state, (void *)av); 56 printf("Handling CALL STATE callback: %d %p\n", state, (void *)av);
60 ((CallControl *)user_data)[friend_number].state = state; 57 ((CallControl *)user_data)[friend_number].state = state;
61} 58}
59
62static void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, 60static void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number,
63 uint16_t width, uint16_t height, 61 uint16_t width, uint16_t height,
64 uint8_t const *y, uint8_t const *u, uint8_t const *v, 62 uint8_t const *y, uint8_t const *u, uint8_t const *v,
65 int32_t ystride, int32_t ustride, int32_t vstride, 63 int32_t ystride, int32_t ustride, int32_t vstride,
66 void *user_data) 64 void *user_data)
67{ 65{
68 (void) av;
69 (void) friend_number;
70 (void) width;
71 (void) height;
72 (void) y;
73 (void) u;
74 (void) v;
75 (void) ystride;
76 (void) ustride;
77 (void) vstride;
78 (void) user_data;
79} 66}
67
80static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, 68static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number,
81 int16_t const *pcm, 69 int16_t const *pcm,
82 size_t sample_count, 70 size_t sample_count,
@@ -84,19 +72,11 @@ static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number,
84 uint32_t sampling_rate, 72 uint32_t sampling_rate,
85 void *user_data) 73 void *user_data)
86{ 74{
87 (void) av;
88 (void) friend_number;
89 (void) pcm;
90 (void) sample_count;
91 (void) channels;
92 (void) sampling_rate;
93 (void) user_data;
94} 75}
76
95static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, 77static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length,
96 void *userdata) 78 void *userdata)
97{ 79{
98 (void) userdata;
99
100 if (length == 7 && memcmp("gentoo", data, 7) == 0) { 80 if (length == 7 && memcmp("gentoo", data, 7) == 0) {
101 ck_assert(tox_friend_add_norequest(m, public_key, nullptr) != (uint32_t) ~0); 81 ck_assert(tox_friend_add_norequest(m, public_key, nullptr) != (uint32_t) ~0);
102 } 82 }
@@ -120,6 +100,7 @@ static ToxAV *setup_av_instance(Tox *tox, CallControl *CC)
120 100
121 return av; 101 return av;
122} 102}
103
123static void *call_thread(void *pd) 104static void *call_thread(void *pd)
124{ 105{
125 ToxAV *AliceAV = ((thread_data *) pd)->AliceAV; 106 ToxAV *AliceAV = ((thread_data *) pd)->AliceAV;
@@ -197,8 +178,7 @@ static void *call_thread(void *pd)
197 pthread_exit(nullptr); 178 pthread_exit(nullptr);
198} 179}
199 180
200 181static void test_av_three_calls(void)
201START_TEST(test_AV_three_calls)
202{ 182{
203 uint32_t index[] = { 1, 2, 3, 4, 5 }; 183 uint32_t index[] = { 1, 2, 3, 4, 5 };
204 Tox *Alice, *bootstrap, *Bobs[3]; 184 Tox *Alice, *bootstrap, *Bobs[3];
@@ -228,13 +208,23 @@ START_TEST(test_AV_three_calls)
228 208
229 printf("Created 5 instances of Tox\n"); 209 printf("Created 5 instances of Tox\n");
230 printf("Preparing network...\n"); 210 printf("Preparing network...\n");
231 long long unsigned int cur_time = time(nullptr); 211 time_t cur_time = time(nullptr);
232 212
233 uint8_t address[TOX_ADDRESS_SIZE]; 213 uint8_t address[TOX_ADDRESS_SIZE];
234 214
235 tox_callback_friend_request(Alice, t_accept_friend_request_cb); 215 tox_callback_friend_request(Alice, t_accept_friend_request_cb);
236 tox_self_get_address(Alice, address); 216 tox_self_get_address(Alice, address);
237 217
218 printf("bootstrapping Alice and the %zd Bobs off a third bootstrap node\n",
219 sizeof(Bobs) / sizeof(Bobs[0]));
220 uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
221 tox_self_get_dht_id(bootstrap, dht_key);
222 const uint16_t dht_port = tox_self_get_udp_port(bootstrap, nullptr);
223
224 tox_bootstrap(Alice, "localhost", dht_port, dht_key, nullptr);
225 tox_bootstrap(Bobs[0], "localhost", dht_port, dht_key, nullptr);
226 tox_bootstrap(Bobs[1], "localhost", dht_port, dht_key, nullptr);
227 tox_bootstrap(Bobs[2], "localhost", dht_port, dht_key, nullptr);
238 228
239 ck_assert(tox_friend_add(Bobs[0], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0); 229 ck_assert(tox_friend_add(Bobs[0], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0);
240 ck_assert(tox_friend_add(Bobs[1], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0); 230 ck_assert(tox_friend_add(Bobs[1], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0);
@@ -254,7 +244,7 @@ START_TEST(test_AV_three_calls)
254 tox_self_get_connection_status(Bobs[0]) && 244 tox_self_get_connection_status(Bobs[0]) &&
255 tox_self_get_connection_status(Bobs[1]) && 245 tox_self_get_connection_status(Bobs[1]) &&
256 tox_self_get_connection_status(Bobs[2]) && off) { 246 tox_self_get_connection_status(Bobs[2]) && off) {
257 printf("Toxes are online, took %llu seconds\n", time(nullptr) - cur_time); 247 printf("Toxes are online, took %ld seconds\n", time(nullptr) - cur_time);
258 off = 0; 248 off = 0;
259 } 249 }
260 250
@@ -276,7 +266,7 @@ START_TEST(test_AV_three_calls)
276 BobsAV[2] = setup_av_instance(Bobs[2], BobsCC + 2); 266 BobsAV[2] = setup_av_instance(Bobs[2], BobsCC + 2);
277 267
278 printf("Created 4 instances of ToxAV\n"); 268 printf("Created 4 instances of ToxAV\n");
279 printf("All set after %llu seconds!\n", time(nullptr) - cur_time); 269 printf("All set after %ld seconds!\n", time(nullptr) - cur_time);
280 270
281 thread_data tds[3]; 271 thread_data tds[3];
282 tds[0].AliceAV = AliceAV; 272 tds[0].AliceAV = AliceAV;
@@ -305,6 +295,7 @@ START_TEST(test_AV_three_calls)
305 time_t start_time = time(nullptr); 295 time_t start_time = time(nullptr);
306 296
307 while (time(nullptr) - start_time < 5) { 297 while (time(nullptr) - start_time < 5) {
298 tox_iterate(bootstrap, nullptr);
308 tox_iterate(Alice, nullptr); 299 tox_iterate(Alice, nullptr);
309 tox_iterate(Bobs[0], nullptr); 300 tox_iterate(Bobs[0], nullptr);
310 tox_iterate(Bobs[1], nullptr); 301 tox_iterate(Bobs[1], nullptr);
@@ -322,44 +313,23 @@ START_TEST(test_AV_three_calls)
322 ck_assert(retval == nullptr); 313 ck_assert(retval == nullptr);
323 314
324 printf("Killing all instances\n"); 315 printf("Killing all instances\n");
325 toxav_kill(BobsAV[0]);
326 toxav_kill(BobsAV[1]);
327 toxav_kill(BobsAV[2]); 316 toxav_kill(BobsAV[2]);
317 toxav_kill(BobsAV[1]);
318 toxav_kill(BobsAV[0]);
328 toxav_kill(AliceAV); 319 toxav_kill(AliceAV);
329 tox_kill(Bobs[0]);
330 tox_kill(Bobs[1]);
331 tox_kill(Bobs[2]); 320 tox_kill(Bobs[2]);
321 tox_kill(Bobs[1]);
322 tox_kill(Bobs[0]);
332 tox_kill(Alice); 323 tox_kill(Alice);
333 tox_kill(bootstrap); 324 tox_kill(bootstrap);
334 325
335 printf("\nTest successful!\n"); 326 printf("\nTest successful!\n");
336} 327}
337END_TEST
338
339
340static Suite *tox_suite(void)
341{
342 Suite *s = suite_create("ToxAV");
343
344 DEFTESTCASE(AV_three_calls);
345
346 return s;
347}
348 328
349int main(int argc, char *argv[]) 329int main(int argc, char *argv[])
350{ 330{
351 (void) argc; 331 setvbuf(stdout, nullptr, _IONBF, 0);
352 (void) argv;
353
354 Suite *tox = tox_suite();
355 SRunner *test_runner = srunner_create(tox);
356
357 setbuf(stdout, nullptr);
358
359 srunner_run_all(test_runner, CK_NORMAL);
360 int number_failed = srunner_ntests_failed(test_runner);
361
362 srunner_free(test_runner);
363 332
364 return number_failed; 333 test_av_three_calls();
334 return 0;
365} 335}