diff options
author | irungentoo <irungentoo@gmail.com> | 2014-12-04 20:54:59 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-12-04 20:54:59 -0500 |
commit | 035cd7ece36f38413aeb55c5e59a616d8348c71e (patch) | |
tree | eb538602fa8150331f73ad24b1797720d8b8c2b8 /auto_tests | |
parent | f1db6e7d6cb94584fbe03a30aebca36666b6e033 (diff) |
Added simple group auto test.
Diffstat (limited to 'auto_tests')
-rw-r--r-- | auto_tests/tox_test.c | 103 |
1 files changed, 101 insertions, 2 deletions
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index 65ce304c..2237f528 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c | |||
@@ -422,11 +422,109 @@ loop_top: | |||
422 | c_sleep(50); | 422 | c_sleep(50); |
423 | } | 423 | } |
424 | 424 | ||
425 | printf("test_many_clients succeeded, took %llu seconds\n", time(NULL) - cur_time); | ||
426 | |||
427 | for (i = 0; i < NUM_TOXES; ++i) { | 425 | for (i = 0; i < NUM_TOXES; ++i) { |
428 | tox_kill(toxes[i]); | 426 | tox_kill(toxes[i]); |
429 | } | 427 | } |
428 | |||
429 | printf("test_many_clients succeeded, took %llu seconds\n", time(NULL) - cur_time); | ||
430 | } | ||
431 | END_TEST | ||
432 | |||
433 | #define NUM_GROUP_TOX 6 | ||
434 | |||
435 | void g_accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata) | ||
436 | { | ||
437 | if (*((uint32_t *)userdata) != 234212) | ||
438 | return; | ||
439 | |||
440 | if (length == 7 && memcmp("Gentoo", data, 7) == 0) { | ||
441 | tox_add_friend_norequest(m, public_key); | ||
442 | } | ||
443 | } | ||
444 | |||
445 | void print_group_invite_callback(Tox *tox, int32_t friendnumber, uint8_t type, const uint8_t *data, uint16_t length, | ||
446 | void *userdata) | ||
447 | { | ||
448 | if (*((uint32_t *)userdata) != 234212) | ||
449 | return; | ||
450 | |||
451 | int g_num; | ||
452 | |||
453 | if ((g_num = tox_join_groupchat(tox, friendnumber, data, length)) == -1) | ||
454 | return; | ||
455 | |||
456 | ck_assert_msg(g_num == 0, "Group number was not 0"); | ||
457 | ck_assert_msg(tox_join_groupchat(tox, friendnumber, data, length) == -1, | ||
458 | "Joining groupchat twice should be impossible."); | ||
459 | |||
460 | if (tox_invite_friend(tox, 0, g_num) == -1) | ||
461 | return; | ||
462 | } | ||
463 | |||
464 | START_TEST(test_many_group) | ||
465 | { | ||
466 | long long unsigned int cur_time = time(NULL); | ||
467 | Tox *toxes[NUM_GROUP_TOX]; | ||
468 | unsigned int i; | ||
469 | |||
470 | uint32_t to_comp = 234212; | ||
471 | |||
472 | for (i = 0; i < NUM_GROUP_TOX; ++i) { | ||
473 | toxes[i] = tox_new(0); | ||
474 | ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); | ||
475 | tox_callback_friend_request(toxes[i], &g_accept_friend_request, &to_comp); | ||
476 | tox_callback_group_invite(toxes[i], &print_group_invite_callback, &to_comp); | ||
477 | } | ||
478 | |||
479 | uint8_t address[TOX_FRIEND_ADDRESS_SIZE]; | ||
480 | tox_get_address(toxes[NUM_GROUP_TOX - 1], address); | ||
481 | |||
482 | for (i = 0; i < NUM_GROUP_TOX; ++i) { | ||
483 | ck_assert_msg(tox_add_friend(toxes[i], address, (uint8_t *)"Gentoo", 7) == 0, "Failed to add friend"); | ||
484 | |||
485 | tox_get_address(toxes[i], address); | ||
486 | } | ||
487 | |||
488 | while (1) { | ||
489 | for (i = 0; i < NUM_GROUP_TOX; ++i) { | ||
490 | if (tox_get_friend_connection_status(toxes[i], 0) != 1) { | ||
491 | break; | ||
492 | } | ||
493 | } | ||
494 | |||
495 | if (i == NUM_GROUP_TOX) | ||
496 | break; | ||
497 | |||
498 | for (i = 0; i < NUM_GROUP_TOX; ++i) { | ||
499 | tox_do(toxes[i]); | ||
500 | } | ||
501 | |||
502 | c_sleep(50); | ||
503 | } | ||
504 | |||
505 | printf("friends connected, took %llu seconds\n", time(NULL) - cur_time); | ||
506 | |||
507 | ck_assert_msg(tox_add_groupchat(toxes[0]) != -1, "Failed to create group"); | ||
508 | ck_assert_msg(tox_invite_friend(toxes[0], 0, 0) == 0, "Failed to invite friend"); | ||
509 | |||
510 | while (1) { | ||
511 | for (i = 0; i < NUM_GROUP_TOX; ++i) { | ||
512 | if (tox_group_number_peers(toxes[i], 0) != NUM_GROUP_TOX) { | ||
513 | break; | ||
514 | } | ||
515 | } | ||
516 | |||
517 | if (i == NUM_GROUP_TOX) | ||
518 | break; | ||
519 | |||
520 | for (i = 0; i < NUM_GROUP_TOX; ++i) { | ||
521 | tox_do(toxes[i]); | ||
522 | } | ||
523 | |||
524 | c_sleep(50); | ||
525 | } | ||
526 | |||
527 | printf("test_many_group succeeded, took %llu seconds\n", time(NULL) - cur_time); | ||
430 | } | 528 | } |
431 | END_TEST | 529 | END_TEST |
432 | 530 | ||
@@ -436,6 +534,7 @@ Suite *tox_suite(void) | |||
436 | 534 | ||
437 | DEFTESTCASE_SLOW(few_clients, 50); | 535 | DEFTESTCASE_SLOW(few_clients, 50); |
438 | DEFTESTCASE_SLOW(many_clients, 150); | 536 | DEFTESTCASE_SLOW(many_clients, 150); |
537 | DEFTESTCASE_SLOW(many_group, 100); | ||
439 | return s; | 538 | return s; |
440 | } | 539 | } |
441 | 540 | ||