mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 13:13:44 +01:00
Fix cases where the tests were doing closesocket() on a non-socket
These seem to have caused warnings on windows. Hmmm.
This commit is contained in:
parent
2fe7e3d9d2
commit
4c55e8a58f
@ -1110,8 +1110,8 @@ tor_close_socket_simple(tor_socket_t s)
|
||||
|
||||
/** As tor_close_socket_simple(), but keeps track of the number
|
||||
* of open sockets. Returns 0 on success, -1 on failure. */
|
||||
int
|
||||
tor_close_socket(tor_socket_t s)
|
||||
MOCK_IMPL(int,
|
||||
tor_close_socket,(tor_socket_t s))
|
||||
{
|
||||
int r = tor_close_socket_simple(s);
|
||||
|
||||
|
@ -478,7 +478,7 @@ typedef int socklen_t;
|
||||
#endif
|
||||
|
||||
int tor_close_socket_simple(tor_socket_t s);
|
||||
int tor_close_socket(tor_socket_t s);
|
||||
MOCK_DECL(int, tor_close_socket, (tor_socket_t s));
|
||||
tor_socket_t tor_open_socket_with_extensions(
|
||||
int domain, int type, int protocol,
|
||||
int cloexec, int nonblock);
|
||||
|
@ -557,6 +557,13 @@ fake_open_socket(int domain, int type, int protocol)
|
||||
return FAKE_SOCKET_FD;
|
||||
}
|
||||
|
||||
static int
|
||||
fake_close_socket(tor_socket_t s)
|
||||
{
|
||||
(void)s;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int last_connected_socket_fd = 0;
|
||||
|
||||
static int connect_retval = 0;
|
||||
@ -617,6 +624,7 @@ test_address_udp_socket_trick_whitebox(void *arg)
|
||||
MOCK(tor_open_socket,fake_open_socket);
|
||||
MOCK(tor_connect_socket,pretend_to_connect);
|
||||
MOCK(tor_getsockname,fake_getsockname);
|
||||
MOCK(tor_close_socket,fake_close_socket);
|
||||
|
||||
mock_addr = tor_malloc_zero(sizeof(struct sockaddr_storage));
|
||||
sockaddr_in_from_string("23.32.246.118",(struct sockaddr_in *)mock_addr);
|
||||
@ -647,11 +655,13 @@ test_address_udp_socket_trick_whitebox(void *arg)
|
||||
|
||||
tt_assert(sockaddr_in6_are_equal(mock_addr6,ipv6_to_check));
|
||||
|
||||
|
||||
done:
|
||||
UNMOCK(tor_open_socket);
|
||||
UNMOCK(tor_connect_socket);
|
||||
UNMOCK(tor_getsockname);
|
||||
UNMOCK(tor_close_socket);
|
||||
|
||||
done:
|
||||
tor_free(ipv6_to_check);
|
||||
tor_free(mock_addr);
|
||||
tor_free(addr_from_hack);
|
||||
|
@ -95,6 +95,13 @@ mock_connection_connect_sockaddr(connection_t *conn,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
fake_close_socket(evutil_socket_t sock)
|
||||
{
|
||||
(void)sock;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
test_conn_lookup_addr_helper(const char *address, int family, tor_addr_t *addr)
|
||||
{
|
||||
@ -124,6 +131,7 @@ test_conn_get_connection(uint8_t state, uint8_t type, uint8_t purpose)
|
||||
|
||||
MOCK(connection_connect_sockaddr,
|
||||
mock_connection_connect_sockaddr);
|
||||
MOCK(tor_close_socket, fake_close_socket);
|
||||
|
||||
init_connection_lists();
|
||||
|
||||
@ -148,12 +156,13 @@ test_conn_get_connection(uint8_t state, uint8_t type, uint8_t purpose)
|
||||
assert_connection_ok(conn, time(NULL));
|
||||
|
||||
UNMOCK(connection_connect_sockaddr);
|
||||
|
||||
UNMOCK(tor_close_socket);
|
||||
return conn;
|
||||
|
||||
/* On failure */
|
||||
done:
|
||||
UNMOCK(connection_connect_sockaddr);
|
||||
UNMOCK(tor_close_socket);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user