Run tst_QEventDispatcher with the GUI event dispatchers as well
authorBradley T. Hughes <bradley.hughes@nokia.com>
Mon, 23 Jan 2012 07:52:13 +0000 (08:52 +0100)
committerQt by Nokia <qt-info@nokia.com>
Fri, 10 Feb 2012 14:22:03 +0000 (15:22 +0100)
Since some GUI event dispatchers are complete reimplementations and do
not build on the corelib ones, we want to run the same tests with the
other dispatcher.

Since this is a GUI test now, we need to make sure to drain system
events queued during application startup to make sure we can reliably
run the test functions.

Change-Id: I4905db70bc8f8584c4ef1f4d767824040281452c
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp
tests/auto/gui/kernel/kernel.pro
tests/auto/gui/kernel/qguieventdispatcher/qguieventdispatcher.pro [new file with mode: 0644]

index 07bd73f..d06912e 100644 (file)
 **
 ****************************************************************************/
 
-#include <QtCore/QCoreApplication>
+#ifdef QT_GUI_LIB
+#  include <QtGui/QGuiApplication>
+#else
+#  include <QtCore/QCoreApplication>
+#endif
 #include <QtTest/QtTest>
 
 enum {
@@ -68,6 +72,7 @@ public:
     { }
 
 private slots:
+    void initTestCase();
     void registerTimer();
     /* void registerSocketNotifier(); */ // Not implemented here, see tst_QSocketNotifier instead
     /* void registerEventNotifiier(); */ // Not implemented here, see tst_QWinEventNotifier instead
@@ -88,6 +93,16 @@ bool tst_QEventDispatcher::event(QEvent *e)
     return QObject::event(e);
 }
 
+// drain the system event queue after the test starts to avoid destabilizing the test functions
+void tst_QEventDispatcher::initTestCase()
+{
+    QElapsedTimer elapsedTimer;
+    elapsedTimer.start();
+    while (!elapsedTimer.hasExpired(CoarseTimerInterval) && eventDispatcher->processEvents(QEventLoop::AllEvents)) {
+            ;
+    }
+}
+
 // test that the eventDispatcher's timer implementation is complete and working
 void tst_QEventDispatcher::registerTimer()
 {
index 1adae12..116e9dd 100644 (file)
@@ -4,6 +4,7 @@ SUBDIRS=\
    qdrag \
    qevent \
    qfileopenevent \
+   qguieventdispatcher \
    qguimetatype \
    qguivariant \
    qinputmethod \
diff --git a/tests/auto/gui/kernel/qguieventdispatcher/qguieventdispatcher.pro b/tests/auto/gui/kernel/qguieventdispatcher/qguieventdispatcher.pro
new file mode 100644 (file)
index 0000000..3057037
--- /dev/null
@@ -0,0 +1,4 @@
+CONFIG += testcase
+TARGET = tst_qguieventdispatcher
+QT = core gui testlib
+SOURCES += ../../../corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp