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
|
||||
|
||||
#define QVERIFY_EVENT(object, child, event) \
|
||||
QVERIFY(QTestAccessibility::verifyEvent(object, child, (int)event))
|
||||
#define QVERIFY_EVENT(event) \
|
||||
QVERIFY(QTestAccessibility::verifyEvent(event))
|
||||
|
||||
#include <QtCore/qlist.h>
|
||||
#include <QtGui/qaccessible.h>
|
||||
@ -63,22 +63,21 @@ QT_BEGIN_NAMESPACE
|
||||
|
||||
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)
|
||||
: object(o), child(c), event(e) {}
|
||||
if (l.type() != r.type() ||
|
||||
l.object() != r.object() ||
|
||||
l.child() != r.child())
|
||||
return false;
|
||||
|
||||
bool operator==(const QTestAccessibilityEvent &o) const
|
||||
{
|
||||
return o.object == object && o.child == child && o.event == event;
|
||||
if (l.type() == QAccessible::StateChanged) {
|
||||
return static_cast<const QAccessibleStateChangeEvent*>(&l)->changedStates()
|
||||
== static_cast<const QAccessibleStateChangeEvent*>(&r)->changedStates();
|
||||
}
|
||||
|
||||
QObject* object;
|
||||
int child;
|
||||
int event;
|
||||
};
|
||||
|
||||
typedef QList<QTestAccessibilityEvent> EventList;
|
||||
return true;
|
||||
}
|
||||
|
||||
class QTestAccessibility
|
||||
{
|
||||
@ -90,6 +89,7 @@ public:
|
||||
qAddPostRoutine(cleanup);
|
||||
}
|
||||
}
|
||||
|
||||
static void cleanup()
|
||||
{
|
||||
delete instance();
|
||||
@ -97,18 +97,13 @@ public:
|
||||
}
|
||||
static void clearEvents() { eventList().clear(); }
|
||||
static EventList events() { return eventList(); }
|
||||
static bool verifyEvent(const QTestAccessibilityEvent& ev)
|
||||
static bool verifyEvent(const QAccessibleEvent& ev)
|
||||
{
|
||||
if (eventList().isEmpty())
|
||||
return FALSE;
|
||||
return eventList().takeFirst() == ev;
|
||||
}
|
||||
|
||||
static bool verifyEvent(QObject *o, int c, int e)
|
||||
{
|
||||
return verifyEvent(QTestAccessibilityEvent(o, c, e));
|
||||
}
|
||||
|
||||
private:
|
||||
QTestAccessibility()
|
||||
{
|
||||
@ -136,8 +131,15 @@ private:
|
||||
|
||||
static void updateHandler(const QAccessibleEvent &event)
|
||||
{
|
||||
// qDebug("updateHandler called: %p %d %d", o, c, (int)e);
|
||||
eventList().append(QTestAccessibilityEvent(event.object(), event.child(), (int)event.type()));
|
||||
eventList().append(copyEvent(event));
|
||||
}
|
||||
|
||||
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()
|
||||
|
@ -403,8 +403,8 @@ void tst_QAccessibility::cleanup()
|
||||
qWarning("%d accessibility event(s) were not handled in testfunction '%s':", list.count(),
|
||||
QString(QTest::currentTestFunction()).toAscii().constData());
|
||||
for (int i = 0; i < list.count(); ++i)
|
||||
qWarning(" %d: Object: %p Event: '%s' (%d) Child: %d", i + 1, list.at(i).object,
|
||||
eventName(list.at(i).event).toAscii().constData(), list.at(i).event, list.at(i).child);
|
||||
qWarning(" %d: Object: %p Event: '%s' Child: %d", i + 1, list.at(i).object(),
|
||||
eventName(list.at(i).type()).toAscii().constData(), list.at(i).child());
|
||||
}
|
||||
QTestAccessibility::clearEvents();
|
||||
}
|
||||
@ -415,18 +415,18 @@ void tst_QAccessibility::eventTest()
|
||||
button->setObjectName(QString("Olaf"));
|
||||
|
||||
button->show();
|
||||
QVERIFY_EVENT(button, -1, QAccessible::ObjectShow);
|
||||
QVERIFY_EVENT(QAccessibleEvent(QAccessible::ObjectShow, button, -1));
|
||||
button->setFocus(Qt::MouseFocusReason);
|
||||
QTestAccessibility::clearEvents();
|
||||
QTest::mouseClick(button, Qt::LeftButton, 0);
|
||||
|
||||
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");
|
||||
QVERIFY_EVENT(button, -1, QAccessible::DescriptionChanged);
|
||||
QVERIFY_EVENT(QAccessibleEvent(QAccessible::DescriptionChanged, button));
|
||||
|
||||
button->hide();
|
||||
QVERIFY_EVENT(button, -1, QAccessible::ObjectHide);
|
||||
QVERIFY_EVENT(QAccessibleEvent(QAccessible::ObjectHide, button));
|
||||
|
||||
delete button;
|
||||
}
|
||||
@ -730,16 +730,16 @@ void tst_QAccessibility::hideShowTest()
|
||||
window->show();
|
||||
QVERIFY(!state(window).invisible);
|
||||
QVERIFY(!state(child).invisible);
|
||||
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(window, -1, QAccessible::ObjectShow)));
|
||||
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(child, -1, QAccessible::ObjectShow)));
|
||||
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::ObjectShow, window)));
|
||||
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::ObjectShow, child)));
|
||||
QTestAccessibility::clearEvents();
|
||||
|
||||
// hide() and veryfy that both window and child are invisible and get ObjectHide events.
|
||||
window->hide();
|
||||
QVERIFY(state(window).invisible);
|
||||
QVERIFY(state(child).invisible);
|
||||
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(window, -1, QAccessible::ObjectHide)));
|
||||
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(child, -1, QAccessible::ObjectHide)));
|
||||
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::ObjectHide, window)));
|
||||
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::ObjectHide, child)));
|
||||
QTestAccessibility::clearEvents();
|
||||
|
||||
delete window;
|
||||
@ -820,7 +820,7 @@ void tst_QAccessibility::mainWindowTest()
|
||||
QLatin1String name = QLatin1String("I am the main window");
|
||||
mw->setWindowTitle(name);
|
||||
QTest::qWaitForWindowShown(mw);
|
||||
QVERIFY_EVENT(mw, -1, QAccessible::ObjectShow);
|
||||
QVERIFY_EVENT(QAccessibleEvent(QAccessible::ObjectShow, mw));
|
||||
|
||||
QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(mw);
|
||||
QCOMPARE(interface->text(QAccessible::Name), name);
|
||||
@ -1050,12 +1050,12 @@ void tst_QAccessibility::scrollBarTest()
|
||||
scrollBar->resize(200, 50);
|
||||
scrollBar->show();
|
||||
QVERIFY(!scrollBarInterface->state().invisible);
|
||||
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(scrollBar, -1, QAccessible::ObjectShow)));
|
||||
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::ObjectShow, scrollBar)));
|
||||
QTestAccessibility::clearEvents();
|
||||
|
||||
scrollBar->hide();
|
||||
QVERIFY(scrollBarInterface->state().invisible);
|
||||
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(scrollBar, -1, QAccessible::ObjectHide)));
|
||||
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::ObjectHide, scrollBar)));
|
||||
QTestAccessibility::clearEvents();
|
||||
|
||||
// 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::qWait(200);
|
||||
EventList events = QTestAccessibility::events();
|
||||
QTestAccessibilityEvent expectedEvent(spinBox, -1, (int)QAccessible::ValueChanged);
|
||||
QAccessibleEvent expectedEvent(QAccessible::ValueChanged, spinBox);
|
||||
QVERIFY(events.contains(expectedEvent));
|
||||
delete spinBox;
|
||||
QTestAccessibility::clearEvents();
|
||||
@ -1767,7 +1767,7 @@ void tst_QAccessibility::lineEditTest()
|
||||
le->setFocus(Qt::TabFocusReason);
|
||||
QTestAccessibility::clearEvents();
|
||||
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->setValidator(new QIntValidator());
|
||||
@ -1787,7 +1787,7 @@ void tst_QAccessibility::lineEditTest()
|
||||
le3->deselect();
|
||||
le3->setCursorPosition(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);
|
||||
QTestAccessibility::clearEvents();
|
||||
|
||||
@ -2158,11 +2158,11 @@ void tst_QAccessibility::listTest()
|
||||
|
||||
// Check for events
|
||||
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(QTestAccessibilityEvent(listView, 2, QAccessible::Focus)));
|
||||
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::Selection, listView, 2)));
|
||||
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::Focus, listView, 2)));
|
||||
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(QTestAccessibilityEvent(listView, 3, QAccessible::Focus)));
|
||||
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::Selection, listView, 3)));
|
||||
QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::Focus, listView, 3)));
|
||||
|
||||
listView->addItem("Munich");
|
||||
QCOMPARE(iface->childCount(), 4);
|
||||
|
Loading…
Reference in New Issue
Block a user