summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2009-04-15 08:12:34 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-04-15 08:17:13 (GMT)
commitb33ebce3de3efd98a45c8ca0a349f78aac09c875 (patch)
tree805f300733a23c73e603124f6510083ff8b579dd
parent6c4b9cb575292f5f81afc772d993c1a53eb96ea5 (diff)
downloadQt-b33ebce3de3efd98a45c8ca0a349f78aac09c875.zip
Qt-b33ebce3de3efd98a45c8ca0a349f78aac09c875.tar.gz
Qt-b33ebce3de3efd98a45c8ca0a349f78aac09c875.tar.bz2
Don't crash or loop infinitely when we retrieving the accessible accel.
qt_accHotKey() was pretty buggy; it could both crash or spin forever in some cases. Task-number: 221731 Reviewed-by: alexis
-rw-r--r--src/gui/accessible/qaccessiblewidget.cpp13
-rw-r--r--tests/auto/qaccessibility/tst_qaccessibility.cpp52
2 files changed, 56 insertions, 9 deletions
diff --git a/src/gui/accessible/qaccessiblewidget.cpp b/src/gui/accessible/qaccessiblewidget.cpp
index 4b2b2ab..753ac57 100644
--- a/src/gui/accessible/qaccessiblewidget.cpp
+++ b/src/gui/accessible/qaccessiblewidget.cpp
@@ -131,9 +131,16 @@ QString Q_GUI_EXPORT qt_accHotKey(const QString &text)
int fa = 0;
QChar ac;
while ((fa = text.indexOf(QLatin1Char('&'), fa)) != -1) {
- if (fa == text.length() - 1 || text.at(fa+1) != QLatin1Char('&')) {
- ac = text.at(fa+1);
- break;
+ ++fa;
+ if (fa < text.length()) {
+ // ignore "&&"
+ if (text.at(fa) == QLatin1Char('&')) {
+ ++fa;
+ continue;
+ } else {
+ ac = text.at(fa);
+ break;
+ }
}
}
if (ac.isNull())
diff --git a/tests/auto/qaccessibility/tst_qaccessibility.cpp b/tests/auto/qaccessibility/tst_qaccessibility.cpp
index d023557..1aca624 100644
--- a/tests/auto/qaccessibility/tst_qaccessibility.cpp
+++ b/tests/auto/qaccessibility/tst_qaccessibility.cpp
@@ -275,6 +275,7 @@ private slots:
void accessibleName();
void treeWidgetTest();
void labelTest();
+ void accelerators();
private:
QWidget *createGUI();
@@ -2592,8 +2593,8 @@ void tst_QAccessibility::menuTest()
QTestAccessibility::clearEvents();
mw.hide();
-
-
+
+
// Do not crash if the menu don't have a parent
QMenu *menu = new QMenu;
menu->addAction(QLatin1String("one"));
@@ -2607,7 +2608,7 @@ void tst_QAccessibility::menuTest()
delete iface2;
delete iface;
delete menu;
-
+
}
QTestAccessibility::clearEvents();
#else
@@ -3988,13 +3989,13 @@ void tst_QAccessibility::treeWidgetTest()
QCOMPARE(entry, 0);
QCOMPARE(accTreeItem2->text(QAccessible::Name, 0), QLatin1String("row: 1"));
-
- // test selected/focused state
+
+ // test selected/focused state
QItemSelectionModel *selModel = tree->selectionModel();
QVERIFY(selModel);
selModel->select(QItemSelection(tree->model()->index(0, 0), tree->model()->index(3, 0)), QItemSelectionModel::Select);
selModel->setCurrentIndex(tree->model()->index(1, 0), QItemSelectionModel::Current);
-
+
for (int i = 1; i < 10 ; ++i) {
QAccessible::State expected;
if (i <= 5 && i >= 2)
@@ -4046,6 +4047,45 @@ void tst_QAccessibility::labelTest()
#endif
}
+void tst_QAccessibility::accelerators()
+{
+#ifdef QTEST_ACCESSIBILITY
+ QWidget *window = new QWidget;
+ QHBoxLayout *lay = new QHBoxLayout(window);
+ QLabel *label = new QLabel(tr("&Line edit"), window);
+ QLineEdit *le = new QLineEdit(window);
+ lay->addWidget(label);
+ lay->addWidget(le);
+ label->setBuddy(le);
+
+ window->show();
+
+ QAccessibleInterface *accLineEdit = QAccessible::queryAccessibleInterface(le);
+ QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString(QKeySequence(Qt::ALT) + QLatin1String("L")));
+ label->setText(tr("Q &"));
+ QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString());
+ label->setText(tr("Q &&"));
+ QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString());
+ label->setText(tr("Q && A"));
+ QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString());
+ label->setText(tr("Q &&&A"));
+ QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString(QKeySequence(Qt::ALT) + QLatin1String("A")));
+ label->setText(tr("Q &&A"));
+ QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString());
+ label->setText(tr("Q &A&B"));
+ QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString(QKeySequence(Qt::ALT) + QLatin1String("A")));
+
+#if defined(Q_WS_X11)
+ qt_x11_wait_for_window_manager(window);
+#endif
+ QTest::qWait(100);
+ delete window;
+ QTestAccessibility::clearEvents();
+#else
+ QSKIP("Test needs Qt >= 0x040000 and accessibility support.", SkipAll);
+#endif
+}
+
QTEST_MAIN(tst_QAccessibility)