summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-03-20 20:12:07 -0400
committerirungentoo <irungentoo@gmail.com>2015-03-20 20:12:07 -0400
commitb1ec15717526679c6d107e3a5a4b2bf08c26b650 (patch)
treec06a7d62a3394b05cf88f88b7fd50931631038d0 /auto_tests
parent8c18dd42a7c24f65d847a99a5147c8922e25fd85 (diff)
For file transfers UINT64_MAX is now used as the size for streaming
transfers instead of 0. For avatar transfers file size 0 now means that the client has no avatar set. Added a test for streaming transfers.
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/tox_test.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c
index 662c0da5..29b91bb2 100644
--- a/auto_tests/tox_test.c
+++ b/auto_tests/tox_test.c
@@ -182,6 +182,8 @@ void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number,
182 sendf_ok = 1; 182 sendf_ok = 1;
183} 183}
184 184
185uint64_t max_sending;
186_Bool m_send_reached;
185uint8_t sending_num; 187uint8_t sending_num;
186_Bool file_sending_done; 188_Bool file_sending_done;
187void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, size_t length, 189void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, size_t length,
@@ -204,6 +206,15 @@ void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_numb
204 return; 206 return;
205 } 207 }
206 208
209 if (position + length > max_sending) {
210 if (m_send_reached) {
211 ck_abort_msg("Requested done file tranfer.");
212 }
213
214 length = max_sending - position;
215 m_send_reached = 1;
216 }
217
207 TOX_ERR_FILE_SEND_CHUNK error; 218 TOX_ERR_FILE_SEND_CHUNK error;
208 uint8_t f_data[length]; 219 uint8_t f_data[length];
209 memset(f_data, sending_num, length); 220 memset(f_data, sending_num, length);
@@ -552,6 +563,7 @@ START_TEST(test_few_clients)
552 printf("Starting file transfer test.\n"); 563 printf("Starting file transfer test.\n");
553 564
554 file_accepted = file_size = file_recv = sendf_ok = size_recv = 0; 565 file_accepted = file_size = file_recv = sendf_ok = size_recv = 0;
566 max_sending = UINT64_MAX;
555 long long unsigned int f_time = time(NULL); 567 long long unsigned int f_time = time(NULL);
556 tox_callback_file_recv_chunk(tox3, write_file, &to_compare); 568 tox_callback_file_recv_chunk(tox3, write_file, &to_compare);
557 tox_callback_file_recv_control(tox2, file_print_control, &to_compare); 569 tox_callback_file_recv_control(tox2, file_print_control, &to_compare);
@@ -598,6 +610,56 @@ START_TEST(test_few_clients)
598 610
599 printf("100MB file sent in %llu seconds\n", time(NULL) - f_time); 611 printf("100MB file sent in %llu seconds\n", time(NULL) - f_time);
600 612
613 printf("Starting file streaming transfer test.\n");
614
615 file_sending_done = file_accepted = file_size = file_recv = sendf_ok = size_recv = 0;
616 f_time = time(NULL);
617 tox_callback_file_recv_chunk(tox3, write_file, &to_compare);
618 tox_callback_file_recv_control(tox2, file_print_control, &to_compare);
619 tox_callback_file_chunk_request(tox2, tox_file_chunk_request, &to_compare);
620 tox_callback_file_recv_control(tox3, file_print_control, &to_compare);
621 tox_callback_file_recv(tox3, tox_file_receive, &to_compare);
622 totalf_size = UINT64_MAX;
623 fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), 0);
624 ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail");
625
626 ck_assert_msg(!tox_file_get_file_id(tox2, 1, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id didn't fail");
627 ck_assert_msg(gfierr == TOX_ERR_FILE_GET_FRIEND_NOT_FOUND, "wrong error");
628 ck_assert_msg(!tox_file_get_file_id(tox2, 0, fnum + 1, file_cmp_id, &gfierr), "tox_file_get_file_id didn't fail");
629 ck_assert_msg(gfierr == TOX_ERR_FILE_GET_NOT_FOUND, "wrong error");
630 ck_assert_msg(tox_file_get_file_id(tox2, 0, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id failed");
631 ck_assert_msg(gfierr == TOX_ERR_FILE_GET_OK, "wrong error");
632
633 max_sending = 100 * 1024;
634 m_send_reached = 0;
635
636 while (1) {
637 tox_iterate(tox1);
638 tox_iterate(tox2);
639 tox_iterate(tox3);
640
641 if (file_sending_done) {
642 if (sendf_ok && file_recv && m_send_reached && totalf_size == file_size && size_recv == max_sending
643 && sending_pos == size_recv) {
644 break;
645 } else {
646 ck_abort_msg("Something went wrong in file transfer %u %u %u %u %u %u %llu %llu %llu %llu", sendf_ok, file_recv,
647 m_send_reached, totalf_size == file_size, size_recv == max_sending, sending_pos == size_recv, totalf_size, file_size,
648 size_recv, sending_pos);
649 }
650 }
651
652 uint32_t tox1_interval = tox_iteration_interval(tox1);
653 uint32_t tox2_interval = tox_iteration_interval(tox2);
654 uint32_t tox3_interval = tox_iteration_interval(tox3);
655
656 if (tox2_interval > tox3_interval) {
657 c_sleep(tox3_interval);
658 } else {
659 c_sleep(tox2_interval);
660 }
661 }
662
601 printf("test_few_clients succeeded, took %llu seconds\n", time(NULL) - cur_time); 663 printf("test_few_clients succeeded, took %llu seconds\n", time(NULL) - cur_time);
602 664
603 tox_kill(tox1); 665 tox_kill(tox1);