Improve accessibility test helpers.
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>
Mon, 9 Jul 2012 12:39:23 +0000 (14:39 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 13 Jul 2012 07:55:18 +0000 (09:55 +0200)
- Wait for accessibility events using qWait, allowing for
  event processing,
- Output a verbose message if the event cannot be found.

Change-Id: Iaadbd235c15dd12bb14724e1724dd04328532a96
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@nokia.com>
src/testlib/qtestaccessible.h

index e039cd3..67b792d 100644 (file)
@@ -53,6 +53,7 @@
     QVERIFY(QTestAccessibility::verifyEvent(event))
 
 #include <QtCore/qlist.h>
+#include <QtCore/qdebug.h>
 #include <QtGui/qaccessible.h>
 #include <QtGui/qguiapplication.h>
 
@@ -137,11 +138,17 @@ public:
     static EventList events() { return eventList(); }
     static bool verifyEvent(QAccessibleEvent *ev)
     {
-        if (eventList().isEmpty())
+        for (int i = 0; eventList().isEmpty() && i < 5; ++i)
+            QTest::qWait(50);
+        if (eventList().isEmpty()) {
+            qWarning("%s: Timeout waiting for accessibility event.", Q_FUNC_INFO);
             return false;
-        QAccessibleEvent *first = eventList().takeFirst();
-        bool res = *first == *ev;
-        delete first;
+        }
+        const bool res = *eventList().first() == *ev;
+        if (!res)
+            qWarning("%s: %s", Q_FUNC_INFO,
+                     qPrintable(msgAccessibilityEventListMismatch(eventList(), ev)));
+        delete eventList().takeFirst();
         return res;
     }
     static bool containsEvent(QAccessibleEvent *event) {
@@ -229,6 +236,22 @@ private:
         static QTestAccessibility *ta = 0;
         return ta;
     }
+
+private:
+    static QString msgAccessibilityEventListMismatch(const EventList &haystack,
+                                                     const QAccessibleEvent *needle)
+    {
+        QString rc;
+        QDebug str = QDebug(&rc).nospace();
+        str << "Event " << needle->object() <<  ", type: "
+           << needle->type() << ", child: " << needle->child()
+           <<  " not found at head of event list of size " << haystack.size() << " :";
+        foreach (const QAccessibleEvent *e, haystack)
+            str << ' ' << e->object() << ", type: "
+                << e->type() << ", child: " << e->child();
+        return rc;
+    }
+
 };
 
 #endif