summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp')
-rw-r--r--tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp57
1 files changed, 17 insertions, 40 deletions
diff --git a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp
index 0e9e6bd493..17bba73dab 100644
--- a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp
+++ b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtTest/QTest>
#include <QtTest/QSignalSpy>
@@ -49,6 +24,7 @@
# undef min
#endif // Q_CC_MSVC
+using namespace std::chrono_literals;
class tst_QSocketNotifier : public QObject
{
@@ -156,11 +132,11 @@ public slots:
++sequence;
if (sequence == 1) {
// read from both ends
- (void) readEnd1->read(data1, sizeof(data1));
- (void) readEnd2->read(data2, sizeof(data2));
+ QCOMPARE(readEnd1->read(data1, sizeof(data1)), 1);
+ QCOMPARE(readEnd2->read(data2, sizeof(data2)), 1);
emit finished();
} else if (sequence == 2) {
- // we should never get here
+ // check that we can't read now because we've read our byte
QCOMPARE(readEnd2->read(data2, sizeof(data2)), qint64(-2));
QVERIFY(readEnd2->isValid());
}
@@ -176,7 +152,7 @@ void tst_QSocketNotifier::unexpectedDisconnection()
Given two sockets and two QSocketNotifiers registered on each
their socket. If both sockets receive data, and the first slot
invoked by one of the socket notifiers empties both sockets, the
- other notifier will also emit activated(). This results in
+ other notifier will also emit activated(). This was causing an
unexpected disconnection in QAbstractSocket.
The use case is that somebody calls one of the
@@ -212,8 +188,9 @@ void tst_QSocketNotifier::unexpectedDisconnection()
writeEnd1->waitForBytesWritten();
writeEnd2->waitForBytesWritten();
- writeEnd1->flush();
- writeEnd2->flush();
+ // ensure both read ends are ready for reading, before the event loop
+ QVERIFY(readEnd1.waitForRead(5s));
+ QVERIFY(readEnd2.waitForRead(5s));
UnexpectedDisconnectTester tester(&readEnd1, &readEnd2);
@@ -334,8 +311,8 @@ void tst_QSocketNotifier::posixSockets()
passive->waitForBytesWritten(5000);
QTestEventLoop::instance().enterLoop(3);
- QCOMPARE(readSpy.count(), 1);
- QCOMPARE(errorSpy.count(), 0);
+ QCOMPARE(readSpy.size(), 1);
+ QCOMPARE(errorSpy.size(), 0);
char buffer[100];
int r = qt_safe_read(posixSocket, buffer, 100);
@@ -349,9 +326,9 @@ void tst_QSocketNotifier::posixSockets()
qt_safe_write(posixSocket, "goodbye", 8);
QTestEventLoop::instance().enterLoop(3);
- QCOMPARE(readSpy.count(), 1);
- QCOMPARE(writeSpy.count(), 1);
- QCOMPARE(errorSpy.count(), 0);
+ QCOMPARE(readSpy.size(), 1);
+ QCOMPARE(writeSpy.size(), 1);
+ QCOMPARE(errorSpy.size(), 0);
// Write notifier may have fired before the read notifier inside
// QTcpSocket, give QTcpSocket a chance to see the incoming data
@@ -399,7 +376,7 @@ void tst_QSocketNotifier::asyncMultipleDatagram()
&tst_QSocketNotifier::async_readDatagramSlot);
// activate socket notifiers
- QTestEventLoop::instance().enterLoopMSecs(100);
+ QTestEventLoop::instance().enterLoop(100ms);
m_asyncSender->writeDatagram("1", makeNonAny(m_asyncReceiver->localAddress()), port);
m_asyncSender->writeDatagram("2", makeNonAny(m_asyncReceiver->localAddress()), port);
@@ -412,7 +389,7 @@ void tst_QSocketNotifier::asyncMultipleDatagram()
QTestEventLoop::instance().enterLoop(1);
QVERIFY(!QTestEventLoop::instance().timeout());
- QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.size(), 2);
delete m_asyncSender;
delete m_asyncReceiver;