summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/Makefile.inc28
-rw-r--r--auto_tests/toxav_basic_test.c86
-rw-r--r--auto_tests/toxav_many_test.c21
3 files changed, 75 insertions, 60 deletions
diff --git a/auto_tests/Makefile.inc b/auto_tests/Makefile.inc
index 5e101f60..55a52541 100644
--- a/auto_tests/Makefile.inc
+++ b/auto_tests/Makefile.inc
@@ -1,9 +1,7 @@
1if BUILD_TESTS 1if BUILD_TESTS
2 2
3TESTS = messenger_autotest crypto_test network_test assoc_test onion_test TCP_test tox_test 3TESTS = messenger_autotest crypto_test network_test assoc_test onion_test TCP_test tox_test
4#toxav_basic_test toxav_many_test 4check_PROGRAMS = messenger_autotest crypto_test network_test assoc_test onion_test TCP_test tox_test
5check_PROGRAMS = messenger_autotest crypto_test network_test assoc_test onion_test TCP_test tox_test
6#toxav_basic_test toxav_many_test
7 5
8AUTOTEST_CFLAGS = \ 6AUTOTEST_CFLAGS = \
9 $(LIBSODIUM_CFLAGS) \ 7 $(LIBSODIUM_CFLAGS) \
@@ -20,11 +18,11 @@ AUTOTEST_LDADD = \
20 $(CHECK_LIBS) 18 $(CHECK_LIBS)
21 19
22 20
23#Tests don't work atm 21
24if BUILD_AV 22if BUILD_AV
25#TESTS += toxav_basic_test 23TESTS += toxav_basic_test toxav_many_test
26#check_PROGRAMS += toxav_basic_test 24check_PROGRAMS += toxav_basic_test toxav_many_test
27#AUTOTEST_LDADD += libtoxav.la 25AUTOTEST_LDADD += libtoxav.la
28endif 26endif
29 27
30messenger_autotest_SOURCES = ../auto_tests/messenger_test.c 28messenger_autotest_SOURCES = ../auto_tests/messenger_test.c
@@ -76,20 +74,20 @@ tox_test_CFLAGS = $(AUTOTEST_CFLAGS)
76tox_test_LDADD = $(AUTOTEST_LDADD) 74tox_test_LDADD = $(AUTOTEST_LDADD)
77 75
78 76
79#Tests don't work atm 77
80if BUILD_AV 78if BUILD_AV
81#toxav_basic_test_SOURCES = ../auto_tests/toxav_basic_test.c 79toxav_basic_test_SOURCES = ../auto_tests/toxav_basic_test.c
82 80
83#toxav_basic_test_CFLAGS = $(AUTOTEST_CFLAGS) 81toxav_basic_test_CFLAGS = $(AUTOTEST_CFLAGS)
84 82
85#toxav_basic_test_LDADD = $(AUTOTEST_LDADD) 83toxav_basic_test_LDADD = $(AUTOTEST_LDADD)
86 84
87 85
88#toxav_many_test_SOURCES = ../auto_tests/toxav_many_test.c 86toxav_many_test_SOURCES = ../auto_tests/toxav_many_test.c
89 87
90#toxav_many_test_CFLAGS = $(AUTOTEST_CFLAGS) 88toxav_many_test_CFLAGS = $(AUTOTEST_CFLAGS)
91 89
92#toxav_many_test_LDADD = $(AUTOTEST_LDADD) 90toxav_many_test_LDADD = $(AUTOTEST_LDADD)
93endif 91endif
94 92
95endif 93endif
diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c
index c0162582..116a519a 100644
--- a/auto_tests/toxav_basic_test.c
+++ b/auto_tests/toxav_basic_test.c
@@ -13,6 +13,7 @@
13 13
14#include "../toxcore/tox.h" 14#include "../toxcore/tox.h"
15#include "../toxcore/logger.h" 15#include "../toxcore/logger.h"
16#include "../toxcore/crypto_core.h"
16#include "../toxav/toxav.h" 17#include "../toxav/toxav.h"
17 18
18#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) 19#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
@@ -159,6 +160,7 @@ case 3: /* Wait for Both to have status ended */\
159if (status_control.Alice.status == Ended && status_control.Bob.status == Ended) running = 0; break; } c_sleep(20); } } printf("\n"); 160if (status_control.Alice.status == Ended && status_control.Bob.status == Ended) running = 0; break; } c_sleep(20); } } printf("\n");
160 161
161START_TEST(test_AV_flows) 162START_TEST(test_AV_flows)
163// int test_AV_flows()
162{ 164{
163 long long unsigned int cur_time = time(NULL); 165 long long unsigned int cur_time = time(NULL);
164 Tox *bootstrap_node = tox_new(0); 166 Tox *bootstrap_node = tox_new(0);
@@ -200,11 +202,10 @@ START_TEST(test_AV_flows)
200 muhcaps.video_height = muhcaps.video_width = 128; 202 muhcaps.video_height = muhcaps.video_width = 128;
201 203
202 Status status_control = { 204 Status status_control = {
203 {none, toxav_new(Alice, 1), NULL}, 205 {none, toxav_new(Alice, 1), NULL, -1},
204 {none, toxav_new(Bob, 1), NULL}, 206 {none, toxav_new(Bob, 1), NULL, -1},
205 }; 207 };
206 208
207
208 ck_assert_msg(status_control.Alice.av || status_control.Bob.av, "Failed to create 2 toxav instances"); 209 ck_assert_msg(status_control.Alice.av || status_control.Bob.av, "Failed to create 2 toxav instances");
209 210
210 211
@@ -222,9 +223,11 @@ START_TEST(test_AV_flows)
222 toxav_register_callstate_callback(callback_requ_timeout, av_OnRequestTimeout, &status_control); 223 toxav_register_callstate_callback(callback_requ_timeout, av_OnRequestTimeout, &status_control);
223 224
224 225
225 226 const int frame_size = (av_DefaultSettings.audio_sample_rate * av_DefaultSettings.audio_frame_duration / 1000);
226 int16_t sample_payload[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 227 int16_t sample_payload[frame_size];
227 uint8_t prepared_payload[1000]; 228 randombytes_salsa20_random_buf(sample_payload, sizeof(int16_t) * frame_size);
229
230 uint8_t prepared_payload[RTP_PAYLOAD_SIZE];
228 int payload_size; 231 int payload_size;
229 232
230 vpx_image_t *sample_image = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, 128, 128, 1); 233 vpx_image_t *sample_image = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, 128, 128, 1);
@@ -241,30 +244,34 @@ START_TEST(test_AV_flows)
241 /* 244 /*
242 * Call with audio only on both sides. Alice calls Bob. 245 * Call with audio only on both sides. Alice calls Bob.
243 */ 246 */
247
248
244 CALL_AND_START_LOOP(TypeAudio, TypeAudio) { 249 CALL_AND_START_LOOP(TypeAudio, TypeAudio) {
245 /* Both send */ 250 /* Both send */
246 int payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, 1000, sample_payload, 120); 251 payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, 1000, sample_payload, frame_size);
247 if (!( payload_size > 0 )) { /* FIXME: this will always fail */ 252 if ( payload_size < 0 ) {
248 ck_assert_msg ( 0, "Failed to encode payload" ); 253 ck_assert_msg ( 0, "Failed to encode payload" );
249 } 254 }
250
251 toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size); 255 toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
256
257 payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000, sample_payload, frame_size);
258 if ( payload_size < 0 ) {
259 ck_assert_msg ( 0, "Failed to encode payload" );
260 }
252 toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size); 261 toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
253 262
254 /* Both receive */ 263 /* Both receive */
255 int16_t storage[10]; 264 int16_t storage[frame_size];
256 int recved; 265 int recved;
257 266
258 /* Payload from Bob */ 267 /* Payload from Bob */
259 recved = toxav_recv_audio(status_control.Alice.av, status_control.Alice.call_index, 120, storage); 268 recved = toxav_recv_audio(status_control.Alice.av, status_control.Alice.call_index, frame_size, storage);
260 269
261 if ( recved ) { 270 if ( recved ) {
262 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");*/ 271 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");*/
263 memset(storage, 0, 10);
264 } 272 }
265 273
266 /* Payload from Alice */ 274 recved = toxav_recv_audio(status_control.Bob.av, status_control.Bob.call_index, frame_size, storage);
267 recved = toxav_recv_audio(status_control.Bob.av, status_control.Bob.call_index, 120, storage);
268 275
269 if ( recved ) { 276 if ( recved ) {
270 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");*/ 277 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");*/
@@ -286,28 +293,30 @@ START_TEST(test_AV_flows)
286 * Call with audio on both sides and video on one side. Alice calls Bob. 293 * Call with audio on both sides and video on one side. Alice calls Bob.
287 */ 294 */
288 CALL_AND_START_LOOP(TypeAudio, TypeVideo) { 295 CALL_AND_START_LOOP(TypeAudio, TypeVideo) {
289 /* Both send */ 296 /* Both send */
290 int payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, 1000, sample_payload, 120); 297 payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, 1000, sample_payload, frame_size);
291 if (!( payload_size > 0 )) { /* FIXME: this will always fail */ 298 if ( payload_size < 0 ) {
292 ck_assert_msg ( 0, "Failed to encode payload" ); 299 ck_assert_msg ( 0, "Failed to encode payload" );
293 } 300 }
294
295 toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size); 301 toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
296 302
303 payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000, sample_payload, frame_size);
304 if ( payload_size < 0 ) {
305 ck_assert_msg ( 0, "Failed to encode payload" );
306 }
297 toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size); 307 toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
298// toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image); 308// toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image);
299 309
300 /* Both receive */ 310 /* Both receive */
301 int16_t storage[10]; 311 int16_t storage[frame_size];
302 vpx_image_t *video_storage; 312 vpx_image_t *video_storage;
303 int recved; 313 int recved;
304 314
305 /* Payload from Bob */ 315 /* Payload from Bob */
306 recved = toxav_recv_audio(status_control.Alice.av, status_control.Alice.call_index, 120, storage); 316 recved = toxav_recv_audio(status_control.Alice.av, status_control.Alice.call_index, frame_size, storage);
307 317
308 if ( recved ) { 318 if ( recved ) {
309 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");*/ 319 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");*/
310 memset(storage, 0, 10);
311 } 320 }
312 321
313 /* Video payload */ 322 /* Video payload */
@@ -324,7 +333,7 @@ START_TEST(test_AV_flows)
324 333
325 334
326 /* Payload from Alice */ 335 /* Payload from Alice */
327 recved = toxav_recv_audio(status_control.Bob.av, status_control.Bob.call_index, 120, storage); 336 recved = toxav_recv_audio(status_control.Bob.av, status_control.Bob.call_index, frame_size, storage);
328 337
329 if ( recved ) { 338 if ( recved ) {
330 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");*/ 339 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");*/
@@ -347,28 +356,32 @@ START_TEST(test_AV_flows)
347 */ 356 */
348 CALL_AND_START_LOOP(TypeVideo, TypeVideo) { 357 CALL_AND_START_LOOP(TypeVideo, TypeVideo) {
349 /* Both send */ 358 /* Both send */
350 int payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, 1000, sample_payload, 120); 359
351 if (!( payload_size > 0 )) { /* FIXME: this will always fail */ 360 payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, 1000, sample_payload, frame_size);
361 if ( payload_size < 0 ) {
352 ck_assert_msg ( 0, "Failed to encode payload" ); 362 ck_assert_msg ( 0, "Failed to encode payload" );
353 } 363 }
364 toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size);
354 365
355 toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size); 366 payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000, sample_payload, frame_size);
356// toxav_send_video(status_control.Alice.av, status_control.Alice.call_index, sample_image); 367 if ( payload_size < 0 ) {
357 368 ck_assert_msg ( 0, "Failed to encode payload" );
369 }
358 toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size); 370 toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size);
371
372// toxav_send_video(status_control.Alice.av, status_control.Alice.call_index, sample_image);
359// toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image); 373// toxav_send_video(status_control.Bob.av, status_control.Bob.call_index, sample_image);
360 374
361 /* Both receive */ 375 /* Both receive */
362 int16_t storage[10]; 376 int16_t storage[frame_size];
363 vpx_image_t *video_storage; 377 vpx_image_t *video_storage;
364 int recved; 378 int recved;
365 379
366 /* Payload from Bob */ 380 /* Payload from Bob */
367 recved = toxav_recv_audio(status_control.Alice.av, status_control.Alice.call_index, 120, storage); 381 recved = toxav_recv_audio(status_control.Alice.av, status_control.Alice.call_index, frame_size, storage);
368 382
369 if ( recved ) { 383 if ( recved ) {
370 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");*/ 384 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Bob is invalid");*/
371 memset(storage, 0, 10);
372 } 385 }
373 386
374 /* Video payload */ 387 /* Video payload */
@@ -385,7 +398,7 @@ START_TEST(test_AV_flows)
385 398
386 399
387 /* Payload from Alice */ 400 /* Payload from Alice */
388 recved = toxav_recv_audio(status_control.Bob.av, status_control.Bob.call_index, 120, storage); 401 recved = toxav_recv_audio(status_control.Bob.av, status_control.Bob.call_index, frame_size, storage);
389 402
390 if ( recved ) { 403 if ( recved ) {
391 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");*/ 404 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from Alice is invalid");*/
@@ -437,7 +450,6 @@ START_TEST(test_AV_flows)
437 toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, TypeAudio, 10); 450 toxav_call(status_control.Alice.av, &status_control.Alice.call_index, 0, TypeAudio, 10);
438 step++; 451 step++;
439 break; 452 break;
440 \
441 453
442 case 1: /* Bob */ 454 case 1: /* Bob */
443 if (status_control.Bob.status == Ringing) { 455 if (status_control.Bob.status == Ringing) {
@@ -491,7 +503,7 @@ START_TEST(test_AV_flows)
491 break; 503 break;
492 504
493 case 2: /* Wait for Both to have status ended */ 505 case 2: /* Wait for Both to have status ended */
494 if (status_control.Alice.status == Ended && status_control.Bob.status == Cancel) running = 0; 506 if (status_control.Bob.status == Cancel) running = 0;
495 507
496 break; 508 break;
497 } 509 }
@@ -521,7 +533,7 @@ Suite *tox_suite(void)
521 533
522 TCase *tc_av_flows = tcase_create("AV_flows"); 534 TCase *tc_av_flows = tcase_create("AV_flows");
523 tcase_add_test(tc_av_flows, test_AV_flows); 535 tcase_add_test(tc_av_flows, test_AV_flows);
524 tcase_set_timeout(tc_av_flows, 100); /* Timeout on 100 too much? */ 536 tcase_set_timeout(tc_av_flows, 200);
525 suite_add_tcase(s, tc_av_flows); 537 suite_add_tcase(s, tc_av_flows);
526 538
527 return s; 539 return s;
@@ -539,4 +551,6 @@ int main(int argc, char *argv[])
539 srunner_free(test_runner); 551 srunner_free(test_runner);
540 552
541 return number_failed; 553 return number_failed;
554
555// return test_AV_flows();
542} 556}
diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c
index b499b439..f9a24012 100644
--- a/auto_tests/toxav_many_test.c
+++ b/auto_tests/toxav_many_test.c
@@ -13,6 +13,7 @@
13 13
14#include "../toxcore/tox.h" 14#include "../toxcore/tox.h"
15#include "../toxcore/logger.h" 15#include "../toxcore/logger.h"
16#include "../toxcore/crypto_core.h"
16#include "../toxav/toxav.h" 17#include "../toxav/toxav.h"
17 18
18#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) 19#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
@@ -131,9 +132,11 @@ void* in_thread_call (void* arg)
131 int step = 0,running = 1; 132 int step = 0,running = 1;
132 int call_idx; 133 int call_idx;
133 134
135 const int frame_size = (av_DefaultSettings.audio_sample_rate * av_DefaultSettings.audio_frame_duration / 1000);
136 int16_t sample_payload[frame_size];
137 randombytes_salsa20_random_buf(sample_payload, sizeof(int16_t) * frame_size);
134 138
135 int16_t sample_payload[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 139 uint8_t prepared_payload[RTP_PAYLOAD_SIZE];
136 uint8_t prepared_payload[1000];
137 140
138 141
139 /* NOTE: CALLEE WILL ALWAHYS NEED CALL_IDX == 0 */ 142 /* NOTE: CALLEE WILL ALWAHYS NEED CALL_IDX == 0 */
@@ -162,37 +165,37 @@ void* in_thread_call (void* arg)
162 toxav_prepare_transmission(this_call->Callee.av, 0, &cast, 1); 165 toxav_prepare_transmission(this_call->Callee.av, 0, &cast, 1);
163 toxav_prepare_transmission(this_call->Caller.av, call_idx, &cast, 1); 166 toxav_prepare_transmission(this_call->Caller.av, call_idx, &cast, 1);
164 167
165 int payload_size = toxav_prepare_audio_frame(this_call->Caller.av, call_idx, prepared_payload, 1000, sample_payload, 120); 168 int payload_size = toxav_prepare_audio_frame(this_call->Caller.av, call_idx, prepared_payload, RTP_PAYLOAD_SIZE, sample_payload, frame_size);
166 if (!( payload_size > 0 )) { 169 if ( payload_size < 0 ) {
167 ck_assert_msg ( 0, "Failed to encode payload" ); 170 ck_assert_msg ( 0, "Failed to encode payload" );
168 } 171 }
169 172
173
170 while (time(NULL) - start < 10) { /* 10 seconds */ 174 while (time(NULL) - start < 10) { /* 10 seconds */
171 /* Both send */ 175 /* Both send */
172 toxav_send_audio(this_call->Caller.av, call_idx, prepared_payload, payload_size); 176 toxav_send_audio(this_call->Caller.av, call_idx, prepared_payload, payload_size);
173 177
174 toxav_send_audio(this_call->Callee.av, 0, prepared_payload, payload_size); 178 toxav_send_audio(this_call->Callee.av, 0, prepared_payload, payload_size);
175 179
176 call_print(time(NULL) - start, "Blaaah");
177 /* Both receive */ 180 /* Both receive */
178 int16_t storage[1000]; 181 int16_t storage[RTP_PAYLOAD_SIZE];
179 int recved; 182 int recved;
180 183
181 /* Payload from CALLER */ 184 /* Payload from CALLER */
182 recved = toxav_recv_audio(this_call->Callee.av, 0, 120, storage); 185 recved = toxav_recv_audio(this_call->Callee.av, 0, frame_size, storage);
183 186
184 if ( recved ) { 187 if ( recved ) {
185 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from CALLER is invalid");*/ 188 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from CALLER is invalid");*/
186 } 189 }
187 190
188 /* Payload from CALLEE */ 191 /* Payload from CALLEE */
189 recved = toxav_recv_audio(this_call->Caller.av, call_idx, 120, storage); 192 recved = toxav_recv_audio(this_call->Caller.av, call_idx, frame_size, storage);
190 193
191 if ( recved ) { 194 if ( recved ) {
192 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from CALLEE is invalid");*/ 195 /*ck_assert_msg(recved == 10 && memcmp(storage, sample_payload, 10) == 0, "Payload from CALLEE is invalid");*/
193 } 196 }
194 197
195 //c_sleep(20); 198 c_sleep(20);
196 } 199 }
197 200
198 step++; /* This terminates the loop */ 201 step++; /* This terminates the loop */