diff options
Diffstat (limited to 'auto_tests')
-rw-r--r-- | auto_tests/tox_test.c | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index 501c93dc..fa1d43e1 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c | |||
@@ -286,6 +286,16 @@ void tox_connection_status(Tox *tox, TOX_CONNECTION connection_status, void *use | |||
286 | 286 | ||
287 | START_TEST(test_one) | 287 | START_TEST(test_one) |
288 | { | 288 | { |
289 | { | ||
290 | TOX_ERR_OPTIONS_NEW o_err; | ||
291 | struct Tox_Options *o1 = tox_options_new(&o_err); | ||
292 | struct Tox_Options o2; | ||
293 | tox_options_default(&o2); | ||
294 | ck_assert_msg(o_err == TOX_ERR_OPTIONS_NEW_OK, "tox_options_new wrong error"); | ||
295 | ck_assert_msg(memcmp(o1, &o2, sizeof(struct Tox_Options)) == 0, "tox_options_new error"); | ||
296 | tox_options_free(o1); | ||
297 | } | ||
298 | |||
289 | Tox *tox1 = tox_new(0, 0); | 299 | Tox *tox1 = tox_new(0, 0); |
290 | Tox *tox2 = tox_new(0, 0); | 300 | Tox *tox2 = tox_new(0, 0); |
291 | 301 | ||
@@ -468,6 +478,44 @@ START_TEST(test_few_clients) | |||
468 | 478 | ||
469 | printf("tox clients messaging succeeded\n"); | 479 | printf("tox clients messaging succeeded\n"); |
470 | 480 | ||
481 | unsigned int save_size1 = tox_get_savedata_size(tox2); | ||
482 | ck_assert_msg(save_size1 != 0 && save_size1 < 4096, "save is invalid size %u", save_size1); | ||
483 | printf("%u\n", save_size1); | ||
484 | uint8_t save1[save_size1]; | ||
485 | tox_get_savedata(tox2, save1); | ||
486 | tox_kill(tox2); | ||
487 | |||
488 | struct Tox_Options options; | ||
489 | tox_options_default(&options); | ||
490 | options.savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE; | ||
491 | options.savedata_data = save1; | ||
492 | options.savedata_length = save_size1; | ||
493 | tox2 = tox_new(&options, NULL); | ||
494 | cur_time = time(NULL); | ||
495 | off = 1; | ||
496 | |||
497 | while (1) { | ||
498 | tox_iterate(tox1); | ||
499 | tox_iterate(tox2); | ||
500 | tox_iterate(tox3); | ||
501 | |||
502 | if (tox_self_get_connection_status(tox1) && tox_self_get_connection_status(tox2) | ||
503 | && tox_self_get_connection_status(tox3)) { | ||
504 | if (off) { | ||
505 | printf("Toxes are online again after reloading, took %llu seconds\n", time(NULL) - cur_time); | ||
506 | con_time = time(NULL); | ||
507 | off = 0; | ||
508 | } | ||
509 | |||
510 | if (tox_friend_get_connection_status(tox2, 0, 0) == TOX_CONNECTION_UDP | ||
511 | && tox_friend_get_connection_status(tox3, 0, 0) == TOX_CONNECTION_UDP) | ||
512 | break; | ||
513 | } | ||
514 | |||
515 | c_sleep(50); | ||
516 | } | ||
517 | |||
518 | printf("tox clients connected took %llu seconds\n", time(NULL) - con_time); | ||
471 | tox_callback_friend_name(tox3, print_nickchange, &to_compare); | 519 | tox_callback_friend_name(tox3, print_nickchange, &to_compare); |
472 | TOX_ERR_SET_INFO err_n; | 520 | TOX_ERR_SET_INFO err_n; |
473 | bool succ = tox_self_set_name(tox2, (uint8_t *)"Gentoo", sizeof("Gentoo"), &err_n); | 521 | bool succ = tox_self_set_name(tox2, (uint8_t *)"Gentoo", sizeof("Gentoo"), &err_n); |
@@ -785,6 +833,14 @@ START_TEST(test_many_clients) | |||
785 | 833 | ||
786 | uint8_t address[TOX_ADDRESS_SIZE]; | 834 | uint8_t address[TOX_ADDRESS_SIZE]; |
787 | 835 | ||
836 | unsigned int num_f = 0; | ||
837 | |||
838 | for (i = 0; i < NUM_TOXES; ++i) { | ||
839 | num_f += tox_self_get_friend_list_size(toxes[i]); | ||
840 | } | ||
841 | |||
842 | ck_assert_msg(num_f == 0, "bad num friends: %u", num_f); | ||
843 | |||
788 | for (i = 0; i < NUM_FRIENDS; ++i) { | 844 | for (i = 0; i < NUM_FRIENDS; ++i) { |
789 | loop_top: | 845 | loop_top: |
790 | pairs[i].tox1 = rand() % NUM_TOXES; | 846 | pairs[i].tox1 = rand() % NUM_TOXES; |
@@ -807,6 +863,12 @@ loop_top: | |||
807 | ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "Failed to add friend error code: %i", test); | 863 | ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "Failed to add friend error code: %i", test); |
808 | } | 864 | } |
809 | 865 | ||
866 | for (i = 0; i < NUM_TOXES; ++i) { | ||
867 | num_f += tox_self_get_friend_list_size(toxes[i]); | ||
868 | } | ||
869 | |||
870 | ck_assert_msg(num_f == NUM_FRIENDS, "bad num friends: %u", num_f); | ||
871 | |||
810 | while (1) { | 872 | while (1) { |
811 | uint16_t counter = 0; | 873 | uint16_t counter = 0; |
812 | 874 | ||
@@ -1210,7 +1272,7 @@ Suite *tox_suite(void) | |||
1210 | Suite *s = suite_create("Tox"); | 1272 | Suite *s = suite_create("Tox"); |
1211 | 1273 | ||
1212 | DEFTESTCASE(one); | 1274 | DEFTESTCASE(one); |
1213 | DEFTESTCASE_SLOW(few_clients, 50); | 1275 | DEFTESTCASE_SLOW(few_clients, 80); |
1214 | DEFTESTCASE_SLOW(many_clients, 80); | 1276 | DEFTESTCASE_SLOW(many_clients, 80); |
1215 | DEFTESTCASE_SLOW(many_clients_tcp, 20); | 1277 | DEFTESTCASE_SLOW(many_clients_tcp, 20); |
1216 | DEFTESTCASE_SLOW(many_clients_tcp_b, 20); | 1278 | DEFTESTCASE_SLOW(many_clients_tcp_b, 20); |