Deliver events in qtestmouse
authorLaszlo Agocs <laszlo.p.agocs@nokia.com>
Mon, 12 Mar 2012 08:48:08 +0000 (10:48 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 13 Mar 2012 20:11:55 +0000 (21:11 +0100)
Not waiting until the QPA event queue is processed after
handleMouseEvent() is wrong. Unlike the synchronous sendEvent() calls
these tests most likely utilized earlier, many of the
QWindowSystemInterace functions are asynchronous in the sense that they
just queue the event, delivery will happen when the event dispatcher on
the main thread gets there.

Change-Id: I8197d2dc4805cda684a8279ceb8d4b317f19aba7
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com>
src/testlib/qtestmouse.h

index 593e164..441cfa1 100644 (file)
@@ -70,6 +70,15 @@ namespace QTest
 {
     enum MouseAction { MousePress, MouseRelease, MouseClick, MouseDClick, MouseMove };
 
+    static void waitForEvents()
+    {
+#ifdef Q_OS_MAC
+        QTest::qWait(20);
+#else
+        qApp->processEvents();
+#endif
+    }
+
     static void mouseEvent(MouseAction action, QWindow *window, Qt::MouseButton button,
                            Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
     {
@@ -119,15 +128,11 @@ namespace QTest
             case MouseMove:
                 QWindowSystemInterface::handleMouseEvent(window,pos,window->mapToGlobal(pos),lastButton,stateKey);
                 //QCursor::setPos(window->mapToGlobal(pos));
-#ifdef Q_OS_MAC
-                QTest::qWait(20);
-#else
-                qApp->processEvents();
-#endif
-                return;
+                break;
             default:
                 QTEST_ASSERT(false);
         }
+        waitForEvents();
     }
 
     inline void mousePress(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,