diff options
author | irungentoo <irungentoo@gmail.com> | 2015-07-01 22:13:27 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-07-01 22:13:27 -0400 |
commit | 7a3ca5d4c530e6899ca5127dbe224b94dea3056f (patch) | |
tree | a8f6a4d90f895319217f2dce5b8c688c47e1e66d | |
parent | 02b156f17a488f12f6c581f331ab36ad7c6920b9 (diff) |
Basic tcp connections test done.
-rw-r--r-- | auto_tests/TCP_test.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c index 7eabd984..819892de 100644 --- a/auto_tests/TCP_test.c +++ b/auto_tests/TCP_test.c | |||
@@ -510,8 +510,29 @@ END_TEST | |||
510 | 510 | ||
511 | #include "../toxcore/TCP_connection.h" | 511 | #include "../toxcore/TCP_connection.h" |
512 | 512 | ||
513 | _Bool tcp_data_callback_called; | ||
514 | static int tcp_data_callback(void *object, int id, const uint8_t *data, uint16_t length) | ||
515 | { | ||
516 | if (object != (void *)120397) | ||
517 | return -1; | ||
518 | |||
519 | if (id != 123) | ||
520 | return -1; | ||
521 | |||
522 | if (length != 6) | ||
523 | return -1; | ||
524 | |||
525 | if (memcmp(data, "Gentoo", length) != 0) | ||
526 | return -1; | ||
527 | |||
528 | tcp_data_callback_called = 1; | ||
529 | return 0; | ||
530 | } | ||
531 | |||
532 | |||
513 | START_TEST(test_tcp_connection) | 533 | START_TEST(test_tcp_connection) |
514 | { | 534 | { |
535 | unix_time_update(); | ||
515 | uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; | 536 | uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; |
516 | uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; | 537 | uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; |
517 | crypto_box_keypair(self_public_key, self_secret_key); | 538 | crypto_box_keypair(self_public_key, self_secret_key); |
@@ -528,6 +549,51 @@ START_TEST(test_tcp_connection) | |||
528 | TCP_Connections *tc_2 = new_tcp_connections(self_secret_key, &proxy_info); | 549 | TCP_Connections *tc_2 = new_tcp_connections(self_secret_key, &proxy_info); |
529 | ck_assert_msg(memcmp(tc_2->self_public_key, self_public_key, crypto_box_PUBLICKEYBYTES) == 0, "Wrong public key"); | 550 | ck_assert_msg(memcmp(tc_2->self_public_key, self_public_key, crypto_box_PUBLICKEYBYTES) == 0, "Wrong public key"); |
530 | 551 | ||
552 | IP_Port ip_port_tcp_s; | ||
553 | |||
554 | ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]); | ||
555 | ip_port_tcp_s.ip.family = AF_INET6; | ||
556 | ip_port_tcp_s.ip.ip6.in6_addr = in6addr_loopback; | ||
557 | |||
558 | int connection = new_tcp_connection_to(tc_1, tc_2->self_public_key, 123); | ||
559 | ck_assert_msg(connection == 0, "Connection id wrong"); | ||
560 | ck_assert_msg(add_tcp_relay_connection(tc_1, connection, ip_port_tcp_s, tcp_s->public_key) == 0, | ||
561 | "Could not add tcp relay to connection\n"); | ||
562 | |||
563 | ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]); | ||
564 | connection = new_tcp_connection_to(tc_2, tc_1->self_public_key, 123); | ||
565 | ck_assert_msg(connection == 0, "Connection id wrong"); | ||
566 | ck_assert_msg(add_tcp_relay_connection(tc_2, connection, ip_port_tcp_s, tcp_s->public_key) == 0, | ||
567 | "Could not add tcp relay to connection\n"); | ||
568 | |||
569 | c_sleep(50); | ||
570 | do_TCP_server(tcp_s); | ||
571 | c_sleep(50); | ||
572 | do_tcp_connections(tc_1); | ||
573 | do_tcp_connections(tc_2); | ||
574 | c_sleep(50); | ||
575 | do_TCP_server(tcp_s); | ||
576 | c_sleep(50); | ||
577 | do_tcp_connections(tc_1); | ||
578 | do_tcp_connections(tc_2); | ||
579 | c_sleep(50); | ||
580 | do_TCP_server(tcp_s); | ||
581 | c_sleep(50); | ||
582 | do_tcp_connections(tc_1); | ||
583 | do_tcp_connections(tc_2); | ||
584 | |||
585 | int ret = send_packet_tcp_connection(tc_1, 0, "Gentoo", 6); | ||
586 | ck_assert_msg(ret == 0, "could not send packet."); | ||
587 | set_packet_tcp_connection_callback(tc_2, &tcp_data_callback, (void *) 120397); | ||
588 | |||
589 | c_sleep(50); | ||
590 | do_TCP_server(tcp_s); | ||
591 | c_sleep(50); | ||
592 | |||
593 | do_tcp_connections(tc_1); | ||
594 | do_tcp_connections(tc_2); | ||
595 | |||
596 | ck_assert_msg(tcp_data_callback_called, "could not recv packet."); | ||
531 | 597 | ||
532 | kill_TCP_server(tcp_s); | 598 | kill_TCP_server(tcp_s); |
533 | kill_tcp_connections(tc_1); | 599 | kill_tcp_connections(tc_1); |