summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-02-26 08:24:19 -0500
committerirungentoo <irungentoo@gmail.com>2015-02-26 08:24:19 -0500
commite61e2919a92ca76e554c9fdc135d0a6ea5d6aedb (patch)
treeccad30367fc69a1285f3611701a6107760a7f7f3 /auto_tests
parent33370edee66b27c4bd2b6b838c764241d737769e (diff)
More tests ported to new api.
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/tox_test.c148
1 files changed, 78 insertions, 70 deletions
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c
index 7e375db0..d9cb46db 100644
--- a/auto_tests/tox_test.c
+++ b/auto_tests/tox_test.c
@@ -70,12 +70,12 @@ void print_typingchange(Tox *m, uint32_t friendnumber, bool typing, void *userda
70 70
71uint32_t custom_packet; 71uint32_t custom_packet;
72 72
73int handle_custom_packet(Tox *m, int32_t friend_num, const uint8_t *data, uint32_t len, void *object) 73void handle_custom_packet(Tox *m, uint32_t friend_num, const uint8_t *data, size_t len, void *object)
74{ 74{
75 uint8_t number = *((uint32_t *)object); 75 uint8_t number = *((uint32_t *)object);
76 76
77 if (len != TOX_MAX_CUSTOM_PACKET_SIZE) 77 if (len != TOX_MAX_CUSTOM_PACKET_SIZE)
78 return -1; 78 return;
79 79
80 uint8_t f_data[len]; 80 uint8_t f_data[len];
81 memset(f_data, number, len); 81 memset(f_data, number, len);
@@ -86,7 +86,7 @@ int handle_custom_packet(Tox *m, int32_t friend_num, const uint8_t *data, uint32
86 printf("Custom packet fail. %u\n", number ); 86 printf("Custom packet fail. %u\n", number );
87 } 87 }
88 88
89 return 0; 89 return;
90} 90}
91 91
92uint8_t filenum; 92uint8_t filenum;
@@ -208,32 +208,33 @@ END_TEST
208START_TEST(test_few_clients) 208START_TEST(test_few_clients)
209{ 209{
210 long long unsigned int con_time, cur_time = time(NULL); 210 long long unsigned int con_time, cur_time = time(NULL);
211 Tox *tox1 = tox_new(0); 211 Tox *tox1 = tox_new(0, 0, 0, 0);
212 Tox *tox2 = tox_new(0); 212 Tox *tox2 = tox_new(0, 0, 0, 0);
213 Tox *tox3 = tox_new(0); 213 Tox *tox3 = tox_new(0, 0, 0, 0);
214 ck_assert_msg(tox1 || tox2 || tox3, "Failed to create 3 tox instances"); 214 ck_assert_msg(tox1 || tox2 || tox3, "Failed to create 3 tox instances");
215 uint32_t to_compare = 974536; 215 uint32_t to_compare = 974536;
216 tox_callback_friend_request(tox2, accept_friend_request, &to_compare); 216 tox_callback_friend_request(tox2, accept_friend_request, &to_compare);
217 uint8_t address[TOX_FRIEND_ADDRESS_SIZE]; 217 uint8_t address[TOX_ADDRESS_SIZE];
218 tox_get_address(tox2, address); 218 tox_self_get_address(tox2, address);
219 int test = tox_add_friend(tox3, address, (uint8_t *)"Gentoo", 7); 219 uint32_t test = tox_friend_add(tox3, address, (uint8_t *)"Gentoo", 7, 0);
220 ck_assert_msg(test == 0, "Failed to add friend error code: %i", test); 220 ck_assert_msg(test == 0, "Failed to add friend error code: %i", test);
221 221
222 uint8_t off = 1; 222 uint8_t off = 1;
223 223
224 while (1) { 224 while (1) {
225 tox_do(tox1); 225 tox_iteration(tox1);
226 tox_do(tox2); 226 tox_iteration(tox2);
227 tox_do(tox3); 227 tox_iteration(tox3);
228 228
229 if (tox_isconnected(tox1) && tox_isconnected(tox2) && tox_isconnected(tox3) && off) { 229 if (tox_get_connection_status(tox1) && tox_get_connection_status(tox2) && tox_get_connection_status(tox3) && off) {
230 printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time); 230 printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time);
231 con_time = time(NULL); 231 con_time = time(NULL);
232 off = 0; 232 off = 0;
233 } 233 }
234 234
235 235
236 if (tox_get_friend_connection_status(tox2, 0) == 1 && tox_get_friend_connection_status(tox3, 0) == 1) 236 if (tox_friend_get_connection_status(tox2, 0, 0) == TOX_CONNECTION_UDP
237 && tox_friend_get_connection_status(tox3, 0, 0) == TOX_CONNECTION_UDP)
237 break; 238 break;
238 239
239 c_sleep(50); 240 c_sleep(50);
@@ -244,15 +245,17 @@ START_TEST(test_few_clients)
244 tox_callback_friend_message(tox3, print_message, &to_compare); 245 tox_callback_friend_message(tox3, print_message, &to_compare);
245 uint8_t msgs[TOX_MAX_MESSAGE_LENGTH + 1]; 246 uint8_t msgs[TOX_MAX_MESSAGE_LENGTH + 1];
246 memset(msgs, 'G', sizeof(msgs)); 247 memset(msgs, 'G', sizeof(msgs));
247 ck_assert_msg(tox_send_message(tox2, 0, msgs, TOX_MAX_MESSAGE_LENGTH + 1) == 0, 248 TOX_ERR_SEND_MESSAGE errm;
248 "TOX_MAX_MESSAGE_LENGTH is too small\n"); 249 tox_send_message(tox2, 0, msgs, TOX_MAX_MESSAGE_LENGTH + 1, &errm);
249 ck_assert_msg(tox_send_message(tox2, 0, msgs, TOX_MAX_MESSAGE_LENGTH) != 0, "TOX_MAX_MESSAGE_LENGTH is too big\n"); 250 ck_assert_msg(errm == TOX_ERR_SEND_MESSAGE_TOO_LONG, "TOX_MAX_MESSAGE_LENGTH is too small\n");
251 tox_send_message(tox2, 0, msgs, TOX_MAX_MESSAGE_LENGTH, &errm);
252 ck_assert_msg(errm == TOX_ERR_SEND_MESSAGE_OK, "TOX_MAX_MESSAGE_LENGTH is too big\n");
250 253
251 while (1) { 254 while (1) {
252 messages_received = 0; 255 messages_received = 0;
253 tox_do(tox1); 256 tox_iteration(tox1);
254 tox_do(tox2); 257 tox_iteration(tox2);
255 tox_do(tox3); 258 tox_iteration(tox3);
256 259
257 if (messages_received) 260 if (messages_received)
258 break; 261 break;
@@ -262,14 +265,16 @@ START_TEST(test_few_clients)
262 265
263 printf("tox clients messaging succeeded\n"); 266 printf("tox clients messaging succeeded\n");
264 267
265 tox_callback_name_change(tox3, print_nickchange, &to_compare); 268 tox_callback_friend_name(tox3, print_nickchange, &to_compare);
266 tox_set_name(tox2, (uint8_t *)"Gentoo", sizeof("Gentoo")); 269 TOX_ERR_SET_INFO err_n;
270 bool succ = tox_self_set_name(tox2, (uint8_t *)"Gentoo", sizeof("Gentoo"), &err_n);
271 ck_assert_msg(succ && err_n == TOX_ERR_SET_INFO_OK, "tox_self_set_name failed because %u\n", err_n);
267 272
268 while (1) { 273 while (1) {
269 name_changes = 0; 274 name_changes = 0;
270 tox_do(tox1); 275 tox_iteration(tox1);
271 tox_do(tox2); 276 tox_iteration(tox2);
272 tox_do(tox3); 277 tox_iteration(tox3);
273 278
274 if (name_changes) 279 if (name_changes)
275 break; 280 break;
@@ -277,18 +282,19 @@ START_TEST(test_few_clients)
277 c_sleep(50); 282 c_sleep(50);
278 } 283 }
279 284
285 ck_assert_msg(tox_friend_get_name_size(tox3, 0, 0) == sizeof("Gentoo"), "Name length not correct");
280 uint8_t temp_name[sizeof("Gentoo")]; 286 uint8_t temp_name[sizeof("Gentoo")];
281 tox_get_name(tox3, 0, temp_name); 287 tox_friend_get_name(tox3, 0, temp_name, 0);
282 ck_assert_msg(memcmp(temp_name, "Gentoo", sizeof("Gentoo")) == 0, "Name not correct"); 288 ck_assert_msg(memcmp(temp_name, "Gentoo", sizeof("Gentoo")) == 0, "Name not correct");
283 289
284 tox_callback_typing_change(tox2, &print_typingchange, &to_compare); 290 tox_callback_friend_typing(tox2, &print_typingchange, &to_compare);
285 tox_set_user_is_typing(tox3, 0, 1); 291 tox_self_set_typing(tox3, 0, 1, 0);
286 292
287 while (1) { 293 while (1) {
288 typing_changes = 0; 294 typing_changes = 0;
289 tox_do(tox1); 295 tox_iteration(tox1);
290 tox_do(tox2); 296 tox_iteration(tox2);
291 tox_do(tox3); 297 tox_iteration(tox3);
292 298
293 299
294 if (typing_changes == 2) 300 if (typing_changes == 2)
@@ -299,14 +305,14 @@ START_TEST(test_few_clients)
299 c_sleep(50); 305 c_sleep(50);
300 } 306 }
301 307
302 ck_assert_msg(tox_get_is_typing(tox2, 0) == 1, "Typing fail"); 308 ck_assert_msg(tox_friend_get_typing(tox2, 0, 0) == 1, "Typing fail");
303 tox_set_user_is_typing(tox3, 0, 0); 309 tox_self_set_typing(tox3, 0, 0, 0);
304 310
305 while (1) { 311 while (1) {
306 typing_changes = 0; 312 typing_changes = 0;
307 tox_do(tox1); 313 tox_iteration(tox1);
308 tox_do(tox2); 314 tox_iteration(tox2);
309 tox_do(tox3); 315 tox_iteration(tox3);
310 316
311 if (typing_changes == 1) 317 if (typing_changes == 1)
312 break; 318 break;
@@ -316,23 +322,24 @@ START_TEST(test_few_clients)
316 c_sleep(50); 322 c_sleep(50);
317 } 323 }
318 324
319 ck_assert_msg(tox_get_is_typing(tox2, 0) == 0, "Typing fail"); 325 TOX_ERR_FRIEND_QUERY err_t;
326 ck_assert_msg(tox_friend_get_typing(tox2, 0, &err_t) == 0, "Typing fail");
327 ck_assert_msg(err_t == TOX_ERR_FRIEND_QUERY_OK, "Typing fail");
320 328
321 uint32_t packet_number = 160; 329 uint32_t packet_number = 160;
322 int ret = tox_lossless_packet_registerhandler(tox3, 0, packet_number, &handle_custom_packet, &packet_number); 330 tox_callback_friend_lossless_packet(tox3, &handle_custom_packet, &packet_number);
323 ck_assert_msg(ret == 0, "tox_lossless_packet_registerhandler fail %i", ret);
324 uint8_t data_c[TOX_MAX_CUSTOM_PACKET_SIZE + 1]; 331 uint8_t data_c[TOX_MAX_CUSTOM_PACKET_SIZE + 1];
325 memset(data_c, ((uint8_t)packet_number), sizeof(data_c)); 332 memset(data_c, ((uint8_t)packet_number), sizeof(data_c));
326 ret = tox_send_lossless_packet(tox2, 0, data_c, sizeof(data_c)); 333 int ret = tox_send_lossless_packet(tox2, 0, data_c, sizeof(data_c), 0);
327 ck_assert_msg(ret == -1, "tox_send_lossless_packet bigger fail %i", ret); 334 ck_assert_msg(ret == 0, "tox_send_lossless_packet bigger fail %i", ret);
328 ret = tox_send_lossless_packet(tox2, 0, data_c, TOX_MAX_CUSTOM_PACKET_SIZE); 335 ret = tox_send_lossless_packet(tox2, 0, data_c, TOX_MAX_CUSTOM_PACKET_SIZE, 0);
329 ck_assert_msg(ret == 0, "tox_send_lossless_packet fail %i", ret); 336 ck_assert_msg(ret == 1, "tox_send_lossless_packet fail %i", ret);
330 337
331 while (1) { 338 while (1) {
332 custom_packet = 0; 339 custom_packet = 0;
333 tox_do(tox1); 340 tox_iteration(tox1);
334 tox_do(tox2); 341 tox_iteration(tox2);
335 tox_do(tox3); 342 tox_iteration(tox3);
336 343
337 if (custom_packet == 1) 344 if (custom_packet == 1)
338 break; 345 break;
@@ -343,19 +350,18 @@ START_TEST(test_few_clients)
343 } 350 }
344 351
345 packet_number = 200; 352 packet_number = 200;
346 ret = tox_lossy_packet_registerhandler(tox3, 0, packet_number, &handle_custom_packet, &packet_number); 353 tox_callback_friend_lossy_packet(tox3, &handle_custom_packet, &packet_number);
347 ck_assert_msg(ret == 0, "tox_lossy_packet_registerhandler fail %i", ret);
348 memset(data_c, ((uint8_t)packet_number), sizeof(data_c)); 354 memset(data_c, ((uint8_t)packet_number), sizeof(data_c));
349 ret = tox_send_lossy_packet(tox2, 0, data_c, sizeof(data_c)); 355 ret = tox_send_lossy_packet(tox2, 0, data_c, sizeof(data_c), 0);
350 ck_assert_msg(ret == -1, "tox_send_lossy_packet bigger fail %i", ret); 356 ck_assert_msg(ret == 0, "tox_send_lossy_packet bigger fail %i", ret);
351 ret = tox_send_lossy_packet(tox2, 0, data_c, TOX_MAX_CUSTOM_PACKET_SIZE); 357 ret = tox_send_lossy_packet(tox2, 0, data_c, TOX_MAX_CUSTOM_PACKET_SIZE, 0);
352 ck_assert_msg(ret == 0, "tox_send_lossy_packet fail %i", ret); 358 ck_assert_msg(ret == 1, "tox_send_lossy_packet fail %i", ret);
353 359
354 while (1) { 360 while (1) {
355 custom_packet = 0; 361 custom_packet = 0;
356 tox_do(tox1); 362 tox_iteration(tox1);
357 tox_do(tox2); 363 tox_iteration(tox2);
358 tox_do(tox3); 364 tox_iteration(tox3);
359 365
360 if (custom_packet == 1) 366 if (custom_packet == 1)
361 break; 367 break;
@@ -381,9 +387,9 @@ START_TEST(test_few_clients)
381 387
382 while (1) { 388 while (1) {
383 file_sent = 0; 389 file_sent = 0;
384 tox_do(tox1); 390 tox_iteration(tox1);
385 tox_do(tox2); 391 tox_iteration(tox2);
386 tox_do(tox3); 392 tox_iteration(tox3);
387 393
388 if (sendf_ok) 394 if (sendf_ok)
389 while (tox_file_send_data(tox2, 0, fnum, f_data, fpiece_size < totalf_size ? fpiece_size : totalf_size) == 0) { 395 while (tox_file_send_data(tox2, 0, fnum, f_data, fpiece_size < totalf_size ? fpiece_size : totalf_size) == 0) {
@@ -401,9 +407,9 @@ START_TEST(test_few_clients)
401 if (file_sent && size_recv == file_size) 407 if (file_sent && size_recv == file_size)
402 break; 408 break;
403 409
404 uint32_t tox1_interval = tox_do_interval(tox1); 410 uint32_t tox1_interval = tox_iteration_interval(tox1);
405 uint32_t tox2_interval = tox_do_interval(tox2); 411 uint32_t tox2_interval = tox_iteration_interval(tox2);
406 uint32_t tox3_interval = tox_do_interval(tox3); 412 uint32_t tox3_interval = tox_iteration_interval(tox3);
407 413
408 if (tox2_interval > tox3_interval) { 414 if (tox2_interval > tox3_interval) {
409 c_sleep(tox3_interval); 415 c_sleep(tox3_interval);
@@ -433,7 +439,7 @@ START_TEST(test_many_clients)
433 uint32_t to_comp = 974536; 439 uint32_t to_comp = 974536;
434 440
435 for (i = 0; i < NUM_TOXES; ++i) { 441 for (i = 0; i < NUM_TOXES; ++i) {
436 toxes[i] = tox_new(0); 442 toxes[i] = tox_new(0, 0, 0, 0);
437 ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); 443 ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i);
438 tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); 444 tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp);
439 } 445 }
@@ -443,7 +449,7 @@ START_TEST(test_many_clients)
443 uint16_t tox2; 449 uint16_t tox2;
444 } pairs[NUM_FRIENDS]; 450 } pairs[NUM_FRIENDS];
445 451
446 uint8_t address[TOX_FRIEND_ADDRESS_SIZE]; 452 uint8_t address[TOX_ADDRESS_SIZE];
447 453
448 for (i = 0; i < NUM_FRIENDS; ++i) { 454 for (i = 0; i < NUM_FRIENDS; ++i) {
449loop_top: 455loop_top:
@@ -455,22 +461,24 @@ loop_top:
455 goto loop_top; 461 goto loop_top;
456 } 462 }
457 463
458 tox_get_address(toxes[pairs[i].tox1], address); 464 tox_self_get_address(toxes[pairs[i].tox1], address);
459 int test = tox_add_friend(toxes[pairs[i].tox2], address, (uint8_t *)"Gentoo", 7);
460 465
461 if (test == TOX_FAERR_ALREADYSENT) { 466 TOX_ERR_FRIEND_ADD test;
467 uint32_t num = tox_friend_add(toxes[pairs[i].tox2], address, (uint8_t *)"Gentoo", 7, &test);
468
469 if (test == TOX_ERR_FRIEND_ADD_ALREADY_SENT) {
462 goto loop_top; 470 goto loop_top;
463 } 471 }
464 472
465 ck_assert_msg(test >= 0, "Failed to add friend error code: %i", test); 473 ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "Failed to add friend error code: %i", test);
466 } 474 }
467 475
468 while (1) { 476 while (1) {
469 uint16_t counter = 0; 477 uint16_t counter = 0;
470 478
471 for (i = 0; i < NUM_TOXES; ++i) { 479 for (i = 0; i < NUM_TOXES; ++i) {
472 for (j = 0; j < tox_count_friendlist(toxes[i]); ++j) 480 for (j = 0; j < tox_friend_list_size(toxes[i]); ++j)
473 if (tox_get_friend_connection_status(toxes[i], j) == 1) 481 if (tox_friend_get_connection_status(toxes[i], j, 0) == TOX_CONNECTION_UDP)
474 ++counter; 482 ++counter;
475 } 483 }
476 484
@@ -479,7 +487,7 @@ loop_top:
479 } 487 }
480 488
481 for (i = 0; i < NUM_TOXES; ++i) { 489 for (i = 0; i < NUM_TOXES; ++i) {
482 tox_do(toxes[i]); 490 tox_iteration(toxes[i]);
483 } 491 }
484 492
485 c_sleep(50); 493 c_sleep(50);