Properly free everything at the end of each test.

This commit is contained in:
irungentoo 2015-02-07 22:57:04 -05:00
parent 65cbea38fd
commit d9ea6e9485
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
4 changed files with 72 additions and 2 deletions

View File

@ -118,6 +118,7 @@ START_TEST(test_basic)
ck_assert_msg(packet_resp_plain[0] == 1, "wrong packet id %u", packet_resp_plain[0]);
ck_assert_msg(packet_resp_plain[1] == 0, "connection not refused %u", packet_resp_plain[1]);
ck_assert_msg(memcmp(packet_resp_plain + 2, f_public_key, crypto_box_PUBLICKEYBYTES) == 0, "key in packet wrong");
kill_TCP_server(tcp_s);
}
END_TEST
@ -175,6 +176,12 @@ struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s)
return sec_c;
}
void kill_TCP_con(struct sec_TCP_con *con)
{
kill_sock(con->sock);
free(con);
}
int write_packet_TCP_secure_connection(struct sec_TCP_con *con, uint8_t *data, uint16_t length)
{
uint8_t packet[sizeof(uint16_t) + length + crypto_box_MACBYTES];
@ -290,6 +297,10 @@ START_TEST(test_some)
ck_assert_msg(len == sizeof(ping_packet), "wrong len %u", len);
ck_assert_msg(data[0] == 5, "wrong packet id %u", data[0]);
ck_assert_msg(memcmp(ping_packet + 1, data + 1, sizeof(uint64_t)) == 0, "wrong packet data");
kill_TCP_server(tcp_s);
kill_TCP_con(con1);
kill_TCP_con(con2);
kill_TCP_con(con3);
}
END_TEST
@ -457,6 +468,9 @@ START_TEST(test_client)
do_TCP_connection(conn2);
ck_assert_msg(status_callback_good == 1, "status callback not called");
ck_assert_msg(status_callback_status == 1, "wrong status");
kill_TCP_server(tcp_s);
kill_TCP_connection(conn);
kill_TCP_connection(conn2);
}
END_TEST
@ -488,6 +502,8 @@ START_TEST(test_client_invalid)
do_TCP_connection(conn);
ck_assert_msg(conn->status == TCP_CLIENT_DISCONNECTED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_DISCONNECTED,
conn->status);
kill_TCP_connection(conn);
}
END_TEST

View File

@ -55,6 +55,7 @@ START_TEST(test_basics)
uint8_t found = Assoc_get_close_entries(assoc, &close_entries);
ck_assert_msg(found == 1, "get_close_entries(): expected %u, got %u", 1, found);
kill_Assoc(assoc);
}
END_TEST
@ -130,6 +131,7 @@ START_TEST(test_fillup)
ck_assert_msg(good == 8, "Entries found were not the closest ones. Only %u/8 were.", good);
//printf("good: %u %u %u\n", good, a, ((uint32_t)current_time() - a));
kill_Assoc(assoc);
}
END_TEST

View File

@ -224,6 +224,39 @@ START_TEST(test_basic)
do_onion(onion2);
c_sleep(50);
}
kill_onion_announce(onion1_a);
kill_onion_announce(onion2_a);
{
Onion *onion = onion1;
Networking_Core *net = onion->dht->net;
DHT *dht = onion->dht;
kill_onion(onion);
kill_DHT(dht);
kill_networking(net);
}
{
Onion *onion = onion2;
Networking_Core *net = onion->dht->net;
DHT *dht = onion->dht;
kill_onion(onion);
kill_DHT(dht);
kill_networking(net);
}
{
Onion *onion = onion3;
Networking_Core *net = onion->dht->net;
DHT *dht = onion->dht;
kill_onion(onion);
kill_DHT(dht);
kill_networking(net);
}
}
END_TEST
@ -257,6 +290,18 @@ void do_onions(Onions *on)
do_onion_client(on->onion_c);
}
void kill_onions(Onions *on)
{
Networking_Core *net = on->onion->dht->net;
DHT *dht = on->onion->dht;
kill_onion_client(on->onion_c);
kill_onion_announce(on->onion_a);
kill_onion(on->onion);
kill_DHT(dht);
kill_networking(net);
free(on);
}
#define NUM_ONIONS 50
START_TEST(test_announce)
@ -334,6 +379,10 @@ START_TEST(test_announce)
}
ck_assert_msg(ip_port.port == onions[7]->onion->net->port, "Port in returned ip not correct.");
for (i = 0; i < NUM_ONIONS; ++i) {
kill_onions(onions[i]);
}
}
END_TEST

View File

@ -595,8 +595,11 @@ START_TEST(test_AV_flows)
printf("\n");
}
toxav_kill(status_control.Alice.av);
toxav_kill(status_control.Bob.av);
tox_kill(bootstrap_node);
tox_kill(Alice);
tox_kill(Bob);
printf("Calls ended!\n");
}