summaryrefslogtreecommitdiffstats
path: root/tests/auto/qudpsocket
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2010-05-05 14:20:07 (GMT)
committerBradley T. Hughes <bradley.hughes@nokia.com>2010-09-01 12:24:37 (GMT)
commit4bdcc1a6f5d11ffb461f174ae3c808ce2512700a (patch)
tree6a9412b7c928c12fcba70e6778456fdff436fff5 /tests/auto/qudpsocket
parent3c35b0607e541008daaf53221da4e727015b5441 (diff)
downloadQt-4bdcc1a6f5d11ffb461f174ae3c808ce2512700a.zip
Qt-4bdcc1a6f5d11ffb461f174ae3c808ce2512700a.tar.gz
Qt-4bdcc1a6f5d11ffb461f174ae3c808ce2512700a.tar.bz2
add an autotest for basic multicast support
Diffstat (limited to 'tests/auto/qudpsocket')
-rw-r--r--tests/auto/qudpsocket/tst_qudpsocket.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/qudpsocket/tst_qudpsocket.cpp b/tests/auto/qudpsocket/tst_qudpsocket.cpp
index abed55c..fdfbb5d 100644
--- a/tests/auto/qudpsocket/tst_qudpsocket.cpp
+++ b/tests/auto/qudpsocket/tst_qudpsocket.cpp
@@ -94,6 +94,7 @@ private slots:
void outOfProcessConnectedClientServerTest();
void outOfProcessUnconnectedClientServerTest();
void zeroLengthDatagram();
+ void multicast();
protected slots:
void empty_readyReadSlot();
@@ -844,5 +845,42 @@ void tst_QUdpSocket::zeroLengthDatagram()
QCOMPARE(receiver.readDatagram(&buf, 1), qint64(0));
}
+void tst_QUdpSocket::multicast()
+{
+ QFETCH_GLOBAL(bool, setProxy);
+ if (setProxy)
+ QSKIP("Multicast does not work with a proxy", SkipAll);
+
+ QHostAddress groupAddress("239.255.116.98");
+
+ QUdpSocket receiver;
+ QVERIFY2(receiver.bind(),
+ qPrintable(receiver.errorString()));
+ QVERIFY2(receiver.joinMulticastGroup(groupAddress, QUdpSocket::MulticastLoopback),
+ qPrintable(receiver.errorString()));
+
+ QList<QByteArray> datagrams = QList<QByteArray>()
+ << QByteArray("0123")
+ << QByteArray("4567")
+ << QByteArray("89ab")
+ << QByteArray("cdef");
+
+ QUdpSocket sender;
+ foreach (const QByteArray &datagram, datagrams)
+ sender.writeDatagram(datagram, receiver.localAddress(), receiver.localPort());
+
+ QVERIFY2(receiver.waitForReadyRead(),
+ qPrintable(receiver.errorString()));
+ QVERIFY(receiver.hasPendingDatagrams());
+ QList<QByteArray> receivedDatagrams;
+ while (receiver.hasPendingDatagrams()) {
+ QByteArray datagram;
+ datagram.resize(receiver.pendingDatagramSize());
+ receiver.readDatagram(datagram.data(), datagram.size(), 0, 0);
+ receivedDatagrams << datagram;
+ }
+ QCOMPARE(receivedDatagrams, datagrams);
+}
+
QTEST_MAIN(tst_QUdpSocket)
#include "tst_qudpsocket.moc"