Use QAccessibleEvent in test.
Change-Id: I4f9c0f503543caa5704a29c8ccd7c4134b455625 Reviewed-by: Jan-Arve Sæther <jan-arve.saether@nokia.com>
This commit is contained in:
parent
431eb30e9e
commit
ca737f566b
@ -49,8 +49,8 @@
|
|||||||
|
|
||||||
#ifndef QT_NO_ACCESSIBILITY
|
#ifndef QT_NO_ACCESSIBILITY
|
||||||
|
|
||||||
#define QVERIFY_EVENT(object, child, event) \
|
#define QVERIFY_EVENT(event) \
|
||||||
QVERIFY(QTestAccessibility::verifyEvent(object, child, (int)event))
|
QVERIFY(QTestAccessibility::verifyEvent(event))
|
||||||
|
|
||||||
#include <QtCore/qlist.h>
|
#include <QtCore/qlist.h>
|
||||||
#include <QtGui/qaccessible.h>
|
#include <QtGui/qaccessible.h>
|
||||||
@ -63,22 +63,21 @@ QT_BEGIN_NAMESPACE
|
|||||||
|
|
||||||
class QObject;
|
class QObject;
|
||||||
|
|
||||||
struct QTestAccessibilityEvent
|
typedef QList<QAccessibleEvent> EventList;
|
||||||
|
|
||||||
|
bool operator==(const QAccessibleEvent &l, const QAccessibleEvent &r)
|
||||||
{
|
{
|
||||||
QTestAccessibilityEvent(QObject* o = 0, int c = 0, int e = 0)
|
if (l.type() != r.type() ||
|
||||||
: object(o), child(c), event(e) {}
|
l.object() != r.object() ||
|
||||||
|
l.child() != r.child())
|
||||||
|
return false;
|
||||||
|
|
||||||
bool operator==(const QTestAccessibilityEvent &o) const
|
if (l.type() == QAccessible::StateChanged) {
|
||||||
{
|
return static_cast<const QAccessibleStateChangeEvent*>(&l)->changedStates()
|
||||||
return o.object == object && o.child == child && o.event == event;
|
== static_cast<const QAccessibleStateChangeEvent*>(&r)->changedStates();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
QObject* object;
|
}
|
||||||
int child;
|
|
||||||
int event;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef QList<QTestAccessibilityEvent> EventList;
|
|
||||||
|
|
||||||
class QTestAccessibility
|
class QTestAccessibility
|
||||||
{
|
{
|
||||||
@ -90,6 +89,7 @@ public:
|
|||||||
qAddPostRoutine(cleanup);
|
qAddPostRoutine(cleanup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cleanup()
|
static void cleanup()
|
||||||
{
|
{
|
||||||
delete instance();
|
delete instance();
|
||||||
@ -97,18 +97,13 @@ public:
|
|||||||
}
|
}
|
||||||
static void clearEvents() { eventList().clear(); }
|
static void clearEvents() { eventList().clear(); }
|
||||||
static EventList events() { return eventList(); }
|
static EventList events() { return eventList(); }
|
||||||
static bool verifyEvent(const QTestAccessibilityEvent& ev)
|
static bool verifyEvent(const QAccessibleEvent& ev)
|
||||||
{
|
{
|
||||||
if (eventList().isEmpty())
|
if (eventList().isEmpty())
|
||||||
return FALSE;
|
return FALSE;
|
||||||
return eventList().takeFirst() == ev;
|
return eventList().takeFirst() == ev;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool verifyEvent(QObject *o, int c, int e)
|
|
||||||
{
|
|
||||||
return verifyEvent(QTestAccessibilityEvent(o, c, e));
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTestAccessibility()
|
QTestAccessibility()
|
||||||
{
|
{
|
||||||
@ -136,8 +131,15 @@ private:
|
|||||||
|
|
||||||
static void updateHandler(const QAccessibleEvent &event)
|
static void updateHandler(const QAccessibleEvent &event)
|
||||||
{
|
{
|
||||||
// qDebug("updateHandler called: %p %d %d", o, c, (int)e);
|
eventList().append(copyEvent(event));
|
||||||
eventList().append(QTestAccessibilityEvent(event.object(), event.child(), (int)event.type()));
|
}
|
||||||
|
|
||||||
|
static QAccessibleEvent copyEvent(const QAccessibleEvent &event)
|
||||||
|
{
|
||||||
|
if (event.type() == QAccessible::StateChanged)
|
||||||
|
return QAccessibleStateChangeEvent(static_cast<const QAccessibleStateChangeEvent*>(&event)->changedStates(),
|
||||||
|
event.object(), event.child());
|
||||||
|
return QAccessibleEvent(event.type(), event.object(), event.child());
|
||||||
}
|
}
|
||||||
|
|
||||||
static EventList &eventList()
|
static EventList &eventList()
|
||||||
|
@ -403,8 +403,8 @@ void tst_QAccessibility::cleanup()
|
|||||||
qWarning("%d accessibility event(s) were not handled in testfunction '%s':", list.count(),
|
qWarning("%d accessibility event(s) were not handled in testfunction '%s':", list.count(),
|
||||||
QString(QTest::currentTestFunction()).toAscii().constData());
|
QString(QTest::currentTestFunction()).toAscii().constData());
|
||||||
for (int i = 0; i < list.count(); ++i)
|
for (int i = 0; i < list.count(); ++i)
|
||||||
qWarning(" %d: Object: %p Event: '%s' (%d) Child: %d", i + 1, list.at(i).object,
|
qWarning(" %d: Object: %p Event: '%s' Child: %d", i + 1, list.at(i).object(),
|
||||||
eventName(list.at(i).event).toAscii().constData(), list.at(i).event, list.at(i).child);
|
eventName(list.at(i).type()).toAscii().constData(), list.at(i).child());
|
||||||
}
|
}
|
||||||
QTestAccessibility::clearEvents();
|
QTestAccessibility::clearEvents();
|
||||||
}
|
}
|
||||||
@ -415,18 +415,18 @@ void tst_QAccessibility::eventTest()
|
|||||||
button->setObjectName(QString("Olaf"));
|
button->setObjectName(QString("Olaf"));
|
||||||
|
|
||||||
button->show();
|
button->show();
|
||||||
QVERIFY_EVENT(button, -1, QAccessible::ObjectShow);
|
QVERIFY_EVENT(QAccessibleEvent(QAccessible::ObjectShow, button, -1));
|
||||||
button->setFocus(Qt::MouseFocusReason);
|
button->setFocus(Qt::MouseFocusReason);
|
||||||
QTestAccessibility::clearEvents();
|
QTestAccessibility::clearEvents();
|
||||||
QTest::mouseClick(button, Qt::LeftButton, 0);
|
QTest::mouseClick(button, Qt::LeftButton, 0);
|
||||||
|
|
||||||
button->setAccessibleName("Olaf the second");
|
button->setAccessibleName("Olaf the second");
|
||||||
QVERIFY_EVENT(button, -1, QAccessible::NameChanged);
|
QVERIFY_EVENT(QAccessibleEvent(QAccessible::NameChanged, button));
|
||||||
button->setAccessibleDescription("This is a button labeled Olaf");
|
button->setAccessibleDescription("This is a button labeled Olaf");
|
||||||
QVERIFY_EVENT(button, -1, QAccessible::DescriptionChanged);
|
QVERIFY_EVENT(QAccessibleEvent(QAccessible::DescriptionChanged, button));
|
||||||
|
|
||||||
button->hide();
|
button->hide();
|
||||||
QVERIFY_EVENT(button, -1, QAccessible::ObjectHide);
|
QVERIFY_EVENT(QAccessibleEvent(QAccessible::ObjectHide, button));
|
||||||
|
|
||||||
delete button;
|
delete button;
|
||||||
}
|
}
|
||||||
@ -730,16 +730,16 @@ void tst_QAccessibility::hideShowTest()
|
|||||||
window->show();
|
window->show();
|
||||||
QVERIFY(!state(window).invisible);
|
QVERIFY(!state(window).invisible);
|
||||||
QVERIFY(!state(child).invisible);
|
QVERIFY(!state(child).invisible);
|
||||||
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(window, -1, QAccessible::ObjectShow)));
|
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::ObjectShow, window)));
|
||||||
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(child, -1, QAccessible::ObjectShow)));
|
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::ObjectShow, child)));
|
||||||
QTestAccessibility::clearEvents();
|
QTestAccessibility::clearEvents();
|
||||||
|
|
||||||
// hide() and veryfy that both window and child are invisible and get ObjectHide events.
|
// hide() and veryfy that both window and child are invisible and get ObjectHide events.
|
||||||
window->hide();
|
window->hide();
|
||||||
QVERIFY(state(window).invisible);
|
QVERIFY(state(window).invisible);
|
||||||
QVERIFY(state(child).invisible);
|
QVERIFY(state(child).invisible);
|
||||||
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(window, -1, QAccessible::ObjectHide)));
|
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::ObjectHide, window)));
|
||||||
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(child, -1, QAccessible::ObjectHide)));
|
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::ObjectHide, child)));
|
||||||
QTestAccessibility::clearEvents();
|
QTestAccessibility::clearEvents();
|
||||||
|
|
||||||
delete window;
|
delete window;
|
||||||
@ -820,7 +820,7 @@ void tst_QAccessibility::mainWindowTest()
|
|||||||
QLatin1String name = QLatin1String("I am the main window");
|
QLatin1String name = QLatin1String("I am the main window");
|
||||||
mw->setWindowTitle(name);
|
mw->setWindowTitle(name);
|
||||||
QTest::qWaitForWindowShown(mw);
|
QTest::qWaitForWindowShown(mw);
|
||||||
QVERIFY_EVENT(mw, -1, QAccessible::ObjectShow);
|
QVERIFY_EVENT(QAccessibleEvent(QAccessible::ObjectShow, mw));
|
||||||
|
|
||||||
QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(mw);
|
QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(mw);
|
||||||
QCOMPARE(interface->text(QAccessible::Name), name);
|
QCOMPARE(interface->text(QAccessible::Name), name);
|
||||||
@ -1050,12 +1050,12 @@ void tst_QAccessibility::scrollBarTest()
|
|||||||
scrollBar->resize(200, 50);
|
scrollBar->resize(200, 50);
|
||||||
scrollBar->show();
|
scrollBar->show();
|
||||||
QVERIFY(!scrollBarInterface->state().invisible);
|
QVERIFY(!scrollBarInterface->state().invisible);
|
||||||
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(scrollBar, -1, QAccessible::ObjectShow)));
|
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::ObjectShow, scrollBar)));
|
||||||
QTestAccessibility::clearEvents();
|
QTestAccessibility::clearEvents();
|
||||||
|
|
||||||
scrollBar->hide();
|
scrollBar->hide();
|
||||||
QVERIFY(scrollBarInterface->state().invisible);
|
QVERIFY(scrollBarInterface->state().invisible);
|
||||||
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(scrollBar, -1, QAccessible::ObjectHide)));
|
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::ObjectHide, scrollBar)));
|
||||||
QTestAccessibility::clearEvents();
|
QTestAccessibility::clearEvents();
|
||||||
|
|
||||||
// Test that the left/right subcontrols are set to unavailable when the scrollBar is at the minimum/maximum.
|
// Test that the left/right subcontrols are set to unavailable when the scrollBar is at the minimum/maximum.
|
||||||
@ -1496,7 +1496,7 @@ void tst_QAccessibility::spinBoxTest()
|
|||||||
QTest::keyPress(spinBox, Qt::Key_Up);
|
QTest::keyPress(spinBox, Qt::Key_Up);
|
||||||
QTest::qWait(200);
|
QTest::qWait(200);
|
||||||
EventList events = QTestAccessibility::events();
|
EventList events = QTestAccessibility::events();
|
||||||
QTestAccessibilityEvent expectedEvent(spinBox, -1, (int)QAccessible::ValueChanged);
|
QAccessibleEvent expectedEvent(QAccessible::ValueChanged, spinBox);
|
||||||
QVERIFY(events.contains(expectedEvent));
|
QVERIFY(events.contains(expectedEvent));
|
||||||
delete spinBox;
|
delete spinBox;
|
||||||
QTestAccessibility::clearEvents();
|
QTestAccessibility::clearEvents();
|
||||||
@ -1767,7 +1767,7 @@ void tst_QAccessibility::lineEditTest()
|
|||||||
le->setFocus(Qt::TabFocusReason);
|
le->setFocus(Qt::TabFocusReason);
|
||||||
QTestAccessibility::clearEvents();
|
QTestAccessibility::clearEvents();
|
||||||
le2->setFocus(Qt::TabFocusReason);
|
le2->setFocus(Qt::TabFocusReason);
|
||||||
QTRY_VERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(le2, -1, QAccessible::Focus)));
|
QTRY_VERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::Focus, le2)));
|
||||||
|
|
||||||
le->setText(QLatin1String("500"));
|
le->setText(QLatin1String("500"));
|
||||||
le->setValidator(new QIntValidator());
|
le->setValidator(new QIntValidator());
|
||||||
@ -1787,7 +1787,7 @@ void tst_QAccessibility::lineEditTest()
|
|||||||
le3->deselect();
|
le3->deselect();
|
||||||
le3->setCursorPosition(3);
|
le3->setCursorPosition(3);
|
||||||
QCOMPARE(textIface->cursorPosition(), 3);
|
QCOMPARE(textIface->cursorPosition(), 3);
|
||||||
QTRY_VERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(le3, -1, QAccessible::TextCaretMoved)));
|
QTRY_VERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::TextCaretMoved, le3)));
|
||||||
QCOMPARE(textIface->selectionCount(), 0);
|
QCOMPARE(textIface->selectionCount(), 0);
|
||||||
QTestAccessibility::clearEvents();
|
QTestAccessibility::clearEvents();
|
||||||
|
|
||||||
@ -2158,11 +2158,11 @@ void tst_QAccessibility::listTest()
|
|||||||
|
|
||||||
// Check for events
|
// Check for events
|
||||||
QTest::mouseClick(listView->viewport(), Qt::LeftButton, 0, listView->visualItemRect(listView->item(1)).center());
|
QTest::mouseClick(listView->viewport(), Qt::LeftButton, 0, listView->visualItemRect(listView->item(1)).center());
|
||||||
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(listView, 2, QAccessible::Selection)));
|
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::Selection, listView, 2)));
|
||||||
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(listView, 2, QAccessible::Focus)));
|
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::Focus, listView, 2)));
|
||||||
QTest::mouseClick(listView->viewport(), Qt::LeftButton, 0, listView->visualItemRect(listView->item(2)).center());
|
QTest::mouseClick(listView->viewport(), Qt::LeftButton, 0, listView->visualItemRect(listView->item(2)).center());
|
||||||
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(listView, 3, QAccessible::Selection)));
|
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::Selection, listView, 3)));
|
||||||
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(listView, 3, QAccessible::Focus)));
|
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::Focus, listView, 3)));
|
||||||
|
|
||||||
listView->addItem("Munich");
|
listView->addItem("Munich");
|
||||||
QCOMPARE(iface->childCount(), 4);
|
QCOMPARE(iface->childCount(), 4);
|
||||||
|
Loading…
Reference in New Issue
Block a user