summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auto_tests/toxav_many_test.c139
1 files changed, 74 insertions, 65 deletions
diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c
index 1573bac9..c8b14022 100644
--- a/auto_tests/toxav_many_test.c
+++ b/auto_tests/toxav_many_test.c
@@ -99,39 +99,8 @@ static void *call_thread(void *pd)
99{ 99{
100 ToxAV *AliceAV = ((thread_data *) pd)->AliceAV; 100 ToxAV *AliceAV = ((thread_data *) pd)->AliceAV;
101 ToxAV *BobAV = ((thread_data *) pd)->BobAV; 101 ToxAV *BobAV = ((thread_data *) pd)->BobAV;
102 CallControl *AliceCC = ((thread_data *) pd)->AliceCC;
103 CallControl *BobCC = ((thread_data *) pd)->BobCC;
104 uint32_t friend_number = ((thread_data *) pd)->friend_number; 102 uint32_t friend_number = ((thread_data *) pd)->friend_number;
105 103
106 memset(AliceCC, 0, sizeof(CallControl));
107 memset(BobCC, 0, sizeof(CallControl));
108
109 { /* Call */
110 Toxav_Err_Call rc;
111 toxav_call(AliceAV, friend_number, 48, 3000, &rc);
112
113 if (rc != TOXAV_ERR_CALL_OK) {
114 printf("toxav_call failed: %d\n", rc);
115 ck_assert(0);
116 }
117 }
118
119 do {
120 c_sleep(10);
121 } while (!BobCC->incoming);
122
123 { /* Answer */
124 Toxav_Err_Answer rc;
125 toxav_answer(BobAV, 0, 8, 500, &rc);
126
127 if (rc != TOXAV_ERR_ANSWER_OK) {
128 printf("toxav_answer failed: %d\n", rc);
129 ck_assert(0);
130 }
131 }
132
133 c_sleep(30);
134
135 int16_t *PCM = (int16_t *)calloc(960, sizeof(int16_t)); 104 int16_t *PCM = (int16_t *)calloc(960, sizeof(int16_t));
136 uint8_t *video_y = (uint8_t *)calloc(800 * 600, sizeof(uint8_t)); 105 uint8_t *video_y = (uint8_t *)calloc(800 * 600, sizeof(uint8_t));
137 uint8_t *video_u = (uint8_t *)calloc(800 * 600 / 4, sizeof(uint8_t)); 106 uint8_t *video_u = (uint8_t *)calloc(800 * 600 / 4, sizeof(uint8_t));
@@ -152,17 +121,6 @@ static void *call_thread(void *pd)
152 c_sleep(10); 121 c_sleep(10);
153 } while (time(nullptr) - start_time < 4); 122 } while (time(nullptr) - start_time < 4);
154 123
155 { /* Hangup */
156 Toxav_Err_Call_Control rc;
157 toxav_call_control(AliceAV, friend_number, TOXAV_CALL_CONTROL_CANCEL, &rc);
158
159 if (rc != TOXAV_ERR_CALL_CONTROL_OK) {
160 printf("toxav_call_control failed: %d %p %p\n", rc, (void *)AliceAV, (void *)BobAV);
161 }
162 }
163
164 c_sleep(30);
165
166 free(PCM); 124 free(PCM);
167 free(video_y); 125 free(video_y);
168 free(video_u); 126 free(video_u);
@@ -257,36 +215,30 @@ static void test_av_three_calls(void)
257 } 215 }
258 216
259 AliceAV = setup_av_instance(Alice, AliceCC); 217 AliceAV = setup_av_instance(Alice, AliceCC);
260 BobsAV[0] = setup_av_instance(Bobs[0], BobsCC + 0); 218 BobsAV[0] = setup_av_instance(Bobs[0], &BobsCC[0]);
261 BobsAV[1] = setup_av_instance(Bobs[1], BobsCC + 1); 219 BobsAV[1] = setup_av_instance(Bobs[1], &BobsCC[1]);
262 BobsAV[2] = setup_av_instance(Bobs[2], BobsCC + 2); 220 BobsAV[2] = setup_av_instance(Bobs[2], &BobsCC[2]);
263 221
264 printf("Created 4 instances of ToxAV\n"); 222 printf("Created 4 instances of ToxAV\n");
265 printf("All set after %lu seconds!\n", (unsigned long)(time(nullptr) - cur_time)); 223 printf("All set after %lu seconds!\n", (unsigned long)(time(nullptr) - cur_time));
266 224
267 thread_data tds[3]; 225 thread_data tds[3];
268 tds[0].AliceAV = AliceAV; 226
269 tds[0].BobAV = BobsAV[0]; 227 for (size_t i = 0; i < 3; i++) {
270 tds[0].AliceCC = AliceCC + 0; 228 tds[i].AliceAV = AliceAV;
271 tds[0].BobCC = BobsCC + 0; 229 tds[i].BobAV = BobsAV[i];
272 tds[0].friend_number = 0; 230 tds[i].AliceCC = &AliceCC[i];
273 231 tds[i].BobCC = &BobsCC[i];
274 tds[1].AliceAV = AliceAV; 232 tds[i].friend_number = i;
275 tds[1].BobAV = BobsAV[1]; 233 memset(tds[i].AliceCC, 0, sizeof(CallControl));
276 tds[1].AliceCC = AliceCC + 1; 234 memset(tds[i].BobCC, 0, sizeof(CallControl));
277 tds[1].BobCC = BobsCC + 1; 235 }
278 tds[1].friend_number = 1;
279
280 tds[2].AliceAV = AliceAV;
281 tds[2].BobAV = BobsAV[2];
282 tds[2].AliceCC = AliceCC + 2;
283 tds[2].BobCC = BobsCC + 2;
284 tds[2].friend_number = 2;
285 236
286 pthread_t tids[3]; 237 pthread_t tids[3];
287 (void) pthread_create(tids + 0, nullptr, call_thread, tds + 0); 238
288 (void) pthread_create(tids + 1, nullptr, call_thread, tds + 1); 239 for (size_t i = 0; i < 3; i++) {
289 (void) pthread_create(tids + 2, nullptr, call_thread, tds + 2); 240 (void) pthread_create(&tids[i], nullptr, call_thread, &tds[i]);
241 }
290 242
291 time_t start_time = time(nullptr); 243 time_t start_time = time(nullptr);
292 244
@@ -297,6 +249,63 @@ static void test_av_three_calls(void)
297 tox_iterate(Bobs[1], nullptr); 249 tox_iterate(Bobs[1], nullptr);
298 tox_iterate(Bobs[2], nullptr); 250 tox_iterate(Bobs[2], nullptr);
299 c_sleep(20); 251 c_sleep(20);
252 } while (time(nullptr) - start_time < 1);
253
254 /* Call */
255 for (size_t i = 0; i < 3; i++) {
256 Toxav_Err_Call rc;
257 toxav_call(AliceAV, tds[i].friend_number, 48, 3000, &rc);
258
259 if (rc != TOXAV_ERR_CALL_OK) {
260 printf("toxav_call failed: %d\n", rc);
261 ck_assert(0);
262 }
263 }
264
265
266 do {
267 tox_iterate(bootstrap, nullptr);
268 tox_iterate(Alice, nullptr);
269 tox_iterate(Bobs[0], nullptr);
270 tox_iterate(Bobs[1], nullptr);
271 tox_iterate(Bobs[2], nullptr);
272
273 for (size_t i = 0; i < 3; i++) {
274 if (BobsCC[i].incoming) {
275 /* Answer */
276 Toxav_Err_Answer rc;
277 toxav_answer(BobsAV[i], 0, 8, 500, &rc);
278
279 if (rc != TOXAV_ERR_ANSWER_OK) {
280 printf("toxav_answer failed: %d\n", rc);
281 ck_assert(0);
282 }
283
284 BobsCC[i].incoming = false;
285 }
286 }
287
288 c_sleep(20);
289 } while (time(nullptr) - start_time < 3);
290
291 /* Hangup */
292 for (size_t i = 0; i < 3; i++) {
293 Toxav_Err_Call_Control rc;
294 toxav_call_control(AliceAV, i, TOXAV_CALL_CONTROL_CANCEL, &rc);
295
296 if (rc != TOXAV_ERR_CALL_CONTROL_OK) {
297 printf("toxav_call_control failed: %d %p %p\n", rc, (void *)AliceAV, (void *)&BobsAV[i]);
298 }
299 }
300
301 do {
302 tox_iterate(bootstrap, nullptr);
303 tox_iterate(Alice, nullptr);
304 tox_iterate(Bobs[0], nullptr);
305 tox_iterate(Bobs[1], nullptr);
306 tox_iterate(Bobs[2], nullptr);
307
308 c_sleep(20);
300 } while (time(nullptr) - start_time < 5); 309 } while (time(nullptr) - start_time < 5);
301 310
302 ck_assert(pthread_join(tids[0], &retval) == 0); 311 ck_assert(pthread_join(tids[0], &retval) == 0);