diff options
Diffstat (limited to 'tests/auto/other')
68 files changed, 1797 insertions, 1806 deletions
diff --git a/tests/auto/other/CMakeLists.txt b/tests/auto/other/CMakeLists.txt index 8255406bb5..16f96cd5f4 100644 --- a/tests/auto/other/CMakeLists.txt +++ b/tests/auto/other/CMakeLists.txt @@ -1,14 +1,15 @@ -# Generated from other.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause if(NOT CMAKE_CROSSCOMPILING) - # add_subdirectory(atwrapper) <- does not exist # special case + # add_subdirectory(atwrapper) <- does not exist endif() if(TARGET Qt::Widgets) add_subdirectory(gestures) add_subdirectory(languagechange) add_subdirectory(qfocusevent) add_subdirectory(qsharedpointer_and_qwidget) - # add_subdirectory(windowsmobile) <- does not exist # special case + # add_subdirectory(windowsmobile) <- does not exist endif() if(TARGET Qt::Network AND TARGET Qt::Widgets) add_subdirectory(qnetworkaccessmanager_and_qprogressdialog) @@ -21,8 +22,7 @@ endif() if(TARGET Qt::Network) add_subdirectory(networkselftest) endif() -# QTBUG-87674 # special case -if(QT_FEATURE_accessibility AND TARGET Qt::Gui AND TARGET Qt::Widgets AND NOT ANDROID) +if(QT_FEATURE_accessibility AND TARGET Qt::Gui AND TARGET Qt::Widgets) add_subdirectory(qaccessibility) endif() if(TARGET Qt::Gui) @@ -30,15 +30,15 @@ if(TARGET Qt::Gui) endif() add_subdirectory(qobjectrace) add_subdirectory(toolsupport) -# QTBUG-87670 # special case +# QTBUG-87670 if(QT_FEATURE_process AND TARGET Qt::Gui AND NOT ANDROID) add_subdirectory(qprocess_and_guieventloop) endif() if(QT_FEATURE_accessibility_atspi_bridge AND TARGET Qt::Gui AND TARGET Qt::Widgets) - #add_subdirectory(qaccessibilitylinux) # special case # This test is broken + #add_subdirectory(qaccessibilitylinux) # TODO: This test is broken endif() if(MACOS AND TARGET Qt::Gui) - # add_subdirectory(macnativeevents) # special case it's disabled in qmake too + # add_subdirectory(macnativeevents) # TODO: it's disabled in qmake too endif() if(embedded) add_subdirectory(qdirectpainter) @@ -46,3 +46,7 @@ endif() if(QT_FEATURE_xkbcommon AND TARGET Qt::Gui) add_subdirectory(xkbkeyboard) endif() + +if(ANDROID AND QT_BUILD_STANDALONE_TESTS) + add_subdirectory(android_deployment_settings) +endif() 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 3a00d9414b..0000000000 --- a/tests/auto/other/android/tst_android.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#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/android_deployment_settings/CMakeLists.txt b/tests/auto/other/android_deployment_settings/CMakeLists.txt new file mode 100644 index 0000000000..f2ba135328 --- /dev/null +++ b/tests/auto/other/android_deployment_settings/CMakeLists.txt @@ -0,0 +1,85 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_android_deployment_settings LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +function(tst_generate_android_deployment_setting target) + # Qt build always use new property format that supports generator expressions. In this test we + # want to test user scenario so disable all Qt specific options to make sure that + # qt6_android_generate_deployment_settings behave like in user projects. + set(QT_BUILD_STANDALONE_TESTS FALSE) + set(QT_BUILDING_QT FALSE) + set(QT_INTERNAL_IS_STANDALONE_TEST FALSE) + + qt6_android_generate_deployment_settings(${target}) +endfunction() + +qt6_policy(SET QTP0002 NEW) + +set(target tst_android_deployment_settings_new) +qt6_add_executable(${target} MANUAL_FINALIZATION EXCLUDE_FROM_ALL noop.cpp) +set_target_properties(${target} PROPERTIES + my_package_source_dir "path/to/source/dir" + my_libs_property "some/path/to/lib2.so;some/path/to/lib3.so" + my_plugins_property "some/path/to/plugin2.so;some/path/to/plugin3.so" + + QT_ANDROID_SDK_BUILD_TOOLS_REVISION "23.0.2" + QT_ANDROID_MIN_SDK_VERSION "1" + QT_ANDROID_TARGET_SDK_VERSION "2" + QT_ANDROID_DEPLOYMENT_DEPENDENCIES "dep1.so;dep2.so;dep3.so" + QT_ANDROID_DEPLOYMENT_SETTINGS_FILE "attempt_to_rewrite.json" + QT_ANDROID_EXTRA_LIBS + "some/path/to/lib1.so;$<TARGET_PROPERTY:${target},my_libs_property>;some/path/to/lib4.so" + QT_ANDROID_EXTRA_PLUGINS + "some/path/to/plugin1.so;$<TARGET_PROPERTY:${target},my_plugins_property>" + QT_ANDROID_PACKAGE_SOURCE_DIR "$<TARGET_PROPERTY:${target},my_package_source_dir>" + QT_ANDROID_SYSTEM_LIBS_PREFIX "myLibPrefix" + + # Make sure that this property is overwritten by + # qt6_android_generate_deployment_settings + QT_ANDROID_DEPLOYMENT_SETTINGS_FILE "custom_deployment_settings.json" +) +tst_generate_android_deployment_setting(${target}) + +qt6_policy(SET QTP0002 OLD) + +set(target tst_android_deployment_settings_old) +qt6_add_executable(${target} MANUAL_FINALIZATION EXCLUDE_FROM_ALL noop.cpp) +set_target_properties(${target} PROPERTIES + QT_ANDROID_SDK_BUILD_TOOLS_REVISION "23.0.2" + QT_ANDROID_MIN_SDK_VERSION "1" + QT_ANDROID_TARGET_SDK_VERSION "2" + QT_ANDROID_DEPLOYMENT_DEPENDENCIES "dep1.so;dep2.so;dep3.so" + QT_ANDROID_EXTRA_LIBS + "some/path/to/lib1.so;some/path\\to/lib2.so;some\\path\\to\\lib3.so;some/path/to/lib4.so" + QT_ANDROID_EXTRA_PLUGINS + "some\\path\\to\\plugin1.so;some/path\\to/plugin2.so;some/path/to/plugin3.so" + QT_ANDROID_PACKAGE_SOURCE_DIR "path\\to/source\\dir" + QT_ANDROID_SYSTEM_LIBS_PREFIX "myLibPrefix" +) +tst_generate_android_deployment_setting(${target}) + +get_target_property(new_settings + tst_android_deployment_settings_new QT_ANDROID_DEPLOYMENT_SETTINGS_FILE) +get_target_property(old_settings + tst_android_deployment_settings_old QT_ANDROID_DEPLOYMENT_SETTINGS_FILE) +set_source_files_properties("${new_settings}" PROPERTIES QT_RESOURCE_ALIAS "new_settings.json") +set_source_files_properties("${old_settings}" PROPERTIES QT_RESOURCE_ALIAS "old_settings.json") +qt_internal_add_test(tst_android_deployment_settings + SOURCES + tst_android_deployment_settings.cpp + DEFINES + DEFAULT_ABI="${CMAKE_ANDROID_ARCH_ABI}" +) +qt6_add_resources(tst_android_deployment_settings + "deployment_settings_res" + PREFIX + "/" + FILES + "${new_settings}" + "${old_settings}" +) diff --git a/tests/auto/other/android_deployment_settings/noop.cpp b/tests/auto/other/android_deployment_settings/noop.cpp new file mode 100644 index 0000000000..6f2ee31826 --- /dev/null +++ b/tests/auto/other/android_deployment_settings/noop.cpp @@ -0,0 +1,7 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +int main(int, char *[]) +{ + return 0; +} diff --git a/tests/auto/other/android_deployment_settings/tst_android_deployment_settings.cpp b/tests/auto/other/android_deployment_settings/tst_android_deployment_settings.cpp new file mode 100644 index 0000000000..d68d08b58e --- /dev/null +++ b/tests/auto/other/android_deployment_settings/tst_android_deployment_settings.cpp @@ -0,0 +1,112 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QJsonDocument> +#include <QJsonObject> +#include <QFile> +#include <QTest> +#include <QLibraryInfo> +#include <QDir> + +class tst_android_deployment_settings : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase_data(); + void init(); + + void DeploymentSettings_data(); + void DeploymentSettings(); + + void QtPaths_data(); + void QtPaths(); + +private: + static QString makePath(QLibraryInfo::LibraryLocation loc); + QJsonDocument jsonDoc; +}; + +QString tst_android_deployment_settings::makePath(QLibraryInfo::LibraryLocation loc) +{ + const auto prefix = QLibraryInfo::path(QLibraryInfo::PrefixPath); + auto path = QLibraryInfo::path(loc); + path.remove(0, prefix.size() + 1); + if (path.isEmpty()) // Assume that if path is empty it's '.' + path = "."; + return path; +} + +void tst_android_deployment_settings::initTestCase_data() +{ + QTest::addColumn<QString>("file"); + QTest::newRow("old") << ":/old_settings.json"; + QTest::newRow("new") << ":/new_settings.json"; +} + +void tst_android_deployment_settings::init() +{ + QFETCH_GLOBAL(QString, file); + QFile settings(file); + QVERIFY(settings.open(QIODeviceBase::ReadOnly)); + jsonDoc = QJsonDocument::fromJson(settings.readAll()); + QVERIFY(!jsonDoc.isNull()); +} + +void tst_android_deployment_settings::DeploymentSettings_data() +{ + QTest::addColumn<QString>("key"); + QTest::addColumn<QString>("value"); + + QTest::newRow("sdkBuildToolsRevision") << "sdkBuildToolsRevision" + << "23.0.2"; + QTest::newRow("deployment-dependencies") << "deployment-dependencies" + << "dep1.so,dep2.so,dep3.so"; + QTest::newRow("android-extra-plugins") + << "android-extra-plugins" + << "some/path/to/plugin1.so,some/path/to/plugin2.so,some/path/to/plugin3.so"; + QTest::newRow("android-extra-libs") << "android-extra-libs" + << "some/path/to/lib1.so,some/path/to/lib2.so,some/path/to/" + "lib3.so,some/path/to/lib4.so"; + QTest::newRow("android-system-libs-prefix") << "android-system-libs-prefix" + << "myLibPrefix"; + QTest::newRow("android-package-source-directory") << "android-package-source-directory" + << "path/to/source/dir"; + QTest::newRow("android-min-sdk-version") << "android-min-sdk-version" + << "1"; + QTest::newRow("android-target-sdk-version") << "android-target-sdk-version" + << "2"; +} + +void tst_android_deployment_settings::DeploymentSettings() +{ + QFETCH(QString, key); + QFETCH(QString, value); + QCOMPARE(jsonDoc[key].toString(), value); +} + +void tst_android_deployment_settings::QtPaths_data() +{ + QTest::addColumn<QString>("key"); + QTest::addColumn<QString>("value"); + + QTest::newRow("qtDataDirectory") << "qtDataDirectory" << makePath(QLibraryInfo::DataPath); + QTest::newRow("qtLibExecsDirectory") + << "qtLibExecsDirectory" << makePath(QLibraryInfo::LibraryExecutablesPath); + QTest::newRow("qtLibsDirectory") << "qtLibsDirectory" << makePath(QLibraryInfo::LibrariesPath); + QTest::newRow("qtPluginsDirectory") + << "qtPluginsDirectory" << makePath(QLibraryInfo::PluginsPath); + QTest::newRow("qtQmlDirectory") << "qtQmlDirectory" << makePath(QLibraryInfo::QmlImportsPath); +} + +void tst_android_deployment_settings::QtPaths() +{ + QFETCH(QString, key); + QFETCH(QString, value); + QCOMPARE(QDir::cleanPath(jsonDoc[key].toObject()[DEFAULT_ABI].toString()), + QDir::cleanPath(value)); +} + +QTEST_MAIN(tst_android_deployment_settings) + +#include "tst_android_deployment_settings.moc" diff --git a/tests/auto/other/gestures/BLACKLIST b/tests/auto/other/gestures/BLACKLIST index 5b4f12b80d..8e96992e4d 100644 --- a/tests/auto/other/gestures/BLACKLIST +++ b/tests/auto/other/gestures/BLACKLIST @@ -1,32 +1,4 @@ -[] -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 -ubuntu-20.04 -rhel -centos -[autoCancelGestures2] -ubuntu-18.04 -ubuntu-20.04 -rhel -centos +[panelPropagation] +ubuntu-22.04 ci +[panelStacksBehindParent] +ubuntu-22.04 ci diff --git a/tests/auto/other/gestures/CMakeLists.txt b/tests/auto/other/gestures/CMakeLists.txt index e4ea953ee3..815846305a 100644 --- a/tests/auto/other/gestures/CMakeLists.txt +++ b/tests/auto/other/gestures/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from gestures.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_gestures Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_gestures LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_gestures SOURCES tst_gestures.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::Widgets ) diff --git a/tests/auto/other/gestures/tst_gestures.cpp b/tests/auto/other/gestures/tst_gestures.cpp index 48cd355554..a413268321 100644 --- a/tests/auto/other/gestures/tst_gestures.cpp +++ b/tests/auto/other/gestures/tst_gestures.cpp @@ -1,36 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtTest/qtesttouch.h> #include <qevent.h> +#include <QSet> #include <qpointingdevice.h> #include <qwidget.h> #include <qlayout.h> @@ -233,7 +208,7 @@ protected: QGestureEvent *e = static_cast<QGestureEvent*>(event); ++gestureEventsReceived; eventsPtr = &events; - foreach(Qt::GestureType type, ignoredGestures) + for (Qt::GestureType type : std::as_const(ignoredGestures)) e->ignore(e->gesture(type)); } else if (event->type() == QEvent::GestureOverride) { ++gestureOverrideEventsReceived; @@ -243,8 +218,8 @@ protected: } if (eventsPtr) { QGestureEvent *e = static_cast<QGestureEvent*>(event); - QList<QGesture*> gestures = e->gestures(); - foreach(QGesture *g, gestures) { + const QList<QGesture*> gestures = e->gestures(); + for (QGesture *g : gestures) { eventsPtr->all << g->gestureType(); switch(g->state()) { case Qt::GestureStarted: @@ -306,6 +281,10 @@ Q_OBJECT private slots: void initTestCase(); void cleanupTestCase(); + + void init(); + void cleanup(); + void customGesture(); void autoCancelingGestures(); void gestureOverChild(); @@ -342,35 +321,60 @@ 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); } +static QtMessageHandler originalMessageHandler = nullptr; +static bool skipCustomGesture = false; +static void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &text) +{ + if (type == QtMsgType::QtWarningMsg && text == "QGestureManager::deliverEvent: could not find the target for gesture") + skipCustomGesture = true; + originalMessageHandler(type, context, text); +} + void tst_Gestures::customGesture() { + originalMessageHandler = qInstallMessageHandler(messageHandler); + auto guard = qScopeGuard([](){ qInstallMessageHandler(originalMessageHandler); }); GestureWidget widget; widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); widget.show(); - QVERIFY(QTest::qWaitForWindowExposed(&widget)); + QVERIFY(QTest::qWaitForWindowActive(&widget)); CustomEvent event; event.hotSpot = widget.mapToGlobal(QPoint(5,5)); event.hasHotSpot = true; sendCustomGesture(&event, &widget); + if (skipCustomGesture) + QSKIP("QApplication unable to access test widget."); static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; static const int TotalCustomEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1; - QCOMPARE(widget.customEventsReceived, TotalCustomEventsCount); + QTRY_COMPARE(widget.customEventsReceived, TotalCustomEventsCount); QCOMPARE(widget.gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(widget.gestureOverrideEventsReceived, 0); QCOMPARE(widget.events.all.size(), TotalGestureEventsCount); @@ -430,7 +434,7 @@ void tst_Gestures::gestureOverChild() static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; static const int TotalCustomEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1; - QCOMPARE(child->customEventsReceived, TotalCustomEventsCount); + QTRY_COMPARE(child->customEventsReceived, TotalCustomEventsCount); QCOMPARE(widget.customEventsReceived, 0); QCOMPARE(child->gestureEventsReceived, 0); QCOMPARE(child->gestureOverrideEventsReceived, 0); @@ -445,7 +449,7 @@ void tst_Gestures::gestureOverChild() sendCustomGesture(&event, child); - QCOMPARE(child->customEventsReceived, TotalCustomEventsCount); + QTRY_COMPARE(child->customEventsReceived, TotalCustomEventsCount); QCOMPARE(widget.customEventsReceived, 0); QCOMPARE(child->gestureEventsReceived, 0); @@ -477,7 +481,7 @@ void tst_Gestures::multipleWidgetOnlyGestureInTree() CustomEvent event; sendCustomGesture(&event, child); - QCOMPARE(child->customEventsReceived, TotalCustomEventsCount); + QTRY_COMPARE(child->customEventsReceived, TotalCustomEventsCount); QCOMPARE(parent.customEventsReceived, 0); QCOMPARE(child->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(child->gestureOverrideEventsReceived, 0); @@ -490,8 +494,8 @@ void tst_Gestures::multipleWidgetOnlyGestureInTree() // same for the parent widget sendCustomGesture(&event, &parent); - QCOMPARE(child->customEventsReceived, 0); QCOMPARE(parent.customEventsReceived, TotalCustomEventsCount); + QCOMPARE(child->customEventsReceived, 0); QCOMPARE(child->gestureEventsReceived, 0); QCOMPARE(child->gestureOverrideEventsReceived, 0); QCOMPARE(parent.gestureEventsReceived, TotalGestureEventsCount); @@ -518,7 +522,7 @@ void tst_Gestures::conflictingGestures() CustomEvent event; sendCustomGesture(&event, child); - QCOMPARE(child->gestureOverrideEventsReceived, 1); + QTRY_COMPARE(child->gestureOverrideEventsReceived, 1); QCOMPARE(child->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(parent.gestureOverrideEventsReceived, 0); QCOMPARE(parent.gestureEventsReceived, 0); @@ -586,8 +590,8 @@ void tst_Gestures::conflictingGestures() // sending events to the child and making sure there is no conflict sendCustomGesture(&event, child); + QTRY_COMPARE(child->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(child->gestureOverrideEventsReceived, 1); - QCOMPARE(child->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(parent.gestureOverrideEventsReceived, 1); QCOMPARE(parent.gestureEventsReceived, TotalGestureEventsCount); @@ -595,6 +599,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. @@ -602,13 +609,11 @@ void tst_Gestures::conflictingGestures() child->acceptGestureOverride = true; sendCustomGesture(&event, child); + QTRY_VERIFY(child->gestureEventsReceived > TotalGestureEventsCount); 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() @@ -621,7 +626,7 @@ void tst_Gestures::finishedWithoutStarted() ev.serial = CustomGesture::SerialFinishedThreshold; QApplication::sendEvent(&widget, &ev); - QCOMPARE(widget.customEventsReceived, 1); + QTRY_COMPARE(widget.customEventsReceived, 1); QCOMPARE(widget.gestureEventsReceived, 2); QCOMPARE(widget.gestureOverrideEventsReceived, 0); QCOMPARE(widget.events.all.size(), 2); @@ -643,7 +648,7 @@ void tst_Gestures::unknownGesture() static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; - QCOMPARE(widget.gestureEventsReceived, TotalGestureEventsCount); + QTRY_COMPARE(widget.gestureEventsReceived, TotalGestureEventsCount); } static const QColor InstanceColors[] = { @@ -737,9 +742,10 @@ public: ++gestureEventsReceived; eventsPtr = &events; QGestureEvent *e = static_cast<QGestureEvent *>(event); - foreach(Qt::GestureType type, ignoredGestures) + for (Qt::GestureType type : std::as_const(ignoredGestures)) e->ignore(e->gesture(type)); - foreach(QGesture *g, e->gestures()) { + const auto gestures = e->gestures(); + for (QGesture *g : gestures) { switch (g->state()) { case Qt::GestureStarted: if (ignoredStartedGestures.contains(g->gestureType())) @@ -765,8 +771,8 @@ public: } if (eventsPtr) { QGestureEvent *e = static_cast<QGestureEvent*>(event); - QList<QGesture*> gestures = e->gestures(); - foreach(QGesture *g, gestures) { + const QList<QGesture*> gestures = e->gestures(); + for (QGesture *g : gestures) { eventsPtr->all << g->gestureType(); switch(g->state()) { case Qt::GestureStarted: @@ -824,6 +830,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); @@ -846,7 +853,7 @@ void tst_Gestures::graphicsItemGesture() QTest::ignoreMessage(QtWarningMsg, "QGestureManager::deliverEvent: could not find the target for gesture"); sendCustomGesture(&event, item, &scene); - QCOMPARE(item->customEventsReceived, TotalCustomEventsCount); + QTRY_COMPARE(item->customEventsReceived, TotalCustomEventsCount); QCOMPARE(item->gestureEventsReceived, 0); QCOMPARE(item->gestureOverrideEventsReceived, 0); @@ -886,6 +893,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); @@ -906,7 +914,7 @@ void tst_Gestures::graphicsView() event.hasHotSpot = true; sendCustomGesture(&event, item, &scene); - QCOMPARE(item->customEventsReceived, TotalCustomEventsCount); + QTRY_COMPARE(item->customEventsReceived, TotalCustomEventsCount); QCOMPARE(item->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(item->gestureOverrideEventsReceived, 0); @@ -941,8 +949,8 @@ void tst_Gestures::graphicsView() item->grabGesture(CustomGesture::GestureType); sendCustomGesture(&event, item, &newScene); + QTRY_COMPARE(item->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(item->customEventsReceived, TotalCustomEventsCount); - QCOMPARE(item->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(item->gestureOverrideEventsReceived, 0); } @@ -951,6 +959,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); @@ -981,12 +990,12 @@ void tst_Gestures::graphicsItemTreeGesture() item1->ignoredGestures << CustomGesture::GestureType; sendCustomGesture(&event, item1_child1, &scene); + QTRY_COMPARE(item1->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(item1_child1->gestureOverrideEventsReceived, 0); QCOMPARE(item1_child1->gestureEventsReceived, 0); QCOMPARE(item1_child2->gestureEventsReceived, 0); QCOMPARE(item1_child2->gestureOverrideEventsReceived, 0); QCOMPARE(item1->gestureOverrideEventsReceived, 0); - QCOMPARE(item1->gestureEventsReceived, TotalGestureEventsCount); item1->reset(); item1_child1->reset(); item1_child2->reset(); @@ -995,7 +1004,7 @@ void tst_Gestures::graphicsItemTreeGesture() item1->ignoredGestures << CustomGesture::GestureType; item1_child1->ignoredGestures << CustomGesture::GestureType; sendCustomGesture(&event, item1_child1, &scene); - QCOMPARE(item1_child1->gestureOverrideEventsReceived, 1); + QTRY_COMPARE(item1_child1->gestureOverrideEventsReceived, 1); QCOMPARE(item1_child1->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(item1_child2->gestureEventsReceived, 0); QCOMPARE(item1_child2->gestureOverrideEventsReceived, 0); @@ -1008,6 +1017,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); @@ -1041,9 +1051,9 @@ void tst_Gestures::explicitGraphicsObjectTarget() sendCustomGesture(&event, item1, &scene); - QCOMPARE(item1->gestureEventsReceived, 0); + QTRY_COMPARE(item2_child1->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(item1->gestureOverrideEventsReceived, 1); - QCOMPARE(item2_child1->gestureEventsReceived, TotalGestureEventsCount); + QCOMPARE(item1->gestureEventsReceived, 0); QCOMPARE(item2_child1->gestureOverrideEventsReceived, 1); QCOMPARE(item2_child1->events.all.size(), TotalGestureEventsCount); for(int i = 0; i < item2_child1->events.all.size(); ++i) @@ -1084,7 +1094,7 @@ void tst_Gestures::gestureOverChildGraphicsItem() item2_child1->setPos(0, 0); view.show(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); + QTRY_VERIFY(QTest::qWaitForWindowExposed(&view)); view.ensureVisible(scene.sceneRect()); item1->grabGesture(CustomGesture::GestureType); @@ -1097,7 +1107,7 @@ void tst_Gestures::gestureOverChildGraphicsItem() event.hasHotSpot = true; sendCustomGesture(&event, item0, &scene); - QCOMPARE(item0->customEventsReceived, TotalCustomEventsCount); + QTRY_COMPARE(item0->customEventsReceived, TotalCustomEventsCount); QCOMPARE(item2_child1->gestureEventsReceived, 0); QCOMPARE(item2_child1->gestureOverrideEventsReceived, 0); QCOMPARE(item2->gestureEventsReceived, 0); @@ -1113,11 +1123,11 @@ void tst_Gestures::gestureOverChildGraphicsItem() event.hasHotSpot = true; sendCustomGesture(&event, item0, &scene); - QCOMPARE(item2_child1->gestureEventsReceived, 0); - QCOMPARE(item2_child1->gestureOverrideEventsReceived, 0); + QTRY_COMPARE(item1->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(item2->gestureEventsReceived, 1); QCOMPARE(item2->gestureOverrideEventsReceived, 1); - QCOMPARE(item1->gestureEventsReceived, TotalGestureEventsCount); + QCOMPARE(item2_child1->gestureEventsReceived, 0); + QCOMPARE(item2_child1->gestureOverrideEventsReceived, 0); QCOMPARE(item1->gestureOverrideEventsReceived, 1); item0->reset(); item1->reset(); item2->reset(); item2_child1->reset(); @@ -1129,9 +1139,9 @@ void tst_Gestures::gestureOverChildGraphicsItem() event.hasHotSpot = true; sendCustomGesture(&event, item0, &scene); + QTRY_COMPARE(item2->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(item2_child1->gestureEventsReceived, 0); QCOMPARE(item2_child1->gestureOverrideEventsReceived, 0); - QCOMPARE(item2->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(item2->gestureOverrideEventsReceived, 1); QCOMPARE(item1->gestureEventsReceived, 1); QCOMPARE(item1->gestureOverrideEventsReceived, 1); @@ -1146,9 +1156,9 @@ void tst_Gestures::gestureOverChildGraphicsItem() event.hasHotSpot = true; sendCustomGesture(&event, item0, &scene); + QTRY_COMPARE(item2->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(item2_child1->gestureEventsReceived, 0); QCOMPARE(item2_child1->gestureOverrideEventsReceived, 0); - QCOMPARE(item2->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(item2->gestureOverrideEventsReceived, 1); QCOMPARE(item1->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(item1->gestureOverrideEventsReceived, 1); @@ -1162,6 +1172,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); @@ -1176,20 +1189,18 @@ void tst_Gestures::twoGesturesOnDifferentLevel() static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; static const int TotalCustomEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1; - QCOMPARE(child->customEventsReceived, TotalCustomEventsCount); + QTRY_COMPARE(child->customEventsReceived, TotalCustomEventsCount); QCOMPARE(child->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(child->gestureOverrideEventsReceived, 0); QCOMPARE(child->events.all.size(), TotalGestureEventsCount); for(int i = 0; i < child->events.all.size(); ++i) QCOMPARE(child->events.all.at(i), SecondGesture); + QCOMPARE(parent.events.all.size(), TotalGestureEventsCount); QCOMPARE(parent.gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(parent.gestureOverrideEventsReceived, 0); - 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() @@ -1203,6 +1214,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] @@ -1227,7 +1242,7 @@ void tst_Gestures::multipleGesturesInTree() static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; // gesture override events - QCOMPARE(D->overrideEvents.all.count(FirstGesture), 1); + QTRY_COMPARE(D->overrideEvents.all.count(FirstGesture), 1); QCOMPARE(D->overrideEvents.all.count(SecondGesture), 0); QCOMPARE(D->overrideEvents.all.count(ThirdGesture), 1); @@ -1259,9 +1274,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() @@ -1279,6 +1291,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] @@ -1308,7 +1328,7 @@ void tst_Gestures::multipleGesturesInComplexTree() static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; // gesture override events - QCOMPARE(D->overrideEvents.all.count(FirstGesture), 1); + QTRY_COMPARE(D->overrideEvents.all.count(FirstGesture), 1); QCOMPARE(D->overrideEvents.all.count(SecondGesture), 0); QCOMPARE(D->overrideEvents.all.count(ThirdGesture), 1); @@ -1356,13 +1376,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() @@ -1425,13 +1438,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); + QTRY_COMPARE(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()); @@ -1442,7 +1455,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); + QTRY_COMPARE(a->gestures.size(), 1); customGestureA = *(a->gestures.begin()); QVERIFY(!customGestureA.isNull()); QCOMPARE(customGestureA->gestureType(), CustomGesture::GestureType); @@ -1450,7 +1463,7 @@ void tst_Gestures::ungrabGesture() // a method on QWidget a->ungrabGesture(CustomGesture::GestureType); //We changed the deletion of Gestures to lazy during QT-4022, so we can't ensure the QGesture is deleted until now - QVERIFY(!customGestureB.isNull()); + QTRY_VERIFY(!customGestureB.isNull()); a->gestures.clear(); a->reset(); @@ -1487,7 +1500,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); } @@ -1498,6 +1511,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); @@ -1520,15 +1536,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); } @@ -1542,7 +1558,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); } @@ -1553,10 +1569,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"); @@ -1576,15 +1596,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); } @@ -1593,6 +1613,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); @@ -1638,7 +1659,7 @@ void tst_Gestures::graphicsViewParentPropagation() event.hasHotSpot = true; sendCustomGesture(&event, item0, &scene); - QCOMPARE(item1_c1_c1->gestureEventsReceived, TotalGestureEventsCount); + QTRY_COMPARE(item1_c1_c1->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(item1_c1_c1->gestureOverrideEventsReceived, 1); QCOMPARE(item1_c1->gestureEventsReceived, TotalGestureEventsCount-1); QCOMPARE(item1_c1->gestureOverrideEventsReceived, 1); @@ -1653,6 +1674,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); @@ -1710,11 +1732,11 @@ void tst_Gestures::panelPropagation() event.hasHotSpot = true; sendCustomGesture(&event, item1, &scene); + QCOMPARE(item1->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(item1_child1_child1->gestureEventsReceived, 0); QCOMPARE(item1_child1_child1->gestureOverrideEventsReceived, 0); QCOMPARE(item1_child1->gestureEventsReceived, 0); QCOMPARE(item1_child1->gestureOverrideEventsReceived, 0); - QCOMPARE(item1->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(item1->gestureOverrideEventsReceived, 1); QCOMPARE(item0->gestureEventsReceived, 0); QCOMPARE(item0->gestureOverrideEventsReceived, 1); @@ -1764,7 +1786,7 @@ void tst_Gestures::panelPropagation() QCOMPARE(item1_child1_child1->gestureEventsReceived, 0); QCOMPARE(item1_child1_child1->gestureOverrideEventsReceived, 0); - QCOMPARE(item1_child1->gestureEventsReceived, TotalGestureEventsCount); + QTRY_COMPARE(item1_child1->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(item1_child1->gestureOverrideEventsReceived, 0); QCOMPARE(item1->gestureEventsReceived, 0); QCOMPARE(item1->gestureOverrideEventsReceived, 0); @@ -1777,6 +1799,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); @@ -1956,7 +1979,7 @@ void tst_Gestures::viewportCoordinates() event.hotSpot = mapToGlobal(item1->boundingRect().center(), item1, &view); event.hasHotSpot = true; sendCustomGesture(&event, item1, &scene); - QVERIFY(item1->gestureEventsReceived != 0); + QTRY_VERIFY(item1->gestureEventsReceived != 0); } void tst_Gestures::partialGesturePropagation() @@ -1964,6 +1987,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); @@ -1998,13 +2022,14 @@ void tst_Gestures::partialGesturePropagation() static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; + QCOMPARE(item1->gestureEventsReceived, TotalGestureEventsCount); + QCOMPARE(item2->gestureEventsReceived, TotalGestureEventsCount-2); // except for started and finished + QCOMPARE(item1->gestureOverrideEventsReceived, 1); QCOMPARE(item2->gestureOverrideEventsReceived, 1); QCOMPARE(item3->gestureOverrideEventsReceived, 1); QCOMPARE(item4->gestureOverrideEventsReceived, 1); - QCOMPARE(item1->gestureEventsReceived, TotalGestureEventsCount); - QCOMPARE(item2->gestureEventsReceived, TotalGestureEventsCount-2); // except for started and finished QCOMPARE(item3->gestureEventsReceived, 0); QCOMPARE(item4->gestureEventsReceived, 0); } @@ -2054,10 +2079,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 @@ -2171,11 +2200,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); @@ -2278,8 +2312,8 @@ void tst_Gestures::conflictingGesturesInGraphicsView() event.hotSpot = mapToGlobal(item2->boundingRect().center(), item2, &view); event.hasHotSpot = true; sendCustomGesture(&event, item2, &scene); + QTRY_COMPARE(item2->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(item2->gestureOverrideEventsReceived, 1); - QCOMPARE(item2->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(item1->gestureOverrideEventsReceived, 1); QCOMPARE(item1->gestureEventsReceived, 0); @@ -2291,8 +2325,8 @@ void tst_Gestures::conflictingGesturesInGraphicsView() event.hotSpot = mapToGlobal(item2->boundingRect().center(), item2, &view); event.hasHotSpot = true; sendCustomGesture(&event, item2, &scene); - QCOMPARE(item2->gestureOverrideEventsReceived, 1); QCOMPARE(item2->gestureEventsReceived, TotalGestureEventsCount); + QCOMPARE(item2->gestureOverrideEventsReceived, 1); QCOMPARE(item1->gestureOverrideEventsReceived, 0); QCOMPARE(item1->gestureEventsReceived, 0); @@ -2304,11 +2338,11 @@ void tst_Gestures::conflictingGesturesInGraphicsView() event.hotSpot = mapToGlobal(item2->boundingRect().center(), item2, &view); event.hasHotSpot = true; sendCustomGesture(&event, item2, &scene); + QCOMPARE(item1->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(item2->gestureOverrideEventsReceived, 1); QCOMPARE(item2->gestureEventsReceived, 0); QCOMPARE(item1->gestureOverrideEventsReceived, 1); - QCOMPARE(item1->gestureEventsReceived, TotalGestureEventsCount); } class NoConsumeWidgetBug13501 :public QWidget diff --git a/tests/auto/other/languagechange/CMakeLists.txt b/tests/auto/other/languagechange/CMakeLists.txt index 0275ea05fd..07f3547d58 100644 --- a/tests/auto/other/languagechange/CMakeLists.txt +++ b/tests/auto/other/languagechange/CMakeLists.txt @@ -1,21 +1,22 @@ -# Generated from languagechange.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_languagechange Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_languagechange LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_languagechange SOURCES tst_languagechange.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate Qt::Widgets ) - -## Scopes: -##################################################################### - -#### Keys ignored in scope 2:.:.:languagechange.pro:WIN32: -# testcase.timeout = "1800" diff --git a/tests/auto/other/languagechange/tst_languagechange.cpp b/tests/auto/other/languagechange/tst_languagechange.cpp index 0c435a0cb1..8f99730a19 100644 --- a/tests/auto/other/languagechange/tst_languagechange.cpp +++ b/tests/auto/other/languagechange/tst_languagechange.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/other/macgui/BLACKLIST b/tests/auto/other/macgui/BLACKLIST index 05e529e519..a6dc56611b 100644 --- a/tests/auto/other/macgui/BLACKLIST +++ b/tests/auto/other/macgui/BLACKLIST @@ -1,5 +1,2 @@ -[nonModalOrder] -osx - [scrollbarPainting] macos diff --git a/tests/auto/other/macgui/CMakeLists.txt b/tests/auto/other/macgui/CMakeLists.txt index 348d7f1241..afa3f0b8df 100644 --- a/tests/auto/other/macgui/CMakeLists.txt +++ b/tests/auto/other/macgui/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from macgui.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_macgui LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() if(NOT APPLE) return() endif() -if(NOT TARGET Qt::Widgets) # special case +if(NOT TARGET Qt::Widgets) return() endif() @@ -15,18 +22,17 @@ qt_internal_add_test(tst_macgui SOURCES guitest.cpp guitest.h tst_macgui.cpp - PUBLIC_LIBRARIES + NO_PCH_SOURCES + guitest.cpp # undef QT_NO_FOREACH + LIBRARIES Qt::CorePrivate Qt::WidgetsPrivate ) -#### Keys ignored in scope 1:.:.:macgui.pro:<TRUE>: -# _REQUIREMENTS = "mac" "widgets" - ## Scopes: ##################################################################### qt_internal_extend_target(tst_macgui CONDITION MACOS - PUBLIC_LIBRARIES + LIBRARIES ${FWApplicationServices} ) diff --git a/tests/auto/other/macgui/guitest.cpp b/tests/auto/other/macgui/guitest.cpp index 2effce7393..fbae891065 100644 --- a/tests/auto/other/macgui/guitest.cpp +++ b/tests/auto/other/macgui/guitest.cpp @@ -1,31 +1,7 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only +#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses #include "guitest.h" #include <QDebug> diff --git a/tests/auto/other/macgui/guitest.h b/tests/auto/other/macgui/guitest.h index 74f4292a6b..80a2103fc9 100644 --- a/tests/auto/other/macgui/guitest.h +++ b/tests/auto/other/macgui/guitest.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef GUITEST_H #define GUITEST_H diff --git a/tests/auto/other/macgui/tst_macgui.cpp b/tests/auto/other/macgui/tst_macgui.cpp index 3b4e0e33cb..efcecef9ad 100644 --- a/tests/auto/other/macgui/tst_macgui.cpp +++ b/tests/auto/other/macgui/tst_macgui.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QApplication> @@ -151,40 +126,6 @@ void tst_MacGui::splashScreenModality() QVERIFY(!QTestEventLoop::instance().timeout()); } -class PrimaryWindowDialog : public QDialog -{ -Q_OBJECT -public: - PrimaryWindowDialog(); - QWidget *secondaryWindow; - QWidget *frontWidget; -public slots: - void showSecondaryWindow(); - void test(); -}; - -PrimaryWindowDialog::PrimaryWindowDialog() : QDialog(0) -{ - frontWidget = 0; - secondaryWindow = new ColorWidget(this); - secondaryWindow->setWindowFlags(Qt::Window); - secondaryWindow->resize(400, 400); - secondaryWindow->move(100, 100); - QTimer::singleShot(1000, this, SLOT(showSecondaryWindow())); - QTimer::singleShot(2000, this, SLOT(test())); - QTimer::singleShot(3000, this, SLOT(close())); -} - -void PrimaryWindowDialog::showSecondaryWindow() -{ - secondaryWindow->show(); -} - -void PrimaryWindowDialog::test() -{ - frontWidget = QApplication::widgetAt(secondaryWindow->mapToGlobal(QPoint(100, 100))); -} - /* Test that a non-modal child window of a modal dialog is shown in front of the dialog even if the dialog becomes modal after the child window @@ -193,11 +134,28 @@ void PrimaryWindowDialog::test() void tst_MacGui::nonModalOrder() { clearSequence(); - PrimaryWindowDialog primary; - primary.resize(400, 400); - primary.move(100, 100); - primary.exec(); - QCOMPARE(primary.frontWidget, primary.secondaryWindow); + + QDialog dialog; + dialog.resize(400, 400); + dialog.move(100, 100); + + ColorWidget child(&dialog); + // The child window needs to be a dialog, as only subclasses of NSPanel + // are allowed to override worksWhenModal, which is needed to mark the + // transient child as working within the modal session of the parent. + child.setWindowFlags(Qt::Window | Qt::Dialog); + child.resize(400, 400); + child.move(100, 100); + + QTimer::singleShot(0, [&]{ + QVERIFY(QTest::qWaitForWindowExposed(&dialog)); + child.show(); + QVERIFY(QTest::qWaitForWindowExposed(&child)); + QCOMPARE(QApplication::widgetAt(child.mapToGlobal(QPoint(100, 100))), &child); + dialog.close(); + }); + + dialog.exec(); } /* diff --git a/tests/auto/other/macnativeevents/CMakeLists.txt b/tests/auto/other/macnativeevents/CMakeLists.txt index dd049c245a..c44cf61920 100644 --- a/tests/auto/other/macnativeevents/CMakeLists.txt +++ b/tests/auto/other/macnativeevents/CMakeLists.txt @@ -1,4 +1,11 @@ -# Generated from macnativeevents.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_macnativeevents LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() if(NOT APPLE) return() @@ -15,13 +22,8 @@ qt_internal_add_test(tst_macnativeevents qnativeevents.cpp qnativeevents.h qnativeevents_mac.cpp tst_macnativeevents.cpp - DEFINES - QT_DISABLE_DEPRECATED_BEFORE=0 - PUBLIC_LIBRARIES + LIBRARIES ${FWAppKit} Qt::Gui Qt::Widgets ) - -#### Keys ignored in scope 1:.:.:macnativeevents.pro:<TRUE>: -# _REQUIREMENTS = "mac" diff --git a/tests/auto/other/macnativeevents/expectedeventlist.cpp b/tests/auto/other/macnativeevents/expectedeventlist.cpp index 52552342e4..a8c662ad93 100644 --- a/tests/auto/other/macnativeevents/expectedeventlist.cpp +++ b/tests/auto/other/macnativeevents/expectedeventlist.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "expectedeventlist.h" #include <QDebug> diff --git a/tests/auto/other/macnativeevents/expectedeventlist.h b/tests/auto/other/macnativeevents/expectedeventlist.h index a48581df21..f21b56c9b2 100644 --- a/tests/auto/other/macnativeevents/expectedeventlist.h +++ b/tests/auto/other/macnativeevents/expectedeventlist.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef EVENTFILTER #define EVENTFILTER diff --git a/tests/auto/other/macnativeevents/nativeeventlist.cpp b/tests/auto/other/macnativeevents/nativeeventlist.cpp index b2956fa94e..6216c9682f 100644 --- a/tests/auto/other/macnativeevents/nativeeventlist.cpp +++ b/tests/auto/other/macnativeevents/nativeeventlist.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "nativeeventlist.h" diff --git a/tests/auto/other/macnativeevents/nativeeventlist.h b/tests/auto/other/macnativeevents/nativeeventlist.h index 7425414da7..20e91a689a 100644 --- a/tests/auto/other/macnativeevents/nativeeventlist.h +++ b/tests/auto/other/macnativeevents/nativeeventlist.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef Q_NATIVE_PLAYBACK #define Q_NATIVE_PLAYBACK diff --git a/tests/auto/other/macnativeevents/qnativeevents.cpp b/tests/auto/other/macnativeevents/qnativeevents.cpp index 970c41bf2e..a516fc28d6 100644 --- a/tests/auto/other/macnativeevents/qnativeevents.cpp +++ b/tests/auto/other/macnativeevents/qnativeevents.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qnativeevents.h" diff --git a/tests/auto/other/macnativeevents/qnativeevents.h b/tests/auto/other/macnativeevents/qnativeevents.h index ca0cd47675..cab2472083 100644 --- a/tests/auto/other/macnativeevents/qnativeevents.h +++ b/tests/auto/other/macnativeevents/qnativeevents.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef Q_NATIVE_INPUT #define Q_NATIVE_INPUT diff --git a/tests/auto/other/macnativeevents/qnativeevents_mac.cpp b/tests/auto/other/macnativeevents/qnativeevents_mac.cpp index 6d7fbbecc1..a2e1a66c65 100644 --- a/tests/auto/other/macnativeevents/qnativeevents_mac.cpp +++ b/tests/auto/other/macnativeevents/qnativeevents_mac.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qnativeevents.h" #include <CoreGraphics/CoreGraphics.h> diff --git a/tests/auto/other/macnativeevents/tst_macnativeevents.cpp b/tests/auto/other/macnativeevents/tst_macnativeevents.cpp index 79e59e2616..3cb934d7d5 100644 --- a/tests/auto/other/macnativeevents/tst_macnativeevents.cpp +++ b/tests/auto/other/macnativeevents/tst_macnativeevents.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QApplication> #include <QWidget> diff --git a/tests/auto/other/macplist/BLACKLIST b/tests/auto/other/macplist/BLACKLIST deleted file mode 100644 index 83ed55936e..0000000000 --- a/tests/auto/other/macplist/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[test_plist:LSUIElement-as-garbage] -osx diff --git a/tests/auto/other/macplist/CMakeLists.txt b/tests/auto/other/macplist/CMakeLists.txt index 7ebb9d732c..6a98d4dc16 100644 --- a/tests/auto/other/macplist/CMakeLists.txt +++ b/tests/auto/other/macplist/CMakeLists.txt @@ -1,6 +1,13 @@ -# Generated from macplist.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause -if(NOT TARGET Qt::Widgets) # special case +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_macplist LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +if(NOT TARGET Qt::Widgets) return() endif() add_subdirectory(app) diff --git a/tests/auto/other/macplist/app/CMakeLists.txt b/tests/auto/other/macplist/app/CMakeLists.txt index 127d72b1e4..8af8e9f578 100644 --- a/tests/auto/other/macplist/app/CMakeLists.txt +++ b/tests/auto/other/macplist/app/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from app.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## app Binary: @@ -6,10 +7,10 @@ qt_internal_add_executable(app GUI - OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} # special case + OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} SOURCES main.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::Widgets ) diff --git a/tests/auto/other/macplist/app/main.cpp b/tests/auto/other/macplist/app/main.cpp index 1d620eb7c6..2f07fe3c25 100644 --- a/tests/auto/other/macplist/app/main.cpp +++ b/tests/auto/other/macplist/app/main.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtWidgets/QApplication> diff --git a/tests/auto/other/macplist/test/CMakeLists.txt b/tests/auto/other/macplist/test/CMakeLists.txt index 157df5767f..e55dfb2591 100644 --- a/tests/auto/other/macplist/test/CMakeLists.txt +++ b/tests/auto/other/macplist/test/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from test.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_macplist Test: @@ -8,7 +9,7 @@ qt_internal_add_test(tst_macplist OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" SOURCES ../tst_macplist.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/other/macplist/tst_macplist.cpp b/tests/auto/other/macplist/tst_macplist.cpp index 10303aed96..12240c45b5 100644 --- a/tests/auto/other/macplist/tst_macplist.cpp +++ b/tests/auto/other/macplist/tst_macplist.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/other/networkselftest/BLACKLIST b/tests/auto/other/networkselftest/BLACKLIST index 20f0295b48..9865f4def5 100644 --- a/tests/auto/other/networkselftest/BLACKLIST +++ b/tests/auto/other/networkselftest/BLACKLIST @@ -1,6 +1,5 @@ # QTBUG-27571 [ftpProxyServer] -windows-7sp1 windows-10 [smbServer] opensuse-leap diff --git a/tests/auto/other/networkselftest/CMakeLists.txt b/tests/auto/other/networkselftest/CMakeLists.txt index 547e4afd7e..6491c510f6 100644 --- a/tests/auto/other/networkselftest/CMakeLists.txt +++ b/tests/auto/other/networkselftest/CMakeLists.txt @@ -1,17 +1,21 @@ -# Generated from networkselftest.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_networkselftest Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_networkselftest LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_networkselftest SOURCES tst_networkselftest.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Network - QT_TEST_SERVER_LIST "danted" "squid" "apache2" "ftp-proxy" "vsftpd" "cyrus" "echo" # special case + QT_TEST_SERVER_LIST "danted" "squid" "apache2" "ftp-proxy" "vsftpd" "cyrus" "echo" ) - -#### Keys ignored in scope 1:.:.:networkselftest.pro:<TRUE>: -# QT_TEST_SERVER_LIST = "cyrus" "vsftpd" "apache2" "ftp-proxy" "danted" "squid" "echo" diff --git a/tests/auto/other/networkselftest/tst_networkselftest.cpp b/tests/auto/other/networkselftest/tst_networkselftest.cpp index f1fd869671..81d3b60248 100644 --- a/tests/auto/other/networkselftest/tst_networkselftest.cpp +++ b/tests/auto/other/networkselftest/tst_networkselftest.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtNetwork/QtNetwork> @@ -130,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': @@ -233,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, @@ -251,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()); @@ -264,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; } @@ -379,7 +354,7 @@ void tst_NetworkSelfTest::initTestCase() if (resolved.error() == QHostInfo::NoError && !resolved.addresses().isEmpty()) ftpServerIpAddress = resolved.addresses().first(); // TODO: 'ssh', port 22. - QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::ftpProxyServerName(), 2121)); + // QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::ftpProxyServerName(), 2121)); QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::httpServerName(), 80)); // TODO: 'smb', port 139. QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::imapServerName(), 143)); @@ -536,6 +511,7 @@ void tst_NetworkSelfTest::ftpServer() void tst_NetworkSelfTest::ftpProxyServer() { + QSKIP("FTP not currently supported."); netChat(2121, ftpChat("@" + QtNetworkSettings::ftpServerName().toLatin1())); } diff --git a/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.cpp b/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.cpp index ecc95d30b6..d670cec196 100644 --- a/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.cpp +++ b/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Stephen Kelly <steveire@gmail.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2009 Stephen Kelly <steveire@gmail.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "dynamictreemodel.h" @@ -216,7 +191,7 @@ void ModelMoveCommand::doCommand() return; for (int column = 0; column < m_numCols; ++column) { - QList<qint64> l = m_model->m_childItems.value(srcParent.internalId())[column].mid( + const QList<qint64> l = m_model->m_childItems.value(srcParent.internalId())[column].mid( m_startRow, m_endRow - m_startRow + 1); for (int i = m_startRow; i <= m_endRow; i++) @@ -231,7 +206,7 @@ void ModelMoveCommand::doCommand() d = m_destRow; } - foreach (const qint64 id, l) + for (qint64 id : l) m_model->m_childItems[destParent.internalId()][column].insert(d++, id); } @@ -308,9 +283,7 @@ void ModelChangeChildrenLayoutsCommand::doCommand() const QPersistentModelIndex parent1 = findIndex(m_rowNumbers); const QPersistentModelIndex parent2 = findIndex(m_secondRowNumbers); - QList<QPersistentModelIndex> parents; - parents << parent1; - parents << parent2; + const QList<QPersistentModelIndex> parents = { parent1, parent2 }; emit m_model->layoutAboutToBeChanged(parents); @@ -334,13 +307,13 @@ void ModelChangeChildrenLayoutsCommand::doCommand() // changing any children of that parent. The reason is that we're keeping parent1 and parent2 // around as QPersistentModelIndex instances, and we query idx.parent() in the loop. QModelIndexList persistent = m_model->persistentIndexList(); - foreach (const QModelIndex &parent, parents) { + for (const QPersistentModelIndex &parent : parents) { int idx = persistent.indexOf(parent); if (idx != -1) persistent.move(idx, 0); } - foreach (const QModelIndex &idx, persistent) { + for (const QModelIndex &idx : std::as_const(persistent)) { if (idx.parent() == parent1) { if (idx.row() == rowSize1 - 1) { m_model->changePersistentIndex(idx, diff --git a/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.h b/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.h index ba566cbbac..bc7db2ad0f 100644 --- a/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.h +++ b/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Stephen Kelly <steveire@gmail.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2009 Stephen Kelly <steveire@gmail.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef DYNAMICTREEMODEL_H #define DYNAMICTREEMODEL_H diff --git a/tests/auto/other/qaccessibility/CMakeLists.txt b/tests/auto/other/qaccessibility/CMakeLists.txt index c516188396..9160bafe52 100644 --- a/tests/auto/other/qaccessibility/CMakeLists.txt +++ b/tests/auto/other/qaccessibility/CMakeLists.txt @@ -1,14 +1,15 @@ -# Generated from qaccessibility.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause -if(NOT QT_FEATURE_accessibility) - return() +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qaccessibility LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) endif() -# special case begin -if (WIN32 AND NOT TARGET Qt::WindowsUIAutomationSupport) +if(NOT QT_FEATURE_accessibility) return() endif() -# special case end ##################################################################### ## tst_qaccessibility Test: @@ -18,7 +19,7 @@ qt_internal_add_test(tst_qaccessibility SOURCES accessiblewidgets.h tst_qaccessibility.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate @@ -26,19 +27,16 @@ qt_internal_add_test(tst_qaccessibility Qt::WidgetsPrivate ) -#### Keys ignored in scope 1:.:.:qaccessibility.pro:<TRUE>: -# _REQUIREMENTS = "qtConfig(accessibility)" - ## Scopes: ##################################################################### qt_internal_extend_target(tst_qaccessibility CONDITION UNIX AND NOT APPLE AND NOT HAIKU AND NOT INTEGRITY - PUBLIC_LIBRARIES + LIBRARIES m ) qt_internal_extend_target(tst_qaccessibility CONDITION WIN32 - PUBLIC_LIBRARIES + LIBRARIES ole32 oleacc oleaut32 diff --git a/tests/auto/other/qaccessibility/accessiblewidgets.h b/tests/auto/other/qaccessibility/accessiblewidgets.h index 13ca687dd9..76b1f1f473 100644 --- a/tests/auto/other/qaccessibility/accessiblewidgets.h +++ b/tests/auto/other/qaccessibility/accessiblewidgets.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef ACCESSIBLEWIDGETS_H @@ -141,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 615a1a1617..5fd695e2e6 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -1,50 +1,31 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtCore/qglobal.h> #ifdef Q_OS_WIN # include <QtCore/qt_windows.h> # include <oleacc.h> -# include <QtGui/private/qwindowsuiawrapper_p.h> +# include <uiautomation.h> # include <servprov.h> # include <winuser.h> #endif #include <QTest> +#include <QSignalSpy> #include <QtGui> #include <QtWidgets> #include <math.h> #include <qpa/qplatformnativeinterface.h> #include <qpa/qplatformintegration.h> #include <qpa/qplatformaccessibility.h> +#ifdef Q_OS_WIN +#include <QtCore/private/qfunctions_win_p.h> +#endif #include <QtGui/private/qguiapplication_p.h> #include <QtGui/private/qhighdpiscaling_p.h> +#include <QtWidgets/private/qapplication_p.h> +#include <QtWidgets/private/qdialog_p.h> + #if defined(Q_OS_WIN) && defined(interface) # undef interface #endif @@ -58,6 +39,7 @@ #include <QtTest/private/qtesthelpers_p.h> using namespace QTestPrivate; +using namespace Qt::StringLiterals; static inline bool verifyChild(QWidget *child, QAccessibleInterface *interface, int index, const QRect &domain) @@ -185,6 +167,7 @@ public slots: void cleanup(); private slots: void eventTest(); + void eventWithChildTest(); void customWidget(); void deletedWidget(); void subclassedWidget(); @@ -231,18 +214,24 @@ private slots: void listTest(); void treeTest(); void tableTest(); + void rootIndexView(); + void uniqueIdTest(); void calendarWidgetTest(); void dockWidgetTest(); void comboBoxTest(); void accessibleName(); #if QT_CONFIG(shortcut) void labelTest(); + void relationTest(); void accelerators(); #endif void bridgeTest(); void focusChild(); + void messageBoxTest_data(); + void messageBoxTest(); + protected slots: void onClicked(); private: @@ -269,13 +258,21 @@ void tst_QAccessibility::onClicked() click_count++; } +static bool initAccessibility() +{ + QPlatformIntegration *pfIntegration = QGuiApplicationPrivate::platformIntegration(); + if (pfIntegration->accessibility()) { + pfIntegration->accessibility()->setActive(true); + return true; + } + return false; +} + void tst_QAccessibility::initTestCase() { QTestAccessibility::initialize(); - QPlatformIntegration *pfIntegration = QGuiApplicationPrivate::platformIntegration(); - if (!pfIntegration->accessibility()) + if (!initAccessibility()) QSKIP("This platform does not support accessibility"); - pfIntegration->accessibility()->setActive(true); } void tst_QAccessibility::cleanupTestCase() @@ -286,15 +283,26 @@ void tst_QAccessibility::cleanupTestCase() void tst_QAccessibility::init() { QTestAccessibility::clearEvents(); +#ifdef Q_OS_ANDROID + // On Android a11y state is not explicitly set by calling + // QPlatformAccessibility::setActive(), there is another flag that is + // controlled from the Java side. The state of this flag is queried + // during event processing, so a11y state can be reset to false while + // we do QTest::qWait(). + // To overcome the issue in unit-tests, re-enable a11y before each test. + // A more precise fix will require re-enabling it after every qWait() or + // processEvents() call, but the current tests pass with such condition. + initAccessibility(); +#endif } 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()); } @@ -304,7 +312,8 @@ void tst_QAccessibility::cleanup() void tst_QAccessibility::eventTest() { - QPushButton* button = new QPushButton(0); + auto buttonHolder = std::make_unique<QPushButton>(nullptr); + auto button = buttonHolder.get(); QAccessible::queryAccessibleInterface(button); button->setObjectName(QString("Olaf")); setFrameless(button); @@ -329,83 +338,109 @@ void tst_QAccessibility::eventTest() // some platforms might send other events first, (such as state change event active=1) QVERIFY(QTestAccessibility::containsEvent(&hideEvent)); - delete button; + buttonHolder.reset(); // Make sure that invalid events don't bring down the system // these events can be in user code. - QWidget *widget = new QWidget(); + auto widgetHolder = std::make_unique<QWidget>(); + auto widget = widgetHolder.get(); QAccessibleEvent ev1(widget, QAccessible::Focus); QAccessible::updateAccessibility(&ev1); QAccessibleEvent ev2(widget, QAccessible::Focus); ev2.setChild(7); QAccessible::updateAccessibility(&ev2); - delete widget; + widgetHolder.reset(); - QObject *object = new QObject(); + auto objectHolder = std::make_unique<QObject>(); + auto object = objectHolder.get(); QAccessibleEvent ev3(object, QAccessible::Focus); QAccessible::updateAccessibility(&ev3); - delete object; + objectHolder.reset(); 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() { { - QtTestAccessibleWidget* widget = new QtTestAccessibleWidget(0, "Heinz"); - widget->show(); - QVERIFY(QTest::qWaitForWindowExposed(widget)); + QtTestAccessibleWidget widget(nullptr, "Heinz"); + widget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&widget)); // By default we create QAccessibleWidget - QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(widget); + QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(&widget); QVERIFY(iface != 0); QVERIFY(iface->isValid()); - QCOMPARE(iface->object(), (QObject*)widget); + QCOMPARE(iface->object(), (QObject*)&widget); QCOMPARE(iface->object()->objectName(), QString("Heinz")); - QCOMPARE(iface->rect().height(), widget->height()); + QCOMPARE(iface->rect().height(), widget.height()); QCOMPARE(iface->text(QAccessible::Help), QString()); - QCOMPARE(iface->rect().height(), widget->height()); - delete widget; + QCOMPARE(iface->rect().width(), widget.width()); } { QAccessible::installFactory(QtTestAccessibleWidgetIface::ifaceFactory); - QtTestAccessibleWidget* widget = new QtTestAccessibleWidget(0, "Heinz"); - widget->show(); - QVERIFY(QTest::qWaitForWindowExposed(widget)); - QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(widget); + QtTestAccessibleWidget widget(nullptr, "Heinz"); + widget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&widget)); + QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(&widget); QVERIFY(iface != 0); QVERIFY(iface->isValid()); - QCOMPARE(iface->object(), (QObject*)widget); + QCOMPARE(iface->object(), (QObject*)&widget); QCOMPARE(iface->object()->objectName(), QString("Heinz")); - QCOMPARE(iface->rect().height(), widget->height()); + QCOMPARE(iface->rect().height(), widget.height()); // The help text is only set if our factory works QCOMPARE(iface->text(QAccessible::Help), QString("Help yourself")); - delete widget; } { // A subclass of any class should still get the right QAccessibleInterface - QtTestAccessibleWidgetSubclass* subclassedWidget = new QtTestAccessibleWidgetSubclass(0, "Hans"); - QAccessibleInterface *subIface = QAccessible::queryAccessibleInterface(subclassedWidget); + QtTestAccessibleWidgetSubclass subclassedWidget(nullptr, "Hans"); + QAccessibleInterface *subIface = QAccessible::queryAccessibleInterface(&subclassedWidget); QVERIFY(subIface != 0); QVERIFY(subIface->isValid()); - QCOMPARE(subIface->object(), (QObject*)subclassedWidget); + QCOMPARE(subIface->object(), (QObject*)&subclassedWidget); QCOMPARE(subIface->text(QAccessible::Help), QString("Help yourself")); - delete subclassedWidget; } QTestAccessibility::clearEvents(); } void tst_QAccessibility::deletedWidget() { - QtTestAccessibleWidget *widget = new QtTestAccessibleWidget(0, "Ralf"); + auto widgetHolder = std::make_unique<QtTestAccessibleWidget>(nullptr, "Ralf"); + auto widget = widgetHolder.get(); QAccessible::installFactory(QtTestAccessibleWidgetIface::ifaceFactory); QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(widget); QVERIFY(iface != 0); QVERIFY(iface->isValid()); QCOMPARE(iface->object(), (QObject*)widget); - delete widget; - widget = 0; + widgetHolder.reset(); // fixme: QVERIFY(!iface->isValid()); } @@ -442,7 +477,8 @@ void tst_QAccessibility::statesStructTest() void tst_QAccessibility::sliderTest() { { - QSlider *slider = new QSlider(0); + auto sliderHolder = std::make_unique<QSlider>(nullptr); + auto slider = sliderHolder.get(); setFrameless(slider); slider->setObjectName(QString("Slidy")); slider->show(); @@ -468,8 +504,6 @@ void tst_QAccessibility::sliderTest() QCOMPARE(77, slider->value()); slider->setSingleStep(2); QCOMPARE(valueIface->minimumStepSize().toInt(), 2); - - delete slider; } QTestAccessibility::clearEvents(); } @@ -477,7 +511,8 @@ void tst_QAccessibility::sliderTest() void tst_QAccessibility::navigateHierarchy() { { - QWidget *w = new QWidget(0); + auto widgetHolder = std::make_unique<QWidget>(nullptr); + auto w = widgetHolder.get(); w->setObjectName(QString("Hans")); w->show(); QWidget *w1 = new QWidget(w); @@ -531,8 +566,6 @@ void tst_QAccessibility::navigateHierarchy() QVERIFY(parent != 0); QVERIFY(parent->isValid()); QCOMPARE(parent->object(), (QObject*)w3); - - delete w; } QTestAccessibility::clearEvents(); } @@ -588,7 +621,8 @@ static QWidget *createWidgets() void tst_QAccessibility::accessibleName() { - QWidget *toplevel = createWidgets(); + auto holder = std::unique_ptr<QWidget>(createWidgets()); + auto toplevel = holder.get(); toplevel->show(); QVERIFY(QTest::qWaitForWindowExposed(toplevel)); @@ -607,8 +641,6 @@ void tst_QAccessibility::accessibleName() child->setAccessibleDescription(desc); QCOMPARE(acc->text(QAccessible::Description), desc); } - - delete toplevel; QTestAccessibility::clearEvents(); } @@ -633,7 +665,7 @@ void tst_QAccessibility::textAttributes_data() defaultComplexFont.setStyle(QFont::StyleItalic); defaultComplexFont.setUnderline(true); - static QStringList defaults = QString("font-style:normal;font-weight:normal;text-align:left;text-position:baseline;font-size:13pt").split(';'); + static QStringList defaults = QString("font-style:normal;font-weight:normal;text-align:left;text-position:baseline;font-size:13pt;text-line-through-type:none").split(';'); static QStringList bold = defaults; bold[1] = QString::fromLatin1("font-weight:bold"); @@ -669,7 +701,7 @@ void tst_QAccessibility::textAttributes_data() defaultFontDifferentBoldItalic[1] = QString::fromLatin1("font-weight:bold"); static QStringList defaultFontDifferentMonospace = defaultFontDifferent; - defaultFontDifferentMonospace[7] = (QLatin1String("font-family:\"monospace\"")); + defaultFontDifferentMonospace[8] = (QLatin1String("font-family:\"monospace\"")); static QStringList defaultFontDifferentFont8pt = defaultFontDifferent; defaultFontDifferentFont8pt[4] = (QLatin1String("font-size:8pt")); @@ -756,7 +788,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; @@ -774,7 +806,8 @@ void tst_QAccessibility::textAttributes() void tst_QAccessibility::hideShowTest() { - QWidget * const window = new QWidget(); + auto windowHolder = std::make_unique<QWidget>(); + QWidget * const window = windowHolder.get(); window->resize(200, 200); QWidget * const child = new QWidget(window); @@ -804,7 +837,7 @@ void tst_QAccessibility::hideShowTest() QVERIFY(QTestAccessibility::containsEvent(&hideChild)); QTestAccessibility::clearEvents(); - delete window; + windowHolder.reset(); QTestAccessibility::clearEvents(); } @@ -814,7 +847,8 @@ void tst_QAccessibility::actionTest() { QCOMPARE(QAccessibleActionInterface::pressAction(), QString(QStringLiteral("Press"))); - QWidget *widget = new QWidget; + auto widgetHolder = std::make_unique<QWidget>(); + auto widget = widgetHolder.get(); widget->setFocusPolicy(Qt::NoFocus); widget->show(); @@ -828,13 +862,12 @@ void tst_QAccessibility::actionTest() QCOMPARE(actions->actionNames(), QStringList()); widget->setFocusPolicy(Qt::StrongFocus); QCOMPARE(actions->actionNames(), QStringList(QAccessibleActionInterface::setFocusAction())); - - delete widget; } QTestAccessibility::clearEvents(); { - QPushButton *button = new QPushButton; + auto buttonHolder = std::make_unique<QPushButton>(); + auto button = buttonHolder.get(); setFrameless(button); button->show(); QVERIFY(QTest::qWaitForWindowExposed(button)); @@ -856,8 +889,6 @@ void tst_QAccessibility::actionTest() actions->doAction(QAccessibleActionInterface::pressAction()); QTest::qWait(500); QCOMPARE(click_count, 1); - - delete button; } QTestAccessibility::clearEvents(); } @@ -890,7 +921,7 @@ void tst_QAccessibility::applicationTest() QWidget widget; widget.show(); - qApp->setActiveWindow(&widget); + QApplicationPrivate::setActiveWindow(&widget); QVERIFY(QTest::qWaitForWindowActive(&widget)); QAccessibleInterface *widgetIface = QAccessible::queryAccessibleInterface(&widget); @@ -913,10 +944,11 @@ void tst_QAccessibility::mainWindowTest() QSKIP("Platform does not support window activation"); { - QMainWindow *mw = new QMainWindow; + auto mwHolder = std::make_unique<QMainWindow>(); + auto mw = mwHolder.get(); mw->resize(300, 200); mw->show(); // triggers layout - qApp->setActiveWindow(mw); + QApplicationPrivate::setActiveWindow(mw); QLatin1String name = QLatin1String("I am the main window"); mw->setWindowTitle(name); @@ -934,9 +966,6 @@ void tst_QAccessibility::mainWindowTest() QCOMPARE(iface->text(QAccessible::Name), name); QCOMPARE(iface->role(), QAccessible::Window); QVERIFY(iface->state().active); - - - delete mw; } QTestAccessibility::clearEvents(); @@ -1090,7 +1119,10 @@ void tst_QAccessibility::buttonTest() interface = QAccessible::queryAccessibleInterface(&toggleButton); actionInterface = interface->actionInterface(); QCOMPARE(interface->role(), QAccessible::CheckBox); - QCOMPARE(actionInterface->actionNames(), QStringList() << QAccessibleActionInterface::toggleAction() << QAccessibleActionInterface::setFocusAction()); + QCOMPARE(actionInterface->actionNames(), + QStringList() << QAccessibleActionInterface::toggleAction() + << QAccessibleActionInterface::pressAction() + << QAccessibleActionInterface::setFocusAction()); QCOMPARE(actionInterface->localizedActionDescription(QAccessibleActionInterface::toggleAction()), QString("Toggles the state")); QVERIFY(!toggleButton.isChecked()); QVERIFY(!interface->state().checked); @@ -1102,13 +1134,13 @@ void tst_QAccessibility::buttonTest() { // test menu push button - QAction *foo = new QAction("Foo", 0); + QAction *foo = new QAction("Foo", nullptr); foo->setShortcut(QKeySequence("Ctrl+F")); - QMenu *menu = new QMenu(); + auto menu = std::make_unique<QMenu>(); menu->addAction(foo); QPushButton menuButton; setFrameless(&menuButton); - menuButton.setMenu(menu); + menuButton.setMenu(menu.get()); menuButton.show(); QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(&menuButton); QCOMPARE(interface->role(), QAccessible::ButtonMenu); @@ -1117,7 +1149,6 @@ void tst_QAccessibility::buttonTest() // showing the menu enters a new event loop... // interface->actionInterface()->doAction(QAccessibleActionInterface::showMenuAction()); // QTest::qWait(500); - delete menu; } @@ -1127,12 +1158,18 @@ void tst_QAccessibility::buttonTest() interface = QAccessible::queryAccessibleInterface(&checkBox); actionInterface = interface->actionInterface(); QCOMPARE(interface->role(), QAccessible::CheckBox); - QCOMPARE(actionInterface->actionNames(), QStringList() << QAccessibleActionInterface::toggleAction() << QAccessibleActionInterface::setFocusAction()); + QCOMPARE(actionInterface->actionNames(), + QStringList() << QAccessibleActionInterface::toggleAction() + << QAccessibleActionInterface::pressAction() + << QAccessibleActionInterface::setFocusAction()); QVERIFY(!interface->state().checked); actionInterface->doAction(QAccessibleActionInterface::toggleAction()); QTest::qWait(500); - QCOMPARE(actionInterface->actionNames(), QStringList() << QAccessibleActionInterface::toggleAction() << QAccessibleActionInterface::setFocusAction()); + QCOMPARE(actionInterface->actionNames(), + QStringList() << QAccessibleActionInterface::toggleAction() + << QAccessibleActionInterface::pressAction() + << QAccessibleActionInterface::setFocusAction()); QVERIFY(interface->state().checked); QVERIFY(checkBox.isChecked()); QAccessible::State st; @@ -1215,8 +1252,10 @@ void tst_QAccessibility::buttonTest() void tst_QAccessibility::scrollBarTest() { - QScrollBar *scrollBar = new QScrollBar(Qt::Horizontal); - QAccessibleInterface * const scrollBarInterface = QAccessible::queryAccessibleInterface(scrollBar); + auto scrollBarHolder = std::make_unique<QScrollBar>(Qt::Horizontal); + auto scrollBar = scrollBarHolder.get(); + QAccessibleInterface * const scrollBarInterface = + QAccessible::queryAccessibleInterface(scrollBar); QVERIFY(scrollBarInterface); QVERIFY(scrollBarInterface->state().invisible); scrollBar->resize(200, 50); @@ -1253,14 +1292,13 @@ void tst_QAccessibility::scrollBarTest() const QRect scrollBarRect = scrollBarInterface->rect(); QVERIFY(scrollBarRect.isValid()); - delete scrollBar; - QTestAccessibility::clearEvents(); } void tst_QAccessibility::tabTest() { - QTabBar *tabBar = new QTabBar(); + auto tabBarHolder = std::make_unique<QTabBar>(); + auto tabBar = tabBarHolder.get(); setFrameless(tabBar); tabBar->show(); @@ -1324,13 +1362,13 @@ void tst_QAccessibility::tabTest() tabBar->setCurrentIndex(1); QCOMPARE(interface->text(QAccessible::Name), QLatin1String("AccBar")); - delete tabBar; QTestAccessibility::clearEvents(); } void tst_QAccessibility::tabWidgetTest() { - QTabWidget *tabWidget = new QTabWidget(); + auto tabWidgetHolder = std::make_unique<QTabWidget>(); + auto tabWidget = tabWidgetHolder.get(); tabWidget->show(); // the interface for the tab is just a container for tabbar and stacked widget @@ -1389,9 +1427,7 @@ void tst_QAccessibility::tabWidgetTest() QAccessibleInterface* stackChild1Interface = stackWidgetInterface->child(0); QVERIFY(stackChild1Interface); -#ifndef Q_CC_INTEL QCOMPARE(stackChild1Interface->childCount(), 0); -#endif QCOMPARE(stackChild1Interface->role(), QAccessible::StaticText); QCOMPARE(stackChild1Interface->text(QAccessible::Name), QLatin1String("Page 1")); QCOMPARE(label1, stackChild1Interface->object()); @@ -1399,9 +1435,7 @@ void tst_QAccessibility::tabWidgetTest() // Navigation in stack widgets should be consistent QAccessibleInterface* parent = stackChild1Interface->parent(); QVERIFY(parent); -#ifndef Q_CC_INTEL QCOMPARE(parent->childCount(), 2); -#endif QCOMPARE(parent->role(), QAccessible::LayeredPane); QAccessibleInterface* stackChild2Interface = stackWidgetInterface->child(1); @@ -1413,12 +1447,9 @@ void tst_QAccessibility::tabWidgetTest() parent = stackChild2Interface->parent(); QVERIFY(parent); -#ifndef Q_CC_INTEL QCOMPARE(parent->childCount(), 2); -#endif QCOMPARE(parent->role(), QAccessible::LayeredPane); - delete tabWidget; QTestAccessibility::clearEvents(); } @@ -1618,17 +1649,17 @@ void tst_QAccessibility::menuTest() mw.hide(); // Do not crash if the menu don't have a parent - QMenu *menu = new QMenu; + auto menu = std::make_unique<QMenu>(); menu->addAction(QLatin1String("one")); menu->addAction(QLatin1String("two")); menu->addAction(QLatin1String("three")); - iface = QAccessible::queryAccessibleInterface(menu); + iface = QAccessible::queryAccessibleInterface(menu.get()); iface2 = iface->parent(); QVERIFY(iface2); QCOMPARE(iface2->role(), QAccessible::Application); // caused a *crash* iface2->state(); - delete menu; + menu.reset(); } QTestAccessibility::clearEvents(); @@ -1638,7 +1669,8 @@ void tst_QAccessibility::menuTest() void tst_QAccessibility::spinBoxTest() { - QSpinBox * const spinBox = new QSpinBox(); + auto spinBoxHolder = std::make_unique<QSpinBox>(); + const auto spinBox = spinBoxHolder.get(); setFrameless(spinBox); spinBox->setValue(3); spinBox->show(); @@ -1675,13 +1707,13 @@ void tst_QAccessibility::spinBoxTest() QAccessibleTextInterface *textIface = interface->textInterface(); QVERIFY(textIface); - delete spinBox; QTestAccessibility::clearEvents(); } void tst_QAccessibility::doubleSpinBoxTest() { - QDoubleSpinBox *doubleSpinBox = new QDoubleSpinBox; + auto holder = std::make_unique<QDoubleSpinBox>(); + auto doubleSpinBox = holder.get(); setFrameless(doubleSpinBox); doubleSpinBox->show(); @@ -1702,7 +1734,6 @@ void tst_QAccessibility::doubleSpinBoxTest() QVERIFY(childRect.isValid()); } - delete doubleSpinBox; QTestAccessibility::clearEvents(); } @@ -1928,7 +1959,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); @@ -1943,7 +1974,7 @@ void tst_QAccessibility::mdiSubWindowTest() { QMdiArea mdiArea; mdiArea.show(); - qApp->setActiveWindow(&mdiArea); + QApplicationPrivate::setActiveWindow(&mdiArea); QVERIFY(QTest::qWaitForWindowActive(&mdiArea)); @@ -1966,7 +1997,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); @@ -1985,6 +2016,10 @@ void tst_QAccessibility::mdiSubWindowTest() mdiArea.setActiveSubWindow(testWindow); +#ifdef Q_OS_ANDROID // on Android QMdiSubWindow is maximized by default + testWindow->showNormal(); +#endif + // state QAccessible::State state; state.focusable = true; @@ -2007,7 +2042,7 @@ void tst_QAccessibility::mdiSubWindowTest() testWindow->setEnabled(false); QVERIFY(interface->state().disabled); testWindow->setEnabled(true); - qApp->setActiveWindow(&mdiArea); + QApplicationPrivate::setActiveWindow(&mdiArea); mdiArea.setActiveSubWindow(testWindow); testWindow->setFocus(); QVERIFY(testWindow->isAncestorOf(qApp->focusWidget())); @@ -2049,10 +2084,11 @@ void tst_QAccessibility::mdiSubWindowTest() void tst_QAccessibility::lineEditTest() { - QWidget *toplevel = new QWidget; + auto topLevelHolder = std::make_unique<QWidget>(); + auto toplevel = topLevelHolder.get(); { - QLineEdit *le = new QLineEdit; - QAccessibleInterface *iface(QAccessible::queryAccessibleInterface(le)); + auto le = std::make_unique<QLineEdit>(); + QAccessibleInterface *iface(QAccessible::queryAccessibleInterface(le.get())); QVERIFY(iface); le->show(); @@ -2085,10 +2121,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); @@ -2121,7 +2157,7 @@ void tst_QAccessibility::lineEditTest() iface->setText(QAccessible::Value, QLatin1String("This text is not a number")); QCOMPARE(le->text(), QLatin1String("500")); - delete le; + le.reset(); delete le2; } @@ -2180,7 +2216,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); @@ -2224,8 +2260,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); @@ -2298,7 +2334,6 @@ void tst_QAccessibility::lineEditTest() QAccessibleTextInsertEvent insertO(lineEdit, 4, "O"); QVERIFY(QTestAccessibility::containsEvent(&insertO)); } - delete toplevel; QTestAccessibility::clearEvents(); } @@ -2449,11 +2484,11 @@ void tst_QAccessibility::textInterfaceTest() QFETCH(QString, expectedText); QAccessible::installFactory(CustomTextWidgetIface::ifaceFactory); - CustomTextWidget *w = new CustomTextWidget(); + auto w = std::make_unique<CustomTextWidget>(); w->text = text; w->cursorPosition = cursorPosition; - QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(w); + QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(w.get()); QVERIFY(iface); QCOMPARE(iface->text(QAccessible::Value), text); QAccessibleTextInterface *textIface = iface->textInterface(); @@ -2478,7 +2513,6 @@ void tst_QAccessibility::textInterfaceTest() QCOMPARE(start, expectedStart); QCOMPARE(end, expectedEnd); - delete w; QAccessible::removeFactory(CustomTextWidgetIface::ifaceFactory); QTestAccessibility::clearEvents(); } @@ -2486,7 +2520,8 @@ void tst_QAccessibility::textInterfaceTest() void tst_QAccessibility::groupBoxTest() { { - QGroupBox *groupBox = new QGroupBox(); + auto gbHolder = std::make_unique<QGroupBox>(); + auto groupBox = gbHolder.get(); QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(groupBox); groupBox->setTitle(QLatin1String("Test QGroupBox")); @@ -2511,12 +2546,11 @@ void tst_QAccessibility::groupBoxTest() QPair<QAccessibleInterface*, QAccessible::Relation> relation = relations.first(); QCOMPARE(relation.first->object(), groupBox); QCOMPARE(relation.second, QAccessible::Label); - - delete groupBox; } { - QGroupBox *groupBox = new QGroupBox(); + auto gbHolder = std::make_unique<QGroupBox>(); + auto groupBox = gbHolder.get(); QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(groupBox); QVERIFY(!iface->state().checkable); groupBox->setCheckable(true); @@ -2540,8 +2574,6 @@ void tst_QAccessibility::groupBoxTest() QVERIFY(state.checked); QAccessibleStateChangeEvent ev2(groupBox, st); QVERIFY_EVENT(&ev2); - - delete groupBox; } } @@ -2585,7 +2617,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; @@ -2637,7 +2669,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; @@ -2813,7 +2845,8 @@ void tst_QAccessibility::scrollAreaTest() void tst_QAccessibility::listTest() { { - QListWidget *listView = new QListWidget; + auto lvHolder = std::make_unique<QListWidget>(); + auto listView = lvHolder.get(); listView->addItem("Oslo"); listView->addItem("Berlin"); listView->addItem("Brisbane"); @@ -2846,6 +2879,12 @@ void tst_QAccessibility::listTest() QCOMPARE(iface->indexOfChild(child3), 2); QCOMPARE(child3->text(QAccessible::Name), QString("Brisbane")); } + + // Check that application is accessible parent, since it's a top-level widget + QAccessibleInterface *parentIface = iface->parent(); + QVERIFY(parentIface); + QVERIFY(parentIface->role() == QAccessible::Application); + QTestAccessibility::clearEvents(); // Check for events @@ -2897,7 +2936,8 @@ void tst_QAccessibility::listTest() QVERIFY(!(cell4->state().expandable)); QVERIFY( (cell4->state().selectable)); QVERIFY(!(cell4->state().selected)); - table2->selectRow(3); + QAccessibleSelectionInterface *selection2 = iface->selectionInterface(); + selection2->select(cell4); QCOMPARE(listView->selectedItems().size(), 1); QCOMPARE(listView->selectedItems().at(0)->text(), QLatin1String("Munich")); QVERIFY(cell4->state().selected); @@ -2929,19 +2969,17 @@ void tst_QAccessibility::listTest() // list: Oslo, Helsinki // verify that it doesn't return an invalid item from the cache QVERIFY(table2->cellAt(2,0) == 0); - - delete listView; } QTestAccessibility::clearEvents(); } void tst_QAccessibility::treeTest() { - QTreeWidget *treeView = new QTreeWidget; + auto treeView = std::make_unique<QTreeWidget>(); // Empty model (do not crash, etc) treeView->setColumnCount(0); - QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(treeView); + QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(treeView.get()); QCOMPARE(iface->child(0), static_cast<QAccessibleInterface*>(0)); treeView->setColumnCount(2); @@ -3074,7 +3112,6 @@ void tst_QAccessibility::treeTest() QCOMPARE(table2->columnDescription(0), QString("Artist")); QCOMPARE(table2->columnDescription(1), QString("Work")); - delete treeView; QTestAccessibility::clearEvents(); } @@ -3085,7 +3122,8 @@ void tst_QAccessibility::treeTest() // v3 (12) | 0.2 (13) | 1.2 (14) | 2.2 (15) void tst_QAccessibility::tableTest() { - QTableWidget *tableView = new QTableWidget(3, 3); + auto tvHolder = std::make_unique<QTableWidget>(3, 3); + auto tableView = tvHolder.get(); tableView->setColumnCount(3); QStringList hHeader; hHeader << "h1" << "h2" << "h3"; @@ -3365,11 +3403,75 @@ void tst_QAccessibility::tableTest() tableView->horizontalHeader()->setVisible(false); } - delete tableView; + tvHolder.reset(); QVERIFY(!QAccessible::accessibleInterface(id00)); QTestAccessibility::clearEvents(); } +void tst_QAccessibility::rootIndexView() +{ + QStandardItemModel model; + for (int i = 0; i < 2; ++i) { + QStandardItem *item = new QStandardItem(u"root %1"_s.arg(i)); + for (int j = 0; j < 5 * (i + 1); ++j) { + switch (i) { + case 0: + item->appendRow(new QStandardItem(u"child0/%1"_s.arg(j))); + break; + case 1: + item->appendRow({new QStandardItem(u"column0 1/%1"_s.arg(j)), + new QStandardItem(u"column1 1/%1"_s.arg(j)) + }); + break; + } + } + model.appendRow(item); + } + + QListView view; + view.setModel(&model); + QTestAccessibility::clearEvents(); + + QAccessibleInterface *accView = QAccessible::queryAccessibleInterface(&view); + QVERIFY(accView); + QAccessibleTableInterface *accTable = accView->tableInterface(); + QVERIFY(accTable); + QCOMPARE(accTable->rowCount(), 2); + QCOMPARE(accTable->columnCount(), 1); + + view.setRootIndex(model.index(0, 0)); + QAccessibleTableModelChangeEvent resetEvent(&view, QAccessibleTableModelChangeEvent::ModelReset); + QVERIFY(QTestAccessibility::containsEvent(&resetEvent)); + + QCOMPARE(accTable->rowCount(), 5); + QCOMPARE(accTable->columnCount(), 1); + + view.setRootIndex(model.index(1, 0)); + QCOMPARE(accTable->rowCount(), 10); + QCOMPARE(accTable->columnCount(), 2); + + 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) @@ -3397,7 +3499,7 @@ void tst_QAccessibility::calendarWidgetTest() QCOMPARE(interface->rect(), globalGeometry); QWidget *navigationBar = 0; - foreach (QObject *child, calendarWidget.children()) { + for (QObject *child : calendarWidget.children()) { if (child->objectName() == QLatin1String("qt_calendar_navigationbar")) { navigationBar = static_cast<QWidget *>(child); break; @@ -3407,7 +3509,7 @@ void tst_QAccessibility::calendarWidgetTest() QVERIFY(verifyChild(navigationBar, interface, 0, globalGeometry)); QAbstractItemView *calendarView = 0; - foreach (QObject *child, calendarWidget.children()) { + for (QObject *child : calendarWidget.children()) { if (child->objectName() == QLatin1String("qt_calendar_calendarview")) { calendarView = static_cast<QAbstractItemView *>(child); break; @@ -3455,7 +3557,8 @@ void tst_QAccessibility::dockWidgetTest() { #if QT_CONFIG(dockwidget) // Set up a proper main window with two dock widgets - QMainWindow *mw = new QMainWindow(); + auto mwHolder = std::make_unique<QMainWindow>(); + auto mw = mwHolder.get(); QFrame *central = new QFrame(mw); mw->setCentralWidget(central); QMenuBar *mb = new QMenuBar(mw); @@ -3584,7 +3687,6 @@ void tst_QAccessibility::dockWidgetTest() QAccessibleInterface *dock3Widget = accDock3->child(0); QCOMPARE(dock3Widget->text(QAccessible::Name), pb3->text()); - delete mw; QTestAccessibility::clearEvents(); #endif // QT_CONFIG(dockwidget) } @@ -3609,6 +3711,8 @@ void tst_QAccessibility::comboBoxTest() QCOMPARE(iface->text(QAccessible::Name), QLatin1String("one")); #endif QCOMPARE(iface->text(QAccessible::Value), QLatin1String("one")); + QCOMPARE(combo.view()->selectionModel()->currentIndex().row(), 0); + combo.setCurrentIndex(2); #ifdef Q_OS_UNIX QCOMPARE(iface->text(QAccessible::Name), QLatin1String("three")); @@ -3619,7 +3723,13 @@ void tst_QAccessibility::comboBoxTest() QCOMPARE(listIface->role(), QAccessible::List); QCOMPARE(listIface->childCount(), 3); + QAccessibleSelectionInterface *selectionIface = listIface->selectionInterface(); + QVERIFY(selectionIface); + QCOMPARE(selectionIface->selectedItemCount(), 1); + QCOMPARE(listIface->indexOfChild(selectionIface->selectedItem(0)), 2); + QVERIFY(!combo.view()->isVisible()); + QCOMPARE(combo.view()->selectionModel()->currentIndex().row(), 2); QVERIFY(iface->actionInterface()); QCOMPARE(iface->actionInterface()->actionNames(), QStringList() << QAccessibleActionInterface::showMenuAction() << QAccessibleActionInterface::pressAction()); iface->actionInterface()->doAction(QAccessibleActionInterface::showMenuAction()); @@ -3649,11 +3759,75 @@ 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() { - QWidget *window = new QWidget; + auto windowHolder = std::make_unique<QWidget>(); + auto window = windowHolder.get(); QString text = "Hello World"; QLabel *label = new QLabel(text, window); setFrameless(label); @@ -3670,6 +3844,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); @@ -3679,15 +3855,25 @@ 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.count(), 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); + } - delete window; + { + 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(); QPixmap testPixmap(50, 50); @@ -3713,7 +3899,8 @@ void tst_QAccessibility::labelTest() void tst_QAccessibility::accelerators() { - QWidget *window = new QWidget; + auto windowHolder = std::make_unique<QWidget>(); + auto window = windowHolder.get(); QHBoxLayout *lay = new QHBoxLayout(window); QLabel *label = new QLabel(tr("&Line edit"), window); QLineEdit *le = new QLineEdit(window); @@ -3747,7 +3934,7 @@ void tst_QAccessibility::accelerators() QCoreApplication::processEvents(); #endif QTest::qWait(100); - delete window; + windowHolder.reset(); QTestAccessibility::clearEvents(); } @@ -3780,6 +3967,7 @@ void tst_QAccessibility::bridgeTest() // For now this is a simple test to see if the bridge is working at all. // Ideally it should be extended to test all aspects of the bridge. #if defined(Q_OS_WIN) + auto guard = qScopeGuard([]() { QTestAccessibility::clearEvents(); }); QWidget window; QVBoxLayout *lay = new QVBoxLayout(&window); @@ -3828,14 +4016,14 @@ void tst_QAccessibility::bridgeTest() POINT pt{nativePos.x(), nativePos.y()}; // Initialize COM stuff. - HRESULT hr = CoInitialize(nullptr); - QVERIFY(SUCCEEDED(hr)); + QComHelper comHelper; + QVERIFY(comHelper.isValid()); // Get UI Automation interface. const GUID CLSID_CUIAutomation_test{0xff48dba4, 0x60ef, 0x4201, {0xaa,0x87, 0x54,0x10,0x3e,0xef,0x59,0x4e}}; IUIAutomation *automation = nullptr; - hr = CoCreateInstance(CLSID_CUIAutomation_test, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&automation)); + HRESULT hr = CoCreateInstance(CLSID_CUIAutomation_test, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&automation)); QVERIFY(SUCCEEDED(hr)); // Get button element from UI Automation using point. @@ -3853,7 +4041,12 @@ void tst_QAccessibility::bridgeTest() RECT rect; hr = buttonElement->get_CurrentBoundingRectangle(&rect); QVERIFY(SUCCEEDED(hr)); - QCOMPARE(buttonRect, QRect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top)); + const QRect boundingRect(rect.left, rect.top, rect.right - rect.left + 1, rect.bottom - rect.top + 1); + const QRectF nativeRect = QHighDpi::toNativePixels(QRectF(buttonRect), window.windowHandle()); + const QRect truncRect(int(nativeRect.left()), int(nativeRect.top()), + int(nativeRect.right()) - int(nativeRect.left()) + 1, + int(nativeRect.bottom()) - int(nativeRect.top()) + 1); + QCOMPARE(truncRect, boundingRect); buttonElement->Release(); @@ -3912,10 +4105,105 @@ void tst_QAccessibility::bridgeTest() QCOMPARE(controlTypeId, UIA_ButtonControlTypeId); // Edit - hr = nodeList.at(2)->get_CurrentControlType(&controlTypeId); + IUIAutomationElement *uiaElement = nodeList.at(2); + hr = uiaElement->get_CurrentControlType(&controlTypeId); QVERIFY(SUCCEEDED(hr)); QCOMPARE(controlTypeId, UIA_EditControlTypeId); + // "hello world\nhow are you today?\n" + IUIAutomationTextPattern *textPattern = nullptr; + hr = uiaElement->GetCurrentPattern(UIA_TextPattern2Id, reinterpret_cast<IUnknown**>(&textPattern)); + QVERIFY(SUCCEEDED(hr)); + QVERIFY(textPattern); + + IUIAutomationTextRange *docRange = nullptr; + hr = textPattern->get_DocumentRange(&docRange); + QVERIFY(SUCCEEDED(hr)); + QVERIFY(docRange); + + IUIAutomationTextRange *textRange = nullptr; + hr = docRange->Clone(&textRange); + QVERIFY(SUCCEEDED(hr)); + QVERIFY(textRange); + int moved; + + auto rangeText = [](IUIAutomationTextRange *textRange) { + BSTR str; + QString res = "IUIAutomationTextRange::GetText() failed"; + HRESULT hr = textRange->GetText(-1, &str); + if (SUCCEEDED(hr)) { + res = QString::fromWCharArray(str); + ::SysFreeString(str); + } + return res; + }; + + // Move start endpoint past "hello " to "world" + hr = textRange->Move(TextUnit_Character, 6, &moved); + QVERIFY(SUCCEEDED(hr)); + QCOMPARE(moved, 6); + // If the range was not empty, it should be collapsed to contain a single text unit + QCOMPARE(rangeText(textRange), QString("w")); + + // Move end endpoint to end of "world" + hr = textRange->MoveEndpointByUnit(TextPatternRangeEndpoint_End, TextUnit_Character, 4, &moved); + QVERIFY(SUCCEEDED(hr)); + QCOMPARE(moved, 4); + QCOMPARE(rangeText(textRange), QString("world")); + + // MSDN: "Zero has no effect". This behavior was also verified with native controls. + hr = textRange->Move(TextUnit_Character, 0, &moved); + QVERIFY(SUCCEEDED(hr)); + QCOMPARE(moved, 0); + QCOMPARE(rangeText(textRange), QString("world")); + + hr = textRange->Move(TextUnit_Character, 1, &moved); + QVERIFY(SUCCEEDED(hr)); + QCOMPARE(rangeText(textRange), QString("o")); + + // move as far towards the end as possible + hr = textRange->Move(TextUnit_Character, 999, &moved); + QVERIFY(SUCCEEDED(hr)); + QCOMPARE(rangeText(textRange), QString("")); + + hr = textRange->MoveEndpointByUnit(TextPatternRangeEndpoint_Start, TextUnit_Character, -1, &moved); + QVERIFY(SUCCEEDED(hr)); + QCOMPARE(rangeText(textRange), QString("\n")); + + // move one forward (last possible position again) + hr = textRange->Move(TextUnit_Character, 1, &moved); + QVERIFY(SUCCEEDED(hr)); + QCOMPARE(rangeText(textRange), QString("")); + + hr = textRange->Move(TextUnit_Character, -7, &moved); + QVERIFY(SUCCEEDED(hr)); + QCOMPARE(moved, -7); + QCOMPARE(rangeText(textRange), QString("")); + // simulate moving cursor (empty range) towards (and past) the end + QString today(" today?\n"); + for (int i = 1; i < 9; ++i) { // 9 is deliberately too much + // peek one character back + hr = textRange->MoveEndpointByUnit(TextPatternRangeEndpoint_Start, TextUnit_Character, -1, &moved); + QVERIFY(SUCCEEDED(hr)); + QCOMPARE(rangeText(textRange), today.mid(i - 1, 1)); + + hr = textRange->Move(TextUnit_Character, 1, &moved); + QVERIFY(SUCCEEDED(hr)); + QCOMPARE(rangeText(textRange), today.mid(i, moved)); // when we cannot move further, moved will be 0 + + // Make the range empty again + hr = textRange->MoveEndpointByUnit(TextPatternRangeEndpoint_End, TextUnit_Character, -moved, &moved); + QVERIFY(SUCCEEDED(hr)); + + // advance the empty range + hr = textRange->Move(TextUnit_Character, 1, &moved); + QVERIFY(SUCCEEDED(hr)); + } + docRange->Release(); + textRange->Release(); + textPattern->Release(); + + // Table hr = nodeList.at(3)->get_CurrentControlType(&controlTypeId); QVERIFY(SUCCEEDED(hr)); @@ -3933,9 +4221,6 @@ void tst_QAccessibility::bridgeTest() controlWalker->Release(); windowElement->Release(); automation->Release(); - CoUninitialize(); - - QTestAccessibility::clearEvents(); #endif } @@ -4026,6 +4311,9 @@ private: void tst_QAccessibility::focusChild() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Platform does not support window activation"); + { QMainWindow mainWindow; QtTestAccessibleWidget *widget1 = new QtTestAccessibleWidget(0, "Widget1"); @@ -4059,9 +4347,6 @@ void tst_QAccessibility::focusChild() QCOMPARE(iface2->focusChild(), iface2); QCOMPARE(QAccessible::queryAccessibleInterface(&mainWindow)->focusChild(), iface2); - delete widget1; - delete widget2; - delete centralWidget; QTestAccessibility::clearEvents(); } @@ -4078,7 +4363,6 @@ void tst_QAccessibility::focusChild() widget->setFocus(); QCOMPARE(iface->focusChild(), QAccessible::queryAccessibleInterface(widget)->child(1)); - delete widget; QAccessible::removeFactory(FocusChildTestAccessibleWidget::ifaceFactory); QTestAccessibility::clearEvents(); } @@ -4101,11 +4385,256 @@ void tst_QAccessibility::focusChild() QCOMPARE(iface->focusChild()->text(QAccessible::Name), QStringLiteral("Second tab")); QCOMPARE(iface->focusChild()->role(), QAccessible::PageTab); - delete tabBar; QTestAccessibility::clearEvents(); } + + { + auto tableView = std::make_unique<QTableWidget>(3, 3); + + QSignalSpy spy(tableView.get(), SIGNAL(currentCellChanged(int,int,int,int))); + + tableView->setColumnCount(3); + QStringList hHeader; + hHeader << "h1" << "h2" << "h3"; + tableView->setHorizontalHeaderLabels(hHeader); + + QStringList vHeader; + vHeader << "v1" << "v2" << "v3"; + tableView->setVerticalHeaderLabels(vHeader); + + for (int i = 0; i < 9; ++i) { + QTableWidgetItem *item = new QTableWidgetItem; + item->setText(QString::number(i/3) + QString(".") + QString::number(i%3)); + tableView->setItem(i/3, i%3, item); + } + + tableView->resize(600, 600); + tableView->show(); + QVERIFY(QTest::qWaitForWindowExposed(tableView.get())); + + tableView->setFocus(); + + QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(tableView.get()); + QVERIFY(iface); + + spy.clear(); + tableView->setCurrentCell(2, 1); + QTRY_COMPARE(spy.size(), 1); + + QAccessibleInterface *child = iface->focusChild(); + QVERIFY(child); + QCOMPARE(child->text(QAccessible::Name), QStringLiteral("2.1")); + + spy.clear(); + tableView->setCurrentCell(1, 2); + QTRY_COMPARE(spy.size(), 1); + + child = iface->focusChild(); + QVERIFY(child); + QCOMPARE(child->text(QAccessible::Name), QStringLiteral("1.2")); + } + + { + auto treeView = std::make_unique<QTreeWidget>(); + + QSignalSpy spy(treeView.get(), SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*))); + + treeView->setColumnCount(2); + QTreeWidgetItem *header = new QTreeWidgetItem; + header->setText(0, "Artist"); + header->setText(1, "Work"); + treeView->setHeaderItem(header); + + QTreeWidgetItem *root1 = new QTreeWidgetItem; + root1->setText(0, "Spain"); + treeView->addTopLevelItem(root1); + + QTreeWidgetItem *item1 = new QTreeWidgetItem; + item1->setText(0, "Picasso"); + item1->setText(1, "Guernica"); + root1->addChild(item1); + + QTreeWidgetItem *item2 = new QTreeWidgetItem; + item2->setText(0, "Tapies"); + item2->setText(1, "Ambrosia"); + root1->addChild(item2); + + QTreeWidgetItem *root2 = new QTreeWidgetItem; + root2->setText(0, "Austria"); + treeView->addTopLevelItem(root2); + + QTreeWidgetItem *item3 = new QTreeWidgetItem; + item3->setText(0, "Klimt"); + item3->setText(1, "The Kiss"); + root2->addChild(item3); + + treeView->resize(400, 400); + treeView->show(); + QVERIFY(QTest::qWaitForWindowExposed(treeView.get())); + + treeView->setFocus(); + + QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(treeView.get()); + QVERIFY(iface); + + spy.clear(); + treeView->setCurrentItem(item2); + QTRY_COMPARE(spy.size(), 1); + + QAccessibleInterface *child = iface->focusChild(); + QVERIFY(child); + QCOMPARE(child->text(QAccessible::Name), QStringLiteral("Tapies")); + + spy.clear(); + treeView->setCurrentItem(item3); + 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() +{ + QTest::addColumn<QMessageBox::Icon>("icon"); + QTest::addColumn<QMessageBox::StandardButtons>("buttons"); + QTest::addColumn<QString>("title"); + QTest::addColumn<QString>("text"); + QTest::addColumn<QString>("infoText"); + QTest::addColumn<QString>("details"); + QTest::addColumn<bool>("checkbox"); + QTest::addColumn<bool>("textInteractive"); + + QTest::addRow("Information") << QMessageBox::Information + << QMessageBox::StandardButtons(QMessageBox::Ok) + << "Information" + << "Here, have some information." + << QString() + << QString() + << false + << false; + + QTest::addRow("Warning") << QMessageBox::Warning + << QMessageBox::StandardButtons(QMessageBox::Ok | QMessageBox::Cancel) + << "Warning" + << "This is a dangerous operation!" + << "Ok or Cancel?" + << QString() + << true + << false; + + QTest::addRow("Error") << QMessageBox::Critical + << QMessageBox::StandardButtons(QMessageBox::Abort | QMessageBox::Retry | QMessageBox::Ignore) + << "Error" + << "Operation failed for http://example.com" + << "You have to decide what to do" + << "Detailed log output" + << false + << true; } +void tst_QAccessibility::messageBoxTest() +{ + QFETCH(QMessageBox::Icon, icon); + QFETCH(QMessageBox::StandardButtons, buttons); + QFETCH(QString, title); + QFETCH(QString, text); + QFETCH(QString, infoText); + QFETCH(QString, details); + QFETCH(bool, checkbox); + QFETCH(bool, textInteractive); + + QMessageBox box(icon, title, text, buttons); + + QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(&box); + QVERIFY(iface); + QCOMPARE(iface->role(), QAccessible::AlertMessage); +#ifndef Q_OS_DARWIN // macOS message boxes show no title + QCOMPARE(iface->text(QAccessible::Name), title); +#endif + QCOMPARE(iface->text(QAccessible::Value), text); + + int expectedChildCount = 3; + QCOMPARE(iface->childCount(), expectedChildCount); + + if (textInteractive) + box.setTextInteractionFlags(Qt::TextBrowserInteraction); + + if (!infoText.isEmpty()) { + box.setInformativeText(infoText); + QCOMPARE(iface->childCount(), ++expectedChildCount); + } + QCOMPARE(iface->text(QAccessible::Help), infoText); + + if (!details.isEmpty()) { + box.setDetailedText(details); + QCOMPARE(iface->childCount(), ++expectedChildCount); + } + if (checkbox) { + box.setCheckBox(new QCheckBox("Don't show again")); + QCOMPARE(iface->childCount(), ++expectedChildCount); + } + + QTestAccessibility::clearEvents(); + + QDialogPrivate *boxPrivate = static_cast<QDialogPrivate *>(QDialogPrivate::get(&box)); + if (!boxPrivate->canBeNativeDialog()) { + // platforms that use a native message box will not emit accessibility events + box.show(); + + QAccessibleEvent showEvent(&box, QAccessible::DialogStart); + QVERIFY(QTestAccessibility::containsEvent(&showEvent)); + + box.hide(); + + QAccessibleEvent hideEvent(&box, QAccessible::DialogEnd); + QVERIFY(QTestAccessibility::containsEvent(&hideEvent)); + } + + QTestAccessibility::clearEvents(); +} QTEST_MAIN(tst_QAccessibility) #include "tst_qaccessibility.moc" diff --git a/tests/auto/other/qaccessibilitylinux/CMakeLists.txt b/tests/auto/other/qaccessibilitylinux/CMakeLists.txt index ba6443d364..5c85827a3b 100644 --- a/tests/auto/other/qaccessibilitylinux/CMakeLists.txt +++ b/tests/auto/other/qaccessibilitylinux/CMakeLists.txt @@ -1,10 +1,16 @@ -# Generated from qaccessibilitylinux.pro. -# special case begin +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qaccessibilitylinux LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + if (NOT QT_FEATURE_accessibility OR NOT TARGET Qt::LinuxAccessibilitySupportPrivate OR (QT_BUILD_STANDALONE_TESTS AND QT_WILL_INSTALL)) return() endif() -# special case end ##################################################################### ## tst_qaccessibilitylinux Test: @@ -15,7 +21,7 @@ qt_internal_add_test(tst_qaccessibilitylinux tst_qaccessibilitylinux.cpp DBUS_INTERFACE_SOURCES ../../../../src/platformsupport/linuxaccessibility/dbusxml/Bus.xml - PUBLIC_LIBRARIES + LIBRARIES Qt::DBus Qt::Gui Qt::GuiPrivate @@ -23,9 +29,7 @@ qt_internal_add_test(tst_qaccessibilitylinux Qt::Widgets ) -# special case begin # require for struct_marshallers_p.h which is included dbus_interface.h target_include_directories(tst_qaccessibilitylinux PRIVATE ../../../../src/platformsupport/linuxaccessibility ) -# special case end diff --git a/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp b/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp index f776e87692..18bcdeca29 100644 --- a/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp +++ b/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtGui> @@ -80,7 +55,7 @@ class tst_QAccessibilityLinux : public QObject public: tst_QAccessibilityLinux() : m_window(0), root(0), rootApplication(0), mainWindow(0) { - qputenv("QT_LINUX_ACCESSIBILITY_ALWAYS_ON", QByteArrayLiteral("1")); + qputenv("QT_LINUX_ACCESSIBILITY_ALWAYS_ON", "1"); dbus = new DBusConnection(); } ~tst_QAccessibilityLinux() @@ -128,7 +103,7 @@ QStringList tst_QAccessibilityLinux::getChildren(QDBusInterface *interface) Q_ASSERT(interface->property("ChildCount").toInt() == list.count()); QStringList children; - Q_FOREACH (const QSpiObjectReference &ref, list) + for (const QSpiObjectReference &ref : std::as_const(list)) children << ref.path.path(); return children; @@ -179,6 +154,7 @@ void tst_QAccessibilityLinux::initTestCase() QVERIFY(!address.isEmpty()); m_window = new AccessibleTestWindow(); + m_window->setObjectName("mainWindow"_L1); m_window->show(); QVERIFY(QTest::qWaitForWindowExposed(m_window)); @@ -236,8 +212,11 @@ bool hasState(QDBusInterface *interface, AtspiStateType state) void tst_QAccessibilityLinux::testLabel() { QLabel *l = new QLabel(m_window); + l->setObjectName("theObjectName"_L1); l->setText("Hello A11y"); m_window->addWidget(l); + auto a11yEmpty = new QLabel(m_window); + m_window->addWidget(l); // Application QCOMPARE(getParent(mainWindow), QLatin1String(ATSPI_DBUS_PATH_ROOT)); @@ -249,6 +228,8 @@ void tst_QAccessibilityLinux::testLabel() QCOMPARE(getChildren(labelInterface).count(), 0); QCOMPARE(labelInterface->call(QDBus::Block, "GetRoleName").arguments().first().toString(), QLatin1String("label")); QCOMPARE(labelInterface->call(QDBus::Block, "GetRole").arguments().first().toUInt(), 29u); + QCOMPARE(labelInterface->call(QDBus::Block, "GetAccessibleId").arguments().first().toString(), + "mainWindow.theObjectName"_L1); QCOMPARE(getParent(labelInterface), mainWindow->path()); QVERIFY(!hasState(labelInterface, ATSPI_STATE_EDITABLE)); QVERIFY(hasState(labelInterface, ATSPI_STATE_READ_ONLY)); @@ -256,7 +237,12 @@ void tst_QAccessibilityLinux::testLabel() l->setText("New text"); QCOMPARE(labelInterface->property("Name").toString(), l->text()); + auto *a11yEmptyInterface = getInterface(children.at(1), "org.a11y.atspi.Accessible"); + QCOMPARE(a11yEmptyInterface->call(QDBus::Block, "GetAccessibleId").arguments().first().toString(), + "mainWindow.QLabel"_L1); + m_window->clearChildren(); + delete a11yEmptyInterface; delete labelInterface; } diff --git a/tests/auto/other/qaccessibilitymac/CMakeLists.txt b/tests/auto/other/qaccessibilitymac/CMakeLists.txt index 6dd30a6fa1..66896ed384 100644 --- a/tests/auto/other/qaccessibilitymac/CMakeLists.txt +++ b/tests/auto/other/qaccessibilitymac/CMakeLists.txt @@ -1,32 +1,22 @@ -# Generated from qaccessibilitymac.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qaccessibilitymac LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() if(NOT APPLE) return() endif() -##################################################################### -## tst_qaccessibilitymac Test: -##################################################################### - qt_internal_add_test(tst_qaccessibilitymac SOURCES - tst_qaccessibilitymac.cpp - tst_qaccessibilitymac_helpers.h - PUBLIC_LIBRARIES + tst_qaccessibilitymac.mm + 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 a766e1e374..0000000000 --- a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#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 7e89b3a166..4bedd07e15 100644 --- a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm +++ b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.mm @@ -1,35 +1,14 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#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> @@ -80,17 +59,10 @@ 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; + bool axError; } @property (readonly) NSString *role; @property (readonly) NSString *title; @@ -106,11 +78,13 @@ QDebug operator<<(QDebug dbg, AXErrorTag err) if ((self = [super init])) { reference = ref; + axError = false; } return self; } - (AXUIElementRef) ref { return reference; } +- (bool)errorOccurred { return axError; } - (void) print { NSLog(@"Accessible Object role: '%@', title: '%@', description: '%@', value: '%@', rect: '%@'", self.role, self.title, self.description, self.value, NSStringFromRect(NSRectFromCGRect(self.rect))); NSLog(@" Children: %ld", [[self childList] count]); @@ -138,6 +112,28 @@ QDebug operator<<(QDebug dbg, AXErrorTag err) return list; } +- (NSArray *)tableRows +{ + NSArray *arr; + AXUIElementCopyAttributeValues( + reference, + kAXRowsAttribute, + 0, 100, /*min, max*/ + (CFArrayRef *) &arr); + return arr; +} + +- (NSArray *)tableColumns +{ + NSArray *arr; + AXUIElementCopyAttributeValues( + reference, + kAXColumnsAttribute, + 0, 100, /*min, max*/ + (CFArrayRef *) &arr); + return arr; +} + - (AXUIElementRef) findDirectChildByRole: (CFStringRef) role { TestAXObject *result = nil; @@ -232,8 +228,8 @@ QDebug operator<<(QDebug dbg, AXErrorTag err) CFTypeRef value = NULL; AXError err; - if (kAXErrorSuccess != (err = AXUIElementCopyAttributeValue(reference, attribute, &value))) - { + if (kAXErrorSuccess != (err = AXUIElementCopyAttributeValue(reference, attribute, &value))) { + axError = true; qDebug() << "AXUIElementCopyAttributeValue(" << QString::fromCFString(attribute) << ") returned error = " << AXErrorTag(err); } return value; @@ -279,8 +275,8 @@ QDebug operator<<(QDebug dbg, AXErrorTag err) CFTypeRef value = NULL; AXError err; - if (kAXErrorSuccess != (err = AXUIElementCopyParameterizedAttributeValue(reference, attribute, parameter, &value))) - { + if (kAXErrorSuccess != (err = AXUIElementCopyParameterizedAttributeValue(reference, attribute, parameter, &value))) { + axError = true; CFStringRef description = CFCopyDescription(parameter); qDebug() << "AXUIElementCopyParameterizedAttributeValue(" << QString::fromCFString(attribute) << ", parameter=" << QString::fromCFString(description) << ") returned error = " << AXErrorTag(err); CFRelease(description); @@ -318,8 +314,8 @@ QDebug operator<<(QDebug dbg, AXErrorTag err) AXError err; CFArrayRef actions; - if (kAXErrorSuccess != (err = AXUIElementCopyActionNames(reference, &actions))) - { + if (kAXErrorSuccess != (err = AXUIElementCopyActionNames(reference, &actions))) { + axError = true; qDebug() << "AXUIElementCopyActionNames(...) returned error = " << AXErrorTag(err); } @@ -330,8 +326,8 @@ QDebug operator<<(QDebug dbg, AXErrorTag err) { AXError err; - if (kAXErrorSuccess != (err = AXUIElementPerformAction(reference, action))) - { + if (kAXErrorSuccess != (err = AXUIElementPerformAction(reference, action))) { + axError = true; qDebug() << "AXUIElementPerformAction(" << QString::fromCFString(action) << ") returned error = " << AXErrorTag(err); } } @@ -366,66 +362,140 @@ 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); +} -bool singleWidget() +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(); + void tableViewTest(); + void treeViewTest(); + +private: + AccessibleTestWindow *m_window; +}; + + +void tst_QAccessibilityMac::init() +{ + m_window = new AccessibleTestWindow(); + m_window->setWindowTitle(QString("Test window - %1").arg(QTest::currentTestFunction())); + 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; + 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 - lineEditTest"]); // 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}, @@ -440,82 +510,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; + QVERIFY([[focusButton1 role] isEqualToString: NSAccessibilityButtonRole]); + QVERIFY([[focusButton1 title] isEqualToString: @"I am a button"]); } -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); -} - - -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); @@ -525,76 +594,215 @@ 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); + QVERIFY([cb valueNumber] == 2); +} + +void tst_QAccessibilityMac::tableViewTest() +{ + QTableWidget *tw = new QTableWidget(3, 2, m_window); + struct Person + { + const char *name; + const char *address; + }; + const Person contents[] = { { "Socrates", "Greece" }, + { "Confucius", "China" }, + { "Kant", "Preussia" } + }; + for (int i = 0; i < int(sizeof(contents) / sizeof(Person)); ++i) { + Person p = contents[i]; + QTableWidgetItem *name = new QTableWidgetItem(QString::fromLatin1(p.name)); + tw->setItem(i, 0, name); + QTableWidgetItem *address = new QTableWidgetItem(QString::fromLatin1(p.address)); + tw->setItem(i, 1, address); + } + m_window->addWidget(tw); + QVERIFY(QTest::qWaitForWindowExposed(m_window)); + QCoreApplication::processEvents(); + + TestAXObject *appObject = [TestAXObject getApplicationAXObject]; + QVERIFY(appObject); - return true; + NSArray *windowList = [appObject windowList]; + // one window + QVERIFY([windowList count] == 1); + AXUIElementRef windowRef = (AXUIElementRef)[windowList objectAtIndex:0]; + QVERIFY(windowRef != nil); + TestAXObject *window = [[TestAXObject alloc] initWithAXUIElementRef:windowRef]; + + // children of window: + AXUIElementRef tableView = [window findDirectChildByRole:kAXTableRole]; + QVERIFY(tableView != nil); + + TestAXObject *tv = [[TestAXObject alloc] initWithAXUIElementRef:tableView]; + + // here start actual tableview tests + // Should have 2 columns + const unsigned int columnCount = 2; + NSArray *columnArray = [tv tableColumns]; + QCOMPARE([columnArray count], columnCount); + + // should have 3 rows + const unsigned int rowCount = 3; + NSArray *rowArray = [tv tableRows]; + QCOMPARE([rowArray count], rowCount); + + // The individual cells are children of the rows + TestAXObject *row = [[TestAXObject alloc] initWithAXUIElementRef:(AXUIElementRef)rowArray[0]]; + TestAXObject *cell = [[TestAXObject alloc] initWithAXUIElementRef:(AXUIElementRef)[row childList][0]]; + QVERIFY([cell.title isEqualToString:@"Socrates"]); + row = [[TestAXObject alloc] initWithAXUIElementRef:(AXUIElementRef)rowArray[2]]; + cell = [[TestAXObject alloc] initWithAXUIElementRef:(AXUIElementRef)[row childList][1]]; + QVERIFY([cell.title isEqualToString:@"Preussia"]); + + // both rows and columns are direct children of the table + NSArray *childList = [tv childList]; + QCOMPARE([childList count], columnCount + rowCount); + for (id child in childList) { + TestAXObject *childObject = [[TestAXObject alloc] initWithAXUIElementRef:(AXUIElementRef)child]; + QVERIFY([childObject.role isEqualToString:NSAccessibilityRowRole] || + [childObject.role isEqualToString:NSAccessibilityColumnRole]); + } } + +void tst_QAccessibilityMac::treeViewTest() +{ + QTreeWidget *tw = new QTreeWidget; + tw->setColumnCount(2); + QTreeWidgetItem *root = new QTreeWidgetItem(tw, {"/", "0"}); + root->setExpanded(false); + QTreeWidgetItem *users = new QTreeWidgetItem(root,{ "Users", "1"}); + (void)new QTreeWidgetItem(root, {"Applications", "2"}); + QTreeWidgetItem *lastChild = new QTreeWidgetItem(root, {"Libraries", "3"}); + + m_window->addWidget(tw); + QVERIFY(QTest::qWaitForWindowExposed(m_window)); + QCoreApplication::processEvents(); + + TestAXObject *appObject = [TestAXObject getApplicationAXObject]; + QVERIFY(appObject); + + NSArray *windowList = [appObject windowList]; + // one window + QVERIFY([windowList count] == 1); + AXUIElementRef windowRef = (AXUIElementRef)[windowList objectAtIndex:0]; + QVERIFY(windowRef != nil); + TestAXObject *window = [[TestAXObject alloc] initWithAXUIElementRef:windowRef]; + + // children of window + AXUIElementRef treeView = [window findDirectChildByRole:kAXOutlineRole]; + QVERIFY(treeView != nil); + + TestAXObject *tv = [[TestAXObject alloc] initWithAXUIElementRef:treeView]; + + // here start actual treeview tests. NSAccessibilityOutline is a specialization + // of NSAccessibilityTable, and we represent trees as tables. + // Should have 2 columns + const unsigned int columnCount = 2; + NSArray *columnArray = [tv tableColumns]; + QCOMPARE([columnArray count], columnCount); + + // should have 1 row for now - as long as the root item is not expanded + NSArray *rowArray = [tv tableRows]; + QCOMPARE(int([rowArray count]), 1); + + root->setExpanded(true); + rowArray = [tv tableRows]; + QCOMPARE(int([rowArray count]), root->childCount() + 1); + + // this should not trigger any assert + tw->setCurrentItem(lastChild); + + bool errorOccurred = false; + + const auto cellText = [rowArray, &errorOccurred](int rowIndex, int columnIndex) -> QString { + TestAXObject *row = [[TestAXObject alloc] initWithAXUIElementRef:(AXUIElementRef)rowArray[rowIndex]]; + Q_ASSERT(row); + TestAXObject *cell = [[TestAXObject alloc] initWithAXUIElementRef:(AXUIElementRef)[row childList][columnIndex]]; + Q_ASSERT(cell); + const QString result = QString::fromNSString(cell.title); + errorOccurred = cell.errorOccurred; + return result; + }; + + QString text = cellText(0, 0); + if (errorOccurred) + QSKIP("Cocoa Accessibility API error, aborting"); + QCOMPARE(text, root->text(0)); + QCOMPARE(cellText(1, 0), users->text(0)); + QCOMPARE(cellText(1, 1), users->text(1)); +} + +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 58ea2d02b0..0000000000 --- a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#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/CMakeLists.txt b/tests/auto/other/qcomplextext/CMakeLists.txt index 3a86e9096b..74996c7ad7 100644 --- a/tests/auto/other/qcomplextext/CMakeLists.txt +++ b/tests/auto/other/qcomplextext/CMakeLists.txt @@ -1,16 +1,23 @@ -# Generated from qcomplextext.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qcomplextext Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qcomplextext LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data list(APPEND test_data "data") qt_internal_add_test(tst_qcomplextext SOURCES tst_qcomplextext.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/other/qcomplextext/bidireorderstring.h b/tests/auto/other/qcomplextext/bidireorderstring.h index b537bf45e4..831fd34883 100644 --- a/tests/auto/other/qcomplextext/bidireorderstring.h +++ b/tests/auto/other/qcomplextext/bidireorderstring.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only struct LV { const char *name; const char *logical; diff --git a/tests/auto/other/qcomplextext/tst_qcomplextext.cpp b/tests/auto/other/qcomplextext/tst_qcomplextext.cpp index 453dc23bcd..b8014126ed 100644 --- a/tests/auto/other/qcomplextext/tst_qcomplextext.cpp +++ b/tests/auto/other/qcomplextext/tst_qcomplextext.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtGui/QtGui> @@ -109,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; @@ -118,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; @@ -340,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; @@ -349,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; @@ -372,9 +347,7 @@ void tst_QComplexText::bidiCharacterTest() { QString testFile = QFINDTESTDATA("data/BidiCharacterTest.txt"); QFile f(testFile); - QVERIFY(f.exists()); - - f.open(QIODevice::ReadOnly); + QVERIFY(f.open(QIODevice::ReadOnly)); int linenum = 0; while (!f.atEnd()) { @@ -466,9 +439,7 @@ void tst_QComplexText::bidiTest() { QString testFile = QFINDTESTDATA("data/BidiTest.txt"); QFile f(testFile); - QVERIFY(f.exists()); - - f.open(QIODevice::ReadOnly); + QVERIFY(f.open(QIODevice::ReadOnly)); int linenum = 0; QList<int> resolvedLevels; diff --git a/tests/auto/other/qfocusevent/CMakeLists.txt b/tests/auto/other/qfocusevent/CMakeLists.txt index d7f8d5982a..61682af4e7 100644 --- a/tests/auto/other/qfocusevent/CMakeLists.txt +++ b/tests/auto/other/qfocusevent/CMakeLists.txt @@ -1,14 +1,22 @@ -# Generated from qfocusevent.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qfocusevent Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qfocusevent LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qfocusevent SOURCES tst_qfocusevent.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate Qt::Widgets + Qt::WidgetsPrivate ) diff --git a/tests/auto/other/qfocusevent/tst_qfocusevent.cpp b/tests/auto/other/qfocusevent/tst_qfocusevent.cpp index cd00f4cc9c..8297b53ea1 100644 --- a/tests/auto/other/qfocusevent/tst_qfocusevent.cpp +++ b/tests/auto/other/qfocusevent/tst_qfocusevent.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -41,6 +16,8 @@ #include <qpa/qplatformintegration.h> #include <private/qguiapplication_p.h> +#include <QtWidgets/private/qapplication_p.h> + QT_FORWARD_DECLARE_CLASS(QWidget) class FocusLineEdit : public QLineEdit @@ -137,7 +114,7 @@ void tst_QFocusEvent::initWidget() { // On X11 we have to ensure the event was processed before doing any checking, on Windows // this is processed straight away. - QApplication::setActiveWindow(testFocusWidget); + QApplicationPrivate::setActiveWindow(testFocusWidget); childFocusWidgetOne->setFocus(); // The first lineedit should have focus QVERIFY(QTest::qWaitForWindowActive(testFocusWidget)); QTRY_VERIFY(childFocusWidgetOne->hasFocus()); @@ -335,7 +312,6 @@ void tst_QFocusEvent::checkReason_ActiveWindow() QVERIFY(QTest::qWaitForWindowExposed(d)); d->activateWindow(); // ### CDE - QApplication::setActiveWindow(d); QVERIFY(QTest::qWaitForWindowActive(d)); QTRY_VERIFY(childFocusWidgetOne->focusOutEventRecieved); @@ -357,9 +333,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(); } @@ -369,6 +346,42 @@ void tst_QFocusEvent::checkReason_ActiveWindow() QVERIFY( childFocusWidgetOne->hasFocus() ); QVERIFY( childFocusWidgetOne->focusInEventRecieved ); QCOMPARE( childFocusWidgetOne->focusInEventReason, (int)Qt::ActiveWindowFocusReason); + + const bool windowActivationReasonFail = + QGuiApplication::platformName().toLower() == "minimal"; + + struct Window : public QWindow + { + Qt::FocusReason lastReason = Qt::NoFocusReason; + protected: + void focusInEvent(QFocusEvent *event) override + { + lastReason = event->reason(); + } + void focusOutEvent(QFocusEvent *event) override + { + lastReason = event->reason(); + } + }; + + Window window; + window.show(); + window.requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(&window)); + + if (windowActivationReasonFail) + QEXPECT_FAIL("", "Platform doesn't set window activation reason for QWindow", Continue); + QCOMPARE(window.lastReason, Qt::ActiveWindowFocusReason); + window.lastReason = Qt::NoFocusReason; + + Window window2; + window2.show(); + window2.requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(&window2)); + + if (windowActivationReasonFail) + QEXPECT_FAIL("", "Platform doesn't set window activation reason for QWindow", Continue); + QCOMPARE(window.lastReason, Qt::ActiveWindowFocusReason); } diff --git a/tests/auto/other/qnetworkaccessmanager_and_qprogressdialog/CMakeLists.txt b/tests/auto/other/qnetworkaccessmanager_and_qprogressdialog/CMakeLists.txt index e4041de233..313d9464a3 100644 --- a/tests/auto/other/qnetworkaccessmanager_and_qprogressdialog/CMakeLists.txt +++ b/tests/auto/other/qnetworkaccessmanager_and_qprogressdialog/CMakeLists.txt @@ -1,14 +1,22 @@ -# Generated from qnetworkaccessmanager_and_qprogressdialog.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qnetworkaccessmanager_and_qprogressdialog Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qnetworkaccessmanager_and_qprogressdialog LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qnetworkaccessmanager_and_qprogressdialog SOURCES tst_qnetworkaccessmanager_and_qprogressdialog.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::Network Qt::Widgets + QT_TEST_SERVER_LIST "apache2" ) diff --git a/tests/auto/other/qnetworkaccessmanager_and_qprogressdialog/tst_qnetworkaccessmanager_and_qprogressdialog.cpp b/tests/auto/other/qnetworkaccessmanager_and_qprogressdialog/tst_qnetworkaccessmanager_and_qprogressdialog.cpp index a321900df2..c665068f72 100644 --- a/tests/auto/other/qnetworkaccessmanager_and_qprogressdialog/tst_qnetworkaccessmanager_and_qprogressdialog.cpp +++ b/tests/auto/other/qnetworkaccessmanager_and_qprogressdialog/tst_qnetworkaccessmanager_and_qprogressdialog.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -68,13 +43,13 @@ public: public slots: void go() { - QNetworkRequest request(QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/bigfile")); + QNetworkRequest request(QUrl("http://" + QtNetworkSettings::httpServerName() + "/qtest/bigfile")); if (zeroCopy) request.setAttribute(QNetworkRequest::MaximumDownloadBufferSizeAttribute, 10*1024*1024); QNetworkReply *reply = netmanager.get( QNetworkRequest( - QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/bigfile") + QUrl("http://" + QtNetworkSettings::httpServerName() + "/qtest/bigfile") )); connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(dataReadProgress(qint64,qint64))); @@ -117,8 +92,13 @@ tst_QNetworkAccessManager_And_QProgressDialog::tst_QNetworkAccessManager_And_QPr void tst_QNetworkAccessManager_And_QProgressDialog::initTestCase() { +#ifdef QT_TEST_SERVER + if (!QtNetworkSettings::verifyConnection(QtNetworkSettings::httpServerName(), 80)) + QSKIP("No network test server available"); +#else if (!QtNetworkSettings::verifyTestNetworkSettings()) QSKIP("No network test server available"); +#endif } void tst_QNetworkAccessManager_And_QProgressDialog::downloadCheck_data() diff --git a/tests/auto/other/qobjectrace/CMakeLists.txt b/tests/auto/other/qobjectrace/CMakeLists.txt index 7a2be39d81..6516c9ee73 100644 --- a/tests/auto/other/qobjectrace/CMakeLists.txt +++ b/tests/auto/other/qobjectrace/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qobjectrace.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## qobjectrace Test: ##################################################################### -qt_internal_add_test(qobjectrace +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qobjectrace LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qobjectrace SOURCES tst_qobjectrace.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::TestPrivate ) diff --git a/tests/auto/other/qobjectrace/tst_qobjectrace.cpp b/tests/auto/other/qobjectrace/tst_qobjectrace.cpp index 093b4d2476..af6634f253 100644 --- a/tests/auto/other/qobjectrace/tst_qobjectrace.cpp +++ b/tests/auto/other/qobjectrace/tst_qobjectrace.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtCore> @@ -32,6 +7,8 @@ #include <QtTest/private/qemulationdetector_p.h> +#include <optional> + enum { OneMinute = 60 * 1000, TwoMinutes = OneMinute * 2 }; @@ -44,12 +21,20 @@ struct Functor class tst_QObjectRace: public QObject { Q_OBJECT +public: + tst_QObjectRace() + : ThreadCount(QThread::idealThreadCount()) + {} + private slots: void moveToThreadRace(); void destroyRace(); void blockingQueuedDestroyRace(); void disconnectRace(); void disconnectRace2(); + +private: + const int ThreadCount; }; class RaceObject : public QObject @@ -133,8 +118,7 @@ void tst_QObjectRace::moveToThreadRace() { RaceObject *object = new RaceObject; - enum { ThreadCount = 6 }; - RaceThread *threads[ThreadCount]; + QVarLengthArray<RaceThread *, 16> threads(ThreadCount); for (int i = 0; i < ThreadCount; ++i) { threads[i] = new RaceThread; threads[i]->setObject(object); @@ -264,10 +248,10 @@ void tst_QObjectRace::destroyRace() if (QTestPrivate::isRunningArmOnX86()) QSKIP("Test is too slow to run on emulator"); - enum { ThreadCount = 10, ObjectCountPerThread = 2777, - ObjectCount = ThreadCount * ObjectCountPerThread }; + constexpr int ObjectCountPerThread = 2777; + const int ObjectCount = ThreadCount * ObjectCountPerThread; - MyObject *objects[ObjectCount]; + QVarLengthArray<MyObject *, ObjectCountPerThread * 10> objects(ObjectCount); for (int i = 0; i < ObjectCount; ++i) objects[i] = new MyObject; @@ -284,10 +268,10 @@ void tst_QObjectRace::destroyRace() objects[((i+5)*79) % ObjectCount], Functor() ); } - DestroyThread *threads[ThreadCount]; + QVarLengthArray<DestroyThread *, 16> threads(ThreadCount); for (int i = 0; i < ThreadCount; ++i) { threads[i] = new DestroyThread; - threads[i]->setObjects(objects + i*ObjectCountPerThread, ObjectCountPerThread); + threads[i]->setObjects(objects.data() + i*ObjectCountPerThread, ObjectCountPerThread); } for (int i = 0; i < ThreadCount; ++i) @@ -325,8 +309,7 @@ public slots: break; } - Q_UNREACHABLE(); - return false; + Q_UNREACHABLE_RETURN(false); } private: @@ -335,9 +318,6 @@ private: void tst_QObjectRace::blockingQueuedDestroyRace() { -#if !QT_CONFIG(cxx11_future) - QSKIP("This test requires QThread::create"); -#else enum { MinIterations = 100, MinTime = 3000, WaitTime = 25 }; BlockingQueuedDestroyRaceObject sender; @@ -347,17 +327,13 @@ void tst_QObjectRace::blockingQueuedDestroyRace() while (iteration++ < MinIterations || !timer.hasExpired()) { // Manually allocate some storage, and create a receiver in there - std::aligned_storage< - sizeof(BlockingQueuedDestroyRaceObject), - alignof(BlockingQueuedDestroyRaceObject) - >::type storage; + std::optional<BlockingQueuedDestroyRaceObject> receiver; - auto *receiver = reinterpret_cast<BlockingQueuedDestroyRaceObject *>(&storage); - new (receiver) BlockingQueuedDestroyRaceObject(BlockingQueuedDestroyRaceObject::Behavior::Normal); + receiver.emplace(BlockingQueuedDestroyRaceObject::Behavior::Normal); // Connect it to the sender via BlockingQueuedConnection QVERIFY(connect(&sender, &BlockingQueuedDestroyRaceObject::aSignal, - receiver, &BlockingQueuedDestroyRaceObject::aSlot, + &*receiver, &BlockingQueuedDestroyRaceObject::aSlot, Qt::BlockingQueuedConnection)); const auto emitUntilDestroyed = [&sender] { @@ -379,17 +355,14 @@ void tst_QObjectRace::blockingQueuedDestroyRace() // - the metacall event to be posted to a destroyed object; // - the metacall event to be posted to the wrong object. // In both cases we hope to catch the race by crashing. - receiver->~BlockingQueuedDestroyRaceObject(); - new (receiver) BlockingQueuedDestroyRaceObject(BlockingQueuedDestroyRaceObject::Behavior::Crash); + receiver.reset(); + receiver.emplace(BlockingQueuedDestroyRaceObject::Behavior::Crash); // Flush events QTest::qWait(0); thread->wait(); - - receiver->~BlockingQueuedDestroyRaceObject(); } -#endif } static QAtomicInteger<unsigned> countedStructObjectsCount; @@ -506,7 +479,7 @@ public: void tst_QObjectRace::disconnectRace() { - enum { ThreadCount = 20, TimeLimit = 3000 }; + enum { TimeLimit = 3000 }; QCOMPARE(countedStructObjectsCount.loadRelaxed(), 0u); @@ -516,7 +489,7 @@ void tst_QObjectRace::disconnectRace() senderThread->start(); sender->moveToThread(senderThread.data()); - DisconnectRaceThread *threads[ThreadCount]; + QVarLengthArray<DisconnectRaceThread *, 16> threads(ThreadCount); for (int i = 0; i < ThreadCount; ++i) { threads[i] = new DisconnectRaceThread(sender.data(), !(i % 10)); threads[i]->start(); @@ -542,7 +515,7 @@ void tst_QObjectRace::disconnectRace() senderThread->start(); sender->moveToThread(senderThread.data()); - DeleteReceiverRaceReceiverThread *threads[ThreadCount]; + QVarLengthArray<DeleteReceiverRaceReceiverThread *, 16> threads(ThreadCount); for (int i = 0; i < ThreadCount; ++i) { threads[i] = new DeleteReceiverRaceReceiverThread(sender.data()); threads[i]->start(); diff --git a/tests/auto/other/qprocess_and_guieventloop/CMakeLists.txt b/tests/auto/other/qprocess_and_guieventloop/CMakeLists.txt index 126feeeb2d..3383677009 100644 --- a/tests/auto/other/qprocess_and_guieventloop/CMakeLists.txt +++ b/tests/auto/other/qprocess_and_guieventloop/CMakeLists.txt @@ -1,13 +1,21 @@ -# Generated from qprocess_and_guieventloop.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qprocess_and_guieventloop Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qprocess_and_guieventloop LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qprocess_and_guieventloop SOURCES tst_qprocess_and_guieventloop.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) add_subdirectory(write-read-write) +add_dependencies(tst_qprocess_and_guieventloop write-read-write) 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 a21bb9a005..b5b8c4cfc3 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 @@ -1,31 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Copyright (C) 2016 Intel Corporation. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2021 The Qt Company Ltd. +// Copyright (C) 2016 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtGui/QGuiApplication> #include <QTest> @@ -60,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 } diff --git a/tests/auto/other/qprocess_and_guieventloop/write-read-write/CMakeLists.txt b/tests/auto/other/qprocess_and_guieventloop/write-read-write/CMakeLists.txt index b395ebf1a4..2bc1ebb7b0 100644 --- a/tests/auto/other/qprocess_and_guieventloop/write-read-write/CMakeLists.txt +++ b/tests/auto/other/qprocess_and_guieventloop/write-read-write/CMakeLists.txt @@ -1,5 +1,12 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + ##################################################################### ## write-read-write Binary: ##################################################################### -add_executable(write-read-write main.cpp) +qt_internal_add_executable(write-read-write + OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/" + SOURCES + main.cpp +) diff --git a/tests/auto/other/qprocess_and_guieventloop/write-read-write/main.cpp b/tests/auto/other/qprocess_and_guieventloop/write-read-write/main.cpp index 5e75f7db3c..126c85dfd7 100644 --- a/tests/auto/other/qprocess_and_guieventloop/write-read-write/main.cpp +++ b/tests/auto/other/qprocess_and_guieventloop/write-read-write/main.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Intel Corporation. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <stdio.h> diff --git a/tests/auto/other/qsharedpointer_and_qwidget/CMakeLists.txt b/tests/auto/other/qsharedpointer_and_qwidget/CMakeLists.txt index 448d0fd313..a405f54151 100644 --- a/tests/auto/other/qsharedpointer_and_qwidget/CMakeLists.txt +++ b/tests/auto/other/qsharedpointer_and_qwidget/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qsharedpointer_and_qwidget.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qsharedpointer_and_qwidget Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qsharedpointer_and_qwidget LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qsharedpointer_and_qwidget SOURCES tst_qsharedpointer_and_qwidget.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::Widgets ) diff --git a/tests/auto/other/qsharedpointer_and_qwidget/tst_qsharedpointer_and_qwidget.cpp b/tests/auto/other/qsharedpointer_and_qwidget/tst_qsharedpointer_and_qwidget.cpp index 38fc547335..5fa9d8740a 100644 --- a/tests/auto/other/qsharedpointer_and_qwidget/tst_qsharedpointer_and_qwidget.cpp +++ b/tests/auto/other/qsharedpointer_and_qwidget/tst_qsharedpointer_and_qwidget.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtWidgets/QWidget> #include <QtWidgets/QPushButton> diff --git a/tests/auto/other/qvariant_common/tst_qvariant_common.h b/tests/auto/other/qvariant_common/tst_qvariant_common.h index 70a44ad10f..553c396e47 100644 --- a/tests/auto/other/qvariant_common/tst_qvariant_common.h +++ b/tests/auto/other/qvariant_common/tst_qvariant_common.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef TST_QVARIANT_COMMON #define TST_QVARIANT_COMMON diff --git a/tests/auto/other/sessionmanagement_macos/tst_sessionmanagement_macos.mm b/tests/auto/other/sessionmanagement_macos/tst_sessionmanagement_macos.mm index eac31444c7..02a3464ec7 100644 --- a/tests/auto/other/sessionmanagement_macos/tst_sessionmanagement_macos.mm +++ b/tests/auto/other/sessionmanagement_macos/tst_sessionmanagement_macos.mm @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2019 Samuel Gaist <samuel.gaist@idiap.ch> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2019 Samuel Gaist <samuel.gaist@idiap.ch> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/other/toolsupport/BLACKLIST b/tests/auto/other/toolsupport/BLACKLIST deleted file mode 100644 index 6a4d5aece5..0000000000 --- a/tests/auto/other/toolsupport/BLACKLIST +++ /dev/null @@ -1,3 +0,0 @@ -# QTBUG-87396 -[offsets] -android diff --git a/tests/auto/other/toolsupport/CMakeLists.txt b/tests/auto/other/toolsupport/CMakeLists.txt index 686d702a23..5b2cc0c0e2 100644 --- a/tests/auto/other/toolsupport/CMakeLists.txt +++ b/tests/auto/other/toolsupport/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from toolsupport.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_toolsupport Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_toolsupport LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_toolsupport SOURCES tst_toolsupport.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate ) diff --git a/tests/auto/other/toolsupport/tst_toolsupport.cpp b/tests/auto/other/toolsupport/tst_toolsupport.cpp index 7ba4286a4d..965b55977c 100644 --- a/tests/auto/other/toolsupport/tst_toolsupport.cpp +++ b/tests/auto/other/toolsupport/tst_toolsupport.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2015 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -63,6 +38,7 @@ template <typename T, typename K> size_t pmm_to_offsetof(T K:: *pmm) { #ifdef Q_CC_MSVC + // Even on 64 bit MSVC uses 4 byte offsets. quint32 ret; #else @@ -139,12 +115,12 @@ void tst_toolsupport::offsets_data() QTestData &data = QTest::newRow("QFilePrivate::fileName") << pmm_to_offsetof(&QFilePrivate::fileName); // Please heed the comment at the top of this file when changing one of these lines: -#ifdef Q_PROCESSOR_X86 +#ifdef Q_PROCESSOR_X86_32 // x86 32-bit has weird alignment rules. Refer to QtPrivate::AlignOf in // qglobal.h for more details. - data << 188 << 304; + data << 264 << -1; #else - data << 196 << 304; + data << 300 << 424; #endif } #endif diff --git a/tests/auto/other/xkbkeyboard/CMakeLists.txt b/tests/auto/other/xkbkeyboard/CMakeLists.txt index 206f128cf8..06e471c68b 100644 --- a/tests/auto/other/xkbkeyboard/CMakeLists.txt +++ b/tests/auto/other/xkbkeyboard/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from xkbkeyboard.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_xkbkeyboard Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_xkbkeyboard LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_xkbkeyboard SOURCES tst_xkbkeyboard.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::GuiPrivate ) diff --git a/tests/auto/other/xkbkeyboard/tst_xkbkeyboard.cpp b/tests/auto/other/xkbkeyboard/tst_xkbkeyboard.cpp index 6a3fe73829..323693bb84 100644 --- a/tests/auto/other/xkbkeyboard/tst_xkbkeyboard.cpp +++ b/tests/auto/other/xkbkeyboard/tst_xkbkeyboard.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtCore> #include <QtGui> |