summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/socket/qudpsocket/udpServer/main.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2016-04-07 14:18:21 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2016-05-02 19:20:33 +0000
commit22a7edd816b417daf43e3b4c4f0257fbc3ad7921 (patch)
tree1cbb22bbaac5d3b609fb3a473fbc8e3e0e0ab46d /tests/auto/network/socket/qudpsocket/udpServer/main.cpp
parent8f0bf2d3d258acfae91e7dda2d1e7ad29b950c9b (diff)
tst_QTcpSocket, tst_QUdpSocket: Improve diagnostics.
Add more error messages on failures. Task-number: QTBUG-25367 Task-number: QTBUG-25368 Change-Id: I064143a058b7b98d9d5eecab8b5da49f5307e1eb Reviewed-by: Edward Welbourne <edward.welbourne@theqtcompany.com> Reviewed-by: Richard J. Moore <rich@kde.org>
Diffstat (limited to 'tests/auto/network/socket/qudpsocket/udpServer/main.cpp')
-rw-r--r--tests/auto/network/socket/qudpsocket/udpServer/main.cpp30
1 files changed, 22 insertions, 8 deletions
diff --git a/tests/auto/network/socket/qudpsocket/udpServer/main.cpp b/tests/auto/network/socket/qudpsocket/udpServer/main.cpp
index 2562e58862..f393c26329 100644
--- a/tests/auto/network/socket/qudpsocket/udpServer/main.cpp
+++ b/tests/auto/network/socket/qudpsocket/udpServer/main.cpp
@@ -36,18 +36,21 @@ class Server : public QObject
{
Q_OBJECT
public:
- Server(int port)
+
+ Server() { connect(&serverSocket, &QIODevice::readyRead, this, &Server::sendEcho); }
+
+ bool bind(quint16 port)
{
- connect(&serverSocket, SIGNAL(readyRead()),
- this, SLOT(sendEcho()));
- if (serverSocket.bind(QHostAddress::Any, port,
- QUdpSocket::ReuseAddressHint
- | QUdpSocket::ShareAddress)) {
+ const bool result = serverSocket.bind(QHostAddress::Any, port,
+ QUdpSocket::ReuseAddressHint
+ | QUdpSocket::ShareAddress);
+ if (result) {
printf("OK\n");
} else {
- printf("FAILED\n");
+ printf("FAILED: %s\n", qPrintable(serverSocket.errorString()));
}
fflush(stdout);
+ return result;
}
private slots:
@@ -73,8 +76,19 @@ private:
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
+ QStringList arguments = QCoreApplication::arguments();
+ arguments.pop_front();
+ quint16 port = 0;
+ if (!arguments.isEmpty())
+ port = arguments.constFirst().toUShort();
+ if (!port) {
+ printf("Specify port number\n");
+ return -1;
+ }
- Server server(app.arguments().at(1).toInt());
+ Server server;
+ if (!server.bind(port))
+ return -2;
return app.exec();
}