From 00bafafbee3db66738ad5e96fcc69a480adc7428 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 9 Jul 2012 14:39:23 +0200 Subject: [PATCH] Improve accessibility test helpers. - 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 --- src/testlib/qtestaccessible.h | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/testlib/qtestaccessible.h b/src/testlib/qtestaccessible.h index e039cd3998..67b792d78a 100644 --- a/src/testlib/qtestaccessible.h +++ b/src/testlib/qtestaccessible.h @@ -53,6 +53,7 @@ QVERIFY(QTestAccessibility::verifyEvent(event)) #include +#include #include #include @@ -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