Skip to content

Commit

Permalink
Autotest: use QUdpSocket instead of QTcpSocket in tst_QNetworkInterface
Browse files Browse the repository at this point in the history
We don't need to bother the network test server with a TCP SYN packet.
All we need is for the local operating system to figure out the IP
address it would use to send a packet to the test server. We can do that
with QUdpSocket.

Also, the network test server hasn't been called "fluke.troll.no" for
almost a decade.

Change-Id: I209fcd5dbc2b4e5381cffffd14df65ccc7133247
Reviewed-by: Timur Pocheptsov <[email protected]>
  • Loading branch information
thiagomacieira authored and Timur Pocheptsov committed Sep 14, 2017
1 parent 6aa0015 commit 5d48143
Showing 1 changed file with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#include <qcoreapplication.h>
#include <qnetworkinterface.h>
#include <qtcpsocket.h>
#include <qudpsocket.h>
#ifndef QT_NO_BEARERMANAGEMENT
#include <QNetworkConfigurationManager>
#include <QNetworkSession>
Expand Down Expand Up @@ -189,17 +189,12 @@ void tst_QNetworkInterface::loopbackIPv6()

void tst_QNetworkInterface::localAddress()
{
QTcpSocket socket;
QUdpSocket socket;
socket.connectToHost(QtNetworkSettings::serverName(), 80);
QVERIFY(socket.waitForConnected(5000));

QHostAddress local = socket.localAddress();

// make Apache happy on fluke
socket.write("GET / HTTP/1.0\r\n\r\n");
socket.waitForBytesWritten(1000);
socket.close();

// test that we can find the address that QTcpSocket reported
QList<QHostAddress> all = QNetworkInterface::allAddresses();
QVERIFY(all.contains(local));
Expand Down

0 comments on commit 5d48143

Please sign in to comment.