summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp')
-rw-r--r--tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp95
1 files changed, 44 insertions, 51 deletions
diff --git a/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp b/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp
index 1f0b8d4b4e..06175e6f2f 100644
--- a/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp
+++ b/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp
@@ -1,32 +1,7 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
#include <qabstracteventdispatcher.h>
#include <qcoreapplication.h>
@@ -34,7 +9,9 @@
#include <qeventloop.h>
#include <private/qeventloop_p.h>
#if defined(Q_OS_UNIX)
- #include <private/qeventdispatcher_unix_p.h>
+ #if !defined(Q_OS_WASM)
+ #include <private/qeventdispatcher_unix_p.h>
+ #endif
#include <QtCore/private/qcore_unix_p.h>
#if defined(HAVE_GLIB)
#include <private/qeventdispatcher_glib_p.h>
@@ -46,6 +23,7 @@
#include <qwaitcondition.h>
#include <QTcpServer>
#include <QTcpSocket>
+#include <QSignalSpy>
class EventLoopExiter : public QObject
{
@@ -77,7 +55,7 @@ signals:
void checkPoint();
public:
QEventLoop *eventLoop;
- void run();
+ void run() override;
};
void EventLoopThread::run()
@@ -86,7 +64,7 @@ void EventLoopThread::run()
emit checkPoint();
(void) eventLoop->exec();
delete eventLoop;
- eventLoop = 0;
+ eventLoop = nullptr;
}
class MultipleExecThread : public QThread
@@ -101,7 +79,7 @@ public:
volatile int result2;
MultipleExecThread() : result1(0xdead), result2(0xbeef) {}
- void run()
+ void run() override
{
QMutexLocker locker(&mutex);
// this exec should work
@@ -126,7 +104,7 @@ public:
class StartStopEvent: public QEvent
{
public:
- explicit StartStopEvent(int type, QEventLoop *loop = 0)
+ explicit StartStopEvent(int type, QEventLoop *loop = nullptr)
: QEvent(Type(type)), el(loop)
{ }
@@ -162,6 +140,7 @@ class tst_QEventLoop : public QObject
Q_OBJECT
private slots:
// This test *must* run first. See the definition for why.
+ void processEvents_data();
void processEvents();
void exec();
void reexec();
@@ -180,11 +159,24 @@ private slots:
void testQuitLock();
protected:
- void customEvent(QEvent *e);
+ void customEvent(QEvent *e) override;
};
+void tst_QEventLoop::processEvents_data()
+{
+ QTest::addColumn<QString>("mode");
+
+#ifdef QT_GUI_LIB
+ QTest::addRow("gui") << "gui";
+#else
+ QTest::addRow("core") << "core";
+#endif
+}
+
void tst_QEventLoop::processEvents()
{
+ QFETCH(QString, mode);
+
QSignalSpy aboutToBlockSpy(QAbstractEventDispatcher::instance(), &QAbstractEventDispatcher::aboutToBlock);
QSignalSpy awakeSpy(QAbstractEventDispatcher::instance(), &QAbstractEventDispatcher::awake);
@@ -198,8 +190,8 @@ void tst_QEventLoop::processEvents()
// process posted events, QEventLoop::processEvents() should return
// true
QVERIFY(eventLoop.processEvents());
- QCOMPARE(aboutToBlockSpy.count(), 0);
- QCOMPARE(awakeSpy.count(), 1);
+ QCOMPARE(aboutToBlockSpy.size(), 0);
+ QCOMPARE(awakeSpy.size(), 1);
// allow any session manager to complete its handshake, so that
// there are no pending events left. This tests that we are able
@@ -220,8 +212,8 @@ void tst_QEventLoop::processEvents()
// processEvents is entered. There is no guarantee that that the
// processEvents call actually blocked, since the OS may introduce
// native events at any time.
- QVERIFY(awakeSpy.count() > 0);
- QVERIFY(awakeSpy.count() >= aboutToBlockSpy.count());
+ QVERIFY(awakeSpy.size() > 0);
+ QVERIFY(awakeSpy.size() >= aboutToBlockSpy.size());
killTimer(timerId);
}
@@ -264,7 +256,7 @@ void tst_QEventLoop::exec()
QVERIFY(spy.isValid());
thread.cond.wakeOne();
thread.cond.wait(&thread.mutex);
- QVERIFY(spy.count() > 0);
+ QVERIFY(spy.size() > 0);
int v = thread.result1;
QCOMPARE(v, 0);
@@ -273,7 +265,7 @@ void tst_QEventLoop::exec()
thread.cond.wakeOne();
thread.mutex.unlock();
thread.wait();
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
v = thread.result2;
QCOMPARE(v, -1);
}
@@ -331,7 +323,7 @@ void tst_QEventLoop::wakeUp()
QTimer::singleShot(1000, &eventLoop, SLOT(quit()));
(void) eventLoop.exec();
- QVERIFY(spy.count() > 0);
+ QVERIFY(spy.size() > 0);
thread.quit();
(void) eventLoop.exec();
@@ -424,8 +416,8 @@ public slots:
dataSent = serverSocket->waitForBytesWritten(-1);
if (dataSent) {
- pollfd pfd = qt_make_pollfd(socket->socketDescriptor(), POLLIN);
- dataReadable = (1 == qt_safe_poll(&pfd, 1, nullptr));
+ pollfd pfd = qt_make_pollfd(int(socket->socketDescriptor()), POLLIN);
+ dataReadable = (1 == qt_safe_poll(&pfd, 1, QDeadlineTimer::Forever));
}
if (!dataReadable) {
@@ -446,7 +438,7 @@ class SocketTestThread : public QThread
Q_OBJECT
public:
SocketTestThread():QThread(0),testResult(false){};
- void run()
+ void run() override
{
SocketEventsTester *tester = new SocketEventsTester();
if (tester->init())
@@ -489,7 +481,7 @@ public:
: QObject(), gotTimerEvent(-1)
{ }
- void timerEvent(QTimerEvent *event)
+ void timerEvent(QTimerEvent *event) override
{
gotTimerEvent = event->timerId();
}
@@ -510,7 +502,7 @@ void tst_QEventLoop::processEventsExcludeTimers()
// but not if we exclude timers
eventLoop.processEvents(QEventLoop::X11ExcludeTimers);
-#if defined(Q_OS_UNIX)
+#if defined(Q_OS_UNIX) && !defined(Q_OS_WASM)
QAbstractEventDispatcher *eventDispatcher = QCoreApplication::eventDispatcher();
if (!qobject_cast<QEventDispatcherUNIX *>(eventDispatcher)
#if defined(HAVE_GLIB)
@@ -546,7 +538,7 @@ namespace DeliverInDefinedOrder {
}
int lastReceived[NbEventQueue];
int count;
- virtual void customEvent(QEvent* e) {
+ virtual void customEvent(QEvent* e) override {
QVERIFY(e->type() >= QEvent::User);
QVERIFY(e->type() < QEvent::User + 5);
uint idx = e->type() - QEvent::User;
@@ -569,7 +561,8 @@ void tst_QEventLoop::deliverInDefinedOrder()
using namespace DeliverInDefinedOrder;
qMetaTypeId<QThread*>();
QThread threads[NbThread];
- Object objects[NbObject];
+ // GHS compiler needs the namespace prefix, despite using above.
+ DeliverInDefinedOrder::Object objects[NbObject];
for (int t = 0; t < NbThread; t++) {
threads[t].start();
}
@@ -602,12 +595,12 @@ class JobObject : public QObject
Q_OBJECT
public:
- explicit JobObject(QEventLoop *loop, QObject *parent = 0)
+ explicit JobObject(QEventLoop *loop, QObject *parent = nullptr)
: QObject(parent), locker(loop)
{
}
- explicit JobObject(QObject *parent = 0)
+ explicit JobObject(QObject *parent = nullptr)
: QObject(parent)
{
}