diff --git a/src/Server.cpp b/src/Server.cpp index 40e03ef..94a850b 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -201,7 +201,8 @@ bool Server::startWorker() clear(); // Start to listen - const auto result = _worker->listen(QHostAddress(address()), port()); + const auto hostAddress = address().isEmpty() ? QHostAddress::Any : QHostAddress(address()); + const auto result = _worker->listen(hostAddress, port()); setListening(result); return result; } diff --git a/tests/ServerTests.cpp b/tests/ServerTests.cpp index 2c4b06a..bd4ffaf 100644 --- a/tests/ServerTests.cpp +++ b/tests/ServerTests.cpp @@ -38,11 +38,11 @@ class ServerTests : public ::testing::Test QTimer timer; - void echoTest(quint16 port) + void echoTest(quint16 port, QString serverAddress = "127.0.0.1") { QSignalSpy connectedSpy(&client, &MySocket::isConnectedChanged); client.start("127.0.0.1", port); - server.start("127.0.0.1", port); + server.start(serverAddress, port); if(!client.isConnected()) { ASSERT_TRUE(connectedSpy.wait()); @@ -120,6 +120,23 @@ class ServerTests : public ::testing::Test } }; +TEST_F(ServerTests, echoTestEmptyServerHostAddress) +{ + server.setUseWorkerThread(false); + client.setUseWorkerThread(false); + // Empty QString -> QHostAddress is creating a QHostAddress::Any in Qt5, but QHostAddress::Null in Qt6 + // We want to keep the behavior of Qt5 + echoTest(30000, ""); +} + +TEST_F(ServerTests, echoTest0000ServerHostAddress) +{ + server.setUseWorkerThread(false); + client.setUseWorkerThread(false); + // This should create a QHostAddress::Any + echoTest(30000, "0.0.0.0"); +} + TEST_F(ServerTests, echoTestMonoThread) { server.setUseWorkerThread(false);