Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Empty address creates QHostAddress::Any like in Qt5 #10

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
21 changes: 19 additions & 2 deletions tests/ServerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down
Loading