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 <frederik.gladhorn@nokia.com>
This commit is contained in:
Friedemann Kleint 2012-07-09 14:39:23 +02:00 committed by Qt by Nokia
parent c97104f31e
commit 00bafafbee

View File

@ -53,6 +53,7 @@
QVERIFY(QTestAccessibility::verifyEvent(event)) QVERIFY(QTestAccessibility::verifyEvent(event))
#include <QtCore/qlist.h> #include <QtCore/qlist.h>
#include <QtCore/qdebug.h>
#include <QtGui/qaccessible.h> #include <QtGui/qaccessible.h>
#include <QtGui/qguiapplication.h> #include <QtGui/qguiapplication.h>
@ -137,11 +138,17 @@ public:
static EventList events() { return eventList(); } static EventList events() { return eventList(); }
static bool verifyEvent(QAccessibleEvent *ev) 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; return false;
QAccessibleEvent *first = eventList().takeFirst(); }
bool res = *first == *ev; const bool res = *eventList().first() == *ev;
delete first; if (!res)
qWarning("%s: %s", Q_FUNC_INFO,
qPrintable(msgAccessibilityEventListMismatch(eventList(), ev)));
delete eventList().takeFirst();
return res; return res;
} }
static bool containsEvent(QAccessibleEvent *event) { static bool containsEvent(QAccessibleEvent *event) {
@ -229,6 +236,22 @@ private:
static QTestAccessibility *ta = 0; static QTestAccessibility *ta = 0;
return ta; 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 #endif