summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-12-05 21:39:46 -0500
committerirungentoo <irungentoo@gmail.com>2014-12-05 21:39:46 -0500
commit51121569531b504de6dc21303453f960b199ac56 (patch)
treeee3aaabd4875009b5cf74d24f3a376ab9992624f
parent035cd7ece36f38413aeb55c5e59a616d8348c71e (diff)
Added basic group message test.
-rw-r--r--auto_tests/tox_test.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c
index 2237f528..b1a314f2 100644
--- a/auto_tests/tox_test.c
+++ b/auto_tests/tox_test.c
@@ -461,11 +461,26 @@ void print_group_invite_callback(Tox *tox, int32_t friendnumber, uint8_t type, c
461 return; 461 return;
462} 462}
463 463
464static unsigned int num_recv;
465
466void print_group_message(Tox *tox, int groupnumber, int peernumber, const uint8_t *message, uint16_t length,
467 void *userdata)
468{
469 if (*((uint32_t *)userdata) != 234212)
470 return;
471
472 if (length != length)
473 if (memcmp(message, "Install Gentoo", sizeof("Install Gentoo") - 1) != 0)
474 return;
475
476 ++num_recv;
477}
478
464START_TEST(test_many_group) 479START_TEST(test_many_group)
465{ 480{
466 long long unsigned int cur_time = time(NULL); 481 long long unsigned int cur_time = time(NULL);
467 Tox *toxes[NUM_GROUP_TOX]; 482 Tox *toxes[NUM_GROUP_TOX];
468 unsigned int i; 483 unsigned int i, j;
469 484
470 uint32_t to_comp = 234212; 485 uint32_t to_comp = 234212;
471 486
@@ -524,6 +539,25 @@ START_TEST(test_many_group)
524 c_sleep(50); 539 c_sleep(50);
525 } 540 }
526 541
542 printf("group connected\n");
543
544 for (i = 0; i < NUM_GROUP_TOX; ++i) {
545 tox_callback_group_message(toxes[i], &print_group_message, &to_comp);
546 }
547
548 ck_assert_msg(tox_group_message_send(toxes[rand() % NUM_GROUP_TOX], 0, "Install Gentoo",
549 sizeof("Install Gentoo") - 1) == 0, "Failed to send group message.");
550 num_recv = 0;
551
552 for (j = 0; j < 20; ++j) {
553 for (i = 0; i < NUM_GROUP_TOX; ++i) {
554 tox_do(toxes[i]);
555 }
556
557 c_sleep(50);
558 }
559
560 ck_assert_msg(num_recv == NUM_GROUP_TOX, "Failed to recv group messages.");
527 printf("test_many_group succeeded, took %llu seconds\n", time(NULL) - cur_time); 561 printf("test_many_group succeeded, took %llu seconds\n", time(NULL) - cur_time);
528} 562}
529END_TEST 563END_TEST