diff options
Diffstat (limited to 'auto_tests/toxav_many_test.c')
-rw-r--r-- | auto_tests/toxav_many_test.c | 88 |
1 files changed, 45 insertions, 43 deletions
diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index 5796905c..9a639eb8 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c | |||
@@ -1,4 +1,6 @@ | |||
1 | #ifndef _XOPEN_SOURCE | ||
1 | #define _XOPEN_SOURCE 600 | 2 | #define _XOPEN_SOURCE 600 |
3 | #endif | ||
2 | 4 | ||
3 | #ifdef HAVE_CONFIG_H | 5 | #ifdef HAVE_CONFIG_H |
4 | #include "config.h" | 6 | #include "config.h" |
@@ -96,7 +98,7 @@ static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const | |||
96 | (void) userdata; | 98 | (void) userdata; |
97 | 99 | ||
98 | if (length == 7 && memcmp("gentoo", data, 7) == 0) { | 100 | if (length == 7 && memcmp("gentoo", data, 7) == 0) { |
99 | ck_assert(tox_friend_add_norequest(m, public_key, NULL) != (uint32_t) ~0); | 101 | ck_assert(tox_friend_add_norequest(m, public_key, nullptr) != (uint32_t) ~0); |
100 | } | 102 | } |
101 | } | 103 | } |
102 | 104 | ||
@@ -160,17 +162,17 @@ static void *call_thread(void *pd) | |||
160 | uint8_t *video_u = (uint8_t *)calloc(800 * 600 / 4, sizeof(uint8_t)); | 162 | uint8_t *video_u = (uint8_t *)calloc(800 * 600 / 4, sizeof(uint8_t)); |
161 | uint8_t *video_v = (uint8_t *)calloc(800 * 600 / 4, sizeof(uint8_t)); | 163 | uint8_t *video_v = (uint8_t *)calloc(800 * 600 / 4, sizeof(uint8_t)); |
162 | 164 | ||
163 | time_t start_time = time(NULL); | 165 | time_t start_time = time(nullptr); |
164 | 166 | ||
165 | while (time(NULL) - start_time < 4) { | 167 | while (time(nullptr) - start_time < 4) { |
166 | toxav_iterate(AliceAV); | 168 | toxav_iterate(AliceAV); |
167 | toxav_iterate(BobAV); | 169 | toxav_iterate(BobAV); |
168 | 170 | ||
169 | toxav_audio_send_frame(AliceAV, friend_number, PCM, 960, 1, 48000, NULL); | 171 | toxav_audio_send_frame(AliceAV, friend_number, PCM, 960, 1, 48000, nullptr); |
170 | toxav_audio_send_frame(BobAV, 0, PCM, 960, 1, 48000, NULL); | 172 | toxav_audio_send_frame(BobAV, 0, PCM, 960, 1, 48000, nullptr); |
171 | 173 | ||
172 | toxav_video_send_frame(AliceAV, friend_number, 800, 600, video_y, video_u, video_v, NULL); | 174 | toxav_video_send_frame(AliceAV, friend_number, 800, 600, video_y, video_u, video_v, nullptr); |
173 | toxav_video_send_frame(BobAV, 0, 800, 600, video_y, video_u, video_v, NULL); | 175 | toxav_video_send_frame(BobAV, 0, 800, 600, video_y, video_u, video_v, nullptr); |
174 | 176 | ||
175 | c_sleep(10); | 177 | c_sleep(10); |
176 | } | 178 | } |
@@ -192,7 +194,7 @@ static void *call_thread(void *pd) | |||
192 | free(video_v); | 194 | free(video_v); |
193 | 195 | ||
194 | printf("Closing thread\n"); | 196 | printf("Closing thread\n"); |
195 | pthread_exit(NULL); | 197 | pthread_exit(nullptr); |
196 | } | 198 | } |
197 | 199 | ||
198 | 200 | ||
@@ -208,25 +210,25 @@ START_TEST(test_AV_three_calls) | |||
208 | { | 210 | { |
209 | TOX_ERR_NEW error; | 211 | TOX_ERR_NEW error; |
210 | 212 | ||
211 | bootstrap = tox_new_log(NULL, &error, &index[0]); | 213 | bootstrap = tox_new_log(nullptr, &error, &index[0]); |
212 | ck_assert(error == TOX_ERR_NEW_OK); | 214 | ck_assert(error == TOX_ERR_NEW_OK); |
213 | 215 | ||
214 | Alice = tox_new_log(NULL, &error, &index[1]); | 216 | Alice = tox_new_log(nullptr, &error, &index[1]); |
215 | ck_assert(error == TOX_ERR_NEW_OK); | 217 | ck_assert(error == TOX_ERR_NEW_OK); |
216 | 218 | ||
217 | Bobs[0] = tox_new_log(NULL, &error, &index[2]); | 219 | Bobs[0] = tox_new_log(nullptr, &error, &index[2]); |
218 | ck_assert(error == TOX_ERR_NEW_OK); | 220 | ck_assert(error == TOX_ERR_NEW_OK); |
219 | 221 | ||
220 | Bobs[1] = tox_new_log(NULL, &error, &index[3]); | 222 | Bobs[1] = tox_new_log(nullptr, &error, &index[3]); |
221 | ck_assert(error == TOX_ERR_NEW_OK); | 223 | ck_assert(error == TOX_ERR_NEW_OK); |
222 | 224 | ||
223 | Bobs[2] = tox_new_log(NULL, &error, &index[4]); | 225 | Bobs[2] = tox_new_log(nullptr, &error, &index[4]); |
224 | ck_assert(error == TOX_ERR_NEW_OK); | 226 | ck_assert(error == TOX_ERR_NEW_OK); |
225 | } | 227 | } |
226 | 228 | ||
227 | printf("Created 5 instances of Tox\n"); | 229 | printf("Created 5 instances of Tox\n"); |
228 | printf("Preparing network...\n"); | 230 | printf("Preparing network...\n"); |
229 | long long unsigned int cur_time = time(NULL); | 231 | long long unsigned int cur_time = time(nullptr); |
230 | 232 | ||
231 | uint8_t address[TOX_ADDRESS_SIZE]; | 233 | uint8_t address[TOX_ADDRESS_SIZE]; |
232 | 234 | ||
@@ -234,34 +236,34 @@ START_TEST(test_AV_three_calls) | |||
234 | tox_self_get_address(Alice, address); | 236 | tox_self_get_address(Alice, address); |
235 | 237 | ||
236 | 238 | ||
237 | ck_assert(tox_friend_add(Bobs[0], address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); | 239 | ck_assert(tox_friend_add(Bobs[0], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0); |
238 | ck_assert(tox_friend_add(Bobs[1], address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); | 240 | ck_assert(tox_friend_add(Bobs[1], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0); |
239 | ck_assert(tox_friend_add(Bobs[2], address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); | 241 | ck_assert(tox_friend_add(Bobs[2], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0); |
240 | 242 | ||
241 | uint8_t off = 1; | 243 | uint8_t off = 1; |
242 | 244 | ||
243 | while (1) { | 245 | while (1) { |
244 | tox_iterate(bootstrap, NULL); | 246 | tox_iterate(bootstrap, nullptr); |
245 | tox_iterate(Alice, NULL); | 247 | tox_iterate(Alice, nullptr); |
246 | tox_iterate(Bobs[0], NULL); | 248 | tox_iterate(Bobs[0], nullptr); |
247 | tox_iterate(Bobs[1], NULL); | 249 | tox_iterate(Bobs[1], nullptr); |
248 | tox_iterate(Bobs[2], NULL); | 250 | tox_iterate(Bobs[2], nullptr); |
249 | 251 | ||
250 | if (tox_self_get_connection_status(bootstrap) && | 252 | if (tox_self_get_connection_status(bootstrap) && |
251 | tox_self_get_connection_status(Alice) && | 253 | tox_self_get_connection_status(Alice) && |
252 | tox_self_get_connection_status(Bobs[0]) && | 254 | tox_self_get_connection_status(Bobs[0]) && |
253 | tox_self_get_connection_status(Bobs[1]) && | 255 | tox_self_get_connection_status(Bobs[1]) && |
254 | tox_self_get_connection_status(Bobs[2]) && off) { | 256 | tox_self_get_connection_status(Bobs[2]) && off) { |
255 | printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time); | 257 | printf("Toxes are online, took %llu seconds\n", time(nullptr) - cur_time); |
256 | off = 0; | 258 | off = 0; |
257 | } | 259 | } |
258 | 260 | ||
259 | if (tox_friend_get_connection_status(Alice, 0, NULL) == TOX_CONNECTION_UDP && | 261 | if (tox_friend_get_connection_status(Alice, 0, nullptr) == TOX_CONNECTION_UDP && |
260 | tox_friend_get_connection_status(Alice, 1, NULL) == TOX_CONNECTION_UDP && | 262 | tox_friend_get_connection_status(Alice, 1, nullptr) == TOX_CONNECTION_UDP && |
261 | tox_friend_get_connection_status(Alice, 2, NULL) == TOX_CONNECTION_UDP && | 263 | tox_friend_get_connection_status(Alice, 2, nullptr) == TOX_CONNECTION_UDP && |
262 | tox_friend_get_connection_status(Bobs[0], 0, NULL) == TOX_CONNECTION_UDP && | 264 | tox_friend_get_connection_status(Bobs[0], 0, nullptr) == TOX_CONNECTION_UDP && |
263 | tox_friend_get_connection_status(Bobs[1], 0, NULL) == TOX_CONNECTION_UDP && | 265 | tox_friend_get_connection_status(Bobs[1], 0, nullptr) == TOX_CONNECTION_UDP && |
264 | tox_friend_get_connection_status(Bobs[2], 0, NULL) == TOX_CONNECTION_UDP) { | 266 | tox_friend_get_connection_status(Bobs[2], 0, nullptr) == TOX_CONNECTION_UDP) { |
265 | break; | 267 | break; |
266 | } | 268 | } |
267 | 269 | ||
@@ -274,7 +276,7 @@ START_TEST(test_AV_three_calls) | |||
274 | BobsAV[2] = setup_av_instance(Bobs[2], BobsCC + 2); | 276 | BobsAV[2] = setup_av_instance(Bobs[2], BobsCC + 2); |
275 | 277 | ||
276 | printf("Created 4 instances of ToxAV\n"); | 278 | printf("Created 4 instances of ToxAV\n"); |
277 | printf("All set after %llu seconds!\n", time(NULL) - cur_time); | 279 | printf("All set after %llu seconds!\n", time(nullptr) - cur_time); |
278 | 280 | ||
279 | thread_data tds[3]; | 281 | thread_data tds[3]; |
280 | tds[0].AliceAV = AliceAV; | 282 | tds[0].AliceAV = AliceAV; |
@@ -296,28 +298,28 @@ START_TEST(test_AV_three_calls) | |||
296 | tds[2].friend_number = 2; | 298 | tds[2].friend_number = 2; |
297 | 299 | ||
298 | pthread_t tids[3]; | 300 | pthread_t tids[3]; |
299 | (void) pthread_create(tids + 0, NULL, call_thread, tds + 0); | 301 | (void) pthread_create(tids + 0, nullptr, call_thread, tds + 0); |
300 | (void) pthread_create(tids + 1, NULL, call_thread, tds + 1); | 302 | (void) pthread_create(tids + 1, nullptr, call_thread, tds + 1); |
301 | (void) pthread_create(tids + 2, NULL, call_thread, tds + 2); | 303 | (void) pthread_create(tids + 2, nullptr, call_thread, tds + 2); |
302 | 304 | ||
303 | time_t start_time = time(NULL); | 305 | time_t start_time = time(nullptr); |
304 | 306 | ||
305 | while (time(NULL) - start_time < 5) { | 307 | while (time(nullptr) - start_time < 5) { |
306 | tox_iterate(Alice, NULL); | 308 | tox_iterate(Alice, nullptr); |
307 | tox_iterate(Bobs[0], NULL); | 309 | tox_iterate(Bobs[0], nullptr); |
308 | tox_iterate(Bobs[1], NULL); | 310 | tox_iterate(Bobs[1], nullptr); |
309 | tox_iterate(Bobs[2], NULL); | 311 | tox_iterate(Bobs[2], nullptr); |
310 | c_sleep(20); | 312 | c_sleep(20); |
311 | } | 313 | } |
312 | 314 | ||
313 | ck_assert(pthread_join(tids[0], &retval) == 0); | 315 | ck_assert(pthread_join(tids[0], &retval) == 0); |
314 | ck_assert(retval == NULL); | 316 | ck_assert(retval == nullptr); |
315 | 317 | ||
316 | ck_assert(pthread_join(tids[1], &retval) == 0); | 318 | ck_assert(pthread_join(tids[1], &retval) == 0); |
317 | ck_assert(retval == NULL); | 319 | ck_assert(retval == nullptr); |
318 | 320 | ||
319 | ck_assert(pthread_join(tids[2], &retval) == 0); | 321 | ck_assert(pthread_join(tids[2], &retval) == 0); |
320 | ck_assert(retval == NULL); | 322 | ck_assert(retval == nullptr); |
321 | 323 | ||
322 | printf("Killing all instances\n"); | 324 | printf("Killing all instances\n"); |
323 | toxav_kill(BobsAV[0]); | 325 | toxav_kill(BobsAV[0]); |
@@ -355,7 +357,7 @@ int main(int argc, char *argv[]) | |||
355 | Suite *tox = tox_suite(); | 357 | Suite *tox = tox_suite(); |
356 | SRunner *test_runner = srunner_create(tox); | 358 | SRunner *test_runner = srunner_create(tox); |
357 | 359 | ||
358 | setbuf(stdout, NULL); | 360 | setbuf(stdout, nullptr); |
359 | 361 | ||
360 | srunner_run_all(test_runner, CK_NORMAL); | 362 | srunner_run_all(test_runner, CK_NORMAL); |
361 | int number_failed = srunner_ntests_failed(test_runner); | 363 | int number_failed = srunner_ntests_failed(test_runner); |