summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/socket
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-11-28 13:35:58 -0800
committerThiago Macieira <thiago.macieira@intel.com>2017-12-05 15:32:29 +0000
commit637e8ebcc3c2394d01827043d1a410866234fd0c (patch)
tree7ef061ddceb4eb6aa395bd7ce142dc0fd07a91a8 /tests/auto/network/socket
parentff7dbda3b0eaedf857de3913c2be2f880909ee82 (diff)
tst_QUdpSocket: Don't test for .bytesAvailable on untrusted platforms
FreeBSD, for example, does not have SO_NREAD and its FIONREAD returns the full socket buffer size, including IP and UDP headers. Change-Id: Ifb5969bf206e4cd7b14efffd14fb5d8ca778d16a Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/auto/network/socket')
-rw-r--r--tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
index 0f46caa7c2..aa71f7e94d 100644
--- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
+++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
@@ -60,6 +60,13 @@
#include <errno.h>
#endif
+#ifdef Q_OS_UNIX
+# include <sys/socket.h>
+#endif
+#if defined(Q_OS_LINUX) || defined(Q_OS_WIN) || defined(SO_NREAD)
+# define RELIABLE_BYTES_AVAILABLE
+#endif
+
Q_DECLARE_METATYPE(QHostAddress)
QT_FORWARD_DECLARE_CLASS(QUdpSocket)
@@ -1806,7 +1813,9 @@ void tst_QUdpSocket::readyRead()
// make sure only one signal was emitted
QCOMPARE(spy.count(), 1);
QVERIFY(receiver.hasPendingDatagrams());
+#ifdef RELIABLE_BYTES_AVAILABLE
QCOMPARE(receiver.bytesAvailable(), qint64(2));
+#endif
QCOMPARE(receiver.pendingDatagramSize(), qint64(2));
// write another datagram
@@ -1828,7 +1837,9 @@ void tst_QUdpSocket::readyRead()
QTest::qWait(100);
QCOMPARE(spy.count(), 2);
QVERIFY(receiver.hasPendingDatagrams());
+#ifdef RELIABLE_BYTES_AVAILABLE
QCOMPARE(receiver.bytesAvailable(), qint64(3));
+#endif
QCOMPARE(receiver.pendingDatagramSize(), qint64(3));
}
@@ -1860,7 +1871,9 @@ void tst_QUdpSocket::readyReadForEmptyDatagram()
char buf[1];
QVERIFY(receiver.hasPendingDatagrams());
QCOMPARE(receiver.pendingDatagramSize(), qint64(0));
+#ifdef RELIABLE_BYTES_AVAILABLE
QCOMPARE(receiver.bytesAvailable(), qint64(0));
+#endif
QCOMPARE(receiver.readDatagram(buf, sizeof buf), qint64(0));
}
@@ -1869,7 +1882,9 @@ void tst_QUdpSocket::async_readDatagramSlot()
char buf[1];
QVERIFY(m_asyncReceiver->hasPendingDatagrams());
QCOMPARE(m_asyncReceiver->pendingDatagramSize(), qint64(1));
+#ifdef RELIABLE_BYTES_AVAILABLE
QCOMPARE(m_asyncReceiver->bytesAvailable(), qint64(1));
+#endif
QCOMPARE(m_asyncReceiver->readDatagram(buf, sizeof(buf)), qint64(1));
if (buf[0] == '2') {