summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2015-04-16 16:13:37 -0700
committerThiago Macieira <thiago.macieira@intel.com>2015-06-19 23:22:30 +0000
commit54589f293297f0c132a7814a14f0d6ab38393b19 (patch)
tree4e9794a616fede2cc6bb22f30495ff5ee1354ae1 /tests
parente70d4b989903203e3309272666a42e4ee1846b6c (diff)
Autotest: Check where global event filters get run
Global (application-level) event filters are supposed to be run only in the main thread, so ensure that it is the case. Change-Id: I27eaacb532114dd188c4ffff13d5a17d991b8bd2 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp55
-rw-r--r--tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h3
2 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp
index 924db17c04..efecf31d66 100644
--- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp
+++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2015 Intel Corporation.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -60,6 +61,23 @@ public:
}
};
+class ThreadedEventReceiver : public QObject
+{
+ Q_OBJECT
+public:
+ QList<int> recordedEvents;
+ bool event(QEvent *event) Q_DECL_OVERRIDE
+ {
+ if (event->type() != QEvent::Type(QEvent::User + 1))
+ return QObject::event(event);
+ recordedEvents.append(event->type());
+ QThread::currentThread()->quit();
+ QCoreApplication::quit();
+ moveToThread(0);
+ return true;
+ }
+};
+
void tst_QCoreApplication::sendEventsOnProcessEvents()
{
int argc = 1;
@@ -797,6 +815,43 @@ void tst_QCoreApplication::QTBUG31606_QEventDestructorDeadLock()
QVERIFY(spy.recordedEvents.contains(QEvent::User + 2));
}
+// this is almost identical to sendEventsOnProcessEvents
+void tst_QCoreApplication::applicationEventFilters_mainThread()
+{
+ int argc = 1;
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
+ TestApplication app(argc, argv);
+
+ EventSpy spy;
+ app.installEventFilter(&spy);
+
+ QCoreApplication::postEvent(&app, new QEvent(QEvent::Type(QEvent::User + 1)));
+ QTimer::singleShot(10, &app, SLOT(quit()));
+ app.exec();
+ QVERIFY(spy.recordedEvents.contains(QEvent::User + 1));
+}
+
+void tst_QCoreApplication::applicationEventFilters_auxThread()
+{
+ int argc = 1;
+ char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
+ TestApplication app(argc, argv);
+ QThread thread;
+ ThreadedEventReceiver receiver;
+ receiver.moveToThread(&thread);
+
+ EventSpy spy;
+ app.installEventFilter(&spy);
+
+ // this is very similar to sendEventsOnProcessEvents
+ QCoreApplication::postEvent(&receiver, new QEvent(QEvent::Type(QEvent::User + 1)));
+ QTimer::singleShot(1000, &app, SLOT(quit()));
+ thread.start();
+ app.exec();
+ QVERIFY(thread.wait(1000));
+ QVERIFY(receiver.recordedEvents.contains(QEvent::User + 1));
+ QVERIFY(!spy.recordedEvents.contains(QEvent::User + 1));
+}
static void createQObjectOnDestruction()
{
diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h
index 3dd84482d7..09e15723ac 100644
--- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h
+++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2015 Intel Corporation.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -58,6 +59,8 @@ private slots:
void customEventDispatcher();
void testQuitLock();
void QTBUG31606_QEventDestructorDeadLock();
+ void applicationEventFilters_mainThread();
+ void applicationEventFilters_auxThread();
};
#endif // TST_QCOREAPPLICATION_H