diff options
Diffstat (limited to 'tests/auto/other')
15 files changed, 383 insertions, 449 deletions
diff --git a/tests/auto/other/android/CMakeLists.txt b/tests/auto/other/android/CMakeLists.txt deleted file mode 100644 index c2749825ac..0000000000 --- a/tests/auto/other/android/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -# Generated from android.pro. - -##################################################################### -## tst_android Test: -##################################################################### - -qt_internal_add_test(tst_android - SOURCES - tst_android.cpp -) - -if(ANDROID) - set_property(TARGET tst_android APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR - ${CMAKE_CURRENT_SOURCE_DIR}/testdata - ) - # QTBUG-88840 # special case - qt_android_generate_deployment_settings(tst_android) # special case -endif() - -#### Keys ignored in scope 1:.:.:android.pro:<TRUE>: -# DISTFILES = "testdata/assets/test.txt" diff --git a/tests/auto/other/android/testdata/assets/test.txt b/tests/auto/other/android/testdata/assets/test.txt deleted file mode 100644 index 61e2c47c25..0000000000 --- a/tests/auto/other/android/testdata/assets/test.txt +++ /dev/null @@ -1 +0,0 @@ -FooBar
\ No newline at end of file diff --git a/tests/auto/other/android/tst_android.cpp b/tests/auto/other/android/tst_android.cpp deleted file mode 100644 index 938ff3c9b2..0000000000 --- a/tests/auto/other/android/tst_android.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#include <jni.h> - -#include <QTest> -#include <QtCore/qnativeinterface.h> -#include <QtCore/qjniobject.h> - -class tst_Android : public QObject -{ -Q_OBJECT -private slots: - void assetsRead(); - void assetsNotWritable(); - void testAndroidSdkVersion(); - void testAndroidActivity(); -}; - -void tst_Android::assetsRead() -{ - { - QFile file(QStringLiteral("assets:/test.txt")); - QVERIFY(file.open(QIODevice::ReadOnly)); - QCOMPARE(file.readAll(), QByteArray("FooBar")); - } - - { - QFile file(QStringLiteral("assets:/test.txt")); - QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); - QCOMPARE(file.readAll(), QByteArray("FooBar")); - } -} - -void tst_Android::assetsNotWritable() -{ - QFile file(QStringLiteral("assets:/test.txt")); - QVERIFY(!file.open(QIODevice::WriteOnly)); - QVERIFY(!file.open(QIODevice::ReadWrite)); - QVERIFY(!file.open(QIODevice::Append)); -} - -void tst_Android::testAndroidSdkVersion() -{ - QVERIFY(QNativeInterface::QAndroidApplication::sdkVersion() > 0); -} - -void tst_Android::testAndroidActivity() -{ - QJniObject activity = QNativeInterface::QAndroidApplication::context(); - QVERIFY(activity.isValid()); - QVERIFY(activity.callMethod<jboolean>("isTaskRoot")); -} - -QTEST_MAIN(tst_Android) -#include "tst_android.moc" - diff --git a/tests/auto/other/gestures/BLACKLIST b/tests/auto/other/gestures/BLACKLIST index 5b4f12b80d..494005abf3 100644 --- a/tests/auto/other/gestures/BLACKLIST +++ b/tests/auto/other/gestures/BLACKLIST @@ -1,32 +1,10 @@ -[] -rhel -centos -ubuntu-18.04 -ubuntu-20.04 [customGesture] opensuse-leap # QTBUG-67254 opensuse-42.3 -[graphicsItemGesture] -ubuntu-18.04 -ubuntu-20.04 -rhel -centos -[graphicsItemTreeGesture] -ubuntu-18.04 -ubuntu-20.04 -[graphicsView] -ubuntu-18.04 -ubuntu-20.04 -rhel -centos -[explicitGraphicsObjectTarget] -ubuntu-18.04 +[panelPropagation] ubuntu-20.04 -rhel -centos -[autoCancelGestures2] -ubuntu-18.04 +ubuntu-22.04 ci +[panelStacksBehindParent] ubuntu-20.04 -rhel -centos +ubuntu-22.04 ci diff --git a/tests/auto/other/gestures/tst_gestures.cpp b/tests/auto/other/gestures/tst_gestures.cpp index 81b186c0a1..ac85872b1d 100644 --- a/tests/auto/other/gestures/tst_gestures.cpp +++ b/tests/auto/other/gestures/tst_gestures.cpp @@ -282,6 +282,10 @@ Q_OBJECT private slots: void initTestCase(); void cleanupTestCase(); + + void init(); + void cleanup(); + void customGesture(); void autoCancelingGestures(); void gestureOverChild(); @@ -318,16 +322,28 @@ private slots: void testQGestureRecognizerCleanup(); void testReuseCanceledGestures(); void bug_13501_gesture_not_accepted(); +private: + QPoint m_availableTopLeft; }; void tst_Gestures::initTestCase() { + const QScreen *screen = QGuiApplication::primaryScreen(); + m_availableTopLeft = screen->availableGeometry().topLeft(); +} + +void tst_Gestures::cleanupTestCase() +{ +} + +void tst_Gestures::init() +{ CustomGesture::GestureType = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); QVERIFY(CustomGesture::GestureType != Qt::GestureType(0)); QVERIFY(CustomGesture::GestureType != Qt::CustomGesture); } -void tst_Gestures::cleanupTestCase() +void tst_Gestures::cleanup() { QGestureRecognizer::unregisterRecognizer(CustomGesture::GestureType); } @@ -571,6 +587,9 @@ void tst_Gestures::conflictingGestures() child->reset(); Qt::GestureType ContinuousGesture = QGestureRecognizer::registerRecognizer(new CustomContinuousGestureRecognizer); + auto unregisterRecognizer = qScopeGuard([ContinuousGesture]{ + QGestureRecognizer::unregisterRecognizer(ContinuousGesture); + }); static const int ContinuousGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1; child->grabGesture(ContinuousGesture); // child accepts override. And it also receives another custom gesture. @@ -580,11 +599,9 @@ void tst_Gestures::conflictingGestures() QCOMPARE(child->gestureOverrideEventsReceived, 1); QVERIFY(child->gestureEventsReceived > TotalGestureEventsCount); - QCOMPARE(child->events.all.count(), TotalGestureEventsCount + ContinuousGestureEventsCount); + QCOMPARE(child->events.all.size(), TotalGestureEventsCount + ContinuousGestureEventsCount); QCOMPARE(parent.gestureOverrideEventsReceived, 0); QCOMPARE(parent.gestureEventsReceived, 0); - - QGestureRecognizer::unregisterRecognizer(ContinuousGesture); } void tst_Gestures::finishedWithoutStarted() @@ -800,6 +817,7 @@ void tst_Gestures::graphicsItemGesture() QGraphicsScene scene; QGraphicsView view(&scene); view.setWindowFlags(Qt::X11BypassWindowManagerHint); + view.move(m_availableTopLeft); GestureItem *item = new GestureItem("item"); scene.addItem(item); @@ -862,6 +880,7 @@ void tst_Gestures::graphicsView() QGraphicsScene scene; QGraphicsView view(&scene); view.setWindowFlags(Qt::X11BypassWindowManagerHint); + view.move(m_availableTopLeft); GestureItem *item = new GestureItem("item"); scene.addItem(item); @@ -927,6 +946,7 @@ void tst_Gestures::graphicsItemTreeGesture() QGraphicsScene scene; QGraphicsView view(&scene); view.setWindowFlags(Qt::X11BypassWindowManagerHint); + view.move(m_availableTopLeft); GestureItem *item1 = new GestureItem("item1"); item1->setPos(100, 100); @@ -984,6 +1004,7 @@ void tst_Gestures::explicitGraphicsObjectTarget() QGraphicsScene scene; QGraphicsView view(&scene); view.setWindowFlags(Qt::X11BypassWindowManagerHint); + view.move(m_availableTopLeft); GestureItem *item1 = new GestureItem("item1"); scene.addItem(item1); @@ -1138,6 +1159,9 @@ void tst_Gestures::twoGesturesOnDifferentLevel() l->addWidget(child); Qt::GestureType SecondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + auto unregisterRecognizer = qScopeGuard([SecondGesture]{ + QGestureRecognizer::unregisterRecognizer(SecondGesture); + }); parent.grabGesture(CustomGesture::GestureType); child->grabGesture(SecondGesture); @@ -1164,8 +1188,6 @@ void tst_Gestures::twoGesturesOnDifferentLevel() QCOMPARE(parent.events.all.size(), TotalGestureEventsCount); for(int i = 0; i < child->events.all.size(); ++i) QCOMPARE(parent.events.all.at(i), CustomGesture::GestureType); - - QGestureRecognizer::unregisterRecognizer(SecondGesture); } void tst_Gestures::multipleGesturesInTree() @@ -1179,6 +1201,10 @@ void tst_Gestures::multipleGesturesInTree() Qt::GestureType FirstGesture = CustomGesture::GestureType; Qt::GestureType SecondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); Qt::GestureType ThirdGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + auto unregisterRecognizer = qScopeGuard([SecondGesture, ThirdGesture]{ + QGestureRecognizer::unregisterRecognizer(SecondGesture); + QGestureRecognizer::unregisterRecognizer(ThirdGesture); + }); Qt::GestureFlags flags = Qt::ReceivePartialGestures; A->grabGesture(FirstGesture, flags); // A [1 3] @@ -1235,9 +1261,6 @@ void tst_Gestures::multipleGesturesInTree() QCOMPARE(A->events.all.count(FirstGesture), TotalGestureEventsCount); QCOMPARE(A->events.all.count(SecondGesture), 0); QCOMPARE(A->events.all.count(ThirdGesture), TotalGestureEventsCount); - - QGestureRecognizer::unregisterRecognizer(SecondGesture); - QGestureRecognizer::unregisterRecognizer(ThirdGesture); } void tst_Gestures::multipleGesturesInComplexTree() @@ -1255,6 +1278,14 @@ void tst_Gestures::multipleGesturesInComplexTree() Qt::GestureType FifthGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); Qt::GestureType SixthGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); Qt::GestureType SeventhGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + auto unregisterRecognizer = qScopeGuard([=]{ + QGestureRecognizer::unregisterRecognizer(SecondGesture); + QGestureRecognizer::unregisterRecognizer(ThirdGesture); + QGestureRecognizer::unregisterRecognizer(FourthGesture); + QGestureRecognizer::unregisterRecognizer(FifthGesture); + QGestureRecognizer::unregisterRecognizer(SixthGesture); + QGestureRecognizer::unregisterRecognizer(SeventhGesture); + }); Qt::GestureFlags flags = Qt::ReceivePartialGestures; A->grabGesture(FirstGesture, flags); // A [1,3,4] @@ -1332,13 +1363,6 @@ void tst_Gestures::multipleGesturesInComplexTree() QCOMPARE(A->events.all.count(FifthGesture), 0); QCOMPARE(A->events.all.count(SixthGesture), 0); QCOMPARE(A->events.all.count(SeventhGesture), 0); - - QGestureRecognizer::unregisterRecognizer(SecondGesture); - QGestureRecognizer::unregisterRecognizer(ThirdGesture); - QGestureRecognizer::unregisterRecognizer(FourthGesture); - QGestureRecognizer::unregisterRecognizer(FifthGesture); - QGestureRecognizer::unregisterRecognizer(SixthGesture); - QGestureRecognizer::unregisterRecognizer(SeventhGesture); } void tst_Gestures::testMapToScene() @@ -1401,13 +1425,13 @@ void tst_Gestures::ungrabGesture() // a method on QWidget // sending an event will cause the QGesture objects to be instantiated for the widgets sendCustomGesture(&event, b); - QCOMPARE(a->gestures.count(), 1); + QCOMPARE(a->gestures.size(), 1); QPointer<QGesture> customGestureA; customGestureA = *(a->gestures.begin()); QVERIFY(!customGestureA.isNull()); QCOMPARE(customGestureA->gestureType(), CustomGesture::GestureType); - QCOMPARE(b->gestures.count(), 1); + QCOMPARE(b->gestures.size(), 1); QPointer<QGesture> customGestureB; customGestureB = *(b->gestures.begin()); QVERIFY(!customGestureB.isNull()); @@ -1418,7 +1442,7 @@ void tst_Gestures::ungrabGesture() // a method on QWidget // sending an event will cause the QGesture objects to be instantiated for the widget sendCustomGesture(&event, a); - QCOMPARE(a->gestures.count(), 1); + QCOMPARE(a->gestures.size(), 1); customGestureA = *(a->gestures.begin()); QVERIFY(!customGestureA.isNull()); QCOMPARE(customGestureA->gestureType(), CustomGesture::GestureType); @@ -1463,7 +1487,7 @@ void tst_Gestures::autoCancelGestures() { if (event->type() == QEvent::Gesture) { QGestureEvent *ge = static_cast<QGestureEvent*>(event); - if (ge->gestures().count() != 1) + if (ge->gestures().size() != 1) ++badGestureEvents; // event should contain exactly one gesture ge->gestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext); } @@ -1474,6 +1498,9 @@ void tst_Gestures::autoCancelGestures() }; const Qt::GestureType secondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + auto unregisterRecognizer = qScopeGuard([secondGesture]{ + QGestureRecognizer::unregisterRecognizer(secondGesture); + }); MockWidget parent("parent"); // this one sets the cancel policy to CancelAllInContext parent.resize(300, 100); @@ -1496,15 +1523,15 @@ void tst_Gestures::autoCancelGestures() CustomEvent event; event.serial = CustomGesture::SerialStartedThreshold; QApplication::sendEvent(child, &event); - QCOMPARE(child->events.all.count(), 2); - QCOMPARE(child->events.started.count(), 1); - QCOMPARE(child->events.canceled.count(), 1); - QCOMPARE(parent.events.all.count(), 1); + QCOMPARE(child->events.all.size(), 2); + QCOMPARE(child->events.started.size(), 1); + QCOMPARE(child->events.canceled.size(), 1); + QCOMPARE(parent.events.all.size(), 1); // clean up, make the parent gesture finish event.serial = CustomGesture::SerialFinishedThreshold; QApplication::sendEvent(child, &event); - QCOMPARE(parent.events.all.count(), 2); + QCOMPARE(parent.events.all.size(), 2); QCOMPARE(parent.badGestureEvents, 0); } @@ -1518,7 +1545,7 @@ void tst_Gestures::autoCancelGestures2() { if (event->type() == QEvent::Gesture) { QGestureEvent *ge = static_cast<QGestureEvent*>(event); - if (ge->gestures().count() != 1) + if (ge->gestures().size() != 1) ++badGestureEvents; // event should contain exactly one gesture ge->gestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext); } @@ -1529,10 +1556,14 @@ void tst_Gestures::autoCancelGestures2() }; const Qt::GestureType secondGesture = QGestureRecognizer ::registerRecognizer(new CustomGestureRecognizer); + auto unregisterRecognizer = qScopeGuard([secondGesture]{ + QGestureRecognizer::unregisterRecognizer(secondGesture); + }); QGraphicsScene scene; QGraphicsView view(&scene); view.setWindowFlags(Qt::X11BypassWindowManagerHint); + view.move(m_availableTopLeft); MockItem *parent = new MockItem("parent"); GestureItem *child = new GestureItem("child"); @@ -1552,15 +1583,15 @@ void tst_Gestures::autoCancelGestures2() event.hasHotSpot = true; event.hotSpot = mapToGlobal(QPointF(5, 5), child, &view); scene.sendEvent(child, &event); - QCOMPARE(parent->events.all.count(), 1); - QCOMPARE(child->events.started.count(), 1); - QCOMPARE(child->events.canceled.count(), 1); - QCOMPARE(child->events.all.count(), 2); + QCOMPARE(parent->events.all.size(), 1); + QCOMPARE(child->events.started.size(), 1); + QCOMPARE(child->events.canceled.size(), 1); + QCOMPARE(child->events.all.size(), 2); // clean up, make the parent gesture finish event.serial = CustomGesture::SerialFinishedThreshold; scene.sendEvent(child, &event); - QCOMPARE(parent->events.all.count(), 2); + QCOMPARE(parent->events.all.size(), 2); QCOMPARE(parent->badGestureEvents, 0); } @@ -1569,6 +1600,7 @@ void tst_Gestures::graphicsViewParentPropagation() QGraphicsScene scene; QGraphicsView view(&scene); view.setWindowFlags(Qt::X11BypassWindowManagerHint); + view.move(m_availableTopLeft); GestureItem *item0 = new GestureItem("item0"); scene.addItem(item0); @@ -1629,6 +1661,7 @@ void tst_Gestures::panelPropagation() QGraphicsScene scene; QGraphicsView view(&scene); view.setWindowFlags(Qt::X11BypassWindowManagerHint); + view.move(m_availableTopLeft); GestureItem *item0 = new GestureItem("item0"); scene.addItem(item0); @@ -1753,6 +1786,7 @@ void tst_Gestures::panelStacksBehindParent() QGraphicsScene scene; QGraphicsView view(&scene); view.setWindowFlags(Qt::X11BypassWindowManagerHint); + view.move(m_availableTopLeft); GestureItem *item1 = new GestureItem("item1"); item1->grabGesture(CustomGesture::GestureType); @@ -1940,6 +1974,7 @@ void tst_Gestures::partialGesturePropagation() QGraphicsScene scene; QGraphicsView view(&scene); view.setWindowFlags(Qt::X11BypassWindowManagerHint); + view.move(m_availableTopLeft); GestureItem *item1 = new GestureItem("item1"); item1->grabGesture(CustomGesture::GestureType); @@ -2030,10 +2065,14 @@ void tst_Gestures::testQGestureRecognizerCleanup() // Mimic QGestureManager: register both default and "platform" recognizers // (this is done in windows when QT_NO_NATIVE_GESTURES is not defined) PanRecognizer *def = new PanRecognizer(PanRecognizer::Default); - QGestureRecognizer::registerRecognizer(def); + auto defRecognizer = QGestureRecognizer::registerRecognizer(def); PanRecognizer *plt = new PanRecognizer(PanRecognizer::Platform); - QGestureRecognizer::registerRecognizer(plt); + auto pltRecognizer = QGestureRecognizer::registerRecognizer(plt); qDebug () << "register: default =" << def << "; platform =" << plt; + auto unregisterRecognizer = qScopeGuard([defRecognizer, pltRecognizer]{ + QGestureRecognizer::unregisterRecognizer(defRecognizer); + QGestureRecognizer::unregisterRecognizer(pltRecognizer); + }); // ^-- Qt singleton QGManager initialization @@ -2147,11 +2186,16 @@ void tst_Gestures::testReuseCanceledGestures() new ReuseCanceledGesturesRecognizer(ReuseCanceledGesturesRecognizer::RmbAndCancelAllType)); Qt::GestureType tapGestureTypeId = QGestureRecognizer::registerRecognizer( new ReuseCanceledGesturesRecognizer(ReuseCanceledGesturesRecognizer::LmbType)); + auto unregisterRecognizer = qScopeGuard([=]{ + QGestureRecognizer::unregisterRecognizer(cancellingGestureTypeId); + QGestureRecognizer::unregisterRecognizer(tapGestureTypeId); + }); QMainWindow mw; mw.setWindowFlags(Qt::X11BypassWindowManagerHint); QGraphicsView *gv = new QGraphicsView(&mw); QGraphicsScene *scene = new QGraphicsScene; + mw.move(m_availableTopLeft); gv->setScene(scene); scene->setSceneRect(0,0,100,100); diff --git a/tests/auto/other/networkselftest/tst_networkselftest.cpp b/tests/auto/other/networkselftest/tst_networkselftest.cpp index 824f26aeaa..16b7d33097 100644 --- a/tests/auto/other/networkselftest/tst_networkselftest.cpp +++ b/tests/auto/other/networkselftest/tst_networkselftest.cpp @@ -105,8 +105,8 @@ static QString prettyByteArray(const QByteArray &array) { // any control chars? QString result; - result.reserve(array.length() + array.length() / 3); - for (int i = 0; i < array.length(); ++i) { + result.reserve(array.size() + array.size() / 3); + for (int i = 0; i < array.size(); ++i) { char c = array.at(i); switch (c) { case '\n': @@ -208,11 +208,11 @@ static void netChat(int port, const QList<Chat> &chat) switch (it->type) { case Chat::Expect: { qDebug() << i << "Expecting" << prettyByteArray(it->data); - if (!doSocketRead(&socket, it->data.length(), 3 * defaultReadTimeoutMS)) - QFAIL(msgDoSocketReadFailed(serverName, port, i, it->data.length())); + if (!doSocketRead(&socket, it->data.size(), 3 * defaultReadTimeoutMS)) + QFAIL(msgDoSocketReadFailed(serverName, port, i, it->data.size())); // pop that many bytes off the socket - QByteArray received = socket.read(it->data.length()); + QByteArray received = socket.read(it->data.size()); // is it what we expected? QVERIFY2(received == it->data, @@ -226,8 +226,8 @@ static void netChat(int port, const QList<Chat> &chat) qDebug() << i << "Discarding until" << prettyByteArray(it->data); while (true) { // scan the buffer until we have our string - if (!doSocketRead(&socket, it->data.length())) - QFAIL(msgDoSocketReadFailed(serverName, port, i, it->data.length())); + if (!doSocketRead(&socket, it->data.size())) + QFAIL(msgDoSocketReadFailed(serverName, port, i, it->data.size())); QByteArray buffer; buffer.resize(socket.bytesAvailable()); @@ -239,7 +239,7 @@ static void netChat(int port, const QList<Chat> &chat) continue; } - buffer = socket.read(pos + it->data.length()); + buffer = socket.read(pos + it->data.size()); qDebug() << i << "Discarded" << prettyByteArray(buffer); break; } diff --git a/tests/auto/other/qaccessibility/accessiblewidgets.h b/tests/auto/other/qaccessibility/accessiblewidgets.h index 2e93f24fd3..b0382ef60a 100644 --- a/tests/auto/other/qaccessibility/accessiblewidgets.h +++ b/tests/auto/other/qaccessibility/accessiblewidgets.h @@ -116,7 +116,7 @@ public: int cursorPosition() const override { return textWidget()->cursorPosition; } void setCursorPosition(int position) override { textWidget()->cursorPosition = position; } QString text(int startOffset, int endOffset) const override { return textWidget()->text.mid(startOffset, endOffset); } - int characterCount() const override { return textWidget()->text.length(); } + int characterCount() const override { return textWidget()->text.size(); } QRect characterRect(int) const override { return QRect(); } int offsetAtPoint(const QPoint &) const override { return 0; } void scrollToSubstring(int, int) override {} diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index 89ef57e29b..60a8dde623 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -163,6 +163,7 @@ public slots: void cleanup(); private slots: void eventTest(); + void eventWithChildTest(); void customWidget(); void deletedWidget(); void subclassedWidget(); @@ -210,6 +211,7 @@ private slots: void treeTest(); void tableTest(); + void uniqueIdTest(); void calendarWidgetTest(); void dockWidgetTest(); void comboBoxTest(); @@ -292,9 +294,9 @@ void tst_QAccessibility::cleanup() { const EventList list = QTestAccessibility::events(); if (!list.isEmpty()) { - qWarning("%zd accessibility event(s) were not handled in testfunction '%s':", size_t(list.count()), + qWarning("%zd accessibility event(s) were not handled in testfunction '%s':", size_t(list.size()), QString(QTest::currentTestFunction()).toLatin1().constData()); - for (int i = 0; i < list.count(); ++i) + for (int i = 0; i < list.size(); ++i) qWarning(" %d: Object: %p Event: '%s' Child: %d", i + 1, list.at(i)->object(), qAccessibleEventString(list.at(i)->type()), list.at(i)->child()); } @@ -353,6 +355,33 @@ void tst_QAccessibility::eventTest() QTestAccessibility::clearEvents(); } +void tst_QAccessibility::eventWithChildTest() +{ + // make sure that QAccessibleEvent created using either of the two QAccessibleEvent + // behaves the same when the same underlying QObject is used + QWidget widget; + QWidget childWidget(&widget); + + // QAccessibleEvent constructor called with the QObject* + QAccessibleEvent event1(&widget, QAccessible::Focus); + + // QAccessibleEvent constructor called with the QAccessibleInterface* for the same QObject* + QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(&widget); + QAccessibleEvent event2(iface, QAccessible::Focus); + + QVERIFY(event1.accessibleInterface() != nullptr); + QVERIFY(event2.accessibleInterface() != nullptr); + QCOMPARE(event1.accessibleInterface(), event2.accessibleInterface()); + + // set same child for both + event1.setChild(0); + event2.setChild(0); + + QVERIFY(event1.accessibleInterface() != nullptr); + QVERIFY(event2.accessibleInterface() != nullptr); + QCOMPARE(event1.accessibleInterface(), event2.accessibleInterface()); +} + void tst_QAccessibility::customWidget() { { @@ -753,7 +782,7 @@ void tst_QAccessibility::textAttributes() QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(&textEdit); QAccessibleTextInterface *textInterface=interface->textInterface(); QVERIFY(textInterface); - QCOMPARE(textInterface->characterCount(), textEdit.toPlainText().length()); + QCOMPARE(textInterface->characterCount(), textEdit.toPlainText().size()); int startOffset = -1; int endOffset = -1; @@ -1915,7 +1944,7 @@ void tst_QAccessibility::mdiAreaTest() mdiArea.addSubWindow(new QWidget, Qt::Dialog)->show(); QList<QMdiSubWindow *> subWindows = mdiArea.subWindowList(); - QCOMPARE(subWindows.count(), subWindowCount); + QCOMPARE(subWindows.size(), subWindowCount); QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(&mdiArea); QVERIFY(interface); @@ -1953,7 +1982,7 @@ void tst_QAccessibility::mdiSubWindowTest() } QList<QMdiSubWindow *> subWindows = mdiArea.subWindowList(); - QCOMPARE(subWindows.count(), subWindowCount); + QCOMPARE(subWindows.size(), subWindowCount); QMdiSubWindow *testWindow = subWindows.at(3); QVERIFY(testWindow); @@ -2077,10 +2106,10 @@ void tst_QAccessibility::lineEditTest() QCOMPARE(iface->text(QAccessible::Value), QString()); le->setEchoMode(QLineEdit::Password); QVERIFY(iface->state().passwordEdit); - QCOMPARE(iface->text(QAccessible::Value), QString(secret.length(), QLatin1Char('*'))); + QCOMPARE(iface->text(QAccessible::Value), QString(secret.size(), QLatin1Char('*'))); le->setEchoMode(QLineEdit::PasswordEchoOnEdit); QVERIFY(iface->state().passwordEdit); - QCOMPARE(iface->text(QAccessible::Value), QString(secret.length(), QLatin1Char('*'))); + QCOMPARE(iface->text(QAccessible::Value), QString(secret.size(), QLatin1Char('*'))); le->setEchoMode(QLineEdit::Normal); QVERIFY(!(iface->state().passwordEdit)); QCOMPARE(iface->text(QAccessible::Value), secret); @@ -2172,7 +2201,7 @@ void tst_QAccessibility::lineEditTest() QCOMPARE(textIface->textAtOffset(5, QAccessible::ParagraphBoundary,&start,&end), cite); QCOMPARE(start, 0); - QCOMPARE(end, cite.length()); + QCOMPARE(end, cite.size()); QCOMPARE(textIface->textAtOffset(5, QAccessible::LineBoundary,&start,&end), cite); QCOMPARE(textIface->textAtOffset(5, QAccessible::NoBoundary,&start,&end), cite); @@ -2216,8 +2245,8 @@ void tst_QAccessibility::lineEditTest() QVERIFY_EVENT(&sel); lineEdit->selectAll(); - sel.setSelection(0, lineEdit->text().length()); - sel.setCursorPosition(lineEdit->text().length()); + sel.setSelection(0, lineEdit->text().size()); + sel.setCursorPosition(lineEdit->text().size()); QVERIFY_EVENT(&sel); lineEdit->setSelection(10, -4); @@ -2573,7 +2602,7 @@ void tst_QAccessibility::dialogButtonBoxTest() std::sort(buttons.begin(), buttons.end(), accessibleInterfaceLeftOf); - for (int i = 0; i < buttons.count(); ++i) + for (int i = 0; i < buttons.size(); ++i) actualOrder << buttons.at(i)->text(QAccessible::Name); QStringList expectedOrder; @@ -2625,7 +2654,7 @@ void tst_QAccessibility::dialogButtonBoxTest() std::sort(buttons.begin(), buttons.end(), accessibleInterfaceAbove); - for (int i = 0; i < buttons.count(); ++i) + for (int i = 0; i < buttons.size(); ++i) actualOrder << buttons.at(i)->text(QAccessible::Name); QStringList expectedOrder; @@ -3357,6 +3386,25 @@ void tst_QAccessibility::tableTest() QTestAccessibility::clearEvents(); } +void tst_QAccessibility::uniqueIdTest() +{ + // Test that an ID isn't reassigned to another interface right away when an accessible interface + // that has just been created is removed from the cache and deleted before the next + // accessible interface is registered. + // For example for AT-SPI, that would result in the same object path being used, and thus + // data from the old and new interface can get confused due to caching. + QWidget widget1; + QAccessibleInterface *iface1 = QAccessible::queryAccessibleInterface(&widget1); + QAccessible::Id id1 = QAccessible::uniqueId(iface1); + QAccessible::deleteAccessibleInterface(id1); + + QWidget widget2; + QAccessibleInterface *iface2 = QAccessible::queryAccessibleInterface(&widget2); + QAccessible::Id id2 = QAccessible::uniqueId(iface2); + + QVERIFY(id1 != id2); +} + void tst_QAccessibility::calendarWidgetTest() { #if QT_CONFIG(calendarwidget) @@ -3668,7 +3716,7 @@ void tst_QAccessibility::labelTest() QCOMPARE(acc_label->state().readOnly, true); QList<QPair<QAccessibleInterface *, QAccessible::Relation>> rels = acc_label->relations(); - QCOMPARE(rels.count(), 1); + QCOMPARE(rels.size(), 1); QAccessibleInterface *iface = rels.first().first; QAccessible::Relation rel = rels.first().second; @@ -4125,7 +4173,7 @@ void tst_QAccessibility::focusChild() spy.clear(); tableView->setCurrentCell(2, 1); - QTRY_COMPARE(spy.count(), 1); + QTRY_COMPARE(spy.size(), 1); QAccessibleInterface *child = iface->focusChild(); QVERIFY(child); @@ -4133,7 +4181,7 @@ void tst_QAccessibility::focusChild() spy.clear(); tableView->setCurrentCell(1, 2); - QTRY_COMPARE(spy.count(), 1); + QTRY_COMPARE(spy.size(), 1); child = iface->focusChild(); QVERIFY(child); @@ -4185,7 +4233,7 @@ void tst_QAccessibility::focusChild() spy.clear(); treeView->setCurrentItem(item2); - QTRY_COMPARE(spy.count(), 1); + QTRY_COMPARE(spy.size(), 1); QAccessibleInterface *child = iface->focusChild(); QVERIFY(child); @@ -4193,12 +4241,53 @@ void tst_QAccessibility::focusChild() spy.clear(); treeView->setCurrentItem(item3); - QTRY_COMPARE(spy.count(), 1); + QTRY_COMPARE(spy.size(), 1); child = iface->focusChild(); QVERIFY(child); QCOMPARE(child->text(QAccessible::Name), QStringLiteral("Klimt")); } + { + QWidget window; + // takes the initial focus + QLineEdit lineEdit; + QComboBox comboBox; + comboBox.addItems({"One", "Two", "Three"}); + QComboBox editableComboBox; + editableComboBox.setEditable(true); + editableComboBox.addItems({"A", "B", "C"}); + QVBoxLayout vbox; + vbox.addWidget(&lineEdit); + vbox.addWidget(&comboBox); + vbox.addWidget(&editableComboBox); + window.setLayout(&vbox); + + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QTestAccessibility::clearEvents(); + QAccessibleInterface *iface = nullptr; + + comboBox.setFocus(); + { + QAccessibleEvent focusEvent(&comboBox, QAccessible::Focus); + QVERIFY(QTestAccessibility::containsEvent(&focusEvent)); + } + iface = QAccessible::queryAccessibleInterface(&comboBox); + QVERIFY(iface); + QCOMPARE(iface->focusChild(), nullptr); + + editableComboBox.setFocus(); + // Qt updates about the editable combobox, not the lineedit, as the + // combobox is the lineedit's focus proxy. + { + QAccessibleEvent focusEvent(&editableComboBox, QAccessible::Focus); + QVERIFY(QTestAccessibility::containsEvent(&focusEvent)); + } + iface = QAccessible::queryAccessibleInterface(&editableComboBox); + QVERIFY(iface); + QVERIFY(iface->focusChild()); + QCOMPARE(iface->focusChild()->role(), QAccessible::EditableText); + } } void tst_QAccessibility::messageBoxTest_data() @@ -4288,20 +4377,10 @@ void tst_QAccessibility::messageBoxTest() if (!boxPrivate->canBeNativeDialog()) { // platforms that use a native message box will not emit accessibility events box.show(); - QVERIFY(QTest::qWaitForWindowActive(&box)); QAccessibleEvent showEvent(&box, QAccessible::DialogStart); QVERIFY(QTestAccessibility::containsEvent(&showEvent)); - // on some platforms, like macOS, not all widgets get key board focus; we - // only care about a push button getting focus - if (QTest::qWaitFor([&box]{ return qobject_cast<QPushButton *>(box.focusWidget()); }, 1000)) { - // a widget that gets focus through window activation should not emit an accessibility - // notification - QAccessibleEvent focusEvent(box.focusWidget(), QAccessible::Focus); - QVERIFY(!QTestAccessibility::containsEvent(&focusEvent)); - } - box.hide(); QAccessibleEvent hideEvent(&box, QAccessible::DialogEnd); diff --git a/tests/auto/other/qaccessibilitymac/CMakeLists.txt b/tests/auto/other/qaccessibilitymac/CMakeLists.txt index 6dd30a6fa1..03762f1fcd 100644 --- a/tests/auto/other/qaccessibilitymac/CMakeLists.txt +++ b/tests/auto/other/qaccessibilitymac/CMakeLists.txt @@ -1,32 +1,14 @@ -# Generated from qaccessibilitymac.pro. if(NOT APPLE) return() endif() -##################################################################### -## tst_qaccessibilitymac Test: -##################################################################### - qt_internal_add_test(tst_qaccessibilitymac SOURCES - tst_qaccessibilitymac.cpp - tst_qaccessibilitymac_helpers.h + tst_qaccessibilitymac.mm PUBLIC_LIBRARIES Qt::Gui Qt::Widgets -) - -#### Keys ignored in scope 1:.:.:qaccessibilitymac.pro:<TRUE>: -# _REQUIREMENTS = "mac" - -## Scopes: -##################################################################### - -qt_internal_extend_target(tst_qaccessibilitymac CONDITION APPLE - SOURCES - tst_qaccessibilitymac_helpers.mm - PUBLIC_LIBRARIES ${FWAppKit} ${FWApplicationServices} ${FWSecurity} diff --git a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.cpp b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.cpp deleted file mode 100644 index 2141869f16..0000000000 --- a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.cpp +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#include <QApplication> -#include <QtWidgets> -#include <QTest> -#include <QtCore/qcoreapplication.h> - -#include "tst_qaccessibilitymac_helpers.h" - -QT_USE_NAMESPACE - - -class AccessibleTestWindow : public QWidget -{ - Q_OBJECT -public: - AccessibleTestWindow() - { - new QHBoxLayout(this); - } - - void addWidget(QWidget* widget) - { - layout()->addWidget(widget); - widget->show(); - QVERIFY(QTest::qWaitForWindowExposed(widget)); - } - - void clearChildren() - { - qDeleteAll(children()); - new QHBoxLayout(this); - } -}; - -class tst_QAccessibilityMac : public QObject -{ -Q_OBJECT -private slots: - void init(); - void cleanup(); - - void singleWidgetTest(); - void lineEditTest(); - void hierarchyTest(); - void notificationsTest(); - void checkBoxTest(); - -private: - AccessibleTestWindow *m_window; -}; - - -void tst_QAccessibilityMac::init() -{ - m_window = new AccessibleTestWindow(); - m_window->setWindowTitle("Test window"); - m_window->show(); - m_window->resize(400, 400); - - QVERIFY(QTest::qWaitForWindowExposed(m_window)); -} - -void tst_QAccessibilityMac::cleanup() -{ - delete m_window; -} - -void tst_QAccessibilityMac::singleWidgetTest() -{ - delete m_window; - m_window = 0; - - QVERIFY(singleWidget()); -} - -void tst_QAccessibilityMac::lineEditTest() -{ - QLineEdit *lineEdit = new QLineEdit(m_window); - lineEdit->setText("a11y test QLineEdit"); - m_window->addWidget(lineEdit); - QVERIFY(QTest::qWaitForWindowExposed(m_window)); - QCoreApplication::processEvents(); - - QVERIFY(testLineEdit()); -} - -void tst_QAccessibilityMac::hierarchyTest() -{ - QWidget *w = new QWidget(m_window); - m_window->addWidget(w); - - w->setLayout(new QVBoxLayout()); - QPushButton *b = new QPushButton(w); - w->layout()->addWidget(b); - b->setText("I am a button"); - - QPushButton *b2 = new QPushButton(w); - w->layout()->addWidget(b2); - b2->setText("Button 2"); - - QVERIFY(QTest::qWaitForWindowExposed(m_window)); - QCoreApplication::processEvents(); - QVERIFY(testHierarchy(w)); -} - -void tst_QAccessibilityMac::notificationsTest() -{ - QVERIFY(notifications(m_window)); -} - -void tst_QAccessibilityMac::checkBoxTest() -{ - QCheckBox *cb = new QCheckBox(m_window); - cb->setText("Great option"); - m_window->addWidget(cb); - QVERIFY(QTest::qWaitForWindowExposed(m_window)); - QCoreApplication::processEvents(); - - QVERIFY(testCheckBox(cb)); -} - -QTEST_MAIN(tst_QAccessibilityMac) -#include "tst_qaccessibilitymac.moc" diff --git a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.mm index ceac828eed..39ffe504c7 100644 --- a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm +++ b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.mm @@ -1,10 +1,14 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +#include <QApplication> +#include <QtWidgets> +#include <QTest> +#include <QtCore/qcoreapplication.h> + // some versions of CALayer.h use 'slots' as an identifier #define QT_NO_KEYWORDS -#include "tst_qaccessibilitymac_helpers.h" #include <QtWidgets/qapplication.h> #include <QtWidgets/qlineedit.h> #include <QtWidgets/qpushbutton.h> @@ -55,14 +59,6 @@ QDebug operator<<(QDebug dbg, AXErrorTag err) return dbg; } -#define EXPECT(cond) \ - if (!(cond)) { \ - qWarning("Failure in %s, line: %d", __FILE__ , __LINE__); \ - return false; \ - } \ - -#define TRY_EXPECT(cond) EXPECT(QTest::qWaitFor([&]{ return (cond); })) - @interface TestAXObject : NSObject { AXUIElementRef reference; @@ -341,66 +337,138 @@ QDebug operator<<(QDebug dbg, AXErrorTag err) @end +QVector<int> notificationList; + +void observerCallback(AXObserverRef /*observer*/, AXUIElementRef /*element*/, CFStringRef notification, void *) +{ + if ([(NSString*)notification isEqualToString: NSAccessibilityFocusedUIElementChangedNotification]) + notificationList.append(QAccessible::Focus); + else if ([(NSString*)notification isEqualToString: NSAccessibilityValueChangedNotification]) + notificationList.append(QAccessible::ValueChanged); + else + notificationList.append(-1); +} + +class AccessibleTestWindow : public QWidget +{ + Q_OBJECT +public: + AccessibleTestWindow() + { + new QHBoxLayout(this); + } + + void addWidget(QWidget* widget) + { + layout()->addWidget(widget); + widget->show(); + QVERIFY(QTest::qWaitForWindowExposed(widget)); + } + + void clearChildren() + { + qDeleteAll(children()); + new QHBoxLayout(this); + } +}; + +class tst_QAccessibilityMac : public QObject +{ +Q_OBJECT +private Q_SLOTS: + void init(); + void cleanup(); + + void singleWidgetTest(); + void lineEditTest(); + void hierarchyTest(); + void notificationsTest(); + void checkBoxTest(); + +private: + AccessibleTestWindow *m_window; +}; + + +void tst_QAccessibilityMac::init() +{ + m_window = new AccessibleTestWindow(); + m_window->setWindowTitle("Test window"); + m_window->show(); + m_window->resize(400, 400); + + QVERIFY(QTest::qWaitForWindowExposed(m_window)); +} -bool singleWidget() +void tst_QAccessibilityMac::cleanup() { + delete m_window; +} + +void tst_QAccessibilityMac::singleWidgetTest() +{ + delete m_window; + m_window = 0; + QLineEdit *le = new QLineEdit(); le->setText("button"); le->show(); - EXPECT(QTest::qWaitForWindowExposed(le)); + QVERIFY(QTest::qWaitForWindowExposed(le)); QCoreApplication::processEvents(); TestAXObject *appObject = [TestAXObject getApplicationAXObject]; - EXPECT(appObject); + QVERIFY(appObject); - NSArray *windows = [appObject windowList]; - EXPECT([windows count] == 1); + QTRY_VERIFY(appObject.windowList.count == 1); - AXUIElementRef windowRef = (AXUIElementRef) [windows objectAtIndex: 0]; - EXPECT(windowRef != nil); + AXUIElementRef windowRef = (AXUIElementRef) [appObject.windowList objectAtIndex: 0]; + QVERIFY(windowRef != nil); TestAXObject *window = [[TestAXObject alloc] initWithAXUIElementRef: windowRef]; AXUIElementRef lineEditRef = [window findDirectChildByRole: kAXTextFieldRole]; - EXPECT(lineEditRef != nil); + QVERIFY(lineEditRef != nil); TestAXObject *lineEdit = [[TestAXObject alloc] initWithAXUIElementRef: lineEditRef]; - EXPECT([[lineEdit value] isEqualToString:@"button"]); + QVERIFY([[lineEdit value] isEqualToString:@"button"]); // Access invalid reference, should return empty value delete le; QCoreApplication::processEvents(); TestAXObject *lineEditInvalid = [[TestAXObject alloc] initWithAXUIElementRef: lineEditRef]; - EXPECT([[lineEditInvalid value] length] == 0); - - return true; + QVERIFY([[lineEditInvalid value] length] == 0); } -bool testLineEdit() +void tst_QAccessibilityMac::lineEditTest() { + QLineEdit *lineEdit = new QLineEdit(m_window); + lineEdit->setText("a11y test QLineEdit"); + m_window->addWidget(lineEdit); + QVERIFY(QTest::qWaitForWindowExposed(m_window)); + QCoreApplication::processEvents(); + TestAXObject *appObject = [TestAXObject getApplicationAXObject]; - EXPECT(appObject); + QVERIFY(appObject); - NSArray *windowList = [appObject windowList]; // one window - EXPECT([windowList count] == 1); - AXUIElementRef windowRef = (AXUIElementRef) [windowList objectAtIndex: 0]; - EXPECT(windowRef != nil); + QTRY_VERIFY(appObject.windowList.count == 1); + AXUIElementRef windowRef = (AXUIElementRef) [appObject.windowList objectAtIndex: 0]; + QVERIFY(windowRef != nil); TestAXObject *window = [[TestAXObject alloc] initWithAXUIElementRef: windowRef]; - EXPECT([window rect].size.width == 400); + QVERIFY([window rect].size.width == 400); // height of window includes title bar - EXPECT([window rect].size.height >= 400); + QVERIFY([window rect].size.height >= 400); - EXPECT([window.title isEqualToString:@"Test window"]); + QVERIFY([window.title isEqualToString:@"Test window"]); // children of window: - AXUIElementRef lineEdit = [window findDirectChildByRole: kAXTextFieldRole]; - EXPECT(lineEdit != nil); + AXUIElementRef lineEditElement = [window findDirectChildByRole: kAXTextFieldRole]; + QVERIFY(lineEditElement != nil); - TestAXObject *le = [[TestAXObject alloc] initWithAXUIElementRef: lineEdit]; + TestAXObject *le = [[TestAXObject alloc] initWithAXUIElementRef: lineEditElement]; NSString *value = @"a11y test QLineEdit"; - EXPECT([le.value isEqualToString:value]); - EXPECT(value.length <= NSIntegerMax); - EXPECT(le.numberOfCharacters == static_cast<NSInteger>(value.length)); + QVERIFY([le.value isEqualToString:value]); + QVERIFY(value.length <= NSIntegerMax); + QVERIFY(le.numberOfCharacters == static_cast<NSInteger>(value.length)); const NSRange ranges[] = { { 0, 0}, { 0, 1}, @@ -415,82 +483,81 @@ bool testLineEdit() NSString *expectedSubstring = [value substringWithRange:range]; NSString *actualSubstring = [le stringForRange:range]; NSString *actualAttributedSubstring = [le attributedStringForRange:range].string; - EXPECT([actualSubstring isEqualTo:expectedSubstring]); - EXPECT([actualAttributedSubstring isEqualTo:expectedSubstring]); + QVERIFY([actualSubstring isEqualTo:expectedSubstring]); + QVERIFY([actualAttributedSubstring isEqualTo:expectedSubstring]); } - return true; } -bool testHierarchy(QWidget *w) +void tst_QAccessibilityMac::hierarchyTest() { + QWidget *w = new QWidget(m_window); + m_window->addWidget(w); + + w->setLayout(new QVBoxLayout()); + QPushButton *b = new QPushButton(w); + w->layout()->addWidget(b); + b->setText("I am a button"); + + QPushButton *b2 = new QPushButton(w); + w->layout()->addWidget(b2); + b2->setText("Button 2"); + + QVERIFY(QTest::qWaitForWindowExposed(m_window)); + QCoreApplication::processEvents(); + TestAXObject *appObject = [TestAXObject getApplicationAXObject]; - EXPECT(appObject); + QVERIFY(appObject); - NSArray *windowList = [appObject windowList]; // one window - EXPECT([windowList count] == 1); - AXUIElementRef windowRef = (AXUIElementRef) [windowList objectAtIndex: 0]; - EXPECT(windowRef != nil); + QTRY_VERIFY(appObject.windowList.count == 1); + AXUIElementRef windowRef = (AXUIElementRef) [appObject.windowList objectAtIndex: 0]; + QVERIFY(windowRef != nil); TestAXObject *window = [[TestAXObject alloc] initWithAXUIElementRef: windowRef]; // Because the plain widget is filtered out of the hierarchy, we expect the button // to be a direct child of the window AXUIElementRef buttonRef = [window findDirectChildByRole: kAXButtonRole]; - EXPECT(buttonRef != nil); + QVERIFY(buttonRef != nil); TestAXObject *buttonObject = [[TestAXObject alloc] initWithAXUIElementRef: buttonRef]; TestAXObject *parentObject = [[TestAXObject alloc] initWithAXUIElementRef: [buttonObject parent]]; // check that the parent is a window - EXPECT([[parentObject role] isEqualToString: NSAccessibilityWindowRole]); + QVERIFY([[parentObject role] isEqualToString: NSAccessibilityWindowRole]); // test the focus // child 0 is the layout, then button1 and 2 QPushButton *button1 = qobject_cast<QPushButton*>(w->children().at(1)); - EXPECT(button1); + QVERIFY(button1); QPushButton *button2 = qobject_cast<QPushButton*>(w->children().at(2)); - EXPECT(button2); + QVERIFY(button2); button2->setFocus(); AXUIElementRef systemWideElement = AXUIElementCreateSystemWide(); AXUIElementRef focussedElement = NULL; AXError error = AXUIElementCopyAttributeValue(systemWideElement, (CFStringRef)NSAccessibilityFocusedUIElementAttribute, (CFTypeRef*)&focussedElement); - EXPECT(!error); - EXPECT(focussedElement); + QVERIFY(!error); + QVERIFY(focussedElement); TestAXObject *focusButton2 = [[TestAXObject alloc] initWithAXUIElementRef: focussedElement]; - EXPECT([[focusButton2 role] isEqualToString: NSAccessibilityButtonRole]); - EXPECT([[focusButton2 title] isEqualToString: @"Button 2"]); + QVERIFY([[focusButton2 role] isEqualToString: NSAccessibilityButtonRole]); + QVERIFY([[focusButton2 title] isEqualToString: @"Button 2"]); button1->setFocus(); error = AXUIElementCopyAttributeValue(systemWideElement, (CFStringRef)NSAccessibilityFocusedUIElementAttribute, (CFTypeRef*)&focussedElement); - EXPECT(!error); - EXPECT(focussedElement); + QVERIFY(!error); + QVERIFY(focussedElement); TestAXObject *focusButton1 = [[TestAXObject alloc] initWithAXUIElementRef: focussedElement]; - EXPECT([[focusButton1 role] isEqualToString: NSAccessibilityButtonRole]); - EXPECT([[focusButton1 title] isEqualToString: @"I am a button"]); - - return true; -} - -QVector<int> notificationList; - -void observerCallback(AXObserverRef /*observer*/, AXUIElementRef /*element*/, CFStringRef notification, void *) -{ - if ([(NSString*)notification isEqualToString: NSAccessibilityFocusedUIElementChangedNotification]) - notificationList.append(QAccessible::Focus); - else if ([(NSString*)notification isEqualToString: NSAccessibilityValueChangedNotification]) - notificationList.append(QAccessible::ValueChanged); - else - notificationList.append(-1); + QVERIFY([[focusButton1 role] isEqualToString: NSAccessibilityButtonRole]); + QVERIFY([[focusButton1 title] isEqualToString: @"I am a button"]); } - -bool notifications(QWidget *w) +void tst_QAccessibilityMac::notificationsTest() { + auto *w = m_window; QLineEdit *le1 = new QLineEdit(w); QLineEdit *le2 = new QLineEdit(w); w->layout()->addWidget(le1); @@ -500,76 +567,79 @@ bool notifications(QWidget *w) QTest::qWait(100); TestAXObject *appObject = [TestAXObject getApplicationAXObject]; - EXPECT(appObject); + QVERIFY(appObject); - NSArray *windowList = [appObject windowList]; // one window - EXPECT([windowList count] == 1); - AXUIElementRef windowRef = (AXUIElementRef) [windowList objectAtIndex: 0]; - EXPECT(windowRef != nil); + QTRY_VERIFY(appObject.windowList.count == 1); + AXUIElementRef windowRef = (AXUIElementRef) [appObject.windowList objectAtIndex: 0]; + QVERIFY(windowRef != nil); TestAXObject *window = [[TestAXObject alloc] initWithAXUIElementRef: windowRef]; AXUIElementRef lineEdit1 = [window findDirectChildByRole: kAXTextFieldRole]; - EXPECT(lineEdit1 != nil); + QVERIFY(lineEdit1 != nil); AXObserverRef observer = 0; AXError err = AXObserverCreate(getpid(), observerCallback, &observer); - EXPECT(!err); + QVERIFY(!err); AXObserverAddNotification(observer, appObject.ref, kAXFocusedUIElementChangedNotification, 0); AXObserverAddNotification(observer, lineEdit1, kAXValueChangedNotification, 0); CFRunLoopAddSource( [[NSRunLoop currentRunLoop] getCFRunLoop], AXObserverGetRunLoopSource(observer), kCFRunLoopDefaultMode); - EXPECT(notificationList.length() == 0); + QVERIFY(notificationList.length() == 0); le2->setFocus(); - TRY_EXPECT(notificationList.length() == 1); - TRY_EXPECT(notificationList.at(0) == QAccessible::Focus); + QTRY_VERIFY(notificationList.length() == 1); + QTRY_VERIFY(notificationList.at(0) == QAccessible::Focus); le1->setFocus(); - TRY_EXPECT(notificationList.length() == 2); - TRY_EXPECT(notificationList.at(1) == QAccessible::Focus); + QTRY_VERIFY(notificationList.length() == 2); + QTRY_VERIFY(notificationList.at(1) == QAccessible::Focus); le1->setText("hello"); - TRY_EXPECT(notificationList.length() == 3); - TRY_EXPECT(notificationList.at(2) == QAccessible::ValueChanged); + QTRY_VERIFY(notificationList.length() == 3); + QTRY_VERIFY(notificationList.at(2) == QAccessible::ValueChanged); le1->setText("foo"); - TRY_EXPECT(notificationList.length() == 4); - TRY_EXPECT(notificationList.at(3) == QAccessible::ValueChanged); - - return true; + QTRY_VERIFY(notificationList.length() == 4); + QTRY_VERIFY(notificationList.at(3) == QAccessible::ValueChanged); } -bool testCheckBox(QCheckBox *ckBox) +void tst_QAccessibilityMac::checkBoxTest() { + QCheckBox *ckBox = new QCheckBox(m_window); + ckBox->setText("Great option"); + m_window->addWidget(ckBox); + QVERIFY(QTest::qWaitForWindowExposed(m_window)); + QCoreApplication::processEvents(); + TestAXObject *appObject = [TestAXObject getApplicationAXObject]; - EXPECT(appObject); + QVERIFY(appObject); - NSArray *windowList = [appObject windowList]; // one window - EXPECT([windowList count] == 1); - AXUIElementRef windowRef = (AXUIElementRef) [windowList objectAtIndex: 0]; - EXPECT(windowRef != nil); + QTRY_VERIFY(appObject.windowList.count == 1); + AXUIElementRef windowRef = (AXUIElementRef) [appObject.windowList objectAtIndex: 0]; + QVERIFY(windowRef != nil); TestAXObject *window = [[TestAXObject alloc] initWithAXUIElementRef: windowRef]; // children of window: AXUIElementRef checkBox = [window findDirectChildByRole: kAXCheckBoxRole]; - EXPECT(checkBox != nil); + QVERIFY(checkBox != nil); TestAXObject *cb = [[TestAXObject alloc] initWithAXUIElementRef: checkBox]; // here start actual checkbox tests - EXPECT([cb valueNumber] == 0); - EXPECT([cb.title isEqualToString:@"Great option"]); + QVERIFY([cb valueNumber] == 0); + QVERIFY([cb.title isEqualToString:@"Great option"]); // EXPECT(cb.description == nil); // currently returns "" instead of nil - EXPECT([cb.actions containsObject:(NSString*)kAXPressAction]); + QVERIFY([cb.actions containsObject:(NSString*)kAXPressAction]); [cb performAction:kAXPressAction]; - EXPECT([cb valueNumber] == 1); + QVERIFY([cb valueNumber] == 1); [cb performAction:kAXPressAction]; - EXPECT([cb valueNumber] == 0); + QVERIFY([cb valueNumber] == 0); ckBox->setCheckState(Qt::PartiallyChecked); - EXPECT([cb valueNumber] == 2); - - return true; + QVERIFY([cb valueNumber] == 2); } + +QTEST_MAIN(tst_QAccessibilityMac) +#include "tst_qaccessibilitymac.moc" diff --git a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.h b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.h deleted file mode 100644 index 003aa90dfd..0000000000 --- a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.h +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -#include <QtCore/QString> -#include <QtCore/QPair> -#include <QtWidgets/QWidget> -#include <QtWidgets/QCheckBox> - -#pragma once // Yeah, it's deprecated in general, but it's standard practice for Mac OS X. - -QT_USE_NAMESPACE - -bool testLineEdit(); -bool testHierarchy(QWidget *w); -bool singleWidget(); -bool notifications(QWidget *w); -bool testCheckBox(QCheckBox *ckBox); diff --git a/tests/auto/other/qcomplextext/tst_qcomplextext.cpp b/tests/auto/other/qcomplextext/tst_qcomplextext.cpp index 1b944bf1b6..a164851886 100644 --- a/tests/auto/other/qcomplextext/tst_qcomplextext.cpp +++ b/tests/auto/other/qcomplextext/tst_qcomplextext.cpp @@ -84,7 +84,7 @@ void tst_QComplexText::bidiReorderString() if (si.analysis.bidiLevel % 2) { // reverse sub QChar *a = sub.data(); - QChar *b = a + sub.length() - 1; + QChar *b = a + sub.size() - 1; while (a < b) { QChar tmp = *a; *a = *b; @@ -93,7 +93,7 @@ void tst_QComplexText::bidiReorderString() --b; } a = (QChar *)sub.unicode(); - b = a + sub.length(); + b = a + sub.size(); while (a<b) { *a = a->mirroredChar(); ++a; @@ -315,7 +315,7 @@ static void testBidiString(const QString &data, int paragraphDirection, if (si.analysis.bidiLevel % 2) { // reverse sub QChar *a = sub.data(); - QChar *b = a + sub.length() - 1; + QChar *b = a + sub.size() - 1; while (a < b) { QChar tmp = *a; *a = *b; @@ -324,7 +324,7 @@ static void testBidiString(const QString &data, int paragraphDirection, --b; } a = (QChar *)sub.unicode(); - b = a + sub.length(); + b = a + sub.size(); // while (a<b) { // *a = a->mirroredChar(); // ++a; diff --git a/tests/auto/other/qfocusevent/tst_qfocusevent.cpp b/tests/auto/other/qfocusevent/tst_qfocusevent.cpp index 0d34b8dfea..d265326e6d 100644 --- a/tests/auto/other/qfocusevent/tst_qfocusevent.cpp +++ b/tests/auto/other/qfocusevent/tst_qfocusevent.cpp @@ -332,9 +332,10 @@ void tst_QFocusEvent::checkReason_ActiveWindow() d->hide(); if (!QGuiApplication::platformName().compare(QLatin1String("offscreen"), Qt::CaseInsensitive) - || !QGuiApplication::platformName().compare(QLatin1String("minimal"), Qt::CaseInsensitive)) { + || !QGuiApplication::platformName().compare(QLatin1String("minimal"), Qt::CaseInsensitive) + || !QGuiApplication::platformName().compare(QLatin1String("cocoa"), Qt::CaseInsensitive)) { // Activate window of testFocusWidget, focus in that window goes to childFocusWidgetOne - qWarning("Platforms offscreen and minimal require explicit activateWindow()"); + qWarning("Platforms offscreen, minimal and macOS require explicit activateWindow()"); testFocusWidget->activateWindow(); } diff --git a/tests/auto/other/qprocess_and_guieventloop/tst_qprocess_and_guieventloop.cpp b/tests/auto/other/qprocess_and_guieventloop/tst_qprocess_and_guieventloop.cpp index e70d132ea7..3541576bb8 100644 --- a/tests/auto/other/qprocess_and_guieventloop/tst_qprocess_and_guieventloop.cpp +++ b/tests/auto/other/qprocess_and_guieventloop/tst_qprocess_and_guieventloop.cpp @@ -35,20 +35,20 @@ void tst_QProcess_and_GuiEventLoop::waitForAndEventLoop() qApp->processEvents(QEventLoop::AllEvents, 100); // we mustn't have read anything in the event loop - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); // ensure the process hasn't died QVERIFY(!process.waitForFinished(250)); // we mustn't have read anything during waitForFinished either - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); // release the child for the second write process.write("\n"); QVERIFY(process.waitForFinished(5000)); QCOMPARE(int(process.exitStatus()), int(QProcess::NormalExit)); QCOMPARE(process.exitCode(), 0); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCOMPARE(process.readAll().trimmed(), msg); #endif } |