mirror of
https://github.com/minetest/minetest.git
synced 2024-11-24 00:23:46 +01:00
Fix unit test if there isn't a localhost address (for example FreeBSD jails)
This commit is contained in:
parent
3b6b9435c5
commit
a3e2b3e404
34
src/test.cpp
34
src/test.cpp
@ -1669,9 +1669,24 @@ struct TestSocket: public TestBase
|
|||||||
void Run()
|
void Run()
|
||||||
{
|
{
|
||||||
const int port = 30003;
|
const int port = 30003;
|
||||||
Address address(0,0,0,0, port);
|
Address address(0, 0, 0, 0, port);
|
||||||
|
Address bind_addr(0, 0, 0, 0, port);
|
||||||
Address address6((IPv6AddressBytes*) NULL, port);
|
Address address6((IPv6AddressBytes*) NULL, port);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Try to use the bind_address for servers with no localhost address
|
||||||
|
* For example: FreeBSD jails
|
||||||
|
*/
|
||||||
|
std::string bind_str = g_settings->get("bind_address");
|
||||||
|
try {
|
||||||
|
bind_addr.Resolve(bind_str.c_str());
|
||||||
|
|
||||||
|
if (!bind_addr.isIPv6()) {
|
||||||
|
address = bind_addr;
|
||||||
|
}
|
||||||
|
} catch (ResolveError &e) {
|
||||||
|
}
|
||||||
|
|
||||||
// IPv6 socket test
|
// IPv6 socket test
|
||||||
if (g_settings->getBool("enable_ipv6")) {
|
if (g_settings->getBool("enable_ipv6")) {
|
||||||
UDPSocket socket6;
|
UDPSocket socket6;
|
||||||
@ -1709,7 +1724,7 @@ struct TestSocket: public TestBase
|
|||||||
UASSERT(memcmp(sender.getAddress6().sin6_addr.s6_addr,
|
UASSERT(memcmp(sender.getAddress6().sin6_addr.s6_addr,
|
||||||
Address(&bytes, 0).getAddress6().sin6_addr.s6_addr, 16) == 0);
|
Address(&bytes, 0).getAddress6().sin6_addr.s6_addr, 16) == 0);
|
||||||
}
|
}
|
||||||
catch (SendFailedException e) {
|
catch (SendFailedException &e) {
|
||||||
errorstream << "IPv6 support enabled but not available!"
|
errorstream << "IPv6 support enabled but not available!"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
@ -1722,6 +1737,14 @@ struct TestSocket: public TestBase
|
|||||||
socket.Bind(address);
|
socket.Bind(address);
|
||||||
|
|
||||||
const char sendbuffer[] = "hello world!";
|
const char sendbuffer[] = "hello world!";
|
||||||
|
/*
|
||||||
|
* If there is a bind address, use it.
|
||||||
|
* It's useful in container environments
|
||||||
|
*/
|
||||||
|
if (address != Address(0, 0, 0, 0, port)) {
|
||||||
|
socket.Send(address, sendbuffer, sizeof(sendbuffer));
|
||||||
|
}
|
||||||
|
else
|
||||||
socket.Send(Address(127, 0, 0 ,1, port), sendbuffer, sizeof(sendbuffer));
|
socket.Send(Address(127, 0, 0 ,1, port), sendbuffer, sizeof(sendbuffer));
|
||||||
|
|
||||||
sleep_ms(50);
|
sleep_ms(50);
|
||||||
@ -1734,10 +1757,17 @@ struct TestSocket: public TestBase
|
|||||||
}
|
}
|
||||||
//FIXME: This fails on some systems
|
//FIXME: This fails on some systems
|
||||||
UASSERT(strncmp(sendbuffer, rcvbuffer, sizeof(sendbuffer)) == 0);
|
UASSERT(strncmp(sendbuffer, rcvbuffer, sizeof(sendbuffer)) == 0);
|
||||||
|
|
||||||
|
if (address != Address(0, 0, 0, 0, port)) {
|
||||||
|
UASSERT(sender.getAddress().sin_addr.s_addr ==
|
||||||
|
address.getAddress().sin_addr.s_addr);
|
||||||
|
}
|
||||||
|
else {
|
||||||
UASSERT(sender.getAddress().sin_addr.s_addr ==
|
UASSERT(sender.getAddress().sin_addr.s_addr ==
|
||||||
Address(127, 0, 0, 1, 0).getAddress().sin_addr.s_addr);
|
Address(127, 0, 0, 1, 0).getAddress().sin_addr.s_addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TestConnection: public TestBase
|
struct TestConnection: public TestBase
|
||||||
|
Loading…
Reference in New Issue
Block a user