Skip to content

Commit 0b3d7b9

Browse files
committed
tst_qnetworkreply_local: Fail the test if server fails to listen
Change-Id: I63f87edd297949a145b10d55f5ce6172d2eeb8e4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
1 parent f31e5f6 commit 0b3d7b9

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

tests/auto/network/access/qnetworkreply_local/tst_qnetworkreply_local.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (C) 2024 The Qt Company Ltd.
22
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
33

4+
#define QTEST_THROW_ON_FAIL
5+
46
#include <QtNetwork/qtnetworkglobal.h>
57

68
#include <QtTest/qtest.h>
@@ -49,14 +51,19 @@ static std::unique_ptr<MiniHttpServerV2> getServerForCurrentScheme()
4951
if (scheme.startsWith("unix"_L1) || scheme.startsWith("local"_L1)) {
5052
#if QT_CONFIG(localserver)
5153
QLocalServer *localServer = new QLocalServer(server.get());
52-
localServer->listen(u"qt_networkreply_test_"_s
53-
% QLatin1StringView(QTest::currentTestFunction())
54-
% QString::number(QCoreApplication::applicationPid()));
54+
bool listening = localServer->listen(u"qt_networkreply_test_"_s
55+
% QLatin1StringView(QTest::currentTestFunction())
56+
% QString::number(QCoreApplication::applicationPid()));
57+
if (!listening) {
58+
QFAIL(qPrintable(
59+
u"Failed to listen on local server: %1"_s.arg(localServer->errorString())));
60+
}
5561
server->bind(localServer);
5662
#endif
5763
} else if (scheme == "http") {
5864
QTcpServer *tcpServer = new QTcpServer(server.get());
59-
tcpServer->listen(QHostAddress::LocalHost, 0);
65+
if (!tcpServer->listen(QHostAddress::LocalHost, 0))
66+
QFAIL(qPrintable(u"Failed to listen on TCP port: %1"_s.arg(tcpServer->errorString())));
6067
server->bind(tcpServer);
6168
}
6269
return server;

0 commit comments

Comments
 (0)