diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/other/qaccessibility/tst_qaccessibility.cpp | 88 |
1 files changed, 82 insertions, 6 deletions
diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index 662d459af6..76d50b93e3 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -222,6 +222,7 @@ private slots: void accessibleName(); #if QT_CONFIG(shortcut) void labelTest(); + void relationTest(); void accelerators(); #endif void bridgeTest(); @@ -3688,6 +3689,69 @@ void tst_QAccessibility::comboBoxTest() QTestAccessibility::clearEvents(); } +void tst_QAccessibility::relationTest() +{ + auto windowHolder = std::make_unique<QWidget>(); + auto window = windowHolder.get(); + QString text = "Hello World"; + QLabel *label = new QLabel(text, window); + setFrameless(label); + QSpinBox *spinBox = new QSpinBox(window); + label->setBuddy(spinBox); + QProgressBar *pb = new QProgressBar(window); + pb->setRange(0, 99); + connect(spinBox, SIGNAL(valueChanged(int)), pb, SLOT(setValue(int))); + + window->resize(320, 200); + window->show(); + + QVERIFY(QTest::qWaitForWindowExposed(window)); +#if defined(Q_OS_UNIX) + QCoreApplication::processEvents(); +#endif + QTest::qWait(100); + + QAccessibleInterface *acc_label = QAccessible::queryAccessibleInterface(label); + QVERIFY(acc_label); + QAccessibleInterface *acc_spinBox = QAccessible::queryAccessibleInterface(spinBox); + QVERIFY(acc_spinBox); + QAccessibleInterface *acc_pb = QAccessible::queryAccessibleInterface(pb); + QVERIFY(acc_pb); + + typedef QPair<QAccessibleInterface*, QAccessible::Relation> RelationPair; + { + const QList<RelationPair> rels = acc_label->relations(QAccessible::Labelled); + QCOMPARE(rels.size(), 1); + const RelationPair relPair = rels.first(); + + // spinBox is Labelled by acc_label + QCOMPARE(relPair.first->object(), spinBox); + QCOMPARE(relPair.second, QAccessible::Labelled); + } + + { + // Test multiple relations (spinBox have two) + const QList<RelationPair> rels = acc_spinBox->relations(); + QCOMPARE(rels.size(), 2); + int visitCount = 0; + for (const auto &relPair : rels) { + if (relPair.second & QAccessible::Label) { + // label is the Label of spinBox + QCOMPARE(relPair.first->object(), label); + ++visitCount; + } else if (relPair.second & QAccessible::Controlled) { + // progressbar is Controlled by the spinBox + QCOMPARE(relPair.first->object(), pb); + ++visitCount; + } + } + QCOMPARE(visitCount, rels.size()); + } + + windowHolder.reset(); + QTestAccessibility::clearEvents(); +} + #if QT_CONFIG(shortcut) void tst_QAccessibility::labelTest() @@ -3710,6 +3774,8 @@ void tst_QAccessibility::labelTest() QAccessibleInterface *acc_label = QAccessible::queryAccessibleInterface(label); QVERIFY(acc_label); + QAccessibleInterface *acc_lineEdit = QAccessible::queryAccessibleInterface(buddy); + QVERIFY(acc_lineEdit); QCOMPARE(acc_label->text(QAccessible::Name), text); QCOMPARE(acc_label->state().editable, false); @@ -3719,13 +3785,23 @@ void tst_QAccessibility::labelTest() QCOMPARE(acc_label->state().focusable, false); QCOMPARE(acc_label->state().readOnly, true); - QList<QPair<QAccessibleInterface *, QAccessible::Relation>> rels = acc_label->relations(); - QCOMPARE(rels.size(), 1); - QAccessibleInterface *iface = rels.first().first; - QAccessible::Relation rel = rels.first().second; - QCOMPARE(rel, QAccessible::Labelled); - QCOMPARE(iface->role(), QAccessible::EditableText); + typedef QPair<QAccessibleInterface*, QAccessible::Relation> RelationPair; + { + const QList<RelationPair> rels = acc_label->relations(QAccessible::Labelled); + QCOMPARE(rels.size(), 1); + const RelationPair relPair = rels.first(); + QCOMPARE(relPair.first->object(), buddy); + QCOMPARE(relPair.second, QAccessible::Labelled); + } + + { + const QList<RelationPair> rels = acc_lineEdit->relations(QAccessible::Label); + QCOMPARE(rels.size(), 1); + const RelationPair relPair = rels.first(); + QCOMPARE(relPair.first->object(), label); + QCOMPARE(relPair.second, QAccessible::Label); + } windowHolder.reset(); QTestAccessibility::clearEvents(); |