diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2010-05-06 10:59:41 (GMT) |
---|---|---|
committer | Bradley T. Hughes <bradley.hughes@nokia.com> | 2010-09-01 12:24:38 (GMT) |
commit | b3a93f3d5d7aaaa9b41eb1a5fc9082e5bec86a68 (patch) | |
tree | 107f270c84638a02304de4337c1a38ad40c1ead5 /tests/auto/qudpsocket | |
parent | 7b2a41340bd1296a6712cd22ad7e8806f28c796c (diff) | |
download | Qt-b3a93f3d5d7aaaa9b41eb1a5fc9082e5bec86a68.zip Qt-b3a93f3d5d7aaaa9b41eb1a5fc9082e5bec86a68.tar.gz Qt-b3a93f3d5d7aaaa9b41eb1a5fc9082e5bec86a68.tar.bz2 |
Improved auto-test for multicast support in QUdpSocket
In particular:
- test that leaving the group "works" (returns true, still unsure if the
test should verify that the socket no longer gets packets)
- joining a group is not possible before binding
- leaving a group without being bound is not possible
Diffstat (limited to 'tests/auto/qudpsocket')
-rw-r--r-- | tests/auto/qudpsocket/tst_qudpsocket.cpp | 73 |
1 files changed, 49 insertions, 24 deletions
diff --git a/tests/auto/qudpsocket/tst_qudpsocket.cpp b/tests/auto/qudpsocket/tst_qudpsocket.cpp index fdfbb5d..39a7ab1 100644 --- a/tests/auto/qudpsocket/tst_qudpsocket.cpp +++ b/tests/auto/qudpsocket/tst_qudpsocket.cpp @@ -850,36 +850,61 @@ 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())); + { + QUdpSocket receiver; - QList<QByteArray> datagrams = QList<QByteArray>() - << QByteArray("0123") - << QByteArray("4567") - << QByteArray("89ab") - << QByteArray("cdef"); + // cannot join group before binding + QTest::ignoreMessage(QtWarningMsg, "QUdpSocket::joinMulticastGroup() called on a QUdpSocket when not in QUdpSocket::BoundState"); + QVERIFY(!receiver.joinMulticastGroup(groupAddress)); + } - QUdpSocket sender; - foreach (const QByteArray &datagram, datagrams) - sender.writeDatagram(datagram, receiver.localAddress(), receiver.localPort()); + { + QUdpSocket receiver; + + // bind first, then verify that we can join the multicast group + 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); - 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; + QVERIFY2(receiver.leaveMulticastGroup(groupAddress), qPrintable(receiver.errorString())); + } + + { + QUdpSocket receiver; + + QVERIFY2(receiver.bind(), + qPrintable(receiver.errorString())); + QVERIFY2(receiver.joinMulticastGroup(groupAddress, QUdpSocket::MulticastLoopback), + qPrintable(receiver.errorString())); + receiver.close(); + QTest::ignoreMessage(QtWarningMsg, "QUdpSocket::leaveMulticastGroup() called on a QUdpSocket when not in QUdpSocket::BoundState"); + QVERIFY(!receiver.leaveMulticastGroup(groupAddress)); } - QCOMPARE(receivedDatagrams, datagrams); } QTEST_MAIN(tst_QUdpSocket) |