summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/tox_test.c85
1 files changed, 84 insertions, 1 deletions
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c
index def9e5df..7e74fba7 100644
--- a/auto_tests/tox_test.c
+++ b/auto_tests/tox_test.c
@@ -62,6 +62,51 @@ void print_typingchange(Tox *m, int friendnumber, int typing, void *userdata)
62 typing_changes = 2; 62 typing_changes = 2;
63} 63}
64 64
65uint8_t filenum;
66uint32_t file_accepted;
67uint64_t file_size;
68void file_request_accept(Tox *m, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename,
69 uint16_t filename_length, void *userdata)
70{
71 if (*((uint32_t *)userdata) != 974536)
72 return;
73
74 if (filename_length == sizeof("Gentoo.exe") && memcmp(filename, "Gentoo.exe", sizeof("Gentoo.exe")) == 0)
75 ++file_accepted;
76
77 file_size = filesize;
78 tox_file_send_control(m, friendnumber, 1, filenumber, TOX_FILECONTROL_ACCEPT, NULL, 0);
79}
80
81uint32_t file_sent;
82uint32_t sendf_ok;
83void file_print_control(Tox *m, int friendnumber, uint8_t send_recieve, uint8_t filenumber, uint8_t control_type,
84 uint8_t *data, uint16_t length, void *userdata)
85{
86 if (*((uint32_t *)userdata) != 974536)
87 return;
88
89 if (send_recieve == 0 && control_type == TOX_FILECONTROL_FINISHED)
90 file_sent = 1;
91
92 if (send_recieve == 1 && control_type == TOX_FILECONTROL_ACCEPT)
93 sendf_ok = 1;
94
95}
96
97uint64_t size_recv;
98void write_file(Tox *m, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata)
99{
100 if (*((uint32_t *)userdata) != 974536)
101 return;
102
103 uint8_t *f_data = malloc(length);
104 memset(f_data, 6, length);
105
106 if (memcmp(f_data, data, length) == 0)
107 size_recv += length;
108}
109
65START_TEST(test_few_clients) 110START_TEST(test_few_clients)
66{ 111{
67 long long unsigned int cur_time = time(NULL); 112 long long unsigned int cur_time = time(NULL);
@@ -168,6 +213,44 @@ START_TEST(test_few_clients)
168 } 213 }
169 214
170 ck_assert_msg(tox_get_is_typing(tox2, 0) == 0, "Typing fail"); 215 ck_assert_msg(tox_get_is_typing(tox2, 0) == 0, "Typing fail");
216
217 filenum = file_accepted = file_size = file_sent = sendf_ok = size_recv = 0;
218 long long unsigned int f_time = time(NULL);
219 tox_callback_file_data(tox3, write_file, &to_compare);
220 tox_callback_file_control(tox2, file_print_control, &to_compare);
221 tox_callback_file_control(tox3, file_print_control, &to_compare);
222 tox_callback_file_send_request(tox3, file_request_accept, &to_compare);
223 uint64_t totalf_size = 100 * 1024 * 1024;
224 int fnum = tox_new_file_sender(tox2, 0, totalf_size, (uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"));
225 ck_assert_msg(fnum != -1, "tox_new_file_sender fail");
226 int fpiece_size = tox_file_data_size(tox2, 0);
227 uint8_t *f_data = malloc(fpiece_size);
228 memset(f_data, 6, fpiece_size);
229
230 while (1) {
231 file_sent = 0;
232 tox_do(tox1);
233 tox_do(tox2);
234 tox_do(tox3);
235
236 if (sendf_ok)
237 while (tox_file_send_data(tox2, 0, fnum, f_data, fpiece_size < totalf_size ? fpiece_size : totalf_size) == 0) {
238 if (totalf_size <= fpiece_size) {
239 sendf_ok = 0;
240 tox_file_send_control(tox2, 0, 0, fnum, TOX_FILECONTROL_FINISHED, NULL, 0);
241 }
242
243 totalf_size -= fpiece_size;
244 }
245
246 if (file_sent && size_recv == file_size)
247 break;
248
249 c_sleep(10);
250 }
251
252 printf("100MB file sent in %llu seconds\n", time(NULL) - f_time);
253
171 printf("test_few_clients succeeded, took %llu seconds\n", time(NULL) - cur_time); 254 printf("test_few_clients succeeded, took %llu seconds\n", time(NULL) - cur_time);
172} 255}
173END_TEST 256END_TEST
@@ -244,7 +327,7 @@ Suite *tox_suite(void)
244{ 327{
245 Suite *s = suite_create("Tox"); 328 Suite *s = suite_create("Tox");
246 329
247 DEFTESTCASE_SLOW(few_clients, 30); 330 DEFTESTCASE_SLOW(few_clients, 50);
248 DEFTESTCASE_SLOW(many_clients, 240); 331 DEFTESTCASE_SLOW(many_clients, 240);
249 return s; 332 return s;
250} 333}