tst_QUdpSocket: Fix inverted logic in getting a non-"any" address
We want to use "localhost" if the server's address is "any", as some OS can't send datagrams to "any" (e.g., OS X and FreeBSD). Change-Id: I1004bc2282e7f930cdb7ed394aa9f4b5a1cfcf82 Reviewed-by: Richard J. Moore <rich@kde.org>
This commit is contained in:
parent
9a70b67b5a
commit
1196f69112
@ -127,6 +127,17 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static QHostAddress makeNonAny(const QHostAddress &address, QHostAddress::SpecialAddress preferForAny = QHostAddress::LocalHost)
|
||||||
|
{
|
||||||
|
if (address == QHostAddress::Any)
|
||||||
|
return preferForAny;
|
||||||
|
if (address == QHostAddress::AnyIPv4)
|
||||||
|
return QHostAddress::LocalHost;
|
||||||
|
if (address == QHostAddress::AnyIPv6)
|
||||||
|
return QHostAddress::LocalHostIPv6;
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
tst_QUdpSocket::tst_QUdpSocket()
|
tst_QUdpSocket::tst_QUdpSocket()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -236,10 +247,7 @@ void tst_QUdpSocket::unconnectedServerAndClientTest()
|
|||||||
|
|
||||||
const char *message[] = {"Yo mista", "Yo", "Wassap"};
|
const char *message[] = {"Yo mista", "Yo", "Wassap"};
|
||||||
|
|
||||||
QHostAddress serverAddress = QHostAddress::LocalHost;
|
QHostAddress serverAddress = makeNonAny(serverSocket.localAddress());
|
||||||
if (!(serverSocket.localAddress() == QHostAddress::AnyIPv4 || serverSocket.localAddress() == QHostAddress::AnyIPv6))
|
|
||||||
serverAddress = serverSocket.localAddress();
|
|
||||||
|
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
QUdpSocket clientSocket;
|
QUdpSocket clientSocket;
|
||||||
#ifdef FORCE_SESSION
|
#ifdef FORCE_SESSION
|
||||||
@ -375,12 +383,8 @@ void tst_QUdpSocket::loop()
|
|||||||
QVERIFY2(peter.bind(), peter.errorString().toLatin1().constData());
|
QVERIFY2(peter.bind(), peter.errorString().toLatin1().constData());
|
||||||
QVERIFY2(paul.bind(), paul.errorString().toLatin1().constData());
|
QVERIFY2(paul.bind(), paul.errorString().toLatin1().constData());
|
||||||
|
|
||||||
QHostAddress peterAddress = QHostAddress::LocalHost;
|
QHostAddress peterAddress = makeNonAny(peter.localAddress());
|
||||||
if (!(peter.localAddress() == QHostAddress::AnyIPv4 || peter.localAddress() == QHostAddress::AnyIPv6))
|
QHostAddress pualAddress = makeNonAny(paul.localAddress());
|
||||||
peterAddress = peter.localAddress();
|
|
||||||
QHostAddress pualAddress = QHostAddress::LocalHost;
|
|
||||||
if (!(paul.localAddress() == QHostAddress::AnyIPv4 || paul.localAddress() == QHostAddress::AnyIPv6))
|
|
||||||
pualAddress = paul.localAddress();
|
|
||||||
|
|
||||||
QCOMPARE(peter.writeDatagram(peterMessage.data(), peterMessage.length(),
|
QCOMPARE(peter.writeDatagram(peterMessage.data(), peterMessage.length(),
|
||||||
pualAddress, paul.localPort()), qint64(peterMessage.length()));
|
pualAddress, paul.localPort()), qint64(peterMessage.length()));
|
||||||
@ -624,7 +628,7 @@ void tst_QUdpSocket::readLine()
|
|||||||
#endif
|
#endif
|
||||||
QVERIFY2(socket1.bind(), socket1.errorString().toLatin1().constData());
|
QVERIFY2(socket1.bind(), socket1.errorString().toLatin1().constData());
|
||||||
|
|
||||||
socket2.connectToHost("127.0.0.1", socket1.localPort());
|
socket2.connectToHost(makeNonAny(socket1.localAddress()), socket1.localPort());
|
||||||
QVERIFY(socket2.waitForConnected(5000));
|
QVERIFY(socket2.waitForConnected(5000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,10 +642,7 @@ void tst_QUdpSocket::pendingDatagramSize()
|
|||||||
#endif
|
#endif
|
||||||
QVERIFY2(server.bind(), server.errorString().toLatin1().constData());
|
QVERIFY2(server.bind(), server.errorString().toLatin1().constData());
|
||||||
|
|
||||||
QHostAddress serverAddress = QHostAddress::LocalHost;
|
QHostAddress serverAddress = makeNonAny(server.localAddress());
|
||||||
if (!(server.localAddress() == QHostAddress::AnyIPv4 || server.localAddress() == QHostAddress::AnyIPv6))
|
|
||||||
serverAddress = server.localAddress();
|
|
||||||
|
|
||||||
QUdpSocket client;
|
QUdpSocket client;
|
||||||
#ifdef FORCE_SESSION
|
#ifdef FORCE_SESSION
|
||||||
client.setProperty("_q_networksession", QVariant::fromValue(networkSession));
|
client.setProperty("_q_networksession", QVariant::fromValue(networkSession));
|
||||||
@ -689,10 +690,7 @@ void tst_QUdpSocket::writeDatagram()
|
|||||||
#endif
|
#endif
|
||||||
QVERIFY2(server.bind(), server.errorString().toLatin1().constData());
|
QVERIFY2(server.bind(), server.errorString().toLatin1().constData());
|
||||||
|
|
||||||
QHostAddress serverAddress = QHostAddress::LocalHost;
|
QHostAddress serverAddress = makeNonAny(server.localAddress());
|
||||||
if (!(server.localAddress() == QHostAddress::AnyIPv4 || server.localAddress() == QHostAddress::AnyIPv6))
|
|
||||||
serverAddress = server.localAddress();
|
|
||||||
|
|
||||||
QUdpSocket client;
|
QUdpSocket client;
|
||||||
#ifdef FORCE_SESSION
|
#ifdef FORCE_SESSION
|
||||||
client.setProperty("_q_networksession", QVariant::fromValue(networkSession));
|
client.setProperty("_q_networksession", QVariant::fromValue(networkSession));
|
||||||
@ -739,10 +737,7 @@ void tst_QUdpSocket::performance()
|
|||||||
#endif
|
#endif
|
||||||
QVERIFY2(server.bind(), server.errorString().toLatin1().constData());
|
QVERIFY2(server.bind(), server.errorString().toLatin1().constData());
|
||||||
|
|
||||||
QHostAddress serverAddress = QHostAddress::LocalHost;
|
QHostAddress serverAddress = makeNonAny(server.localAddress());
|
||||||
if (!(server.localAddress() == QHostAddress::AnyIPv4 || server.localAddress() == QHostAddress::AnyIPv6))
|
|
||||||
serverAddress = server.localAddress();
|
|
||||||
|
|
||||||
QUdpSocket client;
|
QUdpSocket client;
|
||||||
#ifdef FORCE_SESSION
|
#ifdef FORCE_SESSION
|
||||||
client.setProperty("_q_networksession", QVariant::fromValue(networkSession));
|
client.setProperty("_q_networksession", QVariant::fromValue(networkSession));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user