summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qsocketnotifier
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/kernel/qsocketnotifier')
-rw-r--r--tests/auto/corelib/kernel/qsocketnotifier/BLACKLIST3
-rw-r--r--tests/auto/corelib/kernel/qsocketnotifier/CMakeLists.txt16
-rw-r--r--tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp30
3 files changed, 26 insertions, 23 deletions
diff --git a/tests/auto/corelib/kernel/qsocketnotifier/BLACKLIST b/tests/auto/corelib/kernel/qsocketnotifier/BLACKLIST
deleted file mode 100644
index 664ad32582..0000000000
--- a/tests/auto/corelib/kernel/qsocketnotifier/BLACKLIST
+++ /dev/null
@@ -1,3 +0,0 @@
-[unexpectedDisconnection]
-windows ci
-
diff --git a/tests/auto/corelib/kernel/qsocketnotifier/CMakeLists.txt b/tests/auto/corelib/kernel/qsocketnotifier/CMakeLists.txt
index 3790e46eaa..2a802b5f4d 100644
--- a/tests/auto/corelib/kernel/qsocketnotifier/CMakeLists.txt
+++ b/tests/auto/corelib/kernel/qsocketnotifier/CMakeLists.txt
@@ -1,4 +1,11 @@
-# Generated from qsocketnotifier.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qsocketnotifier LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
if(NOT QT_FEATURE_private_tests)
return()
@@ -11,19 +18,16 @@ endif()
qt_internal_add_test(tst_qsocketnotifier
SOURCES
tst_qsocketnotifier.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Network
Qt::NetworkPrivate
)
-#### Keys ignored in scope 1:.:.:qsocketnotifier.pro:<TRUE>:
-# _REQUIREMENTS = "qtConfig(private_tests)"
-
## Scopes:
#####################################################################
qt_internal_extend_target(tst_qsocketnotifier CONDITION WIN32
- PUBLIC_LIBRARIES
+ LIBRARIES
ws2_32
)
diff --git a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp
index 59ef20c6e4..17bba73dab 100644
--- a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp
+++ b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtTest/QTest>
#include <QtTest/QSignalSpy>
@@ -24,6 +24,7 @@
# undef min
#endif // Q_CC_MSVC
+using namespace std::chrono_literals;
class tst_QSocketNotifier : public QObject
{
@@ -131,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());
}
@@ -151,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
@@ -187,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);
@@ -309,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);
@@ -324,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
@@ -374,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);
@@ -387,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;