summaryrefslogtreecommitdiffstats
path: root/tests/auto/qudpsocket
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2010-08-05 12:48:44 +0200
committerBradley T. Hughes <bradley.hughes@nokia.com>2010-09-01 14:24:46 +0200
commit75a56ce44908eb14ef058d111129ef3d285c5364 (patch)
treed59c138a649140a93ff86b1987e98d1a2e8a322c /tests/auto/qudpsocket
parent8082ee277b44a158ce87d646e0d2c1d11e7d8348 (diff)
Add QUdpSocket::setMulticastInterface() and ::multicastInterface()
This API allows the programmer to set/query the outgoing interface for multicast packets for the socket. Both functions need an initialized socket to work. Autotest updated to test setting each interface in the system as the multicast interface for IPv4 and IPv6 UDP sockets.
Diffstat (limited to 'tests/auto/qudpsocket')
-rw-r--r--tests/auto/qudpsocket/tst_qudpsocket.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/qudpsocket/tst_qudpsocket.cpp b/tests/auto/qudpsocket/tst_qudpsocket.cpp
index a1dd20037d..2b78706deb 100644
--- a/tests/auto/qudpsocket/tst_qudpsocket.cpp
+++ b/tests/auto/qudpsocket/tst_qudpsocket.cpp
@@ -50,11 +50,13 @@
#include <qhostinfo.h>
#include <qmap.h>
#include <QNetworkProxy>
+#include <QNetworkInterface>
#include <qstringlist.h>
#include "../network-settings.h"
Q_DECLARE_METATYPE(QHostAddress)
+Q_DECLARE_METATYPE(QNetworkInterface)
//TESTED_CLASS=
//TESTED_FILES=
@@ -102,6 +104,8 @@ private slots:
void multicastJoinBeforeBind();
void multicastLeaveAfterClose_data();
void multicastLeaveAfterClose();
+ void setMulticastInterface_data();
+ void setMulticastInterface();
void multicast_data();
void multicast();
@@ -954,6 +958,46 @@ void tst_QUdpSocket::multicastLeaveAfterClose()
QVERIFY(!udpSocket.leaveMulticastGroup(groupAddress));
}
+void tst_QUdpSocket::setMulticastInterface_data()
+{
+ QTest::addColumn<QNetworkInterface>("iface");
+ QTest::addColumn<QHostAddress>("address");
+ QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
+ foreach (const QNetworkInterface &iface, interfaces) {
+ foreach (const QNetworkAddressEntry &entry, iface.addressEntries()) {
+ QTest::newRow(QString("%1:%2").arg(iface.name()).arg(entry.ip().toString()).toAscii())
+ << iface
+ << entry.ip();
+ }
+ }
+}
+
+void tst_QUdpSocket::setMulticastInterface()
+{
+ QFETCH_GLOBAL(bool, setProxy);
+ QFETCH(QNetworkInterface, iface);
+ QFETCH(QHostAddress, address);
+
+ QUdpSocket udpSocket;
+ // bind initializes the socket
+ bool bound = udpSocket.bind((address.protocol() == QAbstractSocket::IPv6Protocol
+ ? QHostAddress(QHostAddress::AnyIPv6)
+ : QHostAddress(QHostAddress::Any)),
+ 0);
+ if (!bound)
+ QTest::ignoreMessage(QtWarningMsg, "QUdpSocket::setMulticastInterface() called on a QUdpSocket when not in QUdpSocket::BoundState");
+ udpSocket.setMulticastInterface(iface);
+ if (!bound)
+ QTest::ignoreMessage(QtWarningMsg, "QUdpSocket::multicastInterface() called on a QUdpSocket when not in QUdpSocket::BoundState");
+ QNetworkInterface iface2 = udpSocket.multicastInterface();
+ if (!setProxy) {
+ QVERIFY(iface2.isValid());
+ QCOMPARE(iface.name(), iface2.name());
+ } else {
+ QVERIFY(!iface2.isValid());
+ }
+}
+
void tst_QUdpSocket::multicast_data()
{
QHostAddress anyAddress = QHostAddress(QHostAddress::Any);