diff options
Diffstat (limited to 'tests/auto/gui')
336 files changed, 11865 insertions, 2259 deletions
diff --git a/tests/auto/gui/CMakeLists.txt b/tests/auto/gui/CMakeLists.txt index 7ba124952d..b0fb8891f5 100644 --- a/tests/auto/gui/CMakeLists.txt +++ b/tests/auto/gui/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from gui.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause add_subdirectory(kernel) if(NOT UIKIT) diff --git a/tests/auto/gui/image/CMakeLists.txt b/tests/auto/gui/image/CMakeLists.txt index 27916d0409..c7fc6f07d3 100644 --- a/tests/auto/gui/image/CMakeLists.txt +++ b/tests/auto/gui/image/CMakeLists.txt @@ -1,6 +1,7 @@ -# Generated from image.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause -# QTBUG-87669 # special case +# QTBUG-87669 if(TARGET Qt::Network AND NOT ANDROID) add_subdirectory(qimagereader) endif() @@ -11,13 +12,15 @@ add_subdirectory(qpixmap) add_subdirectory(qimage) add_subdirectory(qimageiohandler) add_subdirectory(qimagewriter) -add_subdirectory(qmovie) -add_subdirectory(qpicture) +if(QT_FEATURE_movie) + add_subdirectory(qmovie) +endif() +if(QT_FEATURE_picture) + add_subdirectory(qpicture) +endif() add_subdirectory(qiconhighdpi) if(QT_FEATURE_private_tests) add_subdirectory(qpixmapcache) endif() -# QTBUG-87669 # special case -if(NOT ANDROID) - add_subdirectory(qicon) -endif() + +add_subdirectory(qicon) diff --git a/tests/auto/gui/image/qicoimageformat/CMakeLists.txt b/tests/auto/gui/image/qicoimageformat/CMakeLists.txt index 9e77aad1fe..17ec68df4e 100644 --- a/tests/auto/gui/image/qicoimageformat/CMakeLists.txt +++ b/tests/auto/gui/image/qicoimageformat/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from qicoimageformat.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qicoimageformat Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qicoimageformat LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data file(GLOB_RECURSE test_data_glob RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} @@ -13,7 +20,7 @@ list(APPEND test_data ${test_data_glob}) qt_internal_add_test(tst_qicoimageformat SOURCES tst_qicoimageformat.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui TESTDATA ${test_data} ) diff --git a/tests/auto/gui/image/qicoimageformat/icons/masked/24bpp.ico b/tests/auto/gui/image/qicoimageformat/icons/masked/24bpp.ico Binary files differnew file mode 100644 index 0000000000..7e9cfa2414 --- /dev/null +++ b/tests/auto/gui/image/qicoimageformat/icons/masked/24bpp.ico diff --git a/tests/auto/gui/image/qicoimageformat/icons/masked/24bpp.png b/tests/auto/gui/image/qicoimageformat/icons/masked/24bpp.png Binary files differnew file mode 100644 index 0000000000..f0a19c05e3 --- /dev/null +++ b/tests/auto/gui/image/qicoimageformat/icons/masked/24bpp.png diff --git a/tests/auto/gui/image/qicoimageformat/icons/masked/32bpp.ico b/tests/auto/gui/image/qicoimageformat/icons/masked/32bpp.ico Binary files differnew file mode 100644 index 0000000000..a22248d76a --- /dev/null +++ b/tests/auto/gui/image/qicoimageformat/icons/masked/32bpp.ico diff --git a/tests/auto/gui/image/qicoimageformat/icons/masked/32bpp.png b/tests/auto/gui/image/qicoimageformat/icons/masked/32bpp.png Binary files differnew file mode 100644 index 0000000000..a6ceac73fa --- /dev/null +++ b/tests/auto/gui/image/qicoimageformat/icons/masked/32bpp.png diff --git a/tests/auto/gui/image/qicoimageformat/tst_qicoimageformat.cpp b/tests/auto/gui/image/qicoimageformat/tst_qicoimageformat.cpp index 47bfb5bca5..136f56facf 100644 --- a/tests/auto/gui/image/qicoimageformat/tst_qicoimageformat.cpp +++ b/tests/auto/gui/image/qicoimageformat/tst_qicoimageformat.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtGui> #include <QtCore> @@ -27,6 +27,8 @@ private slots: void pngCompression(); void write_data(); void write(); + void icoMask_data(); + void icoMask(); private: QString m_IconPath; @@ -319,6 +321,33 @@ void tst_QIcoImageFormat::write() } } +void tst_QIcoImageFormat::icoMask_data() +{ + QTest::addColumn<QString>("inFile"); + QTest::addColumn<QString>("outFile"); + + QTest::newRow("24bpp") << "masked/24bpp.ico" << "masked/24bpp.png"; + QTest::newRow("32bpp") << "masked/32bpp.ico" << "masked/32bpp.png"; +} + +void tst_QIcoImageFormat::icoMask() +{ + QFETCH(QString, inFile); + QFETCH(QString, outFile); + + QImage inImage; + QImageReader inReader(m_IconPath + QLatin1Char('/') + inFile); + inReader.read(&inImage); + + QImage outImage; + QImageReader outReader(m_IconPath + QLatin1Char('/') + outFile); + outReader.read(&outImage); + outImage.setColorSpace(inImage.colorSpace()); + outImage = outImage.convertToFormat(inImage.format()); + + QCOMPARE(inImage, outImage); +} + QTEST_MAIN(tst_QIcoImageFormat) #include "tst_qicoimageformat.moc" diff --git a/tests/auto/gui/image/qicon/CMakeLists.txt b/tests/auto/gui/image/qicon/CMakeLists.txt index 5f6b139205..93f75741c0 100644 --- a/tests/auto/gui/image/qicon/CMakeLists.txt +++ b/tests/auto/gui/image/qicon/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from qicon.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qicon Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qicon LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data file(GLOB_RECURSE test_data_glob RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} @@ -30,11 +37,14 @@ file(GLOB_RECURSE test_data_glob *.svgz) list(APPEND test_data ${test_data_glob}) +add_subdirectory(plugin) + qt_internal_add_test(tst_qicon SOURCES tst_qicon.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui + TestIconPlugin TESTDATA ${test_data} ) @@ -55,6 +65,10 @@ set(tst_qicon_resource_files "./icons/themeparent/index.theme" "./icons/themeparent/scalable/actions/address-book-new.svg" "./icons/themeparent/scalable/actions/appointment-new.svg" + "./icons/fallbacktheme/index.theme" + "./icons/fallbacktheme/16x16/edit-cut.png" + "./icons/hicolor/index.theme" + "./icons/hicolor/16x16/hicolor-icon.png" "./second_icons/testtheme/32x32/actions/appointment-new.png" "./styles/commonstyle/images/standardbutton-open-128.png" "./styles/commonstyle/images/standardbutton-open-16.png" @@ -91,6 +105,8 @@ qt_internal_add_resource(tst_qicon "qmake_immediate" ##################################################################### qt_internal_extend_target(tst_qicon CONDITION TARGET Qt::Widgets - PUBLIC_LIBRARIES + LIBRARIES Qt::Widgets ) + +add_dependencies(tst_qicon TestIconPlugin) diff --git a/tests/auto/gui/image/qicon/icons/fallbacktheme/16x16/edit-cut.png b/tests/auto/gui/image/qicon/icons/fallbacktheme/16x16/edit-cut.png Binary files differnew file mode 100644 index 0000000000..661ef1ad03 --- /dev/null +++ b/tests/auto/gui/image/qicon/icons/fallbacktheme/16x16/edit-cut.png diff --git a/tests/auto/gui/image/qicon/icons/fallbacktheme/index.theme b/tests/auto/gui/image/qicon/icons/fallbacktheme/index.theme new file mode 100644 index 0000000000..809d296669 --- /dev/null +++ b/tests/auto/gui/image/qicon/icons/fallbacktheme/index.theme @@ -0,0 +1,8 @@ +[Icon Theme] +Name=fallbacktheme + +Directories=16x16 + +[16x16] +Size=16 +Type=Fixed diff --git a/tests/auto/gui/image/qicon/icons/hicolor/16x16/hicolor-icon.png b/tests/auto/gui/image/qicon/icons/hicolor/16x16/hicolor-icon.png Binary files differnew file mode 100644 index 0000000000..661ef1ad03 --- /dev/null +++ b/tests/auto/gui/image/qicon/icons/hicolor/16x16/hicolor-icon.png diff --git a/tests/auto/gui/image/qicon/icons/hicolor/index.theme b/tests/auto/gui/image/qicon/icons/hicolor/index.theme new file mode 100644 index 0000000000..e5e5cef9b1 --- /dev/null +++ b/tests/auto/gui/image/qicon/icons/hicolor/index.theme @@ -0,0 +1,11 @@ +[Icon Theme] +Name=hicolor + +# Provide a minimal hicolor theme, so that our hicolor fallback +# lookup during testing will find that theme on all systems. + +Directories=16x16 + +[16x16] +Size=16 +Type=Fixed diff --git a/tests/auto/gui/image/qicon/icons/testtheme/index.theme b/tests/auto/gui/image/qicon/icons/testtheme/index.theme index e18736ab43..53664b14b2 100644 --- a/tests/auto/gui/image/qicon/icons/testtheme/index.theme +++ b/tests/auto/gui/image/qicon/icons/testtheme/index.theme @@ -1,7 +1,7 @@ [Icon Theme] _Name=Test _Comment=Test Theme -Inherits=crystalsvg, themeparent +Inherits=themeparent Example=x-directory-normal # KDE Specific Stuff diff --git a/tests/auto/gui/image/qicon/icons/themeparent/index.theme b/tests/auto/gui/image/qicon/icons/themeparent/index.theme index e536a0bf2f..96267addd6 100644 --- a/tests/auto/gui/image/qicon/icons/themeparent/index.theme +++ b/tests/auto/gui/image/qicon/icons/themeparent/index.theme @@ -1,7 +1,6 @@ [Icon Theme] _Name=Test _Comment=Test Theme -Inherits=gnome,crystalsvg Example=x-directory-normal # KDE Specific Stuff diff --git a/tests/auto/gui/image/qicon/plugin/CMakeLists.txt b/tests/auto/gui/image/qicon/plugin/CMakeLists.txt new file mode 100644 index 0000000000..cae49b2df1 --- /dev/null +++ b/tests/auto/gui/image/qicon/plugin/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## TestIconEngine Plugin: +##################################################################### + +qt_internal_add_plugin(TestIconPlugin + STATIC + OUTPUT_NAME qtesticonplugin + OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" + SKIP_INSTALL + PLUGIN_TYPE iconengines + DEFAULT_IF TRUE + SOURCES + main.cpp + LIBRARIES + Qt::Core + Qt::Gui +) diff --git a/tests/auto/gui/image/qicon/plugin/main.cpp b/tests/auto/gui/image/qicon/plugin/main.cpp new file mode 100644 index 0000000000..58d9807142 --- /dev/null +++ b/tests/auto/gui/image/qicon/plugin/main.cpp @@ -0,0 +1,73 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <qiconengineplugin.h> +#include <qiconengine.h> + +QT_BEGIN_NAMESPACE + +class TestIconPlugin : public QIconEnginePlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QIconEngineFactoryInterface" FILE "plugin.json") + +public: + QIconEngine *create(const QString &icon) override; +}; + +class TestIconEngine : public QIconEngine +{ +public: + TestIconEngine(const QString &icon) + : m_iconName(QIcon::themeName() + "/" + icon) + { + } + + ~TestIconEngine() + {} + + QIconEngine *clone() const override + { + return new TestIconEngine(m_iconName); + } + + QString key() const override + { + return QStringLiteral("TestIconEngine"); + } + + QString iconName() override + { + return m_iconName; + } + + bool isNull() override + { + return m_iconName.isNull(); + } + + QList<QSize> availableSizes(QIcon::Mode, QIcon::State) override + { + return {{16, 16}, {48, 48}, {64, 64}}; + } + + void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override + { + Q_UNUSED(painter); + Q_UNUSED(rect); + Q_UNUSED(mode); + Q_UNUSED(state); + } + +private: + const QString m_iconName; +}; + +QIconEngine *TestIconPlugin::create(const QString &icon) +{ + return new TestIconEngine(icon); +} + +QT_END_NAMESPACE + +#include "main.moc" diff --git a/tests/auto/gui/image/qicon/plugin/plugin.json b/tests/auto/gui/image/qicon/plugin/plugin.json new file mode 100644 index 0000000000..96b59aa79e --- /dev/null +++ b/tests/auto/gui/image/qicon/plugin/plugin.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "plugintheme", "SpecialTheme" ] +} diff --git a/tests/auto/gui/image/qicon/tst_qicon.cpp b/tests/auto/gui/image/qicon/tst_qicon.cpp index 514a2d9bcf..d95ee66fb6 100644 --- a/tests/auto/gui/image/qicon/tst_qicon.cpp +++ b/tests/auto/gui/image/qicon/tst_qicon.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QImageReader> @@ -41,12 +41,16 @@ private slots: void streamAvailableSizes(); void fromTheme(); void fromThemeCache(); + void fromThemeConstant(); #ifndef QT_NO_WIDGETS void task184901_badCache(); #endif void task223279_inconsistentAddFile(); + void themeFromPlugin_data(); + void themeFromPlugin(); + private: bool haveImageFormat(QByteArray const&); @@ -191,21 +195,21 @@ void tst_QIcon::isNull() { // test string constructor with empty string QIcon iconEmptyString = QIcon(QString()); QVERIFY(iconEmptyString.isNull()); - QVERIFY(!iconEmptyString.actualSize(QSize(32, 32)).isValid());; + QVERIFY(!iconEmptyString.actualSize(QSize(32, 32)).isValid()); // test string constructor with non-existing file QIcon iconNoFile = QIcon("imagedoesnotexist"); - QVERIFY(!iconNoFile.isNull()); + QVERIFY(iconNoFile.isNull()); QVERIFY(!iconNoFile.actualSize(QSize(32, 32)).isValid()); // test string constructor with non-existing file with suffix QIcon iconNoFileSuffix = QIcon("imagedoesnotexist.png"); - QVERIFY(!iconNoFileSuffix.isNull()); + QVERIFY(iconNoFileSuffix.isNull()); QVERIFY(!iconNoFileSuffix.actualSize(QSize(32, 32)).isValid()); // test string constructor with existing file but unsupported format QIcon iconUnsupportedFormat = QIcon(m_sourceFileName); - QVERIFY(!iconUnsupportedFormat.isNull()); + QVERIFY(iconUnsupportedFormat.isNull()); QVERIFY(!iconUnsupportedFormat.actualSize(QSize(32, 32)).isValid()); // test string constructor with existing file and supported format @@ -552,6 +556,10 @@ void tst_QIcon::availableSizes() void tst_QIcon::name() { + const auto reset = qScopeGuard([]{ + QIcon::setThemeName({}); + QIcon::setThemeSearchPaths({}); + }); { // No name if icon does not come from a theme QIcon icon(":/image.png"); @@ -629,6 +637,7 @@ void tst_QIcon::task184901_badCache() void tst_QIcon::fromTheme() { + const bool abIconFromPlatform = !QIcon::fromTheme("address-book-new").isNull(); QString firstSearchPath = QLatin1String(":/icons"); QString secondSearchPath = QLatin1String(":/second_icons"); QIcon::setThemeSearchPaths(QStringList() << firstSearchPath << secondSearchPath); @@ -717,14 +726,44 @@ void tst_QIcon::fromTheme() QCOMPARE(i.availableSizes(), abIcon.availableSizes()); } + // Setting or changing the fallback theme should invalidate earlier lookups. + // We can only test this if the system doesn't provide an icon, because once + // we got a valid icon, it will be cached, and even if we proxy to a different + // engine when a fallback theme is set, the cacheKey of the icon will be the + // same. + const QIcon editCut = QIcon::fromTheme("edit-cut"); + if (editCut.isNull()) { + QIcon::setFallbackThemeName("fallbacktheme"); + QVERIFY(!QIcon::fromTheme("edit-cut").isNull()); + } + // Make sure setting the theme name clears the state QIcon::setThemeName(""); abIcon = QIcon::fromTheme("address-book-new"); - QVERIFY(abIcon.isNull()); + QCOMPARE_NE(abIcon.isNull(), abIconFromPlatform); + + // Test fallback icon behavior for empty theme names. + // Can only reliably test this on systems that don't have a + // named system icon theme. + QIcon::setThemeName(""); // Reset user-theme + if (QIcon::themeName().isEmpty()) { + // Test icon from fallback theme even when theme name is empty + QIcon::setFallbackThemeName("fallbacktheme"); + QVERIFY(!QIcon::fromTheme("edit-cut").isNull()); + + // Test icon from fallback path even when theme name is empty + fallbackIcon = QIcon::fromTheme("red"); + QVERIFY(!fallbackIcon.isNull()); + QVERIFY(QIcon::hasThemeIcon("red")); + QCOMPARE(fallbackIcon.availableSizes().size(), 1); + } // Passing a full path to fromTheme is not very useful, but should work anyway QIcon fullPathIcon = QIcon::fromTheme(m_pngImageFileName); QVERIFY(!fullPathIcon.isNull()); + + // Restore to system fallback theme + QIcon::setFallbackThemeName(""); } static inline QString findGtkUpdateIconCache() @@ -785,7 +824,7 @@ void tst_QIcon::fromThemeCache() QTest::qWait(1000); // wait enough to have a different modification time in seconds QVERIFY(QFile(QStringLiteral(":/styles/commonstyle/images/standardbutton-save-16.png")) .copy(dir.path() + QLatin1String("/testcache/16x16/actions/button-save.png"))); - QVERIFY(QFileInfo(cacheName).lastModified() < QFileInfo(dir.path() + QLatin1String("/testcache/16x16/actions")).lastModified()); + QVERIFY(QFileInfo(cacheName).lastModified(QTimeZone::UTC) < QFileInfo(dir.path() + QLatin1String("/testcache/16x16/actions")).lastModified(QTimeZone::UTC)); QIcon::setThemeSearchPaths(QStringList() << dir.path()); // reload themes QVERIFY(!QIcon::fromTheme("button-open").isNull()); @@ -806,13 +845,18 @@ void tst_QIcon::fromThemeCache() QCOMPARE(process.exitStatus(), QProcess::NormalExit); QCOMPARE(process.exitCode(), 0); #endif // QT_CONFIG(process) - QVERIFY(QFileInfo(cacheName).lastModified() >= QFileInfo(dir.path() + QLatin1String("/testcache/16x16/actions")).lastModified()); + QVERIFY(QFileInfo(cacheName).lastModified(QTimeZone::UTC) >= QFileInfo(dir.path() + QLatin1String("/testcache/16x16/actions")).lastModified(QTimeZone::UTC)); QIcon::setThemeSearchPaths(QStringList() << dir.path()); // reload themes QVERIFY(!QIcon::fromTheme("button-open").isNull()); QVERIFY(!QIcon::fromTheme("button-open-fallback").isNull()); QVERIFY(QIcon::fromTheme("notexist-fallback").isNull()); } +void tst_QIcon::fromThemeConstant() +{ + const QIcon icon = QIcon::fromTheme(QIcon::ThemeIcon::EditCut); +} + void tst_QIcon::task223279_inconsistentAddFile() { QIcon icon1; @@ -831,6 +875,32 @@ void tst_QIcon::task223279_inconsistentAddFile() QCOMPARE(pm1.size(), pm2.size()); } +Q_IMPORT_PLUGIN(TestIconPlugin) + +void tst_QIcon::themeFromPlugin_data() +{ + QTest::addColumn<QString>("themeName"); + + QTest::addRow("plugintheme") << "plugintheme"; + QTest::addRow("specialtheme") << "specialTheme"; // deliberately not matching case +} + +void tst_QIcon::themeFromPlugin() +{ + QFETCH(const QString, themeName); + auto restoreTheme = qScopeGuard([oldTheme = QIcon::themeName()]{ + QIcon::setThemeName(oldTheme); + }); + + QIcon icon = QIcon::fromTheme("icon1"); + QVERIFY(icon.isNull()); + + QIcon::setThemeName(themeName); + + icon = QIcon::fromTheme("icon1"); + QVERIFY(!icon.isNull()); + QCOMPARE(icon.name(), themeName + "/icon1"); +} QTEST_MAIN(tst_QIcon) #include "tst_qicon.moc" diff --git a/tests/auto/gui/image/qiconhighdpi/CMakeLists.txt b/tests/auto/gui/image/qiconhighdpi/CMakeLists.txt index 989cf1f44d..f0ccb97c8a 100644 --- a/tests/auto/gui/image/qiconhighdpi/CMakeLists.txt +++ b/tests/auto/gui/image/qiconhighdpi/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from qiconhighdpi.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qiconhighdpi Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qiconhighdpi LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data file(GLOB_RECURSE test_data_glob RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} @@ -13,7 +20,7 @@ list(APPEND test_data ${test_data_glob}) qt_internal_add_test(tst_qiconhighdpi SOURCES tst_qiconhighdpi.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui TESTDATA ${test_data} ) diff --git a/tests/auto/gui/image/qiconhighdpi/tst_qiconhighdpi.cpp b/tests/auto/gui/image/qiconhighdpi/tst_qiconhighdpi.cpp index 829c463c6b..34f0132865 100644 --- a/tests/auto/gui/image/qiconhighdpi/tst_qiconhighdpi.cpp +++ b/tests/auto/gui/image/qiconhighdpi/tst_qiconhighdpi.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <qicon.h> @@ -17,6 +17,7 @@ private slots: void addPixmap_data(); void addPixmap(); void ninePatch(); + void preferUpscale(); }; tst_QIconHighDpi::tst_QIconHighDpi() @@ -211,6 +212,23 @@ void tst_QIconHighDpi::ninePatch() } } +void tst_QIconHighDpi::preferUpscale() +{ + QIcon icon; + + // manual pixmap adder for full control of devicePixelRatio + auto addPixmapWithDpr = [&icon](const QString &path, qreal dpr) { + QImage image(path); + image.setDevicePixelRatio(dpr); + icon.addPixmap(QPixmap::fromImage(image)); + }; + + addPixmapWithDpr(":/icons/testtheme/22x22/actions/appointment-new.png", 1); + addPixmapWithDpr(":/icons/testtheme/22x22@2/actions/appointment-new.png", 2); + + QCOMPARE(icon.pixmap(QSize(22, 22), 1.25f).devicePixelRatio(), 1.25f); +} + int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); diff --git a/tests/auto/gui/image/qimage/CMakeLists.txt b/tests/auto/gui/image/qimage/CMakeLists.txt index 60c6267463..8d0842026d 100644 --- a/tests/auto/gui/image/qimage/CMakeLists.txt +++ b/tests/auto/gui/image/qimage/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from qimage.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qimage Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qimage LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data file(GLOB_RECURSE test_data_glob RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} @@ -13,7 +20,7 @@ list(APPEND test_data ${test_data_glob}) qt_internal_add_test(tst_qimage SOURCES tst_qimage.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate @@ -21,12 +28,12 @@ qt_internal_add_test(tst_qimage ) qt_internal_extend_target(tst_qimage CONDITION WIN32 - PUBLIC_LIBRARIES + LIBRARIES gdi32 user32 ) qt_internal_extend_target(tst_qimage CONDITION APPLE - PUBLIC_LIBRARIES + LIBRARIES ${FWCoreGraphics} ) diff --git a/tests/auto/gui/image/qimage/images/CGATS001Compat-v2-micro.icc b/tests/auto/gui/image/qimage/images/CGATS001Compat-v2-micro.icc Binary files differnew file mode 100644 index 0000000000..b5a73495bf --- /dev/null +++ b/tests/auto/gui/image/qimage/images/CGATS001Compat-v2-micro.icc diff --git a/tests/auto/gui/image/qimage/images/VideoHD.icc b/tests/auto/gui/image/qimage/images/VideoHD.icc Binary files differnew file mode 100644 index 0000000000..b96eb68136 --- /dev/null +++ b/tests/auto/gui/image/qimage/images/VideoHD.icc diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index 5b11a672fb..8086ffcc28 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -1,9 +1,10 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QBuffer> +#include <QMatrix4x4> #include <qimage.h> #include <qimagereader.h> @@ -14,6 +15,7 @@ #include <stdio.h> #include <qpainter.h> +#include <private/qcmyk_p.h> #include <private/qimage_p.h> #include <private/qdrawhelper_p.h> @@ -67,6 +69,7 @@ private slots: void rotate_data(); void rotate(); + void rotateBigImage(); void copy(); @@ -106,6 +109,10 @@ private slots: void smoothScaleAlpha(); void smoothScaleFormats_data(); void smoothScaleFormats(); + void smoothScaleNoConversion_data(); + void smoothScaleNoConversion(); + void smoothScale_CMYK_data(); + void smoothScale_CMYK(); void transformed_data(); void transformed(); @@ -165,6 +172,15 @@ private slots: void largeInplaceRgbConversion_data(); void largeInplaceRgbConversion(); + void colorSpaceRgbConversion_data(); + void colorSpaceRgbConversion(); + void colorSpaceCmykConversion_data(); + void colorSpaceCmykConversion(); + void colorSpaceFromGrayConversion_data(); + void colorSpaceFromGrayConversion(); + void colorSpaceToGrayConversion_data(); + void colorSpaceToGrayConversion(); + void deepCopyWhenPaintingActive(); void scaled_QTBUG19157(); @@ -226,12 +242,18 @@ private slots: void largeFillScale(); void largeRasterScale(); + void metadataChangeWithReadOnlyPixels(); + void scaleIndexed(); + #if defined(Q_OS_WIN) void toWinHBITMAP_data(); void toWinHBITMAP(); void fromMonoHBITMAP(); #endif // Q_OS_WIN + void tofromPremultipliedFormat_data(); + void tofromPremultipliedFormat(); + private: const QString m_prefix; }; @@ -311,7 +333,9 @@ static QLatin1String formatToString(QImage::Format format) return QLatin1String("RGBA32FPx4"); case QImage::Format_RGBA32FPx4_Premultiplied: return QLatin1String("RGBA32FPx4pm"); - default: + case QImage::Format_CMYK8888: + return QLatin1String("CMYK8888"); + case QImage::NImageFormats: break; }; Q_UNREACHABLE(); @@ -1129,10 +1153,9 @@ void tst_QImage::rotate_data() QTest::addColumn<QImage::Format>("format"); QTest::addColumn<int>("degrees"); - QList<int> degrees; - degrees << 0 << 90 << 180 << 270; + constexpr int degrees[] = {0, 90, 180, 270}; - foreach (int d, degrees) { + for (int d : degrees) { const QString dB = QString::number(d); for (int i = QImage::Format_Indexed8; i < QImage::NImageFormats; i++) { QImage::Format format = static_cast<QImage::Format>(i); @@ -1210,6 +1233,23 @@ void tst_QImage::rotate() QCOMPARE(original, dest); } +void tst_QImage::rotateBigImage() +{ + // QTBUG-105088 + QImage big_image(3840, 2160, QImage::Format_ARGB32_Premultiplied); + QTransform t; + t.translate(big_image.width() / 2.0, big_image.height() / 2.0); + t.rotate(-89, Qt::YAxis, big_image.width()); + t.translate(-big_image.width() / 2.0, -big_image.height() / 2.0); + QVERIFY(!big_image.transformed(t).isNull()); + + QMatrix4x4 m; + m.translate(big_image.width() / 2.0, big_image.height() / 2.0); + m.projectedRotate(89, 0, 1, 0, big_image.width()); + m.translate(-big_image.width() / 2.0, -big_image.height() / 2.0); + QVERIFY(!big_image.transformed(m.toTransform()).isNull()); +} + void tst_QImage::copy() { // Task 99250 @@ -1481,6 +1521,8 @@ void tst_QImage::setPixelWithAlpha_data() continue; if (c == QImage::Format_Alpha8) continue; + if (c == QImage::Format_CMYK8888) + continue; QTest::newRow(qPrintable(formatToString(QImage::Format(c)))) << QImage::Format(c); } } @@ -2038,6 +2080,94 @@ void tst_QImage::smoothScaleFormats() QVERIFY(rotated.hasAlphaChannel()); } +void tst_QImage::smoothScaleNoConversion_data() +{ + QTest::addColumn<QImage::Format>("format"); + QTest::addRow("Mono") << QImage::Format_Mono; + QTest::addRow("MonoLSB") << QImage::Format_MonoLSB; + QTest::addRow("Indexed8") << QImage::Format_Indexed8; +} + +void tst_QImage::smoothScaleNoConversion() +{ + QFETCH(QImage::Format, format); + QImage img(128, 128, format); + img.fill(1); + img.setColorTable(QList<QRgb>() << qRgba(255,0,0,255) << qRgba(0,0,0,0)); + img = img.scaled(QSize(48, 48), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + QVERIFY(img.hasAlphaChannel()); +} + +void tst_QImage::smoothScale_CMYK_data() +{ + QTest::addColumn<int>("size"); + + const int sizes[] = { 2, 3, 4, 6, 7, 8, 10, 16, 20, 32, 40, 64, 100, 101, 128 }; + for (int size : sizes) + QTest::addRow("%d x %d", size, size) << size; +} + +void tst_QImage::smoothScale_CMYK() +{ + QFETCH(int, size); + QImage img(size, size, QImage::Format_CMYK8888); + QCmyk32 expected(31, 63, 127, 127); + img.fill(expected.toUint()); + + auto getCmykPixel = [](const QImage &image, int x, int y) { + Q_ASSERT(image.format() == QImage::Format_CMYK8888); + const uint *line = reinterpret_cast<const uint *>(image.scanLine(y)); + const uint pixel = line[x]; + return QCmyk32::fromCmyk32(pixel); + }; + + // scale x down, y down + QImage scaled = img.scaled(QSize(1, 1), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + QCmyk32 pixel = getCmykPixel(scaled, 0, 0); + QCOMPARE(pixel, expected); + + // scale x down, y up + scaled = img.scaled(QSize(1, size * 2), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + for (int y = 0; y < scaled.height(); ++y) { + pixel = getCmykPixel(scaled, 0, y); + QCOMPARE(pixel, expected); + } + + // scale x up, y down + scaled = img.scaled(QSize(size * 2, 1), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + for (int x = 0; x < scaled.width(); ++x) { + pixel = getCmykPixel(scaled, x, 0); + QCOMPARE(pixel, expected); + } + + // scale x up + scaled = img.scaled(QSize(size, size * 2), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + for (int y = 0; y < scaled.height(); ++y) { + for (int x = 0; x < scaled.width(); ++x) { + pixel = getCmykPixel(scaled, x, y); + QCOMPARE(pixel, expected); + } + } + + // scale y up + scaled = img.scaled(QSize(size * 2, size), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + for (int y = 0; y < scaled.height(); ++y) { + for (int x = 0; x < scaled.width(); ++x) { + pixel = getCmykPixel(scaled, x, y); + QCOMPARE(pixel, expected); + } + } + + // scale x up, y up + scaled = img.scaled(QSize(size * 2, size * 2), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + for (int y = 0; y < scaled.height(); ++y) { + for (int x = 0; x < scaled.width(); ++x) { + pixel = getCmykPixel(scaled, x, y); + QCOMPARE(pixel, expected); + } + } +} + static int count(const QImage &img, int x, int y, int dx, int dy, QRgb pixel) { int i = 0; @@ -2524,7 +2654,8 @@ void tst_QImage::rgbSwapped_data() for (int i = QImage::Format_Indexed8; i < QImage::NImageFormats; ++i) { if (i == QImage::Format_Alpha8 || i == QImage::Format_Grayscale8 - || i == QImage::Format_Grayscale16) { + || i == QImage::Format_Grayscale16 + || i == QImage::Format_CMYK8888) { continue; } QTest::addRow("%s", formatToString(QImage::Format(i)).data()) << QImage::Format(i); @@ -2618,20 +2749,20 @@ void tst_QImage::mirrored_data() QTest::newRow("Format_Mono, horizontal+vertical") << QImage::Format_Mono << true << true << 16 << 16; QTest::newRow("Format_MonoLSB, horizontal+vertical") << QImage::Format_MonoLSB << true << true << 16 << 16; - QTest::newRow("Format_RGB32, vertical") << QImage::Format_RGB32 << true << false << 8 << 16; - QTest::newRow("Format_ARGB32, vertical") << QImage::Format_ARGB32 << true << false << 16 << 8; + QTest::newRow("Format_RGB32, vertical, narrow") << QImage::Format_RGB32 << true << false << 8 << 16; + QTest::newRow("Format_ARGB32, vertical, short") << QImage::Format_ARGB32 << true << false << 16 << 8; QTest::newRow("Format_Mono, vertical, non-aligned") << QImage::Format_Mono << true << false << 19 << 25; QTest::newRow("Format_MonoLSB, vertical, non-aligned") << QImage::Format_MonoLSB << true << false << 19 << 25; // Non-aligned horizontal 1-bit needs special handling so test this. QTest::newRow("Format_Mono, horizontal, non-aligned") << QImage::Format_Mono << false << true << 13 << 17; - QTest::newRow("Format_Mono, horizontal, non-aligned") << QImage::Format_Mono << false << true << 19 << 25; - QTest::newRow("Format_Mono, horizontal+vertical, non-aligned") << QImage::Format_Mono << true << true << 25 << 47; + QTest::newRow("Format_Mono, horizontal, non-aligned, big") << QImage::Format_Mono << false << true << 19 << 25; + QTest::newRow("Format_Mono, horizontal+vertical, non-aligned, big") << QImage::Format_Mono << true << true << 25 << 47; QTest::newRow("Format_Mono, horizontal+vertical, non-aligned") << QImage::Format_Mono << true << true << 21 << 16; QTest::newRow("Format_MonoLSB, horizontal, non-aligned") << QImage::Format_MonoLSB << false << true << 13 << 17; - QTest::newRow("Format_MonoLSB, horizontal, non-aligned") << QImage::Format_MonoLSB << false << true << 19 << 25; - QTest::newRow("Format_MonoLSB, horizontal+vertical, non-aligned") << QImage::Format_MonoLSB << true << true << 25 << 47; + QTest::newRow("Format_MonoLSB, horizontal, non-aligned, big") << QImage::Format_MonoLSB << false << true << 19 << 25; + QTest::newRow("Format_MonoLSB, horizontal+vertical, non-aligned, big") << QImage::Format_MonoLSB << true << true << 25 << 47; QTest::newRow("Format_MonoLSB, horizontal+vertical, non-aligned") << QImage::Format_MonoLSB << true << true << 21 << 16; } @@ -3006,13 +3137,15 @@ void tst_QImage::inplaceRgbConversion_data() for (int i = QImage::Format_RGB32; i < QImage::NImageFormats; ++i) { if (i == QImage::Format_Alpha8 || i == QImage::Format_Grayscale8 - || i == QImage::Format_Grayscale16) { + || i == QImage::Format_Grayscale16 + || i == QImage::Format_CMYK8888) { continue; } for (int j = QImage::Format_RGB32; j < QImage::NImageFormats; ++j) { if (j == QImage::Format_Alpha8 || j == QImage::Format_Grayscale8 - || j == QImage::Format_Grayscale16) { + || j == QImage::Format_Grayscale16 + || j == QImage::Format_CMYK8888) { continue; } if (i == j) @@ -3193,6 +3326,258 @@ void tst_QImage::largeInplaceRgbConversion() } } +void tst_QImage::colorSpaceRgbConversion_data() +{ + QTest::addColumn<QImage::Format>("fromFormat"); + QTest::addColumn<QImage::Format>("toFormat"); + + // The various possible code paths for color space conversions compatible with RGB color spaces: + QImage::Format formats[] = { + QImage::Format_RGB32, + QImage::Format_ARGB32, + QImage::Format_ARGB32_Premultiplied, + QImage::Format_RGBX64, + QImage::Format_RGBA64, + QImage::Format_RGBA64_Premultiplied, + QImage::Format_RGBX32FPx4, + QImage::Format_RGBA32FPx4, + QImage::Format_RGBA32FPx4_Premultiplied, + QImage::Format_Grayscale8, + QImage::Format_Grayscale16, + }; + + for (auto fromFormat : formats) { + const QLatin1String formatI = formatToString(fromFormat); + for (auto toFormat : formats) { + QTest::addRow("%s -> %s", formatI.data(), formatToString(toFormat).data()) + << fromFormat << toFormat; + } + } +} + +void tst_QImage::colorSpaceRgbConversion() +{ + // Test that all color space conversions work + QFETCH(QImage::Format, fromFormat); + QFETCH(QImage::Format, toFormat); + + bool srcGrayscale = fromFormat == QImage::Format_Grayscale8 || fromFormat == QImage::Format_Grayscale16; + bool dstGrayscale = toFormat == QImage::Format_Grayscale8 || toFormat == QImage::Format_Grayscale16; + + QImage image(16, 16, fromFormat); + image.setColorSpace(QColorSpace::SRgb); + + for (int i = 0; i < image.height(); ++i) { + for (int j = 0; j < image.width(); ++j) { + if (srcGrayscale || dstGrayscale) + image.setPixel(j, i, qRgb((i + j) * 8, (i + j) * 8, (i + j) * 8)); + else + image.setPixel(j, i, qRgb(j * 16, i * 16, (i + j) * 8)); + } + } + + QImage imageConverted = image.convertedToColorSpace(QColorSpace::DisplayP3, toFormat); + QCOMPARE(imageConverted.format(), toFormat); + QCOMPARE(imageConverted.size(), image.size()); + if (dstGrayscale) { + int gray = 0; + for (int x = 0; x < image.width(); ++x) { + int newGray = qGray(imageConverted.pixel(x, 6)); + QCOMPARE_GE(newGray, gray); + gray = newGray; + } + } else { + int red = 0; + int blue = 0; + for (int x = 0; x < image.width(); ++x) { + int newRed = qRed(imageConverted.pixel(x, 5)); + int newBlue = qBlue(imageConverted.pixel(x, 7)); + QCOMPARE_GE(newBlue, blue); + QCOMPARE_GE(newRed, red); + blue = newBlue; + red = newRed; + } + } +} + + +void tst_QImage::colorSpaceCmykConversion_data() +{ + QTest::addColumn<QImage::Format>("toFormat"); + + QImage::Format formats[] = { + QImage::Format_RGB32, + QImage::Format_ARGB32, + QImage::Format_ARGB32_Premultiplied, + QImage::Format_RGBX64, + QImage::Format_RGBA64, + QImage::Format_RGBA64_Premultiplied, + QImage::Format_RGBX32FPx4, + QImage::Format_RGBA32FPx4, + QImage::Format_RGBA32FPx4_Premultiplied, + QImage::Format_Grayscale8, + QImage::Format_Grayscale16, + }; + + for (auto toFormat : formats) + QTest::addRow("CMYK8888 -> %s", formatToString(toFormat).data()) << toFormat; +} + +void tst_QImage::colorSpaceCmykConversion() +{ + QFETCH(QImage::Format, toFormat); + + bool dstGrayscale = toFormat == QImage::Format_Grayscale8 || toFormat == QImage::Format_Grayscale16; + + QImage image(16, 16, QImage::Format_CMYK8888); + QFile iccProfile(m_prefix +"CGATS001Compat-v2-micro.icc"); + iccProfile.open(QIODevice::ReadOnly); + image.setColorSpace(QColorSpace::fromIccProfile(iccProfile.readAll())); + QVERIFY(image.colorSpace().isValid()); + + for (int i = 0; i < image.height(); ++i) { + for (int j = 0; j < image.width(); ++j) { + if (dstGrayscale) + image.setPixel(j, i, qRgb((i + j) * 8, (i + j) * 8, (i + j) * 8)); + else + image.setPixel(j, i, qRgb(j * 16, i * 16, (i + j) * 8)); + } + } + + QImage imageConverted = image.convertedToColorSpace(QColorSpace::SRgb, toFormat); + QCOMPARE(imageConverted.format(), toFormat); + QCOMPARE(imageConverted.size(), image.size()); + if (dstGrayscale) { + int gray = 0; + for (int x = 0; x < image.width(); ++x) { + int newGray = qGray(imageConverted.pixel(x, 6)); + QCOMPARE_GE(newGray, gray); + gray = newGray; + } + } else { + int red = 0; + for (int x = 0; x < image.width(); ++x) { + int newRed = qRed(imageConverted.pixel(x, 5)); + QCOMPARE_GE(newRed, red); + red = newRed; + } + } +} + +void tst_QImage::colorSpaceFromGrayConversion_data() +{ + QTest::addColumn<QImage::Format>("fromFormat"); + QTest::addColumn<QColorSpace>("fromCS"); + QTest::addColumn<QColorSpace>("toCS"); + + QImage::Format formats[] = { + QImage::Format_Grayscale8, + QImage::Format_Grayscale16, + }; + + QList<QColorSpace> colorSpaces = { + QColorSpace::SRgbLinear, + QColorSpace::DisplayP3, + QColorSpace(QPointF(0.31271, 0.32902), QColorSpace::TransferFunction::SRgb), + QColorSpace(QPointF(0.30, 0.33), QColorSpace::TransferFunction::Linear) + }; + std::string names[] = { + "sRgbLinear", + "displayP3", + "graySRgb", + "grayOther", + "videoHD(A2B)" + }; + + QFile iccProfile(m_prefix + "VideoHD.icc"); + iccProfile.open(QIODevice::ReadOnly); + colorSpaces.append(QColorSpace::fromIccProfile(iccProfile.readAll())); + + for (auto fromFormat : formats) { + for (int from = 0; from < 5; ++from) { + for (int to = 0; to < 4; ++to) { + QTest::addRow("%s: %s -> %s", formatToString(fromFormat).data(), names[from].c_str(), names[to].c_str()) + << fromFormat << colorSpaces[from] << colorSpaces[to]; + } + } + } +} + +void tst_QImage::colorSpaceFromGrayConversion() +{ + QFETCH(QImage::Format, fromFormat); + QFETCH(QColorSpace, fromCS); + QFETCH(QColorSpace, toCS); + + QImage image(16, 16, fromFormat); + image.setColorSpace(fromCS); + QVERIFY(image.colorSpace().isValid()); + + for (int i = 0; i < image.height(); ++i) { + for (int j = 0; j < image.width(); ++j) { + image.setPixel(j, i, qRgb((i + j) * 8, (i + j) * 8, (i + j) * 8)); + } + } + QImage imageConverted = image.convertedToColorSpace(toCS); + QCOMPARE(imageConverted.format(), fromFormat); + QCOMPARE(imageConverted.size(), image.size()); + int gray = 0; + for (int x = 0; x < image.width(); ++x) { + int newGray = qGray(imageConverted.pixel(x, 3)); + QCOMPARE_GE(newGray, gray); + gray = newGray; + } +} + +void tst_QImage::colorSpaceToGrayConversion_data() +{ + QTest::addColumn<QImage::Format>("fromFormat"); + + QImage::Format formats[] = { + QImage::Format_RGB32, + QImage::Format_ARGB32, + QImage::Format_ARGB32_Premultiplied, + QImage::Format_RGBX64, + QImage::Format_RGBA64, + QImage::Format_RGBA64_Premultiplied, + QImage::Format_RGBX32FPx4, + QImage::Format_RGBA32FPx4, + QImage::Format_RGBA32FPx4_Premultiplied, + QImage::Format_Grayscale8, + QImage::Format_Grayscale16, + }; + + for (auto fromFormat : formats) + QTest::addRow("%s -> Gray", formatToString(fromFormat).data()) << fromFormat; +} + +void tst_QImage::colorSpaceToGrayConversion() +{ + QFETCH(QImage::Format, fromFormat); + + QImage image(16, 16, fromFormat); + image.setColorSpace(QColorSpace::DisplayP3); + QVERIFY(image.colorSpace().isValid()); + + for (int i = 0; i < image.height(); ++i) { + for (int j = 0; j < image.width(); ++j) { + image.setPixel(j, i, qRgb((i + j) * 8, (i + j) * 8, (i + j) * 8)); + } + } + + QColorSpace grayColorSpace(QPointF(0.31271, 0.32902), QColorSpace::TransferFunction::SRgb); + + QImage imageConverted = image.convertedToColorSpace(grayColorSpace); + QVERIFY(imageConverted.format() == QImage::Format_Grayscale8 || imageConverted.format() == QImage::Format_Grayscale16); + QCOMPARE(imageConverted.size(), image.size()); + int gray = 0; + for (int x = 0; x < image.width(); ++x) { + int newGray = qGray(imageConverted.pixel(x, 11)); + QCOMPARE_GE(newGray, gray); + gray = newGray; + } +} + void tst_QImage::deepCopyWhenPaintingActive() { QImage image(64, 64, QImage::Format_ARGB32_Premultiplied); @@ -3301,7 +3686,8 @@ void tst_QImage::invertPixelsRGB_data() for (int i = QImage::Format_RGB32; i < QImage::NImageFormats; ++i) { if (i == QImage::Format_Alpha8 || i == QImage::Format_Grayscale8 - || i == QImage::Format_Grayscale16) { + || i == QImage::Format_Grayscale16 + || i == QImage::Format_CMYK8888) { continue; } QTest::addRow("%s", formatToString(QImage::Format(i)).data()) << QImage::Format(i); @@ -3433,6 +3819,9 @@ void tst_QImage::exifInvalidData() void tst_QImage::exifReadComments() { +#ifdef QT_NO_IMAGEIO_TEXT_LOADING + QSKIP("Reading text from image file is configured off"); +#endif QImage image; QVERIFY(image.load(m_prefix + "jpeg_exif_utf8_comment.jpg")); QVERIFY(!image.isNull()); @@ -3665,10 +4054,12 @@ void tst_QImage::metadataPassthrough() QCOMPARE(alphaMask.dotsPerMeterY(), a.dotsPerMeterY()); QCOMPARE(alphaMask.devicePixelRatio(), a.devicePixelRatio()); +#ifndef QT_NO_IMAGE_HEURISTIC_MASK QImage heuristicMask = a.createHeuristicMask(); QCOMPARE(heuristicMask.dotsPerMeterX(), a.dotsPerMeterX()); QCOMPARE(heuristicMask.dotsPerMeterY(), a.dotsPerMeterY()); QCOMPARE(heuristicMask.devicePixelRatio(), a.devicePixelRatio()); +#endif QImage maskFromColor = a.createMaskFromColor(qRgb(0, 0, 0)); QCOMPARE(maskFromColor.dotsPerMeterX(), a.dotsPerMeterX()); @@ -3826,7 +4217,7 @@ void tst_QImage::reinterpretAsFormat_data() QTest::newRow("rgb32 -> argb32") << QImage::Format_RGB32 << QImage::Format_ARGB32 << QColor(Qt::cyan) << QColor(Qt::cyan); QTest::newRow("argb32pm -> rgb32") << QImage::Format_ARGB32_Premultiplied << QImage::Format_RGB32 << QColor(Qt::transparent) << QColor(Qt::black); QTest::newRow("argb32 -> rgb32") << QImage::Format_ARGB32 << QImage::Format_RGB32 << QColor(255, 0, 0, 127) << QColor(255, 0, 0); - QTest::newRow("argb32pm -> rgb32") << QImage::Format_ARGB32_Premultiplied << QImage::Format_RGB32 << QColor(255, 0, 0, 127) << QColor(127, 0, 0); + QTest::newRow("argb32pm (red) -> rgb32") << QImage::Format_ARGB32_Premultiplied << QImage::Format_RGB32 << QColor(255, 0, 0, 127) << QColor(127, 0, 0); } void tst_QImage::reinterpretAsFormat() @@ -4038,6 +4429,34 @@ void tst_QImage::largeRasterScale() // image.save("largeRasterScale.png", "PNG"); } +void tst_QImage::metadataChangeWithReadOnlyPixels() +{ + const QRgb data[3] = { qRgb(255, 0, 0), qRgb(0, 255, 0), qRgb(0, 0, 255) }; + QImage image((const uchar *)data, 3, 1, QImage::Format_RGB32); + + QCOMPARE(image.constBits(), (const uchar *)data); + image.setDotsPerMeterX(100); + QCOMPARE(image.constBits(), (const uchar *)data); + + QImage image2 = image; + QCOMPARE(image2.constBits(), (const uchar *)data); + image2.setDotsPerMeterX(200); + // Pixels and metadata has the same sharing mechanism, so a change of a shared + // image metadata forces pixel detach (remove this sub-test if that ever changes). + QVERIFY(image2.constBits() != (const uchar *)data); + QCOMPARE(image.constBits(), (const uchar *)data); +} + +void tst_QImage::scaleIndexed() +{ + QImage image(10, 10, QImage::Format_Indexed8); + image.setColor(0, qRgb(0,0,0)); + image.setColor(1, qRgb(1,1,1)); + image.fill(1); + image.setDevicePixelRatio(2); + QImage image2 = image.scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation); // do not crash +} + #if defined(Q_OS_WIN) static inline QColor COLORREFToQColor(COLORREF cr) @@ -4150,5 +4569,27 @@ void tst_QImage::fromMonoHBITMAP() // QTBUG-72343, corruption for mono bitmaps #endif // Q_OS_WIN +void tst_QImage::tofromPremultipliedFormat_data() +{ + QTest::addColumn<QImage::Format>("unpremul"); + QTest::addColumn<QImage::Format>("premul"); + + // Test all available formats with both premultiplied and unpremultiplied versions + QTest::newRow("argb32") << QImage::Format_ARGB32 << QImage::Format_ARGB32_Premultiplied; + QTest::newRow("rgba8888") << QImage::Format_RGBA8888 << QImage::Format_RGBA8888_Premultiplied; + QTest::newRow("rgba64") << QImage::Format_RGBA64 << QImage::Format_RGBA64_Premultiplied; + QTest::newRow("rgba16fpx4") << QImage::Format_RGBA16FPx4 << QImage::Format_RGBA16FPx4_Premultiplied; + QTest::newRow("rgba32fpx4") << QImage::Format_RGBA32FPx4 << QImage::Format_RGBA32FPx4_Premultiplied; +} + +void tst_QImage::tofromPremultipliedFormat() +{ + QFETCH(QImage::Format, unpremul); + QFETCH(QImage::Format, premul); + + QCOMPARE(qt_toPremultipliedFormat(unpremul), premul); + QCOMPARE(qt_toUnpremultipliedFormat(premul), unpremul); +} + QTEST_GUILESS_MAIN(tst_QImage) #include "tst_qimage.moc" diff --git a/tests/auto/gui/image/qimageiohandler/CMakeLists.txt b/tests/auto/gui/image/qimageiohandler/CMakeLists.txt index 4bbf2f5b01..9fbd9c9b9f 100644 --- a/tests/auto/gui/image/qimageiohandler/CMakeLists.txt +++ b/tests/auto/gui/image/qimageiohandler/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qimageiohandler.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qimageiohandler Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qimageiohandler LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qimageiohandler SOURCES tst_qimageiohandler.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/image/qimageiohandler/tst_qimageiohandler.cpp b/tests/auto/gui/image/qimageiohandler/tst_qimageiohandler.cpp index fd0e61b1ba..bd325e185c 100644 --- a/tests/auto/gui/image/qimageiohandler/tst_qimageiohandler.cpp +++ b/tests/auto/gui/image/qimageiohandler/tst_qimageiohandler.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/gui/image/qimagereader/BLACKLIST b/tests/auto/gui/image/qimagereader/BLACKLIST new file mode 100644 index 0000000000..6422ff1dac --- /dev/null +++ b/tests/auto/gui/image/qimagereader/BLACKLIST @@ -0,0 +1,8 @@ +[setClipRect:SVG: rect] +wayland +[setClipRect:SVGZ: rect] +wayland +[setScaledClipRect:SVG: rect] +wayland +[setScaledClipRect:SVGZ: rect] +wayland diff --git a/tests/auto/gui/image/qimagereader/CMakeLists.txt b/tests/auto/gui/image/qimagereader/CMakeLists.txt index 3a2dceeebe..2a14ca3c9c 100644 --- a/tests/auto/gui/image/qimagereader/CMakeLists.txt +++ b/tests/auto/gui/image/qimagereader/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from qimagereader.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qimagereader Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qimagereader LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data file(GLOB_RECURSE test_data_glob RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} @@ -17,7 +24,7 @@ list(APPEND test_data ${test_data_glob}) qt_internal_add_test(tst_qimagereader SOURCES tst_qimagereader.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/image/qimagereader/images/image.pbm b/tests/auto/gui/image/qimagereader/images/image.pbm index 67e5efa3e9..e529536ca4 100644 --- a/tests/auto/gui/image/qimagereader/images/image.pbm +++ b/tests/auto/gui/image/qimagereader/images/image.pbm @@ -1,8 +1,8 @@ P1 16 6 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 +10 00 00 00 01 00 00 01 +1000 0000 0100 0001 +100000000 1000001 +1000000001000001 +10 000 0000 10000 01 diff --git a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp index b01eb83089..96af8b4e9b 100644 --- a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp @@ -1,6 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -11,7 +10,7 @@ #include <QImageReader> #include <QImageWriter> #include <QPixmap> -#include <QSet> +#include <QScopeGuard> #include <QTcpSocket> #include <QTcpServer> #include <QTimer> @@ -63,6 +62,9 @@ private slots: void setScaledSize_data(); void setScaledSize(); + void setScaledSizeOneDimension_data(); + void setScaledSizeOneDimension(); + void setClipRect_data(); void setClipRect(); @@ -301,25 +303,52 @@ void tst_QImageReader::jpegRgbCmyk() QImage image1(prefix + QLatin1String("YCbCr_cmyk.jpg")); QImage image2(prefix + QLatin1String("YCbCr_cmyk.png")); - if (image1 != image2) { - // first, do some obvious tests - QCOMPARE(image1.height(), image2.height()); - QCOMPARE(image1.width(), image2.width()); - QCOMPARE(image1.format(), image2.format()); - QCOMPARE(image1.format(), QImage::Format_RGB32); - - // compare all the pixels with a slack of 3. This ignores rounding errors - // in libjpeg/libpng, where some versions sacrifice accuracy for speed. - for (int h = 0; h < image1.height(); ++h) { - const uchar *s1 = image1.constScanLine(h); - const uchar *s2 = image2.constScanLine(h); - for (int w = 0; w < image1.width() * 4; ++w) { - if (*s1 != *s2) { - QVERIFY2(qAbs(*s1 - *s2) <= 3, qPrintable(QString("images differ in line %1, col %2 (image1: %3, image2: %4)").arg(h).arg(w).arg(*s1, 0, 16).arg(*s2, 0, 16))); - } - s1++; - s2++; - } + QVERIFY(!image1.isNull()); + QVERIFY(!image2.isNull()); + + QCOMPARE(image1.height(), image2.height()); + QCOMPARE(image1.width(), image2.width()); + + QCOMPARE(image1.format(), QImage::Format_CMYK8888); + QCOMPARE(image2.format(), QImage::Format_RGB32); + + // compare all the pixels with a slack of 3. This ignores rounding errors + // in libjpeg/libpng, where some versions sacrifice accuracy for speed. + const auto fuzzyCompareColors = [](const QColor &c1, const QColor &c2) { + int c1rgba[4]; + int c2rgba[4]; + + c1.getRgb(c1rgba + 0, + c1rgba + 1, + c1rgba + 2, + c1rgba + 3); + + c2.getRgb(c2rgba + 0, + c2rgba + 1, + c2rgba + 2, + c2rgba + 3); + + const auto fuzzyCompare = [](int a, int b) { + return qAbs(a - b) <= 3; + }; + + return fuzzyCompare(c1rgba[0], c2rgba[0]) && + fuzzyCompare(c1rgba[1], c2rgba[1]) && + fuzzyCompare(c1rgba[2], c2rgba[2]) && + fuzzyCompare(c1rgba[3], c2rgba[3]); + }; + + for (int h = 0; h < image1.height(); ++h) { + const uchar *sl1 = image1.constScanLine(h); + const uchar *sl2 = image2.constScanLine(h); + for (int w = 0; w < image1.width(); ++w) { + const uchar *s1 = sl1 + w * 4; + const uchar *s2 = sl2 + w * 4; + + QColor c1 = QColor::fromCmyk(s1[0], s1[1], s1[2], s1[3]); + QColor c2 = QColor::fromRgb(s2[2], s2[1], s2[0]); + QVERIFY2(fuzzyCompareColors(c1, c2), + qPrintable(QString("images differ in line %1, col %2").arg(h).arg(w))); } } } @@ -372,6 +401,60 @@ void tst_QImageReader::setScaledSize() QCOMPARE(image.size(), newSize); } +void tst_QImageReader::setScaledSizeOneDimension_data() +{ + QTest::addColumn<QString>("fileName"); + QTest::addColumn<QByteArray>("format"); + + QTest::newRow("PNG: kollada") << QString("kollada") << QByteArray("png"); + QTest::newRow("JPEG: beavis") << QString("beavis") << QByteArray("jpeg"); + QTest::newRow("GIF: earth") << QString("earth") << QByteArray("gif"); + QTest::newRow("SVG: rect") << QString("rect") << QByteArray("svg"); + QTest::newRow("BMP: colorful") << QString("colorful") << QByteArray("bmp"); + QTest::newRow("XPM: marble") << QString("marble") << QByteArray("xpm"); + QTest::newRow("PPM: teapot") << QString("teapot") << QByteArray("ppm"); + QTest::newRow("XBM: gnus") << QString("gnus") << QByteArray("xbm"); +} + +void tst_QImageReader::setScaledSizeOneDimension() +{ + QFETCH(QString, fileName); + QFETCH(QByteArray, format); + + SKIP_IF_UNSUPPORTED(format); + + const QSize originalSize = QImageReader(prefix + fileName).size(); + QVERIFY(!originalSize.isEmpty()); + + auto testScaledSize = [&] (const QSize &scaledSize) { + QSize expectedSize = scaledSize; + if (scaledSize.width() <= 0) + expectedSize.setWidth(qRound(originalSize.width() * + (qreal(scaledSize.height()) / originalSize.height()))); + else if (scaledSize.height() <= 0) + expectedSize.setHeight(qRound(originalSize.height() * + (qreal(scaledSize.width()) / originalSize.width()))); + + QImageReader reader(prefix + fileName); + reader.setScaledSize(scaledSize); + QImage image = reader.read(); + QVERIFY(!image.isNull()); + QCOMPARE(image.size(), expectedSize); + }; + + // downscale + testScaledSize(QSize(originalSize.width() / 2, 0)); + testScaledSize(QSize(originalSize.width() / 2, -1)); + testScaledSize(QSize(0, originalSize.height() / 2)); + testScaledSize(QSize(-1, originalSize.height() / 2)); + + // upscale + testScaledSize(QSize(originalSize.width() * 2, 0)); + testScaledSize(QSize(originalSize.width() * 2, -1)); + testScaledSize(QSize(0, originalSize.height() * 2)); + testScaledSize(QSize(-1, originalSize.height() * 2)); +} + void tst_QImageReader::task255627_setNullScaledSize_data() { setScaledSize_data(); @@ -487,8 +570,11 @@ void tst_QImageReader::setScaledClipRect() QImageReader originalReader(prefix + fileName); originalReader.setScaledSize(QSize(300, 300)); QImage originalImage = originalReader.read(); - if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive) && format.contains("svg")) - QEXPECT_FAIL("", "This fails on Wayland, see QTBUG-100917.", Abort); + if (format.contains("svg")) { + // rendering of subrect may yield slight rounding differences, truncate them away + image.convertTo(QImage::Format_RGB444); + originalImage.convertTo(QImage::Format_RGB444); + } QCOMPARE(originalImage.copy(newRect), image); } @@ -530,7 +616,7 @@ void tst_QImageReader::imageFormat_data() QTest::newRow("ppm-4") << QString("test.ppm") << QByteArray("ppm") << QImage::Format_RGB32; QTest::newRow("jpeg-1") << QString("beavis.jpg") << QByteArray("jpeg") << QImage::Format_Grayscale8; - QTest::newRow("jpeg-2") << QString("YCbCr_cmyk.jpg") << QByteArray("jpeg") << QImage::Format_RGB32; + QTest::newRow("jpeg-2") << QString("YCbCr_cmyk.jpg") << QByteArray("jpeg") << QImage::Format_CMYK8888; QTest::newRow("jpeg-3") << QString("YCbCr_rgb.jpg") << QByteArray("jpeg") << QImage::Format_RGB32; QTest::newRow("gif-1") << QString("earth.gif") << QByteArray("gif") << QImage::Format_Invalid; @@ -591,41 +677,31 @@ void tst_QImageReader::multiWordNamedColorXPM() QCOMPARE(image.pixel(0, 2), qRgb(255, 250, 205)); // lemon chiffon } -void tst_QImageReader::supportedFormats() +namespace { +template <typename ForwardIterator> +bool is_sorted_unique(ForwardIterator first, ForwardIterator last) { - QList<QByteArray> formats = QImageReader::supportedImageFormats(); - QList<QByteArray> sortedFormats = formats; - std::sort(sortedFormats.begin(), sortedFormats.end()); - - // check that the list is sorted - QCOMPARE(formats, sortedFormats); - - QSet<QByteArray> formatSet; - foreach (QByteArray format, formats) - formatSet << format; + // a range is sorted with no dups iff each *i < *(i+1), so check that none are >=: + return std::adjacent_find(first, last, std::greater_equal<>{}) == last; +} +} - // check that the list does not contain duplicates - QCOMPARE(formatSet.size(), formats.size()); +void tst_QImageReader::supportedFormats() +{ + const QList<QByteArray> formats = QImageReader::supportedImageFormats(); + auto printOnFailure = qScopeGuard([&] { qDebug() << formats; }); + QVERIFY(is_sorted_unique(formats.begin(), formats.end())); + printOnFailure.dismiss(); } void tst_QImageReader::supportedMimeTypes() { - QList<QByteArray> mimeTypes = QImageReader::supportedMimeTypes(); - QList<QByteArray> sortedMimeTypes = mimeTypes; - std::sort(sortedMimeTypes.begin(), sortedMimeTypes.end()); - - // check that the list is sorted - QCOMPARE(mimeTypes, sortedMimeTypes); - - QSet<QByteArray> mimeTypeSet; - foreach (QByteArray mimeType, mimeTypes) - mimeTypeSet << mimeType; - + const QList<QByteArray> mimeTypes = QImageReader::supportedMimeTypes(); + auto printOnFailure = qScopeGuard([&] { qDebug() << mimeTypes; }); + QVERIFY(is_sorted_unique(mimeTypes.begin(), mimeTypes.end())); // check the list as a minimum contains image/bmp - QVERIFY(mimeTypeSet.contains("image/bmp")); - - // check that the list does not contain duplicates - QCOMPARE(mimeTypeSet.size(), mimeTypes.size()); + QVERIFY(mimeTypes.contains("image/bmp")); + printOnFailure.dismiss(); } void tst_QImageReader::setBackgroundColor_data() @@ -670,7 +746,7 @@ void tst_QImageReader::supportsAnimation_data() QTest::newRow("BMP: colorful") << QString("colorful.bmp") << false; QTest::newRow("BMP: font") << QString("font.bmp") << false; QTest::newRow("BMP: signed char") << QString("crash-signed-char.bmp") << false; - QTest::newRow("BMP: test32bfv4") << QString("test32bfv4.bmp") << false;; + QTest::newRow("BMP: test32bfv4") << QString("test32bfv4.bmp") << false; QTest::newRow("BMP: test32v5") << QString("test32v5.bmp") << false; QTest::newRow("XPM: marble") << QString("marble.xpm") << false; QTest::newRow("PNG: kollada") << QString("kollada.png") << false; @@ -1620,43 +1696,56 @@ void tst_QImageReader::supportsOption_data() QTest::addColumn<QIntList>("options"); QTest::newRow("png") << QString("black.png") - << (QIntList() << QImageIOHandler::Gamma - << QImageIOHandler::Description - << QImageIOHandler::Quality - << QImageIOHandler::CompressionRatio - << QImageIOHandler::Size - << QImageIOHandler::ScaledSize); + << QIntList{ + QImageIOHandler::Gamma, + QImageIOHandler::Description, + QImageIOHandler::Quality, + QImageIOHandler::CompressionRatio, + QImageIOHandler::Size, + QImageIOHandler::ScaledSize, + QImageIOHandler::ImageFormat, + }; } void tst_QImageReader::supportsOption() { QFETCH(QString, fileName); - QFETCH(QIntList, options); - - QSet<QImageIOHandler::ImageOption> allOptions; - allOptions << QImageIOHandler::Size - << QImageIOHandler::ClipRect - << QImageIOHandler::Description - << QImageIOHandler::ScaledClipRect - << QImageIOHandler::ScaledSize - << QImageIOHandler::CompressionRatio - << QImageIOHandler::Gamma - << QImageIOHandler::Quality - << QImageIOHandler::Name - << QImageIOHandler::SubType - << QImageIOHandler::IncrementalReading - << QImageIOHandler::Endianness - << QImageIOHandler::Animation - << QImageIOHandler::BackgroundColor; + QFETCH(const QIntList, options); QImageReader reader(prefix + fileName); - for (int i = 0; i < options.size(); ++i) { - QVERIFY(reader.supportsOption(QImageIOHandler::ImageOption(options.at(i)))); - allOptions.remove(QImageIOHandler::ImageOption(options.at(i))); - } - foreach (QImageIOHandler::ImageOption option, allOptions) - QVERIFY(!reader.supportsOption(option)); + for (int i = 0; ; ++i) { + // this switch ensures the compiler warns when we miss an enumerator [-Wswitch] + // do _not_ add a default case! + switch (const auto o = QImageIOHandler::ImageOption(i)) { + case QImageIOHandler::Size: + case QImageIOHandler::ClipRect: + case QImageIOHandler::Description: + case QImageIOHandler::ScaledClipRect: + case QImageIOHandler::ScaledSize: + case QImageIOHandler::CompressionRatio: + case QImageIOHandler::Gamma: + case QImageIOHandler::Quality: + case QImageIOHandler::Name: + case QImageIOHandler::SubType: + case QImageIOHandler::IncrementalReading: + case QImageIOHandler::Endianness: + case QImageIOHandler::Animation: + case QImageIOHandler::BackgroundColor: + case QImageIOHandler::ImageFormat: + case QImageIOHandler::SupportedSubTypes: + case QImageIOHandler::OptimizedWrite: + case QImageIOHandler::ProgressiveScanWrite: + case QImageIOHandler::ImageTransformation: + { + auto printOnFailure = qScopeGuard([&] { qDebug("failed at %d", i); }); + QCOMPARE(reader.supportsOption(o), options.contains(i)); + printOnFailure.dismiss(); + continue; // ... as long as `i` represents a valid ImageOption value + } + } + break; // ... once `i` no longer represents a valid ImageOption value + } } void tst_QImageReader::autoDetectImageFormat() @@ -1825,13 +1914,13 @@ void tst_QImageReader::testIgnoresFormatAndExtension() SKIP_IF_UNSUPPORTED(expected.toLatin1()); - QList<QByteArray> formats = QImageReader::supportedImageFormats(); + const QList<QByteArray> formats = QImageReader::supportedImageFormats(); QString fileNameBase = prefix + name + QLatin1Char('.'); QString tempPath = m_temporaryDir.path(); if (!tempPath.endsWith(QLatin1Char('/'))) tempPath += QLatin1Char('/'); - foreach (const QByteArray &f, formats) { + for (const QByteArray &f : formats) { if (f == extension.toLocal8Bit()) continue; @@ -1981,19 +2070,31 @@ void tst_QImageReader::preserveTexts_data() for (int c = 0xa0; c <= 0xff; c++) latin1set.append(QLatin1Char(c)); - QStringList fileNames; - fileNames << QLatin1String(":/images/kollada.png") - << QLatin1String(":/images/txts.jpg"); - foreach (const QString &fileName, fileNames) { - QTest::newRow("Simple") << fileName << "simpletext"; - QTest::newRow("Whitespace") << fileName << " A text with whitespace "; - QTest::newRow("Newline") << fileName << "A text\nwith newlines\n"; - QTest::newRow("Double newlines") << fileName << "A text\n\nwith double newlines\n\n"; - QTest::newRow("Long") << fileName << QString("A rather long text, at least after many repetitions. ").repeated(100); - QTest::newRow("All Latin1 chars") << fileName << latin1set; + const QList<QLatin1StringView> fileNames{ + QLatin1StringView(":/images/kollada.png"), + QLatin1StringView(":/images/txts.jpg") + // Common prefix of length 9 before file names: ":/images/", skipped below by + 9. + }; + for (const auto &fileName : fileNames) { + QTest::addRow("Simple %s", fileName.data() + 9) + << QString(fileName) << "simpletext"; + QTest::addRow("Whitespace %s", fileName.data() + 9) + << QString(fileName) << " A text with whitespace "; + QTest::addRow("Newline %s", fileName.data() + 9) + << QString(fileName) << "A text\nwith newlines\n"; + QTest::addRow("Double newlines %s", fileName.data() + 9) + << QString(fileName) << "A text\n\nwith double newlines\n\n"; + QTest::addRow("Long %s", fileName.data() + 9) + << QString(fileName) + << QString("A rather long text, at least after many repetitions. ").repeated(100); + QTest::addRow("All Latin1 chars %s", fileName.data() + 9) + << QString(fileName) << latin1set; #if 0 // Depends on iTXt support in libpng - QTest::newRow("Multibyte string") << fileName << QString::fromUtf8("\341\233\222\341\233\226\341\232\251\341\232\271\341\232\242\341\233\232\341\232\240"); + QTest::addRow("Multibyte string %s", fileName.data() + 9) + << QString(fileName) + << QString::fromUtf8("\341\233\222\341\233\226\341\232\251\341\232" + "\271\341\232\242\341\233\232\341\232\240"); #endif } } diff --git a/tests/auto/gui/image/qimagewriter/CMakeLists.txt b/tests/auto/gui/image/qimagewriter/CMakeLists.txt index 7587645585..06273ce7e4 100644 --- a/tests/auto/gui/image/qimagewriter/CMakeLists.txt +++ b/tests/auto/gui/image/qimagewriter/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from qimagewriter.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qimagewriter Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qimagewriter LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data file(GLOB_RECURSE test_data_glob RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} @@ -13,7 +20,7 @@ list(APPEND test_data ${test_data_glob}) qt_internal_add_test(tst_qimagewriter SOURCES tst_qimagewriter.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui TESTDATA ${test_data} ) diff --git a/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp b/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp index 88fa0634fb..1059cc48ab 100644 --- a/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp +++ b/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QDebug> @@ -102,7 +102,7 @@ void tst_QImageWriter::getSetCheck() QCOMPARE((QIODevice *) var1, obj1.device()); // The class should possibly handle a 0-pointer as a device, since - // there is a default contructor, so it's "handling" a 0 device by default. + // there is a default constructor, so it's "handling" a 0 device by default. // For example: QMovie::setDevice(0) works just fine obj1.setDevice((QIODevice *)0); QCOMPARE((QIODevice *) 0, obj1.device()); diff --git a/tests/auto/gui/image/qmovie/CMakeLists.txt b/tests/auto/gui/image/qmovie/CMakeLists.txt index 545ee481d1..52e0a347c4 100644 --- a/tests/auto/gui/image/qmovie/CMakeLists.txt +++ b/tests/auto/gui/image/qmovie/CMakeLists.txt @@ -1,20 +1,28 @@ -# Generated from qmovie.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qmovie Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qmovie LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data file(GLOB_RECURSE test_data_glob RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - animations/*) + animations/* multiframe/*) list(APPEND test_data ${test_data_glob}) qt_internal_add_test(tst_qmovie SOURCES tst_qmovie.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui + Qt::TestPrivate TESTDATA ${test_data} ) @@ -23,6 +31,7 @@ set(resources_resource_files "animations/comicsecard.gif" "animations/corrupt.gif" "animations/trolltech.gif" + "multiframe/Obj_N2_Internal_Mem.ico" ) qt_internal_add_resource(tst_qmovie "resources" @@ -32,16 +41,11 @@ qt_internal_add_resource(tst_qmovie "resources" ${resources_resource_files} ) - -#### Keys ignored in scope 1:.:.:qmovie.pro:<TRUE>: -# MOC_DIR = "tmp" -# QT_FOR_CONFIG = "gui-private" - ## Scopes: ##################################################################### qt_internal_extend_target(tst_qmovie CONDITION TARGET Qt::Widgets - PUBLIC_LIBRARIES + LIBRARIES Qt::Widgets ) diff --git a/tests/auto/gui/image/qmovie/multiframe/Obj_N2_Internal_Mem.ico b/tests/auto/gui/image/qmovie/multiframe/Obj_N2_Internal_Mem.ico Binary files differnew file mode 100644 index 0000000000..8da119efdd --- /dev/null +++ b/tests/auto/gui/image/qmovie/multiframe/Obj_N2_Internal_Mem.ico diff --git a/tests/auto/gui/image/qmovie/tst_qmovie.cpp b/tests/auto/gui/image/qmovie/tst_qmovie.cpp index b2f9c038aa..29c3297043 100644 --- a/tests/auto/gui/image/qmovie/tst_qmovie.cpp +++ b/tests/auto/gui/image/qmovie/tst_qmovie.cpp @@ -1,10 +1,11 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QTestEventLoop> #include <QSignalSpy> +#include <QtTest/private/qpropertytesthelper_p.h> #include <QIODevice> #ifndef QT_NO_WIDGETS @@ -35,12 +36,20 @@ private slots: void playMovie(); void jumpToFrame_data(); void jumpToFrame(); + void frameDelay(); void changeMovieFile(); #ifndef QT_NO_WIDGETS void infiniteLoop(); #endif void emptyMovie(); void bindings(); + void automatedBindings(); +#ifndef QT_NO_ICO + void multiFrameImage(); +#endif + + void setScaledSize_data(); + void setScaledSize(); }; // Testing get/set functions @@ -156,7 +165,7 @@ void tst_QMovie::playMovie() movie.start(); QCOMPARE(movie.state(), QMovie::Running); QTestEventLoop::instance().enterLoop(2); - QCOMPARE(finishedSpy.count(), 0); + QCOMPARE(finishedSpy.size(), 0); QCOMPARE(movie.state(), QMovie::Running); QCOMPARE(movie.currentFrameNumber(), 0); } @@ -176,6 +185,17 @@ void tst_QMovie::jumpToFrame() QCOMPARE(movie.currentFrameNumber(), 0); } +void tst_QMovie::frameDelay() +{ + QMovie movie(QFINDTESTDATA("animations/comicsecard.gif")); + QList<int> frameDelays{ 200, 800, 800, 2000, 2600 }; + for (int i = 0; i < movie.frameCount(); i++) { + movie.jumpToFrame(i); + // Processing may have taken a little time, so round to nearest 100ms + QCOMPARE(100 * qRound(movie.nextFrameDelay() / 100.0f), frameDelays[i]); + } +} + void tst_QMovie::changeMovieFile() { QMovie movie(QFINDTESTDATA("animations/comicsecard.gif")); @@ -239,5 +259,78 @@ void tst_QMovie::bindings() QCOMPARE(cacheModeObserver, QMovie::CacheAll); } +void tst_QMovie::automatedBindings() +{ + QMovie movie; + + QTestPrivate::testReadWritePropertyBasics(movie, 50, 100, "speed"); + if (QTest::currentTestFailed()) { + qDebug("Failed property test for QMovie::speed"); + return; + } + + QTestPrivate::testReadWritePropertyBasics(movie, QMovie::CacheAll, QMovie::CacheNone, + "cacheMode"); + if (QTest::currentTestFailed()) { + qDebug("Failed property test for QMovie::cacheMode"); + return; + } +} + +#ifndef QT_NO_ICO +/*! \internal + Test behavior of QMovie with image formats that are multi-frame, + but not normally intended as animation formats (such as tiff and ico). +*/ +void tst_QMovie::multiFrameImage() +{ + QMovie movie(QFINDTESTDATA("multiframe/Obj_N2_Internal_Mem.ico")); + const int expectedFrameCount = 9; + + QCOMPARE(movie.frameCount(), expectedFrameCount); + QVERIFY(movie.isValid()); + movie.setSpeed(1000); // speed up the test: play at 10 FPS (1000% of normal) + QElapsedTimer playTimer; + QSignalSpy frameChangedSpy(&movie, &QMovie::frameChanged); + QSignalSpy errorSpy(&movie, &QMovie::error); + QSignalSpy finishedSpy(&movie, &QMovie::finished); + playTimer.start(); + movie.start(); + QTRY_COMPARE(finishedSpy.size(), 1); + QCOMPARE_GE(playTimer.elapsed(), 100 * expectedFrameCount); + QCOMPARE(movie.nextFrameDelay(), 100); + QCOMPARE(errorSpy.size(), 0); + QCOMPARE(frameChangedSpy.size(), expectedFrameCount); +} +#endif + +void tst_QMovie::setScaledSize_data() +{ + QTest::addColumn<QString>("fileName"); + QTest::addColumn<QSize>("scaledSize"); + QTest::addColumn<QSize>("expectedSize"); + + QTest::newRow("trolltech (50, 50)") << QString("animations/trolltech.gif") << QSize(50, 50) << QSize(50, 50); + QTest::newRow("trolltech (400, 400)") << QString("animations/trolltech.gif") << QSize(400, 400) << QSize(400, 400); + QTest::newRow("trolltech (50, 0)") << QString("animations/trolltech.gif") << QSize(50, 0) << QSize(50, 25); + QTest::newRow("trolltech (50, -1)") << QString("animations/trolltech.gif") << QSize(50, -1) << QSize(50, 25); + QTest::newRow("trolltech (0, 50)") << QString("animations/trolltech.gif") << QSize(0, 50) << QSize(100, 50); + QTest::newRow("trolltech (-1, 50)") << QString("animations/trolltech.gif") << QSize(-1, 50) << QSize(100, 50); +} + +void tst_QMovie::setScaledSize() +{ + QFETCH(QString, fileName); + QFETCH(QSize, scaledSize); + QFETCH(QSize, expectedSize); + + QMovie movie(QFINDTESTDATA(fileName)); + movie.setScaledSize(scaledSize); + + movie.start(); + QCOMPARE(movie.currentFrameNumber(), 0); + QCOMPARE(movie.currentImage().size(), expectedSize); +} + QTEST_MAIN(tst_QMovie) #include "tst_qmovie.moc" diff --git a/tests/auto/gui/image/qpicture/CMakeLists.txt b/tests/auto/gui/image/qpicture/CMakeLists.txt index 29bf68fa06..30b0aafd11 100644 --- a/tests/auto/gui/image/qpicture/CMakeLists.txt +++ b/tests/auto/gui/image/qpicture/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qpicture.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qpicture Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qpicture LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qpicture SOURCES tst_qpicture.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/image/qpicture/tst_qpicture.cpp b/tests/auto/gui/image/qpicture/tst_qpicture.cpp index de2b841927..2fa4436154 100644 --- a/tests/auto/gui/image/qpicture/tst_qpicture.cpp +++ b/tests/auto/gui/image/qpicture/tst_qpicture.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/gui/image/qpixmap/CMakeLists.txt b/tests/auto/gui/image/qpixmap/CMakeLists.txt index 1946715047..8531ef5b7b 100644 --- a/tests/auto/gui/image/qpixmap/CMakeLists.txt +++ b/tests/auto/gui/image/qpixmap/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from qpixmap.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qpixmap Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qpixmap LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data file(GLOB_RECURSE test_data_glob RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} @@ -25,7 +32,7 @@ list(APPEND test_data ${test_data_glob}) qt_internal_add_test(tst_qpixmap SOURCES tst_qpixmap.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate @@ -95,13 +102,13 @@ qt_internal_add_resource(tst_qpixmap "qpixmap" ##################################################################### qt_internal_extend_target(tst_qpixmap CONDITION TARGET Qt::Widgets - PUBLIC_LIBRARIES + LIBRARIES Qt::Widgets Qt::WidgetsPrivate ) qt_internal_extend_target(tst_qpixmap CONDITION WIN32 - PUBLIC_LIBRARIES + LIBRARIES gdi32 user32 ) diff --git a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp index 4e9be4e033..d8c553b521 100644 --- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QSet> #include <QTemporaryFile> @@ -1176,8 +1176,10 @@ void tst_QPixmap::dprPassthrough() pm.convertFromImage(img); QCOMPARE(pm.devicePixelRatio(), dpr); +#ifndef QT_NO_IMAGE_HEURISTIC_MASK QBitmap heuristicMask = src.createHeuristicMask(); QCOMPARE(heuristicMask.devicePixelRatio(), dpr); +#endif QBitmap maskFromColor = src.createMaskFromColor(Qt::white); QCOMPARE(maskFromColor.devicePixelRatio(), dpr); @@ -1423,7 +1425,7 @@ void tst_QPixmap::loadFromDataImage() QPixmap pixmapWithCopy = QPixmap::fromImage(imageRef); QFile file(imagePath); - file.open(QIODevice::ReadOnly); + QVERIFY(file.open(QIODevice::ReadOnly)); QByteArray rawData = file.readAll(); QPixmap directLoadingPixmap; diff --git a/tests/auto/gui/image/qpixmapcache/CMakeLists.txt b/tests/auto/gui/image/qpixmapcache/CMakeLists.txt index 9e99842e6e..444de9cb3e 100644 --- a/tests/auto/gui/image/qpixmapcache/CMakeLists.txt +++ b/tests/auto/gui/image/qpixmapcache/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qpixmapcache.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qpixmapcache Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qpixmapcache LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qpixmapcache SOURCES tst_qpixmapcache.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate ) diff --git a/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp b/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp index 84b1c8ab06..8384a46491 100644 --- a/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp +++ b/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp @@ -1,7 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#define Q_TEST_QPIXMAPCACHE +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -9,6 +7,16 @@ #include <qpixmapcache.h> #include "private/qpixmapcache_p.h" +#include <functional> + +QT_BEGIN_NAMESPACE // The test requires QT_BUILD_INTERNAL +Q_AUTOTEST_EXPORT void qt_qpixmapcache_flush_detached_pixmaps(); +Q_AUTOTEST_EXPORT int qt_qpixmapcache_qpixmapcache_total_used(); +Q_AUTOTEST_EXPORT int q_QPixmapCache_keyHashSize(); +QT_END_NAMESPACE + +using namespace Qt::StringLiterals; + class tst_QPixmapCache : public QObject { Q_OBJECT @@ -25,13 +33,22 @@ private slots: void setCacheLimit(); void find(); void insert(); + void failedInsertReturnsInvalidKey(); +#if QT_DEPRECATED_SINCE(6, 6) void replace(); +#endif void remove(); void clear(); void pixmapKey(); void noLeak(); + void clearDoesNotLeakStringKeys(); + void evictionDoesNotLeakStringKeys(); + void reducingCacheLimitDoesNotLeakStringKeys(); void strictCacheLimit(); void noCrashOnLargeInsert(); + +private: + void stringLeak_impl(std::function<void()> whenOp); }; static QPixmapCache::KeyData* getPrivate(QPixmapCache::Key &key) @@ -98,28 +115,32 @@ void tst_QPixmapCache::setCacheLimit() //The int part of the API p1 = new QPixmap(2, 3); QPixmapCache::Key key = QPixmapCache::insert(*p1); - QVERIFY(QPixmapCache::find(key, p1) != 0); + QVERIFY(QPixmapCache::find(key, p1)); delete p1; QPixmapCache::setCacheLimit(0); - QVERIFY(QPixmapCache::find(key, p1) == 0); + QVERIFY(!QPixmapCache::find(key, p1)); - p1 = new QPixmap(2, 3); QPixmapCache::setCacheLimit(1000); - QPixmapCache::replace(key, *p1); - QVERIFY(QPixmapCache::find(key, p1) == 0); +#if QT_DEPRECATED_SINCE(6, 6) + QT_WARNING_PUSH + QT_WARNING_DISABLE_DEPRECATED + p1 = new QPixmap(2, 3); + QVERIFY(!QPixmapCache::replace(key, *p1)); + QVERIFY(!QPixmapCache::find(key, p1)); delete p1; +#endif // QT_DEPRECATED_SINCE(6, 6) //Let check if keys are released when the pixmap cache is //full or has been flushed. QPixmapCache::clear(); p1 = new QPixmap(2, 3); key = QPixmapCache::insert(*p1); - QVERIFY(QPixmapCache::find(key, p1) != 0); + QVERIFY(QPixmapCache::find(key, p1)); p1->detach(); // dectach so that the cache thinks no-one is using it. QPixmapCache::setCacheLimit(0); - QVERIFY(QPixmapCache::find(key, p1) == 0); + QVERIFY(!QPixmapCache::find(key, p1)); QPixmapCache::setCacheLimit(1000); key = QPixmapCache::insert(*p1); QVERIFY(key.isValid()); @@ -133,7 +154,7 @@ void tst_QPixmapCache::setCacheLimit() QPixmap p2; p1 = new QPixmap(2, 3); key = QPixmapCache::insert(*p1); - QVERIFY(QPixmapCache::find(key, &p2) != 0); + QVERIFY(QPixmapCache::find(key, &p2)); //we flush the cache p1->detach(); p2.detach(); @@ -141,8 +162,8 @@ void tst_QPixmapCache::setCacheLimit() QPixmapCache::setCacheLimit(1000); QPixmapCache::Key key2 = QPixmapCache::insert(*p1); QCOMPARE(getPrivate(key2)->key, 1); - QVERIFY(QPixmapCache::find(key, &p2) == 0); - QVERIFY(QPixmapCache::find(key2, &p2) != 0); + QVERIFY(!QPixmapCache::find(key, &p2)); + QVERIFY(QPixmapCache::find(key2, &p2)); QCOMPARE(p2, *p1); delete p1; @@ -160,12 +181,12 @@ void tst_QPixmapCache::setCacheLimit() p1->detach(); QPixmapCache::Key key3 = QPixmapCache::insert(*p1); p1->detach(); - QPixmapCache::flushDetachedPixmaps(); + qt_qpixmapcache_flush_detached_pixmaps(); key2 = QPixmapCache::insert(*p1); QCOMPARE(getPrivate(key2)->key, 1); //This old key is not valid anymore after the flush QVERIFY(!key.isValid()); - QVERIFY(QPixmapCache::find(key, &p2) == 0); + QVERIFY(!QPixmapCache::find(key, &p2)); delete p1; } @@ -203,7 +224,7 @@ void tst_QPixmapCache::find() QPixmapCache::insert(p5); //at that time the first key has been erase because no more place in the cache - QVERIFY(QPixmapCache::find(key, &p1) == 0); + QVERIFY(!QPixmapCache::find(key, &p1)); QVERIFY(!key.isValid()); } @@ -262,6 +283,7 @@ void tst_QPixmapCache::insert() for (int i = 0; i < numberOfKeys; ++i) { QPixmap p3(10,10); keys.append(QPixmapCache::insert(p3)); + QVERIFY(keys.back().isValid()); } num = 0; @@ -275,6 +297,35 @@ void tst_QPixmapCache::insert() QVERIFY(num <= estimatedNum); } +void tst_QPixmapCache::failedInsertReturnsInvalidKey() +{ + // + // GIVEN: a pixmap whose memory footprint exceeds the cache's limit: + // + QPixmapCache::setCacheLimit(20); + + QPixmap pm(256, 256); + pm.fill(Qt::transparent); + QCOMPARE_GT(pm.width() * pm.height() * pm.depth() / 8, + QPixmapCache::cacheLimit() * 1024); + + // + // WHEN: trying to add this pixmap to the cache + // + const auto success = QPixmapCache::insert(u"foo"_s, pm); // QString API + { QPixmap r; QVERIFY(!QPixmapCache::find(u"foo"_s, &r)); } + const auto key = QPixmapCache::insert(pm); // "int" API + + // + // THEN: failure is reported to the user + // + QVERIFY(!key.isValid()); // "int" API + QVERIFY(!success); // QString API +} + +#if QT_DEPRECATED_SINCE(6, 6) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED void tst_QPixmapCache::replace() { //The int part of the API @@ -303,6 +354,8 @@ void tst_QPixmapCache::replace() //Broken keys QCOMPARE(QPixmapCache::replace(QPixmapCache::Key(), p2), false); } +QT_WARNING_POP +#endif // QT_DEPRECATED_SINCE(6, 6) void tst_QPixmapCache::remove() { @@ -336,11 +389,11 @@ void tst_QPixmapCache::remove() QVERIFY(p1.toImage() == p1.toImage()); // sanity check QPixmapCache::remove(key); - QVERIFY(QPixmapCache::find(key, &p1) == 0); + QVERIFY(!QPixmapCache::find(key, &p1)); //Broken key QPixmapCache::remove(QPixmapCache::Key()); - QVERIFY(QPixmapCache::find(QPixmapCache::Key(), &p1) == 0); + QVERIFY(!QPixmapCache::find(QPixmapCache::Key(), &p1)); //Test if keys are release QPixmapCache::clear(); @@ -354,7 +407,7 @@ void tst_QPixmapCache::remove() QPixmapCache::clear(); key = QPixmapCache::insert(p1); QCOMPARE(getPrivate(key)->key, 1); - QVERIFY(QPixmapCache::find(key, &p1) != 0); + QVERIFY(QPixmapCache::find(key, &p1)); QPixmapCache::remove(key); QCOMPARE(p1.isDetached(), true); @@ -364,8 +417,8 @@ void tst_QPixmapCache::remove() QPixmapCache::insert("red", p1); key = QPixmapCache::insert(p1); QPixmapCache::remove(key); - QVERIFY(QPixmapCache::find(key, &p1) == 0); - QVERIFY(QPixmapCache::find("red", &p1) != 0); + QVERIFY(!QPixmapCache::find(key, &p1)); + QVERIFY(QPixmapCache::find("red", &p1)); } void tst_QPixmapCache::clear() @@ -409,7 +462,7 @@ void tst_QPixmapCache::clear() QPixmapCache::clear(); for (int k = 0; k < numberOfKeys; ++k) { - QVERIFY(QPixmapCache::find(keys.at(k), &p1) == 0); + QVERIFY(!QPixmapCache::find(keys.at(k), &p1)); QVERIFY(!keys[k].isValid()); } } @@ -458,10 +511,6 @@ void tst_QPixmapCache::pixmapKey() QVERIFY(!getPrivate(key8)); } -QT_BEGIN_NAMESPACE -extern int q_QPixmapCache_keyHashSize(); -QT_END_NAMESPACE - void tst_QPixmapCache::noLeak() { QPixmapCache::Key key; @@ -478,6 +527,68 @@ void tst_QPixmapCache::noLeak() QCOMPARE(oldSize, newSize); } +void tst_QPixmapCache::clearDoesNotLeakStringKeys() +{ + stringLeak_impl([] { QPixmapCache::clear(); }); +} + +void tst_QPixmapCache::evictionDoesNotLeakStringKeys() +{ + stringLeak_impl([] { + // fill the cache with other pixmaps to force eviction of "our" pixmap: + constexpr int Iterations = 10; + for (int i = 0; i < Iterations; ++i) { + QPixmap pm(64, 64); + pm.fill(Qt::transparent); + [[maybe_unused]] auto r = QPixmapCache::insert(pm); + } + }); +} + +void tst_QPixmapCache::reducingCacheLimitDoesNotLeakStringKeys() +{ + stringLeak_impl([] { + QPixmapCache::setCacheLimit(0); + }); +} + +void tst_QPixmapCache::stringLeak_impl(std::function<void()> whenOp) +{ + QVERIFY(whenOp); + + QPixmapCache::setCacheLimit(20); // 20KiB + // + // GIVEN: a QPixmap with QString key `key` in QPixmapCache + // + QString key; + { + QPixmap pm(64, 64); + QCOMPARE_LT(pm.width() * pm.height() * std::ceil(pm.depth() / 8.0), + QPixmapCache::cacheLimit() * 1024); + pm.fill(Qt::transparent); + key = u"theKey"_s.repeated(20); // avoid eventual QString SSO + QVERIFY(key.isDetached()); + QPixmapCache::insert(key, pm); + } + QVERIFY(!key.isDetached()); // was saved inside QPixmapCache + + // + // WHEN: performing the given operation + // + whenOp(); + if (QTest::currentTestFailed()) + return; + + // + // THEN: `key` is no longer referenced by QPixmapCache: + // + QVERIFY(key.isDetached()); + // verify that the pixmap is really gone from the cache + // (do it after the key check, because QPixmapCache cleans up `key` on a failed lookup) + QPixmap r; + QVERIFY(!QPixmapCache::find(key, &r)); +} + void tst_QPixmapCache::strictCacheLimit() { @@ -499,7 +610,7 @@ void tst_QPixmapCache::strictCacheLimit() QPixmapCache::insert(id + "-b", pixmap); } - QVERIFY(QPixmapCache::totalUsed() <= limit); + QVERIFY(qt_qpixmapcache_qpixmapcache_total_used() <= limit); } void tst_QPixmapCache::noCrashOnLargeInsert() diff --git a/tests/auto/gui/itemmodels/CMakeLists.txt b/tests/auto/gui/itemmodels/CMakeLists.txt index 69b6cb0e22..4c25418ef1 100644 --- a/tests/auto/gui/itemmodels/CMakeLists.txt +++ b/tests/auto/gui/itemmodels/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from itemmodels.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause add_subdirectory(qstandarditem) if(TARGET Qt::Widgets) diff --git a/tests/auto/gui/itemmodels/qfilesystemmodel/CMakeLists.txt b/tests/auto/gui/itemmodels/qfilesystemmodel/CMakeLists.txt index 31fd8ca32d..85fb4fe2e1 100644 --- a/tests/auto/gui/itemmodels/qfilesystemmodel/CMakeLists.txt +++ b/tests/auto/gui/itemmodels/qfilesystemmodel/CMakeLists.txt @@ -1,25 +1,23 @@ -# Generated from qfilesystemmodel.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qfilesystemmodel Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qfilesystemmodel LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qfilesystemmodel SOURCES tst_qfilesystemmodel.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::Widgets Qt::WidgetsPrivate Qt::TestPrivate ) - -## Scopes: -##################################################################### - -#### Keys ignored in scope 2:.:.:qfilesystemmodel.pro:WIN32: -# testcase.timeout = "900" - -#### Keys ignored in scope 3:.:.:qfilesystemmodel.pro:MACOS: -# testcase.timeout = "900" diff --git a/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp index 4c94b17df2..4ba3ae11de 100644 --- a/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -20,6 +20,7 @@ #include <QStyle> #include <QtGlobal> #include <QTemporaryDir> +#include <QAbstractItemModelTester> #if defined(Q_OS_WIN) # include <qt_windows.h> // for SetFileAttributes #endif @@ -28,6 +29,7 @@ #include <algorithm> using namespace Qt::StringLiterals; +using namespace std::chrono; #define WAITTIME 1000 @@ -63,6 +65,7 @@ private slots: void rootPath(); void readOnly(); void iconProvider(); + void nullIconProvider(); void rowCount(); @@ -78,6 +81,8 @@ private slots: void filters_data(); void filters(); + void showFilesOnly(); + void nameFilters(); void setData_data(); @@ -112,8 +117,7 @@ protected: bool createFiles(QFileSystemModel *model, const QString &test_path, const QStringList &initial_files, int existingFileCount = 0, const QStringList &initial_dirs = QStringList()); - QModelIndex prepareTestModelRoot(QFileSystemModel *model, const QString &test_path, - QSignalSpy **spy2 = nullptr, QSignalSpy **spy3 = nullptr); + QModelIndex prepareTestModelRoot(QFileSystemModel *model, const QString &test_path); private: QString flatDirTestPath; @@ -149,6 +153,8 @@ void tst_QFileSystemModel::indexPath() { #if !defined(Q_OS_WIN) QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QAbstractItemModelTester tester(model.get()); + tester.setUseFetchMore(false); int depth = QDir::currentPath().count('/'); model->setRootPath(QDir::currentPath()); QString backPath; @@ -163,12 +169,14 @@ void tst_QFileSystemModel::indexPath() void tst_QFileSystemModel::rootPath() { QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QAbstractItemModelTester tester(model.get()); + tester.setUseFetchMore(false); QCOMPARE(model->rootPath(), QString(QDir().path())); QSignalSpy rootChanged(model.data(), &QFileSystemModel::rootPathChanged); QModelIndex root = model->setRootPath(model->rootPath()); root = model->setRootPath("this directory shouldn't exist"); - QCOMPARE(rootChanged.count(), 0); + QCOMPARE(rootChanged.size(), 0); QString oldRootPath = model->rootPath(); const QStringList documentPaths = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation); @@ -185,26 +193,26 @@ void tst_QFileSystemModel::rootPath() QTRY_VERIFY(model->rowCount(root) >= 0); QCOMPARE(model->rootPath(), QString(documentPath)); - QCOMPARE(rootChanged.count(), oldRootPath == model->rootPath() ? 0 : 1); + QCOMPARE(rootChanged.size(), oldRootPath == model->rootPath() ? 0 : 1); QCOMPARE(model->rootDirectory().absolutePath(), documentPath); model->setRootPath(QDir::rootPath()); - int oldCount = rootChanged.count(); + int oldCount = rootChanged.size(); oldRootPath = model->rootPath(); root = model->setRootPath(documentPath + QLatin1String("/.")); QTRY_VERIFY(model->rowCount(root) >= 0); QCOMPARE(model->rootPath(), documentPath); - QCOMPARE(rootChanged.count(), oldRootPath == model->rootPath() ? oldCount : oldCount + 1); + QCOMPARE(rootChanged.size(), oldRootPath == model->rootPath() ? oldCount : oldCount + 1); QCOMPARE(model->rootDirectory().absolutePath(), documentPath); QDir newdir = documentPath; if (newdir.cdUp()) { - oldCount = rootChanged.count(); + oldCount = rootChanged.size(); oldRootPath = model->rootPath(); root = model->setRootPath(documentPath + QLatin1String("/..")); QTRY_VERIFY(model->rowCount(root) >= 0); QCOMPARE(model->rootPath(), newdir.path()); - QCOMPARE(rootChanged.count(), oldCount + 1); + QCOMPARE(rootChanged.size(), oldCount + 1); QCOMPARE(model->rootDirectory().absolutePath(), newdir.path()); } @@ -227,6 +235,8 @@ void tst_QFileSystemModel::rootPath() void tst_QFileSystemModel::readOnly() { QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QAbstractItemModelTester tester(model.get()); + tester.setUseFetchMore(false); QCOMPARE(model->isReadOnly(), true); QTemporaryFile file(flatDirTestPath + QStringLiteral("/XXXXXX.dat")); QVERIFY2(file.open(), qPrintable(file.errorString())); @@ -280,6 +290,8 @@ private: void tst_QFileSystemModel::iconProvider() { QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QAbstractItemModelTester tester(model.get()); + tester.setUseFetchMore(false); QVERIFY(model->iconProvider()); QScopedPointer<QFileIconProvider> provider(new QFileIconProvider); model->setIconProvider(provider.data()); @@ -299,6 +311,19 @@ void tst_QFileSystemModel::iconProvider() QCOMPARE(myModel->fileIcon(myModel->index(QDir::homePath())).pixmap(50, 50), mb); } +void tst_QFileSystemModel::nullIconProvider() +{ + QFileSystemModel model; + QAbstractItemModelTester tester(&model); + tester.setUseFetchMore(false); + QVERIFY(model.iconProvider()); + // No crash when setIconProvider(nullptr) is used + model.setIconProvider(nullptr); + const auto documentPaths = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation); + QVERIFY(!documentPaths.isEmpty()); + model.setRootPath(documentPaths.constFirst()); +} + bool tst_QFileSystemModel::createFiles(QFileSystemModel *model, const QString &test_path, const QStringList &initial_files, int existingFileCount, const QStringList &initial_dirs) @@ -356,17 +381,12 @@ bool tst_QFileSystemModel::createFiles(QFileSystemModel *model, const QString &t return true; } -QModelIndex tst_QFileSystemModel::prepareTestModelRoot(QFileSystemModel *model, const QString &test_path, - QSignalSpy **spy2, QSignalSpy **spy3) +QModelIndex tst_QFileSystemModel::prepareTestModelRoot(QFileSystemModel *model, + const QString &test_path) { if (model->rowCount(model->index(test_path)) != 0) return QModelIndex(); - if (spy2) - *spy2 = new QSignalSpy(model, &QFileSystemModel::rowsInserted); - if (spy3) - *spy3 = new QSignalSpy(model, &QFileSystemModel::rowsAboutToBeInserted); - QStringList files = { "b", "d", "f", "h", "j", ".a", ".c", ".e", ".g" }; if (!createFiles(model, test_path, files)) @@ -386,14 +406,16 @@ QModelIndex tst_QFileSystemModel::prepareTestModelRoot(QFileSystemModel *model, void tst_QFileSystemModel::rowCount() { - QSignalSpy *spy2 = nullptr; - QSignalSpy *spy3 = nullptr; QScopedPointer<QFileSystemModel> model(new QFileSystemModel); - QModelIndex root = prepareTestModelRoot(model.data(), flatDirTestPath, &spy2, &spy3); + QAbstractItemModelTester tester(model.get()); + QSignalSpy rowsInsertedSpy(model.get(), &QFileSystemModel::rowsInserted); + QSignalSpy rowsAboutToBeInsertedSpy(model.get(), &QFileSystemModel::rowsAboutToBeInserted); + tester.setUseFetchMore(false); + QModelIndex root = prepareTestModelRoot(model.data(), flatDirTestPath); QVERIFY(root.isValid()); - QVERIFY(spy2 && spy2->count() > 0); - QVERIFY(spy3 && spy3->count() > 0); + QCOMPARE_GT(rowsInsertedSpy.size(), 0); + QCOMPARE_GT(rowsAboutToBeInsertedSpy.size(), 0); } void tst_QFileSystemModel::rowsInserted_data() @@ -417,6 +439,8 @@ void tst_QFileSystemModel::rowsInserted() { const QString tmp = flatDirTestPath; QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QAbstractItemModelTester tester(model.get()); + tester.setUseFetchMore(false); QModelIndex root = prepareTestModelRoot(model.data(), tmp); QVERIFY(root.isValid()); @@ -433,7 +457,7 @@ void tst_QFileSystemModel::rowsInserted() QVERIFY(createFiles(model.data(), tmp, files, 5)); QTRY_COMPARE(model->rowCount(root), oldCount + count); int totalRowsInserted = 0; - for (int i = 0; i < spy0.count(); ++i) { + for (int i = 0; i < spy0.size(); ++i) { int start = spy0[i].value(1).toInt(); int end = spy0[i].value(2).toInt(); totalRowsInserted += end - start + 1; @@ -442,24 +466,24 @@ void tst_QFileSystemModel::rowsInserted() const QString expected = ascending == Qt::AscendingOrder ? QStringLiteral("j") : QStringLiteral("b"); QTRY_COMPARE(lastEntry(root), expected); - if (spy0.count() > 0) { + if (spy0.size() > 0) { if (count == 0) - QCOMPARE(spy0.count(), 0); + QCOMPARE(spy0.size(), 0); else - QVERIFY(spy0.count() >= 1); + QVERIFY(spy0.size() >= 1); } - if (count == 0) QCOMPARE(spy1.count(), 0); else QVERIFY(spy1.count() >= 1); + if (count == 0) QCOMPARE(spy1.size(), 0); else QVERIFY(spy1.size() >= 1); QVERIFY(createFiles(model.data(), tmp, QStringList(".hidden_file"), 5 + count)); if (count != 0) - QTRY_VERIFY(spy0.count() >= 1); + QTRY_VERIFY(spy0.size() >= 1); else - QTRY_COMPARE(spy0.count(), 0); + QTRY_COMPARE(spy0.size(), 0); if (count != 0) - QTRY_VERIFY(spy1.count() >= 1); + QTRY_VERIFY(spy1.size() >= 1); else - QTRY_COMPARE(spy1.count(), 0); + QTRY_COMPARE(spy1.size(), 0); } void tst_QFileSystemModel::rowsRemoved_data() @@ -471,6 +495,8 @@ void tst_QFileSystemModel::rowsRemoved() { const QString tmp = flatDirTestPath; QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QAbstractItemModelTester tester(model.get()); + tester.setUseFetchMore(false); QModelIndex root = prepareTestModelRoot(model.data(), tmp); QVERIFY(root.isValid()); @@ -488,14 +514,14 @@ void tst_QFileSystemModel::rowsRemoved() } for (int i = 0 ; i < 10; ++i) { if (count != 0) { - if (i == 10 || spy0.count() != 0) { - QVERIFY(spy0.count() >= 1); - QVERIFY(spy1.count() >= 1); + if (i == 10 || spy0.size() != 0) { + QVERIFY(spy0.size() >= 1); + QVERIFY(spy1.size() >= 1); } } else { - if (i == 10 || spy0.count() == 0) { - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); + if (i == 10 || spy0.size() == 0) { + QCOMPARE(spy0.size(), 0); + QCOMPARE(spy1.size(), 0); } } QStringList lst; @@ -514,11 +540,11 @@ void tst_QFileSystemModel::rowsRemoved() QVERIFY(QFile::remove(tmp + QLatin1String("/.c"))); if (count != 0) { - QVERIFY(spy0.count() >= 1); - QVERIFY(spy1.count() >= 1); + QVERIFY(spy0.size() >= 1); + QVERIFY(spy1.size() >= 1); } else { - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); + QCOMPARE(spy0.size(), 0); + QCOMPARE(spy1.size(), 0); } } @@ -533,6 +559,8 @@ void tst_QFileSystemModel::dataChanged() const QString tmp = flatDirTestPath; QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QAbstractItemModelTester tester(model.get()); + tester.setUseFetchMore(false); QModelIndex root = prepareTestModelRoot(model.data(), tmp); QVERIFY(root.isValid()); @@ -548,7 +576,7 @@ void tst_QFileSystemModel::dataChanged() QTest::qWait(WAITTIME); - if (count != 0) QVERIFY(spy.count() >= 1); else QCOMPARE(spy.count(), 0); + if (count != 0) QVERIFY(spy.size() >= 1); else QCOMPARE(spy.size(), 0); } void tst_QFileSystemModel::filters_data() @@ -593,6 +621,8 @@ void tst_QFileSystemModel::filters() { QString tmp = flatDirTestPath; QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QAbstractItemModelTester tester(model.get()); + tester.setUseFetchMore(false); QVERIFY(createFiles(model.data(), tmp, QStringList())); QModelIndex root = model->setRootPath(tmp); QFETCH(QStringList, files); @@ -601,7 +631,7 @@ void tst_QFileSystemModel::filters() QFETCH(QStringList, nameFilters); QFETCH(int, rowCount); - if (nameFilters.count() > 0) + if (nameFilters.size() > 0) model->setNameFilters(nameFilters); model->setNameFilterDisables(false); model->setFilter(dirFilters); @@ -613,12 +643,12 @@ void tst_QFileSystemModel::filters() QDir xFactor(tmp); QStringList dirEntries; - if (nameFilters.count() > 0) + if (nameFilters.size() > 0) dirEntries = xFactor.entryList(nameFilters, dirFilters); else dirEntries = xFactor.entryList(dirFilters); - QCOMPARE(dirEntries.count(), rowCount); + QCOMPARE(dirEntries.size(), rowCount); QStringList modelEntries; @@ -630,7 +660,7 @@ void tst_QFileSystemModel::filters() QCOMPARE(dirEntries, modelEntries); #ifdef Q_OS_LINUX - if (files.count() >= 3 && rowCount >= 3 && rowCount != 5) { + if (files.size() >= 3 && rowCount >= 3 && rowCount != 5) { QString fileName1 = (tmp + '/' + files.at(0)); QString fileName2 = (tmp + '/' + files.at(1)); QString fileName3 = (tmp + '/' + files.at(2)); @@ -656,11 +686,46 @@ void tst_QFileSystemModel::filters() #endif } +void tst_QFileSystemModel::showFilesOnly() +{ + QString tmp = flatDirTestPath; + QFileSystemModel model; + QAbstractItemModelTester tester(&model); + tester.setUseFetchMore(false); + QVERIFY(createFiles(&model, tmp, QStringList())); + const QStringList files{u"a"_s, u"b"_s, u"c"_s}; + const auto subdir = u"sub_directory"_s; + QVERIFY(createFiles(&model, tmp, files, 0, {subdir})); + + // The model changes asynchronously when we run the event loop in the QTRY_... + // macros, so the root index returned by an earlier call to setRootPath might + // become invalid. Make sure we use a fresh one for each iteration. + + // QTBUG-74471 + // WHAT: setting the root path of the model to a dir with some files and a subdir + QTRY_COMPARE(model.rowCount(model.setRootPath(tmp)), files.size() + 1); + + // Change the model to only show files + model.setFilter(QDir::Files); + QTRY_COMPARE(model.rowCount(model.setRootPath(tmp)), files.size()); + + // WHEN: setting the root path to a subdir + QModelIndex subIndex = model.setRootPath(tmp + u'/' + subdir); + QTRY_COMPARE(model.rowCount(subIndex), 0); + + // THEN: setting the root path to the previous (parent) dir, the model should + // still only show files. + // Doubling the default timeout (5s) as this test to fails on macos on the CI + QTRY_COMPARE_WITH_TIMEOUT(model.rowCount(model.setRootPath(tmp)), files.size(), 10s); +} + void tst_QFileSystemModel::nameFilters() { QStringList list; list << "a" << "b" << "c"; QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QAbstractItemModelTester tester(model.get()); + tester.setUseFetchMore(false); model->setNameFilters(list); model->setNameFilterDisables(false); QCOMPARE(model->nameFilters(), list); @@ -706,6 +771,8 @@ void tst_QFileSystemModel::setData_data() void tst_QFileSystemModel::setData() { QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QAbstractItemModelTester tester(model.get()); + tester.setUseFetchMore(false); QSignalSpy spy(model.data(), &QFileSystemModel::fileRenamed); QFETCH(QString, subdirName); QFETCH(QStringList, files); @@ -725,7 +792,7 @@ void tst_QFileSystemModel::setData() tmpIdx = model->index(tmp); model->fetchMore(tmpIdx); } - QTRY_COMPARE(model->rowCount(tmpIdx), files.count()); + QTRY_COMPARE(model->rowCount(tmpIdx), files.size()); QModelIndex idx = model->index(tmp + '/' + oldFileName); QCOMPARE(idx.isValid(), true); @@ -735,16 +802,17 @@ void tst_QFileSystemModel::setData() QCOMPARE(model->setData(idx, newFileName), success); model->setReadOnly(true); if (success) { - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QList<QVariant> arguments = spy.takeFirst(); QCOMPARE(model->data(idx, QFileSystemModel::FileNameRole).toString(), newFileName); + QCOMPARE(model->data(idx, QFileSystemModel::FileInfoRole).value<QFileInfo>().fileName(), newFileName); QCOMPARE(model->fileInfo(idx).filePath(), tmp + '/' + newFileName); QCOMPARE(model->index(arguments.at(0).toString()), model->index(tmp)); QCOMPARE(arguments.at(1).toString(), oldFileName); QCOMPARE(arguments.at(2).toString(), newFileName); QCOMPARE(QFile::rename(tmp + '/' + newFileName, tmp + '/' + oldFileName), true); } - QTRY_COMPARE(model->rowCount(tmpIdx), files.count()); + QTRY_COMPARE(model->rowCount(tmpIdx), files.size()); // cleanup if (!subdirName.isEmpty()) QVERIFY(QDir(tmp).removeRecursively()); @@ -758,6 +826,8 @@ void tst_QFileSystemModel::sortPersistentIndex() file.close(); QTRY_VERIFY(QDir(flatDirTestPath).entryInfoList().contains(fileInfo)); QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QAbstractItemModelTester tester(model.get()); + tester.setUseFetchMore(false); QModelIndex root = model->setRootPath(flatDirTestPath); QTRY_VERIFY(model->rowCount(root) > 0); @@ -802,13 +872,13 @@ void tst_QFileSystemModel::sort() //Create a file that will be at the end when sorting by name (For Mac, the default) //but if we sort by size descending it will be the first QFile tempFile(dirPath + "/plop2.txt"); - tempFile.open(QIODevice::WriteOnly | QIODevice::Text); + QVERIFY(tempFile.open(QIODevice::WriteOnly | QIODevice::Text)); QTextStream out(&tempFile); out << "The magic number is: " << 49 << "\n"; tempFile.close(); QFile tempFile2(dirPath + "/plop.txt"); - tempFile2.open(QIODevice::WriteOnly | QIODevice::Text); + QVERIFY(tempFile2.open(QIODevice::WriteOnly | QIODevice::Text)); QTextStream out2(&tempFile2); out2 << "The magic number is : " << 49 << " but i write some stuff in the file \n"; tempFile2.close(); @@ -837,7 +907,7 @@ void tst_QFileSystemModel::sort() expectedOrder << tempFile2.fileName() << tempFile.fileName() << dirPath + QChar('/') + ".." << dirPath + QChar('/') + "."; if (fileDialogMode) { - QTRY_COMPARE(myModel->rowCount(parent), expectedOrder.count()); + QTRY_COMPARE(myModel->rowCount(parent), expectedOrder.size()); // File dialog Mode means sub trees are not sorted, only the current root. // There's no way we can check that the sub tree is "not sorted"; just check if it // has the same contents of the expected list @@ -864,6 +934,8 @@ void tst_QFileSystemModel::mkdir() QString tmp = flatDirTestPath; QString newFolderPath = QDir::toNativeSeparators(tmp + '/' + "NewFoldermkdirtest4"); QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QAbstractItemModelTester tester(model.get()); + tester.setUseFetchMore(false); QModelIndex tmpDir = model->index(tmp); QVERIFY(tmpDir.isValid()); QDir bestatic(newFolderPath); @@ -899,6 +971,8 @@ void tst_QFileSystemModel::deleteFile() } newFile.close(); QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QAbstractItemModelTester tester(model.get()); + tester.setUseFetchMore(false); QModelIndex idx = model->index(newFilePath); QVERIFY(idx.isValid()); QVERIFY(model->remove(idx)); @@ -961,12 +1035,14 @@ void tst_QFileSystemModel::caseSensitivity() QStringList files; files << "a" << "c" << "C"; QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QAbstractItemModelTester tester(model.get()); + tester.setUseFetchMore(false); QVERIFY(createFiles(model.data(), tmp, files)); QModelIndex root = model->index(tmp); QStringList paths; QModelIndexList indexes; QCOMPARE(model->rowCount(root), 0); - for (int i = 0; i < files.count(); ++i) { + for (int i = 0; i < files.size(); ++i) { const QString path = tmp + '/' + files.at(i); const QModelIndex index = model->index(path); QVERIFY(index.isValid()); @@ -976,7 +1052,7 @@ void tst_QFileSystemModel::caseSensitivity() if (!QFileSystemEngine::isCaseSensitive()) { // QTBUG-31103, QTBUG-64147: Verify that files can be accessed by paths with fLipPeD case. - for (int i = 0; i < paths.count(); ++i) { + for (int i = 0; i < paths.size(); ++i) { const QModelIndex flippedCaseIndex = model->index(flipCase(paths.at(i))); QCOMPARE(indexes.at(i), flippedCaseIndex); } @@ -997,11 +1073,12 @@ void tst_QFileSystemModel::drives() QFileSystemModel model; model.setRootPath(path); model.fetchMore(QModelIndex()); - QFileInfoList drives = QDir::drives(); + const QFileInfoList drives = QDir::drives(); int driveCount = 0; - foreach(const QFileInfo& driveRoot, drives) + for (const QFileInfo& driveRoot : drives) { if (driveRoot.exists()) driveCount++; + } QTRY_COMPARE(model.rowCount(), driveCount); } @@ -1026,6 +1103,8 @@ void tst_QFileSystemModel::dirsBeforeFiles() } QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QAbstractItemModelTester tester(model.get()); + tester.setUseFetchMore(false); QModelIndex root = model->setRootPath(dir.absolutePath()); // Wait for model to be notified by the file system watcher QTRY_COMPARE(model->rowCount(root), 2 * itemCount); @@ -1100,6 +1179,8 @@ void tst_QFileSystemModel::permissions() // checks QTBUG-20503 const QString tmp = flatDirTestPath; const QString file = tmp + QLatin1String("/f"); QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QAbstractItemModelTester tester(model.get()); + tester.setUseFetchMore(false); QVERIFY(createFiles(model.data(), tmp, QStringList{QLatin1String("f")})); QVERIFY(QFile::setPermissions(file, permissions)); diff --git a/tests/auto/gui/itemmodels/qstandarditem/CMakeLists.txt b/tests/auto/gui/itemmodels/qstandarditem/CMakeLists.txt index e5446d596a..db29eaaf94 100644 --- a/tests/auto/gui/itemmodels/qstandarditem/CMakeLists.txt +++ b/tests/auto/gui/itemmodels/qstandarditem/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qstandarditem.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qstandarditem Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qstandarditem LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qstandarditem SOURCES tst_qstandarditem.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp b/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp index 40834459e5..093367c759 100644 --- a/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp +++ b/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -112,13 +112,17 @@ void tst_QStandardItem::getSetData() item.setToolTip(toolTip); QCOMPARE(item.toolTip(), toolTip); +#ifndef QT_NO_STATUSTIP QString statusTip = QLatin1String("statusTip ") + iS; item.setStatusTip(statusTip); QCOMPARE(item.statusTip(), statusTip); +#endif +#if QT_CONFIG(whatsthis) QString whatsThis = QLatin1String("whatsThis ") + iS; item.setWhatsThis(whatsThis); QCOMPARE(item.whatsThis(), whatsThis); +#endif QSize sizeHint(64*i, 48*i); item.setSizeHint(sizeHint); @@ -157,8 +161,12 @@ void tst_QStandardItem::getSetData() QCOMPARE(item.text(), text); QCOMPARE(item.icon(), icon); QCOMPARE(item.toolTip(), toolTip); +#ifndef QT_NO_STATUSTIP QCOMPARE(item.statusTip(), statusTip); +#endif +#if QT_CONFIG(whatsthis) QCOMPARE(item.whatsThis(), whatsThis); +#endif QCOMPARE(item.sizeHint(), sizeHint); QCOMPARE(item.font(), font); QCOMPARE(item.textAlignment(), textAlignment); @@ -171,8 +179,12 @@ void tst_QStandardItem::getSetData() QCOMPARE(qvariant_cast<QString>(item.data(Qt::DisplayRole)), text); QCOMPARE(qvariant_cast<QIcon>(item.data(Qt::DecorationRole)), icon); QCOMPARE(qvariant_cast<QString>(item.data(Qt::ToolTipRole)), toolTip); +#ifndef QT_NO_STATUSTIP QCOMPARE(qvariant_cast<QString>(item.data(Qt::StatusTipRole)), statusTip); +#endif +#if QT_CONFIG(whatsthis) QCOMPARE(qvariant_cast<QString>(item.data(Qt::WhatsThisRole)), whatsThis); +#endif QCOMPARE(qvariant_cast<QSize>(item.data(Qt::SizeHintRole)), sizeHint); QCOMPARE(qvariant_cast<QFont>(item.data(Qt::FontRole)), font); QCOMPARE(qvariant_cast<int>(item.data(Qt::TextAlignmentRole)), int(textAlignment)); @@ -757,10 +769,10 @@ void tst_QStandardItem::takeColumn() QList<QStandardItem *> taken = item.takeColumn(column); if (expectSuccess) { - QCOMPARE(taken.count(), item.rowCount()); + QCOMPARE(taken.size(), item.rowCount()); QCOMPARE(item.columnCount(), columns - 1); int index = column; - for (int i = 0; i < taken.count(); ++i) { + for (int i = 0; i < taken.size(); ++i) { QCOMPARE(taken.at(i), originalChildren.takeAt(index)); index += item.columnCount(); } @@ -818,10 +830,10 @@ void tst_QStandardItem::takeRow() QList<QStandardItem *> taken = item.takeRow(row); if (expectSuccess) { - QCOMPARE(taken.count(), item.columnCount()); + QCOMPARE(taken.size(), item.columnCount()); QCOMPARE(item.rowCount(), rows - 1); int index = row * columns; - for (int i = 0; i < taken.count(); ++i) { + for (int i = 0; i < taken.size(); ++i) { QCOMPARE(taken.at(i), originalChildren.takeAt(index)); } index = 0; @@ -844,7 +856,9 @@ void tst_QStandardItem::streamItem() item.setText(QLatin1String("text")); item.setToolTip(QLatin1String("toolTip")); item.setStatusTip(QLatin1String("statusTip")); +#if QT_CONFIG(whatsthis) item.setWhatsThis(QLatin1String("whatsThis")); +#endif item.setSizeHint(QSize(64, 48)); item.setFont(QFont()); item.setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter); @@ -866,7 +880,9 @@ void tst_QStandardItem::streamItem() QCOMPARE(streamedItem.text(), item.text()); QCOMPARE(streamedItem.toolTip(), item.toolTip()); QCOMPARE(streamedItem.statusTip(), item.statusTip()); +#if QT_CONFIG(whatsthis) QCOMPARE(streamedItem.whatsThis(), item.whatsThis()); +#endif QCOMPARE(streamedItem.sizeHint(), item.sizeHint()); QCOMPARE(streamedItem.font(), item.font()); QCOMPARE(streamedItem.textAlignment(), item.textAlignment()); @@ -905,7 +921,9 @@ void tst_QStandardItem::clone() item.setText(QLatin1String("text")); item.setToolTip(QLatin1String("toolTip")); item.setStatusTip(QLatin1String("statusTip")); +#if QT_CONFIG(whatsthis) item.setWhatsThis(QLatin1String("whatsThis")); +#endif item.setSizeHint(QSize(64, 48)); item.setFont(QFont()); item.setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter); @@ -920,7 +938,9 @@ void tst_QStandardItem::clone() QCOMPARE(clone->text(), item.text()); QCOMPARE(clone->toolTip(), item.toolTip()); QCOMPARE(clone->statusTip(), item.statusTip()); +#if QT_CONFIG(whatsthis) QCOMPARE(clone->whatsThis(), item.whatsThis()); +#endif QCOMPARE(clone->sizeHint(), item.sizeHint()); QCOMPARE(clone->font(), item.font()); QCOMPARE(clone->textAlignment(), item.textAlignment()); @@ -984,8 +1004,8 @@ void tst_QStandardItem::sortChildren() QCOMPARE(two->child(1)->text(), QLatin1String("e")); QCOMPARE(two->child(2)->text(), QLatin1String("f")); - QCOMPARE(layoutAboutToBeChangedSpy.count(), (x == 0) ? 0 : 3); - QCOMPARE(layoutChangedSpy.count(), (x == 0) ? 0 : 3); + QCOMPARE(layoutAboutToBeChangedSpy.size(), (x == 0) ? 0 : 3); + QCOMPARE(layoutChangedSpy.size(), (x == 0) ? 0 : 3); if (x == 0) delete item; @@ -1001,11 +1021,37 @@ public: int type() const override { return QStandardItem::UserType + 1; } bool operator<(const QStandardItem &other) const override { - return text().length() < other.text().length(); + return text().size() < other.text().size(); } using QStandardItem::clone; using QStandardItem::emitDataChanged; + + void setData(const QVariant &value, int role) override + { + switch (role) { + case Qt::DisplayRole: + QStandardItem::setData(value, role); + break; + default: + // setFlags() uses "UserRole - 1" to store the flags, which is an + // implementation detail not exposed in the docs. + QStandardItem::setData(value, role); + break; + } + } + + QVariant data(int role) const override + { + switch (role) { + case Qt::DisplayRole: + return QStandardItem::data(role); + default: + // flags() uses "UserRole - 1" to get the flags, which is an implementation + // detail not exposed in the docs. + return QStandardItem::data(role); + } + } }; Q_DECLARE_METATYPE(QStandardItem*) @@ -1027,8 +1073,8 @@ void tst_QStandardItem::subclassing() QSignalSpy itemChangedSpy(&model, &QStandardItemModel::itemChanged); item->emitDataChanged(); - QCOMPARE(itemChangedSpy.count(), 1); - QCOMPARE(itemChangedSpy.at(0).count(), 1); + QCOMPARE(itemChangedSpy.size(), 1); + QCOMPARE(itemChangedSpy.at(0).size(), 1); QCOMPARE(qvariant_cast<QStandardItem*>(itemChangedSpy.at(0).at(0)), item); CustomItem *child0 = new CustomItem("cc"); @@ -1041,6 +1087,12 @@ void tst_QStandardItem::subclassing() QCOMPARE(item->child(0), child2); QCOMPARE(item->child(1), child0); QCOMPARE(item->child(2), child1); + + item->setFlags(Qt::ItemFlags{0}); + QCOMPARE(item->flags(), Qt::ItemFlags{0}); + + item->setFlags(Qt::ItemFlags{Qt::ItemIsEditable | Qt::ItemIsSelectable}); + QCOMPARE(item->flags(), Qt::ItemFlags{Qt::ItemIsEditable | Qt::ItemIsSelectable}); } void tst_QStandardItem::lessThan() diff --git a/tests/auto/gui/itemmodels/qstandarditemmodel/CMakeLists.txt b/tests/auto/gui/itemmodels/qstandarditemmodel/CMakeLists.txt index 49cbcbfa88..31ae25d008 100644 --- a/tests/auto/gui/itemmodels/qstandarditemmodel/CMakeLists.txt +++ b/tests/auto/gui/itemmodels/qstandarditemmodel/CMakeLists.txt @@ -1,16 +1,24 @@ -# Generated from qstandarditemmodel.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qstandarditemmodel Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qstandarditemmodel LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qstandarditemmodel SOURCES tst_qstandarditemmodel.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate Qt::Widgets Qt::WidgetsPrivate + Qt::TestPrivate ) diff --git a/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp b/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp index ea9077e2a0..ef2fd83d4c 100644 --- a/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp +++ b/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp @@ -1,16 +1,22 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QStandardItemModel> #include <QTreeView> +#include <QMap> #include <QSignalSpy> #include <QAbstractItemModelTester> #include <private/qabstractitemmodel_p.h> +#include <private/qpropertytesthelper_p.h> #include <private/qtreeview_p.h> +#include <algorithm> + +using namespace Qt::StringLiterals; + class tst_QStandardItemModel : public QObject { Q_OBJECT @@ -87,6 +93,7 @@ private slots: void indexFromItem(); void itemFromIndex(); void getSetItemPrototype(); + void getSetItemData_data(); void getSetItemData(); void setHeaderLabels_data(); void setHeaderLabels(); @@ -113,6 +120,7 @@ private slots: void taskQTBUG_45114_setItemData(); void setItemPersistentIndex(); void signalsOnTakeItem(); + void takeChild(); void createPersistentOnLayoutAboutToBeChanged(); private: QStandardItemModel *m_model = nullptr; @@ -448,16 +456,16 @@ void tst_QStandardItemModel::setHeaderData() for (int i = 0; i < count; ++i) { QString customString = QString("custom") + QString::number(i); QCOMPARE(m_model->setHeaderData(i, orient, customString), true); - QCOMPARE(headerDataChangedSpy.count(), 1); - QCOMPARE(dataChangedSpy.count(), 0); + QCOMPARE(headerDataChangedSpy.size(), 1); + QCOMPARE(dataChangedSpy.size(), 0); QVariantList args = headerDataChangedSpy.takeFirst(); QCOMPARE(qvariant_cast<Qt::Orientation>(args.at(0)), orient); QCOMPARE(args.at(1).toInt(), i); QCOMPARE(args.at(2).toInt(), i); QCOMPARE(m_model->headerData(i, orient).toString(), customString); QCOMPARE(m_model->setHeaderData(i, orient, customString), true); - QCOMPARE(headerDataChangedSpy.count(), 0); - QCOMPARE(dataChangedSpy.count(), 0); + QCOMPARE(headerDataChangedSpy.size(), 0); + QCOMPARE(dataChangedSpy.size(), 0); } //check read from invalid sections @@ -720,7 +728,7 @@ void tst_QStandardItemModel::data() const QMap<int, QVariant> itmData = m_model->itemData(m_model->index(0, 0)); QCOMPARE(itmData.value(Qt::DisplayRole), QLatin1String("initialitem")); QCOMPARE(itmData.value(Qt::ToolTipRole), QLatin1String("tooltip")); - QVERIFY(!itmData.contains(Qt::UserRole - 1)); + QVERIFY(!itmData.contains(Qt::UserRole - 1)); // Qt::UserRole - 1 is used to store flags QVERIFY(m_model->itemData(QModelIndex()).isEmpty()); } @@ -761,9 +769,9 @@ void tst_QStandardItemModel::clear() model.clear(); - QCOMPARE(modelResetSpy.count(), 1); - QCOMPARE(layoutChangedSpy.count(), 0); - QCOMPARE(rowsRemovedSpy.count(), 0); + QCOMPARE(modelResetSpy.size(), 1); + QCOMPARE(layoutChangedSpy.size(), 0); + QCOMPARE(rowsRemovedSpy.size(), 0); QCOMPARE(model.index(0, 0), QModelIndex()); QCOMPARE(model.columnCount(), 0); QCOMPARE(model.rowCount(), 0); @@ -805,8 +813,8 @@ void tst_QStandardItemModel::sort() QFETCH(QStringList, expected); // prepare model QStandardItemModel model; - QVERIFY(model.insertRows(0, initial.count(), QModelIndex())); - QCOMPARE(model.rowCount(QModelIndex()), initial.count()); + QVERIFY(model.insertRows(0, initial.size(), QModelIndex())); + QCOMPARE(model.rowCount(QModelIndex()), initial.size()); model.insertColumns(0, 1, QModelIndex()); QCOMPARE(model.columnCount(QModelIndex()), 1); for (int row = 0; row < model.rowCount(QModelIndex()); ++row) { @@ -822,8 +830,8 @@ void tst_QStandardItemModel::sort() // sort model.sort(0, sortOrder); - QCOMPARE(layoutAboutToBeChangedSpy.count(), 1); - QCOMPARE(layoutChangedSpy.count(), 1); + QCOMPARE(layoutAboutToBeChangedSpy.size(), 1); + QCOMPARE(layoutChangedSpy.size(), 1); // make sure the model is sorted for (int row = 0; row < model.rowCount(QModelIndex()); ++row) { @@ -867,7 +875,7 @@ void tst_QStandardItemModel::sortRole() QFETCH(QVariantList, expectedData); QStandardItemModel model; - for (int i = 0; i < initialText.count(); ++i) { + for (int i = 0; i < initialText.size(); ++i) { QStandardItem *item = new QStandardItem; item->setText(initialText.at(i)); item->setData(initialData.at(i), Qt::UserRole); @@ -875,7 +883,7 @@ void tst_QStandardItemModel::sortRole() } model.setSortRole(sortRole); model.sort(0, sortOrder); - for (int i = 0; i < expectedText.count(); ++i) { + for (int i = 0; i < expectedText.size(); ++i) { QStandardItem *item = model.item(i); QCOMPARE(item->text(), expectedText.at(i)); QCOMPARE(item->data(Qt::UserRole), expectedData.at(i)); @@ -896,6 +904,9 @@ void tst_QStandardItemModel::sortRoleBindings() sortRoleObserver.setBinding([&] { return model.sortRole(); }); model.setSortRole(Qt::EditRole); QCOMPARE(sortRoleObserver, Qt::EditRole); + + QTestPrivate::testReadWritePropertyBasics(model, static_cast<int>(Qt::DisplayRole), + static_cast<int>(Qt::EditRole), "sortRole"); } void tst_QStandardItemModel::findItems() @@ -906,15 +917,15 @@ void tst_QStandardItemModel::findItems() model.item(1)->appendRow(new QStandardItem(QLatin1String("foo"))); QList<QStandardItem*> matches; matches = model.findItems(QLatin1String("foo"), Qt::MatchExactly|Qt::MatchRecursive, 0); - QCOMPARE(matches.count(), 2); + QCOMPARE(matches.size(), 2); matches = model.findItems(QLatin1String("foo"), Qt::MatchExactly, 0); - QCOMPARE(matches.count(), 1); + QCOMPARE(matches.size(), 1); matches = model.findItems(QLatin1String("food"), Qt::MatchExactly|Qt::MatchRecursive, 0); - QCOMPARE(matches.count(), 0); + QCOMPARE(matches.size(), 0); matches = model.findItems(QLatin1String("foo"), Qt::MatchExactly|Qt::MatchRecursive, -1); - QCOMPARE(matches.count(), 0); + QCOMPARE(matches.size(), 0); matches = model.findItems(QLatin1String("foo"), Qt::MatchExactly|Qt::MatchRecursive, 1); - QCOMPARE(matches.count(), 0); + QCOMPARE(matches.size(), 0); } void tst_QStandardItemModel::getSetHeaderItem() @@ -1025,33 +1036,49 @@ void tst_QStandardItemModel::getSetItemPrototype() QCOMPARE(model.itemPrototype(), nullptr); } +using RoleMap = QMap<int, QVariant>; +using RoleList = QList<int>; + +static RoleMap getSetItemDataRoleMap(int textRole) +{ + return {{textRole, "text"_L1}, + {Qt::StatusTipRole, "statusTip"_L1}, + {Qt::ToolTipRole, "toolTip"_L1}, + {Qt::WhatsThisRole, "whatsThis"_L1}, + {Qt::SizeHintRole, QSize{64, 48}}, + {Qt::FontRole, QFont{}}, + {Qt::TextAlignmentRole, int(Qt::AlignLeft|Qt::AlignVCenter)}, + {Qt::BackgroundRole, QColor(Qt::blue)}, + {Qt::ForegroundRole, QColor(Qt::green)}, + {Qt::CheckStateRole, int(Qt::PartiallyChecked)}, + {Qt::AccessibleTextRole, "accessibleText"_L1}, + {Qt::AccessibleDescriptionRole, "accessibleDescription"_L1}}; +} + +void tst_QStandardItemModel::getSetItemData_data() +{ + QTest::addColumn<RoleMap>("itemData"); + QTest::addColumn<RoleMap>("expectedItemData"); + QTest::addColumn<RoleList>("expectedRoles"); + + // QTBUG-112326: verify that text data set using Qt::EditRole is mapped to + // Qt::DisplayRole and both roles are in the changed signal + const RoleMap expectedItemData = getSetItemDataRoleMap(Qt::DisplayRole); + RoleList expectedRoles = expectedItemData.keys() << Qt::EditRole; + std::sort(expectedRoles.begin(), expectedRoles.end()); + + QTest::newRow("DisplayRole") << expectedItemData + << expectedItemData << expectedRoles; + + QTest::newRow("EditRole") << getSetItemDataRoleMap(Qt::EditRole) + << expectedItemData << expectedRoles; +} + void tst_QStandardItemModel::getSetItemData() { - QMap<int, QVariant> roles; - QLatin1String text("text"); - roles.insert(Qt::DisplayRole, text); - QLatin1String statusTip("statusTip"); - roles.insert(Qt::StatusTipRole, statusTip); - QLatin1String toolTip("toolTip"); - roles.insert(Qt::ToolTipRole, toolTip); - QLatin1String whatsThis("whatsThis"); - roles.insert(Qt::WhatsThisRole, whatsThis); - QSize sizeHint(64, 48); - roles.insert(Qt::SizeHintRole, sizeHint); - QFont font; - roles.insert(Qt::FontRole, font); - Qt::Alignment textAlignment(Qt::AlignLeft|Qt::AlignVCenter); - roles.insert(Qt::TextAlignmentRole, int(textAlignment)); - QColor backgroundColor(Qt::blue); - roles.insert(Qt::BackgroundRole, backgroundColor); - QColor textColor(Qt::green); - roles.insert(Qt::ForegroundRole, textColor); - Qt::CheckState checkState(Qt::PartiallyChecked); - roles.insert(Qt::CheckStateRole, int(checkState)); - QLatin1String accessibleText("accessibleText"); - roles.insert(Qt::AccessibleTextRole, accessibleText); - QLatin1String accessibleDescription("accessibleDescription"); - roles.insert(Qt::AccessibleDescriptionRole, accessibleDescription); + QFETCH(RoleMap, itemData); + QFETCH(RoleMap, expectedItemData); + QFETCH(RoleList, expectedRoles); QStandardItemModel model; model.insertRows(0, 1); @@ -1060,11 +1087,17 @@ void tst_QStandardItemModel::getSetItemData() QSignalSpy modelDataChangedSpy( &model, &QStandardItemModel::dataChanged); - QVERIFY(model.setItemData(idx, roles)); - QCOMPARE(modelDataChangedSpy.count(), 1); - QVERIFY(model.setItemData(idx, roles)); - QCOMPARE(modelDataChangedSpy.count(), 1); //it was already changed once - QCOMPARE(model.itemData(idx), roles); + QVERIFY(model.setItemData(idx, itemData)); + QCOMPARE(modelDataChangedSpy.size(), 1); + const QVariantList &args = modelDataChangedSpy.constFirst(); + QCOMPARE(args.size(), 3); + auto roleList = args.at(2).value<QList<int> >(); + std::sort(roleList.begin(), roleList.end()); + QCOMPARE(roleList, expectedRoles); + + QVERIFY(model.setItemData(idx, itemData)); + QCOMPARE(modelDataChangedSpy.size(), 1); //it was already changed once + QCOMPARE(model.itemData(idx), expectedItemData); } void tst_QStandardItemModel::setHeaderLabels_data() @@ -1127,12 +1160,12 @@ void tst_QStandardItemModel::setHeaderLabels() model.setHorizontalHeaderLabels(labels); else model.setVerticalHeaderLabels(labels); - for (int i = 0; i < expectedLabels.count(); ++i) + for (int i = 0; i < expectedLabels.size(); ++i) QCOMPARE(model.headerData(i, orientation).toString(), expectedLabels.at(i)); - QCOMPARE(columnsInsertedSpy.count(), - (orientation == Qt::Vertical) ? 0 : labels.count() > columns); - QCOMPARE(rowsInsertedSpy.count(), - (orientation == Qt::Horizontal) ? 0 : labels.count() > rows); + QCOMPARE(columnsInsertedSpy.size(), + (orientation == Qt::Vertical) ? 0 : labels.size() > columns); + QCOMPARE(rowsInsertedSpy.size(), + (orientation == Qt::Horizontal) ? 0 : labels.size() > rows); } void tst_QStandardItemModel::itemDataChanged() @@ -1143,8 +1176,8 @@ void tst_QStandardItemModel::itemDataChanged() QSignalSpy itemChangedSpy(&model, &QStandardItemModel::itemChanged); model.setItem(0, &item); - QCOMPARE(dataChangedSpy.count(), 1); - QCOMPARE(itemChangedSpy.count(), 1); + QCOMPARE(dataChangedSpy.size(), 1); + QCOMPARE(itemChangedSpy.size(), 1); QModelIndex index = model.indexFromItem(&item); QList<QVariant> args; args = dataChangedSpy.takeFirst(); @@ -1154,8 +1187,8 @@ void tst_QStandardItemModel::itemDataChanged() QCOMPARE(qvariant_cast<QStandardItem*>(args.at(0)), &item); item.setData(QLatin1String("foo"), Qt::DisplayRole); - QCOMPARE(dataChangedSpy.count(), 1); - QCOMPARE(itemChangedSpy.count(), 1); + QCOMPARE(dataChangedSpy.size(), 1); + QCOMPARE(itemChangedSpy.size(), 1); args = dataChangedSpy.takeFirst(); QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), index); QCOMPARE(qvariant_cast<QModelIndex>(args.at(1)), index); @@ -1163,12 +1196,12 @@ void tst_QStandardItemModel::itemDataChanged() QCOMPARE(qvariant_cast<QStandardItem*>(args.at(0)), &item); item.setData(item.data(Qt::DisplayRole), Qt::DisplayRole); - QCOMPARE(dataChangedSpy.count(), 0); - QCOMPARE(itemChangedSpy.count(), 0); + QCOMPARE(dataChangedSpy.size(), 0); + QCOMPARE(itemChangedSpy.size(), 0); item.setFlags(Qt::ItemIsEnabled); - QCOMPARE(dataChangedSpy.count(), 1); - QCOMPARE(itemChangedSpy.count(), 1); + QCOMPARE(dataChangedSpy.size(), 1); + QCOMPARE(itemChangedSpy.size(), 1); args = dataChangedSpy.takeFirst(); QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), index); QCOMPARE(qvariant_cast<QModelIndex>(args.at(1)), index); @@ -1176,8 +1209,8 @@ void tst_QStandardItemModel::itemDataChanged() QCOMPARE(qvariant_cast<QStandardItem*>(args.at(0)), &item); item.setFlags(item.flags()); - QCOMPARE(dataChangedSpy.count(), 0); - QCOMPARE(itemChangedSpy.count(), 0); + QCOMPARE(dataChangedSpy.size(), 0); + QCOMPARE(itemChangedSpy.size(), 0); } void tst_QStandardItemModel::takeHeaderItem() @@ -1305,7 +1338,7 @@ void tst_QStandardItemModel::setNullChild() QSignalSpy spy(&model, &QAbstractItemModel::dataChanged); item->setChild(0, nullptr); QCOMPARE(item->child(0), nullptr); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } void tst_QStandardItemModel::deleteChild() @@ -1317,7 +1350,7 @@ void tst_QStandardItemModel::deleteChild() QSignalSpy spy(&model, &QAbstractItemModel::dataChanged); delete item->child(0); QCOMPARE(item->child(0), nullptr); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } void tst_QStandardItemModel::rootItemFlags() @@ -1558,8 +1591,8 @@ void tst_QStandardItemModel::removeRowsAndColumns() QStringList row_list = QString("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20").split(','); QStringList col_list = row_list; QStandardItemModel model; - for (int c = 0; c < col_list.count(); c++) - for (int r = 0; r < row_list.count(); r++) + for (int c = 0; c < col_list.size(); c++) + for (int r = 0; r < row_list.size(); r++) model.setItem(r, c, new QStandardItem(row_list[r] + QLatin1Char('x') + col_list[c])); VERIFY_MODEL @@ -1580,16 +1613,22 @@ void tst_QStandardItemModel::removeRowsAndColumns() VERIFY_MODEL QList<QStandardItem *> row_taken = model.takeRow(6); - QCOMPARE(row_taken.count(), col_list.count()); - for (int c = 0; c < col_list.count(); c++) - QCOMPARE(row_taken[c]->text() , row_list[6] + QLatin1Char('x') + col_list[c]); + QCOMPARE(row_taken.size(), col_list.size()); + for (qsizetype c = 0; c < row_taken.size(); c++) { + auto item = row_taken.at(c); + QCOMPARE(item->text() , row_list[6] + QLatin1Char('x') + col_list[c]); + delete item; + } row_list.remove(6); VERIFY_MODEL QList<QStandardItem *> col_taken = model.takeColumn(10); - QCOMPARE(col_taken.count(), row_list.count()); - for (int r = 0; r < row_list.count(); r++) - QCOMPARE(col_taken[r]->text() , row_list[r] + QLatin1Char('x') + col_list[10]); + QCOMPARE(col_taken.size(), row_list.size()); + for (qsizetype r = 0; r < col_taken.size(); r++) { + auto item = col_taken.at(r); + QCOMPARE(item->text() , row_list[r] + QLatin1Char('x') + col_list[10]); + delete item; + } col_list.remove(10); VERIFY_MODEL } @@ -1605,8 +1644,8 @@ void tst_QStandardItemModel::itemRoleNames() QStringList row_list = QString("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20").split(','); QStringList col_list = row_list; QStandardItemModel model; - for (int c = 0; c < col_list.count(); c++) - for (int r = 0; r < row_list.count(); r++) + for (int c = 0; c < col_list.size(); c++) + for (int r = 0; r < row_list.size(); r++) model.setItem(r, c, new QStandardItem(row_list[r] + QLatin1Char('x') + col_list[c])); VERIFY_MODEL @@ -1646,7 +1685,7 @@ void tst_QStandardItemModel::taskQTBUG_45114_setItemData() QModelIndex index = item->index(); QCOMPARE(model.itemData(index).size(), 3); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); QMap<int, QVariant> roles; @@ -1654,21 +1693,21 @@ void tst_QStandardItemModel::taskQTBUG_45114_setItemData() roles.insert(Qt::UserRole + 2, 2); model.setItemData(index, roles); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); roles.insert(Qt::UserRole + 1, 1); roles.insert(Qt::UserRole + 2, 2); roles.insert(Qt::UserRole + 3, QVariant()); model.setItemData(index, roles); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); roles.clear(); roles.insert(Qt::UserRole + 1, 10); roles.insert(Qt::UserRole + 3, 12); model.setItemData(index, roles); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QMap<int, QVariant> itemRoles = model.itemData(index); QCOMPARE(itemRoles.size(), 4); @@ -1680,13 +1719,13 @@ void tst_QStandardItemModel::taskQTBUG_45114_setItemData() roles.insert(Qt::UserRole + 3, 1); model.setItemData(index, roles); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); roles.clear(); roles.insert(Qt::UserRole + 3, QVariant()); model.setItemData(index, roles); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); itemRoles = model.itemData(index); QCOMPARE(itemRoles.size(), 3); @@ -1739,13 +1778,13 @@ void tst_QStandardItemModel::signalsOnTakeItem() // QTBUG-89145 QSignalSpy dataChangedSpy(&m, &QAbstractItemModel::dataChanged); QStandardItem *const takenItem = m.takeItem(1, 0); for (auto &&spy : removeSpies) { - QCOMPARE(spy->count(), 1); + QCOMPARE(spy->size(), 1); const auto spyArgs = spy->takeFirst(); QCOMPARE(spyArgs.at(0).value<QModelIndex>(), parentIndex); QCOMPARE(spyArgs.at(1).toInt(), 0); QCOMPARE(spyArgs.at(2).toInt(), 1); } - QCOMPARE(dataChangedSpy.count(), 1); + QCOMPARE(dataChangedSpy.size(), 1); const auto dataChangedSpyArgs = dataChangedSpy.takeFirst(); QCOMPARE(dataChangedSpyArgs.at(0).value<QModelIndex>(), m.index(1, 0)); QCOMPARE(dataChangedSpyArgs.at(1).value<QModelIndex>(), m.index(1, 0)); @@ -1759,6 +1798,7 @@ void tst_QStandardItemModel::signalsOnTakeItem() // QTBUG-89145 QCOMPARE(takenItem->model(), nullptr); QCOMPARE(takenItem->child(0, 0)->model(), nullptr); QCOMPARE(m.index(1, 0).data(), QVariant()); + delete takenItem; } void tst_QStandardItemModel::createPersistentOnLayoutAboutToBeChanged() // QTBUG-93466 @@ -1796,5 +1836,36 @@ void tst_QStandardItemModel::createPersistentOnLayoutAboutToBeChanged() // QTBUG QCOMPARE(layoutChangedSpy.size(), 1); } +void tst_QStandardItemModel::takeChild() // QTBUG-117900 +{ + { + // with model + QStandardItemModel model1; + QStandardItemModel model2; + QStandardItem base1("base1"); + model1.setItem(0, 0, &base1); + QStandardItem base2("base2"); + model2.setItem(0, 0, &base2); + auto item = new QStandardItem("item1"); + item->appendRow(new QStandardItem("child")); + base1.appendRow(item); + base2.appendRow(base1.takeChild(0, 0)); + QCOMPARE(base1.child(0, 0), nullptr); + QCOMPARE(base2.child(0, 0), item); + } + { + // without model + QStandardItem base1("base1"); + QStandardItem base2("base2"); + auto item = new QStandardItem("item1"); + item->appendRow(new QStandardItem("child")); + base1.appendRow(item); + base2.appendRow(base1.takeChild(0, 0)); + QCOMPARE(base1.child(0, 0), nullptr); + QCOMPARE(base2.child(0, 0), item); + } +} + + QTEST_MAIN(tst_QStandardItemModel) #include "tst_qstandarditemmodel.moc" diff --git a/tests/auto/gui/kernel/CMakeLists.txt b/tests/auto/gui/kernel/CMakeLists.txt index 1e72872516..9acd817610 100644 --- a/tests/auto/gui/kernel/CMakeLists.txt +++ b/tests/auto/gui/kernel/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from kernel.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause if(QT_FEATURE_action) add_subdirectory(qaction) @@ -9,6 +10,7 @@ add_subdirectory(qcursor) add_subdirectory(qdrag) add_subdirectory(qevent) add_subdirectory(qfileopenevent) +add_subdirectory(qguichronotimer) add_subdirectory(qguieventdispatcher) add_subdirectory(qguitimer) if(NOT ANDROID AND NOT WASM) @@ -28,7 +30,7 @@ endif() add_subdirectory(qpixelformat) add_subdirectory(qrasterwindow) add_subdirectory(qaddpostroutine) -if(NOT ANDROID AND NOT UIKIT) +if(NOT UIKIT) add_subdirectory(qclipboard) endif() if(TARGET Qt::Network) diff --git a/tests/auto/gui/kernel/noqteventloop/CMakeLists.txt b/tests/auto/gui/kernel/noqteventloop/CMakeLists.txt index 9e47156add..e9d3d96af9 100644 --- a/tests/auto/gui/kernel/noqteventloop/CMakeLists.txt +++ b/tests/auto/gui/kernel/noqteventloop/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from noqteventloop.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_noqteventloop Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_noqteventloop LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_noqteventloop SOURCES tst_noqteventloop.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate @@ -18,6 +25,6 @@ qt_internal_add_test(tst_noqteventloop ##################################################################### qt_internal_extend_target(tst_noqteventloop CONDITION QT_FEATURE_dynamicgl AND WIN32 - PUBLIC_LIBRARIES + LIBRARIES user32 ) diff --git a/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp b/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp index e7a2a67895..65fe4a83ed 100644 --- a/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp +++ b/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -131,7 +131,8 @@ public: } - void run() { + void run() override + { struct ScopedCleanup { /* This is in order to ensure that the window is hidden when returning from run(), diff --git a/tests/auto/gui/kernel/qaction/CMakeLists.txt b/tests/auto/gui/kernel/qaction/CMakeLists.txt index ed0a0a8a5b..8f70a36c61 100644 --- a/tests/auto/gui/kernel/qaction/CMakeLists.txt +++ b/tests/auto/gui/kernel/qaction/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qaction.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qaction_kernel Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qaction_kernel LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qaction_kernel SOURCES tst_qaction.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/kernel/qaction/tst_qaction.cpp b/tests/auto/gui/kernel/qaction/tst_qaction.cpp index cebcf9ca5a..4a4d1a75c8 100644 --- a/tests/auto/gui/kernel/qaction/tst_qaction.cpp +++ b/tests/auto/gui/kernel/qaction/tst_qaction.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2019 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QSignalSpy> @@ -209,11 +209,11 @@ void tst_QAction::setToolTip() QFETCH(QStringList, values); QFETCH(QStringList, expectedToolTips); - QCOMPARE(properties.count(), values.count()); - QCOMPARE(properties.count(), expectedToolTips.count()); + QCOMPARE(properties.size(), values.size()); + QCOMPARE(properties.size(), expectedToolTips.size()); QAction action(nullptr); - for (int i = 0; i < properties.count(); ++i) { + for (int i = 0; i < properties.size(); ++i) { const auto property = properties.at(i); const auto value = values.at(i); const auto expectedToolTip = expectedToolTips.at(i); @@ -272,19 +272,19 @@ void tst_QAction::task229128TriggeredSignalWithoutActiongroup() // test without a group const QScopedPointer<QAction> actionWithoutGroup(new QAction("Test", nullptr)); QSignalSpy spyWithoutGroup(actionWithoutGroup.data(), QOverload<bool>::of(&QAction::triggered)); - QCOMPARE(spyWithoutGroup.count(), 0); + QCOMPARE(spyWithoutGroup.size(), 0); actionWithoutGroup->trigger(); // signal should be emitted - QCOMPARE(spyWithoutGroup.count(), 1); + QCOMPARE(spyWithoutGroup.size(), 1); // it is now a checkable checked action actionWithoutGroup->setCheckable(true); actionWithoutGroup->setChecked(true); spyWithoutGroup.clear(); - QCOMPARE(spyWithoutGroup.count(), 0); + QCOMPARE(spyWithoutGroup.size(), 0); actionWithoutGroup->trigger(); // signal should be emitted - QCOMPARE(spyWithoutGroup.count(), 1); + QCOMPARE(spyWithoutGroup.size(), 1); } void tst_QAction::setData() // QTBUG-62006 @@ -292,14 +292,14 @@ void tst_QAction::setData() // QTBUG-62006 QAction act(nullptr); QSignalSpy spy(&act, &QAction::changed); QCOMPARE(act.data(), QVariant()); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); act.setData(QVariant()); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); act.setData(-1); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); act.setData(-1); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } void tst_QAction::setEnabledSetVisible() @@ -308,22 +308,22 @@ void tst_QAction::setEnabledSetVisible() QSignalSpy spy(&action, &QAction::enabledChanged); QVERIFY(action.isEnabled()); QVERIFY(action.isVisible()); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); action.setVisible(false); QVERIFY(!action.isEnabled()); QVERIFY(!action.isVisible()); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); action.setEnabled(false); QVERIFY(!action.isEnabled()); QVERIFY(!action.isVisible()); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); action.setVisible(true); QVERIFY(!action.isEnabled()); QVERIFY(action.isVisible()); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); action.resetEnabled(); QVERIFY(action.isEnabled()); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } void tst_QAction::setCheckabledSetChecked() @@ -334,37 +334,37 @@ void tst_QAction::setCheckabledSetChecked() QSignalSpy checkableSpy(&action, &QAction::checkableChanged); QVERIFY(!action.isCheckable()); QVERIFY(!action.isChecked()); - QCOMPARE(changedSpy.count(), 0); - QCOMPARE(checkedSpy.count(), 0); - QCOMPARE(checkableSpy.count(), 0); + QCOMPARE(changedSpy.size(), 0); + QCOMPARE(checkedSpy.size(), 0); + QCOMPARE(checkableSpy.size(), 0); action.setCheckable(true); QVERIFY(action.isCheckable()); QVERIFY(!action.isChecked()); - QCOMPARE(changedSpy.count(), 1); - QCOMPARE(checkedSpy.count(), 0); - QCOMPARE(checkableSpy.count(), 1); + QCOMPARE(changedSpy.size(), 1); + QCOMPARE(checkedSpy.size(), 0); + QCOMPARE(checkableSpy.size(), 1); action.setChecked(true); QVERIFY(action.isCheckable()); QVERIFY(action.isChecked()); - QCOMPARE(changedSpy.count(), 2); - QCOMPARE(checkedSpy.count(), 1); - QCOMPARE(checkableSpy.count(), 1); + QCOMPARE(changedSpy.size(), 2); + QCOMPARE(checkedSpy.size(), 1); + QCOMPARE(checkableSpy.size(), 1); action.setCheckable(false); QVERIFY(!action.isCheckable()); QVERIFY(!action.isChecked()); - QCOMPARE(changedSpy.count(), 3); - QCOMPARE(checkedSpy.count(), 2); - QCOMPARE(checkableSpy.count(), 2); + QCOMPARE(changedSpy.size(), 3); + QCOMPARE(checkedSpy.size(), 2); + QCOMPARE(checkableSpy.size(), 2); action.setCheckable(true); QVERIFY(action.isCheckable()); QVERIFY(action.isChecked()); - QCOMPARE(changedSpy.count(), 4); - QCOMPARE(checkedSpy.count(), 3); - QCOMPARE(checkableSpy.count(), 3); + QCOMPARE(changedSpy.size(), 4); + QCOMPARE(checkedSpy.size(), 3); + QCOMPARE(checkableSpy.size(), 3); } QTEST_MAIN(tst_QAction) diff --git a/tests/auto/gui/kernel/qactiongroup/CMakeLists.txt b/tests/auto/gui/kernel/qactiongroup/CMakeLists.txt index 10354f865c..360a20cc95 100644 --- a/tests/auto/gui/kernel/qactiongroup/CMakeLists.txt +++ b/tests/auto/gui/kernel/qactiongroup/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qactiongroup.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qactiongroup_kernel Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qactiongroup_kernel LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qactiongroup_kernel SOURCES tst_qactiongroup.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/kernel/qactiongroup/tst_qactiongroup.cpp b/tests/auto/gui/kernel/qactiongroup/tst_qactiongroup.cpp index 2e04e13b7e..a9e331e111 100644 --- a/tests/auto/gui/kernel/qactiongroup/tst_qactiongroup.cpp +++ b/tests/auto/gui/kernel/qactiongroup/tst_qactiongroup.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2019 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/gui/kernel/qaddpostroutine/CMakeLists.txt b/tests/auto/gui/kernel/qaddpostroutine/CMakeLists.txt index 454196ce1b..46a0475521 100644 --- a/tests/auto/gui/kernel/qaddpostroutine/CMakeLists.txt +++ b/tests/auto/gui/kernel/qaddpostroutine/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qaddpostroutine.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qaddpostroutine Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qaddpostroutine LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qaddpostroutine SOURCES tst_qaddpostroutine.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/kernel/qaddpostroutine/tst_qaddpostroutine.cpp b/tests/auto/gui/kernel/qaddpostroutine/tst_qaddpostroutine.cpp index c56eb3ff4c..c5cc0a9b20 100644 --- a/tests/auto/gui/kernel/qaddpostroutine/tst_qaddpostroutine.cpp +++ b/tests/auto/gui/kernel/qaddpostroutine/tst_qaddpostroutine.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2020 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/gui/kernel/qbackingstore/CMakeLists.txt b/tests/auto/gui/kernel/qbackingstore/CMakeLists.txt index 64ef31a0b5..811da8bb53 100644 --- a/tests/auto/gui/kernel/qbackingstore/CMakeLists.txt +++ b/tests/auto/gui/kernel/qbackingstore/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qbackingstore.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qbackingstore Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qbackingstore LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qbackingstore SOURCES tst_qbackingstore.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/kernel/qbackingstore/tst_qbackingstore.cpp b/tests/auto/gui/kernel/qbackingstore/tst_qbackingstore.cpp index 0406fe0f07..a830d14be8 100644 --- a/tests/auto/gui/kernel/qbackingstore/tst_qbackingstore.cpp +++ b/tests/auto/gui/kernel/qbackingstore/tst_qbackingstore.cpp @@ -1,9 +1,11 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qwindow.h> #include <qbackingstore.h> #include <qpa/qplatformbackingstore.h> +#include <qpa/qplatformintegration.h> +#include <private/qguiapplication_p.h> #include <qpainter.h> #include <QTest> @@ -30,6 +32,8 @@ private slots: void scroll(); void flush(); + + void staticContents(); }; void tst_QBackingStore::initTestCase_data() @@ -89,6 +93,11 @@ void tst_QBackingStore::paint() QRect rect(0, 0, 100, 100); backingStore.resize(rect.size()); + // Partial fill of a fresh backingstore should not crash + backingStore.beginPaint(QRect(0, 0, 50, 50)); + backingStore.endPaint(); + backingStore.flush(rect); + // Two rounds, with flush in between for (int i = 0; i < 2; ++i) { backingStore.beginPaint(rect); @@ -239,7 +248,7 @@ public: backingStore.resize(size()); } - void exposeEvent(QExposeEvent *event) override + void paintEvent(QPaintEvent *event) override { QRect rect(QPoint(), size()); @@ -251,10 +260,7 @@ public: backingStore.endPaint(); -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED backingStore.flush(event->region().boundingRect()); -QT_WARNING_POP } private: @@ -270,5 +276,79 @@ void tst_QBackingStore::flush() QTRY_VERIFY(window.isExposed()); } +void tst_QBackingStore::staticContents() +{ + const auto *integration = QGuiApplicationPrivate::platformIntegration(); + if (!integration->hasCapability(QPlatformIntegration::BackingStoreStaticContents)) + QSKIP("Platform does not support static backingstore content"); + + QWindow window; + window.create(); + + const auto dpr = window.devicePixelRatio(); + + QBackingStore backingStore(&window); + + QRect initialRect(0, 0, 100, 100); + + // Static contents without paint first should not crash + backingStore.setStaticContents(initialRect); + backingStore.resize(initialRect.size()); + QCOMPARE(backingStore.size(), initialRect.size()); + backingStore.beginPaint(QRect(0, 0, 50, 50)); + backingStore.endPaint(); + backingStore.handle()->toImage(); + + { + backingStore.setStaticContents(QRect()); + backingStore.beginPaint(initialRect); + QPainter p(backingStore.paintDevice()); + p.fillRect(initialRect, Qt::green); + p.end(); + backingStore.endPaint(); + + QImage image = backingStore.handle()->toImage(); + if (image.isNull()) + QSKIP("Platform backingstore does not implement toImage"); + + QCOMPARE(image.pixelColor(initialRect.topLeft() * dpr), Qt::green); + QCOMPARE(image.pixelColor(initialRect.bottomLeft() * dpr), Qt::green); + QCOMPARE(image.pixelColor(initialRect.topRight() * dpr), Qt::green); + QCOMPARE(image.pixelColor(initialRect.bottomRight() * dpr), Qt::green); + } + + { + backingStore.setStaticContents(initialRect); + + QRect resizedRect(0, 0, 200, 200); + backingStore.resize(resizedRect.size()); + + QRegion repaintRegion = QRegion(resizedRect) - QRegion(initialRect); + + backingStore.beginPaint(repaintRegion); + QPainter p(backingStore.paintDevice()); + for (auto repaintRect : repaintRegion) + p.fillRect(repaintRect, Qt::red); + p.end(); + backingStore.endPaint(); + + QImage image = backingStore.handle()->toImage(); + if (image.isNull()) + QSKIP("Platform backingstore does not implement toImage"); + + QCOMPARE(image.pixelColor(initialRect.topLeft() * dpr), Qt::green); + QCOMPARE(image.pixelColor(initialRect.bottomLeft() * dpr), Qt::green); + QCOMPARE(image.pixelColor(initialRect.topRight() * dpr), Qt::green); + QCOMPARE(image.pixelColor(initialRect.bottomRight() * dpr), Qt::green); + + for (auto repaintRect : repaintRegion) { + QCOMPARE(image.pixelColor(repaintRect.topLeft() * dpr), Qt::red); + QCOMPARE(image.pixelColor(repaintRect.bottomLeft() * dpr), Qt::red); + QCOMPARE(image.pixelColor(repaintRect.topRight() * dpr), Qt::red); + QCOMPARE(image.pixelColor(repaintRect.bottomRight() * dpr), Qt::red); + } + } +} + #include <tst_qbackingstore.moc> QTEST_MAIN(tst_QBackingStore); diff --git a/tests/auto/gui/kernel/qclipboard/CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/CMakeLists.txt index 05eba972d6..b7a0467758 100644 --- a/tests/auto/gui/kernel/qclipboard/CMakeLists.txt +++ b/tests/auto/gui/kernel/qclipboard/CMakeLists.txt @@ -1,4 +1,11 @@ -# Generated from qclipboard.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_qclipboard LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() add_subdirectory(copier) add_subdirectory(paster) diff --git a/tests/auto/gui/kernel/qclipboard/copier/CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/copier/CMakeLists.txt index ef599b121e..ea7def8c0d 100644 --- a/tests/auto/gui/kernel/qclipboard/copier/CMakeLists.txt +++ b/tests/auto/gui/kernel/qclipboard/copier/CMakeLists.txt @@ -1,23 +1,16 @@ -# Generated from copier.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## copier Binary: ##################################################################### -# special case begin set(args OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") -# special case end qt_internal_add_executable(copier - ${args} # special case + ${args} SOURCES main.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) - -## Scopes: -##################################################################### - -#### Keys ignored in scope 2:.:.:copier.pro:WIN32: -# DESTDIR = "../copier" diff --git a/tests/auto/gui/kernel/qclipboard/copier/main.cpp b/tests/auto/gui/kernel/qclipboard/copier/main.cpp index 411ac1e00e..362ede38b7 100644 --- a/tests/auto/gui/kernel/qclipboard/copier/main.cpp +++ b/tests/auto/gui/kernel/qclipboard/copier/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtGui/QGuiApplication> #include <QtGui/QClipboard> #include <QtCore/QStringList> diff --git a/tests/auto/gui/kernel/qclipboard/paster/CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/paster/CMakeLists.txt index 571ae4944e..9bc1985ee4 100644 --- a/tests/auto/gui/kernel/qclipboard/paster/CMakeLists.txt +++ b/tests/auto/gui/kernel/qclipboard/paster/CMakeLists.txt @@ -1,23 +1,16 @@ -# Generated from paster.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## paster Binary: ##################################################################### -# special case begin set(args OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") -# special case end qt_internal_add_executable(paster - ${args} # special case + ${args} SOURCES main.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) - -## Scopes: -##################################################################### - -#### Keys ignored in scope 2:.:.:paster.pro:WIN32: -# DESTDIR = "../paster" diff --git a/tests/auto/gui/kernel/qclipboard/paster/main.cpp b/tests/auto/gui/kernel/qclipboard/paster/main.cpp index 06db447569..bf47b10ba6 100644 --- a/tests/auto/gui/kernel/qclipboard/paster/main.cpp +++ b/tests/auto/gui/kernel/qclipboard/paster/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtGui/QGuiApplication> #include <QtGui/QClipboard> #include <QtGui/QImage> diff --git a/tests/auto/gui/kernel/qclipboard/test/BLACKLIST b/tests/auto/gui/kernel/qclipboard/test/BLACKLIST new file mode 100644 index 0000000000..3ca7791b37 --- /dev/null +++ b/tests/auto/gui/kernel/qclipboard/test/BLACKLIST @@ -0,0 +1,5 @@ +# QTBUG-87429 +[testSignals] +android +[setMimeData] +android diff --git a/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt index 0e9fa8f40d..fad30c16fd 100644 --- a/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt +++ b/tests/auto/gui/kernel/qclipboard/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_qclipboard Test: @@ -8,7 +9,7 @@ qt_internal_add_test(tst_qclipboard OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" SOURCES ../tst_qclipboard.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate ) @@ -17,9 +18,8 @@ qt_internal_add_test(tst_qclipboard ##################################################################### qt_internal_extend_target(tst_qclipboard CONDITION MACOS - PUBLIC_LIBRARIES + LIBRARIES ${FWAppKit} ) -#### Keys ignored in scope 6:.:.:test.pro:NOT ANDROID: # TEST_HELPER_INSTALLS = "../copier/copier" "../paster/paster" diff --git a/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp index 4163d072e0..30366c6aa1 100644 --- a/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp +++ b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -21,8 +21,9 @@ #ifdef Q_OS_WIN # include <QtGui/private/qguiapplication_p.h> -# include <QtGui/private/qwindowsmime_p.h> +# include <QtGui/qwindowsmimeconverter.h> # include <QtGui/qpa/qplatformintegration.h> +# include <QtCore/qt_windows.h> #endif class tst_QClipboard : public QObject @@ -41,6 +42,7 @@ private slots: void testSignals(); void setMimeData(); void clearBeforeSetText(); + void getTextFromHTMLMimeType(); # ifdef Q_OS_WIN void testWindowsMimeRegisterType(); void testWindowsMime_data(); @@ -61,7 +63,7 @@ void tst_QClipboard::initTestCase() #if QT_CONFIG(clipboard) void tst_QClipboard::init() { -#if QT_CONFIG(process) +#if QT_CONFIG(process) && !defined(Q_OS_ANDROID) const QString testdataDir = QFileInfo(QFINDTESTDATA("copier")).absolutePath(); QVERIFY2(QDir::setCurrent(testdataDir), qPrintable("Could not chdir to " + testdataDir)); #endif @@ -124,7 +126,7 @@ public: operator bool() const { - if (m_timer.elapsed() && !m_spy.count()) + if (m_timer.elapsed() && !m_spy.size()) return true; m_spy.clear(); return false; @@ -166,11 +168,11 @@ void tst_QClipboard::testSignals() // Test the default mode signal. clipboard->setText(text); - QTRY_COMPARE(dataChangedSpy.count(), 1); - QCOMPARE(searchChangedSpy.count(), 0); - QCOMPARE(selectionChangedSpy.count(), 0); - QCOMPARE(changedSpy.count(), 1); - QCOMPARE(changedSpy.at(0).count(), 1); + QTRY_COMPARE(dataChangedSpy.size(), 1); + QCOMPARE(searchChangedSpy.size(), 0); + QCOMPARE(selectionChangedSpy.size(), 0); + QCOMPARE(changedSpy.size(), 1); + QCOMPARE(changedSpy.at(0).size(), 1); QCOMPARE(qvariant_cast<QClipboard::Mode>(changedSpy.at(0).at(0)), QClipboard::Clipboard); changedSpy.clear(); @@ -178,29 +180,29 @@ void tst_QClipboard::testSignals() // Test the selection mode signal. if (clipboard->supportsSelection()) { clipboard->setText(text, QClipboard::Selection); - QCOMPARE(selectionChangedSpy.count(), 1); - QCOMPARE(changedSpy.count(), 1); - QCOMPARE(changedSpy.at(0).count(), 1); + QCOMPARE(selectionChangedSpy.size(), 1); + QCOMPARE(changedSpy.size(), 1); + QCOMPARE(changedSpy.at(0).size(), 1); QCOMPARE(qvariant_cast<QClipboard::Mode>(changedSpy.at(0).at(0)), QClipboard::Selection); } else { - QCOMPARE(selectionChangedSpy.count(), 0); + QCOMPARE(selectionChangedSpy.size(), 0); } - QCOMPARE(dataChangedSpy.count(), 1); - QCOMPARE(searchChangedSpy.count(), 0); + QCOMPARE(dataChangedSpy.size(), 1); + QCOMPARE(searchChangedSpy.size(), 0); changedSpy.clear(); // Test the search mode signal. if (clipboard->supportsFindBuffer()) { clipboard->setText(text, QClipboard::FindBuffer); - QCOMPARE(searchChangedSpy.count(), 1); - QCOMPARE(changedSpy.count(), 1); - QCOMPARE(changedSpy.at(0).count(), 1); + QCOMPARE(searchChangedSpy.size(), 1); + QCOMPARE(changedSpy.size(), 1); + QCOMPARE(changedSpy.at(0).size(), 1); QCOMPARE(qvariant_cast<QClipboard::Mode>(changedSpy.at(0).at(0)), QClipboard::FindBuffer); } else { - QCOMPARE(searchChangedSpy.count(), 0); + QCOMPARE(searchChangedSpy.size(), 0); } - QCOMPARE(dataChangedSpy.count(), 1); + QCOMPARE(dataChangedSpy.size(), 1); } #if defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(Q_OS_QNX) @@ -340,16 +342,16 @@ void tst_QClipboard::setMimeData() QGuiApplication::clipboard()->clear(QClipboard::FindBuffer); if (QGuiApplication::clipboard()->supportsSelection()) - QCOMPARE(spySelection.count(), 1); + QCOMPARE(spySelection.size(), 1); else - QCOMPARE(spySelection.count(), 0); + QCOMPARE(spySelection.size(), 0); if (QGuiApplication::clipboard()->supportsFindBuffer()) - QCOMPARE(spyFindBuffer.count(), 1); + QCOMPARE(spyFindBuffer.size(), 1); else - QCOMPARE(spyFindBuffer.count(), 0); + QCOMPARE(spyFindBuffer.size(), 0); - QTRY_COMPARE(spyData.count(), 1); + QTRY_COMPARE(spyData.size(), 1); // an other crash test data = new QMimeData; @@ -376,16 +378,16 @@ void tst_QClipboard::setMimeData() QGuiApplication::clipboard()->setMimeData(newData, QClipboard::FindBuffer); if (QGuiApplication::clipboard()->supportsSelection()) - QCOMPARE(spySelection.count(), 1); + QCOMPARE(spySelection.size(), 1); else - QCOMPARE(spySelection.count(), 0); + QCOMPARE(spySelection.size(), 0); if (QGuiApplication::clipboard()->supportsFindBuffer()) - QCOMPARE(spyFindBuffer.count(), 1); + QCOMPARE(spyFindBuffer.size(), 1); else - QCOMPARE(spyFindBuffer.count(), 0); + QCOMPARE(spyFindBuffer.size(), 0); - QTRY_COMPARE(spyData.count(), 1); + QTRY_COMPARE(spyData.size(), 1); } void tst_QClipboard::clearBeforeSetText() @@ -424,12 +426,30 @@ void tst_QClipboard::clearBeforeSetText() QCOMPARE(QGuiApplication::clipboard()->text(), text); } +void tst_QClipboard::getTextFromHTMLMimeType() +{ + QClipboard * clipboard = QGuiApplication::clipboard(); + QMimeData * mimeData = new QMimeData(); + const QString testString("TEST"); + const QString htmlString(QLatin1String("<html><body>") + testString + QLatin1String("</body></html>")); + + mimeData->setText(testString); + mimeData->setHtml(htmlString); + clipboard->setMimeData(mimeData); + + QCOMPARE(clipboard->text(), testString); + QVERIFY(clipboard->mimeData()->hasText()); + QVERIFY(clipboard->mimeData()->hasHtml()); + QCOMPARE(clipboard->mimeData()->text(), testString); + QCOMPARE(clipboard->mimeData()->html(), htmlString); +} + # ifdef Q_OS_WIN -using QWindowsMime = QNativeInterface::Private::QWindowsMime; +using QWindowsMimeConverter = QWindowsMimeConverter; using QWindowsApplication = QNativeInterface::Private::QWindowsApplication; -class TestMime : public QWindowsMime +class TestMime : public QWindowsMimeConverter { public: bool canConvertFromMime(const FORMATETC &, const QMimeData *) const override diff --git a/tests/auto/gui/kernel/qcursor/CMakeLists.txt b/tests/auto/gui/kernel/qcursor/CMakeLists.txt index 1304dd2ba2..52c88fc231 100644 --- a/tests/auto/gui/kernel/qcursor/CMakeLists.txt +++ b/tests/auto/gui/kernel/qcursor/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qcursor.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qcursor Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qcursor LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qcursor SOURCES tst_qcursor.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/kernel/qcursor/tst_qcursor.cpp b/tests/auto/gui/kernel/qcursor/tst_qcursor.cpp index 42ef690efa..edc44b9ea6 100644 --- a/tests/auto/gui/kernel/qcursor/tst_qcursor.cpp +++ b/tests/auto/gui/kernel/qcursor/tst_qcursor.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtTest/QTest> #include <qcursor.h> diff --git a/tests/auto/gui/kernel/qdrag/CMakeLists.txt b/tests/auto/gui/kernel/qdrag/CMakeLists.txt index b03f82da39..015cfe70d0 100644 --- a/tests/auto/gui/kernel/qdrag/CMakeLists.txt +++ b/tests/auto/gui/kernel/qdrag/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qdrag.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdrag Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdrag LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qdrag SOURCES tst_qdrag.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/kernel/qdrag/tst_qdrag.cpp b/tests/auto/gui/kernel/qdrag/tst_qdrag.cpp index 8891ddc4ea..9e0d5ad0f4 100644 --- a/tests/auto/gui/kernel/qdrag/tst_qdrag.cpp +++ b/tests/auto/gui/kernel/qdrag/tst_qdrag.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/gui/kernel/qevent/CMakeLists.txt b/tests/auto/gui/kernel/qevent/CMakeLists.txt index 7b37b0c51a..c6ad861f25 100644 --- a/tests/auto/gui/kernel/qevent/CMakeLists.txt +++ b/tests/auto/gui/kernel/qevent/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qevent.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qevent Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qevent LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qevent SOURCES tst_qevent.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::CorePrivate ) diff --git a/tests/auto/gui/kernel/qevent/tst_qevent.cpp b/tests/auto/gui/kernel/qevent/tst_qevent.cpp index 0ad8a60bea..8e8169b16c 100644 --- a/tests/auto/gui/kernel/qevent/tst_qevent.cpp +++ b/tests/auto/gui/kernel/qevent/tst_qevent.cpp @@ -1,17 +1,56 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtGui/qguiapplication.h> #include <QtGui/qevent.h> +#if QT_CONFIG(future) #include <QtCore/private/qfutureinterface_p.h> +#endif + + +#if QT_CONFIG(future) +#define X_QFutureCallOutEvent(X) X(QFutureCallOutEvent, ()) +#else +#define X_QFutureCallOutEvent(X) +#endif + +#if QT_CONFIG(wheelevent) +#define X_QWheelEvent(X) X(QWheelEvent, ({}, {}, {}, {}, {}, {}, {}, {})) +#else +#define X_QWheelEvent(X) +#endif + +#if QT_CONFIG(tabletevent) +#define X_QTabletEvent(X) X(QTabletEvent, (QEvent::None, QPointingDevice::primaryPointingDevice(), {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {})) +#else +#define X_QTabletEvent(X) +#endif + +#if QT_CONFIG(gestures) +#define X_QNativeGestureEvent(X) X(QNativeGestureEvent, ({}, QPointingDevice::primaryPointingDevice(), 0, {}, {}, {}, {}, {})) +#else +#define X_QNativeGestureEvent(X) +#endif + +#if QT_CONFIG(whatsthis) +#define X_QWhatsThisClickedEvent(X) X(QWhatsThisClickedEvent, ({})) +#else +#define X_QWhatsThisClickedEvent(X) +#endif + +#if QT_CONFIG(action) +#define X_QActionEvent(X) X(QActionEvent, (0, nullptr)) +#else +#define X_QActionEvent(X) +#endif -#ifdef QT_BUILD_INTERNAL -# define ONLY_IF_INTERNAL_BUILD(...) __VA_ARGS__ +#if QT_CONFIG(shortcut) +#define X_QShortcutEvent(X) X(QShortcutEvent, ({}, 0)) #else -# define ONLY_IF_INTERNAL_BUILD(...) +#define X_QShortcutEvent(X) #endif #define FOR_EACH_CORE_EVENT(X) \ @@ -20,9 +59,8 @@ X(QTimerEvent, (42)) \ X(QChildEvent, (QEvent::ChildAdded, nullptr)) \ X(QDynamicPropertyChangeEvent, ("size")) \ - X(QDeferredDeleteEvent, ()) \ /* qfutureinterface_p.h */ \ - ONLY_IF_INTERNAL_BUILD(X(QFutureCallOutEvent, ())) \ + X_QFutureCallOutEvent(X) \ /* end */ #define FOR_EACH_GUI_EVENT(X) \ @@ -34,9 +72,9 @@ X(QEnterEvent, ({}, {}, {})) \ X(QMouseEvent, (QEvent::None, {}, {}, {}, {}, {}, {}, {}, QPointingDevice::primaryPointingDevice())) \ X(QHoverEvent, (QEvent::None, {}, {}, QPointF{})) \ - X(QWheelEvent, ({}, {}, {}, {}, {}, {}, {}, {})) \ - X(QTabletEvent, (QEvent::None, QPointingDevice::primaryPointingDevice(), {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {})) \ - X(QNativeGestureEvent, ({}, QPointingDevice::primaryPointingDevice(), 0, {}, {}, {}, {}, {})) \ + X_QWheelEvent(X) \ + X_QTabletEvent(X) \ + X_QNativeGestureEvent(X) \ X(QKeyEvent, (QEvent::None, 0, {})) \ X(QFocusEvent, (QEvent::None)) \ X(QPaintEvent, (QRect{0, 0, 100, 100})) \ @@ -48,10 +86,7 @@ X(QIconDragEvent, ()) \ X(QShowEvent, ()) \ X(QHideEvent, ()) \ - QT_WARNING_PUSH \ - QT_WARNING_DISABLE_DEPRECATED \ - X(QContextMenuEvent, (QContextMenuEvent::Reason::Keyboard, {})) \ - QT_WARNING_POP \ + X(QContextMenuEvent, (QContextMenuEvent::Reason::Keyboard, {}, {})) \ X(QInputMethodEvent, ()) \ X(QInputMethodQueryEvent, ({})) \ X(QDropEvent, ({}, {}, {}, {}, {})) \ @@ -60,11 +95,11 @@ X(QDragLeaveEvent, ()) \ X(QHelpEvent, ({}, {}, {})) \ X(QStatusTipEvent, ({})) \ - X(QWhatsThisClickedEvent, ({})) \ - X(QActionEvent, (0, nullptr)) \ + X_QWhatsThisClickedEvent(X) \ + X_QActionEvent(X) \ X(QFileOpenEvent, (QString{})) \ X(QToolBarChangeEvent, (false)) \ - X(QShortcutEvent, ({}, 0)) \ + X_QShortcutEvent(X) \ X(QWindowStateChangeEvent, ({})) \ X(QTouchEvent, (QEvent::None)) \ X(QScrollPrepareEvent, ({})) \ diff --git a/tests/auto/gui/kernel/qfileopenevent/CMakeLists.txt b/tests/auto/gui/kernel/qfileopenevent/CMakeLists.txt index 2404833737..9906400a66 100644 --- a/tests/auto/gui/kernel/qfileopenevent/CMakeLists.txt +++ b/tests/auto/gui/kernel/qfileopenevent/CMakeLists.txt @@ -1,4 +1,11 @@ -# Generated from qfileopenevent.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_qfileopenevent LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() add_subdirectory(test) add_subdirectory(qfileopeneventexternal) diff --git a/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/CMakeLists.txt b/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/CMakeLists.txt index 658a70619f..7a39bc111c 100644 --- a/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/CMakeLists.txt +++ b/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from qfileopeneventexternal.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## qfileopeneventexternal Binary: @@ -8,9 +9,6 @@ qt_internal_add_executable(qfileopeneventexternal GUI SOURCES qfileopeneventexternal.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) - -#### Keys ignored in scope 1:.:.:qfileopeneventexternal.pro:<TRUE>: -# TEMPLATE = "app" diff --git a/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp b/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp index 6e50a96258..bd74e7497f 100644 --- a/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp +++ b/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtGui> #include <QEvent> @@ -14,8 +14,8 @@ struct MyApplication : public QGuiApplication { if (event->type() == QEvent::FileOpen) { QFileOpenEvent* ev = static_cast<QFileOpenEvent *>(event); - QFile file; - bool ok = ev->openFile(file, QFile::Append | QFile::Unbuffered); + QFile file(ev->file()); + bool ok = file.open(QFile::Append | QFile::Unbuffered); if (ok) file.write(QByteArray("+external")); return true; diff --git a/tests/auto/gui/kernel/qfileopenevent/test/CMakeLists.txt b/tests/auto/gui/kernel/qfileopenevent/test/CMakeLists.txt index faa5e5acfc..d7f4e32f70 100644 --- a/tests/auto/gui/kernel/qfileopenevent/test/CMakeLists.txt +++ b/tests/auto/gui/kernel/qfileopenevent/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_qfileopenevent Test: @@ -7,6 +8,6 @@ qt_internal_add_test(tst_qfileopenevent SOURCES tst_qfileopenevent.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/kernel/qfileopenevent/test/tst_qfileopenevent.cpp b/tests/auto/gui/kernel/qfileopenevent/test/tst_qfileopenevent.cpp index b526240d88..4b9a23ffcf 100644 --- a/tests/auto/gui/kernel/qfileopenevent/test/tst_qfileopenevent.cpp +++ b/tests/auto/gui/kernel/qfileopenevent/test/tst_qfileopenevent.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtCore/QTemporaryDir> #include <QTest> @@ -54,7 +54,7 @@ void tst_qfileopenevent::cleanupTestCase() void tst_qfileopenevent::createFile(const QString &filename, const QByteArray &content) { QFile file(filename); - file.open(QFile::WriteOnly); + QVERIFY(file.open(QFile::WriteOnly)); file.write(content); file.close(); } @@ -78,8 +78,9 @@ void tst_qfileopenevent::constructor() QByteArray tst_qfileopenevent::readFileContent(QFileOpenEvent& event) { - QFile file; - event.openFile(file, QFile::ReadOnly); + QFile file(event.file()); + if (!file.open(QFile::ReadOnly)) + qFatal("Cannot open file %s", qPrintable(event.file())); file.seek(0); QByteArray data = file.readAll(); return data; @@ -87,8 +88,8 @@ QByteArray tst_qfileopenevent::readFileContent(QFileOpenEvent& event) bool tst_qfileopenevent::appendFileContent(QFileOpenEvent& event, const QByteArray& writeContent) { - QFile file; - bool ok = event.openFile(file, QFile::Append | QFile::Unbuffered); + QFile file(event.file()); + bool ok = file.open(QFile::Append | QFile::Unbuffered); if (ok) ok = file.write(writeContent) == writeContent.size(); return ok; @@ -127,8 +128,8 @@ void tst_qfileopenevent::handleLifetime() QScopedPointer<QFileOpenEvent> event(createFileAndEvent(QLatin1String("testHandleLifetime"), QByteArray("test content"))); // open a QFile after the original RFile is closed - QFile qFile; - QCOMPARE(event->openFile(qFile, QFile::Append | QFile::Unbuffered), true); + QFile qFile(event->file()); + QVERIFY(qFile.open(QFile::Append | QFile::Unbuffered)); event.reset(0); // write to the QFile after the event is closed @@ -138,7 +139,7 @@ void tst_qfileopenevent::handleLifetime() // check the content QFile checkContent("testHandleLifetime"); - checkContent.open(QFile::ReadOnly); + QVERIFY(checkContent.open(QFile::ReadOnly)); QString content(checkContent.readAll()); QCOMPARE(content, QLatin1String("test content+closed original handles")); checkContent.close(); @@ -152,7 +153,8 @@ void tst_qfileopenevent::multiOpen() QFile files[5]; for (int i=0; i<5; i++) { - QCOMPARE(event->openFile(files[i], QFile::ReadOnly), true); + files[i].setFileName(event->file()); + QVERIFY(files[i].open(QFile::ReadOnly)); } for (int i=0; i<5; i++) files[i].seek(i); diff --git a/tests/auto/gui/kernel/qguiapplication/BLACKLIST b/tests/auto/gui/kernel/qguiapplication/BLACKLIST index 2f1e5f333e..3fa6c4880b 100644 --- a/tests/auto/gui/kernel/qguiapplication/BLACKLIST +++ b/tests/auto/gui/kernel/qguiapplication/BLACKLIST @@ -1,6 +1,2 @@ -[focusObject] -ubuntu-16.04 -opensuse-42.3 - [quitOnLastWindowClosedWithEventLoopLocker] b2qt diff --git a/tests/auto/gui/kernel/qguiapplication/CMakeLists.txt b/tests/auto/gui/kernel/qguiapplication/CMakeLists.txt index 12989dd375..6f1f845edd 100644 --- a/tests/auto/gui/kernel/qguiapplication/CMakeLists.txt +++ b/tests/auto/gui/kernel/qguiapplication/CMakeLists.txt @@ -1,16 +1,21 @@ -# Generated from qguiapplication.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qguiapplication Test: ##################################################################### -# special case begin +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qguiapplication LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + if (WIN32) set(target_version "1.2.3.4") else() set(target_version "1.2.3") endif() -# special case end # Resources: set(tst_qguiapplication_resource_files @@ -19,16 +24,15 @@ set(tst_qguiapplication_resource_files ) qt_internal_add_test(tst_qguiapplication - VERSION ${target_version} # special case + VERSION ${target_version} SOURCES - ../../../corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp ../../../corelib/kernel/qcoreapplication/tst_qcoreapplication.h # special case + ../../../corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp ../../../corelib/kernel/qcoreapplication/tst_qcoreapplication.h tst_qguiapplication.cpp DEFINES - QT_DISABLE_DEPRECATED_BEFORE=0x050E00 QT_QGUIAPPLICATIONTEST=1 INCLUDE_DIRECTORIES ../../../corelib/kernel/qcoreapplication - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::GuiPrivate TESTDATA ${tst_qguiapplication_resource_files} @@ -38,9 +42,7 @@ qt_internal_add_test(tst_qguiapplication if (ANDROID) set_property(TARGET tst_qguiapplication PROPERTY QT_ANDROID_VERSION_NAME ${target_version}) endif() -# special case begin if (APPLE) set_property(TARGET tst_qguiapplication PROPERTY MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist") set_property(TARGET tst_qguiapplication PROPERTY PROPERTY MACOSX_BUNDLE TRUE) endif() -# special case end diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index 500f13ea38..d1a50e3d69 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -47,6 +47,7 @@ private slots: void changeFocusWindow(); void keyboardModifiers(); void palette(); + void paletteNoCrash(); void font(); void modalWindow(); void quitOnLastWindowClosed(); @@ -60,6 +61,8 @@ private slots: void staticFunctions(); + void topLevelAt(); + void settableStyleHints_data(); void settableStyleHints(); // Needs to run last as it changes style hints. }; @@ -98,20 +101,20 @@ void tst_QGuiApplication::displayName() QGuiApplication::setApplicationName("The Core Application"); QCOMPARE(QGuiApplication::applicationName(), QString::fromLatin1("The Core Application")); QCOMPARE(QGuiApplication::applicationDisplayName(), QString::fromLatin1("The Core Application")); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QGuiApplication::setApplicationDisplayName("The GUI Application"); QCOMPARE(QGuiApplication::applicationDisplayName(), QString::fromLatin1("The GUI Application")); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); QGuiApplication::setApplicationName("The Core Application 2"); QCOMPARE(QGuiApplication::applicationName(), QString::fromLatin1("The Core Application 2")); QCOMPARE(QGuiApplication::applicationDisplayName(), QString::fromLatin1("The GUI Application")); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); QGuiApplication::setApplicationDisplayName("The GUI Application 2"); QCOMPARE(QGuiApplication::applicationDisplayName(), QString::fromLatin1("The GUI Application 2")); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); } void tst_QGuiApplication::desktopFileName() @@ -122,8 +125,8 @@ void tst_QGuiApplication::desktopFileName() QCOMPARE(QGuiApplication::desktopFileName(), QString()); - QGuiApplication::setDesktopFileName("io.qt.QGuiApplication.desktop"); - QCOMPARE(QGuiApplication::desktopFileName(), QString::fromLatin1("io.qt.QGuiApplication.desktop")); + QGuiApplication::setDesktopFileName("io.qt.QGuiApplication"); + QCOMPARE(QGuiApplication::desktopFileName(), QString::fromLatin1("io.qt.QGuiApplication")); QGuiApplication::setDesktopFileName(QString()); QCOMPARE(QGuiApplication::desktopFileName(), QString()); @@ -222,12 +225,12 @@ void tst_QGuiApplication::focusObject() window1.setFocusObject(&obj1); QCOMPARE(app.focusObject(), &obj1); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); spy.clear(); window1.setFocusObject(&obj2); QCOMPARE(app.focusObject(), &obj2); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); spy.clear(); window2.setFocusObject(&obj3); @@ -236,12 +239,12 @@ void tst_QGuiApplication::focusObject() QVERIFY(QTest::qWaitForWindowExposed(&window2)); QTRY_COMPARE(app.focusWindow(), &window2); QCOMPARE(app.focusObject(), &obj3); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); // focus change on unfocused window does not show spy.clear(); window1.setFocusObject(&obj1); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); QCOMPARE(app.focusObject(), &obj3); } @@ -253,13 +256,13 @@ void tst_QGuiApplication::allWindows() QWindow *window2 = new QWindow(window1); QVERIFY(app.allWindows().contains(window1)); QVERIFY(app.allWindows().contains(window2)); - QCOMPARE(app.allWindows().count(), 2); + QCOMPARE(app.allWindows().size(), 2); delete window1; window1 = nullptr; window2 = nullptr; QVERIFY(!app.allWindows().contains(window2)); QVERIFY(!app.allWindows().contains(window1)); - QCOMPARE(app.allWindows().count(), 0); + QCOMPARE(app.allWindows().size(), 0); } void tst_QGuiApplication::topLevelWindows() @@ -270,13 +273,13 @@ void tst_QGuiApplication::topLevelWindows() QWindow *window2 = new QWindow(window1); QVERIFY(app.topLevelWindows().contains(window1)); QVERIFY(!app.topLevelWindows().contains(window2)); - QCOMPARE(app.topLevelWindows().count(), 1); + QCOMPARE(app.topLevelWindows().size(), 1); delete window1; window1 = nullptr; window2 = nullptr; QVERIFY(!app.topLevelWindows().contains(window2)); QVERIFY(!app.topLevelWindows().contains(window1)); - QCOMPARE(app.topLevelWindows().count(), 0); + QCOMPARE(app.topLevelWindows().size(), 0); } class ShowCloseShowWindow : public QWindow @@ -457,16 +460,12 @@ void tst_QGuiApplication::keyboardModifiers() QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier); // wheel events - QPoint global = window->mapToGlobal(center); QPoint delta(0, 1); - QWindowSystemInterface::handleWheelEvent(window.data(), center, global, delta, delta, Qt::NoModifier); - QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::AllEvents); + QTest::wheelEvent(window.data(), center, delta, delta, Qt::NoModifier); QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier); - QWindowSystemInterface::handleWheelEvent(window.data(), center, global, delta, delta, Qt::AltModifier); - QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::AllEvents); + QTest::wheelEvent(window.data(), center, delta, delta, Qt::AltModifier); QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::AltModifier); - QWindowSystemInterface::handleWheelEvent(window.data(), center, global, delta, delta, Qt::ControlModifier); - QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::AllEvents); + QTest::wheelEvent(window.data(), center, delta, delta, Qt::ControlModifier); QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier); // touch events @@ -520,52 +519,78 @@ void tst_QGuiApplication::palette() // The default application palette is not resolved QVERIFY(!QGuiApplication::palette().resolveMask()); + // TODO: add event processing instead of the signal +#if QT_DEPRECATED_SINCE(6, 0) QSignalSpy signalSpy(&app, SIGNAL(paletteChanged(QPalette))); +#endif QPalette oldPalette = QGuiApplication::palette(); QPalette newPalette = QPalette(Qt::red); QGuiApplication::setPalette(newPalette); QVERIFY(palettesMatch(QGuiApplication::palette(), newPalette)); - QCOMPARE(signalSpy.count(), 1); +#if QT_DEPRECATED_SINCE(6, 0) + QCOMPARE(signalSpy.size(), 1); QVERIFY(palettesMatch(signalSpy.at(0).at(0).value<QPalette>(), newPalette)); +#endif QCOMPARE(QGuiApplication::palette(), QPalette()); QGuiApplication::setPalette(oldPalette); QVERIFY(palettesMatch(QGuiApplication::palette(), oldPalette)); - QCOMPARE(signalSpy.count(), 2); +#if QT_DEPRECATED_SINCE(6, 0) + QCOMPARE(signalSpy.size(), 2); QVERIFY(palettesMatch(signalSpy.at(1).at(0).value<QPalette>(), oldPalette)); +#endif QCOMPARE(QGuiApplication::palette(), QPalette()); QGuiApplication::setPalette(oldPalette); QVERIFY(palettesMatch(QGuiApplication::palette(), oldPalette)); - QCOMPARE(signalSpy.count(), 2); +#if QT_DEPRECATED_SINCE(6, 0) + QCOMPARE(signalSpy.size(), 2); +#endif QCOMPARE(QGuiApplication::palette(), QPalette()); } +void tst_QGuiApplication::paletteNoCrash() +{ + QGuiApplication::setDesktopSettingsAware(false); + int argc = 1; + char *argv[] = { const_cast<char*>("tst_qguiapplication") }; + // this would crash on windows (QTBUG-111527) + QGuiApplication a(argc, argv); +} + void tst_QGuiApplication::font() { int argc = 1; char *argv[] = { const_cast<char*>("tst_qguiapplication") }; QGuiApplication app(argc, argv); +#if QT_DEPRECATED_SINCE(6, 0) QSignalSpy signalSpy(&app, SIGNAL(fontChanged(QFont))); +#endif QFont oldFont = QGuiApplication::font(); QFont newFont = QFont("BogusFont", 33); QGuiApplication::setFont(newFont); QCOMPARE(QGuiApplication::font(), newFont); - QCOMPARE(signalSpy.count(), 1); +#if QT_DEPRECATED_SINCE(6, 0) + QCOMPARE(signalSpy.size(), 1); QCOMPARE(signalSpy.at(0).at(0), QVariant(newFont)); +#endif QGuiApplication::setFont(oldFont); QCOMPARE(QGuiApplication::font(), oldFont); - QCOMPARE(signalSpy.count(), 2); +#if QT_DEPRECATED_SINCE(6, 0) + QCOMPARE(signalSpy.size(), 2); QCOMPARE(signalSpy.at(1).at(0), QVariant(oldFont)); +#endif QGuiApplication::setFont(oldFont); QCOMPARE(QGuiApplication::font(), oldFont); - QCOMPARE(signalSpy.count(), 2); +#if QT_DEPRECATED_SINCE(6, 0) + QCOMPARE(signalSpy.size(), 2); +#endif } class BlockableWindow : public QWindow @@ -870,9 +895,9 @@ void tst_QGuiApplication::quitOnLastWindowClosed() app.exec(); - QCOMPARE(spyAboutToQuit.count(), 1); + QCOMPARE(spyAboutToQuit.size(), 1); // Should be around 10 if closing caused the quit - QVERIFY2(spyTimeout.count() < 15, QByteArray::number(spyTimeout.count()).constData()); + QVERIFY2(spyTimeout.size() < 15, QByteArray::number(spyTimeout.size()).constData()); } void tst_QGuiApplication::quitOnLastWindowClosedMulti() @@ -913,7 +938,7 @@ void tst_QGuiApplication::quitOnLastWindowClosedMulti() app.exec(); QVERIFY(!prematureQuit); - QCOMPARE(spyAboutToQuit.count(), 1); // fired only once + QCOMPARE(spyAboutToQuit.size(), 1); // fired only once } void tst_QGuiApplication::dontQuitOnLastWindowClosed() @@ -941,8 +966,8 @@ void tst_QGuiApplication::dontQuitOnLastWindowClosed() app.setQuitOnLastWindowClosed(true); // restore underlying static to default value - QCOMPARE(spyTimeout.count(), 1); // quit timer fired - QCOMPARE(spyLastWindowClosed.count(), 1); // lastWindowClosed emitted + QCOMPARE(spyTimeout.size(), 1); // quit timer fired + QCOMPARE(spyLastWindowClosed.size(), 1); // lastWindowClosed emitted } class QuitSpy : public QObject @@ -979,10 +1004,27 @@ void tst_QGuiApplication::quitOnLastWindowClosedWithEventLoopLocker() }); { - // Disabling QEventLoopLocker support should not affect - // quitting when last window is closed. + // Disabling QEventLoopLocker automatic quit should not affect + // quitting when last window is closed if there are no lockers. + app.setQuitLockEnabled(false); + + QuitSpy quitSpy; + QWindow window; + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QTimer::singleShot(0, &window, &QWindow::close); + QTimer::singleShot(200, &app, []{ QCoreApplication::exit(0); }); + app.exec(); + QCOMPARE(quitSpy.quits, 1); + } + + { + // Disabling QEventLoopLocker automatic quit should still block + // quitting when last window is closed if there is a locker alive. app.setQuitLockEnabled(false); + QScopedPointer<QEventLoopLocker> locker(new QEventLoopLocker); + QuitSpy quitSpy; QWindow window; window.show(); @@ -990,12 +1032,27 @@ void tst_QGuiApplication::quitOnLastWindowClosedWithEventLoopLocker() QTimer::singleShot(0, &window, &QWindow::close); QTimer::singleShot(200, &app, []{ QCoreApplication::exit(0); }); app.exec(); + QCOMPARE(quitSpy.quits, 0); + } + + { + // Disabling quitOnLastWindowClosed automatic quit should not affect + // quitting when last QEventLoopLocker goes out of scope if + // there are no windows. + app.setQuitLockEnabled(true); + app.setQuitOnLastWindowClosed(false); + + QuitSpy quitSpy; + QScopedPointer<QEventLoopLocker> locker(new QEventLoopLocker); + QTimer::singleShot(0, [&]{ locker.reset(nullptr); }); + QTimer::singleShot(200, &app, []{ QCoreApplication::exit(0); }); + app.exec(); QCOMPARE(quitSpy.quits, 1); } { - // Disabling quitOnLastWindowClosed support should not affect - // quitting when last QEventLoopLocker goes out of scope. + // Disabling quitOnLastWindowClosed automatic quit should still block + // quitting via QEventLoopLocker if there's a window alive. app.setQuitLockEnabled(true); app.setQuitOnLastWindowClosed(false); @@ -1007,7 +1064,7 @@ void tst_QGuiApplication::quitOnLastWindowClosedWithEventLoopLocker() QTimer::singleShot(0, [&]{ locker.reset(nullptr); }); QTimer::singleShot(200, &app, []{ QCoreApplication::exit(0); }); app.exec(); - QCOMPARE(quitSpy.quits, 1); + QCOMPARE(quitSpy.quits, 0); } { @@ -1121,8 +1178,6 @@ void tst_QGuiApplication::genericPluginsAndWindowSystemEvents() QVERIFY(QGuiApplication::primaryScreen()); QCOMPARE(QGuiApplication::primaryScreen()->orientation(), testOrientationToSend); - if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) - QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100891.", Abort); QCOMPARE(testReceiver.customEvents, 0); QCoreApplication::sendPostedEvents(&testReceiver); QCOMPARE(testReceiver.customEvents, 1); @@ -1146,12 +1201,12 @@ void tst_QGuiApplication::layoutDirection() QGuiApplication::setLayoutDirection(oldDirection); QCOMPARE(QGuiApplication::layoutDirection(), oldDirection); - QCOMPARE(signalSpy.count(), 1); + QCOMPARE(signalSpy.size(), 1); QCOMPARE(signalSpy.at(0).at(0).toInt(), static_cast<int>(oldDirection)); QGuiApplication::setLayoutDirection(oldDirection); QCOMPARE(QGuiApplication::layoutDirection(), oldDirection); - QCOMPARE(signalSpy.count(), 1); + QCOMPARE(signalSpy.size(), 1); // with QGuiApplication instantiated, install a translator that gives us control class LayoutDirectionTranslator : public QTranslator @@ -1182,31 +1237,31 @@ void tst_QGuiApplication::layoutDirection() LayoutDirectionTranslator translator(oldDirection); QGuiApplication::installTranslator(&translator); QCOMPARE(QGuiApplication::layoutDirection(), translator.direction); - QCOMPARE(signalSpy.count(), layoutDirectionChangedCount); + QCOMPARE(signalSpy.size(), layoutDirectionChangedCount); } - QCOMPARE(signalSpy.count(), layoutDirectionChangedCount); // ltrTranslator removed, no change + QCOMPARE(signalSpy.size(), layoutDirectionChangedCount); // ltrTranslator removed, no change // install a new translator that changes the direction { LayoutDirectionTranslator translator(newDirection); QGuiApplication::installTranslator(&translator); QCOMPARE(QGuiApplication::layoutDirection(), translator.direction); - QCOMPARE(signalSpy.count(), ++layoutDirectionChangedCount); + QCOMPARE(signalSpy.size(), ++layoutDirectionChangedCount); } // rtlTranslator removed - QCOMPARE(signalSpy.count(), ++layoutDirectionChangedCount); + QCOMPARE(signalSpy.size(), ++layoutDirectionChangedCount); // override translation QGuiApplication::setLayoutDirection(newDirection); - QCOMPARE(signalSpy.count(), ++layoutDirectionChangedCount); + QCOMPARE(signalSpy.size(), ++layoutDirectionChangedCount); { // this translator will be ignored LayoutDirectionTranslator translator(oldDirection); QGuiApplication::installTranslator(&translator); QCOMPARE(QGuiApplication::layoutDirection(), newDirection); - QCOMPARE(signalSpy.count(), layoutDirectionChangedCount); + QCOMPARE(signalSpy.size(), layoutDirectionChangedCount); } - QCOMPARE(signalSpy.count(), layoutDirectionChangedCount); + QCOMPARE(signalSpy.size(), layoutDirectionChangedCount); } @@ -1300,6 +1355,40 @@ void tst_QGuiApplication::staticFunctions() QPixmap::defaultDepth(); } +void tst_QGuiApplication::topLevelAt() +{ + int argc = 1; + char *argv[] = { const_cast<char*>("tst_qguiapplication") }; + QGuiApplication app(argc, argv); + + if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) + QSKIP("QGuiApplication::topLevelAt() is not Wayland compliant, see also QTBUG-121015"); + + QWindow bottom; + bottom.setObjectName("Bottom"); + bottom.setFlag(Qt::FramelessWindowHint); + bottom.setGeometry(200, 200, 200, 200); + bottom.showNormal(); + QVERIFY(QTest::qWaitForWindowExposed(&bottom)); + QTRY_COMPARE(app.topLevelAt(QPoint(300, 300)), &bottom); + + QWindow top; + top.setObjectName("Top"); + top.setFlag(Qt::FramelessWindowHint); + top.setGeometry(200, 200, 200, 200); + top.showNormal(); + QVERIFY(QTest::qWaitForWindowExposed(&top)); + top.raise(); + QTRY_COMPARE(app.topLevelAt(QPoint(300, 300)), &top); + + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowMasks)) + QSKIP("QWindow::setMask() is not supported."); + + top.setMask(QRect(0, 0, 50, 50)); + QTRY_COMPARE(app.topLevelAt(QPoint(300, 300)), &bottom); + QTRY_COMPARE(app.topLevelAt(QPoint(225, 225)), &top); +} + void tst_QGuiApplication::settableStyleHints_data() { QTest::addColumn<bool>("appInstance"); diff --git a/tests/auto/gui/kernel/qguichronotimer/CMakeLists.txt b/tests/auto/gui/kernel/qguichronotimer/CMakeLists.txt new file mode 100644 index 0000000000..37848d8cec --- /dev/null +++ b/tests/auto/gui/kernel/qguichronotimer/CMakeLists.txt @@ -0,0 +1,38 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## tst_qguichronotimer Test: +##################################################################### + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qguichronotimer LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +function(addGuiChronoTimerTest test) + qt_internal_add_test(${test} + SOURCES + ../../../corelib/kernel/qchronotimer/tst_qchronotimer.cpp + LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::TestPrivate + ) +endfunction() + +addGuiChronoTimerTest(tst_qguichronotimer) +qt_internal_extend_target(tst_qguichronotimer + DEFINES + tst_Qtimer=tst_QGuiChronoTimer +) + +if(QT_FEATURE_glib AND UNIX) + addGuiChronoTimerTest(tst_qguichronotimer_no_glib) + qt_internal_extend_target(tst_qguichronotimer_no_glib + DEFINES + DISABLE_GLIB + tst_QTimer=tst_QGuiChronoTimer_no_glib # Class name in the unittest + ) +endif() diff --git a/tests/auto/gui/kernel/qguieventdispatcher/CMakeLists.txt b/tests/auto/gui/kernel/qguieventdispatcher/CMakeLists.txt index b1c0508198..62299f77df 100644 --- a/tests/auto/gui/kernel/qguieventdispatcher/CMakeLists.txt +++ b/tests/auto/gui/kernel/qguieventdispatcher/CMakeLists.txt @@ -1,12 +1,40 @@ -# Generated from qguieventdispatcher.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qguieventdispatcher Test: ##################################################################### -qt_internal_add_test(tst_qguieventdispatcher - SOURCES - ../../../corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp - PUBLIC_LIBRARIES - Qt::Gui +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qguieventdispatcher LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +set(test_names "tst_qguieventdispatcher") +if(QT_FEATURE_glib AND UNIX) + list(APPEND test_names "tst_qguieventdispatcher_no_glib") +endif() + +foreach(test ${test_names}) + qt_internal_add_test(${test} + NO_BATCH + SOURCES + ../../../corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp + LIBRARIES + Qt::Gui + ) +endforeach() + +qt_internal_extend_target(tst_qguieventdispatcher + DEFINES + tst_QEventDispatcher=tst_qguieventdispatcher ) + +if (TARGET tst_qeventdispatcher_no_glib) + qt_internal_extend_target(tst_qguieventdispatcher_no_glib + DEFINES + DISABLE_GLIB + tst_QEventDispatcher=tst_qguieventdispatcher_no_glib + ) +endif() diff --git a/tests/auto/gui/kernel/qguieventloop/CMakeLists.txt b/tests/auto/gui/kernel/qguieventloop/CMakeLists.txt index ec9441a1dc..89c518be10 100644 --- a/tests/auto/gui/kernel/qguieventloop/CMakeLists.txt +++ b/tests/auto/gui/kernel/qguieventloop/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qguieventloop.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qguieventloop Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qguieventloop LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qguieventloop SOURCES ../../../corelib/kernel/qeventloop/tst_qeventloop.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::Network @@ -17,7 +24,7 @@ qt_internal_add_test(tst_qguieventloop ##################################################################### qt_internal_extend_target(tst_qguieventloop CONDITION WIN32 - PUBLIC_LIBRARIES + LIBRARIES user32 ) diff --git a/tests/auto/gui/kernel/qguimetatype/CMakeLists.txt b/tests/auto/gui/kernel/qguimetatype/CMakeLists.txt index 0887f05fc6..7c93e4b8a2 100644 --- a/tests/auto/gui/kernel/qguimetatype/CMakeLists.txt +++ b/tests/auto/gui/kernel/qguimetatype/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qguimetatype.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qguimetatype Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qguimetatype LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qguimetatype SOURCES tst_qguimetatype.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp b/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp index ff464e29c9..54e95a2b38 100644 --- a/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp +++ b/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtCore> @@ -20,6 +20,8 @@ private slots: void sizeOf(); void flags_data(); void flags(); + void flags2_data(); + void flags2(); void construct_data(); void construct(); void constructCopy_data(); @@ -293,14 +295,27 @@ struct TypeAlignment enum { Value = alignof(T) }; }; +template <typename T> void addFlagsRow(const char *name, int id = qMetaTypeId<T>()) +{ + QTest::newRow(name) + << id + << bool(QTypeInfo<T>::isRelocatable) + << bool(!std::is_trivially_default_constructible_v<T>) + << bool(!std::is_trivially_copy_constructible_v<T>) + << bool(!std::is_trivially_destructible_v<T>); +} + +// tst_QGuiMetaType::flags is nearly identical to tst_QMetaType::flags void tst_QGuiMetaType::flags_data() { QTest::addColumn<int>("type"); QTest::addColumn<bool>("isRelocatable"); - QTest::addColumn<bool>("isComplex"); + QTest::addColumn<bool>("needsConstruction"); + QTest::addColumn<bool>("needsCopyConstruction"); + QTest::addColumn<bool>("needsDestruction"); #define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \ - QTest::newRow(#RealType) << MetaTypeId << bool(QTypeInfo<RealType>::isRelocatable) << bool(QTypeInfo<RealType>::isComplex); + addFlagsRow<RealType>(#RealType, MetaTypeId); QT_FOR_EACH_STATIC_GUI_CLASS(ADD_METATYPE_TEST_ROW) #undef ADD_METATYPE_TEST_ROW } @@ -309,13 +324,62 @@ void tst_QGuiMetaType::flags() { QFETCH(int, type); QFETCH(bool, isRelocatable); - QFETCH(bool, isComplex); + QFETCH(bool, needsConstruction); + QFETCH(bool, needsCopyConstruction); + QFETCH(bool, needsDestruction); - QCOMPARE(bool(QMetaType(type).flags() & QMetaType::NeedsConstruction), isComplex); - QCOMPARE(bool(QMetaType(type).flags() & QMetaType::NeedsDestruction), isComplex); + QCOMPARE(bool(QMetaType(type).flags() & QMetaType::NeedsConstruction), needsConstruction); + QCOMPARE(bool(QMetaType(type).flags() & QMetaType::NeedsCopyConstruction), needsCopyConstruction); + QCOMPARE(bool(QMetaType(type).flags() & QMetaType::NeedsDestruction), needsDestruction); QCOMPARE(bool(QMetaType(type).flags() & QMetaType::RelocatableType), isRelocatable); } +template <typename T> static void addFlags2Row(QMetaType metaType = QMetaType::fromType<T>()) +{ + QTest::newRow(metaType.name() ? metaType.name() : "UnknownType") + << metaType + << std::is_default_constructible_v<T> + << std::is_copy_constructible_v<T> + << std::is_move_constructible_v<T> + << std::is_destructible_v<T> + << (QTypeTraits::has_operator_equal<T>::value || QTypeTraits::has_operator_less_than<T>::value) + << QTypeTraits::has_operator_less_than<T>::value; +}; + +// tst_QGuiMetaType::flags2 is nearly identical to tst_QMetaType::flags2 +void tst_QGuiMetaType::flags2_data() +{ + QTest::addColumn<QMetaType>("type"); + QTest::addColumn<bool>("isDefaultConstructible"); + QTest::addColumn<bool>("isCopyConstructible"); + QTest::addColumn<bool>("isMoveConstructible"); + QTest::addColumn<bool>("isDestructible"); + QTest::addColumn<bool>("isEqualityComparable"); + QTest::addColumn<bool>("isOrdered"); + +#define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \ + addFlags2Row<RealType>(); +QT_FOR_EACH_STATIC_GUI_CLASS(ADD_METATYPE_TEST_ROW) +#undef ADD_METATYPE_TEST_ROW +} + +void tst_QGuiMetaType::flags2() +{ + QFETCH(QMetaType, type); + QFETCH(bool, isDefaultConstructible); + QFETCH(bool, isCopyConstructible); + QFETCH(bool, isMoveConstructible); + QFETCH(bool, isDestructible); + QFETCH(bool, isEqualityComparable); + QFETCH(bool, isOrdered); + + QCOMPARE(type.isDefaultConstructible(), isDefaultConstructible); + QCOMPARE(type.isCopyConstructible(), isCopyConstructible); + QCOMPARE(type.isMoveConstructible(), isMoveConstructible); + QCOMPARE(type.isDestructible(), isDestructible); + QCOMPARE(type.isEqualityComparable(), isEqualityComparable); + QCOMPARE(type.isOrdered(), isOrdered); +} void tst_QGuiMetaType::construct_data() { diff --git a/tests/auto/gui/kernel/qguitimer/CMakeLists.txt b/tests/auto/gui/kernel/qguitimer/CMakeLists.txt index 5375155a82..bc292e133b 100644 --- a/tests/auto/gui/kernel/qguitimer/CMakeLists.txt +++ b/tests/auto/gui/kernel/qguitimer/CMakeLists.txt @@ -1,13 +1,38 @@ -# Generated from qguitimer.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qguitimer Test: ##################################################################### -qt_internal_add_test(tst_qguitimer - SOURCES - ../../../corelib/kernel/qtimer/tst_qtimer.cpp - PUBLIC_LIBRARIES - Qt::CorePrivate - Qt::Gui +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qguitimer LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +function(addGuiTimerTest test) + qt_internal_add_test(${test} + SOURCES + ../../../corelib/kernel/qtimer/tst_qtimer.cpp + LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::TestPrivate + ) +endfunction() + +addGuiTimerTest(tst_qguitimer) +qt_internal_extend_target(tst_qguitimer + DEFINES + tst_Qtimer=tst_QGuiTimer ) + +if(QT_FEATURE_glib AND UNIX) + addGuiTimerTest(tst_qguitimer_no_glib) + qt_internal_extend_target(tst_qguitimer_no_glib + DEFINES + DISABLE_GLIB + tst_QTimer=tst_QGuiTimer_no_glib # Class name in the unittest + ) +endif() diff --git a/tests/auto/gui/kernel/qguivariant/CMakeLists.txt b/tests/auto/gui/kernel/qguivariant/CMakeLists.txt index 3a0adab6e3..eda22152ec 100644 --- a/tests/auto/gui/kernel/qguivariant/CMakeLists.txt +++ b/tests/auto/gui/kernel/qguivariant/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from qguivariant.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause add_subdirectory(test) add_subdirectory(no_application) diff --git a/tests/auto/gui/kernel/qguivariant/no_application/CMakeLists.txt b/tests/auto/gui/kernel/qguivariant/no_application/CMakeLists.txt index 2e6f548f11..4470411a3b 100644 --- a/tests/auto/gui/kernel/qguivariant/no_application/CMakeLists.txt +++ b/tests/auto/gui/kernel/qguivariant/no_application/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from no_application.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## no_application Test: ##################################################################### -qt_internal_add_test(no_application +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_gui_variant_no_application LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_gui_variant_no_application SOURCES main.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/kernel/qguivariant/no_application/main.cpp b/tests/auto/gui/kernel/qguivariant/no_application/main.cpp index bf6e2080b2..2b6ec7b870 100644 --- a/tests/auto/gui/kernel/qguivariant/no_application/main.cpp +++ b/tests/auto/gui/kernel/qguivariant/no_application/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/gui/kernel/qguivariant/test/CMakeLists.txt b/tests/auto/gui/kernel/qguivariant/test/CMakeLists.txt index 49e985fa82..36b732e4ae 100644 --- a/tests/auto/gui/kernel/qguivariant/test/CMakeLists.txt +++ b/tests/auto/gui/kernel/qguivariant/test/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from test.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qguivariant Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qguivariant LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Resources: file(GLOB_RECURSE qguivariant_resource_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" @@ -15,7 +22,7 @@ qt_internal_add_test(tst_qguivariant tst_qguivariant.cpp INCLUDE_DIRECTORIES ../../../../other/qvariant_common - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui TESTDATA ${qguivariant_resource_files} BUILTIN_TESTDATA diff --git a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp index 27ba5e9386..cb22024f76 100644 --- a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp +++ b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/gui/kernel/qhighdpi/CMakeLists.txt b/tests/auto/gui/kernel/qhighdpi/CMakeLists.txt index bdd9a5e17f..aa61bfbb0b 100644 --- a/tests/auto/gui/kernel/qhighdpi/CMakeLists.txt +++ b/tests/auto/gui/kernel/qhighdpi/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qhighdpi.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qhighdpi Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qhighdpi LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qhighdpi SOURCES tst_qhighdpi.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp index 5f0d226124..6fe4faec03 100644 --- a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp +++ b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2020 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <private/qhighdpiscaling_p.h> #include <qpa/qplatformscreen.h> @@ -10,6 +10,7 @@ #include <QJsonObject> #include <QJsonDocument> #include <QStringView> +#include <QSignalSpy> Q_LOGGING_CATEGORY(lcTests, "qt.gui.tests") @@ -35,10 +36,13 @@ private slots: void screenDpiAndDpr_data(); void screenDpiAndDpr(); void screenDpiChange(); + void screenDpiChangeWithWindow(); void environment_QT_SCALE_FACTOR(); void environment_QT_SCREEN_SCALE_FACTORS_data(); void environment_QT_SCREEN_SCALE_FACTORS(); void environment_QT_USE_PHYSICAL_DPI(); + void environment_QT_SCALE_FACTOR_ROUNDING_POLICY(); + void application_setScaleFactorRoundingPolicy(); void screenAt_data(); void screenAt(); void screenGeometry_data(); @@ -53,6 +57,8 @@ private slots: void mouseVelocity_data(); void setCursor(); void setCursor_data(); + void setGlobalFactorEmits(); + void setScreenFactorEmits(); }; /// Offscreen platform plugin test setup @@ -63,7 +69,7 @@ const int standardScreenCount = 3; QJsonArray tst_QHighDpi::createStandardScreens(const QList<qreal> &dpiValues) { - Q_ASSERT(dpiValues.count() == standardScreenCount); + Q_ASSERT(dpiValues.size() == standardScreenCount); // Create row of three screens: screen#0 screen#1 screen#2 return QJsonArray { @@ -187,6 +193,7 @@ void tst_QHighDpi::cleanup() qunsetenv("QT_SCALE_FACTOR"); qunsetenv("QT_SCREEN_SCALE_FACTORS"); qunsetenv("QT_USE_PHYSICAL_DPI"); + qunsetenv("QT_SCALE_FACTOR_ROUNDING_POLICY"); } void tst_QHighDpi::qhighdpiscaling_data() @@ -232,6 +239,9 @@ void tst_QHighDpi::screenDpiAndDpr() QWindow window(screen); QCOMPARE(window.devicePixelRatio(), screen->devicePixelRatio()); + window.setGeometry(QRect(screen->geometry().center(), QSize(10, 10))); + window.create(); + QCOMPARE(window.devicePixelRatio(), screen->devicePixelRatio()); } } @@ -258,16 +268,52 @@ void tst_QHighDpi::screenDpiChange() for (QScreen *screen : app->screens()) { QCOMPARE(screen->devicePixelRatio(), newDpi / standardBaseDpi); QCOMPARE(screen->logicalDotsPerInch(), newDpi / screen->devicePixelRatio()); + QWindow window(screen); QCOMPARE(window.devicePixelRatio(), screen->devicePixelRatio()); + window.create(); + QCOMPARE(window.devicePixelRatio(), screen->devicePixelRatio()); } QCOMPARE(app->devicePixelRatio(), newDpi / standardBaseDpi); } +void tst_QHighDpi::screenDpiChangeWithWindow() +{ + QList<qreal> dpiValues = { 96, 192, 288 }; + std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); + + // Create windows for screens + QList<QScreen *> screens = app->screens(); + QList<QWindow *> windows; + for (int i = 0; i < screens.count(); ++i) { + QScreen *screen = screens[i]; + QWindow *window = new QWindow(); + windows.append(window); + window->setGeometry(QRect(screen->geometry().center(), QSize(10, 10))); + window->create(); + QCOMPARE(window->devicePixelRatio(), dpiValues[i] / standardBaseDpi); + } + + // Change screen DPI + QList<qreal> newDpiValues = { 288, 192, 96 }; + QJsonValue config = offscreenConfiguration(); + QCborMap map = QCborMap::fromJsonObject(config.toObject()); + for (int i = 0; i < screens.count(); ++i) { + map[QLatin1String("screens")][i][QLatin1String("logicalDpi")] = newDpiValues[i]; + } + setOffscreenConfiguration(map.toJsonObject()); + + // Verify that window DPR changes on Screen DPI change. + for (int i = 0; i < screens.count(); ++i) { + QWindow *window = windows[i]; + QCOMPARE(window->devicePixelRatio(), newDpiValues[i] / standardBaseDpi); + } +} + void tst_QHighDpi::environment_QT_SCALE_FACTOR() { qreal factor = 3.1415; - qputenv("QT_SCALE_FACTOR", QByteArray::number(factor)); + qputenv("QT_SCALE_FACTOR", std::to_string(factor)); QList<qreal> dpiValues { 96, 144, 192 }; std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); @@ -310,9 +356,10 @@ void tst_QHighDpi::environment_QT_SCREEN_SCALE_FACTORS() QFETCH(QByteArray, environment); QFETCH(QList<qreal>, expectedDprValues); + qputenv("QT_SCREEN_SCALE_FACTORS", environment); + // Verify that setting QT_SCREEN_SCALE_FACTORS overrides the from-platform-screen-DPI DPR. { - qputenv("QT_SCREEN_SCALE_FACTORS", environment); std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(platformScreenDpi)); int i = 0; for (QScreen *screen : app->screens()) { @@ -324,6 +371,18 @@ void tst_QHighDpi::environment_QT_SCREEN_SCALE_FACTORS() QCOMPARE(window.devicePixelRatio(), expextedDpr); } } + + // Verify that setHighDpiScaleFactorRoundingPolicy applies to QT_SCREEN_SCALE_FACTORS as well + QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round); + { + std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(platformScreenDpi)); + int i = 0; + for (QScreen *screen : app->screens()) { + qreal expectedRounderDpr = qRound(expectedDprValues[i++]); + qreal windowDpr = QWindow(screen).devicePixelRatio(); + QCOMPARE(windowDpr, expectedRounderDpr); + } + } } void tst_QHighDpi::environment_QT_USE_PHYSICAL_DPI() @@ -351,6 +410,59 @@ void tst_QHighDpi::environment_QT_USE_PHYSICAL_DPI() } } +void tst_QHighDpi::environment_QT_SCALE_FACTOR_ROUNDING_POLICY() +{ + QList<qreal> dpiValues { 96, 144, 192 }; + + qputenv("QT_SCALE_FACTOR_ROUNDING_POLICY", "PassThrough"); + { + std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); + for (int i = 0; i < dpiValues.size(); ++i) + QCOMPARE(app->screens()[i]->devicePixelRatio(), dpiValues[i] / qreal(96)); + } + + qputenv("QT_SCALE_FACTOR_ROUNDING_POLICY", "Round"); + { + std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); + for (int i = 0; i < dpiValues.size(); ++i) + QCOMPARE(app->screens()[i]->devicePixelRatio(), qRound(dpiValues[i] / qreal(96))); + } + + qunsetenv("QT_SCALE_FACTOR_ROUNDING_POLICY"); + { + std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); + for (int i = 0; i < dpiValues.size(); ++i) + QCOMPARE(app->screens()[i]->devicePixelRatio(), dpiValues[i] / qreal(96)); + } +} + +void tst_QHighDpi::application_setScaleFactorRoundingPolicy() +{ + QList<qreal> dpiValues { 96, 144, 192 }; + QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round); + { + std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); + for (int i = 0; i < dpiValues.size(); ++i) + QCOMPARE(app->screens()[i]->devicePixelRatio(), qRound(dpiValues[i] / qreal(96))); + } + + QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); + { + std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); + for (int i = 0; i < dpiValues.size(); ++i) + QCOMPARE(app->screens()[i]->devicePixelRatio(), dpiValues[i] / qreal(96)); + } + + // Verify that environment overrides app setting + QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round); + qputenv("QT_SCALE_FACTOR_ROUNDING_POLICY", "PassThrough"); + { + std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); + for (int i = 0; i < dpiValues.size(); ++i) + QCOMPARE(app->screens()[i]->devicePixelRatio(), dpiValues[i] / qreal(96)); + } +} + void tst_QHighDpi::minimumDpr() { QList<qreal> dpiValues { 40, 60, 95 }; @@ -394,7 +506,7 @@ void tst_QHighDpi::screenAt() QFETCH(QList<qreal>, dpiValues); std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); - QCOMPARE(app->screens().count(), standardScreenCount); // standard setup + QCOMPARE(app->screens().size(), standardScreenCount); // standard setup // Verify that screenAt() returns the correct or no screen for various points, // for all screens. @@ -403,7 +515,7 @@ void tst_QHighDpi::screenAt() qreal dpi = dpiValues[i++]; // veryfy virtualSiblings and that AA_EnableHighDpiScaling is active - QCOMPARE(screen->virtualSiblings().count(), standardScreenCount); + QCOMPARE(screen->virtualSiblings().size(), standardScreenCount); QCOMPARE(screen->geometry().size(), QSize(standardScreenWidth, standardScreenHeight) * (96.0 / dpi)); // test points on screen @@ -742,5 +854,34 @@ void tst_QHighDpi::setCursor() } } +void tst_QHighDpi::setGlobalFactorEmits() +{ + QList<qreal> dpiValues { 96, 96, 96 }; + std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); + + std::vector<std::unique_ptr<QSignalSpy>> spies; + for (QScreen *screen : app->screens()) + spies.push_back(std::make_unique<QSignalSpy>(screen, &QScreen::geometryChanged)); + + QHighDpiScaling::setGlobalFactor(2); + + for (const auto &spy : spies) + QCOMPARE(spy->count(), 1); + + QHighDpiScaling::setGlobalFactor(1); +} + +void tst_QHighDpi::setScreenFactorEmits() +{ + QList<qreal> dpiValues { 96, 96, 96 }; + std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); + + for (QScreen *screen : app->screens()) { + QSignalSpy spy(screen, &QScreen::geometryChanged); + QHighDpiScaling::setScreenFactor(screen, 2); + QCOMPARE(spy.count(), 1); + } +} + #include "tst_qhighdpi.moc" QTEST_APPLESS_MAIN(tst_QHighDpi); diff --git a/tests/auto/gui/kernel/qinputdevice/CMakeLists.txt b/tests/auto/gui/kernel/qinputdevice/CMakeLists.txt index aea72357dd..afbfd9bb37 100644 --- a/tests/auto/gui/kernel/qinputdevice/CMakeLists.txt +++ b/tests/auto/gui/kernel/qinputdevice/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qinputdevice.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qinputdevice Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qinputdevice LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qinputdevice SOURCES tst_qinputdevice.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate ) diff --git a/tests/auto/gui/kernel/qinputdevice/tst_qinputdevice.cpp b/tests/auto/gui/kernel/qinputdevice/tst_qinputdevice.cpp index 67c65f1160..8587aebf2a 100644 --- a/tests/auto/gui/kernel/qinputdevice/tst_qinputdevice.cpp +++ b/tests/auto/gui/kernel/qinputdevice/tst_qinputdevice.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2020 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <qpa/qwindowsysteminterface.h> @@ -78,7 +78,7 @@ void tst_QInputDevice::multiSeatDevices() QWindowSystemInterface::registerInputDevice(new QPointingDevice("seat 2 mouse", 2010, QInputDevice::DeviceType::Mouse, QPointingDevice::PointerType::Generic, QInputDevice::Capability::Position | QInputDevice::Capability::Hover, 1, 2, "seat 2", QPointingDeviceUniqueId(), this)); - QVERIFY(QInputDevice::devices().count() >= 4); + QVERIFY(QInputDevice::devices().size() >= 4); QVERIFY(QInputDevicePrivate::fromId(1010)); QVERIFY(QInputDevicePrivate::fromId(1010)->hasCapability(QInputDevice::Capability::Scroll)); QVERIFY(QInputDevicePrivate::fromId(2010)); diff --git a/tests/auto/gui/kernel/qinputmethod/CMakeLists.txt b/tests/auto/gui/kernel/qinputmethod/CMakeLists.txt index bbe8652e99..e3ce0774bc 100644 --- a/tests/auto/gui/kernel/qinputmethod/CMakeLists.txt +++ b/tests/auto/gui/kernel/qinputmethod/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qinputmethod.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qinputmethod Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qinputmethod LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qinputmethod SOURCES tst_qinputmethod.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/kernel/qinputmethod/tst_qinputmethod.cpp b/tests/auto/gui/kernel/qinputmethod/tst_qinputmethod.cpp index 86669fde62..619de7bed3 100644 --- a/tests/auto/gui/kernel/qinputmethod/tst_qinputmethod.cpp +++ b/tests/auto/gui/kernel/qinputmethod/tst_qinputmethod.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QSignalSpy> @@ -125,7 +125,7 @@ void tst_qinputmethod::animating() QSignalSpy spy(qApp->inputMethod(), SIGNAL(animatingChanged())); m_platformInputContext.emitAnimatingChanged(); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } void tst_qinputmethod::keyboarRectangle() @@ -137,7 +137,7 @@ void tst_qinputmethod::keyboarRectangle() QSignalSpy spy(qApp->inputMethod(), SIGNAL(keyboardRectangleChanged())); m_platformInputContext.emitKeyboardRectChanged(); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } void tst_qinputmethod::inputItemTransform() @@ -152,7 +152,7 @@ void tst_qinputmethod::inputItemTransform() qApp->inputMethod()->setInputItemTransform(transform); QCOMPARE(qApp->inputMethod()->inputItemTransform(), transform); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); // reset qApp->inputMethod()->setInputItemTransform(QTransform()); @@ -249,13 +249,13 @@ void tst_qinputmethod::query() void tst_qinputmethod::inputDirection() { - QCOMPARE(m_platformInputContext.m_inputDirectionCallCount, 0); + auto originalCount = m_platformInputContext.m_inputDirectionCallCount; qApp->inputMethod()->inputDirection(); - QCOMPARE(m_platformInputContext.m_inputDirectionCallCount, 1); + QCOMPARE(m_platformInputContext.m_inputDirectionCallCount, originalCount + 1); - QCOMPARE(m_platformInputContext.m_localeCallCount, 0); + originalCount = m_platformInputContext.m_localeCallCount; qApp->inputMethod()->locale(); - QCOMPARE(m_platformInputContext.m_localeCallCount, 1); + QCOMPARE(m_platformInputContext.m_localeCallCount, originalCount + 1); } void tst_qinputmethod::inputMethodAccepted() diff --git a/tests/auto/gui/kernel/qkeyevent/CMakeLists.txt b/tests/auto/gui/kernel/qkeyevent/CMakeLists.txt index bd9f602e56..c3c9892d14 100644 --- a/tests/auto/gui/kernel/qkeyevent/CMakeLists.txt +++ b/tests/auto/gui/kernel/qkeyevent/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qkeyevent.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qkeyevent Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qkeyevent LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qkeyevent SOURCES tst_qkeyevent.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp b/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp index 4f2379fbb4..7d8e0aa5dc 100644 --- a/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp +++ b/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp @@ -1,5 +1,7 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses #include <QTest> diff --git a/tests/auto/gui/kernel/qkeysequence/CMakeLists.txt b/tests/auto/gui/kernel/qkeysequence/CMakeLists.txt index ea71ce3870..1676302d1b 100644 --- a/tests/auto/gui/kernel/qkeysequence/CMakeLists.txt +++ b/tests/auto/gui/kernel/qkeysequence/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from qkeysequence.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qkeysequence Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qkeysequence LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Resources: set(qkeysequence_resource_files "keys_de.qm" @@ -13,7 +20,7 @@ set(qkeysequence_resource_files qt_internal_add_test(tst_qkeysequence SOURCES tst_qkeysequence.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp b/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp index f2efefeeb4..67fef3cf44 100644 --- a/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp +++ b/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -473,10 +473,15 @@ void tst_QKeySequence::toStringFromKeycode_data() QTest::newRow("A") << QKeySequence(Qt::Key_A) << "A"; QTest::newRow("-1") << QKeySequence(-1) << ""; QTest::newRow("Unknown") << QKeySequence(Qt::Key_unknown) << ""; + QTest::newRow("Ctrl+Unknown") << QKeySequence(Qt::ControlModifier | Qt::Key_unknown) << ""; QTest::newRow("Ctrl+Num+Ins") << QKeySequence(Qt::ControlModifier | Qt::KeypadModifier | Qt::Key_Insert) << "Ctrl+Num+Ins"; QTest::newRow("Ctrl+Num+Del") << QKeySequence(Qt::ControlModifier | Qt::KeypadModifier | Qt::Key_Delete) << "Ctrl+Num+Del"; QTest::newRow("Ctrl+Alt+Num+Del") << QKeySequence(Qt::ControlModifier | Qt::AltModifier | Qt::KeypadModifier | Qt::Key_Delete) << "Ctrl+Alt+Num+Del"; QTest::newRow("Ctrl+Ins") << QKeySequence(Qt::ControlModifier | Qt::Key_Insert) << "Ctrl+Ins"; + QTest::newRow("Ctrl") << QKeySequence(Qt::Key_Control) << "Control"; + QTest::newRow("Alt") << QKeySequence(Qt::Key_Alt) << "Alt"; + QTest::newRow("Shift") << QKeySequence(Qt::Key_Shift) << "Shift"; + QTest::newRow("Meta") << QKeySequence(Qt::Key_Meta) << "Meta"; } void tst_QKeySequence::toStringFromKeycode() @@ -554,10 +559,6 @@ void tst_QKeySequence::parseString_data() //QTest::newRow("Ctrl") << "Ctrl" << QKeySequence(Qt::CTRL); //QTest::newRow("Shift") << "Shift" << QKeySequence(Qt::SHIFT); - // Only Keys - QTest::newRow("a") << "a" << QKeySequence(Qt::Key_A); - QTest::newRow("A") << "A" << QKeySequence(Qt::Key_A); - // Incomplete QTest::newRow("Meta+Shift+") << "Meta+Shift+" << QKeySequence(Qt::Key_unknown); } diff --git a/tests/auto/gui/kernel/qmouseevent/CMakeLists.txt b/tests/auto/gui/kernel/qmouseevent/CMakeLists.txt index baf9b83b55..ac2200792b 100644 --- a/tests/auto/gui/kernel/qmouseevent/CMakeLists.txt +++ b/tests/auto/gui/kernel/qmouseevent/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qmouseevent.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qmouseevent Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qmouseevent LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qmouseevent SOURCES tst_qmouseevent.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate ) diff --git a/tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp b/tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp index 5420adca14..f703111384 100644 --- a/tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp +++ b/tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2020 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -7,6 +7,8 @@ #include <qwindow.h> #include <QtGui/private/qpointingdevice_p.h> +#include <QtCore/qpointer.h> + Q_LOGGING_CATEGORY(lcTests, "qt.gui.tests") class MouseEventWidget : public QWindow @@ -97,6 +99,7 @@ private slots: void grabbers_data(); void grabbers(); void velocity(); + void clone(); private: MouseEventWidget* testMouseWidget; @@ -263,14 +266,14 @@ void tst_QMouseEvent::grabbers() auto firstEPD = devPriv->pointById(0); QCOMPARE(firstEPD->eventPoint.pressTimestamp(), testMouseWidget->pressTimestamp); QCOMPARE(firstEPD->exclusiveGrabber, grabExclusive ? testMouseWidget : nullptr); - QCOMPARE(firstEPD->passiveGrabbers.count(), grabPassive ? 1 : 0); + QCOMPARE(firstEPD->passiveGrabbers.size(), grabPassive ? 1 : 0); if (grabPassive) QCOMPARE(firstEPD->passiveGrabbers.first(), testMouseWidget); // Ensure that grabbers are forgotten after release delivery QTest::mouseRelease(testMouseWidget, Qt::LeftButton, Qt::KeyboardModifiers(), {10, 10}); QTRY_COMPARE(firstEPD->exclusiveGrabber, nullptr); - QCOMPARE(firstEPD->passiveGrabbers.count(), 0); + QCOMPARE(firstEPD->passiveGrabbers.size(), 0); } void tst_QMouseEvent::velocity() @@ -309,5 +312,24 @@ void tst_QMouseEvent::velocity() QVERIFY(testMouseWidget->velocity.y() > 0); } +void tst_QMouseEvent::clone() +{ + const QPointF pos(10.0f, 10.0f); + + QMouseEvent originalMe(QEvent::MouseButtonPress, pos, pos, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); + QVERIFY(!originalMe.allPointsAccepted()); + QVERIFY(!originalMe.points().first().isAccepted()); + + // create a clone of the original + std::unique_ptr<QMouseEvent> clonedMe(originalMe.clone()); + QVERIFY(!clonedMe->allPointsAccepted()); + QVERIFY(!clonedMe->points().first().isAccepted()); + + // now we alter originalMe, which should *not* change clonedMe + originalMe.setAccepted(true); + QVERIFY(!clonedMe->allPointsAccepted()); + QVERIFY(!clonedMe->points().first().isAccepted()); +} + QTEST_MAIN(tst_QMouseEvent) #include "tst_qmouseevent.moc" diff --git a/tests/auto/gui/kernel/qmouseevent_modal/CMakeLists.txt b/tests/auto/gui/kernel/qmouseevent_modal/CMakeLists.txt index 698327736e..034b9c794d 100644 --- a/tests/auto/gui/kernel/qmouseevent_modal/CMakeLists.txt +++ b/tests/auto/gui/kernel/qmouseevent_modal/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qmouseevent_modal.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qmouseevent_modal Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qmouseevent_modal LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qmouseevent_modal SOURCES tst_qmouseevent_modal.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::Widgets ) diff --git a/tests/auto/gui/kernel/qmouseevent_modal/tst_qmouseevent_modal.cpp b/tests/auto/gui/kernel/qmouseevent_modal/tst_qmouseevent_modal.cpp index e589e54195..0fe218d503 100644 --- a/tests/auto/gui/kernel/qmouseevent_modal/tst_qmouseevent_modal.cpp +++ b/tests/auto/gui/kernel/qmouseevent_modal/tst_qmouseevent_modal.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/gui/kernel/qopenglwindow/CMakeLists.txt b/tests/auto/gui/kernel/qopenglwindow/CMakeLists.txt index d171716776..0f57b98bc3 100644 --- a/tests/auto/gui/kernel/qopenglwindow/CMakeLists.txt +++ b/tests/auto/gui/kernel/qopenglwindow/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qopenglwindow.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qopenglwindow Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qopenglwindow LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qopenglwindow SOURCES tst_qopenglwindow.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp b/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp index e1c4bab677..06a1ffb296 100644 --- a/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp +++ b/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtOpenGL/QOpenGLWindow> #include <QTest> @@ -119,6 +119,9 @@ void tst_QOpenGLWindow::resize() if (isPlatformWayland()) QSKIP("Wayland: Crashes on Intel Mesa due to a driver bug (QTBUG-66848)."); + if (QGuiApplication::platformName().startsWith(QLatin1String("eglfs"), Qt::CaseInsensitive)) + QSKIP("EGLFS does not allow resizing on top level window"); + Window w; w.reset(); w.resize(640, 480); diff --git a/tests/auto/gui/kernel/qpalette/CMakeLists.txt b/tests/auto/gui/kernel/qpalette/CMakeLists.txt index f69ac75a41..7983b9ac25 100644 --- a/tests/auto/gui/kernel/qpalette/CMakeLists.txt +++ b/tests/auto/gui/kernel/qpalette/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qpalette.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qpalette Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qpalette LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qpalette SOURCES tst_qpalette.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp index 22aaaecf19..c21828bee2 100644 --- a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp +++ b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -22,6 +22,8 @@ private Q_SLOTS: void noBrushesSetForDefaultPalette(); void cannotCheckIfInvalidBrushSet(); void checkIfBrushForCurrentGroupSet(); + void cacheKey(); + void dataStream(); }; void tst_QPalette::roleValues_data() @@ -50,9 +52,10 @@ void tst_QPalette::roleValues_data() QTest::newRow("QPalette::ToolTipBase") << int(QPalette::ToolTipBase) << 18; QTest::newRow("QPalette::ToolTipText") << int(QPalette::ToolTipText) << 19; QTest::newRow("QPalette::PlaceholderText") << int(QPalette::PlaceholderText) << 20; + QTest::newRow("QPalette::Accent") << int(QPalette::Accent) << 21; // Change this value as you add more roles. - QTest::newRow("QPalette::NColorRoles") << int(QPalette::NColorRoles) << 21; + QTest::newRow("QPalette::NColorRoles") << int(QPalette::NColorRoles) << 22; } void tst_QPalette::roleValues() @@ -102,9 +105,16 @@ void tst_QPalette::resolve() // ensure the resolve mask is full for (int r = 0; r < QPalette::NColorRoles; ++r) p3.setBrush(QPalette::All, QPalette::ColorRole(r), Qt::red); + const QPalette::ResolveMask fullMask = p3.resolveMask(); QPalette p3ResolvedToP1 = p3.resolve(p1); QVERIFY(p3ResolvedToP1.isCopyOf(p3)); + + QPalette p4; + QCOMPARE(p4.resolveMask(), QPalette::ResolveMask{}); + // resolve must detach even if p4 has no mask + p4 = p4.resolve(p3); + QCOMPARE(p3.resolveMask(), fullMask); } @@ -190,9 +200,6 @@ void tst_QPalette::setBrush() const QPalette pp = p; QVERIFY(pp.isCopyOf(p)); - // Setting the same brush won't detach - p.setBrush(QPalette::Disabled, QPalette::Button, Qt::green); - QVERIFY(pp.isCopyOf(p)); } void tst_QPalette::isBrushSet() @@ -217,7 +224,7 @@ void tst_QPalette::isBrushSet() QVERIFY(!p2.isBrushSet(QPalette::Active, QPalette::Dark)); p2.setBrush(QPalette::Active, QPalette::Dark, p2.brush(QPalette::Active, QPalette::Dark)); QVERIFY(!p3.isBrushSet(QPalette::Active, QPalette::Dark)); - QVERIFY(!p2.isBrushSet(QPalette::Active, QPalette::Dark)); + QVERIFY(p2.isBrushSet(QPalette::Active, QPalette::Dark)); } void tst_QPalette::setAllPossibleBrushes() @@ -231,8 +238,14 @@ void tst_QPalette::setAllPossibleBrushes() } for (int r = 0; r < QPalette::NColorRoles; ++r) { + const QPalette::ColorRole role = static_cast<QPalette::ColorRole>(r); for (int g = 0; g < QPalette::NColorGroups; ++g) { - QVERIFY(p.isBrushSet(QPalette::ColorGroup(g), QPalette::ColorRole(r))); + const QPalette::ColorGroup group = static_cast<QPalette::ColorGroup>(g); + // NoRole has no resolve bit => isBrushSet returns false + if (role == QPalette::NoRole) + QVERIFY(!p.isBrushSet(group, role)); + else + QVERIFY(p.isBrushSet(group, role)); } } } @@ -260,5 +273,120 @@ void tst_QPalette::checkIfBrushForCurrentGroupSet() QVERIFY(p.isBrushSet(QPalette::Current, QPalette::Link)); } +void tst_QPalette::cacheKey() +{ + const QPalette defaultPalette; + // precondition: all palettes are expected to have contrasting text on base + QVERIFY(defaultPalette.base() != defaultPalette.text()); + const auto defaultCacheKey = defaultPalette.cacheKey(); + const auto defaultSerNo = defaultCacheKey >> 32; + const auto defaultDetachNo = defaultCacheKey & 0xffffffff; + + QPalette changeTwicePalette(defaultPalette); + changeTwicePalette.setBrush(QPalette::All, QPalette::ButtonText, Qt::red); + const auto firstChangeCacheKey = changeTwicePalette.cacheKey(); + QCOMPARE_NE(firstChangeCacheKey, defaultCacheKey); + changeTwicePalette.setBrush(QPalette::All, QPalette::ButtonText, Qt::green); + const auto secondChangeCacheKey = changeTwicePalette.cacheKey(); + QCOMPARE_NE(firstChangeCacheKey, secondChangeCacheKey); + + QPalette copyDifferentData(defaultPalette); + QPalette copyDifferentMask(defaultPalette); + QPalette copyDifferentMaskAndData(defaultPalette); + + QCOMPARE(defaultPalette.cacheKey(), copyDifferentData.cacheKey()); + + // deep detach of both private and data + copyDifferentData.setBrush(QPalette::Base, defaultPalette.text()); + const auto differentDataKey = copyDifferentData.cacheKey(); + const auto differentDataSerNo = differentDataKey >> 32; + const auto differentDataDetachNo = differentDataKey & 0xffffffff; + auto loggerDeepDetach = qScopeGuard([&](){ + qDebug() << "Deep detach serial" << differentDataSerNo; + qDebug() << "Deep detach detach number" << differentDataDetachNo; + }); + + QCOMPARE_NE(copyDifferentData.cacheKey(), defaultCacheKey); + QCOMPARE(defaultPalette.cacheKey(), defaultCacheKey); + + // shallow detach, both privates reference the same data + copyDifferentMask.setResolveMask(0xffffffffffffffff); + const auto differentMaskKey = copyDifferentMask.cacheKey(); + const auto differentMaskSerNo = differentMaskKey >> 32; + const auto differentMaskDetachNo = differentMaskKey & 0xffffffff; + auto loggerShallowDetach = qScopeGuard([&](){ + qDebug() << "Shallow detach serial" << differentMaskSerNo; + qDebug() << "Shallow detach detach number" << differentMaskDetachNo; + }); + + QCOMPARE(differentMaskSerNo, defaultSerNo); + QCOMPARE_NE(differentMaskSerNo, defaultDetachNo); + QCOMPARE_NE(differentMaskKey, defaultCacheKey); + QCOMPARE_NE(differentMaskKey, differentDataKey); + + // shallow detach, both privates reference the same data + copyDifferentMaskAndData.setResolveMask(0xeeeeeeeeeeeeeeee); + const auto modifiedCacheKey = copyDifferentMaskAndData.cacheKey(); + QCOMPARE_NE(modifiedCacheKey, copyDifferentMask.cacheKey()); + QCOMPARE_NE(modifiedCacheKey, defaultCacheKey); + QCOMPARE_NE(modifiedCacheKey, copyDifferentData.cacheKey()); + QCOMPARE_NE(copyDifferentMask.cacheKey(), defaultCacheKey); + + // full detach - both key elements are different + copyDifferentMaskAndData.setBrush(QPalette::Base, defaultPalette.text()); + const auto modifiedAllKey = copyDifferentMaskAndData.cacheKey(); + const auto modifiedAllSerNo = modifiedAllKey >> 32; + const auto modifiedAllDetachNo = modifiedAllKey & 0xffffffff; + QCOMPARE_NE(modifiedAllSerNo, defaultSerNo); + QCOMPARE_NE(modifiedAllDetachNo, defaultDetachNo); + + QCOMPARE_NE(modifiedAllKey, copyDifferentMask.cacheKey()); + QCOMPARE_NE(modifiedAllKey, defaultCacheKey); + QCOMPARE_NE(modifiedAllKey, differentDataKey); + QCOMPARE_NE(modifiedAllKey, modifiedCacheKey); + + loggerDeepDetach.dismiss(); + loggerShallowDetach.dismiss(); +} + +void tst_QPalette::dataStream() +{ + const QColor highlight(42, 42, 42); + const QColor accent(13, 13, 13); + QPalette palette; + palette.setBrush(QPalette::Highlight, highlight); + palette.setBrush(QPalette::Accent, accent); + + // When saved with Qt_6_5 or earlier, Accent defaults to Highlight + { + QByteArray b; + { + QDataStream stream(&b, QIODevice::WriteOnly); + stream.setVersion(QDataStream::Qt_6_5); + stream << palette; + } + QPalette test; + QDataStream stream (&b, QIODevice::ReadOnly); + stream.setVersion(QDataStream::Qt_6_5); + stream >> test; + QCOMPARE(test.accent().color(), highlight); + } + + // When saved with Qt_6_6 or later, Accent is saved explicitly + { + QByteArray b; + { + QDataStream stream(&b, QIODevice::WriteOnly); + stream.setVersion(QDataStream::Qt_6_6); + stream << palette; + } + QPalette test; + QDataStream stream (&b, QIODevice::ReadOnly); + stream.setVersion(QDataStream::Qt_6_6); + stream >> test; + QCOMPARE(test.accent().color(), accent); + } +} + QTEST_MAIN(tst_QPalette) #include "tst_qpalette.moc" diff --git a/tests/auto/gui/kernel/qpixelformat/CMakeLists.txt b/tests/auto/gui/kernel/qpixelformat/CMakeLists.txt index e33600dd8c..c711ceeafa 100644 --- a/tests/auto/gui/kernel/qpixelformat/CMakeLists.txt +++ b/tests/auto/gui/kernel/qpixelformat/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qpixelformat.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qpixelformat Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qpixelformat LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qpixelformat SOURCES tst_qpixelformat.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp b/tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp index a0cf95c7f4..d6d471bf6b 100644 --- a/tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp +++ b/tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtGui/qpixelformat.h> diff --git a/tests/auto/gui/kernel/qrasterwindow/CMakeLists.txt b/tests/auto/gui/kernel/qrasterwindow/CMakeLists.txt index 82391cf18f..dc9d6a70c7 100644 --- a/tests/auto/gui/kernel/qrasterwindow/CMakeLists.txt +++ b/tests/auto/gui/kernel/qrasterwindow/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qrasterwindow.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qrasterwindow Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qrasterwindow LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qrasterwindow SOURCES tst_qrasterwindow.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/kernel/qrasterwindow/tst_qrasterwindow.cpp b/tests/auto/gui/kernel/qrasterwindow/tst_qrasterwindow.cpp index 64e418a251..a06e360e35 100644 --- a/tests/auto/gui/kernel/qrasterwindow/tst_qrasterwindow.cpp +++ b/tests/auto/gui/kernel/qrasterwindow/tst_qrasterwindow.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtGui/QRasterWindow> #include <QTest> @@ -45,7 +45,7 @@ void tst_QRasterWindow::basic() w.reset(); w.resize(400, 400); w.show(); - QVERIFY(QTest::qWaitForWindowExposed(&w));; + QVERIFY(QTest::qWaitForWindowExposed(&w)); QVERIFY(w.paintCount >= 1); diff --git a/tests/auto/gui/kernel/qscreen/CMakeLists.txt b/tests/auto/gui/kernel/qscreen/CMakeLists.txt index 9bed97cfcb..8502176ca4 100644 --- a/tests/auto/gui/kernel/qscreen/CMakeLists.txt +++ b/tests/auto/gui/kernel/qscreen/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qscreen.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qscreen Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qscreen LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qscreen SOURCES tst_qscreen.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp b/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp index 9d85a31d5a..74a03ac851 100644 --- a/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp +++ b/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qpainter.h> #include <qrasterwindow.h> @@ -158,35 +158,34 @@ void tst_QScreen::orientationChange() QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::LandscapeOrientation); QWindowSystemInterface::flushWindowSystemEvents(); QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation); - QCOMPARE(spy.count(), ++expectedSignalCount); + QCOMPARE(spy.size(), ++expectedSignalCount); QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::PortraitOrientation); QWindowSystemInterface::flushWindowSystemEvents(); QTRY_COMPARE(screen->orientation(), Qt::PortraitOrientation); - QCOMPARE(spy.count(), ++expectedSignalCount); + QCOMPARE(spy.size(), ++expectedSignalCount); QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedLandscapeOrientation); QWindowSystemInterface::flushWindowSystemEvents(); QTRY_COMPARE(screen->orientation(), Qt::InvertedLandscapeOrientation); - QCOMPARE(spy.count(), ++expectedSignalCount); + QCOMPARE(spy.size(), ++expectedSignalCount); QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedPortraitOrientation); QWindowSystemInterface::flushWindowSystemEvents(); QTRY_COMPARE(screen->orientation(), Qt::InvertedPortraitOrientation); - QCOMPARE(spy.count(), ++expectedSignalCount); + QCOMPARE(spy.size(), ++expectedSignalCount); QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::LandscapeOrientation); QWindowSystemInterface::flushWindowSystemEvents(); QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation); - QCOMPARE(spy.count(), ++expectedSignalCount); + QCOMPARE(spy.size(), ++expectedSignalCount); } void tst_QScreen::grabWindow_data() { - if (!QGuiApplicationPrivate::platformIntegration()->hasCapability( - QPlatformIntegration::ScreenWindowGrabbing)) { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ScreenWindowGrabbing) + || (QGuiApplication::platformName().toLower() == QStringLiteral("xcb") && !qEnvironmentVariableIsEmpty("WAYLAND_DISPLAY"))) QSKIP("This platform does not support grabbing windows on screen."); - } QTest::addColumn<int>("screenIndex"); QTest::addColumn<QByteArray>("screenName"); QTest::addColumn<bool>("grabWindow"); diff --git a/tests/auto/gui/kernel/qshortcut/CMakeLists.txt b/tests/auto/gui/kernel/qshortcut/CMakeLists.txt index 469ab47769..517a4e8a1a 100644 --- a/tests/auto/gui/kernel/qshortcut/CMakeLists.txt +++ b/tests/auto/gui/kernel/qshortcut/CMakeLists.txt @@ -1,12 +1,20 @@ -# Generated from qshortcut.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qshortcut_kernel Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qshortcut_kernel LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qshortcut_kernel SOURCES tst_qshortcut.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui + Qt::GuiPrivate ) diff --git a/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp index 8a1b2888a2..cb6ebab800 100644 --- a/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp +++ b/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp @@ -1,56 +1,59 @@ // Copyright (C) 2019 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtGui/qguiapplication.h> #include <QtGui/qshortcut.h> -#include <QtGui/qpainter.h> -#include <QtGui/qrasterwindow.h> -#include <QtGui/qscreen.h> #include <QtGui/qwindow.h> +#include <QtTest/qsignalspy.h> + +#include <QtGui/private/qguiapplication_p.h> +#include <qpa/qplatformintegration.h> class tst_QShortcut : public QObject { Q_OBJECT -public: private slots: - void trigger(); -}; - -class ColoredWindow : public QRasterWindow { -public: - ColoredWindow(QColor c) : m_color(c) {} - -protected: - void paintEvent(QPaintEvent *event) override; - -private: - const QColor m_color; + void applicationShortcut(); + void windowShortcut(); }; -void ColoredWindow::paintEvent(QPaintEvent *) +void tst_QShortcut::applicationShortcut() { - QPainter p(this); - p.fillRect(QRect(QPoint(), size()), m_color); + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + + auto *shortcut = new QShortcut(Qt::CTRL | Qt::Key_A, this); + shortcut->setContext(Qt::ApplicationShortcut); + QSignalSpy activatedSpy(shortcut, &QShortcut::activated); + + // Need a window to send key event to, even if the shortcut is application + // global. The documentation for Qt::ApplicationShortcut also says that + // the shortcut "is active when one of the applications windows are active", + // but this is only honored for Qt Widgets, not for Qt Gui. For now we + // activate the window just in case. + QWindow window; + window.show(); + QVERIFY(QTest::qWaitForWindowActive(&window)); + QTRY_COMPARE(QGuiApplication::applicationState(), Qt::ApplicationActive); + QTest::sendKeyEvent(QTest::Shortcut, &window, Qt::Key_A, 'a', Qt::ControlModifier); + + QVERIFY(activatedSpy.size() > 0); } -static void sendKey(QWindow *target, Qt::Key k, char c, Qt::KeyboardModifiers modifiers) +void tst_QShortcut::windowShortcut() { - QTest::sendKeyEvent(QTest::Press, target, k, c, modifiers); - QTest::sendKeyEvent(QTest::Release, target, k, c, modifiers); -} - -void tst_QShortcut::trigger() -{ - ColoredWindow w(Qt::yellow); - w.setTitle(QTest::currentTestFunction()); - w.resize(QGuiApplication::primaryScreen()->size() / 4); + QWindow w; new QShortcut(Qt::CTRL | Qt::Key_Q, &w, SLOT(close())); w.show(); QVERIFY(QTest::qWaitForWindowExposed(&w)); + + if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) + QEXPECT_FAIL("", "It failed on Wayland, QTBUG-120334", Abort); + QTRY_VERIFY(QGuiApplication::applicationState() == Qt::ApplicationActive); - sendKey(&w, Qt::Key_Q, 'q', Qt::ControlModifier); + QTest::sendKeyEvent(QTest::Click, &w, Qt::Key_Q, 'q', Qt::ControlModifier); QTRY_VERIFY(!w.isVisible()); } diff --git a/tests/auto/gui/kernel/qsurfaceformat/CMakeLists.txt b/tests/auto/gui/kernel/qsurfaceformat/CMakeLists.txt index f1fab57ebe..1303f48cf3 100644 --- a/tests/auto/gui/kernel/qsurfaceformat/CMakeLists.txt +++ b/tests/auto/gui/kernel/qsurfaceformat/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qsurfaceformat.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qsurfaceformat Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qsurfaceformat LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qsurfaceformat SOURCES tst_qsurfaceformat.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/kernel/qsurfaceformat/tst_qsurfaceformat.cpp b/tests/auto/gui/kernel/qsurfaceformat/tst_qsurfaceformat.cpp index 0b2d301ad9..3f655bd905 100644 --- a/tests/auto/gui/kernel/qsurfaceformat/tst_qsurfaceformat.cpp +++ b/tests/auto/gui/kernel/qsurfaceformat/tst_qsurfaceformat.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qsurfaceformat.h> diff --git a/tests/auto/gui/kernel/qtouchevent/BLACKLIST b/tests/auto/gui/kernel/qtouchevent/BLACKLIST index 3ae3f6d30d..c4e4b2291d 100644 --- a/tests/auto/gui/kernel/qtouchevent/BLACKLIST +++ b/tests/auto/gui/kernel/qtouchevent/BLACKLIST @@ -1,7 +1,3 @@ -[multiPointRawEventTranslationOnTouchScreen] -ubuntu-16.04 -[multiPointRawEventTranslationOnTouchScreen] -android [multiPointRawEventTranslationOnTouchPad] # QTBUG-101519 windows-11 diff --git a/tests/auto/gui/kernel/qtouchevent/CMakeLists.txt b/tests/auto/gui/kernel/qtouchevent/CMakeLists.txt index e9a6271f58..160263ac66 100644 --- a/tests/auto/gui/kernel/qtouchevent/CMakeLists.txt +++ b/tests/auto/gui/kernel/qtouchevent/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qtouchevent.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtouchevent Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtouchevent LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtouchevent SOURCES tst_qtouchevent.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate Qt::Widgets diff --git a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp index 0a80b127e8..37ddcb8962 100644 --- a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp +++ b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2020 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtGui/QCursor> #include <QtGui/QScreen> @@ -17,6 +17,10 @@ #include <QtGui/private/qeventpoint_p.h> #include <private/qhighdpiscaling_p.h> #include <private/qpointingdevice_p.h> +#include <private/qguiapplication_p.h> +#include <qpa/qplatformintegration.h> + +#include <QtCore/qpointer.h> Q_LOGGING_CATEGORY(lcTests, "qt.gui.tests") @@ -46,6 +50,24 @@ public: deleteInTouchBegin = deleteInTouchUpdate = deleteInTouchEnd = false; } + void paintEvent(QPaintEvent *) override + { + QPainter painter(this); + painter.drawRect(rect()); + painter.setPen(Qt::darkGray); + painter.drawText(rect(), Qt::AlignHCenter | Qt::AlignCenter, objectName()); + static const QString pointFormat = QString::fromUtf8("\360\237\226\227 %1, %2"); + painter.setPen(Qt::darkGreen); + for (const auto &pt : std::as_const(touchBeginPoints)) + painter.drawText(pt.position(), pointFormat.arg(pt.position().toPoint().x()).arg(pt.position().toPoint().y())); + painter.setPen(Qt::darkYellow); + for (const auto &pt : std::as_const(touchUpdatePoints)) + painter.drawText(pt.position(), pointFormat.arg(pt.position().toPoint().x()).arg(pt.position().toPoint().y())); + painter.setPen(Qt::darkRed); + for (const auto &pt : std::as_const(touchEndPoints)) + painter.drawText(pt.position(), pointFormat.arg(pt.position().toPoint().x()).arg(pt.position().toPoint().y())); + } + bool event(QEvent *event) override { lastNormalizedPositions.clear(); @@ -59,13 +81,15 @@ public: auto touchEvent = static_cast<QTouchEvent *>(event); touchBeginPoints = touchEvent->points(); Q_ASSERT(touchBeginPoints.first().device() == touchEvent->pointingDevice()); - for (const QEventPoint &pt : qAsConst(touchBeginPoints)) + for (const QEventPoint &pt : std::as_const(touchBeginPoints)) lastNormalizedPositions << pt.normalizedPosition(); timestamp = touchEvent->timestamp(); deviceFromEvent = touchEvent->pointingDevice(); event->setAccepted(acceptTouchBegin); if (deleteInTouchBegin) delete this; + else + update(); break; } case QEvent::TouchUpdate: { @@ -75,13 +99,15 @@ public: seenTouchUpdate = seenTouchBegin && !seenTouchEnd; auto touchEvent = static_cast<QTouchEvent *>(event); touchUpdatePoints = touchEvent->points(); - for (const QEventPoint &pt : qAsConst(touchUpdatePoints)) + for (const QEventPoint &pt : std::as_const(touchUpdatePoints)) lastNormalizedPositions << pt.normalizedPosition(); timestamp = touchEvent->timestamp(); deviceFromEvent = touchEvent->pointingDevice(); event->setAccepted(acceptTouchUpdate); if (deleteInTouchUpdate) delete this; + else + update(); break; } case QEvent::TouchEnd: { @@ -91,13 +117,15 @@ public: seenTouchEnd = seenTouchBegin && !seenTouchEnd; auto touchEvent = static_cast<QTouchEvent *>(event); touchEndPoints = touchEvent->points(); - for (const QEventPoint &pt : qAsConst(touchEndPoints)) + for (const QEventPoint &pt : std::as_const(touchEndPoints)) lastNormalizedPositions << pt.normalizedPosition(); timestamp = touchEvent->timestamp(); deviceFromEvent = touchEvent->pointingDevice(); event->setAccepted(acceptTouchEnd); if (deleteInTouchEnd) delete this; + else + update(); break; } default: @@ -343,9 +371,11 @@ void tst_QTouchEvent::state() QVERIFY(!touchEvent3.isBeginEvent()); QVERIFY(!touchEvent3.isUpdateEvent()); QVERIFY(touchEvent3.isEndEvent()); +#if QT_DEPRECATED_SINCE(6, 0) QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED // test Qt 5 compatibility wrappers QCOMPARE(touchEvent3.touchPoints(), touchEvent3.points()); QT_WARNING_POP +#endif } void tst_QTouchEvent::touchDisabledByDefault() @@ -706,7 +736,7 @@ void tst_QTouchEvent::basicRawEventTranslation() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchBeginPoints.count(), 1); + QCOMPARE(touchWidget.touchBeginPoints.size(), 1); QCOMPARE(touchWidget.timestamp, timestamp); QEventPoint touchBeginPoint = touchWidget.touchBeginPoints.first(); QCOMPARE(touchBeginPoint.id(), 0); @@ -736,7 +766,7 @@ void tst_QTouchEvent::basicRawEventTranslation() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchUpdatePoints.count(), 1); + QCOMPARE(touchWidget.touchUpdatePoints.size(), 1); QEventPoint touchUpdatePoint = touchWidget.touchUpdatePoints.first(); QCOMPARE(touchUpdatePoint.id(), 0); QCOMPARE(touchUpdatePoint.state(), rawTouchPoint.state()); @@ -764,7 +794,7 @@ void tst_QTouchEvent::basicRawEventTranslation() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchEndPoints.count(), 1); + QCOMPARE(touchWidget.touchEndPoints.size(), 1); QEventPoint touchEndPoint = touchWidget.touchEndPoints.first(); QCOMPARE(touchEndPoint.id(), 0); QCOMPARE(touchEndPoint.state(), rawTouchPoint.state()); @@ -787,9 +817,11 @@ void tst_QTouchEvent::basicRawEventTranslation() void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() { tst_QTouchEventWidget touchWidget; + touchWidget.setObjectName("parent touch widget"); touchWidget.setWindowTitle(QTest::currentTestFunction()); touchWidget.setAttribute(Qt::WA_AcceptTouchEvents); - touchWidget.setGeometry(100, 100, 400, 300); + const QPoint topLeft = QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(100, 100); + touchWidget.setGeometry({topLeft, QSize(400, 300)}); tst_QTouchEventWidget leftWidget(&touchWidget); leftWidget.setObjectName("leftWidget"); @@ -803,24 +835,25 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() touchWidget.show(); QVERIFY(QTest::qWaitForWindowExposed(&touchWidget)); + if (touchWidget.geometry().topLeft() != topLeft) { + qCDebug(lcTests) << "tried to set position 100, 100 on screen; got geometry" + << touchWidget.geometry() << "frame" << touchWidget.frameGeometry(); + QSKIP("failed to position the widget window on this platform"); + } - QPointF leftPos = leftWidget.rect().center(); - QPointF rightPos = rightWidget.rect().center(); - QPointF centerPos = touchWidget.rect().center(); - QPointF leftScreenPos = leftWidget.mapToGlobal(leftPos.toPoint()); - QPointF rightScreenPos = rightWidget.mapToGlobal(rightPos.toPoint()); - QPointF centerScreenPos = touchWidget.mapToGlobal(centerPos.toPoint()); + QPoint leftPos = leftWidget.rect().center(); + QPoint rightPos = rightWidget.rect().center(); + QPoint centerPos = touchWidget.rect().center(); + QPoint leftScenePos = leftWidget.mapToParent(leftPos); + QPoint rightScenePos = rightWidget.mapToParent(rightPos); + QPoint leftScreenPos = leftWidget.mapToGlobal(leftPos); + QPoint rightScreenPos = rightWidget.mapToGlobal(rightPos); + QPoint centerScreenPos = touchWidget.mapToGlobal(centerPos); // generate TouchBegins on both leftWidget and rightWidget - ulong timestamp = 0; - auto rawTouchPoints = QList<QEventPoint>() - << QEventPoint(0, QEventPoint::State::Pressed, QPointF(), leftScreenPos) - << QEventPoint(1, QEventPoint::State::Pressed, QPointF(), rightScreenPos); - QWindow *window = touchWidget.windowHandle(); - QList<QWindowSystemInterface::TouchPoint> nativeTouchPoints = - QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window); - QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints); - QCoreApplication::processEvents(); + auto touchSequence = QTest::touchEvent(touchWidget.windowHandle(), touchScreenDevice); + touchSequence.press(0, leftScenePos).press(1, rightScenePos); + QVERIFY(touchSequence.commit()); // verify acceptance QVERIFY(!touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); @@ -830,14 +863,14 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() QVERIFY(rightWidget.seenTouchBegin); QVERIFY(!rightWidget.seenTouchUpdate); QVERIFY(!rightWidget.seenTouchEnd); - QCOMPARE(leftWidget.touchBeginPoints.count(), 1); - QCOMPARE(rightWidget.touchBeginPoints.count(), 1); + QCOMPARE(leftWidget.touchBeginPoints.size(), 1); + QCOMPARE(rightWidget.touchBeginPoints.size(), 1); const int touchPointId0 = 0; const int touchPointId1 = touchPointId0 + 1; { - QEventPoint leftTouchPoint = leftWidget.touchBeginPoints.first(); + const QEventPoint &leftTouchPoint = leftWidget.touchBeginPoints.first(); QCOMPARE(leftTouchPoint.id(), touchPointId0); - QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state()); + QCOMPARE(leftTouchPoint.state(), QEventPoint::Pressed); QCOMPARE(leftTouchPoint.position(), leftPos); QCOMPARE(leftTouchPoint.pressPosition(), leftPos); QCOMPARE(leftTouchPoint.lastPosition(), leftPos); @@ -847,15 +880,12 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() QCOMPARE(leftTouchPoint.globalPosition(), leftScreenPos); QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos); QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos); - QCOMPARE(leftTouchPoint.position(), leftPos); - QCOMPARE(leftTouchPoint.scenePosition(), leftScreenPos); - QCOMPARE(leftTouchPoint.globalPosition(), leftScreenPos); QCOMPARE(leftTouchPoint.ellipseDiameters(), QSizeF(0, 0)); QCOMPARE(leftTouchPoint.pressure(), qreal(1.)); - QEventPoint rightTouchPoint = rightWidget.touchBeginPoints.first(); + const QEventPoint &rightTouchPoint = rightWidget.touchBeginPoints.first(); QCOMPARE(rightTouchPoint.id(), touchPointId1); - QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state()); + QCOMPARE(rightTouchPoint.state(), QEventPoint::Pressed); QCOMPARE(rightTouchPoint.position(), rightPos); QCOMPARE(rightTouchPoint.pressPosition(), rightPos); QCOMPARE(rightTouchPoint.lastPosition(), rightPos); @@ -865,20 +895,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() QCOMPARE(rightTouchPoint.globalPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos); - QCOMPARE(rightTouchPoint.position(), rightPos); - QCOMPARE(rightTouchPoint.scenePosition(), rightScreenPos); - QCOMPARE(rightTouchPoint.globalPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.ellipseDiameters(), QSizeF(0, 0)); QCOMPARE(rightTouchPoint.pressure(), qreal(1.)); } - rawTouchPoints.clear(); - rawTouchPoints << QEventPoint(0, QEventPoint::State::Updated, QPointF(), centerScreenPos) - << QEventPoint(1, QEventPoint::State::Updated, QPointF(), centerScreenPos); - nativeTouchPoints = - QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window); - QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints); - QCoreApplication::processEvents(); + // an unlikely event with the two touchpoints moving exactly on top of each other + touchSequence.move(0, centerPos).move(1, centerPos); + QVERIFY(touchSequence.commit()); // verify acceptance QVERIFY(!touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); @@ -888,13 +911,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() QVERIFY(rightWidget.seenTouchBegin); QVERIFY(rightWidget.seenTouchUpdate); QVERIFY(!rightWidget.seenTouchEnd); - QCOMPARE(leftWidget.touchUpdatePoints.count(), 1); - QCOMPARE(rightWidget.touchUpdatePoints.count(), 1); + QCOMPARE(leftWidget.touchUpdatePoints.size(), 1); + QCOMPARE(rightWidget.touchUpdatePoints.size(), 1); { - QEventPoint leftTouchPoint = leftWidget.touchUpdatePoints.first(); + const QEventPoint &leftTouchPoint = leftWidget.touchUpdatePoints.first(); QCOMPARE(leftTouchPoint.id(), touchPointId0); - QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state()); - QCOMPARE(leftTouchPoint.position(), QPointF(leftWidget.mapFromParent(centerPos.toPoint()))); + QCOMPARE(leftTouchPoint.state(), QEventPoint::Updated); + QCOMPARE(leftTouchPoint.position(), QPointF(leftWidget.mapFromParent(centerPos))); QCOMPARE(leftTouchPoint.pressPosition(), leftPos); QCOMPARE(leftTouchPoint.lastPosition(), leftPos); QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos); @@ -903,16 +926,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos); QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos); - QCOMPARE(leftTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint())); - QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos); - QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(leftTouchPoint.ellipseDiameters(), QSizeF(0, 0)); QCOMPARE(leftTouchPoint.pressure(), qreal(1.)); - QEventPoint rightTouchPoint = rightWidget.touchUpdatePoints.first(); + const QEventPoint &rightTouchPoint = rightWidget.touchUpdatePoints.first(); QCOMPARE(rightTouchPoint.id(), touchPointId1); - QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state()); - QCOMPARE(rightTouchPoint.position(), QPointF(rightWidget.mapFromParent(centerPos.toPoint()))); + QCOMPARE(rightTouchPoint.state(), QEventPoint::Updated); + QCOMPARE(rightTouchPoint.position(), QPointF(rightWidget.mapFromParent(centerPos))); QCOMPARE(rightTouchPoint.pressPosition(), rightPos); QCOMPARE(rightTouchPoint.lastPosition(), rightPos); QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos); @@ -921,21 +941,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos); - QCOMPARE(rightTouchPoint.position(), rightWidget.mapFromParent(centerPos.toPoint())); - QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos); - QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(rightTouchPoint.ellipseDiameters(), QSizeF(0, 0)); QCOMPARE(rightTouchPoint.pressure(), qreal(1.)); } // generate TouchEnds on both leftWidget and rightWidget - rawTouchPoints.clear(); - rawTouchPoints << QEventPoint(0, QEventPoint::State::Released, QPointF(), centerScreenPos) - << QEventPoint(1, QEventPoint::State::Released, QPointF(), centerScreenPos); - nativeTouchPoints = - QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window); - QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints); - QCoreApplication::processEvents(); + touchSequence.release(0, centerPos).release(1, centerPos); + QVERIFY(touchSequence.commit()); // verify acceptance QVERIFY(!touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); @@ -945,13 +957,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() QVERIFY(rightWidget.seenTouchBegin); QVERIFY(rightWidget.seenTouchUpdate); QVERIFY(rightWidget.seenTouchEnd); - QCOMPARE(leftWidget.touchEndPoints.count(), 1); - QCOMPARE(rightWidget.touchEndPoints.count(), 1); + QCOMPARE(leftWidget.touchEndPoints.size(), 1); + QCOMPARE(rightWidget.touchEndPoints.size(), 1); { - QEventPoint leftTouchPoint = leftWidget.touchEndPoints.first(); + const QEventPoint &leftTouchPoint = leftWidget.touchEndPoints.first(); QCOMPARE(leftTouchPoint.id(), touchPointId0); - QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state()); - QCOMPARE(leftTouchPoint.position(), QPointF(leftWidget.mapFromParent(centerPos.toPoint()))); + QCOMPARE(leftTouchPoint.state(), QEventPoint::Released); + QCOMPARE(leftTouchPoint.position(), QPointF(leftWidget.mapFromParent(centerPos))); QCOMPARE(leftTouchPoint.pressPosition(), leftPos); QCOMPARE(leftTouchPoint.lastPosition(), leftPos); QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos); @@ -960,16 +972,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos); QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos); - QCOMPARE(leftTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint())); - QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos); - QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(leftTouchPoint.ellipseDiameters(), QSizeF(0, 0)); QCOMPARE(leftTouchPoint.pressure(), qreal(0.)); - QEventPoint rightTouchPoint = rightWidget.touchEndPoints.first(); + const QEventPoint &rightTouchPoint = rightWidget.touchEndPoints.first(); QCOMPARE(rightTouchPoint.id(), touchPointId1); - QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state()); - QCOMPARE(rightTouchPoint.position(), QPointF(rightWidget.mapFromParent(centerPos.toPoint()))); + QCOMPARE(rightTouchPoint.state(), QEventPoint::Released); + QCOMPARE(rightTouchPoint.position(), QPointF(rightWidget.mapFromParent(centerPos))); QCOMPARE(rightTouchPoint.pressPosition(), rightPos); QCOMPARE(rightTouchPoint.lastPosition(), rightPos); QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos); @@ -978,9 +987,6 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos); - QCOMPARE(rightTouchPoint.position(), rightWidget.mapFromParent(centerPos.toPoint())); - QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos); - QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(rightTouchPoint.ellipseDiameters(), QSizeF(0, 0)); QCOMPARE(rightTouchPoint.pressure(), qreal(0.)); } @@ -1010,7 +1016,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchBeginPoints.count(), 1); + QCOMPARE(touchWidget.touchBeginPoints.size(), 1); QCOMPARE(touchWidget.timestamp, timestamp); QEventPoint touchBeginPoint = touchWidget.touchBeginPoints.first(); QCOMPARE(touchBeginPoint.id(), 1); @@ -1025,7 +1031,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens() QWindowSystemInterface::handleTouchEvent(window, ++timestamp, secondaryTouchScreenDevice, nativeTouchPoints); QCoreApplication::processEvents(); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchBeginPoints.count(), 1); + QCOMPARE(touchWidget.touchBeginPoints.size(), 1); QCOMPARE(touchWidget.timestamp, timestamp); touchBeginPoint = touchWidget.touchBeginPoints[0]; QCOMPARE(touchBeginPoint.id(), 10); @@ -1040,7 +1046,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens() QWindowSystemInterface::handleTouchEvent(window, ++timestamp, secondaryTouchScreenDevice, nativeTouchPoints); QCoreApplication::processEvents(); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchBeginPoints.count(), 1); + QCOMPARE(touchWidget.touchBeginPoints.size(), 1); QCOMPARE(touchWidget.timestamp, timestamp); touchBeginPoint = touchWidget.touchBeginPoints[0]; QCOMPARE(touchBeginPoint.id(), 11); @@ -1056,7 +1062,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchUpdatePoints.count(), 1); + QCOMPARE(touchWidget.touchUpdatePoints.size(), 1); QEventPoint touchUpdatePoint = touchWidget.touchUpdatePoints.first(); QCOMPARE(touchUpdatePoint.id(), 1); QCOMPARE(touchUpdatePoint.state(), QEventPoint::State::Updated); @@ -1071,7 +1077,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchEndPoints.count(), 1); + QCOMPARE(touchWidget.touchEndPoints.size(), 1); QEventPoint touchEndPoint = touchWidget.touchEndPoints.first(); QCOMPARE(touchEndPoint.id(), 1); QCOMPARE(touchEndPoint.state(), QEventPoint::State::Released); @@ -1096,7 +1102,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchUpdatePoints.count(), 2); + QCOMPARE(touchWidget.touchUpdatePoints.size(), 2); QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 10); QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 11); @@ -1111,7 +1117,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchEndPoints.count(), 1); + QCOMPARE(touchWidget.touchEndPoints.size(), 1); touchEndPoint = touchWidget.touchEndPoints.first(); QCOMPARE(touchEndPoint.id(), 11); QCOMPARE(touchEndPoint.state(), QEventPoint::State::Released); @@ -1127,6 +1133,9 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QSKIP("The macOS mouse cursor interferes with this test can cannot be moved away"); #endif + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("QWindow::requestActivate() is not supported."); + tst_QTouchEventWidget touchWidget; touchWidget.setObjectName("touchWidget"); touchWidget.setWindowTitle(QTest::currentTestFunction()); @@ -1145,7 +1154,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() rightWidget.setGeometry(300, 100, 100, 100); touchWidget.show(); - QVERIFY(QTest::qWaitForWindowExposed(&touchWidget)); + QVERIFY(QTest::qWaitForWindowActive(&touchWidget)); const QPointF leftPos = leftWidget.rect().center(); const QPointF rightPos = rightWidget.rect().center(); @@ -1183,8 +1192,9 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QVERIFY(!rightWidget.seenTouchBegin); QVERIFY(!rightWidget.seenTouchUpdate); QVERIFY(!rightWidget.seenTouchEnd); - QCOMPARE(leftWidget.touchBeginPoints.count(), 2); - QCOMPARE(rightWidget.touchBeginPoints.count(), 0); + QCOMPARE(leftWidget.touchBeginPoints.size(), 2); + QCOMPARE(rightWidget.touchBeginPoints.size(), 0); + QCOMPARE(leftWidget.lastNormalizedPositions.size(), 2); { QEventPoint leftTouchPoint = leftWidget.touchBeginPoints.at(0); qCDebug(lcTests) << "lastNormalizedPositions after press" << leftWidget.lastNormalizedPositions; @@ -1200,7 +1210,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QCOMPARE(leftTouchPoint.globalPosition(), leftScreenPos); QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos); QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos); - QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.2) < 0.05); // 0.198, might depend on window frame size + QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.2), 0.05); // 0.198, might depend on window frame size QCOMPARE(leftTouchPoint.position(), leftPos); QCOMPARE(leftTouchPoint.scenePosition(), leftScreenPos); QCOMPARE(leftTouchPoint.globalPosition(), leftScreenPos); @@ -1220,7 +1230,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QCOMPARE(rightTouchPoint.globalPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos); - QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.8) < 0.05); // 0.798, might depend on window frame size + QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.8), 0.05); // 0.798, might depend on window frame size QCOMPARE(rightTouchPoint.scenePosition(), rightScreenPos); QCOMPARE(rightTouchPoint.globalPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.ellipseDiameters(), QSizeF(0, 0)); @@ -1245,8 +1255,9 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QVERIFY(!rightWidget.seenTouchBegin); QVERIFY(!rightWidget.seenTouchUpdate); QVERIFY(!rightWidget.seenTouchEnd); - QCOMPARE(leftWidget.touchUpdatePoints.count(), 2); - QCOMPARE(rightWidget.touchUpdatePoints.count(), 0); + QCOMPARE(leftWidget.touchUpdatePoints.size(), 2); + QCOMPARE(rightWidget.touchUpdatePoints.size(), 0); + QCOMPARE(leftWidget.lastNormalizedPositions.size(), 2); { QEventPoint leftTouchPoint = leftWidget.touchUpdatePoints.at(0); qCDebug(lcTests) << "lastNormalizedPositions after update" << leftWidget.lastNormalizedPositions; @@ -1262,7 +1273,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos); QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos); - QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.5) < 0.05); // 0.498, might depend on window frame size + QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.5), 0.05); // 0.498, might depend on window frame size QCOMPARE(leftTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint())); QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos); QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos); @@ -1282,7 +1293,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos); - QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.5) < 0.05); // 0.498, might depend on window frame size + QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.5), 0.05); // 0.498, might depend on window frame size QCOMPARE(rightTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint())); QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos); QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos); @@ -1307,8 +1318,9 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QVERIFY(!rightWidget.seenTouchBegin); QVERIFY(!rightWidget.seenTouchUpdate); QVERIFY(!rightWidget.seenTouchEnd); - QCOMPARE(leftWidget.touchEndPoints.count(), 2); - QCOMPARE(rightWidget.touchEndPoints.count(), 0); + QCOMPARE(leftWidget.touchEndPoints.size(), 2); + QCOMPARE(rightWidget.touchEndPoints.size(), 0); + QCOMPARE(leftWidget.lastNormalizedPositions.size(), 2); { QEventPoint leftTouchPoint = leftWidget.touchEndPoints.at(0); qCDebug(lcTests) << "lastNormalizedPositions after release" << leftWidget.lastNormalizedPositions; @@ -1325,7 +1337,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos); QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos); - QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.5) < 0.05); // 0.498, might depend on window frame size + QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.5), 0.05); // 0.498, might depend on window frame size QCOMPARE(leftTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint())); QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos); QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos); @@ -1345,7 +1357,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos); - QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.5) < 0.05); // 0.498, might depend on window frame size + QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.5), 0.05); // 0.498, might depend on window frame size QCOMPARE(rightTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint())); QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos); QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos); @@ -1391,16 +1403,16 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchBeginPoints.count(), 2); + QCOMPARE(touchWidget.touchBeginPoints.size(), 2); - for (int i = 0; i < touchWidget.touchBeginPoints.count(); ++i) { + for (int i = 0; i < touchWidget.touchBeginPoints.size(); ++i) { QEventPoint touchBeginPoint = touchWidget.touchBeginPoints.at(i); QCOMPARE(touchBeginPoint.id(), i); QCOMPARE(touchBeginPoint.state(), rawTouchPoints[i].state()); } // moving the point should translate to TouchUpdate - for (int i = 0; i < rawTouchPoints.count(); ++i) { + for (int i = 0; i < rawTouchPoints.size(); ++i) { auto &p = rawTouchPoints[i]; QMutableEventPoint::setState(p, QEventPoint::State::Updated); QMutableEventPoint::setGlobalPosition(p, p.globalPosition() + delta); @@ -1412,7 +1424,7 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchUpdatePoints.count(), 2); + QCOMPARE(touchWidget.touchUpdatePoints.size(), 2); QCOMPARE(touchWidget.touchUpdatePoints.at(0).id(), 0); QCOMPARE(touchWidget.touchUpdatePoints.at(1).id(), 1); @@ -1427,7 +1439,7 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QCOMPARE(touchWidget.seenTouchEnd, false); - QCOMPARE(touchWidget.touchUpdatePoints.count(), 2); + QCOMPARE(touchWidget.touchUpdatePoints.size(), 2); QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 0); QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 1); @@ -1441,7 +1453,7 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchUpdatePoints.count(), 2); + QCOMPARE(touchWidget.touchUpdatePoints.size(), 2); QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 0); QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 42); @@ -1455,7 +1467,7 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchUpdatePoints.count(), 2); + QCOMPARE(touchWidget.touchUpdatePoints.size(), 2); QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 0); QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 42); } @@ -1819,25 +1831,25 @@ void tst_QTouchEvent::testQGuiAppDelivery() // Now the real thing. QWindowSystemInterface::handleTouchEvent(&w, touchScreenDevice, points); // TouchBegin QCoreApplication::processEvents(); - QCOMPARE(filter.d.count(), 1); + QCOMPARE(filter.d.size(), 1); QCOMPARE(filter.d.contains(touchScreenDevice), true); - QCOMPARE(filter.d.value(touchScreenDevice).points.count(), 1); + QCOMPARE(filter.d.value(touchScreenDevice).points.size(), 1); QCOMPARE(filter.d.value(touchScreenDevice).lastSeenType, QEvent::TouchBegin); points[0].state = QEventPoint::State::Updated; QWindowSystemInterface::handleTouchEvent(&w, touchScreenDevice, points); // TouchUpdate QCoreApplication::processEvents(); - QCOMPARE(filter.d.count(), 1); + QCOMPARE(filter.d.size(), 1); QCOMPARE(filter.d.contains(touchScreenDevice), true); - QCOMPARE(filter.d.value(touchScreenDevice).points.count(), 2); + QCOMPARE(filter.d.value(touchScreenDevice).points.size(), 2); QCOMPARE(filter.d.value(touchScreenDevice).lastSeenType, QEvent::TouchUpdate); points[0].state = QEventPoint::State::Released; QWindowSystemInterface::handleTouchEvent(&w, touchScreenDevice, points); // TouchEnd QCoreApplication::processEvents(); - QCOMPARE(filter.d.count(), 1); + QCOMPARE(filter.d.size(), 1); QCOMPARE(filter.d.contains(touchScreenDevice), true); - QCOMPARE(filter.d.value(touchScreenDevice).points.count(), 3); + QCOMPARE(filter.d.value(touchScreenDevice).points.size(), 3); QCOMPARE(filter.d.value(touchScreenDevice).lastSeenType, QEvent::TouchEnd); } @@ -1880,8 +1892,8 @@ void tst_QTouchEvent::testMultiDevice() QCOMPARE(filter.d.value(touchScreenDevice).lastSeenType, QEvent::TouchBegin); QCOMPARE(filter.d.value(deviceTwo).lastSeenType, QEvent::TouchBegin); - QCOMPARE(filter.d.value(touchScreenDevice).points.count(), 1); - QCOMPARE(filter.d.value(deviceTwo).points.count(), 2); + QCOMPARE(filter.d.value(touchScreenDevice).points.size(), 1); + QCOMPARE(filter.d.value(deviceTwo).points.size(), 2); QCOMPARE(filter.d.value(touchScreenDevice).points.at(0).globalPosition(), area0.center()); // This fails because QGuiApplicationPrivate::processTouchEvent() sends synth-mouse events @@ -1936,7 +1948,7 @@ void tst_QTouchEvent::grabbers() // Ensure that grabbers are persistent between events, within the stored touchpoints QCOMPARE(devPriv->pointById(0)->exclusiveGrabber, grabExclusive ? &w : nullptr); - QCOMPARE(devPriv->pointById(0)->passiveGrabbers.count(), grabPassive ? 1 : 0); + QCOMPARE(devPriv->pointById(0)->passiveGrabbers.size(), grabPassive ? 1 : 0); if (grabPassive) QCOMPARE(devPriv->pointById(0)->passiveGrabbers.first(), &w); diff --git a/tests/auto/gui/kernel/qwindow/BLACKLIST b/tests/auto/gui/kernel/qwindow/BLACKLIST index f5786e7522..69df8883c8 100644 --- a/tests/auto/gui/kernel/qwindow/BLACKLIST +++ b/tests/auto/gui/kernel/qwindow/BLACKLIST @@ -1,9 +1,4 @@ [positioning] -opensuse-leap -[positioning:default] -linux -macos ci -[positioning:fake] macos ci [modalWithChildWindow] # QTBUG-69160 @@ -16,8 +11,6 @@ windows # QTBUG-69162 windows-10 android -[testInputEvents] -rhel-7.4 [modalWindowPosition] # QTBUG-69161 android @@ -28,3 +21,8 @@ android android [modalWindowModallity] android +[enterLeaveOnWindowShowHide] +windows-10 +windows-11 +android +rhel diff --git a/tests/auto/gui/kernel/qwindow/CMakeLists.txt b/tests/auto/gui/kernel/qwindow/CMakeLists.txt index 23671cc385..5824989ac3 100644 --- a/tests/auto/gui/kernel/qwindow/CMakeLists.txt +++ b/tests/auto/gui/kernel/qwindow/CMakeLists.txt @@ -1,22 +1,51 @@ -# Generated from qwindow.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qwindow Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qwindow LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qwindow SOURCES tst_qwindow.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate ) +if(APPLE OR WIN32 OR QT_FEATURE_xcb) + qt_internal_add_test(tst_foreignwindow + LOWDPI + SOURCES + tst_foreignwindow.cpp + LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + ) + + if(APPLE) + enable_language(OBJCXX) + set_source_files_properties(tst_foreignwindow.cpp PROPERTIES LANGUAGE OBJCXX) + set_property(TARGET tst_foreignwindow PROPERTY PROPERTY MACOSX_BUNDLE TRUE) + endif() + + if(QT_FEATURE_xcb) + target_link_libraries(tst_foreignwindow PRIVATE XCB::XCB) + endif() +endif() + ## Scopes: ##################################################################### qt_internal_extend_target(tst_qwindow CONDITION QT_FEATURE_dynamicgl AND WIN32 - PUBLIC_LIBRARIES + LIBRARIES user32 ) diff --git a/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp new file mode 100644 index 0000000000..fdb1b333ef --- /dev/null +++ b/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp @@ -0,0 +1,196 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> + +#include <QtCore/qloggingcategory.h> +#include <private/qguiapplication_p.h> +#include <qpa/qplatformintegration.h> + +#include "../../../../shared/nativewindow.h" + +class tst_ForeignWindow: public QObject +{ + Q_OBJECT + +private slots: + void initTestCase() + { + auto *platformIntegration = QGuiApplicationPrivate::platformIntegration(); + if (!platformIntegration->hasCapability(QPlatformIntegration::ForeignWindows)) + QSKIP("This platform does not support foreign windows"); + } + + void fromWinId(); + void initialState(); + + void embedForeignWindow(); + void embedInForeignWindow(); + + void destroyExplicitly(); + void destroyWhenParentIsDestroyed(); +}; + +void tst_ForeignWindow::fromWinId() +{ + NativeWindow nativeWindow; + QVERIFY(nativeWindow); + + std::unique_ptr<QWindow> foreignWindow(QWindow::fromWinId(nativeWindow)); + QVERIFY(foreignWindow); + QVERIFY(foreignWindow->flags().testFlag(Qt::ForeignWindow)); + QVERIFY(foreignWindow->handle()); + + // fromWinId does not take (exclusive) ownership of the native window, + // so deleting the foreign window should not be a problem/cause crashes. + foreignWindow.reset(); +} + +void tst_ForeignWindow::initialState() +{ + NativeWindow nativeWindow; + QVERIFY(nativeWindow); + + // A foreign window can be used to embed a Qt UI in a foreign window hierarchy, + // in which case the foreign window merely acts as a parent and should not be + // modified, or to embed a foreign window in a Qt UI, in which case the foreign + // window must to be able to re-parent, move, resize, show, etc, so that the + // containing Qt UI can treat it as any other window. + + // At the point of creation though, we don't know what the foreign window + // will be used for, so the platform should not assume it can modify the + // window. Any properties set on the native window should persist past + // creation of the foreign window. + + const QRect initialGeometry(123, 456, 321, 654); + nativeWindow.setGeometry(initialGeometry); + QTRY_COMPARE(nativeWindow.geometry(), initialGeometry); + + std::unique_ptr<QWindow> foreignWindow(QWindow::fromWinId(nativeWindow)); + QCOMPARE(nativeWindow.geometry(), initialGeometry); + + // For extra bonus points, the foreign window should actually + // reflect the state of the native window. + QCOMPARE(foreignWindow->geometry(), initialGeometry); +} + +void tst_ForeignWindow::embedForeignWindow() +{ + // A foreign window embedded into a Qt UI requires that the rest of Qt + // is to be able to treat the foreign child window as any other window + // that it can show, hide, stack, and move around. + + QWindow parentWindow; + + NativeWindow nativeWindow; + QVERIFY(nativeWindow); + + // As a prerequisite to that, we must be able to reparent the foreign window + std::unique_ptr<QWindow> foreignWindow(QWindow::fromWinId(nativeWindow)); + foreignWindow->setParent(&parentWindow); + QTRY_COMPARE(nativeWindow.parentWinId(), parentWindow.winId()); + + // FIXME: This test is flakey on Linux. Figure out why +#if !defined(Q_OS_LINUX) + foreignWindow->setParent(nullptr); + QTRY_VERIFY(nativeWindow.parentWinId() != parentWindow.winId()); +#endif +} + +void tst_ForeignWindow::embedInForeignWindow() +{ + // When a foreign window is used as a container to embed a Qt UI + // in a foreign window hierarchy, the foreign window merely acts + // as a parent, and should not be modified. + + { + // At a minimum, we must be able to reparent into the window + NativeWindow nativeWindow; + QVERIFY(nativeWindow); + + std::unique_ptr<QWindow> foreignWindow(QWindow::fromWinId(nativeWindow)); + + QWindow embeddedWindow; + embeddedWindow.setParent(foreignWindow.get()); + QTRY_VERIFY(nativeWindow.isParentOf(embeddedWindow.winId())); + } + + { + // The foreign window's native window should not be reparent as a + // result of creating the foreign window, adding and removing children, + // or destroying the foreign window. + + NativeWindow topLevelNativeWindow; + NativeWindow childNativeWindow; + childNativeWindow.setParent(topLevelNativeWindow); + QVERIFY(topLevelNativeWindow.isParentOf(childNativeWindow)); + + std::unique_ptr<QWindow> foreignWindow(QWindow::fromWinId(childNativeWindow)); + QVERIFY(topLevelNativeWindow.isParentOf(childNativeWindow)); + + QWindow embeddedWindow; + embeddedWindow.setParent(foreignWindow.get()); + QTRY_VERIFY(childNativeWindow.isParentOf(embeddedWindow.winId())); + QVERIFY(topLevelNativeWindow.isParentOf(childNativeWindow)); + + embeddedWindow.setParent(nullptr); + QVERIFY(topLevelNativeWindow.isParentOf(childNativeWindow)); + + foreignWindow.reset(); + QVERIFY(topLevelNativeWindow.isParentOf(childNativeWindow)); + } +} + +void tst_ForeignWindow::destroyExplicitly() +{ + NativeWindow nativeWindow; + QVERIFY(nativeWindow); + + std::unique_ptr<QWindow> foreignWindow(QWindow::fromWinId(nativeWindow)); + QVERIFY(foreignWindow->handle()); + + // Explicitly destroying a foreign window is a no-op, as + // the documentation claims that it "releases the native + // platform resources associated with this window.", which + // is not technically true for foreign windows. + auto *windowHandleBeforeDestroy = foreignWindow->handle(); + foreignWindow->destroy(); + QCOMPARE(foreignWindow->handle(), windowHandleBeforeDestroy); +} + +void tst_ForeignWindow::destroyWhenParentIsDestroyed() +{ + QWindow parentWindow; + + NativeWindow nativeWindow; + QVERIFY(nativeWindow); + + std::unique_ptr<QWindow> foreignWindow(QWindow::fromWinId(nativeWindow)); + foreignWindow->setParent(&parentWindow); + QTRY_COMPARE(nativeWindow.parentWinId(), parentWindow.winId()); + + // Reparenting into a window will result in creating it + QVERIFY(parentWindow.handle()); + + parentWindow.show(); + QVERIFY(QTest::qWaitForWindowExposed(&parentWindow)); + + // Destroying the parent window of the foreign window results + // in destroying the foreign window as well, as the foreign + // window no longer has a parent it can be embedded in. + QVERIFY(foreignWindow->handle()); + parentWindow.destroy(); + QVERIFY(!foreignWindow->handle()); + + // But the foreign window can be recreated again, and will + // continue to be a native child of the parent window. + foreignWindow->create(); + QVERIFY(foreignWindow->handle()); + QTRY_COMPARE(nativeWindow.parentWinId(), parentWindow.winId()); + + parentWindow.show(); + QVERIFY(QTest::qWaitForWindowExposed(&parentWindow)); +} + +#include <tst_foreignwindow.moc> +QTEST_MAIN(tst_ForeignWindow) diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 1cf0c43d98..227fd77e1a 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qrasterwindow.h> #include <qpa/qwindowsysteminterface.h> @@ -7,6 +7,7 @@ #include <qpa/qplatformwindow.h> #include <private/qguiapplication_p.h> #include <private/qhighdpiscaling_p.h> +#include <private/qwindow_p.h> #include <QtGui/QPainter> #include <QTest> @@ -22,6 +23,12 @@ Q_LOGGING_CATEGORY(lcTests, "qt.gui.tests") +static bool isPlatformEglFS() +{ + static const bool isEglFS = !QGuiApplication::platformName().compare(QLatin1String("eglfs"), Qt::CaseInsensitive); + return isEglFS; +} + class tst_QWindow: public QObject { Q_OBJECT @@ -30,6 +37,7 @@ private slots: void create(); void setParent(); void setVisible(); + void setVisibleThenCreate(); void setVisibleFalseDoesNotCreateWindow(); void eventOrderOnShow(); void paintEvent(); @@ -70,6 +78,7 @@ private slots: void modalWithChildWindow(); void modalWindowModallity(); void modalWindowPosition(); + void modalCloseWhileBlocked(); #ifndef QT_NO_CURSOR void modalWindowEnterEventOnHide_QTBUG35109(); void spuriousMouseMove(); @@ -86,6 +95,15 @@ private slots: void keepPendingUpdateRequests(); void activateDeactivateEvent(); void qobject_castOnDestruction(); + void touchToMouseTranslationByPopup(); + void stateChangeSignal(); +#ifndef QT_NO_CURSOR + void enterLeaveOnWindowShowHide_data(); + void enterLeaveOnWindowShowHide(); +#endif + void windowExposedAfterReparent(); + void childEvents(); + void parentEvents(); private: QPoint m_availableTopLeft; @@ -96,8 +114,17 @@ private: QInputDevice::Capability::Position | QInputDevice::Capability::MouseEmulation); }; +static bool isPlatformWayland() +{ + return QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive); +} + void tst_QWindow::initTestCase() { +#ifdef Q_OS_ANDROID + if (QNativeInterface::QAndroidApplication::sdkVersion() == 33) + QSKIP("Is flaky on Android 13 / RHEL 8.6 and 8.8 (QTQAINFRA-5606)"); +#endif // Size of reference window, 200 for < 2000, scale up for larger screens // to avoid Windows warnings about minimum size for decorated windows. int width = 200; @@ -107,6 +134,10 @@ void tst_QWindow::initTestCase() if (screenWidth > 2000) width = 100 * ((screenWidth + 500) / 1000); m_testWindowSize = QSize(width, width); + + // Make sure test runs consistently on all compositors by force-disabling window decorations + if (isPlatformWayland()) + qputenv("QT_WAYLAND_DISABLE_WINDOWDECORATION", "1"); } void tst_QWindow::cleanup() @@ -219,6 +250,40 @@ void tst_QWindow::setVisible() QVERIFY(QTest::qWaitForWindowExposed(&i)); } +class SurfaceCreatedWindow : public QWindow +{ + Q_OBJECT +public: + using QWindow::QWindow; + + bool eventFilter(QObject *o, QEvent *e) override + { + if (e->type() == QEvent::PlatformSurface) { + auto type = static_cast<QPlatformSurfaceEvent*>(e)->surfaceEventType(); + if (type == QPlatformSurfaceEvent::SurfaceCreated) + ++surfaceCreatedEvents; + } + return QWindow::eventFilter(o, e); + } + + int surfaceCreatedEvents = 0; +}; + +void tst_QWindow::setVisibleThenCreate() +{ + QWindow parent; + parent.setObjectName("Parent"); + SurfaceCreatedWindow child(&parent); + child.installEventFilter(&child); + child.setObjectName("Child"); + child.setVisible(true); + child.create(); + QCOMPARE(child.surfaceCreatedEvents, 1); + parent.setVisible(true); + QCOMPARE(child.surfaceCreatedEvents, 1); + QVERIFY(QTest::qWaitForWindowExposed(&child)); +} + void tst_QWindow::setVisibleFalseDoesNotCreateWindow() { QWindow w; @@ -286,13 +351,6 @@ public: m_received[event->type()]++; m_order << event->type(); switch (event->type()) { - case QEvent::Expose: -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - m_exposeRegion = static_cast<QExposeEvent *>(event)->region(); -QT_WARNING_POP - break; - case QEvent::PlatformSurface: m_surfaceventType = static_cast<QPlatformSurfaceEvent *>(event)->surfaceEventType(); break; @@ -322,11 +380,6 @@ QT_WARNING_POP return m_order.indexOf(type); } - QRegion exposeRegion() const - { - return m_exposeRegion; - } - QPlatformSurfaceEvent::SurfaceEventType surfaceEventType() const { return m_surfaceventType; @@ -338,7 +391,6 @@ QT_WARNING_POP private: QHash<QEvent::Type, int> m_received; QList<QEvent::Type> m_order; - QRegion m_exposeRegion; QPlatformSurfaceEvent::SurfaceEventType m_surfaceventType; }; @@ -430,11 +482,16 @@ void tst_QWindow::resizeEventAfterResize() // Make sure we get a resizeEvent after calling resize window.resize(m_testWindowSize); + if (isPlatformEglFS()) + QEXPECT_FAIL("", "eglfs windows are fullscreen by default.", Continue); + QTRY_COMPARE(window.received(QEvent::Resize), 2); } void tst_QWindow::exposeEventOnShrink_QTBUG54040() { + if (isPlatformEglFS()) + QSKIP("", "eglfs windows are fullscreen by default.", Continue); Window window; window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); window.setTitle(QTest::currentTestFunction()); @@ -498,13 +555,11 @@ static QString msgRectMismatch(const QRect &r1, const QRect &r2) return result; } -static bool isPlatformWayland() -{ - return QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive); -} - void tst_QWindow::positioning() { +#ifdef Q_OS_ANDROID + QSKIP("Fails on Android. QTBUG-105201"); +#endif if (!QGuiApplicationPrivate::platformIntegration()->hasCapability( QPlatformIntegration::NonFullScreenWindows)) { QSKIP("This platform does not support non-fullscreen windows"); @@ -526,9 +581,8 @@ void tst_QWindow::positioning() QCOMPARE(window.geometry(), geometry); // explicitly use non-fullscreen show. show() can be fullscreen on some platforms window.showNormal(); - QCoreApplication::processEvents(); - QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(QTest::qWaitForWindowActive(&window)); QMargins originalMargins = window.frameMargins(); @@ -620,6 +674,8 @@ void tst_QWindow::childWindowPositioning_data() void tst_QWindow::childWindowPositioning() { + if (isPlatformEglFS()) + QSKIP("eglfs does not support child windows."); const QPoint topLeftOrigin(0, 0); ColoredWindow topLevelWindowFirst(Qt::green); @@ -722,7 +778,7 @@ void tst_QWindow::stateChange() // explicitly use non-fullscreen show. show() can be fullscreen on some platforms window.showNormal(); QVERIFY(QTest::qWaitForWindowExposed(&window)); - for (Qt::WindowState state : qAsConst(stateSequence)) { + for (Qt::WindowState state : std::as_const(stateSequence)) { window.setWindowState(state); QCoreApplication::processEvents(); } @@ -796,16 +852,6 @@ void tst_QWindow::isExposed() QTRY_VERIFY(window.received(QEvent::Expose) > 0); QTRY_VERIFY(window.isExposed()); -#ifndef Q_OS_WIN - // This is a top-level window so assuming it is completely exposed, the - // expose region must be (0, 0), (width, height). If this is not the case, - // the platform plugin is sending expose events with a region in an - // incorrect coordinate system. - QRect r = window.exposeRegion().boundingRect(); - r = QRect(window.mapToGlobal(r.topLeft()), r.size()); - QCOMPARE(r, window.geometry()); -#endif - window.hide(); QCoreApplication::processEvents(); @@ -950,6 +996,9 @@ public: if (spinLoopWhenPressed) QCoreApplication::processEvents(); } + if (closeOnTap) + this->close(); + } void mouseReleaseEvent(QMouseEvent *event) override { @@ -1006,7 +1055,7 @@ public: } touchEventType = event->type(); QList<QTouchEvent::TouchPoint> points = event->points(); - for (int i = 0; i < points.count(); ++i) { + for (int i = 0; i < points.size(); ++i) { const auto &point = points.at(i); switch (point.state()) { case QEventPoint::State::Pressed: @@ -1017,6 +1066,8 @@ public: touchPressLocalPos = point.position(); touchPressGlobalPos = point.globalPosition(); } + if (closeOnTap) + this->close(); break; case QEventPoint::State::Released: ++touchReleasedCount; @@ -1073,6 +1124,8 @@ public: const QPointingDevice *mouseDevice = nullptr; const QPointingDevice *touchDevice = nullptr; + + bool closeOnTap = false; }; static void simulateMouseClick(QWindow *target, const QPointF &local, const QPointF &global) @@ -1456,6 +1509,7 @@ void tst_QWindow::touchCancelWithTouchToMouse() void tst_QWindow::touchInterruptedByPopup() { InputTestWindow window; + window.setObjectName("main"); window.setTitle(QLatin1String(QTest::currentTestFunction())); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize)); window.show(); @@ -1476,6 +1530,7 @@ void tst_QWindow::touchInterruptedByPopup() // Launch a popup window InputTestWindow popup; + window.setObjectName("popup"); popup.setFlags(Qt::Popup); popup.setModality(Qt::WindowModal); popup.resize(m_testWindowSize / 2); @@ -1498,9 +1553,6 @@ void tst_QWindow::touchInterruptedByPopup() QWindowSystemInterface::handleTouchEvent(&window, touchDevice, points); QCoreApplication::processEvents(); QTRY_COMPARE(window.touchReleasedCount, 0); - - // Due to temporary fix for QTBUG-37371: the original window should receive a TouchCancel - QTRY_COMPARE(window.touchEventType, QEvent::TouchCancel); } void tst_QWindow::orientation() @@ -1519,7 +1571,7 @@ void tst_QWindow::orientation() QSignalSpy spy(&window, SIGNAL(contentOrientationChanged(Qt::ScreenOrientation))); window.reportContentOrientationChange(Qt::LandscapeOrientation); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } void tst_QWindow::sizes() @@ -1538,40 +1590,58 @@ void tst_QWindow::sizes() QCOMPARE(window.minimumHeight(), 0); QCOMPARE(window.minimumSize(), QSize(10, 0)); QCOMPARE(window.maximumSize(), oldMaximum); - QCOMPARE(minimumWidthSpy.count(), 1); - QCOMPARE(minimumHeightSpy.count(), 0); - QCOMPARE(maximumWidthSpy.count(), 0); - QCOMPARE(maximumHeightSpy.count(), 0); + QCOMPARE(minimumWidthSpy.size(), 1); + QCOMPARE(minimumHeightSpy.size(), 0); + QCOMPARE(maximumWidthSpy.size(), 0); + QCOMPARE(maximumHeightSpy.size(), 0); window.setMinimumHeight(10); QCOMPARE(window.minimumWidth(), 10); QCOMPARE(window.minimumHeight(), 10); QCOMPARE(window.minimumSize(), QSize(10, 10)); QCOMPARE(window.maximumSize(), oldMaximum); - QCOMPARE(minimumWidthSpy.count(), 1); - QCOMPARE(minimumHeightSpy.count(), 1); - QCOMPARE(maximumWidthSpy.count(), 0); - QCOMPARE(maximumHeightSpy.count(), 0); + QCOMPARE(minimumWidthSpy.size(), 1); + QCOMPARE(minimumHeightSpy.size(), 1); + QCOMPARE(maximumWidthSpy.size(), 0); + QCOMPARE(maximumHeightSpy.size(), 0); window.setMaximumWidth(100); QCOMPARE(window.maximumWidth(), 100); QCOMPARE(window.maximumHeight(), oldMaximum.height()); QCOMPARE(window.minimumSize(), QSize(10, 10)); QCOMPARE(window.maximumSize(), QSize(100, oldMaximum.height())); - QCOMPARE(minimumWidthSpy.count(), 1); - QCOMPARE(minimumHeightSpy.count(), 1); - QCOMPARE(maximumWidthSpy.count(), 1); - QCOMPARE(maximumHeightSpy.count(), 0); + QCOMPARE(minimumWidthSpy.size(), 1); + QCOMPARE(minimumHeightSpy.size(), 1); + QCOMPARE(maximumWidthSpy.size(), 1); + QCOMPARE(maximumHeightSpy.size(), 0); window.setMaximumHeight(100); QCOMPARE(window.maximumWidth(), 100); QCOMPARE(window.maximumHeight(), 100); QCOMPARE(window.minimumSize(), QSize(10, 10)); QCOMPARE(window.maximumSize(), QSize(100, 100)); - QCOMPARE(minimumWidthSpy.count(), 1); - QCOMPARE(minimumHeightSpy.count(), 1); - QCOMPARE(maximumWidthSpy.count(), 1); - QCOMPARE(maximumHeightSpy.count(), 1); + QCOMPARE(minimumWidthSpy.size(), 1); + QCOMPARE(minimumHeightSpy.size(), 1); + QCOMPARE(maximumWidthSpy.size(), 1); + QCOMPARE(maximumHeightSpy.size(), 1); + + // test if min and max limits will change the size + QVERIFY(window.minimumWidth() < 50 && window.maximumWidth() > 80); + QVERIFY(window.minimumHeight() < 50 && window.maximumHeight() > 80); + window.resize(50, 50); + QCOMPARE(window.size(), QSize(50, 50)); + window.setMinimumSize(QSize(60, 60)); + QCOMPARE(window.size(), QSize(60, 60)); + window.resize(80, 80); + window.setMaximumSize(QSize(70, 70)); + QCOMPARE(window.size(), QSize(70, 70)); + + // QTBUG-113233 + // test for an invalid min/max pair + window.setMinimumSize(QSize(80, 80)); // current maximumSize = QSize(70, 70) + QCOMPARE(window.size(), QSize(70, 70)); + window.setMaximumSize(QSize(90, 90)); + QCOMPARE(window.size(), QSize(80, 80)); } class CloseOnCloseEventWindow : public QWindow @@ -1803,25 +1873,25 @@ void tst_QWindow::windowModality() QCOMPARE(window.modality(), Qt::NonModal); window.setModality(Qt::NonModal); QCOMPARE(window.modality(), Qt::NonModal); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); window.setModality(Qt::WindowModal); QCOMPARE(window.modality(), Qt::WindowModal); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); window.setModality(Qt::WindowModal); QCOMPARE(window.modality(), Qt::WindowModal); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); window.setModality(Qt::ApplicationModal); QCOMPARE(window.modality(), Qt::ApplicationModal); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); window.setModality(Qt::ApplicationModal); QCOMPARE(window.modality(), Qt::ApplicationModal); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); window.setModality(Qt::NonModal); QCOMPARE(window.modality(), Qt::NonModal); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); } void tst_QWindow::inputReentrancy() @@ -2004,32 +2074,32 @@ void tst_QWindow::visibility() QVERIFY(window.isVisible()); QVERIFY(window.visibility() != QWindow::Hidden); QVERIFY(window.visibility() != QWindow::AutomaticVisibility); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); spy.clear(); window.setVisibility(QWindow::Hidden); QVERIFY(!window.isVisible()); QCOMPARE(window.visibility(), QWindow::Hidden); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); spy.clear(); window.setVisibility(QWindow::FullScreen); QVERIFY(window.isVisible()); QCOMPARE(window.windowState(), Qt::WindowFullScreen); QCOMPARE(window.visibility(), QWindow::FullScreen); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QTRY_COMPARE(window.lastReceivedWindowState, Qt::WindowFullScreen); spy.clear(); window.setWindowState(Qt::WindowNoState); QCOMPARE(window.visibility(), QWindow::Windowed); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QTRY_COMPARE(window.lastReceivedWindowState, Qt::WindowNoState); spy.clear(); window.setVisible(false); QCOMPARE(window.visibility(), QWindow::Hidden); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); spy.clear(); } @@ -2076,8 +2146,10 @@ void tst_QWindow::initialSize() w.setTitle(QLatin1String(QTest::currentTestFunction())); w.setWidth(m_testWindowSize.width()); w.showNormal(); - if (isPlatformWayland()) - QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-66818.", Abort); + + if (isPlatformEglFS()) + QEXPECT_FAIL("", "eglfs windows are fullscreen by default.", Continue); + QTRY_COMPARE(w.width(), m_testWindowSize.width()); QTRY_VERIFY(w.height() > 0); } @@ -2089,6 +2161,8 @@ void tst_QWindow::initialSize() w.showNormal(); const QSize expectedSize = testSize; + if (isPlatformEglFS()) + QEXPECT_FAIL("", "eglfs windows are fullscreen by default.", Continue); QTRY_COMPARE(w.size(), expectedSize); } } @@ -2253,6 +2327,9 @@ void tst_QWindow::modalWindowModallity() void tst_QWindow::modalWindowPosition() { + if (isPlatformWayland()) + QSKIP("Window position not queryable on Wayland"); + QWindow window; window.setTitle(QLatin1String(QTest::currentTestFunction())); window.setGeometry(QRect(m_availableTopLeft + QPoint(100, 100), m_testWindowSize)); @@ -2261,11 +2338,29 @@ void tst_QWindow::modalWindowPosition() window.setModality(Qt::WindowModal); window.show(); QVERIFY(QTest::qWaitForWindowExposed(&window)); - if (isPlatformWayland()) - QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100888.", Abort); + + if (isPlatformEglFS()) + QEXPECT_FAIL("", "eglfs windows are fullscreen by default.", Continue); + QCOMPARE(window.geometry(), origGeo); } +void tst_QWindow::modalCloseWhileBlocked() +{ + QWindow first; + first.setModality(Qt::ApplicationModal); + first.show(); + QVERIFY(QTest::qWaitForWindowExposed(&first)); + + QWindow second; + second.setModality(Qt::ApplicationModal); + second.show(); + QVERIFY(QTest::qWaitForWindowExposed(&first)); + + first.close(); + QTRY_VERIFY(!first.isVisible()); +} + #ifndef QT_NO_CURSOR void tst_QWindow::modalWindowEnterEventOnHide_QTBUG35109() { @@ -2275,6 +2370,9 @@ void tst_QWindow::modalWindowEnterEventOnHide_QTBUG35109() if (isPlatformOffscreenOrMinimal()) QSKIP("Can't test window focusing on offscreen/minimal"); + if (isPlatformEglFS()) + QSKIP("QCursor::setPos() is not supported on this platform"); + const QPoint center = QGuiApplication::primaryScreen()->availableGeometry().center(); const int childOffset = 16; @@ -2455,6 +2553,8 @@ void tst_QWindow::spuriousMouseMove() QSKIP("No enter events sent"); if (platformName == QLatin1String("wayland")) QSKIP("Setting mouse cursor position is not possible on Wayland"); + if (isPlatformEglFS()) + QSKIP("QCursor::setPos() is not supported on this platform"); const QRect screenGeometry = QGuiApplication::primaryScreen()->geometry(); const QPoint center = screenGeometry.center(); QCursor::setPos(center); @@ -2541,8 +2641,6 @@ void tst_QWindow::requestUpdate() QCoreApplication::processEvents(); QTRY_VERIFY(window.isExposed()); - if (isPlatformWayland()) - QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100889.", Abort); QCOMPARE(window.received(QEvent::UpdateRequest), 0); window.requestUpdate(); @@ -2732,6 +2830,395 @@ void tst_QWindow::qobject_castOnDestruction() }); } +void tst_QWindow::touchToMouseTranslationByPopup() +{ + InputTestWindow window; + window.setTitle(QLatin1String(QTest::currentTestFunction())); + window.ignoreTouch = true; + window.setGeometry(QRect(m_availableTopLeft, m_testWindowSize)); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + InputTestWindow popupWindow; + popupWindow.setGeometry(QRect(m_availableTopLeft + QPoint(20, 20), + QSize(m_testWindowSize.width(), m_testWindowSize.height() / 2))); + popupWindow.setFlag(Qt::Popup); + popupWindow.setTransientParent(&window); + popupWindow.ignoreTouch = true; + popupWindow.closeOnTap = true; + popupWindow.show(); + QVERIFY(QTest::qWaitForWindowExposed(&popupWindow)); + + QTest::touchEvent(&popupWindow, touchDevice).press(0, {1, 1}, &window); + QVERIFY(!popupWindow.isVisible()); + + // Omit touchpoint 0: because the popup was closed, touchpoint0.release is not sent. + const QPoint tp1(50, 1); + QTest::touchEvent(&window, touchDevice).press(1, tp1, &window); + QTRY_COMPARE(window.mousePressButton, int(Qt::LeftButton)); + QTest::touchEvent(&window, touchDevice).release(1, tp1, &window); + QTRY_COMPARE(window.mouseReleaseButton, int(Qt::LeftButton)); +} + +// Test that windowStateChanged is not emitted on noop change (QTBUG-102478) +void tst_QWindow::stateChangeSignal() +{ + // Test only for Windows, Linux and macOS +#if !defined(Q_OS_LINUX) && !defined(Q_OS_WINDOWS) && !defined(Q_OS_DARWIN) + QSKIP("Singular windowStateChanged signal emission is guaranteed for Linux, Windows and macOS only.\n" + "On other operating systems, the signal may be emitted twice."); +#endif + QWindow w; + Q_ASSERT(connect (&w, &QWindow::windowStateChanged, [](Qt::WindowState s){qCDebug(lcTests) << "State change to" << s;})); + QSignalSpy spy(&w, SIGNAL(windowStateChanged(Qt::WindowState))); + unsigned short signalCount = 0; + QList<Qt::WindowState> effectiveStates; + Q_ASSERT(connect(&w, &QWindow::windowStateChanged, [&effectiveStates](Qt::WindowState state) + { effectiveStates.append(state); })); + // Part 1: + // => test signal emission on programmatic state changes + QCOMPARE(w.windowState(), Qt::WindowNoState); + // - wait for target state to be set + // - wait for signal spy to have reached target count + // - extract state from signal and compare to target +#define CHECK_STATE(State)\ + QTRY_VERIFY(QTest::qWaitFor([&w](){return (w.windowState() == State); }));\ + CHECK_SIGNAL(State) +#define CHECK_SIGNAL(State)\ + QTRY_COMPARE(spy.count(), signalCount);\ + if (signalCount > 0) {\ + QVariantList list = spy.at(signalCount - 1).toList();\ + QCOMPARE(list.count(), 1);\ + bool ok;\ + const int stateInt = list.at(0).toInt(&ok);\ + QVERIFY(ok);\ + const Qt::WindowState newState = static_cast<Qt::WindowState>(stateInt);\ + QCOMPARE(newState, State);\ + } + // Check initialization + CHECK_STATE(Qt::WindowNoState); + // showMaximized after init + // expected behavior: signal emitted once with state == WindowMaximized + ++signalCount; + w.showMaximized(); + CHECK_STATE(Qt::WindowMaximized); + // setWindowState to normal + // expected behavior: signal emitted once with state == WindowNoState + ++signalCount; + w.setWindowState(Qt::WindowNoState); + CHECK_STATE(Qt::WindowNoState); + // redundant setWindowState to normal - except windows, where the no-op is counted + // expected behavior: No emits. + // On Windows, a no-op state change causes a no-op resize and repaint, leading to a + // no-op state change and singal emission. +#ifdef Q_OS_WINDOWS + ++signalCount; + ++signalCount; +#endif + w.setWindowState(Qt::WindowNoState); + CHECK_STATE(Qt::WindowNoState); + // setWindowState to minimized + // expected behavior: signal emitted once with state == WindowMinimized + ++signalCount; + w.showMinimized(); + CHECK_STATE(Qt::WindowMinimized); + // setWindowState to Normal + // expected behavior: signal emitted once with state == WindowNoState + ++signalCount; + w.showNormal(); + CHECK_STATE(Qt::WindowNoState); + /* + - Testcase showFullScreen is omitted: Depending on window manager, + WindowFullScreen can be mapped to WindowMaximized + - Transition from WindowMinimized to WindowMaximized is omitted: + WindowNoState to WindowMaximized + */ + // Part 2: + // => test signal emission on simulated user interaction + // To test the code path, inject state change events into the QPA event queue. + // Test the signal emission only, not the window's actual visible state. + + // Flush pending events and clear + QCoreApplication::processEvents(); + spy.clear(); + effectiveStates.clear(); + signalCount = 0; + // Maximize window + QWindowSystemInterface::handleWindowStateChanged(&w, Qt::WindowMaximized, w.windowState()); + ++signalCount; + CHECK_SIGNAL(Qt::WindowMaximized); + // Normalize window + QWindowSystemInterface::handleWindowStateChanged(&w, Qt::WindowNoState, w.windowState()); + ++signalCount; + CHECK_SIGNAL(Qt::WindowNoState); + // Minimize window + QWindowSystemInterface::handleWindowStateChanged(&w, Qt::WindowMinimized, w.windowState()); + ++signalCount; + CHECK_SIGNAL(Qt::WindowMinimized); +} + +#ifndef QT_NO_CURSOR +void tst_QWindow::enterLeaveOnWindowShowHide_data() +{ + QTest::addColumn<Qt::WindowType>("windowType"); + QTest::addRow("dialog") << Qt::Dialog; + QTest::addRow("popup") << Qt::Popup; +} + +/*! + Verify that we get enter and leave events if the window under the mouse + opens and closes a modal dialog or popup. QWindow might get multiple + events in a row, as the various QPA plugins need to use different techniques + to synthesize events if the native platform doesn't provide them for us. +*/ +void tst_QWindow::enterLeaveOnWindowShowHide() +{ + if (isPlatformWayland()) + QSKIP("Can't set cursor position and qWaitForWindowActive on Wayland"); + + if (isPlatformEglFS()) + QSKIP("QCursor::setPos() is not supported on this platform"); + + QFETCH(Qt::WindowType, windowType); + + class Window : public QWindow + { + public: + int numEnterEvents = 0; + int numLeaveEvents = 0; + QPoint enterPosition; + protected: + bool event(QEvent *e) override + { + switch (e->type()) { + case QEvent::Enter: + ++numEnterEvents; + enterPosition = static_cast<QEnterEvent*>(e)->position().toPoint(); + break; + case QEvent::Leave: + ++numLeaveEvents; + break; + default: + break; + } + return QWindow::event(e); + } + }; + + int expectedEnter = 0; + int expectedLeave = 0; + + Window window; + const QRect screenGeometry = window.screen()->availableGeometry(); + const QPoint cursorPos = screenGeometry.topLeft() + QPoint(50, 50); + window.setGeometry(QRect(cursorPos - QPoint(50, 50), screenGeometry.size() / 4)); + QCursor::setPos(cursorPos); + + if (!QTest::qWaitFor([&]{ return window.geometry().contains(QCursor::pos()); })) + QSKIP("We can't move the cursor"); + + window.show(); + window.requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(&window)); + + ++expectedEnter; + QTRY_COMPARE_WITH_TIMEOUT(window.numEnterEvents, expectedEnter, 250); + QCOMPARE(window.enterPosition, window.mapFromGlobal(QCursor::pos())); + + QWindow secondary; + secondary.setFlag(windowType); + secondary.setModality(Qt::WindowModal); + secondary.setTransientParent(&window); + secondary.setPosition(cursorPos + QPoint(50, 50)); + secondary.show(); + QVERIFY(QTest::qWaitForWindowExposed(&secondary)); + ++expectedLeave; + QTRY_VERIFY(window.numLeaveEvents >= expectedLeave); + secondary.close(); + ++expectedEnter; + QTRY_VERIFY(window.numEnterEvents >= expectedEnter); + QCOMPARE(window.enterPosition, window.mapFromGlobal(QCursor::pos())); +} +#endif + +void tst_QWindow::windowExposedAfterReparent() +{ + QWindow parent; + QWindow child(&parent); + child.show(); + parent.show(); + + QVERIFY(QTest::qWaitForWindowExposed(&parent)); + QVERIFY(QTest::qWaitForWindowExposed(&child)); + + child.setParent(nullptr); + QCoreApplication::processEvents(); + QVERIFY(QTest::qWaitForWindowExposed(&child)); + + child.setParent(&parent); + QCoreApplication::processEvents(); + QVERIFY(QTest::qWaitForWindowExposed(&child)); +} + +struct ParentWindow : public QWindow +{ + bool event(QEvent *event) override + { + [&]() -> void { + if (event->type() == QEvent::ChildWindowAdded + || event->type() == QEvent::ChildWindowRemoved) { + // We should not receive child events after the window has been destructed + QVERIFY(this->isWindowType()); + + auto *parentWindow = this; + auto *childEvent = static_cast<QChildWindowEvent*>(event); + auto *childWindow = childEvent->child(); + + if (event->type() == QEvent::ChildWindowAdded) { + QVERIFY(childWindow->parent()); + QVERIFY(parentWindow->isAncestorOf(childWindow)); + if (childWindow->handle()) + QVERIFY(childWindow->handle()->parent() == parentWindow->handle()); + + } else { + QVERIFY(!childWindow->parent()); + QVERIFY(!parentWindow->isAncestorOf(childWindow)); + if (childWindow->handle()) + QVERIFY(childWindow->handle()->parent() != parentWindow->handle()); + } + } + }(); + + return QWindow::event(event); + } +}; + +void tst_QWindow::childEvents() +{ + ParentWindow parent; + + { + // ChildAdded via constructor + QWindow constructorChild(&parent); + if (QTest::currentTestFailed()) return; + // ChildRemoved via destructor + } + + if (QTest::currentTestFailed()) return; + + // ChildAdded and ChildRemoved via setParent + QWindow child; + child.setParent(&parent); + if (QTest::currentTestFailed()) return; + child.setParent(nullptr); + if (QTest::currentTestFailed()) return; + + parent.create(); + child.create(); + + // ChildAdded and ChildRemoved after creation + child.setParent(&parent); + if (QTest::currentTestFailed()) return; + child.setParent(nullptr); + if (QTest::currentTestFailed()) return; +} + +struct ChildWindowPrivate; +struct ChildWindow : public QWindow +{ + ChildWindow(QWindow *parent = nullptr); +}; + +struct ChildWindowPrivate : public QWindowPrivate +{ + ChildWindowPrivate() : QWindowPrivate() + { + receiveParentEvents = true; + } +}; + +ChildWindow::ChildWindow(QWindow *parent) + : QWindow(*new ChildWindowPrivate, parent) +{} + +struct ParentEventTester : public QObject +{ + bool eventFilter(QObject *object, QEvent *event) override + { + [&]() -> void { + if (event->type() == QEvent::ParentWindowAboutToChange + || event->type() == QEvent::ParentWindowChange) { + // We should not receive parent events after the window has been destructed + QVERIFY(object->isWindowType()); + auto *window = static_cast<QWindow*>(object); + + if (event->type() == QEvent::ParentWindowAboutToChange) { + QVERIFY(window->parent() != nextExpectedParent); + if (window->handle()) { + QVERIFY(window->handle()->parent() != + (nextExpectedParent ? nextExpectedParent->handle() : nullptr)); + } + } else { + QVERIFY(window->parent() == nextExpectedParent); + if (window->handle()) { + QVERIFY(window->handle()->parent() == + (nextExpectedParent ? nextExpectedParent->handle() : nullptr)); + } + } + } + }(); + + return QObject::eventFilter(object, event); + } + + QWindow *nextExpectedParent = nullptr; +}; + + + +void tst_QWindow::parentEvents() +{ + QWindow parent; + + { + ParentEventTester tester; + + { + // We can't hook in early enough to get the parent change during + // QObject construction. + ChildWindow child(&parent); + + // But we can observe the one during destruction + child.installEventFilter(&tester); + tester.nextExpectedParent = nullptr; + } + } + if (QTest::currentTestFailed()) return; + + ParentEventTester tester; + ChildWindow child; + child.installEventFilter(&tester); + + tester.nextExpectedParent = &parent; + child.setParent(&parent); + if (QTest::currentTestFailed()) return; + + tester.nextExpectedParent = nullptr; + child.setParent(nullptr); + if (QTest::currentTestFailed()) return; + + parent.create(); + child.create(); + + tester.nextExpectedParent = &parent; + child.setParent(&parent); + if (QTest::currentTestFailed()) return; + + tester.nextExpectedParent = nullptr; + child.setParent(nullptr); + if (QTest::currentTestFailed()) return; +} + #include <tst_qwindow.moc> QTEST_MAIN(tst_QWindow) diff --git a/tests/auto/gui/math3d/CMakeLists.txt b/tests/auto/gui/math3d/CMakeLists.txt index 11c50163ad..a7f2a55aa1 100644 --- a/tests/auto/gui/math3d/CMakeLists.txt +++ b/tests/auto/gui/math3d/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from math3d.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause add_subdirectory(qquaternion) add_subdirectory(qvectornd) diff --git a/tests/auto/gui/math3d/qmatrixnxn/CMakeLists.txt b/tests/auto/gui/math3d/qmatrixnxn/CMakeLists.txt index 5c54bd6b95..22f581e9c8 100644 --- a/tests/auto/gui/math3d/qmatrixnxn/CMakeLists.txt +++ b/tests/auto/gui/math3d/qmatrixnxn/CMakeLists.txt @@ -1,14 +1,19 @@ -# Generated from qmatrixnxn.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qmatrixnxn Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qmatrixnxn LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qmatrixnxn SOURCES tst_qmatrixnxn.cpp - DEFINES - QT_DISABLE_DEPRECATED_BEFORE=0 - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp b/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp index 29c5248fe3..e761f8cb3c 100644 --- a/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp +++ b/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtCore/qmath.h> @@ -100,6 +100,7 @@ private slots: void rotate4x4_data(); void rotate4x4(); + void projectedRotate(); void normalMatrix_data(); void normalMatrix(); @@ -132,6 +133,11 @@ private slots: void properties(); void metaTypes(); + // Tests for deprecated APIs +#if QT_DEPRECATED_SINCE(6, 1) + void deprecatedMultiplications(); +#endif + private: static void setMatrix(QMatrix2x2& m, const float *values); static void setMatrixDirect(QMatrix2x2& m, const float *values); @@ -1969,12 +1975,7 @@ void tst_QMatrixNxN::scale4x4() } QVector3D v1(2.0f, 3.0f, -4.0f); - QVector3D v2 = m1 * v1; - QCOMPARE(v2.x(), (float)(2.0f * x)); - QCOMPARE(v2.y(), (float)(3.0f * y)); - QCOMPARE(v2.z(), (float)(-4.0f * z)); - - v2 = v1 * m1; + QVector3D v2 = m1.map(v1); QCOMPARE(v2.x(), (float)(2.0f * x)); QCOMPARE(v2.y(), (float)(3.0f * y)); QCOMPARE(v2.z(), (float)(-4.0f * z)); @@ -1993,7 +1994,7 @@ void tst_QMatrixNxN::scale4x4() QCOMPARE(v4.w(), (float)34.0f); QPoint p1(2, 3); - QPoint p2 = m1 * p1; + QPoint p2 = m1.map(p1); QCOMPARE(p2.x(), (int)(2.0f * x)); QCOMPARE(p2.y(), (int)(3.0f * y)); @@ -2002,7 +2003,7 @@ void tst_QMatrixNxN::scale4x4() QCOMPARE(p2.y(), (int)(3.0f * y)); QPointF p3(2.0f, 3.0f); - QPointF p4 = m1 * p3; + QPointF p4 = m1.map(p3); QCOMPARE(p4.x(), (float)(2.0f * x)); QCOMPARE(p4.y(), (float)(3.0f * y)); @@ -2115,7 +2116,7 @@ void tst_QMatrixNxN::translate4x4() } QVector3D v1(2.0f, 3.0f, -4.0f); - QVector3D v2 = m1 * v1; + QVector3D v2 = m1.map(v1); QCOMPARE(v2.x(), (float)(2.0f + x)); QCOMPARE(v2.y(), (float)(3.0f + y)); QCOMPARE(v2.z(), (float)(-4.0f + z)); @@ -2135,12 +2136,12 @@ void tst_QMatrixNxN::translate4x4() QCOMPARE(v6.w(), (float)34.0f); QPoint p1(2, 3); - QPoint p2 = m1 * p1; + QPoint p2 = m1.map(p1); QCOMPARE(p2.x(), (int)(2.0f + x)); QCOMPARE(p2.y(), (int)(3.0f + y)); QPointF p3(2.0f, 3.0f); - QPointF p4 = m1 * p3; + QPointF p4 = m1.map(p3); QCOMPARE(p4.x(), (float)(2.0f + x)); QCOMPARE(p4.y(), (float)(3.0f + y)); @@ -2342,10 +2343,10 @@ void tst_QMatrixNxN::rotate4x4() ROTATE4(2.0f, 3.0f, 0.0f, 1.0f, p1x, p1y, p1z, p1w); p1x /= p1w; p1y /= p1w; - p1z /= p1w; + Q_UNUSED(p1z); QVector3D v1(2.0f, 3.0f, -4.0f); - QVector3D v2 = m1 * v1; + QVector3D v2 = m1.map(v1); QVERIFY(qFuzzyCompare(v2.x(), v1x)); QVERIFY(qFuzzyCompare(v2.y(), v1y)); QVERIFY(qFuzzyCompare(v2.z(), v1z)); @@ -2365,12 +2366,12 @@ void tst_QMatrixNxN::rotate4x4() QVERIFY(qFuzzyCompare(v6.w(), v5w)); QPoint p1(2, 3); - QPoint p2 = m1 * p1; + QPoint p2 = m1.map(p1); QCOMPARE(p2.x(), qRound(p1x)); QCOMPARE(p2.y(), qRound(p1y)); QPointF p3(2.0f, 3.0f); - QPointF p4 = m1 * p3; + QPointF p4 = m1.map(p3); QVERIFY(qFuzzyCompare(float(p4.x()), p1x)); QVERIFY(qFuzzyCompare(float(p4.y()), p1y)); @@ -2383,6 +2384,22 @@ void tst_QMatrixNxN::rotate4x4() } } +void tst_QMatrixNxN::projectedRotate() +{ + QMatrix4x4 m1, m2; + const QPointF origin(1000, 1000); + + m1.translate(origin.x(), origin.y()); + m1.projectedRotate(60, 0, 1, 0, 0); + m1.translate(-origin.x(), -origin.y()); + + m2.translate(origin.x(), origin.y()); + m2.rotate(60, 0, 1, 0); + m2.translate(-origin.x(), -origin.y()); + + QCOMPARE(m1.toTransform(), m2.toTransform()); +} + static bool isSame(const QMatrix3x3& m1, const Matrix3& m2) { for (int row = 0; row < 3; ++row) { @@ -2604,11 +2621,11 @@ void tst_QMatrixNxN::ortho() { QMatrix4x4 m1; m1.ortho(QRect(0, 0, 300, 150)); - QPointF p1 = m1 * QPointF(0, 0); - QPointF p2 = m1 * QPointF(300, 0); - QPointF p3 = m1 * QPointF(0, 150); - QPointF p4 = m1 * QPointF(300, 150); - QVector3D p5 = m1 * QVector3D(300, 150, 1); + QPointF p1 = m1.map(QPointF(0, 0)); + QPointF p2 = m1.map(QPointF(300, 0)); + QPointF p3 = m1.map(QPointF(0, 150)); + QPointF p4 = m1.map(QPointF(300, 150)); + QVector3D p5 = m1.map(QVector3D(300, 150, 1)); QVERIFY(qFuzzyCompare(float(p1.x()), -1.0f)); QVERIFY(qFuzzyCompare(float(p1.y()), 1.0f)); QVERIFY(qFuzzyCompare(float(p2.x()), 1.0f)); @@ -2623,11 +2640,11 @@ void tst_QMatrixNxN::ortho() QMatrix4x4 m2; m2.ortho(QRectF(0, 0, 300, 150)); - p1 = m2 * QPointF(0, 0); - p2 = m2 * QPointF(300, 0); - p3 = m2 * QPointF(0, 150); - p4 = m2 * QPointF(300, 150); - p5 = m2 * QVector3D(300, 150, 1); + p1 = m2.map(QPointF(0, 0)); + p2 = m2.map(QPointF(300, 0)); + p3 = m2.map(QPointF(0, 150)); + p4 = m2.map(QPointF(300, 150)); + p5 = m2.map(QVector3D(300, 150, 1)); QVERIFY(qFuzzyCompare(float(p1.x()), -1.0f)); QVERIFY(qFuzzyCompare(float(p1.y()), 1.0f)); QVERIFY(qFuzzyCompare(float(p2.x()), 1.0f)); @@ -2642,11 +2659,11 @@ void tst_QMatrixNxN::ortho() QMatrix4x4 m3; m3.ortho(0, 300, 150, 0, -1, 1); - p1 = m3 * QPointF(0, 0); - p2 = m3 * QPointF(300, 0); - p3 = m3 * QPointF(0, 150); - p4 = m3 * QPointF(300, 150); - p5 = m3 * QVector3D(300, 150, 1); + p1 = m3.map(QPointF(0, 0)); + p2 = m3.map(QPointF(300, 0)); + p3 = m3.map(QPointF(0, 150)); + p4 = m3.map(QPointF(300, 150)); + p5 = m3.map(QVector3D(300, 150, 1)); QVERIFY(qFuzzyCompare(float(p1.x()), -1.0f)); QVERIFY(qFuzzyCompare(float(p1.y()), 1.0f)); QVERIFY(qFuzzyCompare(float(p2.x()), 1.0f)); @@ -2661,11 +2678,11 @@ void tst_QMatrixNxN::ortho() QMatrix4x4 m4; m4.ortho(0, 300, 150, 0, -2, 3); - p1 = m4 * QPointF(0, 0); - p2 = m4 * QPointF(300, 0); - p3 = m4 * QPointF(0, 150); - p4 = m4 * QPointF(300, 150); - p5 = m4 * QVector3D(300, 150, 1); + p1 = m4.map(QPointF(0, 0)); + p2 = m4.map(QPointF(300, 0)); + p3 = m4.map(QPointF(0, 150)); + p4 = m4.map(QPointF(300, 150)); + p5 = m4.map(QVector3D(300, 150, 1)); QVERIFY(qFuzzyCompare(float(p1.x()), -1.0f)); QVERIFY(qFuzzyCompare(float(p1.y()), 1.0f)); QVERIFY(qFuzzyCompare(float(p2.x()), 1.0f)); @@ -2693,11 +2710,11 @@ void tst_QMatrixNxN::frustum() { QMatrix4x4 m1; m1.frustum(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f); - QVector3D p1 = m1 * QVector3D(-1.0f, -1.0f, 1.0f); - QVector3D p2 = m1 * QVector3D(1.0f, -1.0f, 1.0f); - QVector3D p3 = m1 * QVector3D(-1.0f, 1.0f, 1.0f); - QVector3D p4 = m1 * QVector3D(1.0f, 1.0f, 1.0f); - QVector3D p5 = m1 * QVector3D(0.0f, 0.0f, 2.0f); + QVector3D p1 = m1.map(QVector3D(-1.0f, -1.0f, 1.0f)); + QVector3D p2 = m1.map(QVector3D(1.0f, -1.0f, 1.0f)); + QVector3D p3 = m1.map(QVector3D(-1.0f, 1.0f, 1.0f)); + QVector3D p4 = m1.map(QVector3D(1.0f, 1.0f, 1.0f)); + QVector3D p5 = m1.map(QVector3D(0.0f, 0.0f, 2.0f)); QVERIFY(qFuzzyCompare(p1.x(), -1.0f)); QVERIFY(qFuzzyCompare(p1.y(), -1.0f)); QVERIFY(qFuzzyCompare(p1.z(), -1.0f)); @@ -2729,11 +2746,11 @@ void tst_QMatrixNxN::perspective() { QMatrix4x4 m1; m1.perspective(45.0f, 1.0f, -1.0f, 1.0f); - QVector3D p1 = m1 * QVector3D(-1.0f, -1.0f, 1.0f); - QVector3D p2 = m1 * QVector3D(1.0f, -1.0f, 1.0f); - QVector3D p3 = m1 * QVector3D(-1.0f, 1.0f, 1.0f); - QVector3D p4 = m1 * QVector3D(1.0f, 1.0f, 1.0f); - QVector3D p5 = m1 * QVector3D(0.0f, 0.0f, 2.0f); + QVector3D p1 = m1.map(QVector3D(-1.0f, -1.0f, 1.0f)); + QVector3D p2 = m1.map(QVector3D(1.0f, -1.0f, 1.0f)); + QVector3D p3 = m1.map(QVector3D(-1.0f, 1.0f, 1.0f)); + QVector3D p4 = m1.map(QVector3D(1.0f, 1.0f, 1.0f)); + QVector3D p5 = m1.map(QVector3D(0.0f, 0.0f, 2.0f)); QVERIFY(qFuzzyCompare(p1.x(), 2.41421f)); QVERIFY(qFuzzyCompare(p1.y(), 2.41421f)); QVERIFY(qFuzzyCompare(p1.z(), -1.0f)); @@ -2799,25 +2816,25 @@ void tst_QMatrixNxN::flipCoordinates() { QMatrix4x4 m1; m1.flipCoordinates(); - QVector3D p1 = m1 * QVector3D(2, 3, 4); + QVector3D p1 = m1.map(QVector3D(2, 3, 4)); QVERIFY(p1 == QVector3D(2, -3, -4)); QMatrix4x4 m2; m2.scale(2.0f, 3.0f, 1.0f); m2.flipCoordinates(); - QVector3D p2 = m2 * QVector3D(2, 3, 4); + QVector3D p2 = m2.map(QVector3D(2, 3, 4)); QVERIFY(p2 == QVector3D(4, -9, -4)); QMatrix4x4 m3; m3.translate(2.0f, 3.0f, 1.0f); m3.flipCoordinates(); - QVector3D p3 = m3 * QVector3D(2, 3, 4); + QVector3D p3 = m3.map(QVector3D(2, 3, 4)); QVERIFY(p3 == QVector3D(4, 0, -3)); QMatrix4x4 m4; m4.rotate(90.0f, 0.0f, 0.0f, 1.0f); m4.flipCoordinates(); - QVector3D p4 = m4 * QVector3D(2, 3, 4); + QVector3D p4 = m4.map(QVector3D(2, 3, 4)); QVERIFY(p4 == QVector3D(3, 2, -4)); } @@ -3019,7 +3036,7 @@ void tst_QMatrixNxN::convertQTransform() QCOMPARE(p1.y(), 150.0 + 2.0); QMatrix4x4 m2(m1); - QPointF p2 = m2 * QPointF(100.0, 150.0); + QPointF p2 = m2.map(QPointF(100.0, 150.0)); QCOMPARE((double)p2.x(), 100.0 - 3.5); QCOMPARE((double)p2.y(), 150.0 + 2.0); QCOMPARE(m1, m2.toTransform()); @@ -3031,7 +3048,7 @@ void tst_QMatrixNxN::convertQTransform() QCOMPARE(p3.y(), -2.0 * 150.0); QMatrix4x4 m4(m3); - QPointF p4 = m4 * QPointF(100.0, 150.0); + QPointF p4 = m4.map(QPointF(100.0, 150.0)); QCOMPARE((double)p4.x(), 1.5 * 100.0); QCOMPARE((double)p4.y(), -2.0 * 150.0); QCOMPARE(m3, m4.toTransform()); @@ -3041,7 +3058,7 @@ void tst_QMatrixNxN::convertQTransform() QPointF p5 = m5.map(QPointF(100.0, 150.0)); QMatrix4x4 m6(m5); - QPointF p6 = m6 * QPointF(100.0, 150.0); + QPointF p6 = m6.map(QPointF(100.0, 150.0)); QVERIFY(qFuzzyCompare(float(p5.x()), float(p6.x()))); QVERIFY(qFuzzyCompare(float(p5.y()), float(p6.y()))); @@ -3291,9 +3308,9 @@ void tst_QMatrixNxN::properties() void tst_QMatrixNxN::metaTypes() { - QCOMPARE(QMetaType::type("QMatrix4x4"), int(QMetaType::QMatrix4x4)); + QCOMPARE(QMetaType::fromName("QMatrix4x4").id(), int(QMetaType::QMatrix4x4)); - QCOMPARE(QByteArray(QMetaType::typeName(QMetaType::QMatrix4x4)), + QCOMPARE(QByteArray(QMetaType(QMetaType::QMatrix4x4).name()), QByteArray("QMatrix4x4")); QVERIFY(QMetaType::isRegistered(QMetaType::QMatrix4x4)); @@ -3301,6 +3318,58 @@ void tst_QMatrixNxN::metaTypes() QCOMPARE(qMetaTypeId<QMatrix4x4>(), int(QMetaType::QMatrix4x4)); } +#if QT_DEPRECATED_SINCE(6, 1) +void tst_QMatrixNxN::deprecatedMultiplications() +{ + QMatrix4x4 m; + m.scale(1.0f, 2.0f, 3.0f); + // QMatrix4x4 and QVector3D + { + QVector3D v(4.0f, 5.0f, 6.0f); + { + // QMatrix4x4 * QVector3D + QT_IGNORE_DEPRECATIONS(const QVector3D v1 = m * v;) + const QVector3D v2 = m.map(v); + + QCOMPARE(v1.x(), v2.x()); + QCOMPARE(v1.y(), v2.y()); + QCOMPARE(v1.z(), v2.z()); + } + { + // QVector3D * QMatrix4x4 + QT_IGNORE_DEPRECATIONS(const QVector3D v1 = v * m;) + + QVector4D v4(v, 1.0); + const QVector4D v2 = v4 * m; + + QCOMPARE(v1.x(), v2.x()); + QCOMPARE(v1.y(), v2.y()); + QCOMPARE(v1.z(), v2.z()); + } + } + { + // QMatrix4x4 * QPoint + const QPoint p(4, 5); + + QT_IGNORE_DEPRECATIONS(const QPoint p1 = m * p;) + const QPoint p2 = m.map(p); + + QCOMPARE(p1.x(), p2.x()); + QCOMPARE(p1.y(), p2.y()); + } + { + // QMatrix4x4 * QPointF + const QPointF p(4.0f, 5.0f); + + QT_IGNORE_DEPRECATIONS(const QPointF p1 = m * p;) + const QPointF p2 = m.map(p); + + QCOMPARE(p1.x(), p2.x()); + QCOMPARE(p1.y(), p2.y()); + } +} +#endif // QT_DEPRECATED_SINCE(6, 1) + QTEST_APPLESS_MAIN(tst_QMatrixNxN) #include "tst_qmatrixnxn.moc" diff --git a/tests/auto/gui/math3d/qquaternion/CMakeLists.txt b/tests/auto/gui/math3d/qquaternion/CMakeLists.txt index fbeb76abdd..205865faba 100644 --- a/tests/auto/gui/math3d/qquaternion/CMakeLists.txt +++ b/tests/auto/gui/math3d/qquaternion/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qquaternion.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qquaternion Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qquaternion LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qquaternion SOURCES tst_qquaternion.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp b/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp index 350be3da6a..8cdc06354e 100644 --- a/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp +++ b/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp @@ -1,5 +1,7 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses #include <QTest> #include <QtCore/qmath.h> @@ -575,7 +577,7 @@ void tst_QQuaternion::multiply_data() for (float x = -1.0f; x <= 1.0f; x += 0.5f) for (float y = -1.0f; y <= 1.0f; y += 0.5f) for (float z = -1.0f; z <= 1.0f; z += 0.5f) { - QTest::newRow("exhaustive") + QTest::addRow("exhaustive: (%.1f, %.1f, %.1f), %.1f", x, y, z, w) << x << y << z << w << z << w << y << x; } @@ -962,28 +964,6 @@ void tst_QQuaternion::rotationTo() QVERIFY(myFuzzyCompare(vec2, from)); } -static QByteArray testnameForAxis(const QVector3D &axis) -{ - QByteArray testname; - if (axis == QVector3D()) { - testname = "null"; - } else { - if (axis.x()) { - testname += axis.x() < 0 ? '-' : '+'; - testname += 'X'; - } - if (axis.y()) { - testname += axis.y() < 0 ? '-' : '+'; - testname += 'Y'; - } - if (axis.z()) { - testname += axis.z() < 0 ? '-' : '+'; - testname += 'Z'; - } - } - return testname; -} - // Test quaternion convertion to and from orthonormal axes. void tst_QQuaternion::fromDirection_data() { @@ -1006,7 +986,10 @@ void tst_QQuaternion::fromDirection_data() QVector3D xAxis, yAxis, zAxis; q.getAxes(&xAxis, &yAxis, &zAxis); - QTest::newRow("dir: " + testnameForAxis(zAxis) + ", up: " + testnameForAxis(yAxis)) + QTest::addRow("ortho dirs: (%.1f,%.1f,%.1f), (%.1f,%.1f,%.1f), (%.1f,%.1f,%.1f)", + xAxis.x(), xAxis.y(), xAxis.z(), + yAxis.x(), yAxis.y(), yAxis.z(), + zAxis.x(), zAxis.y(), zAxis.z()) << zAxis * 10.0f << yAxis * 10.0f; } @@ -1025,7 +1008,10 @@ void tst_QQuaternion::fromDirection_data() QVector3D xAxis, yAxis, zAxis; q.getAxes(&xAxis, &yAxis, &zAxis); - QTest::newRow("dir: " + testnameForAxis(zAxis) + ", up: null") + QTest::addRow("bad dirs: (%.1f,%.1f,%.1f), (%.1f,%.1f,%.1f), (%.1f,%.1f,%.1f)", + xAxis.x(), xAxis.y(), xAxis.z(), + yAxis.x(), yAxis.y(), yAxis.z(), + zAxis.x(), zAxis.y(), zAxis.z()) << zAxis * 10.0f << QVector3D(); } } diff --git a/tests/auto/gui/math3d/qvectornd/CMakeLists.txt b/tests/auto/gui/math3d/qvectornd/CMakeLists.txt index c29550463a..5de1ff11e6 100644 --- a/tests/auto/gui/math3d/qvectornd/CMakeLists.txt +++ b/tests/auto/gui/math3d/qvectornd/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qvectornd.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qvectornd Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qvectornd LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qvectornd SOURCES tst_qvectornd.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp b/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp index ade6eba796..3272ffac0e 100644 --- a/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp +++ b/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp @@ -1,5 +1,38 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QVector2D> +#include <QVector3D> +#include <QVector4D> +#ifdef QVARIANT_H +# error "This test requires qvector{2,3,4}d.h to not include qvariant.h" +#endif + +// don't assume <type_traits> +template <typename T, typename U> +constexpr inline bool my_is_same_v = false; +template <typename T> +constexpr inline bool my_is_same_v<T, T> = true; + +#define CHECK(cvref) \ + static_assert(my_is_same_v<decltype(get<0>(std::declval<QVector2D cvref >())), float cvref >); \ + static_assert(my_is_same_v<decltype(get<1>(std::declval<QVector2D cvref >())), float cvref >); \ + \ + static_assert(my_is_same_v<decltype(get<0>(std::declval<QVector3D cvref >())), float cvref >); \ + static_assert(my_is_same_v<decltype(get<1>(std::declval<QVector3D cvref >())), float cvref >); \ + static_assert(my_is_same_v<decltype(get<2>(std::declval<QVector3D cvref >())), float cvref >); \ + \ + static_assert(my_is_same_v<decltype(get<0>(std::declval<QVector4D cvref >())), float cvref >); \ + static_assert(my_is_same_v<decltype(get<1>(std::declval<QVector4D cvref >())), float cvref >); \ + static_assert(my_is_same_v<decltype(get<2>(std::declval<QVector4D cvref >())), float cvref >); \ + static_assert(my_is_same_v<decltype(get<3>(std::declval<QVector4D cvref >())), float cvref >) + +CHECK(&); +CHECK(const &); +CHECK(&&); +CHECK(const &&); + +#undef CHECK #include <QTest> #include <QtCore/qmath.h> diff --git a/tests/auto/gui/painting/CMakeLists.txt b/tests/auto/gui/painting/CMakeLists.txt index 4f933139ca..b49a80b180 100644 --- a/tests/auto/gui/painting/CMakeLists.txt +++ b/tests/auto/gui/painting/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from painting.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause add_subdirectory(qpainterpath) add_subdirectory(qpainterpathstroker) @@ -9,14 +10,18 @@ add_subdirectory(qpagelayout) add_subdirectory(qpageranges) add_subdirectory(qpagesize) add_subdirectory(qpainter) -add_subdirectory(qpdfwriter) +if (QT_FEATURE_pdf) + add_subdirectory(qpdfwriter) +endif() add_subdirectory(qpen) add_subdirectory(qpaintengine) add_subdirectory(qtransform) add_subdirectory(qpolygon) -# QTBUG-87669 # special case + +# QTBUG-87669 if(NOT ANDROID) add_subdirectory(qcolorspace) + add_subdirectory(qcolortransform) endif() if(QT_FEATURE_private_tests) add_subdirectory(qpathclipper) diff --git a/tests/auto/gui/painting/qbrush/CMakeLists.txt b/tests/auto/gui/painting/qbrush/CMakeLists.txt index c8dad25d94..313bce20a4 100644 --- a/tests/auto/gui/painting/qbrush/CMakeLists.txt +++ b/tests/auto/gui/painting/qbrush/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qbrush.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qbrush Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qbrush LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qbrush SOURCES tst_qbrush.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate ) diff --git a/tests/auto/gui/painting/qbrush/tst_qbrush.cpp b/tests/auto/gui/painting/qbrush/tst_qbrush.cpp index 64513b89c6..678c8d9b32 100644 --- a/tests/auto/gui/painting/qbrush/tst_qbrush.cpp +++ b/tests/auto/gui/painting/qbrush/tst_qbrush.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/gui/painting/qcolor/CMakeLists.txt b/tests/auto/gui/painting/qcolor/CMakeLists.txt index 87753803fb..52e551855c 100644 --- a/tests/auto/gui/painting/qcolor/CMakeLists.txt +++ b/tests/auto/gui/painting/qcolor/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qcolor.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qcolor Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qcolor LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qcolor SOURCES tst_qcolor.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp index 60a63fadcb..f592db5544 100644 --- a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp +++ b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2020 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -73,7 +73,7 @@ private slots: void toCmykNonDestructive(); void toHsl_data(); - void toHsl();; + void toHsl(); void toHslNonDestructive(); void convertTo(); diff --git a/tests/auto/gui/painting/qcolorspace/CMakeLists.txt b/tests/auto/gui/painting/qcolorspace/CMakeLists.txt index ef53c50551..383c1bb890 100644 --- a/tests/auto/gui/painting/qcolorspace/CMakeLists.txt +++ b/tests/auto/gui/painting/qcolorspace/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from qcolorspace.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qcolorspace Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qcolorspace LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data file(GLOB_RECURSE test_data RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} @@ -17,7 +24,7 @@ endforeach() qt_internal_add_test(tst_qcolorspace SOURCES tst_qcolorspace.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/painting/qcolorspace/resources/CGATS001Compat-v2-micro.icc b/tests/auto/gui/painting/qcolorspace/resources/CGATS001Compat-v2-micro.icc Binary files differnew file mode 100644 index 0000000000..b5a73495bf --- /dev/null +++ b/tests/auto/gui/painting/qcolorspace/resources/CGATS001Compat-v2-micro.icc diff --git a/tests/auto/gui/painting/qcolorspace/resources/Rec. ITU-R BT.2100 PQ.icc b/tests/auto/gui/painting/qcolorspace/resources/Rec. ITU-R BT.2100 PQ.icc Binary files differnew file mode 100644 index 0000000000..e0ceaa12f8 --- /dev/null +++ b/tests/auto/gui/painting/qcolorspace/resources/Rec. ITU-R BT.2100 PQ.icc diff --git a/tests/auto/gui/painting/qcolorspace/resources/VideoHD.icc b/tests/auto/gui/painting/qcolorspace/resources/VideoHD.icc Binary files differnew file mode 100644 index 0000000000..b96eb68136 --- /dev/null +++ b/tests/auto/gui/painting/qcolorspace/resources/VideoHD.icc diff --git a/tests/auto/gui/painting/qcolorspace/resources/sGrey-v4.icc b/tests/auto/gui/painting/qcolorspace/resources/sGrey-v4.icc Binary files differnew file mode 100644 index 0000000000..2187b6786a --- /dev/null +++ b/tests/auto/gui/painting/qcolorspace/resources/sGrey-v4.icc diff --git a/tests/auto/gui/painting/qcolorspace/resources/sRGB_ICC_v4_Appearance.icc b/tests/auto/gui/painting/qcolorspace/resources/sRGB_ICC_v4_Appearance.icc Binary files differnew file mode 100644 index 0000000000..30da950907 --- /dev/null +++ b/tests/auto/gui/painting/qcolorspace/resources/sRGB_ICC_v4_Appearance.icc diff --git a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp index 08f45a2552..6c103ce4f3 100644 --- a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp +++ b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2018 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -42,7 +42,12 @@ private slots: void imageConversionOverLargerGamut(); void imageConversionOverLargerGamut2_data(); void imageConversionOverLargerGamut2(); - + void imageConversionOverAnyGamutFP_data(); + void imageConversionOverAnyGamutFP(); + void imageConversionOverAnyGamutFP2_data(); + void imageConversionOverAnyGamutFP2(); + void imageConversionOverNonThreeComponentMatrix_data(); + void imageConversionOverNonThreeComponentMatrix(); void loadImage(); void primaries(); @@ -61,6 +66,13 @@ private slots: void transferFunctionTable(); void description(); + void whitePoint_data(); + void whitePoint(); + void setWhitePoint(); + void grayColorSpace(); + void grayColorSpaceEffectivelySRgb(); + + void scaleAlphaValue(); }; tst_QColorSpace::tst_QColorSpace() @@ -111,6 +123,15 @@ void tst_QColorSpace::namedColorSpaces_data() QTest::newRow("ProPhoto RGB") << QColorSpace::ProPhotoRgb << true << QColorSpace::Primaries::ProPhotoRgb << QColorSpace::TransferFunction::ProPhotoRgb; + QTest::newRow("BT.2020") << QColorSpace::Bt2020 << true + << QColorSpace::Primaries::Bt2020 + << QColorSpace::TransferFunction::Bt2020; + QTest::newRow("BT.2100 PQ") << QColorSpace::Bt2100Pq << true + << QColorSpace::Primaries::Bt2020 + << QColorSpace::TransferFunction::St2084; + QTest::newRow("BT.2100 HLG") << QColorSpace::Bt2100Hlg << true + << QColorSpace::Primaries::Bt2020 + << QColorSpace::TransferFunction::Hlg; QTest::newRow("0") << QColorSpace::NamedColorSpace(0) << false << QColorSpace::Primaries::Custom @@ -178,15 +199,46 @@ void tst_QColorSpace::fromIccProfile_data() QTest::addColumn<QString>("testProfile"); QTest::addColumn<QColorSpace::NamedColorSpace>("namedColorSpace"); QTest::addColumn<QColorSpace::TransferFunction>("transferFunction"); + QTest::addColumn<QColorSpace::TransformModel>("transformModel"); + QTest::addColumn<QColorSpace::ColorModel>("colorModel"); QTest::addColumn<QString>("description"); QString prefix = QFINDTESTDATA("resources/"); // Read the official sRGB ICCv2 profile: QTest::newRow("sRGB2014 (ICCv2)") << prefix + "sRGB2014.icc" << QColorSpace::SRgb - << QColorSpace::TransferFunction::SRgb << QString("sRGB2014"); + << QColorSpace::TransferFunction::SRgb + << QColorSpace::TransformModel::ThreeComponentMatrix + << QColorSpace::ColorModel::Rgb << QString("sRGB2014"); // My monitor's profile: QTest::newRow("HP ZR30w (ICCv4)") << prefix + "HP_ZR30w.icc" << QColorSpace::NamedColorSpace(0) - << QColorSpace::TransferFunction::Gamma << QString("HP Z30i"); + << QColorSpace::TransferFunction::Gamma + << QColorSpace::TransformModel::ThreeComponentMatrix + << QColorSpace::ColorModel::Rgb << QString("HP Z30i"); + // A profile to HD TV + QTest::newRow("VideoHD") << prefix + "VideoHD.icc" << QColorSpace::NamedColorSpace(0) + << QColorSpace::TransferFunction::Custom + << QColorSpace::TransformModel::ElementListProcessing + << QColorSpace::ColorModel::Rgb << QString("HDTV (Rec. 709)"); + // sRGB on PCSLab format + QTest::newRow("sRGB ICCv4 Appearance") << prefix + "sRGB_ICC_v4_Appearance.icc" << QColorSpace::NamedColorSpace(0) + << QColorSpace::TransferFunction::Custom + << QColorSpace::TransformModel::ElementListProcessing + << QColorSpace::ColorModel::Rgb << QString("sRGB_ICC_v4_Appearance.icc"); + // Grayscale profile + QTest::newRow("sGrey-v4") << prefix + "sGrey-v4.icc" << QColorSpace::NamedColorSpace(0) + << QColorSpace::TransferFunction::SRgb + << QColorSpace::TransformModel::ThreeComponentMatrix + << QColorSpace::ColorModel::Gray << QString("sGry"); + // CMYK profile + QTest::newRow("CGATS compat") << prefix + "CGATS001Compat-v2-micro.icc" << QColorSpace::NamedColorSpace(0) + << QColorSpace::TransferFunction::Custom + << QColorSpace::TransformModel::ElementListProcessing + << QColorSpace::ColorModel::Cmyk << QString("uCMY"); + // BT.2100 PQ profile + QTest::newRow("BT.2100 PQ") << prefix + "Rec. ITU-R BT.2100 PQ.icc" << QColorSpace::Bt2100Pq + << QColorSpace::TransferFunction::St2084 + << QColorSpace::TransformModel::ThreeComponentMatrix + << QColorSpace::ColorModel::Rgb << QString("Rec. ITU-R BT.2100 PQ"); } void tst_QColorSpace::fromIccProfile() @@ -194,10 +246,12 @@ void tst_QColorSpace::fromIccProfile() QFETCH(QString, testProfile); QFETCH(QColorSpace::NamedColorSpace, namedColorSpace); QFETCH(QColorSpace::TransferFunction, transferFunction); + QFETCH(QColorSpace::TransformModel, transformModel); + QFETCH(QColorSpace::ColorModel, colorModel); QFETCH(QString, description); QFile file(testProfile); - file.open(QIODevice::ReadOnly); + QVERIFY(file.open(QIODevice::ReadOnly)); QByteArray iccProfile = file.readAll(); QColorSpace fileColorSpace = QColorSpace::fromIccProfile(iccProfile); QVERIFY(fileColorSpace.isValid()); @@ -206,7 +260,23 @@ void tst_QColorSpace::fromIccProfile() QCOMPARE(fileColorSpace, namedColorSpace); QCOMPARE(fileColorSpace.transferFunction(), transferFunction); + QCOMPARE(fileColorSpace.transformModel(), transformModel); + QCOMPARE(fileColorSpace.colorModel(), colorModel); QCOMPARE(fileColorSpace.description(), description); + + QByteArray iccProfile2 = fileColorSpace.iccProfile(); + QCOMPARE(iccProfile, iccProfile2); + QColorSpace fileColorSpace2 = QColorSpace::fromIccProfile(iccProfile2); + QCOMPARE(fileColorSpace2, fileColorSpace); + + // Change description to force generation of new icc profile data. + fileColorSpace2.setDescription("Hello my QTest description"); + iccProfile2 = fileColorSpace2.iccProfile(); + QCOMPARE_NE(iccProfile, iccProfile2); + fileColorSpace2 = QColorSpace::fromIccProfile(iccProfile2); + QVERIFY(fileColorSpace2.isValid()); + // Note, we do not currently compare description in color space equality + QCOMPARE(fileColorSpace2, fileColorSpace); } void tst_QColorSpace::imageConversion_data() @@ -217,9 +287,10 @@ void tst_QColorSpace::imageConversion_data() QTest::newRow("sRGB -> Display-P3") << QColorSpace::SRgb << QColorSpace::DisplayP3 << 0; QTest::newRow("sRGB -> Adobe RGB") << QColorSpace::SRgb << QColorSpace::AdobeRgb << 2; - QTest::newRow("Display-P3 -> sRGB") << QColorSpace::DisplayP3 << QColorSpace::SRgb << 0; QTest::newRow("Adobe RGB -> sRGB") << QColorSpace::AdobeRgb << QColorSpace::SRgb << 2; + QTest::newRow("Adobe RGB -> Display-P3") << QColorSpace::AdobeRgb << QColorSpace::DisplayP3 << 4; QTest::newRow("Display-P3 -> Adobe RGB") << QColorSpace::DisplayP3 << QColorSpace::AdobeRgb << 2; + QTest::newRow("Display-P3 -> sRGB") << QColorSpace::DisplayP3 << QColorSpace::SRgb << 0; QTest::newRow("sRGB -> sRGB Linear") << QColorSpace::SRgb << QColorSpace::SRgbLinear << 0; QTest::newRow("sRGB Linear -> sRGB") << QColorSpace::SRgbLinear << QColorSpace::SRgb << 0; } @@ -246,9 +317,9 @@ void tst_QColorSpace::imageConversion() int lastBlue = 0; for (int i = 0; i < 256; ++i) { QRgb p = testImage.pixel(i, 0); - QVERIFY(qRed(p) >= lastRed); - QVERIFY(qGreen(p) >= lastGreen); - QVERIFY(qBlue(p) >= lastBlue); + QCOMPARE_GE(qRed(p), lastRed); + QCOMPARE_GE(qGreen(p), lastGreen); + QCOMPARE_GE(qBlue(p), lastBlue); lastRed = qRed(p); lastGreen = qGreen(p); lastBlue = qBlue(p); @@ -261,11 +332,12 @@ void tst_QColorSpace::imageConversion() QCOMPARE(testImage.colorSpace(), QColorSpace(fromColorSpace)); for (int i = 0; i < 256; ++i) { QRgb p = testImage.pixel(i, 0); - QVERIFY(qAbs(qRed(p) - qGreen(p)) <= tolerance); - QVERIFY(qAbs(qRed(p) - qBlue(p)) <= tolerance); - QVERIFY((lastRed - qRed(p)) <= (tolerance / 2)); - QVERIFY((lastGreen - qGreen(p)) <= (tolerance / 2)); - QVERIFY((lastBlue - qBlue(p)) <= (tolerance / 2)); + QCOMPARE_LE(qAbs(qRed(p) - qBlue(p)), tolerance); + QCOMPARE_LE(qAbs(qRed(p) - qGreen(p)), tolerance); + QCOMPARE_LE(qAbs(qGreen(p) - qBlue(p)), tolerance); + QCOMPARE_LE(lastRed - qRed(p), tolerance / 2); + QCOMPARE_LE(lastBlue - qBlue(p), tolerance / 2); + QCOMPARE_LE(lastGreen - qGreen(p), tolerance / 2); lastRed = qRed(p); lastGreen = qGreen(p); lastBlue = qBlue(p); @@ -306,9 +378,9 @@ void tst_QColorSpace::imageConversion64() int lastBlue = 0; for (int i = 0; i < 256; ++i) { QRgb p = testImage.pixel(i, 0); - QVERIFY(qRed(p) >= lastRed); - QVERIFY(qGreen(p) >= lastGreen); - QVERIFY(qBlue(p) >= lastBlue); + QCOMPARE_GE(qRed(p), lastRed); + QCOMPARE_GE(qGreen(p), lastGreen); + QCOMPARE_GE(qBlue(p), lastBlue); lastRed = qRed(p); lastGreen = qGreen(p); lastBlue = qBlue(p); @@ -323,9 +395,9 @@ void tst_QColorSpace::imageConversion64() QRgb p = testImage.pixel(i, 0); QCOMPARE(qRed(p), qGreen(p)); QCOMPARE(qRed(p), qBlue(p)); - QVERIFY((lastRed - qRed(p)) <= 0); - QVERIFY((lastGreen - qGreen(p)) <= 0); - QVERIFY((lastBlue - qBlue(p)) <= 0); + QCOMPARE_GE(qRed(p), lastRed); + QCOMPARE_GE(qGreen(p), lastGreen); + QCOMPARE_GE(qBlue(p), lastBlue); lastRed = qRed(p); lastGreen = qGreen(p); lastBlue = qBlue(p); @@ -349,8 +421,10 @@ void tst_QColorSpace::imageConversion64PM() for (int j = 0; j < 16; ++j) { int a = j * 15; - for (int i = 0; i < 256; ++i) - testImage.setPixel(i, j, qPremultiply(qRgba(i, i, i, a))); + for (int i = 0; i < 256; ++i) { + QRgba64 color = QRgba64::fromRgba(i, i, i, a); + testImage.setPixelColor(i, j, QColor::fromRgba64(color)); + } } testImage.setColorSpace(fromColorSpace); @@ -366,17 +440,17 @@ void tst_QColorSpace::imageConversion64PM() const int expectedAlpha = j * 15; for (int i = 0; i < 256; ++i) { QRgb p = testImage.pixel(i, j); - QVERIFY(qRed(p) >= lastRed); - QVERIFY(qGreen(p) >= lastGreen); - QVERIFY(qBlue(p) >= lastBlue); + QCOMPARE_GE(qRed(p), lastRed); + QCOMPARE_GE(qGreen(p), lastGreen); + QCOMPARE_GE(qBlue(p), lastBlue); QCOMPARE(qAlpha(p), expectedAlpha); lastRed = qRed(p); lastGreen = qGreen(p); lastBlue = qBlue(p); } - QVERIFY(lastRed <= expectedAlpha); - QVERIFY(lastGreen <= expectedAlpha); - QVERIFY(lastBlue <= expectedAlpha); + QCOMPARE_LE(lastRed, expectedAlpha); + QCOMPARE_LE(lastGreen, expectedAlpha); + QCOMPARE_LE(lastBlue, expectedAlpha); lastRed = 0; lastGreen = 0; lastBlue = 0; @@ -389,15 +463,15 @@ void tst_QColorSpace::imageConversion64PM() for (int i = 0; i < 256; ++i) { QRgb expected = qPremultiply(qRgba(i, i, i, expectedAlpha)); QRgb p = testImage.pixel(i, j); - QCOMPARE(qRed(p), qGreen(p)); - QCOMPARE(qRed(p), qBlue(p)); + QCOMPARE_LE(qAbs(qRed(p) - qGreen(p)), 1); + QCOMPARE_LE(qAbs(qRed(p) - qBlue(p)), 1); QCOMPARE(qAlpha(p), expectedAlpha); - QVERIFY((lastRed - qRed(p)) <= 0); - QVERIFY((lastGreen - qGreen(p)) <= 0); - QVERIFY((lastBlue - qBlue(p)) <= 0); - QVERIFY(qAbs(qRed(p) - qRed(expected)) <= 1); - QVERIFY(qAbs(qGreen(p) - qGreen(expected)) <= 1); - QVERIFY(qAbs(qBlue(p) - qBlue(expected)) <= 1); + QCOMPARE_GE(qRed(p), lastRed); + QCOMPARE_GE(qGreen(p), lastGreen); + QCOMPARE_GE(qBlue(p), lastBlue); + QCOMPARE_LE(qAbs(qRed(p) - qRed(expected)), 1); + QCOMPARE_LE(qAbs(qGreen(p) - qGreen(expected)), 1); + QCOMPARE_LE(qAbs(qBlue(p) - qBlue(expected)), 1); lastRed = qRed(p); lastGreen = qGreen(p); lastBlue = qBlue(p); @@ -437,14 +511,14 @@ void tst_QColorSpace::imageConversionOverLargerGamut() testImage.setColorSpace(csfrom); for (int y = 0; y < 256; ++y) for (int x = 0; x < 256; ++x) - testImage.setPixel(x, y, qRgb(x, y, 0)); + testImage.setPixel(x, y, qRgb(x, y, qAbs(x - y))); QImage resultImage = testImage.convertedToColorSpace(csto); for (int y = 0; y < 256; ++y) { int lastRed = 0; for (int x = 0; x < 256; ++x) { QRgb p = resultImage.pixel(x, y); - QVERIFY(qRed(p) >= lastRed); + QCOMPARE_GE(qRed(p), lastRed); lastRed = qRed(p); } } @@ -452,7 +526,7 @@ void tst_QColorSpace::imageConversionOverLargerGamut() int lastGreen = 0; for (int y = 0; y < 256; ++y) { QRgb p = resultImage.pixel(x, y); - QVERIFY(qGreen(p) >= lastGreen); + QCOMPARE_GE(qGreen(p), lastGreen); lastGreen = qGreen(p); } } @@ -515,6 +589,138 @@ void tst_QColorSpace::imageConversionOverLargerGamut2() QVERIFY(resultImage.pixelColor(0, 255).greenF() > 1.0f); } +void tst_QColorSpace::imageConversionOverAnyGamutFP_data() +{ + QTest::addColumn<QColorSpace::NamedColorSpace>("fromColorSpace"); + QTest::addColumn<QColorSpace::NamedColorSpace>("toColorSpace"); + + QTest::newRow("sRGB -> Display-P3") << QColorSpace::SRgb << QColorSpace::DisplayP3; + QTest::newRow("sRGB -> Adobe RGB") << QColorSpace::SRgb << QColorSpace::AdobeRgb; + QTest::newRow("sRGB -> ProPhoto RGB") << QColorSpace::SRgb << QColorSpace::ProPhotoRgb; + QTest::newRow("Adobe RGB -> sRGB") << QColorSpace::AdobeRgb << QColorSpace::SRgb; + QTest::newRow("Adobe RGB -> Display-P3") << QColorSpace::AdobeRgb << QColorSpace::DisplayP3; + QTest::newRow("Adobe RGB -> ProPhoto RGB") << QColorSpace::AdobeRgb << QColorSpace::ProPhotoRgb; + QTest::newRow("Display-P3 -> sRGB") << QColorSpace::DisplayP3 << QColorSpace::SRgb; + QTest::newRow("Display-P3 -> Adobe RGB") << QColorSpace::DisplayP3 << QColorSpace::AdobeRgb; + QTest::newRow("Display-P3 -> ProPhoto RGB") << QColorSpace::DisplayP3 << QColorSpace::ProPhotoRgb; +} + +void tst_QColorSpace::imageConversionOverAnyGamutFP() +{ + QFETCH(QColorSpace::NamedColorSpace, fromColorSpace); + QFETCH(QColorSpace::NamedColorSpace, toColorSpace); + + QColorSpace csfrom(fromColorSpace); + QColorSpace csto(toColorSpace); + csfrom.setTransferFunction(QColorSpace::TransferFunction::Linear); + csto.setTransferFunction(QColorSpace::TransferFunction::Linear); + + QImage testImage(256, 256, QImage::Format_RGBX32FPx4); + testImage.setColorSpace(csfrom); + for (int y = 0; y < 256; ++y) + for (int x = 0; x < 256; ++x) + testImage.setPixel(x, y, qRgb(x, y, 0)); + + QImage resultImage = testImage.convertedToColorSpace(csto); + resultImage.convertToColorSpace(csfrom); + + for (int y = 0; y < 256; ++y) { + for (int x = 0; x < 256; ++x) { + QCOMPARE(resultImage.pixel(x, y), testImage.pixel(x, y)); + } + } +} + +void tst_QColorSpace::imageConversionOverAnyGamutFP2_data() +{ + imageConversionOverAnyGamutFP_data(); +} + +void tst_QColorSpace::imageConversionOverAnyGamutFP2() +{ + QFETCH(QColorSpace::NamedColorSpace, fromColorSpace); + QFETCH(QColorSpace::NamedColorSpace, toColorSpace); + + // Same as imageConversionOverAnyGamutFP but using format switching transform + QColorSpace csfrom(fromColorSpace); + QColorSpace csto(toColorSpace); + csfrom.setTransferFunction(QColorSpace::TransferFunction::Linear); + csto.setTransferFunction(QColorSpace::TransferFunction::Linear); + + QImage testImage(256, 256, QImage::Format_RGB32); + testImage.setColorSpace(csfrom); + for (int y = 0; y < 256; ++y) + for (int x = 0; x < 256; ++x) + testImage.setPixel(x, y, qRgb(x, y, 0)); + + QImage resultImage = testImage.convertedToColorSpace(csto, QImage::Format_RGBX32FPx4); + resultImage.convertToColorSpace(csfrom, QImage::Format_RGB32); + + for (int y = 0; y < 256; ++y) { + for (int x = 0; x < 256; ++x) { + QCOMPARE(resultImage.pixel(x, y), testImage.pixel(x, y)); + } + } +} + +void tst_QColorSpace::imageConversionOverNonThreeComponentMatrix_data() +{ + QTest::addColumn<QColorSpace>("fromColorSpace"); + QTest::addColumn<QColorSpace>("toColorSpace"); + + QString prefix = QFINDTESTDATA("resources/"); + QFile file1(prefix + "VideoHD.icc"); + QFile file2(prefix + "sRGB_ICC_v4_Appearance.icc"); + QVERIFY(file1.open(QFile::ReadOnly)); + QVERIFY(file2.open(QFile::ReadOnly)); + QByteArray iccProfile1 = file1.readAll(); + QByteArray iccProfile2 = file2.readAll(); + QColorSpace hdtvColorSpace = QColorSpace::fromIccProfile(iccProfile1); + QColorSpace srgbPcsColorSpace = QColorSpace::fromIccProfile(iccProfile2); + + QTest::newRow("sRGB PCSLab -> sRGB") << srgbPcsColorSpace << QColorSpace(QColorSpace::SRgb); + QTest::newRow("sRGB -> sRGB PCSLab") << QColorSpace(QColorSpace::SRgb) << srgbPcsColorSpace; + QTest::newRow("HDTV -> sRGB") << hdtvColorSpace << QColorSpace(QColorSpace::SRgb); + QTest::newRow("sRGB -> HDTV") << QColorSpace(QColorSpace::SRgb) << hdtvColorSpace; + QTest::newRow("sRGB PCSLab -> HDTV") << srgbPcsColorSpace << hdtvColorSpace; + QTest::newRow("HDTV -> sRGB PCSLab") << hdtvColorSpace << srgbPcsColorSpace; +} + +void tst_QColorSpace::imageConversionOverNonThreeComponentMatrix() +{ + QFETCH(QColorSpace, fromColorSpace); + QFETCH(QColorSpace, toColorSpace); + QVERIFY(fromColorSpace.isValid()); + QVERIFY(toColorSpace.isValidTarget()); + + QVERIFY(!fromColorSpace.transformationToColorSpace(toColorSpace).isIdentity()); + + QImage testImage(256, 256, QImage::Format_RGBX64); + testImage.setColorSpace(fromColorSpace); + for (int y = 0; y < 256; ++y) + for (int x = 0; x < 256; ++x) + testImage.setPixel(x, y, qRgb(x, y, 0)); + + QImage resultImage = testImage.convertedToColorSpace(toColorSpace); + QCOMPARE(resultImage.size(), testImage.size()); + for (int y = 0; y < 256; ++y) { + int lastRed = 0; + for (int x = 0; x < 256; ++x) { + QRgb p = resultImage.pixel(x, y); + QVERIFY(qRed(p) >= lastRed); + lastRed = qRed(p); + } + } + for (int x = 0; x < 256; ++x) { + int lastGreen = 0; + for (int y = 0; y < 256; ++y) { + QRgb p = resultImage.pixel(x, y); + QVERIFY(qGreen(p) >= lastGreen); + lastGreen = qGreen(p); + } + } +} + void tst_QColorSpace::loadImage() { QString prefix = QFINDTESTDATA("resources/"); @@ -692,10 +898,28 @@ void tst_QColorSpace::changePrimaries() cs.setPrimaries(QColorSpace::Primaries::DciP3D65); QVERIFY(cs.isValid()); QCOMPARE(cs, QColorSpace(QColorSpace::DisplayP3)); + QCOMPARE(cs.transformModel(), QColorSpace::TransformModel::ThreeComponentMatrix); cs.setTransferFunction(QColorSpace::TransferFunction::Linear); cs.setPrimaries(QPointF(0.3127, 0.3290), QPointF(0.640, 0.330), QPointF(0.3000, 0.6000), QPointF(0.150, 0.060)); QCOMPARE(cs, QColorSpace(QColorSpace::SRgbLinear)); + + + QFile iccFile(QFINDTESTDATA("resources/") + "VideoHD.icc"); + QVERIFY(iccFile.open(QFile::ReadOnly)); + QByteArray iccData = iccFile.readAll(); + QColorSpace hdtvColorSpace = QColorSpace::fromIccProfile(iccData); + QVERIFY(hdtvColorSpace.isValid()); + QCOMPARE(hdtvColorSpace.transformModel(), QColorSpace::TransformModel::ElementListProcessing); + QCOMPARE(hdtvColorSpace.primaries(), QColorSpace::Primaries::Custom); + QCOMPARE(hdtvColorSpace.transferFunction(), QColorSpace::TransferFunction::Custom); + // Unsets both primaries and transferfunction because they were inseparable in element list processing + hdtvColorSpace.setPrimaries(QColorSpace::Primaries::SRgb); + QVERIFY(!hdtvColorSpace.isValid()); + hdtvColorSpace.setTransferFunction(QColorSpace::TransferFunction::SRgb); + QVERIFY(hdtvColorSpace.isValid()); + QCOMPARE(hdtvColorSpace.transformModel(), QColorSpace::TransformModel::ThreeComponentMatrix); + QCOMPARE(hdtvColorSpace, QColorSpace(QColorSpace::SRgb)); } void tst_QColorSpace::transferFunctionTable() @@ -744,5 +968,101 @@ void tst_QColorSpace::description() QCOMPARE(srgb.description(), QLatin1String("Linear sRGB")); // Set to empty returns default behavior } +void tst_QColorSpace::whitePoint_data() +{ + QTest::addColumn<QColorSpace::NamedColorSpace>("namedColorSpace"); + QTest::addColumn<QPointF>("whitePoint"); + + QTest::newRow("sRGB") << QColorSpace::SRgb << QColorVector::D65Chromaticity(); + QTest::newRow("Adobe RGB") << QColorSpace::AdobeRgb << QColorVector::D65Chromaticity(); + QTest::newRow("Display-P3") << QColorSpace::DisplayP3 << QColorVector::D65Chromaticity(); + QTest::newRow("ProPhoto RGB") << QColorSpace::ProPhotoRgb << QColorVector::D50Chromaticity(); +} + +void tst_QColorSpace::whitePoint() +{ + QFETCH(QColorSpace::NamedColorSpace, namedColorSpace); + QFETCH(QPointF, whitePoint); + + QColorSpace colorSpace(namedColorSpace); + QPointF wpt = colorSpace.whitePoint(); + QCOMPARE_LE(qAbs(wpt.x() - whitePoint.x()), 0.0000001); + QCOMPARE_LE(qAbs(wpt.y() - whitePoint.y()), 0.0000001); +} + +void tst_QColorSpace::setWhitePoint() +{ + QColorSpace colorSpace(QColorSpace::SRgb); + colorSpace.setWhitePoint(QPointF(0.33, 0.33)); + QCOMPARE_NE(colorSpace, QColorSpace(QColorSpace::SRgb)); + colorSpace.setWhitePoint(QColorVector::D65Chromaticity()); + // Check our matrix manipulations returned us to where we came from + QCOMPARE(colorSpace, QColorSpace(QColorSpace::SRgb)); +} + +void tst_QColorSpace::grayColorSpace() +{ + QColorSpace spc; + QCOMPARE(spc.colorModel(), QColorSpace::ColorModel::Undefined); + QVERIFY(!spc.isValid()); + spc.setWhitePoint(QColorVector::D65Chromaticity()); + spc.setTransferFunction(QColorSpace::TransferFunction::SRgb); + QVERIFY(spc.isValid()); + QCOMPARE(spc.colorModel(), QColorSpace::ColorModel::Gray); + + QColorSpace spc2(QColorVector::D65Chromaticity(), QColorSpace::TransferFunction::SRgb); + QVERIFY(spc2.isValid()); + QCOMPARE(spc2.colorModel(), QColorSpace::ColorModel::Gray); + QCOMPARE(spc, spc2); + + QImage rgbImage(1, 8, QImage::Format_RGB32); + QImage grayImage(1, 255, QImage::Format_Grayscale8); + // RGB images can not have gray color space + rgbImage.setColorSpace(spc2); + grayImage.setColorSpace(spc2); + QCOMPARE_NE(rgbImage.colorSpace(), spc2); + QCOMPARE(grayImage.colorSpace(), spc2); + // But gray images can have RGB color space + rgbImage.setColorSpace(QColorSpace::SRgb); + grayImage.setColorSpace(QColorSpace::SRgb); + QCOMPARE(rgbImage.colorSpace(), QColorSpace(QColorSpace::SRgb)); + QCOMPARE(grayImage.colorSpace(), QColorSpace(QColorSpace::SRgb)); + + // While we can not set a grayscale color space on rgb image, we can convert to one + QImage grayImage2 = rgbImage.convertedToColorSpace(spc2); + QCOMPARE(grayImage2.colorSpace(), spc2); + QCOMPARE(grayImage2.format(), QImage::Format_Grayscale8); +} + +void tst_QColorSpace::grayColorSpaceEffectivelySRgb() +{ + // Test grayscale colorspace conversion by making a gray color space that should act like sRGB on gray values. + QColorSpace sRgb(QColorSpace::SRgb); + QColorSpace sRgbGray(QColorVector::D65Chromaticity(), QColorSpace::TransferFunction::SRgb); + + QImage grayImage1(256, 1, QImage::Format_Grayscale8); + QImage grayImage2(256, 1, QImage::Format_Grayscale8); + for (int i = 0; i < 256; ++i) { + grayImage1.bits()[i] = i; + grayImage2.bits()[i] = i; + } + grayImage1.setColorSpace(sRgb); + grayImage2.setColorSpace(sRgbGray); + + QImage rgbImage1 = grayImage1.convertedTo(QImage::Format_RGB32); + QImage rgbImage2 = grayImage2.convertedToColorSpace(sRgb, QImage::Format_RGB32); + + QCOMPARE(rgbImage1, rgbImage2); +} + +void tst_QColorSpace::scaleAlphaValue() +{ + QImage image(1, 1, QImage::Format_ARGB32); + image.setPixel(0, 0, qRgba(255, 255, 255, 125)); + image.setColorSpace(QColorSpace::SRgb); + image.convertToColorSpace(QColorSpace::SRgbLinear, QImage::Format_RGBA64); + QCOMPARE(reinterpret_cast<const QRgba64 *>(image.constBits())->alpha(), 257 * 125); +} + QTEST_MAIN(tst_QColorSpace) #include "tst_qcolorspace.moc" diff --git a/tests/auto/gui/painting/qcolortransform/CMakeLists.txt b/tests/auto/gui/painting/qcolortransform/CMakeLists.txt new file mode 100644 index 0000000000..4aa4a8bc4a --- /dev/null +++ b/tests/auto/gui/painting/qcolortransform/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## tst_qcolortransform Test: +##################################################################### + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qcolortransform LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qcolortransform + SOURCES + tst_qcolortransform.cpp + LIBRARIES + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/painting/qcolortransform/tst_qcolortransform.cpp b/tests/auto/gui/painting/qcolortransform/tst_qcolortransform.cpp new file mode 100644 index 0000000000..7a976b5f5e --- /dev/null +++ b/tests/auto/gui/painting/qcolortransform/tst_qcolortransform.cpp @@ -0,0 +1,380 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + + +#include <QTest> + +#include <qcolorspace.h> +#include <qcolortransform.h> +#include <qrgbafloat.h> +#include <QtGui/private/qcolortransform_p.h> + +class tst_QColorTransform : public QObject +{ + Q_OBJECT + +public: + tst_QColorTransform(); + +private slots: + void mapRGB32_data(); + void mapRGB32(); + void mapRGB64_data(); + void mapRGB64(); + void mapRGBAFP16x4_data(); + void mapRGBAFP16x4(); + void mapRGBAFP32x4_data(); + void mapRGBAFP32x4(); + void mapQColor_data(); + void mapQColor(); + void mapRGB32Prepared_data(); + void mapRGB32Prepared(); + + void transformIsIdentity(); +}; + +tst_QColorTransform::tst_QColorTransform() +{ } + + +void tst_QColorTransform::mapRGB32_data() +{ + QTest::addColumn<QColorTransform>("transform"); + QTest::addColumn<bool>("sharesRed"); + + QColorSpace srgb(QColorSpace::SRgb); + QColorSpace srgbLinear(QColorSpace::SRgbLinear); + QColorSpace adobeRgb(QColorSpace::AdobeRgb); + QColorSpace adobeRgbLinear = adobeRgb.withTransferFunction(QColorSpace::TransferFunction::Linear); + QColorSpace dp3(QColorSpace::DisplayP3); + QColorSpace dp3Linear = dp3.withTransferFunction(QColorSpace::TransferFunction::Linear); + + QTest::newRow("default") << QColorTransform() << true; + QTest::newRow("sRGB to Linear sRGB") << srgb.transformationToColorSpace(srgbLinear) << true; + QTest::newRow("AdobeRGB to sRGB") << adobeRgb.transformationToColorSpace(srgb) << true; + QTest::newRow("Linear AdobeRGB to AdobeRGB") << adobeRgbLinear.transformationToColorSpace(adobeRgb) << true; + QTest::newRow("Linear AdobeRGB to Linear sRGB") << adobeRgbLinear.transformationToColorSpace(srgbLinear) << true; + QTest::newRow("sRgb to AdobeRGB") << srgb.transformationToColorSpace(adobeRgb) << true; + QTest::newRow("DP3 to sRGB") << dp3.transformationToColorSpace(srgb) << false; + QTest::newRow("DP3 to Linear DP3") << dp3.transformationToColorSpace(dp3Linear) << false; + QTest::newRow("Linear DP3 to Linear sRGB") << dp3Linear.transformationToColorSpace(srgbLinear) << false; +} + +void tst_QColorTransform::mapRGB32() +{ + QFETCH(QColorTransform, transform); + QFETCH(bool, sharesRed); + // Do basic sanity tests of conversions between similar sane color spaces + + QRgb testColor = qRgb(32, 64, 128); + QRgb result = transform.map(testColor); + QVERIFY(qRed(result) < qGreen(result)); + QVERIFY(qGreen(result) < qBlue(result)); + QCOMPARE(qAlpha(result), 255); + if (transform.isIdentity()) + QVERIFY(result == testColor); + else + QVERIFY(result != testColor); + + testColor = qRgb(128, 64, 32); + result = transform.map(testColor); + QVERIFY(qRed(result) > qGreen(result)); + QVERIFY(qGreen(result) > qBlue(result)); + QCOMPARE(qAlpha(result), 255); + if (transform.isIdentity()) + QVERIFY(result == testColor); + else + QVERIFY(result != testColor); + + testColor = qRgba(15, 31, 63, 128); + result = transform.map(testColor); + QVERIFY(qRed(result) < qGreen(result)); + QVERIFY(qGreen(result) < qBlue(result)); + QCOMPARE(qAlpha(result), 128); + if (transform.isIdentity()) + QVERIFY(result == testColor); + else + QVERIFY(result != testColor); + + testColor = qRgb(0, 0, 0); + result = transform.map(testColor); + QCOMPARE(qRed(result), 0); + QCOMPARE(qGreen(result), 0); + QCOMPARE(qBlue(result), 0); + QCOMPARE(qAlpha(result), 255); + + testColor = qRgb(255, 255, 255); + result = transform.map(testColor); + QCOMPARE(qRed(result), 255); + QCOMPARE(qGreen(result), 255); + QCOMPARE(qBlue(result), 255); + QCOMPARE(qAlpha(result), 255); + + testColor = qRgb(255, 255, 0); + result = transform.map(testColor); + QCOMPARE(qAlpha(result), 255); + if (sharesRed) + QCOMPARE(qRed(result), 255); + + testColor = qRgb(0, 255, 255); + result = transform.map(testColor); + QCOMPARE(qBlue(result), 255); + QCOMPARE(qAlpha(result), 255); +} + +void tst_QColorTransform::mapRGB64_data() +{ + mapRGB32_data(); +} + +void tst_QColorTransform::mapRGB64() +{ + QFETCH(QColorTransform, transform); + QFETCH(bool, sharesRed); + + QRgba64 testColor = QRgba64::fromRgba(128, 64, 32, 255); + QRgba64 result = transform.map(testColor); + QVERIFY(result.red() > result.green()); + QVERIFY(result.green() > result.blue()); + QCOMPARE(result.alpha(), 0xffff); + if (transform.isIdentity()) + QVERIFY(result == testColor); + else + QVERIFY(result != testColor); + + testColor = QRgba64::fromRgba64(0, 0, 0, 0xffff); + result = transform.map(testColor); + QCOMPARE(result, testColor); + + testColor = QRgba64::fromRgba64(0xffff, 0xffff, 0xffff, 0xffff); + result = transform.map(testColor); + QCOMPARE(result, testColor); + + testColor = QRgba64::fromRgba64(0xffff, 0xffff, 0, 0xffff); + result = transform.map(testColor); + QCOMPARE(result.alpha(), 0xffff); + if (sharesRed) + QCOMPARE(result.red(), 0xffff); + + testColor = QRgba64::fromRgba64(0, 0xffff, 0xffff, 0xffff); + result = transform.map(testColor); + QCOMPARE(result.blue(), 0xffff); + QCOMPARE(result.alpha(), 0xffff); +} + +void tst_QColorTransform::mapRGBAFP16x4_data() +{ + mapRGB32_data(); +} + +void tst_QColorTransform::mapRGBAFP16x4() +{ + QFETCH(QColorTransform, transform); + QFETCH(bool, sharesRed); + + QRgbaFloat16 testColor = QRgbaFloat16::fromRgba(128, 64, 32, 255); + QRgbaFloat16 result = transform.map(testColor); + QVERIFY(result.red() > result.green()); + QVERIFY(result.green() > result.blue()); + QCOMPARE(result.alpha(), 1.0f); + if (transform.isIdentity()) + QVERIFY(result == testColor); + else + QVERIFY(result != testColor); + + testColor = QRgbaFloat16{qfloat16(0.0f), qfloat16(0.0f), qfloat16(0.0f), qfloat16(1.0f)}; + result = transform.map(testColor); + QCOMPARE(result, testColor); + + testColor = QRgbaFloat16{qfloat16(1.0f), qfloat16(1.0f), qfloat16(1.0f), qfloat16(1.0f)}; + result = transform.map(testColor); + QCOMPARE(result, testColor); + + testColor = QRgbaFloat16{qfloat16(1.0f), qfloat16(1.0f), qfloat16(1.0f), qfloat16(1.0f)}; + result = transform.map(testColor); + QCOMPARE(result.alpha(), 1.0f); + if (sharesRed) + QCOMPARE(result.red(), 1.0f); + + testColor = QRgbaFloat16{qfloat16(0.0f), qfloat16(1.0f), qfloat16(1.0f), qfloat16(1.0f)}; + result = transform.map(testColor); + // QRgbaFloat16 might overflow blue if we convert to a smaller gamut: + QCOMPARE(result.blue16(), 65535); + QCOMPARE(result.alpha(), 1.0f); +} + +void tst_QColorTransform::mapRGBAFP32x4_data() +{ + mapRGB32_data(); +} + +void tst_QColorTransform::mapRGBAFP32x4() +{ + QFETCH(QColorTransform, transform); + QFETCH(bool, sharesRed); + + QRgbaFloat32 testColor = QRgbaFloat32::fromRgba(128, 64, 32, 255); + QRgbaFloat32 result = transform.map(testColor); + QVERIFY(result.red() > result.green()); + QVERIFY(result.green() > result.blue()); + QCOMPARE(result.alpha(), 1.0f); + if (transform.isIdentity()) + QVERIFY(result == testColor); + else + QVERIFY(result != testColor); + + testColor = QRgbaFloat32{0.0f, 0.0f, 0.0f, 1.0f}; + result = transform.map(testColor); + QCOMPARE(result.red(), 0.0f); + QCOMPARE(result.green(), 0.0f); + QCOMPARE(result.blue(), 0.0f); + QCOMPARE(result.alpha(), 1.0f); + + testColor = QRgbaFloat32{1.0f, 1.0f, 1.0f, 1.0f}; + result = transform.map(testColor); + QCOMPARE(result.red(), 1.0f); + QCOMPARE(result.green(), 1.0f); + QCOMPARE(result.blue(), 1.0f); + QCOMPARE(result.alpha(), 1.0f); + + testColor = QRgbaFloat32{1.0f, 1.0f, 0.0f, 1.0f}; + result = transform.map(testColor); + QCOMPARE(result.alpha(), 1.0f); + if (sharesRed) + QCOMPARE(result.red(), 1.0f); + + testColor = QRgbaFloat32{0.0f, 1.0f, 1.0f, 1.0f}; + result = transform.map(testColor); + // QRgbaFloat16 might overflow blue if we convert to a smaller gamut: + QCOMPARE(result.blue16(), 65535); + QCOMPARE(result.alpha(), 1.0f); +} + +void tst_QColorTransform::mapQColor_data() +{ + mapRGB32_data(); +} + +void tst_QColorTransform::mapQColor() +{ + QFETCH(QColorTransform, transform); + QFETCH(bool, sharesRed); + + QColor testColor(32, 64, 128); + QColor result = transform.map(testColor); + QVERIFY(result.redF() < result.greenF()); + QVERIFY(result.greenF() < result.blueF()); + QCOMPARE(result.alphaF(), 1.0f); + if (transform.isIdentity()) + QVERIFY(result == testColor); + else + QVERIFY(result != testColor); + + testColor = Qt::black; + result = transform.map(testColor); + QCOMPARE(result, testColor); + + testColor = Qt::white; + result = transform.map(testColor); + QCOMPARE(result, testColor); + + testColor = QColor(255, 255, 0); + result = transform.map(testColor); + QCOMPARE(result.alphaF(), 1); + if (sharesRed) + QVERIFY(result.redF() >= 1.0f); + + testColor = QColor(0, 255, 255); + result = transform.map(testColor); + QCOMPARE(result.alphaF(), 1.0f); + QVERIFY(result.blueF() >= 1.0f); +} + +void tst_QColorTransform::mapRGB32Prepared_data() +{ + mapRGB32_data(); +} + +void tst_QColorTransform::mapRGB32Prepared() +{ + QFETCH(QColorTransform, transform); + QFETCH(bool, sharesRed); + + // The same tests as mapRGB32 but prepared, to use the LUT code-paths + if (!transform.isIdentity()) + QColorTransformPrivate::get(transform)->prepare(); + + QRgb testColor = qRgb(32, 64, 128); + QRgb result = transform.map(testColor); + QVERIFY(qRed(result) < qGreen(result)); + QVERIFY(qGreen(result) < qBlue(result)); + QCOMPARE(qAlpha(result), 255); + if (transform.isIdentity()) + QVERIFY(result == testColor); + else + QVERIFY(result != testColor); + + testColor = qRgb(128, 64, 32); + result = transform.map(testColor); + QVERIFY(qRed(result) > qGreen(result)); + QVERIFY(qGreen(result) > qBlue(result)); + QCOMPARE(qAlpha(result), 255); + if (transform.isIdentity()) + QVERIFY(result == testColor); + else + QVERIFY(result != testColor); + + testColor = qRgba(15, 31, 63, 128); + result = transform.map(testColor); + QVERIFY(qRed(result) < qGreen(result)); + QVERIFY(qGreen(result) < qBlue(result)); + QCOMPARE(qAlpha(result), 128); + if (transform.isIdentity()) + QVERIFY(result == testColor); + else + QVERIFY(result != testColor); + + testColor = qRgb(0, 0, 0); + result = transform.map(testColor); + QCOMPARE(qRed(result), 0); + QCOMPARE(qGreen(result), 0); + QCOMPARE(qBlue(result), 0); + QCOMPARE(qAlpha(result), 255); + + testColor = qRgb(255, 255, 255); + result = transform.map(testColor); + QCOMPARE(qRed(result), 255); + QCOMPARE(qGreen(result), 255); + QCOMPARE(qBlue(result), 255); + QCOMPARE(qAlpha(result), 255); + + testColor = qRgb(255, 255, 0); + result = transform.map(testColor); + QCOMPARE(qAlpha(result), 255); + if (sharesRed) + QCOMPARE(qRed(result), 255); + + testColor = qRgb(0, 255, 255); + result = transform.map(testColor); + QCOMPARE(qBlue(result), 255); + QCOMPARE(qAlpha(result), 255); +} + +void tst_QColorTransform::transformIsIdentity() +{ + QColorTransform ct; + QVERIFY(ct.isIdentity()); + + QColorSpace cs = QColorSpace::SRgb; + ct = cs.transformationToColorSpace(QColorSpace::SRgb); + QVERIFY(ct.isIdentity()); + + ct = cs.transformationToColorSpace(QColorSpace::SRgbLinear); + QVERIFY(!ct.isIdentity()); + + ct = cs.withTransferFunction(QColorSpace::TransferFunction::Linear).transformationToColorSpace(QColorSpace::SRgbLinear); + QVERIFY(ct.isIdentity()); +} + +QTEST_MAIN(tst_QColorTransform) +#include "tst_qcolortransform.moc" diff --git a/tests/auto/gui/painting/qpagelayout/CMakeLists.txt b/tests/auto/gui/painting/qpagelayout/CMakeLists.txt index 913619461e..b19568592b 100644 --- a/tests/auto/gui/painting/qpagelayout/CMakeLists.txt +++ b/tests/auto/gui/painting/qpagelayout/CMakeLists.txt @@ -1,15 +1,22 @@ -# Generated from qpagelayout.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qpagelayout Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qpagelayout LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qpagelayout SOURCES tst_qpagelayout.cpp DEFINES QT_USE_USING_NAMESPACE - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate ) diff --git a/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp b/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp index 123663a0e3..4490877e87 100644 --- a/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp +++ b/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2014 John Layt <jlayt@kde.org> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtGui/qpagelayout.h> @@ -12,6 +12,9 @@ private slots: void invalid(); void basics(); void setGetMargins(); + void setGetClampedMargins(); + void setUnits_data(); + void setUnits(); }; void tst_QPageLayout::invalid() @@ -88,12 +91,14 @@ void tst_QPageLayout::basics() QCOMPARE(tenpoint.margins(QPageLayout::Millimeter), QMarginsF(3.53, 3.53, 3.53, 3.53)); QCOMPARE(tenpoint.marginsPoints(), QMargins(10, 10, 10, 10)); QCOMPARE(tenpoint.marginsPixels(72), QMargins(10, 10, 10, 10)); + QCOMPARE(tenpoint.marginsPixels(600), QMargins(83, 83, 83, 83)); QCOMPARE(tenpoint.minimumMargins(), QMarginsF(0, 0, 0, 0)); QCOMPARE(tenpoint.maximumMargins(), QMarginsF(595, 842, 595, 842)); QCOMPARE(tenpoint.fullRect(), QRectF(0, 0, 595, 842)); QCOMPARE(tenpoint.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 210, 297)); QCOMPARE(tenpoint.fullRectPoints(), QRect(0, 0, 595, 842)); QCOMPARE(tenpoint.fullRectPixels(72), QRect(0, 0, 595, 842)); + QCOMPARE(tenpoint.fullRectPixels(600), QRect(0, 0, 4958, 7016)); QCOMPARE(tenpoint.paintRect(), QRectF(10, 10, 575, 822)); QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter), QRectF(3.53, 3.53, 202.94, 289.94)); QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter).x(), 3.53); @@ -106,6 +111,7 @@ void tst_QPageLayout::basics() QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter).bottom(), 293.47); QCOMPARE(tenpoint.paintRectPoints(), QRect(10, 10, 575, 822)); QCOMPARE(tenpoint.paintRectPixels(72), QRect(10, 10, 575, 822)); + QCOMPARE(tenpoint.paintRectPixels(600), QRect(83, 83, 4792, 6850)); // Change orientation tenpoint.setOrientation(QPageLayout::Landscape); @@ -117,10 +123,12 @@ void tst_QPageLayout::basics() QCOMPARE(tenpoint.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210)); QCOMPARE(tenpoint.fullRectPoints(), QRect(0, 0, 842, 595)); QCOMPARE(tenpoint.fullRectPixels(72), QRect(0, 0, 842, 595)); + QCOMPARE(tenpoint.fullRectPixels(600), QRect(0, 0, 7016, 4958)); QCOMPARE(tenpoint.paintRect(), QRectF(10, 10, 822, 575)); QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter), QRectF(3.53, 3.53, 289.94, 202.94)); QCOMPARE(tenpoint.paintRectPoints(), QRect(10, 10, 822, 575)); QCOMPARE(tenpoint.paintRectPixels(72), QRect(10, 10, 822, 575)); + QCOMPARE(tenpoint.paintRectPixels(600), QRect(83, 83, 6850, 4792)); // Change mode QCOMPARE(tenpoint.mode(), QPageLayout::StandardMode); @@ -134,15 +142,82 @@ void tst_QPageLayout::basics() QCOMPARE(tenpoint.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210)); QCOMPARE(tenpoint.fullRectPoints(), QRect(0, 0, 842, 595)); QCOMPARE(tenpoint.fullRectPixels(72), QRect(0, 0, 842, 595)); + QCOMPARE(tenpoint.fullRectPixels(600), QRect(0, 0, 7016, 4958)); QCOMPARE(tenpoint.paintRect(), QRectF(0, 0, 842, 595)); QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210)); QCOMPARE(tenpoint.paintRectPoints(), QRect(0, 0, 842, 595)); QCOMPARE(tenpoint.paintRectPixels(72), QRect(0, 0, 842, 595)); + QCOMPARE(tenpoint.paintRectPixels(600), QRect(0, 0, 7016, 4958)); + + // A4, 8.4pt margins + QPageLayout fraction = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(8.4, 8.4, 8.4, 8.4)); + QCOMPARE(fraction.isValid(), true); + QCOMPARE(fraction.margins(), QMarginsF(8.4, 8.4, 8.4, 8.4)); + QCOMPARE(fraction.margins(QPageLayout::Millimeter), QMarginsF(2.96, 2.96, 2.96, 2.96)); + QCOMPARE(fraction.marginsPoints(), QMarginsF(8, 8, 8, 8)); + QCOMPARE(fraction.marginsPixels(72), QMargins(8, 8, 8, 8)); + QCOMPARE(fraction.marginsPixels(600), QMargins(70, 70, 70, 70)); + QCOMPARE(fraction.minimumMargins(), QMarginsF(0, 0, 0, 0)); + QCOMPARE(fraction.maximumMargins(), QMarginsF(595, 842, 595, 842)); + QCOMPARE(fraction.fullRect(), QRectF(0, 0, 595, 842)); + QCOMPARE(fraction.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 210, 297)); + QCOMPARE(fraction.fullRectPoints(), QRect(0, 0, 595, 842)); + QCOMPARE(fraction.fullRectPixels(72), QRect(0, 0, 595, 842)); + QCOMPARE(fraction.fullRectPixels(600), QRect(0, 0, 4958, 7016)); + QCOMPARE(fraction.paintRect(), QRectF(8.4, 8.4, 578.2, 825.2)); + QCOMPARE(fraction.paintRect(QPageLayout::Millimeter), QRectF(2.96, 2.96, 204.08, 291.08)); + QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).x(), 2.96); + QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).y(), 2.96); + QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).width(), 204.08); + QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).height(), 291.08); + QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).left(), 2.96); + QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).right(), 207.04); + QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).top(), 2.96); + QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).bottom(), 294.04); + QCOMPARE(fraction.paintRectPoints(), QRect(8, 8, 579, 826)); + QCOMPARE(fraction.paintRectPixels(72), QRect(8, 8, 579, 826)); + QCOMPARE(fraction.paintRectPixels(600), QRect(70, 70, 4818, 6876)); + + // Change orientation + fraction.setOrientation(QPageLayout::Landscape); + QCOMPARE(fraction.orientation(), QPageLayout::Landscape); + QCOMPARE(fraction.margins(), QMarginsF(8.4, 8.4, 8.4, 8.4)); + QCOMPARE(fraction.minimumMargins(), QMarginsF(0, 0, 0, 0)); + QCOMPARE(fraction.maximumMargins(), QMarginsF(842, 595, 842, 595)); + QCOMPARE(fraction.fullRect(), QRectF(0, 0, 842, 595)); + QCOMPARE(fraction.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210)); + QCOMPARE(fraction.fullRectPoints(), QRect(0, 0, 842, 595)); + QCOMPARE(fraction.fullRectPixels(72), QRect(0, 0, 842, 595)); + QCOMPARE(fraction.fullRectPixels(600), QRect(0, 0, 7016, 4958)); + QCOMPARE(fraction.paintRect(), QRectF(8.4, 8.4, 825.2, 578.2)); + QCOMPARE(fraction.paintRect(QPageLayout::Millimeter), QRectF(2.96, 2.96, 291.08, 204.08)); + QCOMPARE(fraction.paintRectPoints(), QRect(8, 8, 826, 579)); + QCOMPARE(fraction.paintRectPixels(72), QRect(8, 8, 826, 579)); + QCOMPARE(fraction.paintRectPixels(600), QRect(70, 70, 6876, 4818)); + + // Change mode + QCOMPARE(fraction.mode(), QPageLayout::StandardMode); + fraction.setMode(QPageLayout::FullPageMode); + QCOMPARE(fraction.mode(), QPageLayout::FullPageMode); + QCOMPARE(fraction.orientation(), QPageLayout::Landscape); + QCOMPARE(fraction.margins(), QMarginsF(8.4, 8.4, 8.4, 8.4)); + QCOMPARE(fraction.minimumMargins(), QMarginsF(0, 0, 0, 0)); + QCOMPARE(fraction.maximumMargins(), QMarginsF(842, 595, 842, 595)); + QCOMPARE(fraction.fullRect(), QRectF(0, 0, 842, 595)); + QCOMPARE(fraction.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210)); + QCOMPARE(fraction.fullRectPoints(), QRect(0, 0, 842, 595)); + QCOMPARE(fraction.fullRectPixels(72), QRect(0, 0, 842, 595)); + QCOMPARE(fraction.fullRectPixels(600), QRect(0, 0, 7016, 4958)); + QCOMPARE(fraction.paintRect(), QRectF(0, 0, 842, 595)); + QCOMPARE(fraction.paintRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210)); + QCOMPARE(fraction.paintRectPoints(), QRect(0, 0, 842, 595)); + QCOMPARE(fraction.paintRectPixels(72), QRect(0, 0, 842, 595)); + QCOMPARE(fraction.paintRectPixels(600), QRect(0, 0, 7016, 4958)); } void tst_QPageLayout::setGetMargins() { - // A4, 20pt margins + // A4, 10pt margins QMarginsF margins = QMarginsF(10, 10, 10, 10); QMarginsF min = QMarginsF(10, 10, 10, 10); QMarginsF max = QMarginsF(585, 832, 585, 832); @@ -155,7 +230,7 @@ void tst_QPageLayout::setGetMargins() QCOMPARE(change.minimumMargins(), min); QCOMPARE(change.maximumMargins(), max); - // Set magins within min/max ok + // Set margins within min/max ok margins = QMarginsF(20, 20, 20, 20); change.setMargins(margins); QCOMPARE(change.margins(QPageLayout::Millimeter), QMarginsF(7.06, 7.06, 7.06, 7.06)); @@ -215,7 +290,7 @@ void tst_QPageLayout::setGetMargins() fullPage.setMargins(margins); QCOMPARE(fullPage.margins(), margins); - // Set margins all above max is rejected + // Set margins all above max is accepted margins = QMarginsF(1000, 1000, 1000, 1000); fullPage.setMargins(margins); QCOMPARE(fullPage.margins(), margins); @@ -238,6 +313,174 @@ void tst_QPageLayout::setGetMargins() QCOMPARE(fullPage.maximumMargins(), max); } +void tst_QPageLayout::setGetClampedMargins() +{ + // A4, 10pt margins + QMarginsF margins = QMarginsF(10, 10, 10, 10); + QMarginsF min = QMarginsF(10, 10, 10, 10); + QMarginsF max = QMarginsF(585, 832, 585, 832); + QPageLayout change = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, margins, QPageLayout::Point, min); + QCOMPARE(change.isValid(), true); + + // Clamp margins within min/max ok + margins = QMarginsF(20, 20, 20, 20); + change.setMargins(margins, QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins(QPageLayout::Millimeter), QMarginsF(7.06, 7.06, 7.06, 7.06)); + QCOMPARE(change.marginsPoints(), QMargins(20, 20, 20, 20)); + QCOMPARE(change.marginsPixels(72), QMargins(20, 20, 20, 20)); + QCOMPARE(change.margins(), margins); + + // Clamp margins all below min + change.setMargins(QMarginsF(0, 0, 0, 0), QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins(), change.minimumMargins()); + + // Clamp margins all above max + change.setMargins(QMarginsF(1000, 1000, 1000, 1000), QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins(), change.maximumMargins()); + + // Only 1 wrong, clamp still works + change.setMargins(QMarginsF(50, 50, 50, 0), QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins(), QMarginsF(50, 50, 50, change.minimumMargins().bottom())); + + // A4, 20pt margins + margins = QMarginsF(20, 20, 20, 20); + min = QMarginsF(10, 10, 10, 10); + max = QMarginsF(585, 832, 585, 832); + QPageLayout fullPage = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, margins, QPageLayout::Point, min); + fullPage.setMode(QPageLayout::FullPageMode); + QCOMPARE(fullPage.isValid(), true); + QCOMPARE(fullPage.margins(), margins); + QCOMPARE(fullPage.minimumMargins(), min); + QCOMPARE(fullPage.maximumMargins(), max); + + // Clamp margins within min/max ok + margins = QMarginsF(50, 50, 50, 50); + fullPage.setMargins(margins, QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(fullPage.margins(), margins); + + // Clamp margins all below min, no clamping + margins = QMarginsF(0, 0, 0, 0); + fullPage.setMargins(margins, QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(fullPage.margins(), margins); + + // Clamp margins all above max, no clamping + margins = QMarginsF(1000, 1000, 1000, 1000); + fullPage.setMargins(margins, QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(fullPage.margins(), margins); + + // Only 1 wrong, no clamping + margins = QMarginsF(50, 50, 50, 0); + fullPage.setMargins(margins, QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(fullPage.margins(), margins); + + // Set page size, sets min/max, clamps existing margins + margins = QMarginsF(20, 500, 20, 500); + fullPage.setMargins(margins, QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(fullPage.margins(), margins); + min = QMarginsF(30, 30, 30, 30); + max = QMarginsF(267, 390, 267, 390); + fullPage.setPageSize(QPageSize(QPageSize::A6)); + fullPage.setMinimumMargins(min); + QCOMPARE(fullPage.margins(), margins); + QCOMPARE(fullPage.minimumMargins(), min); + QCOMPARE(fullPage.maximumMargins(), max); + + // Test set* API calls + min = QMarginsF(1, 2, 3, 4); + max = QMarginsF(595 - min.right(), 842 - min.bottom(), 595 - min.left(), 842 - min.top()); + change = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, margins, QPageLayout::Point, min); + QCOMPARE(change.minimumMargins(), min); + QCOMPARE(change.maximumMargins(), max); + + // Test setLeftMargin + change.setLeftMargin(0, QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins().left(), min.left()); + change.setLeftMargin(change.fullRectPoints().width(), QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins().left(), max.left()); + change.setLeftMargin(min.left(), QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins().left(), min.left()); + change.setLeftMargin(max.left(), QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins().left(), max.left()); + + // Test setTopMargin + change.setTopMargin(0, QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins().top(), min.top()); + change.setTopMargin(change.fullRectPoints().height(), QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins().top(), max.top()); + change.setTopMargin(min.top(), QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins().top(), min.top()); + change.setTopMargin(max.top(), QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins().top(), max.top()); + + // Test setRightMargin + change.setRightMargin(0, QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins().right(), min.right()); + change.setRightMargin(change.fullRectPoints().width(), QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins().right(), max.right()); + change.setRightMargin(min.right(), QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins().right(), min.right()); + change.setRightMargin(max.right(), QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins().right(), max.right()); + + // Test setBottomMargin + change.setBottomMargin(0, QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins().bottom(), min.bottom()); + change.setBottomMargin(change.fullRectPoints().height(), QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins().bottom(), max.bottom()); + change.setBottomMargin(min.bottom(), QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins().bottom(), min.bottom()); + change.setBottomMargin(max.bottom(), QPageLayout::OutOfBoundsPolicy::Clamp); + QCOMPARE(change.margins().bottom(), max.bottom()); +} + +void tst_QPageLayout::setUnits_data() +{ + QTest::addColumn<QPageLayout::Unit>("units"); + QTest::newRow("Millimeter") << QPageLayout::Millimeter; + QTest::newRow("Point") << QPageLayout::Point; + QTest::newRow("Inch") << QPageLayout::Inch; + QTest::newRow("Pica") << QPageLayout::Pica; + QTest::newRow("Didot") << QPageLayout::Didot; + QTest::newRow("Cicero") << QPageLayout::Cicero; +} + +void tst_QPageLayout::setUnits() +{ + QFETCH(QPageLayout::Unit, units); + QPageLayout pageLayout = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(), units); + int maxLeftX100 = qFloor(pageLayout.maximumMargins().left() * 100); + QVERIFY(maxLeftX100 > 0); + for (int i = 1; i <= maxLeftX100; ++i) { + const qreal margin = i / 100.; + const QMarginsF unitsMargins = QMarginsF(margin, margin, margin, margin); + pageLayout.setMargins(unitsMargins); + pageLayout.setUnits(QPageLayout::Point); + const QMarginsF pointsMargins = pageLayout.margins(); + if (units == QPageLayout::Point) { + QCOMPARE(pointsMargins, unitsMargins); + } else { + QCOMPARE_GT(pointsMargins.left(), unitsMargins.left()); + QCOMPARE_GT(pointsMargins.top(), unitsMargins.top()); + QCOMPARE_GT(pointsMargins.right(), unitsMargins.right()); + QCOMPARE_GT(pointsMargins.bottom(), unitsMargins.bottom()); + } + pageLayout.setUnits(units); + const QMarginsF convertedUnitsMargins = pageLayout.margins(); + if (units == QPageLayout::Didot) { + // When using Didot units, the small multiplier and ceiling function in conversion + // may cause the converted units to not match the original exactly. However, we + // can verify that the converted margins are always greater than or equal to the + // original. + QCOMPARE_GE(convertedUnitsMargins.left(), unitsMargins.left()); + QCOMPARE_GE(convertedUnitsMargins.top(), unitsMargins.top()); + QCOMPARE_GE(convertedUnitsMargins.right(), unitsMargins.right()); + QCOMPARE_GE(convertedUnitsMargins.bottom(), unitsMargins.bottom()); + } else { + QCOMPARE(convertedUnitsMargins, unitsMargins); + } + } +} + QTEST_APPLESS_MAIN(tst_QPageLayout) #include "tst_qpagelayout.moc" diff --git a/tests/auto/gui/painting/qpageranges/CMakeLists.txt b/tests/auto/gui/painting/qpageranges/CMakeLists.txt index 660d4b4336..99ab477eae 100644 --- a/tests/auto/gui/painting/qpageranges/CMakeLists.txt +++ b/tests/auto/gui/painting/qpageranges/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qpageranges.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qpageranges Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qpageranges LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qpageranges SOURCES tst_qpageranges.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp b/tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp index 00975906ed..d2dbf990e3 100644 --- a/tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp +++ b/tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2019 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <qpageranges.h> @@ -70,7 +70,7 @@ void tst_QPageRanges::addPage() QFETCH(PageRangeList, expected); QPageRanges result; - for (int pageNumber : qAsConst(pageNumbers)) { + for (int pageNumber : std::as_const(pageNumbers)) { if (QByteArrayView(QTest::currentDataTag()) == "invalid") QTest::ignoreMessage(QtWarningMsg, "QPageRanges::addPage: 'pageNumber' must be greater than 0"); result.addPage(pageNumber); @@ -112,7 +112,7 @@ void tst_QPageRanges::addRange() QFETCH(PageRangeList, expected); QPageRanges result; - for (const auto &range : qAsConst(ranges)) { + for (const auto &range : std::as_const(ranges)) { const QByteArrayView testdata(QTest::currentDataTag()); if (testdata.startsWith("invalid")) QTest::ignoreMessage(QtWarningMsg, "QPageRanges::addRange: 'from' and 'to' must be greater than 0"); diff --git a/tests/auto/gui/painting/qpagesize/CMakeLists.txt b/tests/auto/gui/painting/qpagesize/CMakeLists.txt index fc6fd931c2..b16cd2714a 100644 --- a/tests/auto/gui/painting/qpagesize/CMakeLists.txt +++ b/tests/auto/gui/painting/qpagesize/CMakeLists.txt @@ -1,14 +1,21 @@ -# Generated from qpagesize.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qpagesize Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qpagesize LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qpagesize SOURCES tst_qpagesize.cpp DEFINES QT_USE_USING_NAMESPACE - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp b/tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp index bac7e9cdf8..de9b799902 100644 --- a/tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp +++ b/tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtGlobal> @@ -49,11 +49,13 @@ void tst_QPageSize::basics() QCOMPARE(a4.size(QPageSize::Pica), QSizeF(49.58, 70.17)); QCOMPARE(a4.sizePoints(), QSize(595, 842)); QCOMPARE(a4.sizePixels(72), QSize(595, 842)); + QCOMPARE(a4.sizePixels(600), QSize(4958, 7016)); // Rounded down QCOMPARE(a4.rect(QPageSize::Millimeter), QRectF(0, 0, 210, 297)); QCOMPARE(a4.rect(QPageSize::Inch), QRectF(0, 0, 8.27, 11.69)); QCOMPARE(a4.rect(QPageSize::Pica), QRectF(0, 0, 49.58, 70.17)); QCOMPARE(a4.rectPoints(), QRect(0, 0, 595, 842)); QCOMPARE(a4.rectPixels(72), QRect(0, 0, 595, 842)); + QCOMPARE(a4.rectPixels(600), QRect(0, 0, 4958, 7016)); // Rounded down // Simple QPageSize::PaperSizeId later in list QPageSize folio = QPageSize(QPageSize::Folio); diff --git a/tests/auto/gui/painting/qpaintengine/CMakeLists.txt b/tests/auto/gui/painting/qpaintengine/CMakeLists.txt index b843135645..4cd0151a01 100644 --- a/tests/auto/gui/painting/qpaintengine/CMakeLists.txt +++ b/tests/auto/gui/painting/qpaintengine/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qpaintengine.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qpaintengine Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qpaintengine LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qpaintengine SOURCES tst_qpaintengine.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/painting/qpaintengine/tst_qpaintengine.cpp b/tests/auto/gui/painting/qpaintengine/tst_qpaintengine.cpp index 24e13c2821..02441de54c 100644 --- a/tests/auto/gui/painting/qpaintengine/tst_qpaintengine.cpp +++ b/tests/auto/gui/painting/qpaintengine/tst_qpaintengine.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/gui/painting/qpainter/CMakeLists.txt b/tests/auto/gui/painting/qpainter/CMakeLists.txt index 3d46a708e9..261e1eb2cf 100644 --- a/tests/auto/gui/painting/qpainter/CMakeLists.txt +++ b/tests/auto/gui/painting/qpainter/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from qpainter.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qpainter Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qpainter LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data file(GLOB_RECURSE test_data_glob RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} @@ -26,7 +33,7 @@ list(APPEND test_data "task217400.png") qt_internal_add_test(tst_qpainter SOURCES tst_qpainter.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate @@ -37,7 +44,7 @@ qt_internal_add_test(tst_qpainter ##################################################################### qt_internal_extend_target(tst_qpainter CONDITION TARGET Qt::Widgets - PUBLIC_LIBRARIES + LIBRARIES Qt::Widgets Qt::WidgetsPrivate ) diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp index 470eae31d8..92b28f65bd 100644 --- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp @@ -1,6 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <qpainter.h> @@ -62,6 +61,7 @@ private slots: #endif void drawPixmapFragments(); void drawPixmapNegativeScale(); + void drawPixmapRounding(); void drawLine_data(); void drawLine(); @@ -170,6 +170,7 @@ private slots: void radialGradientRgb30(); #endif + void radialGradient_QTBUG120332_ubsan(); void fpe_pixmapTransform(); void fpe_zeroLengthLines(); void fpe_divByZero(); @@ -747,6 +748,16 @@ void tst_QPainter::drawPixmapNegativeScale() QVERIFY(resultImage.pixel(12, 8) == qRgba(0, 0, 0, 255)); // and right strip is now black } +void tst_QPainter::drawPixmapRounding() +{ + // Just test that we don't assert + QBitmap bm(8, 8); + QImage out(64, 64, QImage::Format_RGB32); + QPainter p(&out); + qreal y = 26.499999999999996; + p.drawPixmap(QPointF(0, y), bm); +} + void tst_QPainter::drawLine_data() { QTest::addColumn<QLine>("line"); @@ -2082,21 +2093,22 @@ void tst_QPainter::clippedLines_data() QPen pen2(QColor(223, 223, 0, 223)); pen2.setWidth(2); - QList<QLineF> lines; - lines << QLineF(15, 15, 65, 65) - << QLineF(14, 14, 66, 66) - << QLineF(16, 16, 64, 64) - << QLineF(65, 65, 15, 15) - << QLineF(66, 66, 14, 14) - << QLineF(64, 64, 14, 14) - << QLineF(15, 50, 15, 64) - << QLineF(15, 50, 15, 65) - << QLineF(15, 50, 15, 66) - << QLineF(15, 50, 64, 50) - << QLineF(15, 50, 65, 50) - << QLineF(15, 50, 66, 50); - - foreach (QLineF line, lines) { + const auto lines = { + QLineF(15, 15, 65, 65), + QLineF(14, 14, 66, 66), + QLineF(16, 16, 64, 64), + QLineF(65, 65, 15, 15), + QLineF(66, 66, 14, 14), + QLineF(64, 64, 14, 14), + QLineF(15, 50, 15, 64), + QLineF(15, 50, 15, 65), + QLineF(15, 50, 15, 66), + QLineF(15, 50, 64, 50), + QLineF(15, 50, 65, 50), + QLineF(15, 50, 66, 50), + }; + + for (QLineF line : lines) { const QByteArray desc = "line (" + QByteArray::number(line.x1()) + ", " + QByteArray::number(line.y1()) + ", " + QByteArray::number(line.x2()) + ", " + QByteArray::number(line.y2()) @@ -2497,6 +2509,12 @@ void tst_QPainter::drawhelper_blend_untransformed_data() setOpacity_data(); } +static const auto &defaultOpacities() +{ + static const std::array opacities = {qreal(0.0), 0.1 , 0.01, 0.4, 0.5, 0.6, 0.9, 1.0}; + return opacities; +} + void tst_QPainter::drawhelper_blend_untransformed() { QFETCH(QImage::Format, destFormat); @@ -2517,9 +2535,7 @@ void tst_QPainter::drawhelper_blend_untransformed() p.fillRect(paintRect, srcColor); p.end(); - QList<qreal> opacities = (QList<qreal>() << 0.0 << 0.1 << 0.01 << 0.4 - << 0.5 << 0.6 << 0.9 << 1.0); - foreach (qreal opacity, opacities) { + for (qreal opacity : defaultOpacities()) { p.begin(&dest); p.fillRect(paintRect, destColor); @@ -2574,9 +2590,7 @@ void tst_QPainter::drawhelper_blend_tiled_untransformed() const QBrush brush(src); - QList<qreal> opacities = (QList<qreal>() << 0.0 << 0.1 << 0.01 << 0.4 - << 0.5 << 0.6 << 0.9 << 1.0); - foreach (qreal opacity, opacities) { + for (qreal opacity : defaultOpacities()) { p.begin(&dest); p.fillRect(paintRect, destColor); @@ -2770,7 +2784,7 @@ void tst_QPainter::monoImages() for (int i = 1; i < QImage::NImageFormats; ++i) { for (int j = 0; j < numColorPairs; ++j) { const QImage::Format format = QImage::Format(i); - if (format == QImage::Format_Indexed8) + if (format == QImage::Format_Indexed8 || format == QImage::Format_CMYK8888) continue; QImage img(2, 2, format); @@ -2830,7 +2844,14 @@ void tst_QPainter::monoImages() } } -#if !defined(Q_OS_AIX) && !defined(Q_CC_MSVC) && !defined(Q_OS_SOLARIS) && !defined(__UCLIBC__) && !defined(Q_OS_INTEGRITY) +#if defined(Q_OS_DARWIN) || defined(Q_OS_FREEBSD) || defined(Q_OS_ANDROID) +# define TEST_FPE_EXCEPTIONS +#elif defined(Q_OS_LINUX) && defined(__GLIBC__) +# define TEST_FPE_EXCEPTIONS +#elif defined(Q_OS_WIN) && defined(Q_CC_GNU) +# define TEST_FPE_EXCEPTIONS +#endif +#ifdef TEST_FPE_EXCEPTIONS #include <fenv.h> static const QString fpeExceptionString(int exception) @@ -3533,9 +3554,13 @@ void tst_QPainter::drawImage_data() for (int srcFormat = QImage::Format_Mono; srcFormat < QImage::NImageFormats; ++srcFormat) { for (int dstFormat = QImage::Format_Mono; dstFormat < QImage::NImageFormats; ++dstFormat) { - // Indexed8 can't be painted to, and Alpha8 can't hold a color. - if (dstFormat == QImage::Format_Indexed8 || dstFormat == QImage::Format_Alpha8) + // Indexed8 and CMYK8888 can't be painted to, and Alpha8 can't hold a color. + if (dstFormat == QImage::Format_Indexed8 || + dstFormat == QImage::Format_CMYK8888 || + dstFormat == QImage::Format_Alpha8) { continue; + } + for (int odd_x = 0; odd_x <= 1; ++odd_x) { for (int odd_width = 0; odd_width <= 1; ++odd_width) { QTest::addRow("srcFormat %d, dstFormat %d, odd x: %d, odd width: %d", @@ -3778,10 +3803,10 @@ static QLinearGradient inverseGradient(QLinearGradient g) { QLinearGradient g2 = g; - QGradientStops stops = g.stops(); + const QGradientStops stops = g.stops(); QGradientStops inverse; - foreach (QGradientStop stop, stops) + for (const QGradientStop &stop : stops) inverse << QGradientStop(1 - stop.first, stop.second); g2.setStops(inverse); @@ -3887,6 +3912,21 @@ void tst_QPainter::gradientPixelFormat() QCOMPARE(a, b.convertToFormat(QImage::Format_ARGB32_Premultiplied)); } +void tst_QPainter::radialGradient_QTBUG120332_ubsan() +{ + // Check if Radial Gradient will cause division by zero or not when + // the center point coincide with the focal point. + QImage image(8, 8, QImage::Format_ARGB32_Premultiplied); + QPainter painter(&image); + + QPointF center(0.5, 0.5); + QPointF focal(0.5, 0.5); + QRadialGradient gradient(center, 0.5, focal, 0.5); + gradient.setColorAt(0, Qt::blue); + gradient.setColorAt(1, Qt::red); + painter.fillRect(image.rect(), QBrush(gradient)); +} + void tst_QPainter::gradientInterpolation() { QImage image(256, 8, QImage::Format_ARGB32_Premultiplied); @@ -4890,10 +4930,7 @@ void tst_QPainter::QTBUG25153_drawLine() { QImage image(2, 2, QImage::Format_RGB32); - QList<Qt::PenCapStyle> styles; - styles << Qt::FlatCap << Qt::SquareCap << Qt::RoundCap; - - foreach (Qt::PenCapStyle style, styles) { + for (Qt::PenCapStyle style : {Qt::FlatCap, Qt::SquareCap, Qt::RoundCap}) { image.fill(0xffffffff); QPainter p(&image); p.setPen(QPen(Qt::black, 0, Qt::SolidLine, style)); @@ -5004,16 +5041,16 @@ void tst_QPainter::blendARGBonRGB_data() QTest::newRow("ARGB_PM over RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32_Premultiplied << QPainter::CompositionMode_SourceOver << qRgba(85, 0, 0, 85) << 85; #if QT_CONFIG(raster_64bit) - QTest::newRow("ARGB source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32 - << QPainter::CompositionMode_Source << qRgba(255, 0, 0, 85) << 85; - QTest::newRow("ARGB source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32 - << QPainter::CompositionMode_Source << qRgba(255, 0, 0, 120) << 85; + QTest::newRow("ARGB@85 source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32 + << QPainter::CompositionMode_Source << qRgba(255, 0, 0, 85) << 85; + QTest::newRow("ARGB@120 source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32 + << QPainter::CompositionMode_Source << qRgba(255, 0, 0, 120) << 85; #endif - QTest::newRow("ARGB_PM source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32_Premultiplied - << QPainter::CompositionMode_Source << qRgba(85, 0, 0, 85) << 85; + QTest::newRow("ARGB_PM@85 source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32_Premultiplied + << QPainter::CompositionMode_Source << qRgba(85, 0, 0, 85) << 85; #if QT_CONFIG(raster_64bit) - QTest::newRow("ARGB_PM source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32_Premultiplied - << QPainter::CompositionMode_Source << qRgba(180, 0, 0, 180) << 170; + QTest::newRow("ARGB_PM@180 source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32_Premultiplied + << QPainter::CompositionMode_Source << qRgba(180, 0, 0, 180) << 170; #endif QTest::newRow("ARGB source-in RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32 << QPainter::CompositionMode_SourceIn << qRgba(255, 0, 0, 85) << 85; @@ -5174,7 +5211,7 @@ void tst_QPainter::drawPolyline() p.setPen(pen); QVERIFY(p.pen().isCosmetic()); if (r) { - for (int i = 0; i < points.count()-1; i++) { + for (int i = 0; i < points.size()-1; i++) { p.drawLine(points.at(i), points.at(i+1)); } } else { @@ -5499,6 +5536,7 @@ void tst_QPainter::hdrColors() QCOMPARE(img.pixelColor(4, 4), color); QImage img2(10, 10, QImage::Format_RGBX32FPx4); + img2.fill(Qt::black); // fill to avoid random FP values like Inf which can break SourceOver composition { QPainter p(&img2); p.drawImage(0, 0, img); diff --git a/tests/auto/gui/painting/qpainter/utils/createImages/main.cpp b/tests/auto/gui/painting/qpainter/utils/createImages/main.cpp index 092986045a..7cb9e74216 100644 --- a/tests/auto/gui/painting/qpainter/utils/createImages/main.cpp +++ b/tests/auto/gui/painting/qpainter/utils/createImages/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qapplication.h> diff --git a/tests/auto/gui/painting/qpainterpath/BLACKLIST b/tests/auto/gui/painting/qpainterpath/BLACKLIST deleted file mode 100644 index b3e6d3bfe4..0000000000 --- a/tests/auto/gui/painting/qpainterpath/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[contains_QPointF] -msvc-2019 diff --git a/tests/auto/gui/painting/qpainterpath/CMakeLists.txt b/tests/auto/gui/painting/qpainterpath/CMakeLists.txt index 47450c9146..1da6e25511 100644 --- a/tests/auto/gui/painting/qpainterpath/CMakeLists.txt +++ b/tests/auto/gui/painting/qpainterpath/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qpainterpath.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qpainterpath Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qpainterpath LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qpainterpath SOURCES tst_qpainterpath.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp index 693c726792..c00dc3a78a 100644 --- a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp +++ b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -81,6 +81,8 @@ private slots: void intersectionEquality(); void intersectionPointOnEdge(); + + void boundsAtStartPoint(); }; void tst_QPainterPath::cleanupTestCase() @@ -385,11 +387,11 @@ void tst_QPainterPath::contains_QRectF_data() QTest::newRow("inside 2 rects (winding)") << path << QRectF(51, 51, 48, 48) << true; path.addEllipse(0, 0, 150, 150); - QTest::newRow("topRight 2 rects") << path << QRectF(100, 25, 24, 24) << true; - QTest::newRow("bottomLeft 2 rects") << path << QRectF(25, 100, 24, 24) << true; + QTest::newRow("topRight rects+circle") << path << QRectF(100, 25, 24, 24) << true; + QTest::newRow("bottomLeft rects+circle") << path << QRectF(25, 100, 24, 24) << true; path.setFillRule(Qt::OddEvenFill); - QTest::newRow("inside 2 rects") << path << QRectF(50, 50, 49, 49) << false; + QTest::newRow("inside rects+circle") << path << QRectF(50, 50, 49, 49) << false; } void tst_QPainterPath::contains_QRectF() @@ -763,6 +765,21 @@ void tst_QPainterPath::testOperatorDatastream() } QCOMPARE(other, path); + + // Check reset & detach + QPainterPath p3; + p3.lineTo(1, 1); + QCOMPARE(p3.elementCount(), 2); + QPainterPath p4 = p3; + QCOMPARE(p4.elementCount(), 2); + { + QFile data(tempDir.path() + "/data"); + QVERIFY(data.open(QFile::ReadOnly)); + QDataStream stream(&data); + stream >> p3; + } + QCOMPARE(p3.elementCount(), path.elementCount()); + QCOMPARE(p4.elementCount(), 2); } void tst_QPainterPath::closing() @@ -893,17 +910,17 @@ void tst_QPainterPath::testArcMoveTo_data() QRectF(100, 100, 100, -100), QRectF(100, 100, -100, -100), }; + constexpr qreal tinyAngle = 1e-10; - for (uint domain = 0; domain < sizeof rects / sizeof *rects; ++domain) { - const QByteArray dB = QByteArray::number(domain); - for (int i=-360; i<=360; ++i) { - QTest::newRow(("test " + dB + ' ' + QByteArray::number(i)).constData()) - << rects[domain] << (qreal) i; - } + int index = 0; + for (const auto &rect : rects) { + for (int i = -360; i <= 360; ++i) + QTest::addRow("test %d %d", index, i) << rect << qreal(i); // test low angles - QTest::newRow("low angles 1") << rects[domain] << (qreal) 1e-10; - QTest::newRow("low angles 2") << rects[domain] << (qreal)-1e-10; + QTest::addRow("low +angle %d", index) << rect << tinyAngle; + QTest::addRow("low -angle %d", index) << rect << -tinyAngle; + ++index; } } @@ -1220,38 +1237,65 @@ void tst_QPainterPath::testNaNandInfinites() QPointF p3 = QPointF(qQNaN(), 1); QPointF pInf = QPointF(qInf(), 1); - // all these operations with NaN/Inf should be ignored - // can't test operator>> reliably, as we can't create a path with NaN to << later + // All these operations with NaN/Inf should be ignored. + // Can't test operator>> reliably, as we can't create a path with NaN to << later. +#ifdef QT_NO_DEBUG +# define WARNS(name) +#else +# define WARNS(name) \ + QTest::ignoreMessage(QtWarningMsg, "QPainterPath::" #name ": " \ + "Adding point with invalid coordinates, ignoring call") +#endif + WARNS(moveTo); path1.moveTo(p1); + WARNS(moveTo); path1.moveTo(qSNaN(), qQNaN()); + WARNS(moveTo); path1.moveTo(pInf); + WARNS(lineTo); path1.lineTo(p1); + WARNS(lineTo); path1.lineTo(qSNaN(), qQNaN()); + WARNS(lineTo); path1.lineTo(pInf); + WARNS(cubicTo); path1.cubicTo(p1, p2, p3); + WARNS(cubicTo); path1.cubicTo(p1, QPointF(1, 1), QPointF(2, 2)); + WARNS(cubicTo); path1.cubicTo(pInf, QPointF(10, 10), QPointF(5, 1)); + WARNS(quadTo); path1.quadTo(p1, p2); + WARNS(quadTo); path1.quadTo(QPointF(1, 1), p3); + WARNS(quadTo); path1.quadTo(QPointF(1, 1), pInf); + WARNS(arcTo); path1.arcTo(QRectF(p1, p2), 5, 5); + WARNS(arcTo); path1.arcTo(QRectF(pInf, QPointF(1, 1)), 5, 5); + WARNS(addRect); path1.addRect(QRectF(p1, p2)); + WARNS(addRect); path1.addRect(QRectF(pInf, QPointF(1, 1))); + WARNS(addEllipse); path1.addEllipse(QRectF(p1, p2)); + WARNS(addEllipse); path1.addEllipse(QRectF(pInf, QPointF(1, 1))); +#undef WARNS + QCOMPARE(path1, path2); path1.lineTo(QPointF(1, 1)); - QVERIFY(path1 != path2); + QCOMPARE_NE(path1, path2); } #endif // signaling_nan @@ -1415,6 +1459,32 @@ void tst_QPainterPath::intersectionPointOnEdge() QVERIFY(p.intersects(r)); } +void tst_QPainterPath::boundsAtStartPoint() +{ + const QPointF startPoint(10, 10); + const QPainterPath constructedPath(startPoint); + { + const auto boundingRect = constructedPath.boundingRect(); + const auto topLeft = boundingRect.topLeft(); + QCOMPARE(topLeft, startPoint); + QCOMPARE(topLeft, constructedPath.elementAt(0)); + QCOMPARE(boundingRect, constructedPath.controlPointRect()); + } + + QPainterPath defaultPath; + defaultPath.moveTo(startPoint); + { + const auto boundingRect = defaultPath.boundingRect(); + const auto topLeft = boundingRect.topLeft(); + QCOMPARE(topLeft, startPoint); + QCOMPARE(topLeft, defaultPath.elementAt(0)); + QCOMPARE(boundingRect, defaultPath.controlPointRect()); + } + + QCOMPARE(constructedPath.boundingRect(), defaultPath.boundingRect()); + QCOMPARE(constructedPath.controlPointRect(), defaultPath.controlPointRect()); +} + QTEST_APPLESS_MAIN(tst_QPainterPath) #include "tst_qpainterpath.moc" diff --git a/tests/auto/gui/painting/qpainterpathstroker/CMakeLists.txt b/tests/auto/gui/painting/qpainterpathstroker/CMakeLists.txt index f4c301c42e..d30778de3f 100644 --- a/tests/auto/gui/painting/qpainterpathstroker/CMakeLists.txt +++ b/tests/auto/gui/painting/qpainterpathstroker/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qpainterpathstroker.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qpainterpathstroker Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qpainterpathstroker LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qpainterpathstroker SOURCES tst_qpainterpathstroker.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp b/tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp index 3a3f8ff89f..ce80019273 100644 --- a/tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp +++ b/tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/gui/painting/qpathclipper/CMakeLists.txt b/tests/auto/gui/painting/qpathclipper/CMakeLists.txt index 191b1b8a93..2cf25cfdf2 100644 --- a/tests/auto/gui/painting/qpathclipper/CMakeLists.txt +++ b/tests/auto/gui/painting/qpathclipper/CMakeLists.txt @@ -1,4 +1,11 @@ -# Generated from qpathclipper.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_qpathclipper LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() if(NOT QT_FEATURE_private_tests) return() @@ -14,18 +21,15 @@ qt_internal_add_test(tst_qpathclipper tst_qpathclipper.cpp INCLUDE_DIRECTORIES . - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate ) -#### Keys ignored in scope 1:.:.:qpathclipper.pro:<TRUE>: -# _REQUIREMENTS = "qtConfig(private_tests)" - ## Scopes: ##################################################################### qt_internal_extend_target(tst_qpathclipper CONDITION UNIX AND NOT APPLE AND NOT HAIKU AND NOT INTEGRITY - PUBLIC_LIBRARIES + LIBRARIES m ) diff --git a/tests/auto/gui/painting/qpathclipper/pathcompare.h b/tests/auto/gui/painting/qpathclipper/pathcompare.h index d1207cfdc0..593176686e 100644 --- a/tests/auto/gui/painting/qpathclipper/pathcompare.h +++ b/tests/auto/gui/painting/qpathclipper/pathcompare.h @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef PATHCOMPARE_H #define PATHCOMPARE_H diff --git a/tests/auto/gui/painting/qpathclipper/paths.cpp b/tests/auto/gui/painting/qpathclipper/paths.cpp index e6be402df7..7b1486152b 100644 --- a/tests/auto/gui/painting/qpathclipper/paths.cpp +++ b/tests/auto/gui/painting/qpathclipper/paths.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "paths.h" QPainterPath Paths::rect() diff --git a/tests/auto/gui/painting/qpathclipper/paths.h b/tests/auto/gui/painting/qpathclipper/paths.h index 8c421dec2e..73b41d324a 100644 --- a/tests/auto/gui/painting/qpathclipper/paths.h +++ b/tests/auto/gui/painting/qpathclipper/paths.h @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef PATHS_H #define PATHS_H diff --git a/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp b/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp index e93d0f4ba1..c5ef8373fd 100644 --- a/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp +++ b/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "private/qpathclipper_p.h" #include "paths.h" #include "pathcompare.h" @@ -470,15 +470,19 @@ void tst_QPathClipper::clipTest(int subjectIndex, int clipIndex, QPathClipper::O break; } - if (expected != inResult) { - char str[256]; - const char *opStr = - op == QPathClipper::BoolAnd ? "and" : - op == QPathClipper::BoolOr ? "or" : "sub"; - sprintf(str, "Expected: %d, actual: %d, subject: %d, clip: %d, op: %s\n", - int(expected), int(inResult), subjectIndex, clipIndex, opStr); - QFAIL(str); - } + auto failLogger = qScopeGuard([&]{ + qCritical().noquote().nospace() + << "\n\tExpected: " << expected + << "\n\tActual: " << inResult + << "\n\tSubject: " << subjectIndex + << "\n\tClip: " << clipIndex + << "\n\tOp: " << (op == QPathClipper::BoolAnd + ? "and" + : op == QPathClipper::BoolOr + ? "or" : "sub"); + }); + QCOMPARE(inResult, expected); + failLogger.dismiss(); } } @@ -772,7 +776,7 @@ void tst_QPathClipper::testIntersections7() void tst_QPathClipper::testIntersections8() { QPainterPath path1 = Paths::node() * QTransform().translate(100, 50); - QPainterPath path2 = Paths::node() * QTransform().translate(150, 50);; + QPainterPath path2 = Paths::node() * QTransform().translate(150, 50); QVERIFY(path1.intersects(path2)); QVERIFY(path2.intersects(path1)); @@ -820,7 +824,7 @@ void tst_QPathClipper::testIntersections9() QVERIFY(path1.intersects(path2)); QVERIFY(path2.intersects(path1)); - path1 = QPainterPath();; + path1 = QPainterPath(); path2 = QPainterPath(); path1.addRect(QRectF(-1,191, 136, 106)); @@ -828,7 +832,7 @@ void tst_QPathClipper::testIntersections9() QVERIFY(path1.intersects(path2)); QVERIFY(path2.intersects(path1)); - path1 = QPainterPath();; + path1 = QPainterPath(); path2 = QPainterPath(); path1.moveTo(-1 , 143); diff --git a/tests/auto/gui/painting/qpdfwriter/CMakeLists.txt b/tests/auto/gui/painting/qpdfwriter/CMakeLists.txt index c6eb5b1034..3a42d81600 100644 --- a/tests/auto/gui/painting/qpdfwriter/CMakeLists.txt +++ b/tests/auto/gui/painting/qpdfwriter/CMakeLists.txt @@ -1,15 +1,22 @@ -# Generated from qpdfwriter.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qpdfwriter Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qpdfwriter LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qpdfwriter SOURCES tst_qpdfwriter.cpp DEFINES QT_USE_USING_NAMESPACE - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate ) diff --git a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp index aaa0877625..4d6b1f01b9 100644 --- a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp +++ b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtGlobal> diff --git a/tests/auto/gui/painting/qpen/CMakeLists.txt b/tests/auto/gui/painting/qpen/CMakeLists.txt index 321c40fa8f..05fbbfb552 100644 --- a/tests/auto/gui/painting/qpen/CMakeLists.txt +++ b/tests/auto/gui/painting/qpen/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qpen.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qpen Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qpen LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qpen SOURCES tst_qpen.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/painting/qpen/tst_qpen.cpp b/tests/auto/gui/painting/qpen/tst_qpen.cpp index e13a8e3270..b3ff1c76f9 100644 --- a/tests/auto/gui/painting/qpen/tst_qpen.cpp +++ b/tests/auto/gui/painting/qpen/tst_qpen.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/gui/painting/qpolygon/CMakeLists.txt b/tests/auto/gui/painting/qpolygon/CMakeLists.txt index a61529d397..42b108efcd 100644 --- a/tests/auto/gui/painting/qpolygon/CMakeLists.txt +++ b/tests/auto/gui/painting/qpolygon/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qpolygon.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qpolygon Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qpolygon LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qpolygon SOURCES tst_qpolygon.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) @@ -15,6 +22,6 @@ qt_internal_add_test(tst_qpolygon ##################################################################### qt_internal_extend_target(tst_qpolygon CONDITION UNIX AND NOT APPLE AND NOT HAIKU AND NOT INTEGRITY - PUBLIC_LIBRARIES + LIBRARIES m ) diff --git a/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp b/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp index 87dda161d2..cd24135ac6 100644 --- a/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp +++ b/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -168,8 +168,8 @@ void tst_QPolygon::swap() QPolygon p2(QList<QPoint>() << QPoint(0, 0) << QPoint(0, 10) << QPoint(10, 10) << QPoint(10, 0)); p1.swap(p2); - QCOMPARE(p1.count(),4); - QCOMPARE(p2.count(),3); + QCOMPARE(p1.size(),4); + QCOMPARE(p2.size(),3); } void tst_QPolygon::intersections_data() diff --git a/tests/auto/gui/painting/qregion/CMakeLists.txt b/tests/auto/gui/painting/qregion/CMakeLists.txt index 9564e0719e..ba580438cd 100644 --- a/tests/auto/gui/painting/qregion/CMakeLists.txt +++ b/tests/auto/gui/painting/qregion/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qregion.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qregion Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qregion LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qregion SOURCES tst_qregion.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate ) diff --git a/tests/auto/gui/painting/qregion/tst_qregion.cpp b/tests/auto/gui/painting/qregion/tst_qregion.cpp index 14e210a056..934725844a 100644 --- a/tests/auto/gui/painting/qregion/tst_qregion.cpp +++ b/tests/auto/gui/painting/qregion/tst_qregion.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -138,12 +138,15 @@ void tst_QRegion::rects() QRegion region(rect); QVERIFY(region.isEmpty()); QCOMPARE(region.begin(), region.end()); + QVERIFY(region.rects().isEmpty()); } { QRect rect(10, -20, 30, 40); QRegion region(rect); QCOMPARE(region.end(), region.begin() + 1); QCOMPARE(*region.begin(), rect); + QCOMPARE(region.rects().size(), 1); + QCOMPARE(region.rects()[0], rect); } { QRect r(QPoint(10, 10), QPoint(40, 40)); @@ -190,6 +193,7 @@ void tst_QRegion::setRects() QCOMPARE(region, QRegion()); QCOMPARE(region.begin(), region.end()); QVERIFY(!region.boundingRect().isValid()); + QVERIFY(region.rects().isEmpty()); } { QRegion region; @@ -197,12 +201,15 @@ void tst_QRegion::setRects() region.setRects(&rect, 1); QCOMPARE(region.begin(), region.end()); QVERIFY(!region.boundingRect().isValid()); + QVERIFY(region.rects().isEmpty()); } { QRegion region; QRect rect(10, -20, 30, 40); region.setRects(&rect, 1); QCOMPARE(region.end(), region.begin() + 1); + QCOMPARE(region.rects().size(), 1); + QCOMPARE(region.rects()[0], rect); QCOMPARE(*region.begin(), rect); } } @@ -316,10 +323,12 @@ void tst_QRegion::emptyPolygonRegion() QRegion r(pa); QTEST(r.isEmpty(), "isEmpty"); QTEST(int(std::distance(r.begin(), r.end())), "numRects"); - QList<QRect> rects; - std::copy(r.begin(), r.end(), std::back_inserter(rects)); + QList<QRect> rects{r.begin(), r.end()}; QTEST(int(rects.size()), "numRects"); QTEST(rects, "rects"); + const auto span = r.rects(); + rects.assign(span.begin(), span.end()); + QTEST(rects, "rects"); } @@ -862,6 +871,7 @@ void tst_QRegion::isEmpty() QCOMPARE(region, QRegion()); QCOMPARE(region.rectCount(), 0); QCOMPARE(region.boundingRect(), QRect()); + QVERIFY(region.rects().isEmpty()); } void tst_QRegion::regionFromPath() @@ -877,6 +887,10 @@ void tst_QRegion::regionFromPath() QCOMPARE(rgn.begin()[0], QRect(0, 0, 10, 10)); QCOMPARE(rgn.begin()[1], QRect(0, 100, 100, 1000)); + QCOMPARE(rgn.rects().size(), 2); + QCOMPARE(rgn.rects()[0], QRect(0, 0, 10, 10)); + QCOMPARE(rgn.rects()[1], QRect(0, 100, 100, 1000)); + QCOMPARE(rgn.boundingRect(), QRect(0, 0, 100, 1100)); } @@ -893,6 +907,12 @@ void tst_QRegion::regionFromPath() QCOMPARE(rgn.begin()[2], QRect(90, 10, 10, 80)); QCOMPARE(rgn.begin()[3], QRect(0, 90, 100, 10)); + QCOMPARE(rgn.rects().size(), 4); + QCOMPARE(rgn.rects()[0], QRect(0, 0, 100, 10)); + QCOMPARE(rgn.rects()[1], QRect(0, 10, 10, 80)); + QCOMPARE(rgn.rects()[2], QRect(90, 10, 10, 80)); + QCOMPARE(rgn.rects()[3], QRect(0, 90, 100, 10)); + QCOMPARE(rgn.boundingRect(), QRect(0, 0, 100, 100)); } } diff --git a/tests/auto/gui/painting/qtransform/CMakeLists.txt b/tests/auto/gui/painting/qtransform/CMakeLists.txt index 4d50e2cf33..557e5fa742 100644 --- a/tests/auto/gui/painting/qtransform/CMakeLists.txt +++ b/tests/auto/gui/painting/qtransform/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qtransform.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtransform Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtransform LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtransform SOURCES tst_qtransform.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) @@ -15,6 +22,6 @@ qt_internal_add_test(tst_qtransform ##################################################################### qt_internal_extend_target(tst_qtransform CONDITION UNIX AND NOT APPLE AND NOT HAIKU AND NOT INTEGRITY - PUBLIC_LIBRARIES + LIBRARIES m ) diff --git a/tests/auto/gui/painting/qtransform/tst_qtransform.cpp b/tests/auto/gui/painting/qtransform/tst_qtransform.cpp index ecc8f7e4cc..428174bfc6 100644 --- a/tests/auto/gui/painting/qtransform/tst_qtransform.cpp +++ b/tests/auto/gui/painting/qtransform/tst_qtransform.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/gui/platform/CMakeLists.txt b/tests/auto/gui/platform/CMakeLists.txt index fc2d330fd7..4b2cee205d 100644 --- a/tests/auto/gui/platform/CMakeLists.txt +++ b/tests/auto/gui/platform/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + if(QT_FEATURE_xcb) add_subdirectory(qx11info) endif() diff --git a/tests/auto/gui/platform/qx11info/CMakeLists.txt b/tests/auto/gui/platform/qx11info/CMakeLists.txt index c4ce1f91c8..40188f24a0 100644 --- a/tests/auto/gui/platform/qx11info/CMakeLists.txt +++ b/tests/auto/gui/platform/qx11info/CMakeLists.txt @@ -1,7 +1,16 @@ +# 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_qx11info LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qx11info SOURCES tst_qx11info.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::GuiPrivate XCB::XCB ) diff --git a/tests/auto/gui/platform/qx11info/tst_qx11info.cpp b/tests/auto/gui/platform/qx11info/tst_qx11info.cpp index 315dc55069..a4effb07cc 100644 --- a/tests/auto/gui/platform/qx11info/tst_qx11info.cpp +++ b/tests/auto/gui/platform/qx11info/tst_qx11info.cpp @@ -1,6 +1,6 @@ // Copyright (C) 2016 The Qt Company Ltd. // Copyright (C) 2016 David Faure <david.faure@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtGui> #include <QtTest/QtTest> diff --git a/tests/auto/gui/qopengl/CMakeLists.txt b/tests/auto/gui/qopengl/CMakeLists.txt index 3be29695a5..48e07d2878 100644 --- a/tests/auto/gui/qopengl/CMakeLists.txt +++ b/tests/auto/gui/qopengl/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qopengl.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qopengl Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qopengl LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qopengl SOURCES tst_qopengl.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index 4e81af6cf3..af59f3e31a 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtOpenGL/QOpenGLFramebufferObject> #include <QtOpenGL/QOpenGLPaintDevice> @@ -7,7 +7,9 @@ #include <QtOpenGL/qopengltextureblitter.h> #include <QtOpenGL/QOpenGLVertexArrayObject> #include <QtOpenGL/QOpenGLBuffer> -#include <QtOpenGL/QOpenGLFunctions_4_2_Core> +#if !QT_CONFIG(opengles2) +# include <QtOpenGL/QOpenGLFunctions_4_2_Core> +#endif #include <QtOpenGL/QOpenGLVersionFunctionsFactory> #include <QtGui/private/qopenglcontext_p.h> #include <QtGui/QOpenGLFunctions> @@ -618,6 +620,10 @@ static bool supportsInternalFboFormat(QOpenGLContext *ctx, int glFormat) void tst_QOpenGL::fboRenderingRGB30() { +#ifdef Q_OS_ANDROID + if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) + QSKIP("Fails on Android 12 (QTBUG-105738)"); +#endif #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(__x86_64__) QSKIP("QTBUG-22617"); #endif @@ -1586,6 +1592,13 @@ void tst_QOpenGL::bufferCreate() buf.allocate(128); QCOMPARE(buf.size(), 128); + { + QOpenGLBuffer moved = std::move(buf); + QCOMPARE_EQ(moved.isCreated(), true); + QCOMPARE_EQ(moved.size(), 128); + buf = std::move(moved); + } + buf.release(); buf.destroy(); @@ -1623,8 +1636,6 @@ void tst_QOpenGL::bufferMapRange() buf.unmap(); p = (char *) buf.mapRange(0, sizeof(data), QOpenGLBuffer::RangeRead); - if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) - QEXPECT_FAIL("", "This fails on Wayland, see QTBUG-100918.", Abort); QVERIFY(!strcmp(p, "sOMe data")); buf.unmap(); diff --git a/tests/auto/gui/qopenglconfig/CMakeLists.txt b/tests/auto/gui/qopenglconfig/CMakeLists.txt index d193e15c2e..ea70afd20a 100644 --- a/tests/auto/gui/qopenglconfig/CMakeLists.txt +++ b/tests/auto/gui/qopenglconfig/CMakeLists.txt @@ -1,16 +1,23 @@ -# Generated from qopenglconfig.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qopenglconfig Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qopenglconfig LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data list(APPEND test_data "buglist.json") qt_internal_add_test(tst_qopenglconfig SOURCES tst_qopenglconfig.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp b/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp index 2572c47096..423f9419da 100644 --- a/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp +++ b/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtGui/QOpenGLFunctions> #include <QtGui/QScreen> diff --git a/tests/auto/gui/qvulkan/CMakeLists.txt b/tests/auto/gui/qvulkan/CMakeLists.txt index 7cca165ed2..d4e2dd6f87 100644 --- a/tests/auto/gui/qvulkan/CMakeLists.txt +++ b/tests/auto/gui/qvulkan/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qvulkan.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qvulkan Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qvulkan LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qvulkan SOURCES tst_qvulkan.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/qvulkan/tst_qvulkan.cpp b/tests/auto/gui/qvulkan/tst_qvulkan.cpp index f01777a1e9..c8f5c27481 100644 --- a/tests/auto/gui/qvulkan/tst_qvulkan.cpp +++ b/tests/auto/gui/qvulkan/tst_qvulkan.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtGui/QVulkanInstance> #include <QtGui/QVulkanFunctions> @@ -88,6 +88,10 @@ void tst_QVulkan::vulkanCheckSupported() void tst_QVulkan::vulkan11() { +#ifdef Q_OS_ANDROID + if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) + QSKIP("Fails on Android 12 (QTBUG-105739)"); +#endif #if VK_VERSION_1_1 QVulkanInstance inst; if (inst.supportedApiVersion() < QVersionNumber(1, 1)) @@ -137,15 +141,17 @@ void tst_QVulkan::vulkan11() QByteArray deviceUuid = QByteArray::fromRawData((const char *) deviceIdProps.deviceUUID, VK_UUID_SIZE).toHex(); QByteArray driverUuid = QByteArray::fromRawData((const char *) deviceIdProps.driverUUID, VK_UUID_SIZE).toHex(); qDebug() << "deviceUUID" << deviceUuid << "driverUUID" << driverUuid; + const bool deviceUuidZero = std::find_if(deviceUuid.cbegin(), deviceUuid.cend(), [](char c) -> bool { return c; }) == deviceUuid.cend(); + const bool driverUuidZero = std::find_if(driverUuid.cbegin(), driverUuid.cend(), [](char c) -> bool { return c; }) == driverUuid.cend(); // deviceUUID cannot be all zero as per spec - bool seenNonZero = false; - for (int i = 0; i < VK_UUID_SIZE; ++i) { - if (deviceIdProps.deviceUUID[i]) { - seenNonZero = true; - break; - } + if (!driverUuidZero) { + // ...but then there are implementations such as some + // versions of Mesa lavapipe, that returns all zeroes + // for both uuids. skip the check if the driver uuid + // was zero too. + // https://gitlab.freedesktop.org/mesa/mesa/-/issues/5875 + QVERIFY(!deviceUuidZero); } - QVERIFY(seenNonZero); } else { qDebug("Physical device is not Vulkan 1.1 capable"); } @@ -160,6 +166,10 @@ void tst_QVulkan::vulkan11() void tst_QVulkan::vulkanPlainWindow() { +#ifdef Q_OS_ANDROID + QSKIP("Fails on Android 7 emulator (QTBUG-108328)"); +#endif + QVulkanInstance inst; if (!inst.create()) QSKIP("Vulkan init failed; skip"); @@ -447,6 +457,10 @@ void tst_QVulkan::vulkanWindowRenderer() void tst_QVulkan::vulkanWindowGrab() { +#ifdef Q_OS_ANDROID + if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) + QSKIP("Fails on Android 12 (QTBUG-105739)"); +#endif QVulkanInstance inst; inst.setLayers(QByteArrayList() << "VK_LAYER_KHRONOS_validation"); if (!inst.create()) diff --git a/tests/auto/gui/rhi/CMakeLists.txt b/tests/auto/gui/rhi/CMakeLists.txt index 786e121f00..898a67d2dc 100644 --- a/tests/auto/gui/rhi/CMakeLists.txt +++ b/tests/auto/gui/rhi/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from rhi.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause add_subdirectory(qshader) add_subdirectory(qrhi) diff --git a/tests/auto/gui/rhi/qrhi/BLACKLIST b/tests/auto/gui/rhi/qrhi/BLACKLIST index dc2bc57077..b3284f8979 100644 --- a/tests/auto/gui/rhi/qrhi/BLACKLIST +++ b/tests/auto/gui/rhi/qrhi/BLACKLIST @@ -17,3 +17,5 @@ android android [renderToRgb10Texture] android +[tessellation vulkan] +android diff --git a/tests/auto/gui/rhi/qrhi/CMakeLists.txt b/tests/auto/gui/rhi/qrhi/CMakeLists.txt index e0e97f6509..3b0d643060 100644 --- a/tests/auto/gui/rhi/qrhi/CMakeLists.txt +++ b/tests/auto/gui/rhi/qrhi/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from qrhi.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qrhi Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qrhi LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Resources: file(GLOB_RECURSE qrhi_resource_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" @@ -13,7 +20,7 @@ file(GLOB_RECURSE qrhi_resource_files qt_internal_add_test(tst_qrhi SOURCES tst_qrhi.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate TESTDATA ${qrhi_resource_files} diff --git a/tests/auto/gui/rhi/qrhi/data/buildshaders.bat b/tests/auto/gui/rhi/qrhi/data/buildshaders.bat index 68d9bb8ae7..fe40459719 100644 --- a/tests/auto/gui/rhi/qrhi/data/buildshaders.bat +++ b/tests/auto/gui/rhi/qrhi/data/buildshaders.bat @@ -1,5 +1,5 @@ :: Copyright (C) 2019 The Qt Company Ltd. -:: SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +:: SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o simple.vert.qsb simple.vert qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o simple.frag.qsb simple.frag @@ -11,3 +11,20 @@ qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o textured.vert.qsb textured. qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o textured.frag.qsb textured.frag qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o textured_multiubuf.vert.qsb textured_multiubuf.vert qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o textured_multiubuf.frag.qsb textured_multiubuf.frag +qsb --glsl 320es,410 --msl 12 --msltess simpletess.vert -o simpletess.vert.qsb +qsb --glsl 320es,410 --msl 12 --tess-mode triangles simpletess.tesc -o simpletess.tesc.qsb +qsb --glsl 320es,410 --msl 12 --tess-vertex-count 3 simpletess.tese -o simpletess.tese.qsb +qsb --glsl 320es,410 --msl 12 simpletess.frag -o simpletess.frag.qsb +qsb --glsl 310es,430 --msl 12 --hlsl 50 storagebuffer.comp -o storagebuffer.comp.qsb +qsb --glsl 320es,430 --msl 12 --msltess storagebuffer_runtime.vert -o storagebuffer_runtime.vert.qsb +qsb --glsl 320es,430 --msl 12 --tess-mode triangles storagebuffer_runtime.tesc -o storagebuffer_runtime.tesc.qsb +qsb --glsl 320es,430 --msl 12 --tess-vertex-count 3 storagebuffer_runtime.tese -o storagebuffer_runtime.tese.qsb +qsb --glsl 320es,430 --msl 12 storagebuffer_runtime.frag -o storagebuffer_runtime.frag.qsb +qsb --glsl 320es,430 --hlsl 50 -c --msl 12 storagebuffer_runtime.comp -o storagebuffer_runtime.comp.qsb +qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o half.vert.qsb half.vert +qsb --glsl 320es,430 --msl 21 --msltess tessinterfaceblocks.vert -o tessinterfaceblocks.vert.qsb +qsb --glsl 320es,430 --msl 21 --tess-mode triangles tessinterfaceblocks.tesc -o tessinterfaceblocks.tesc.qsb +qsb --glsl 320es,430 --msl 21 --tess-vertex-count 3 tessinterfaceblocks.tese -o tessinterfaceblocks.tese.qsb +qsb --glsl 320es,430 --msl 21 simpletess.frag -o tessinterfaceblocks.frag.qsb +qsb --view-count 2 --glsl "300 es,330" --hlsl 61 -c --msl 12 multiview.vert -o multiview.vert.qsb +qsb --glsl "300 es,330" --hlsl 61 -c --msl 12 multiview.frag -o multiview.frag.qsb diff --git a/tests/auto/gui/rhi/qrhi/data/half.vert b/tests/auto/gui/rhi/qrhi/data/half.vert new file mode 100644 index 0000000000..b503201351 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/half.vert @@ -0,0 +1,10 @@ +#version 440 + +layout(location = 0) in vec3 position; + +out gl_PerVertex { vec4 gl_Position; }; + +void main() +{ + gl_Position = vec4(position, 1.0); +} diff --git a/tests/auto/gui/rhi/qrhi/data/half.vert.qsb b/tests/auto/gui/rhi/qrhi/data/half.vert.qsb Binary files differnew file mode 100644 index 0000000000..fb8680024a --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/half.vert.qsb diff --git a/tests/auto/gui/rhi/qrhi/data/multiview.frag b/tests/auto/gui/rhi/qrhi/data/multiview.frag new file mode 100644 index 0000000000..375587662f --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/multiview.frag @@ -0,0 +1,10 @@ +#version 440 + +layout(location = 0) in vec3 v_color; + +layout(location = 0) out vec4 fragColor; + +void main() +{ + fragColor = vec4(v_color, 1.0); +} diff --git a/tests/auto/gui/rhi/qrhi/data/multiview.frag.qsb b/tests/auto/gui/rhi/qrhi/data/multiview.frag.qsb Binary files differnew file mode 100644 index 0000000000..db8133f12e --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/multiview.frag.qsb diff --git a/tests/auto/gui/rhi/qrhi/data/multiview.vert b/tests/auto/gui/rhi/qrhi/data/multiview.vert new file mode 100644 index 0000000000..b9c9e5a704 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/multiview.vert @@ -0,0 +1,18 @@ +#version 440 +#extension GL_EXT_multiview : require + +layout(location = 0) in vec4 pos; +layout(location = 1) in vec3 color; + +layout(location = 0) out vec3 v_color; + +layout(std140, binding = 0) uniform buf +{ + mat4 mvp[2]; +}; + +void main() +{ + v_color = color; + gl_Position = mvp[gl_ViewIndex] * pos; +} diff --git a/tests/auto/gui/rhi/qrhi/data/multiview.vert.qsb b/tests/auto/gui/rhi/qrhi/data/multiview.vert.qsb Binary files differnew file mode 100644 index 0000000000..cf1f67f58f --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/multiview.vert.qsb diff --git a/tests/auto/gui/rhi/qrhi/data/simpletess.frag b/tests/auto/gui/rhi/qrhi/data/simpletess.frag new file mode 100644 index 0000000000..375587662f --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/simpletess.frag @@ -0,0 +1,10 @@ +#version 440 + +layout(location = 0) in vec3 v_color; + +layout(location = 0) out vec4 fragColor; + +void main() +{ + fragColor = vec4(v_color, 1.0); +} diff --git a/tests/auto/gui/rhi/qrhi/data/simpletess.frag.qsb b/tests/auto/gui/rhi/qrhi/data/simpletess.frag.qsb Binary files differnew file mode 100644 index 0000000000..0f42103ac5 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/simpletess.frag.qsb diff --git a/tests/auto/gui/rhi/qrhi/data/simpletess.tesc b/tests/auto/gui/rhi/qrhi/data/simpletess.tesc new file mode 100644 index 0000000000..e192fc77c7 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/simpletess.tesc @@ -0,0 +1,22 @@ +#version 440 + +layout(vertices = 3) out; + +layout(location = 0) in vec3 inColor[]; +layout(location = 0) out vec3 outColor[]; +layout(location = 1) patch out float a_per_patch_output_variable; + +void main() +{ + if (gl_InvocationID == 0) { + gl_TessLevelOuter[0] = 4.0; + gl_TessLevelOuter[1] = 4.0; + gl_TessLevelOuter[2] = 4.0; + + gl_TessLevelInner[0] = 4.0; + } + + gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position; + outColor[gl_InvocationID] = inColor[gl_InvocationID]; + a_per_patch_output_variable = 1.0; +} diff --git a/tests/auto/gui/rhi/qrhi/data/simpletess.tesc.qsb b/tests/auto/gui/rhi/qrhi/data/simpletess.tesc.qsb Binary files differnew file mode 100644 index 0000000000..8c98d92c46 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/simpletess.tesc.qsb diff --git a/tests/auto/gui/rhi/qrhi/data/simpletess.tese b/tests/auto/gui/rhi/qrhi/data/simpletess.tese new file mode 100644 index 0000000000..17b348635a --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/simpletess.tese @@ -0,0 +1,17 @@ +#version 440 + +layout(triangles, fractional_odd_spacing, ccw) in; + +layout(location = 0) in vec3 inColor[]; +layout(location = 0) out vec3 outColor; +layout(location = 1) patch in float a_per_patch_output_variable; + +layout(std140, binding = 0) uniform buf { + mat4 mvp; +}; + +void main() +{ + gl_Position = mvp * ((gl_TessCoord.x * gl_in[0].gl_Position) + (gl_TessCoord.y * gl_in[1].gl_Position) + (gl_TessCoord.z * gl_in[2].gl_Position)); + outColor = gl_TessCoord.x * inColor[0] + gl_TessCoord.y * inColor[1] + gl_TessCoord.z * inColor[2] * a_per_patch_output_variable; +} diff --git a/tests/auto/gui/rhi/qrhi/data/simpletess.tese.qsb b/tests/auto/gui/rhi/qrhi/data/simpletess.tese.qsb Binary files differnew file mode 100644 index 0000000000..8aa7632717 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/simpletess.tese.qsb diff --git a/tests/auto/gui/rhi/qrhi/data/simpletess.vert b/tests/auto/gui/rhi/qrhi/data/simpletess.vert new file mode 100644 index 0000000000..3838d2f3bb --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/simpletess.vert @@ -0,0 +1,12 @@ +#version 440 + +layout(location = 0) in vec3 position; +layout(location = 1) in vec3 color; + +layout(location = 0) out vec3 v_color; + +void main() +{ + gl_Position = vec4(position, 1.0); + v_color = color; +} diff --git a/tests/auto/gui/rhi/qrhi/data/simpletess.vert.qsb b/tests/auto/gui/rhi/qrhi/data/simpletess.vert.qsb Binary files differnew file mode 100644 index 0000000000..ee90983e0b --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/simpletess.vert.qsb diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer.comp b/tests/auto/gui/rhi/qrhi/data/storagebuffer.comp new file mode 100644 index 0000000000..ffa0bc7004 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer.comp @@ -0,0 +1,28 @@ +#version 430 +layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in; + + +layout (binding = 0, std430) readonly buffer toGpu +{ + float _float; + vec2 _vec2; + vec3 _vec3; + vec4 _vec4; +}; + +layout (binding = 1, std140) buffer fromGpu +{ + int _int; + ivec2 _ivec2; + ivec3 _ivec3; + ivec4 _ivec4; +}; + +void main() +{ + _int = int(_float); + _ivec2 = ivec2(_vec2); + _ivec3 = ivec3(_vec3); + _ivec4 = ivec4(_vec4); +} + diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer.comp.qsb b/tests/auto/gui/rhi/qrhi/data/storagebuffer.comp.qsb Binary files differnew file mode 100644 index 0000000000..b02f541cc5 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer.comp.qsb diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.comp b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.comp new file mode 100644 index 0000000000..d36f5426bc --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.comp @@ -0,0 +1,25 @@ +#version 430 + +layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in; + +layout (binding = 0, std430) buffer toGpu +{ + float _float[]; +}; + + +layout (binding = 1, std140) buffer fromGpu +{ + int _int[]; +}; + +void main() +{ + int length = min(_float.length(), _int.length()); + + for (int i = 0; i < length; ++i) + _int[i] = int(_float[i]); + +} + + diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.comp.qsb b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.comp.qsb Binary files differnew file mode 100644 index 0000000000..b4c43ecc9b --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.comp.qsb diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.frag b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.frag new file mode 100644 index 0000000000..2e45a5f62a --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.frag @@ -0,0 +1,33 @@ +#version 450 + +layout (location = 0) out vec4 fragColor; + +layout (std430, binding = 1) readonly buffer ssboG +{ + float g[]; +}; + +layout (std430, binding = 2) readonly buffer ssboB +{ + float b[]; +}; + +layout (std430, binding = 6) readonly buffer ssboR +{ + float r[]; +}; + +layout (std430, binding = 3) readonly buffer ssbo3 +{ + vec4 _vec4; +}; + +void main() +{ + + // some OpenGL implementations will optimize out the buffer variables if we don't use them + // resulting in a .length() of 0. + float a = (r[0]+g[0]+b[0])>0?1:1; + + fragColor = a * vec4(r.length(), g.length(), b.length(), 255)/vec4(255); +} diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.frag.qsb b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.frag.qsb Binary files differnew file mode 100644 index 0000000000..53fc9a1906 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.frag.qsb diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tesc b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tesc new file mode 100644 index 0000000000..56060285d2 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tesc @@ -0,0 +1,42 @@ +#version 450 + +layout(vertices = 3) out; + + +layout (std430, binding = 7) readonly buffer ssbo7 +{ + float float7[]; +}; + +layout (std430, binding = 8) readonly buffer ssbo8 +{ + float float8[]; +}; + +layout (std430, binding = 9) readonly buffer ssbo9 +{ + float float9[]; +}; + +layout (std430, binding = 10) readonly buffer ssbo10 +{ + float float10[]; +}; + +void main() +{ + + // some OpenGL implementations will optimize out the buffer variables if we don't use them + // resulting in a .length() of 0 + float a = float7[0] == 0 && float8[0] == 0 && float9[0] == 0 && float10[0] == 0 ? 1 : 1; + + if (gl_InvocationID == 0) { + gl_TessLevelOuter[0] = float7.length() * a; + gl_TessLevelOuter[1] = float8.length() * a; + gl_TessLevelOuter[2] = float9.length() * a; + gl_TessLevelInner[0] = float10.length() * a; + } + + gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position; + +} diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tesc.qsb b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tesc.qsb Binary files differnew file mode 100644 index 0000000000..e48aa0269c --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tesc.qsb diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tese b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tese new file mode 100644 index 0000000000..a8bec13561 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tese @@ -0,0 +1,39 @@ +#version 450 + +layout(triangles, fractional_odd_spacing, ccw) in; + +layout (std140, binding = 6) uniform unused0 +{ + int unused; +}u0; + +layout (binding = 0) uniform u +{ + mat4 matrix; +}; + +layout (std430, binding = 5) readonly buffer ssbo5 +{ + float _float[]; +}; + +layout (std430, binding = 8) readonly buffer ssbo8 +{ + float float8[]; +}; + +layout (std430, binding = 1) readonly buffer unused1 +{ + int unused[]; +}u1; + + +void main() +{ + // some OpenGL implementations will optimize out the buffer variables if we don't use them + // resulting in a .length() of 0 + float a = _float[0] == 0 && float8[0] == 1 ? 1 : 1; + + if(_float.length() == 64) + gl_Position = a * matrix * ((gl_TessCoord.x * gl_in[0].gl_Position) + (gl_TessCoord.y * gl_in[1].gl_Position) + (gl_TessCoord.z * gl_in[2].gl_Position)) * (float8.length()==2?1:0); +} diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tese.qsb b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tese.qsb Binary files differnew file mode 100644 index 0000000000..23a433b5ae --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tese.qsb diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.vert b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.vert new file mode 100644 index 0000000000..b3ac10efea --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.vert @@ -0,0 +1,48 @@ +#version 450 + +layout (location = 0) in vec3 position; + +layout (std140, binding = 6) uniform unused0 +{ + int unused; +}u0; + +layout (binding = 0) uniform u +{ + mat4 matrix; +}; + +layout (std430, binding = 5) readonly buffer ssbo5 +{ + float _float[]; +}; + +layout (std140, binding = 3) readonly buffer ssbo3 +{ + vec4 _vec4; +}; + +layout (std430, binding = 4) readonly buffer ssbo1 +{ + bool _bool[]; +}; + +layout (std430, binding = 1) readonly buffer unused1 +{ + int unused[]; +}u1; + + +void main() +{ + + // some OpenGL implementations will optimize out the buffer variables if we don't use them + // resulting in a .length() of 0 + float a = _float[0] == 0 && _bool[0] ? 1 : 1; + + gl_Position = vec4(0); + + if(_bool.length() == 32) + gl_Position = a * matrix * vec4(position*_vec4.xyz, _float.length() == 64 ? 1.0 : 0.0); + +} diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.vert.qsb b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.vert.qsb Binary files differnew file mode 100644 index 0000000000..8b1cff52fd --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.vert.qsb diff --git a/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.frag.qsb b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.frag.qsb Binary files differnew file mode 100644 index 0000000000..7eda4bed2d --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.frag.qsb diff --git a/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tesc b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tesc new file mode 100644 index 0000000000..92a2dc28fa --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tesc @@ -0,0 +1,56 @@ +#version 440 + +layout(vertices = 3) out; + +layout(location = 4) in VertOut +{ + vec3 v_color; + int a; + float b; +}vOut[]; + +layout(location = 5) out TescOutA { + vec3 color; + int id; +}tcOutA[]; + +layout(location = 10) out TescOutB { + vec2 some; + int other[3]; + vec3 variables; +}tcOutB[]; + +layout(location = 2) patch out TescOutC { + vec3 stuff; + float more_stuff; +}tcOutC; + +void main() +{ + // tesc builtin outputs + gl_TessLevelOuter[0] = 1.0; + gl_TessLevelOuter[1] = 2.0; + gl_TessLevelOuter[2] = 3.0; + gl_TessLevelOuter[3] = 4.0; + gl_TessLevelInner[0] = 5.0; + gl_TessLevelInner[1] = 6.0; + + gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position; + gl_out[gl_InvocationID].gl_PointSize = 10 + gl_InvocationID; + gl_out[gl_InvocationID].gl_ClipDistance[0] = 20.0 + gl_InvocationID; + gl_out[gl_InvocationID].gl_ClipDistance[1] = 40.0 + gl_InvocationID; + gl_out[gl_InvocationID].gl_ClipDistance[2] = 60.0 + gl_InvocationID; + gl_out[gl_InvocationID].gl_ClipDistance[3] = 80.0 + gl_InvocationID; + gl_out[gl_InvocationID].gl_ClipDistance[4] = 100.0 + gl_InvocationID; + + // outputs + tcOutA[gl_InvocationID].color = vOut[gl_InvocationID].v_color; + tcOutA[gl_InvocationID].id = gl_InvocationID + 91; + tcOutB[gl_InvocationID].some = vec2(gl_InvocationID, vOut[gl_InvocationID].a); + tcOutB[gl_InvocationID].other[0] = gl_PrimitiveID + 10; + tcOutB[gl_InvocationID].other[1] = gl_PrimitiveID + 20; + tcOutB[gl_InvocationID].other[2] = gl_PrimitiveID + 30; + tcOutB[gl_InvocationID].variables = vec3(3.0f, vOut[gl_InvocationID].b, 17.0f); + tcOutC.stuff = vec3(1.0, 2.0, 3.0); + tcOutC.more_stuff = 4.0; +} diff --git a/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tesc.qsb b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tesc.qsb Binary files differnew file mode 100644 index 0000000000..b503d596c6 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tesc.qsb diff --git a/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tese b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tese new file mode 100644 index 0000000000..05430a5f63 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tese @@ -0,0 +1,96 @@ +#version 440 + +layout(triangles, fractional_odd_spacing, ccw) in; + +layout(std140, binding = 0) uniform buf { + mat4 mvp; +}; + +layout(location = 5) in TescOutA { + vec3 color; + int id; +}tcOutA[]; + +layout(location = 10) in TescOutB { + vec2 some; + int other[3]; + vec3 variables; +}tcOutB[]; + +layout(location = 2) patch in TescOutC { + vec3 stuff; + float more_stuff; +}tcOutC; + +layout(location = 0) out vec3 outColor; + +struct A { + vec3 color; + int id; +}; + +struct B { + vec2 some; + int other[3]; + vec3 variables; +}; + +struct C { + vec3 stuff; + float more_stuff; +}; + +struct Element { + A a[3]; + B b[3]; + C c; + vec4 tesslevelOuter; + vec2 tessLevelInner; + float pointSize[3]; + float clipDistance[3][5]; + vec3 tessCoord; + int patchVerticesIn; + int primitiveID; +}; + +layout(std430, binding = 1) buffer result { + int count; + Element elements[]; +}; + +void main() +{ + gl_Position = mvp * ((gl_TessCoord.x * gl_in[0].gl_Position) + (gl_TessCoord.y * gl_in[1].gl_Position) + (gl_TessCoord.z * gl_in[2].gl_Position)); + outColor = gl_TessCoord.x * tcOutA[0].color + gl_TessCoord.y * tcOutA[1].color + gl_TessCoord.z * tcOutA[2].color; + + count = 1; + + elements[gl_PrimitiveID].c.stuff = tcOutC.stuff; + elements[gl_PrimitiveID].c.more_stuff = tcOutC.more_stuff; + elements[gl_PrimitiveID].tesslevelOuter = vec4(gl_TessLevelOuter[0], gl_TessLevelOuter[1], gl_TessLevelOuter[2], gl_TessLevelOuter[3]); + elements[gl_PrimitiveID].tessLevelInner = vec2(gl_TessLevelInner[0], gl_TessLevelInner[1]); + + for (int i = 0; i < 3; ++i) { + + elements[gl_PrimitiveID].a[i].color = tcOutA[i].color; + elements[gl_PrimitiveID].a[i].id = tcOutA[i].id; + + elements[gl_PrimitiveID].b[i].some = tcOutB[i].some; + elements[gl_PrimitiveID].b[i].other = tcOutB[i].other; + elements[gl_PrimitiveID].b[i].variables = tcOutB[i].variables; + + elements[gl_PrimitiveID].pointSize[i] = gl_in[i].gl_PointSize; + elements[gl_PrimitiveID].clipDistance[i][0] = gl_in[i].gl_ClipDistance[0]; + elements[gl_PrimitiveID].clipDistance[i][1] = gl_in[i].gl_ClipDistance[1]; + elements[gl_PrimitiveID].clipDistance[i][2] = gl_in[i].gl_ClipDistance[2]; + elements[gl_PrimitiveID].clipDistance[i][3] = gl_in[i].gl_ClipDistance[3]; + elements[gl_PrimitiveID].clipDistance[i][4] = gl_in[i].gl_ClipDistance[4]; + + } + + elements[gl_PrimitiveID].tessCoord = gl_TessCoord; + elements[gl_PrimitiveID].patchVerticesIn = 3; + elements[gl_PrimitiveID].primitiveID = gl_PrimitiveID; + +} + diff --git a/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tese.qsb b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tese.qsb Binary files differnew file mode 100644 index 0000000000..898bda454a --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tese.qsb diff --git a/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.vert b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.vert new file mode 100644 index 0000000000..7c722bb374 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.vert @@ -0,0 +1,20 @@ +#version 440 + +layout(location = 0) in vec3 position; +layout(location = 1) in vec3 color; + + +layout(location = 4) out VertOut +{ + vec3 v_color; + int a; + float b; +}; + +void main() +{ + gl_Position = vec4(position, 1.0); + v_color = color; + a = gl_VertexIndex; + b = 13.0f + gl_VertexIndex; +} diff --git a/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.vert.qsb b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.vert.qsb Binary files differnew file mode 100644 index 0000000000..07384d643c --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.vert.qsb diff --git a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp index 6409c43bc4..8929b69cec 100644 --- a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp +++ b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2019 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QThread> @@ -9,31 +9,28 @@ #include <qrgbafloat.h> #include <qrgba64.h> -#include <QtGui/private/qrhi_p.h> -#include <QtGui/private/qrhi_p_p.h> -#include <QtGui/private/qrhinull_p.h> +#include <private/qrhi_p.h> #if QT_CONFIG(opengl) # include <QOpenGLContext> # include <QOpenGLFunctions> -# include <QtGui/private/qrhigles2_p.h> +# include <QtGui/private/qguiapplication_p.h> +# include <qpa/qplatformintegration.h> # define TST_GL #endif #if QT_CONFIG(vulkan) # include <QVulkanInstance> # include <QVulkanFunctions> -# include <QtGui/private/qrhivulkan_p.h> # define TST_VK #endif #ifdef Q_OS_WIN -#include <QtGui/private/qrhid3d11_p.h> # define TST_D3D11 +# define TST_D3D12 #endif -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) -# include <QtGui/private/qrhimetal_p.h> +#if QT_CONFIG(metal) # define TST_MTL #endif @@ -49,9 +46,10 @@ private slots: void cleanupTestCase(); void rhiTestData(); - void rhiTestDataOpenGL(); void create_data(); void create(); + void stats_data(); + void stats(); void nativeHandles_data(); void nativeHandles(); void nativeHandlesImportVulkan(); @@ -73,6 +71,8 @@ private slots: void resourceUpdateBatchTextureRawDataStride(); void resourceUpdateBatchLotsOfResources_data(); void resourceUpdateBatchLotsOfResources(); + void resourceUpdateBatchBetweenFrames_data(); + void resourceUpdateBatchBetweenFrames(); void invalidPipeline_data(); void invalidPipeline(); void srbLayoutCompatibility_data(); @@ -83,6 +83,8 @@ private slots: void renderPassDescriptorCompatibility(); void renderPassDescriptorClone_data(); void renderPassDescriptorClone(); + void textureWithSampleCount_data(); + void textureWithSampleCount(); void renderToTextureSimple_data(); void renderToTextureSimple(); @@ -104,12 +106,16 @@ private slots: void renderToTextureTexturedQuadAllDynamicBuffers(); void renderToTextureDeferredSrb_data(); void renderToTextureDeferredSrb(); + void renderToTextureDeferredUpdateSamplerInSrb_data(); + void renderToTextureDeferredUpdateSamplerInSrb(); void renderToTextureMultipleUniformBuffersAndDynamicOffset_data(); void renderToTextureMultipleUniformBuffersAndDynamicOffset(); void renderToTextureSrbReuse_data(); void renderToTextureSrbReuse(); void renderToTextureIndexedDraw_data(); void renderToTextureIndexedDraw(); + void renderToTextureArrayMultiView_data(); + void renderToTextureArrayMultiView(); void renderToWindowSimple_data(); void renderToWindowSimple(); void finishWithinSwapchainFrame_data(); @@ -121,12 +127,12 @@ private slots: void pipelineCache_data(); void pipelineCache(); - void textureImportOpenGL_data(); void textureImportOpenGL(); - void renderbufferImportOpenGL_data(); void renderbufferImportOpenGL(); void threeDimTexture_data(); void threeDimTexture(); + void oneDimTexture_data(); + void oneDimTexture(); void leakedResourceDestroy_data(); void leakedResourceDestroy(); @@ -135,6 +141,22 @@ private slots: void renderToRgb10Texture_data(); void renderToRgb10Texture(); + void tessellation_data(); + void tessellation(); + + void tessellationInterfaceBlocks_data(); + void tessellationInterfaceBlocks(); + + void storageBuffer_data(); + void storageBuffer(); + void storageBufferRuntimeSizeCompute_data(); + void storageBufferRuntimeSizeCompute(); + void storageBufferRuntimeSizeGraphics_data(); + void storageBufferRuntimeSizeGraphics(); + + void halfPrecisionAttributes_data(); + void halfPrecisionAttributes(); + private: void setWindowType(QWindow *window, QRhi::Implementation impl); @@ -147,7 +169,10 @@ private: QRhiVulkanInitParams vk; #endif #ifdef TST_D3D11 - QRhiD3D11InitParams d3d; + QRhiD3D11InitParams d3d11; +#endif +#ifdef TST_D3D12 + QRhiD3D12InitParams d3d12; #endif #ifdef TST_MTL QRhiMetalInitParams mtl; @@ -163,6 +188,12 @@ private: void tst_QRhi::initTestCase() { #ifdef TST_GL + QSurfaceFormat fmt; + fmt.setDepthBufferSize(24); + fmt.setStencilBufferSize(8); + QSurfaceFormat::setDefaultFormat(fmt); + + initParams.gl.format = QSurfaceFormat::defaultFormat(); fallbackSurface = QRhiGles2InitParams::newFallbackSurface(); initParams.gl.fallbackSurface = fallbackSurface; #endif @@ -172,7 +203,7 @@ void tst_QRhi::initTestCase() if (supportedVersion >= QVersionNumber(1, 2)) vulkanInstance.setApiVersion(QVersionNumber(1, 2)); else if (supportedVersion >= QVersionNumber(1, 1)) - vulkanInstance.setApiVersion(QVersionNumber(1, 2)); + vulkanInstance.setApiVersion(QVersionNumber(1, 1)); vulkanInstance.setLayers({ "VK_LAYER_KHRONOS_validation" }); vulkanInstance.setExtensions(QRhiVulkanInitParams::preferredInstanceExtensions()); vulkanInstance.create(); @@ -180,7 +211,10 @@ void tst_QRhi::initTestCase() #endif #ifdef TST_D3D11 - initParams.d3d.enableDebugLayer = true; + initParams.d3d11.enableDebugLayer = true; +#endif +#ifdef TST_D3D12 + initParams.d3d12.enableDebugLayer = true; #endif } @@ -203,30 +237,24 @@ void tst_QRhi::rhiTestData() QTest::newRow("Null") << QRhi::Null << static_cast<QRhiInitParams *>(&initParams.null); #endif #ifdef TST_GL - QTest::newRow("OpenGL") << QRhi::OpenGLES2 << static_cast<QRhiInitParams *>(&initParams.gl); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)) + QTest::newRow("OpenGL") << QRhi::OpenGLES2 << static_cast<QRhiInitParams *>(&initParams.gl); #endif #ifdef TST_VK if (vulkanInstance.isValid()) QTest::newRow("Vulkan") << QRhi::Vulkan << static_cast<QRhiInitParams *>(&initParams.vk); #endif #ifdef TST_D3D11 - QTest::newRow("Direct3D 11") << QRhi::D3D11 << static_cast<QRhiInitParams *>(&initParams.d3d); + QTest::newRow("Direct3D 11") << QRhi::D3D11 << static_cast<QRhiInitParams *>(&initParams.d3d11); +#endif +#ifdef TST_D3D12 + QTest::newRow("Direct3D 12") << QRhi::D3D12 << static_cast<QRhiInitParams *>(&initParams.d3d12); #endif #ifdef TST_MTL QTest::newRow("Metal") << QRhi::Metal << static_cast<QRhiInitParams *>(&initParams.mtl); #endif } -void tst_QRhi::rhiTestDataOpenGL() -{ - QTest::addColumn<QRhi::Implementation>("impl"); - QTest::addColumn<QRhiInitParams *>("initParams"); - -#ifdef TST_GL - QTest::newRow("OpenGL") << QRhi::OpenGLES2 << static_cast<QRhiInitParams *>(&initParams.gl); -#endif -} - void tst_QRhi::create_data() { rhiTestData(); @@ -255,6 +283,7 @@ void tst_QRhi::create() QCOMPARE(rhi->backend(), impl); QVERIFY(strcmp(rhi->backendName(), "")); + QVERIFY(!strcmp(rhi->backendName(), QRhi::backendName(rhi->backend()))); QVERIFY(!rhi->driverInfo().deviceName.isEmpty()); QCOMPARE(rhi->thread(), QThread::currentThread()); @@ -289,8 +318,13 @@ void tst_QRhi::create() QVERIFY(resUpd); resUpd->release(); - QVERIFY(!rhi->supportedSampleCounts().isEmpty()); - QVERIFY(rhi->supportedSampleCounts().contains(1)); + const QVector<int> supportedSampleCounts = rhi->supportedSampleCounts(); + QVERIFY(!supportedSampleCounts.isEmpty()); + QVERIFY(supportedSampleCounts.contains(1)); + for (int i = 1; i < supportedSampleCounts.count(); ++i) { + // Verify the list is sorted. Internally the backends rely on this. + QVERIFY(supportedSampleCounts[i] > supportedSampleCounts[i - 1]); + } QVERIFY(rhi->ubufAlignment() > 0); QCOMPARE(rhi->ubufAligned(123), aligned(123, rhi->ubufAlignment())); @@ -383,7 +417,15 @@ void tst_QRhi::create() QRhi::Tessellation, QRhi::GeometryShader, QRhi::TextureArrayRange, - QRhi::NonFillPolygonMode + QRhi::NonFillPolygonMode, + QRhi::OneDimensionalTextures, + QRhi::OneDimensionalTextureMipmaps, + QRhi::HalfAttributes, + QRhi::RenderToOneDimensionalTexture, + QRhi::ThreeDimensionalTextureMipmaps, + QRhi::MultiView, + QRhi::TextureViewFormat, + QRhi::ResolveDepthStencil }; for (size_t i = 0; i <sizeof(features) / sizeof(QRhi::Feature); ++i) rhi->isFeatureSupported(features[i]); @@ -399,6 +441,38 @@ void tst_QRhi::create() } } +void tst_QRhi::stats_data() +{ + rhiTestData(); +} + +void tst_QRhi::stats() +{ + QFETCH(QRhi::Implementation, impl); + QFETCH(QRhiInitParams *, initParams); + + QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr)); + if (!rhi) + QSKIP("QRhi could not be created, skipping testing statistics getter"); + + QRhiStats stats = rhi->statistics(); + qDebug() << stats; + QCOMPARE(stats.totalPipelineCreationTime, 0); + + if (impl == QRhi::Vulkan) { + QScopedPointer<QRhiBuffer> buf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, 32768)); + QVERIFY(buf->create()); + QScopedPointer<QRhiTexture> tex(rhi->newTexture(QRhiTexture::RGBA8, QSize(1024, 1024))); + QVERIFY(tex->create()); + + stats = rhi->statistics(); + qDebug() << stats; + QVERIFY(stats.allocCount > 0); + QVERIFY(stats.blockCount > 0); + QVERIFY(stats.usedBytes > 0); + } +} + void tst_QRhi::nativeHandles_data() { rhiTestData(); @@ -425,10 +499,10 @@ void tst_QRhi::nativeHandles() case QRhi::Vulkan: { const QRhiVulkanNativeHandles *vkHandles = static_cast<const QRhiVulkanNativeHandles *>(rhiHandles); + QVERIFY(vkHandles->inst); + QCOMPARE(vkHandles->inst, &vulkanInstance); QVERIFY(vkHandles->physDev); QVERIFY(vkHandles->dev); - QVERIFY(vkHandles->gfxQueueFamilyIdx >= 0); - QVERIFY(vkHandles->gfxQueueIdx >= 0); QVERIFY(vkHandles->gfxQueue); QVERIFY(vkHandles->vmemAllocator); } @@ -458,6 +532,17 @@ void tst_QRhi::nativeHandles() } break; #endif +#ifdef TST_D3D12 + case QRhi::D3D12: + { + const QRhiD3D12NativeHandles *d3dHandles = static_cast<const QRhiD3D12NativeHandles *>(rhiHandles); + QVERIFY(d3dHandles->dev); + QVERIFY(d3dHandles->minimumFeatureLevel > 0); + QVERIFY(d3dHandles->adapterLuidLow || d3dHandles->adapterLuidHigh); + QVERIFY(d3dHandles->commandQueue); + } + break; +#endif #ifdef TST_MTL case QRhi::Metal: { @@ -502,6 +587,10 @@ void tst_QRhi::nativeHandles() case QRhi::D3D11: break; #endif +#ifdef TST_D3D12 + case QRhi::D3D12: + break; +#endif #ifdef TST_MTL case QRhi::Metal: { @@ -561,6 +650,10 @@ void tst_QRhi::nativeHandles() case QRhi::D3D11: break; #endif +#ifdef TST_D3D12 + case QRhi::D3D12: + break; +#endif #ifdef TST_MTL case QRhi::Metal: break; @@ -628,7 +721,7 @@ void tst_QRhi::nativeHandlesImportVulkan() void tst_QRhi::nativeHandlesImportD3D11() { #ifdef TST_D3D11 - QScopedPointer<QRhi> rhi(QRhi::create(QRhi::D3D11, &initParams.d3d, QRhi::Flags(), nullptr)); + QScopedPointer<QRhi> rhi(QRhi::create(QRhi::D3D11, &initParams.d3d11, QRhi::Flags(), nullptr)); if (!rhi) QSKIP("QRhi could not be created, skipping testing D3D11 native handle import"); @@ -640,7 +733,7 @@ void tst_QRhi::nativeHandlesImportD3D11() h.featureLevel = 0; // see if these are queried as expected, even when not provided h.adapterLuidLow = 0; h.adapterLuidHigh = 0; - QScopedPointer<QRhi> adoptingRhi(QRhi::create(QRhi::D3D11, &initParams.d3d, QRhi::Flags(), &h)); + QScopedPointer<QRhi> adoptingRhi(QRhi::create(QRhi::D3D11, &initParams.d3d11, QRhi::Flags(), &h)); QVERIFY(adoptingRhi); const QRhiD3D11NativeHandles *newNativeHandles = static_cast<const QRhiD3D11NativeHandles *>(adoptingRhi->nativeHandles()); QCOMPARE(newNativeHandles->dev, nativeHandles->dev); @@ -655,7 +748,7 @@ void tst_QRhi::nativeHandlesImportD3D11() QRhiD3D11NativeHandles h = *nativeHandles; h.dev = nullptr; h.context = nullptr; - QScopedPointer<QRhi> adoptingRhi(QRhi::create(QRhi::D3D11, &initParams.d3d, QRhi::Flags(), &h)); + QScopedPointer<QRhi> adoptingRhi(QRhi::create(QRhi::D3D11, &initParams.d3d11, QRhi::Flags(), &h)); QVERIFY(adoptingRhi); const QRhiD3D11NativeHandles *newNativeHandles = static_cast<const QRhiD3D11NativeHandles *>(adoptingRhi->nativeHandles()); QVERIFY(newNativeHandles->dev != nativeHandles->dev); @@ -675,7 +768,6 @@ void tst_QRhi::nativeHandlesImportOpenGL() #ifdef TST_GL QRhiGles2NativeHandles h; QScopedPointer<QOpenGLContext> ctx(new QOpenGLContext); - ctx->setFormat(QRhiGles2InitParams::adjustedFormat()); if (!ctx->create()) QSKIP("No OpenGL context, skipping OpenGL-specific test"); h.context = ctx.data(); @@ -741,6 +833,14 @@ void tst_QRhi::nativeTexture() } break; #endif +#ifdef TST_D3D12 + case QRhi::D3D12: + { + auto *texture = reinterpret_cast<void *>(nativeTex.object); + QVERIFY(texture); + } + break; +#endif #ifdef TST_MTL case QRhi::Metal: { @@ -816,6 +916,18 @@ void tst_QRhi::nativeBuffer() } break; #endif + #ifdef TST_D3D12 + case QRhi::D3D12: + { + QVERIFY(nativeBuf.slotCount >= 1); // always backed by native buffers + for (int i = 0; i < nativeBuf.slotCount; ++i) { + auto *buffer = static_cast<void * const *>(nativeBuf.objects[i]); + QVERIFY(buffer); + QVERIFY(*buffer); + } + } + break; + #endif #ifdef TST_MTL case QRhi::Metal: { @@ -880,7 +992,7 @@ void tst_QRhi::resourceUpdateBatchBuffer() batch->updateDynamicBuffer(dynamicBuffer.data(), 10, bufferSize - 10, a.constData()); batch->updateDynamicBuffer(dynamicBuffer.data(), 0, 12, b.constData()); - QRhiBufferReadbackResult readResult; + QRhiReadbackResult readResult; bool readCompleted = false; readResult.completed = [&readCompleted] { readCompleted = true; }; batch->readBackBuffer(dynamicBuffer.data(), 5, 10, &readResult); @@ -907,7 +1019,7 @@ void tst_QRhi::resourceUpdateBatchBuffer() batch->uploadStaticBuffer(dynamicBuffer.data(), 10, bufferSize - 10, a.constData()); batch->uploadStaticBuffer(dynamicBuffer.data(), 0, 12, b.constData()); - QRhiBufferReadbackResult readResult; + QRhiReadbackResult readResult; bool readCompleted = false; readResult.completed = [&readCompleted] { readCompleted = true; }; @@ -1016,7 +1128,7 @@ void tst_QRhi::resourceUpdateBatchRGBATextureUpload() QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch(); - QRhiTextureUploadEntry upload(0, 0, { image.constBits(), int(image.sizeInBytes()) }); + QRhiTextureUploadEntry upload(0, 0, { image.constBits(), quint32(image.sizeInBytes()) }); QRhiTextureUploadDescription uploadDesc(upload); batch->uploadTexture(texture.data(), uploadDesc); @@ -1104,8 +1216,8 @@ void tst_QRhi::resourceUpdateBatchRGBATextureUpload() // SourceTopLeft is not supported for non-QImage-based uploads. const QImage im = image.copy(QRect(greenRectPos, copySize)); QRhiTextureSubresourceUploadDescription desc; - desc.setData(QByteArray::fromRawData(reinterpret_cast<const char *>(im.constBits()), - int(im.sizeInBytes()))); + desc.setData(QByteArray::fromRawData(reinterpret_cast<const char *>(im.constBits()), im.sizeInBytes())); + desc.setSourceSize(copySize); desc.setDestinationTopLeft(QPoint(gap, gap)); @@ -1429,6 +1541,86 @@ void tst_QRhi::resourceUpdateBatchLotsOfResources() submitResourceUpdates(rhi.data(), b); } +void tst_QRhi::resourceUpdateBatchBetweenFrames_data() +{ + rhiTestData(); +} + +void tst_QRhi::resourceUpdateBatchBetweenFrames() +{ + QFETCH(QRhi::Implementation, impl); + QFETCH(QRhiInitParams *, initParams); + + QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr)); + if (!rhi) + QSKIP("QRhi could not be created, skipping testing resource updates"); + + QImage image(128, 128, QImage::Format_RGBA8888_Premultiplied); + image.fill(Qt::red); + static const float bufferData[64] = {}; + + QRhiCommandBuffer *cb = nullptr; + QRhi::FrameOpResult result = rhi->beginOffscreenFrame(&cb); + QVERIFY(result == QRhi::FrameOpSuccess); + QVERIFY(cb); + + static const int TEXTURE_COUNT = 123; + static const int BUFFER_COUNT = 456; + + QRhiResourceUpdateBatch *u = rhi->nextResourceUpdateBatch(); + std::vector<std::unique_ptr<QRhiTexture>> textures; + std::vector<std::unique_ptr<QRhiBuffer>> buffers; + + for (int i = 0; i < TEXTURE_COUNT; ++i) { + std::unique_ptr<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8, + image.size(), + 1, + QRhiTexture::UsedAsTransferSource)); + QVERIFY(texture->create()); + u->uploadTexture(texture.get(), image); + textures.push_back(std::move(texture)); + } + + for (int i = 0; i < BUFFER_COUNT; ++i) { + std::unique_ptr<QRhiBuffer> buffer(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, 256)); + QVERIFY(buffer->create()); + u->uploadStaticBuffer(buffer.get(), bufferData); + buffers.push_back(std::move(buffer)); + } + + rhi->endOffscreenFrame(); + cb = nullptr; + + // 'u' stays valid, commit it in another frame + + result = rhi->beginOffscreenFrame(&cb); + QVERIFY(result == QRhi::FrameOpSuccess); + QVERIFY(cb); + + cb->resourceUpdate(u); // this should work + + rhi->endOffscreenFrame(); + + u = rhi->nextResourceUpdateBatch(); + QRhiReadbackResult readResult; + bool readCompleted = false; + readResult.completed = [&readCompleted] { readCompleted = true; }; + u->readBackTexture(textures[5].get(), &readResult); + + QVERIFY(submitResourceUpdates(rhi.data(), u)); + QVERIFY(readCompleted); + QCOMPARE(readResult.format, QRhiTexture::RGBA8); + QCOMPARE(readResult.pixelSize, image.size()); + + QImage wrapperImage(reinterpret_cast<const uchar *>(readResult.data.constData()), + readResult.pixelSize.width(), readResult.pixelSize.height(), + QImage::Format_RGBA8888_Premultiplied); + for (int y = 0; y < image.height(); ++y) { + for (int x = 0; x < image.width(); ++x) + QCOMPARE(wrapperImage.pixel(x, y), qRgba(255, 0, 0, 255)); + } +} + static QShader loadShader(const char *name) { QFile f(QString::fromUtf8(name)); @@ -2917,6 +3109,147 @@ void tst_QRhi::renderToTextureDeferredSrb() QCOMPARE(result.pixel(4, 227), empty); } +void tst_QRhi::renderToTextureDeferredUpdateSamplerInSrb_data() +{ + rhiTestData(); +} + +void tst_QRhi::renderToTextureDeferredUpdateSamplerInSrb() +{ + QFETCH(QRhi::Implementation, impl); + QFETCH(QRhiInitParams *, initParams); + + QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr)); + if (!rhi) + QSKIP("QRhi could not be created, skipping testing rendering"); + + QImage inputImage; + inputImage.load(QLatin1String(":/data/qt256.png")); + QVERIFY(!inputImage.isNull()); + + QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8, inputImage.size(), 1, + QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource)); + QVERIFY(texture->create()); + + QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ texture.data() })); + QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor()); + rt->setRenderPassDescriptor(rpDesc.data()); + QVERIFY(rt->create()); + + QRhiCommandBuffer *cb = nullptr; + QVERIFY(rhi->beginOffscreenFrame(&cb) == QRhi::FrameOpSuccess); + QVERIFY(cb); + + QRhiResourceUpdateBatch *updates = rhi->nextResourceUpdateBatch(); + + QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(quadVerticesUvs))); + QVERIFY(vbuf->create()); + updates->uploadStaticBuffer(vbuf.data(), quadVerticesUvs); + + QScopedPointer<QRhiTexture> inputTexture(rhi->newTexture(QRhiTexture::RGBA8, inputImage.size())); + QVERIFY(inputTexture->create()); + updates->uploadTexture(inputTexture.data(), inputImage); + + QScopedPointer<QRhiSampler> sampler1(rhi->newSampler(QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::Linear, + QRhiSampler::Repeat, QRhiSampler::Repeat)); + QVERIFY(sampler1->create()); + QScopedPointer<QRhiSampler> sampler2(rhi->newSampler(QRhiSampler::Nearest, QRhiSampler::Nearest, QRhiSampler::None, + QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge)); + QVERIFY(sampler2->create()); + + QScopedPointer<QRhiBuffer> ubuf(rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64 + 4)); + QVERIFY(ubuf->create()); + + QMatrix4x4 matrix; + updates->updateDynamicBuffer(ubuf.data(), 0, 64, matrix.constData()); + float opacity = 0.5f; + updates->updateDynamicBuffer(ubuf.data(), 64, 4, &opacity); + + const QRhiShaderResourceBinding::StageFlags commonVisibility = QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage; + QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings()); + srb->setBindings({ + QRhiShaderResourceBinding::uniformBuffer(0, commonVisibility, ubuf.data()), + QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, inputTexture.data(), sampler1.data()) + }); + QVERIFY(srb->create()); + + QScopedPointer<QRhiGraphicsPipeline> pipeline(rhi->newGraphicsPipeline()); + pipeline->setTopology(QRhiGraphicsPipeline::TriangleStrip); + QShader vs = loadShader(":/data/textured.vert.qsb"); + QVERIFY(vs.isValid()); + QShader fs = loadShader(":/data/textured.frag.qsb"); + QVERIFY(fs.isValid()); + pipeline->setShaderStages({ { QRhiShaderStage::Vertex, vs }, { QRhiShaderStage::Fragment, fs } }); + QRhiVertexInputLayout inputLayout; + inputLayout.setBindings({ { 4 * sizeof(float) } }); + inputLayout.setAttributes({ + { 0, 0, QRhiVertexInputAttribute::Float2, 0 }, + { 0, 1, QRhiVertexInputAttribute::Float2, 2 * sizeof(float) } + }); + pipeline->setVertexInputLayout(inputLayout); + pipeline->setShaderResourceBindings(srb.data()); + pipeline->setRenderPassDescriptor(rpDesc.data()); + + QVERIFY(pipeline->create()); + + // Now update the sampler to a different one, so if the pipeline->create() + // baked in static samplers somewhere (with 3D APIs where that's a thing), + // based on sampler1, that's now all invalid. + srb->setBindings({ + QRhiShaderResourceBinding::uniformBuffer(0, commonVisibility, ubuf.data()), + QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, inputTexture.data(), sampler2.data()) + }); + srb->updateResources(); // now it references sampler2, not sampler1 + + cb->beginPass(rt.data(), Qt::black, { 1.0f, 0 }, updates); + cb->setGraphicsPipeline(pipeline.data()); + cb->setShaderResources(); + cb->setViewport({ 0, 0, float(texture->pixelSize().width()), float(texture->pixelSize().height()) }); + QRhiCommandBuffer::VertexInput vbindings(vbuf.data(), 0); + cb->setVertexInput(0, 1, &vbindings); + cb->draw(4); + + QRhiReadbackResult readResult; + QImage result; + readResult.completed = [&readResult, &result] { + result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()), + readResult.pixelSize.width(), readResult.pixelSize.height(), + QImage::Format_RGBA8888_Premultiplied); + }; + QRhiResourceUpdateBatch *readbackBatch = rhi->nextResourceUpdateBatch(); + readbackBatch->readBackTexture({ texture.data() }, &readResult); + cb->endPass(readbackBatch); + + rhi->endOffscreenFrame(); + + QVERIFY(!result.isNull()); + + if (impl == QRhi::Null) + return; + + if (rhi->isYUpInFramebuffer() != rhi->isYUpInNDC()) + result = std::move(result).mirrored(); + + // opacity 0.5 (premultiplied) + static const auto checkSemiWhite = [](const QRgb &c) { + QRgb semiWhite127 = qPremultiply(qRgba(255, 255, 255, 127)); + QRgb semiWhite128 = qPremultiply(qRgba(255, 255, 255, 128)); + return c == semiWhite127 || c == semiWhite128; + }; + QVERIFY(checkSemiWhite(result.pixel(79, 77))); + QVERIFY(checkSemiWhite(result.pixel(124, 81))); + QVERIFY(checkSemiWhite(result.pixel(128, 149))); + QVERIFY(checkSemiWhite(result.pixel(120, 189))); + QVERIFY(checkSemiWhite(result.pixel(116, 185))); + QVERIFY(checkSemiWhite(result.pixel(191, 172))); + + QRgb empty = qRgba(0, 0, 0, 0); + QCOMPARE(result.pixel(11, 45), empty); + QCOMPARE(result.pixel(246, 202), empty); + QCOMPARE(result.pixel(130, 18), empty); + QCOMPARE(result.pixel(4, 227), empty); +} + void tst_QRhi::renderToTextureMultipleUniformBuffersAndDynamicOffset_data() { rhiTestData(); @@ -3234,7 +3567,6 @@ void tst_QRhi::setWindowType(QWindow *window, QRhi::Implementation impl) switch (impl) { #ifdef TST_GL case QRhi::OpenGLES2: - window->setFormat(QRhiGles2InitParams::adjustedFormat()); window->setSurfaceType(QSurface::OpenGLSurface); break; #endif @@ -3375,6 +3707,182 @@ void tst_QRhi::renderToTextureIndexedDraw() QVERIFY(redCount > blueCount); } +void tst_QRhi::renderToTextureArrayMultiView_data() +{ + rhiTestData(); +} + +void tst_QRhi::renderToTextureArrayMultiView() +{ + QFETCH(QRhi::Implementation, impl); + QFETCH(QRhiInitParams *, initParams); + + QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr)); + if (!rhi) + QSKIP("QRhi could not be created, skipping testing rendering"); + + if (!rhi->isFeatureSupported(QRhi::MultiView)) + QSKIP("Multiview not supported, skipping testing on this backend"); + + if (rhi->backend() == QRhi::Vulkan && rhi->driverInfo().deviceType == QRhiDriverInfo::CpuDevice) + QSKIP("lavapipe does not like multiview, skip for now"); + + for (int sampleCount : rhi->supportedSampleCounts()) { + const QSize outputSize(1920, 1080); + QRhiTexture::Flags textureFlags = QRhiTexture::RenderTarget; + if (sampleCount <= 1) + textureFlags |= QRhiTexture::UsedAsTransferSource; + QScopedPointer<QRhiTexture> texture(rhi->newTextureArray(QRhiTexture::RGBA8, 2, outputSize, sampleCount, textureFlags)); + QVERIFY(texture->create()); + + // exercise a depth-stencil buffer as well, not that the triangle needs it; note that this also needs to be a two-layer texture array + QScopedPointer<QRhiTexture> ds(rhi->newTextureArray(QRhiTexture::D24S8, 2, outputSize, sampleCount, QRhiTexture::RenderTarget)); + QVERIFY(ds->create()); + + QScopedPointer<QRhiTexture> resolveTexture; + if (sampleCount > 1) { + resolveTexture.reset(rhi->newTextureArray(QRhiTexture::RGBA8, 2, outputSize, 1, QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource)); + QVERIFY(resolveTexture->create()); + } + + QRhiColorAttachment multiViewAtt(texture.get()); + multiViewAtt.setMultiViewCount(2); + if (sampleCount > 1) + multiViewAtt.setResolveTexture(resolveTexture.get()); + + QRhiTextureRenderTargetDescription rtDesc(multiViewAtt); + rtDesc.setDepthTexture(ds.get()); + + QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget(rtDesc)); + QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor()); + rt->setRenderPassDescriptor(rpDesc.data()); + QVERIFY(rt->create()); + + QRhiCommandBuffer *cb = nullptr; + QVERIFY(rhi->beginOffscreenFrame(&cb) == QRhi::FrameOpSuccess); + QVERIFY(cb); + + QRhiResourceUpdateBatch *updates = rhi->nextResourceUpdateBatch(); + + static float triangleData[] = { + 0.0f, 0.5f, 1.0f, 0.0f, 0.0f, + -0.5f, -0.5f, 0.0f, 1.0f, 0.0f, + 0.5f, -0.5f, 0.0f, 0.0f, 1.0f + }; + + QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(triangleData))); + QVERIFY(vbuf->create()); + updates->uploadStaticBuffer(vbuf.data(), triangleData); + + QScopedPointer<QRhiBuffer> ubuf(rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 128)); // mat4 mvp[2] + QVERIFY(ubuf->create()); + + QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings()); + srb->setBindings({ + QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, ubuf.get()) + }); + QVERIFY(srb->create()); + + QScopedPointer<QRhiGraphicsPipeline> ps(rhi->newGraphicsPipeline()); + ps->setShaderStages({ + { QRhiShaderStage::Vertex, loadShader(":/data/multiview.vert.qsb") }, + { QRhiShaderStage::Fragment, loadShader(":/data/multiview.frag.qsb") } + }); + ps->setMultiViewCount(2); // the view count must be set both on the render target and the pipeline + QRhiVertexInputLayout inputLayout; + inputLayout.setBindings({ + { 5 * sizeof(float) } + }); + inputLayout.setAttributes({ + { 0, 0, QRhiVertexInputAttribute::Float2, 0 }, + { 0, 1, QRhiVertexInputAttribute::Float3, quint32(2 * sizeof(float)) } + }); + ps->setDepthTest(true); + ps->setDepthWrite(true); + ps->setSampleCount(sampleCount); + ps->setVertexInputLayout(inputLayout); + ps->setShaderResourceBindings(srb.get()); + ps->setRenderPassDescriptor(rpDesc.get()); + QVERIFY(ps->create()); + + QMatrix4x4 mvp = rhi->clipSpaceCorrMatrix(); + mvp.perspective(45.0f, outputSize.width() / float(outputSize.height()), 0.01f, 1000.0f); + mvp.translate(0, 0, -2); + mvp.rotate(90, 0, 0, 1); // point left + updates->updateDynamicBuffer(ubuf.get(), 0, 64, mvp.constData()); + mvp.rotate(-180, 0, 0, 1); // point right + updates->updateDynamicBuffer(ubuf.get(), 64, 64, mvp.constData()); + + cb->beginPass(rt.data(), Qt::black, { 1.0f, 0 }, updates); + cb->setGraphicsPipeline(ps.data()); + cb->setShaderResources(); + cb->setViewport({ 0, 0, float(outputSize.width()), float(outputSize.height()) }); + QRhiCommandBuffer::VertexInput vbindings(vbuf.data(), 0); + cb->setVertexInput(0, 1, &vbindings); + cb->draw(3); + + QRhiResourceUpdateBatch *readbackBatch = rhi->nextResourceUpdateBatch(); + QRhiReadbackResult readResult[2]; + QRhiReadbackDescription readbackDesc; + if (sampleCount > 1) + readbackDesc.setTexture(resolveTexture.get()); + else + readbackDesc.setTexture(texture.get()); + readbackDesc.setLayer(0); + readbackBatch->readBackTexture(readbackDesc, &readResult[0]); + readbackDesc.setLayer(1); + readbackBatch->readBackTexture(readbackDesc, &readResult[1]); + + cb->endPass(readbackBatch); + + rhi->endOffscreenFrame(); + + if (rhi->backend() == QRhi::Null) + QSKIP("No real content with Null backend, skipping multiview content check"); + + // both readbacks should be finished now due to using offscreen frames + + QImage image0 = QImage(reinterpret_cast<const uchar *>(readResult[0].data.constData()), + readResult[0].pixelSize.width(), readResult[0].pixelSize.height(), + QImage::Format_RGBA8888); + if (rhi->isYUpInFramebuffer()) // note that we used clipSpaceCorrMatrix + image0 = image0.mirrored(); + + QImage image1 = QImage(reinterpret_cast<const uchar *>(readResult[1].data.constData()), + readResult[1].pixelSize.width(), readResult[1].pixelSize.height(), + QImage::Format_RGBA8888); + if (rhi->isYUpInFramebuffer()) + image1 = image1.mirrored(); + + QVERIFY(!image0.isNull()); + QVERIFY(!image1.isNull()); + + // image0 should have a triangle rotated so that it points left with the red + // tip. image1 should have a triangle rotated so that it points right with + // the red tip. Both are centered, so we will check in range 0..width/2 for + // image0 and width/2..width-1 for image1 to see if the red-enough pixels + // are present. + + int y = image0.height() / 2; + int n = 0; + for (int x = 0; x < image0.width() / 2; ++x) { + QRgb c = image0.pixel(x, y); + if (qRed(c) > 250 && qGreen(c) < 10 && qBlue(c) < 10) + ++n; + } + QVERIFY(n >= 10); + + y = image1.height() / 2; + n = 0; + for (int x = image1.width() / 2; x < image1.width(); ++x) { + QRgb c = image1.pixel(x, y); + if (qRed(c) > 250 && qGreen(c) < 10 && qBlue(c) < 10) + ++n; + } + QVERIFY(n >= 10); + } +} + void tst_QRhi::renderToWindowSimple_data() { rhiTestData(); @@ -3629,7 +4137,7 @@ void tst_QRhi::resourceUpdateBatchBufferTextureWithSwapchainFrames() const char *b = "abcdefghi"; bool readCompleted = false; - QRhiBufferReadbackResult readResult; + QRhiReadbackResult readResult; readResult.completed = [&readCompleted] { readCompleted = true; }; QRhiReadbackResult texReadResult; texReadResult.completed = [&readCompleted] { readCompleted = true; }; @@ -3903,7 +4411,7 @@ void tst_QRhi::srbLayoutCompatibility() QVERIFY(srb2->isLayoutCompatible(srb1.data())); QCOMPARE(srb1->serializedLayoutDescription(), srb2->serializedLayoutDescription()); - QVERIFY(srb1->serializedLayoutDescription().count() == 0); + QVERIFY(srb1->serializedLayoutDescription().size() == 0); } // different count (not compatible) @@ -3921,8 +4429,8 @@ void tst_QRhi::srbLayoutCompatibility() QVERIFY(!srb2->isLayoutCompatible(srb1.data())); QVERIFY(srb1->serializedLayoutDescription() != srb2->serializedLayoutDescription()); - QVERIFY(srb1->serializedLayoutDescription().count() == 0); - QVERIFY(srb2->serializedLayoutDescription().count() == 1 * QRhiShaderResourceBinding::LAYOUT_DESC_ENTRIES_PER_BINDING); + QVERIFY(srb1->serializedLayoutDescription().size() == 0); + QVERIFY(srb2->serializedLayoutDescription().size() == 1 * QRhiShaderResourceBinding::LAYOUT_DESC_ENTRIES_PER_BINDING); } // full match (compatible) @@ -3947,7 +4455,7 @@ void tst_QRhi::srbLayoutCompatibility() QVERIFY(!srb1->serializedLayoutDescription().isEmpty()); QVERIFY(!srb2->serializedLayoutDescription().isEmpty()); QCOMPARE(srb1->serializedLayoutDescription(), srb2->serializedLayoutDescription()); - QVERIFY(srb1->serializedLayoutDescription().count() == 2 * QRhiShaderResourceBinding::LAYOUT_DESC_ENTRIES_PER_BINDING); + QVERIFY(srb1->serializedLayoutDescription().size() == 2 * QRhiShaderResourceBinding::LAYOUT_DESC_ENTRIES_PER_BINDING); // see what we would get if a binding list got serialized "manually", without pulling it out from the srb after building // (the results should be identical) @@ -4262,6 +4770,59 @@ void tst_QRhi::renderPassDescriptorCompatibility() } else { qDebug("Skipping texture format dependent tests"); } + + if (rhi->isFeatureSupported(QRhi::MultiView)) { + { + QScopedPointer<QRhiTexture> texArr(rhi->newTextureArray(QRhiTexture::RGBA8, 2, QSize(512, 512), 1, QRhiTexture::RenderTarget)); + QVERIFY(texArr->create()); + QRhiColorAttachment multiViewAtt(texArr.data()); + multiViewAtt.setMultiViewCount(2); + QRhiTextureRenderTargetDescription rtDesc(multiViewAtt); + QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget(rtDesc)); + QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor()); + rt->setRenderPassDescriptor(rpDesc.data()); + QVERIFY(rt->create()); + + QScopedPointer<QRhiTextureRenderTarget> rt2(rhi->newTextureRenderTarget(rtDesc)); + QScopedPointer<QRhiRenderPassDescriptor> rpDesc2(rt2->newCompatibleRenderPassDescriptor()); + rt2->setRenderPassDescriptor(rpDesc2.data()); + QVERIFY(rt2->create()); + + QVERIFY(rpDesc->isCompatible(rpDesc2.data())); + QVERIFY(rpDesc2->isCompatible(rpDesc.data())); + QCOMPARE(rpDesc->serializedFormat(), rpDesc2->serializedFormat()); + + QScopedPointer<QRhiRenderPassDescriptor> rpDescClone(rpDesc->newCompatibleRenderPassDescriptor()); + QVERIFY(rpDesc->isCompatible(rpDescClone.data())); + QVERIFY(rpDesc2->isCompatible(rpDescClone.data())); + QCOMPARE(rpDesc->serializedFormat(), rpDescClone->serializedFormat()); + + // With Vulkan the multiViewCount really matters since it is baked + // in to underlying native object (VkRenderPass). Verify that the + // compatibility check fails when the view count differs. Other + // backends cannot do this test since they will likely report the + // rps being compatible regardless. + if (impl == QRhi::Vulkan) { + QRhiColorAttachment nonMultiViewAtt(texArr.data()); + QRhiTextureRenderTargetDescription rtDesc3(nonMultiViewAtt); + QScopedPointer<QRhiTextureRenderTarget> rt3(rhi->newTextureRenderTarget(rtDesc3)); + QScopedPointer<QRhiRenderPassDescriptor> rpDesc3(rt3->newCompatibleRenderPassDescriptor()); + rt3->setRenderPassDescriptor(rpDesc3.data()); + QVERIFY(rt3->create()); + + QVERIFY(!rpDesc->isCompatible(rpDesc3.data())); + QVERIFY(!rpDesc2->isCompatible(rpDesc3.data())); + QVERIFY(rpDesc->serializedFormat() != rpDesc3->serializedFormat()); + + QScopedPointer<QRhiRenderPassDescriptor> rpDesc3Clone(rpDesc3->newCompatibleRenderPassDescriptor()); + QVERIFY(!rpDesc->isCompatible(rpDesc3Clone.data())); + QVERIFY(!rpDesc2->isCompatible(rpDesc3Clone.data())); + QVERIFY(rpDesc->serializedFormat() != rpDesc3Clone->serializedFormat()); + } + } + } else { + qDebug("Skipping multiview dependent tests"); + } } void tst_QRhi::renderPassDescriptorClone_data() @@ -4379,22 +4940,67 @@ void tst_QRhi::pipelineCache() } } -void tst_QRhi::textureImportOpenGL_data() +void tst_QRhi::textureWithSampleCount_data() { - rhiTestDataOpenGL(); + rhiTestData(); } -void tst_QRhi::textureImportOpenGL() +void tst_QRhi::textureWithSampleCount() { QFETCH(QRhi::Implementation, impl); - if (impl != QRhi::OpenGLES2) - QSKIP("Skipping OpenGL-dependent test"); - -#ifdef TST_GL QFETCH(QRhiInitParams *, initParams); QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr)); if (!rhi) + QSKIP("QRhi could not be created, skipping testing renderpass descriptors"); + + if (!rhi->isFeatureSupported(QRhi::MultisampleTexture)) + QSKIP("No multisample texture support with this backend, skipping"); + + { + QScopedPointer<QRhiTexture> tex(rhi->newTexture(QRhiTexture::RGBA8, QSize(512, 512), 1)); + QVERIFY(tex->create()); + } + + // Ensure 0 is accepted the same way as 1. + { + QScopedPointer<QRhiTexture> tex(rhi->newTexture(QRhiTexture::RGBA8, QSize(512, 512), 0)); + QVERIFY(tex->create()); + } + + // Note that we intentionally do not pass in RenderTarget in flags. Where + // matters for create(), the backend is expected to act as if it was + // specified whenever samples > 1. (in practice it does not make sense to not + // have the flag for an msaa texture, but we only care about create() here) + + // Pick the commonly supported sample count of 4. + { + QScopedPointer<QRhiTexture> tex(rhi->newTexture(QRhiTexture::RGBA8, QSize(512, 512), 4)); + QVERIFY(tex->create()); + } + + // Now a bogus value that is typically in-between the supported values. + { + QScopedPointer<QRhiTexture> tex(rhi->newTexture(QRhiTexture::RGBA8, QSize(512, 512), 3)); + QVERIFY(tex->create()); + } + + // Now a bogus value that is out of range. + { + QScopedPointer<QRhiTexture> tex(rhi->newTexture(QRhiTexture::RGBA8, QSize(512, 512), 123)); + QVERIFY(tex->create()); + } +} + + +void tst_QRhi::textureImportOpenGL() +{ +#ifdef TST_GL + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)) + QSKIP("Skipping OpenGL-dependent test"); + + QScopedPointer<QRhi> rhi(QRhi::create(QRhi::OpenGLES2, &initParams.gl, QRhi::Flags(), nullptr)); + if (!rhi) QSKIP("QRhi could not be created, skipping testing native texture"); QVERIFY(rhi->makeThreadLocalNativeContextCurrent()); @@ -4433,21 +5039,13 @@ void tst_QRhi::textureImportOpenGL() #endif } -void tst_QRhi::renderbufferImportOpenGL_data() -{ - rhiTestDataOpenGL(); -} - void tst_QRhi::renderbufferImportOpenGL() { - QFETCH(QRhi::Implementation, impl); - if (impl != QRhi::OpenGLES2) - QSKIP("Skipping OpenGL-dependent test"); - #ifdef TST_GL - QFETCH(QRhiInitParams *, initParams); + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)) + QSKIP("Skipping OpenGL-dependent test"); - QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr)); + QScopedPointer<QRhi> rhi(QRhi::create(QRhi::OpenGLES2, &initParams.gl, QRhi::Flags(), nullptr)); if (!rhi) QSKIP("QRhi could not be created, skipping testing native texture"); @@ -4539,7 +5137,7 @@ void tst_QRhi::threeDimTexture() } // mipmaps - { + if (rhi->isFeatureSupported(QRhi::ThreeDimensionalTextureMipmaps)) { QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8, WIDTH, HEIGHT, DEPTH, 1, QRhiTexture::MipMapped | QRhiTexture::UsedWithGenerateMips)); QVERIFY(texture->create()); @@ -4584,6 +5182,8 @@ void tst_QRhi::threeDimTexture() // problems with this. if (impl != QRhi::Null && impl != QRhi::OpenGLES2) QVERIFY(imageRGBAEquals(result, referenceImage, 2)); + } else { + qDebug("Skipping 3D texture mipmap generation test because it is reported as unsupported"); } // render target (one slice) @@ -4602,11 +5202,531 @@ void tst_QRhi::threeDimTexture() rt->setRenderPassDescriptor(rp.data()); QVERIFY(rt->create()); + // render to slice 23 + QRhiCommandBuffer *cb = nullptr; + QVERIFY(rhi->beginOffscreenFrame(&cb) == QRhi::FrameOpSuccess); + QVERIFY(cb); + cb->beginPass(rt.data(), Qt::blue, { 1.0f, 0 }); + // slice 23 is now blue + cb->endPass(); + rhi->endOffscreenFrame(); + + // Fill all other slices with some color. We should be free to do this + // step *before* the "render to slice 23" block above as well. However, + // as QTBUG-111772 shows, some Vulkan implementations have problems + // then. (or it could be QRhi is doing something wrong, but there is no + // evidence of that yet) For now, keep the order of first rendering to + // a slice and then uploading data for the rest. QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch(); QVERIFY(batch); - for (int i = 0; i < DEPTH; ++i) { - QImage img(WIDTH, HEIGHT, QImage::Format_RGBA8888); + if (i != SLICE) { + QImage img(WIDTH, HEIGHT, QImage::Format_RGBA8888); + img.fill(QColor::fromRgb(i * 2, 0, 0)); + QRhiTextureUploadEntry sliceUpload(i, 0, QRhiTextureSubresourceUploadDescription(img)); + batch->uploadTexture(texture.data(), sliceUpload); + } + } + QVERIFY(submitResourceUpdates(rhi.data(), batch)); + + // read back slice 23 (blue) + batch = rhi->nextResourceUpdateBatch(); + QVERIFY(batch); + QRhiReadbackResult readResult; + QImage result; + readResult.completed = [&readResult, &result] { + result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()), + readResult.pixelSize.width(), readResult.pixelSize.height(), + QImage::Format_RGBA8888); + }; + QRhiReadbackDescription readbackDescription(texture.data()); + readbackDescription.setLayer(23); + batch->readBackTexture(readbackDescription, &readResult); + QVERIFY(submitResourceUpdates(rhi.data(), batch)); + QVERIFY(!result.isNull()); + QImage referenceImage(WIDTH, HEIGHT, result.format()); + referenceImage.fill(QColor::fromRgbF(0.0f, 0.0f, 1.0f)); + // the Null backend does not render so skip the verification for that + if (impl != QRhi::Null) + QVERIFY(imageRGBAEquals(result, referenceImage)); + + // read back slice 0 (black) + batch = rhi->nextResourceUpdateBatch(); + result = QImage(); + readbackDescription.setLayer(0); + batch->readBackTexture(readbackDescription, &readResult); + QVERIFY(submitResourceUpdates(rhi.data(), batch)); + QVERIFY(!result.isNull()); + referenceImage.fill(QColor::fromRgbF(0.0f, 0.0f, 0.0f)); + QVERIFY(imageRGBAEquals(result, referenceImage)); + + // read back slice 127 (almost red) + batch = rhi->nextResourceUpdateBatch(); + result = QImage(); + readbackDescription.setLayer(127); + batch->readBackTexture(readbackDescription, &readResult); + QVERIFY(submitResourceUpdates(rhi.data(), batch)); + QVERIFY(!result.isNull()); + referenceImage.fill(QColor::fromRgb(254, 0, 0)); + QVERIFY(imageRGBAEquals(result, referenceImage)); + } +} +void tst_QRhi::oneDimTexture_data() +{ + rhiTestData(); +} + +void tst_QRhi::oneDimTexture() +{ + QFETCH(QRhi::Implementation, impl); + QFETCH(QRhiInitParams *, initParams); + + QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams)); + if (!rhi) + QSKIP("QRhi could not be created, skipping testing 1D textures"); + + if (!rhi->isFeatureSupported(QRhi::OneDimensionalTextures)) + QSKIP("Skipping testing 1D textures because they are reported as unsupported"); + + const int WIDTH = 512; + const int LAYERS = 128; + + { + QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8, WIDTH, 0, 0)); + QVERIFY(texture->create()); + + QVERIFY(texture->flags().testFlag(QRhiTexture::Flag::OneDimensional)); + + QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch(); + QVERIFY(batch); + + QImage img(WIDTH, 1, QImage::Format_RGBA8888); + img.fill(QColor::fromRgb(255, 0, 0)); + + QRhiTextureUploadEntry upload(0, 0, QRhiTextureSubresourceUploadDescription(img)); + batch->uploadTexture(texture.data(), upload); + + QVERIFY(submitResourceUpdates(rhi.data(), batch)); + } + + { + QScopedPointer<QRhiTexture> texture( + rhi->newTextureArray(QRhiTexture::RGBA8, LAYERS, QSize(WIDTH, 0))); + QVERIFY(texture->create()); + + QVERIFY(texture->flags().testFlag(QRhiTexture::Flag::OneDimensional)); + QVERIFY(texture->flags().testFlag(QRhiTexture::Flag::TextureArray)); + + QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch(); + QVERIFY(batch); + + for (int i = 0; i < LAYERS; ++i) { + QImage img(WIDTH, 1, QImage::Format_RGBA8888); + img.fill(QColor::fromRgb(i * 2, 0, 0)); + QRhiTextureUploadEntry layerUpload(i, 0, QRhiTextureSubresourceUploadDescription(img)); + batch->uploadTexture(texture.data(), layerUpload); + } + + QVERIFY(submitResourceUpdates(rhi.data(), batch)); + } + + // Copy from 2D texture to 1D texture + { + const int WIDTH = 256; + const int HEIGHT = 256; + + QScopedPointer<QRhiTexture> srcTexture(rhi->newTexture( + QRhiTexture::RGBA8, WIDTH, HEIGHT, 0, 1, QRhiTexture::Flag::UsedAsTransferSource)); + QVERIFY(srcTexture->create()); + + QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch(); + QVERIFY(batch); + + QImage img(WIDTH, HEIGHT, QImage::Format_RGBA8888); + for (int x = 0; x < WIDTH; ++x) { + for (int y = 0; y < HEIGHT; ++y) { + img.setPixelColor(x, y, QColor::fromRgb(x, y, 0)); + } + } + QRhiTextureUploadEntry upload(0, 0, QRhiTextureSubresourceUploadDescription(img)); + batch->uploadTexture(srcTexture.data(), upload); + + QScopedPointer<QRhiTexture> dstTexture(rhi->newTexture( + QRhiTexture::RGBA8, WIDTH, 0, 0, 1, QRhiTexture::Flag::UsedAsTransferSource)); + QVERIFY(dstTexture->create()); + + QRhiTextureCopyDescription copy; + copy.setPixelSize(QSize(WIDTH / 2, 1)); + copy.setDestinationTopLeft(QPoint(WIDTH / 2, 0)); + copy.setSourceTopLeft(QPoint(33, 67)); + batch->copyTexture(dstTexture.data(), srcTexture.data(), copy); + + copy.setDestinationTopLeft(QPoint(0, 0)); + copy.setSourceTopLeft(QPoint(99, 12)); + batch->copyTexture(dstTexture.data(), srcTexture.data(), copy); + + QRhiReadbackResult readResult; + QImage result; + readResult.completed = [&readResult, &result] { + result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()), + readResult.pixelSize.width(), readResult.pixelSize.height(), + QImage::Format_RGBA8888); + }; + + QRhiReadbackDescription readbackDescription(dstTexture.data()); + batch->readBackTexture(readbackDescription, &readResult); + QVERIFY(submitResourceUpdates(rhi.data(), batch)); + QVERIFY(!result.isNull()); + QImage referenceImage(WIDTH, 1, result.format()); + for (int i = 0; i < WIDTH / 2; ++i) { + referenceImage.setPixelColor(i, 0, img.pixelColor(99 + i, 12)); + referenceImage.setPixelColor(WIDTH / 2 + i, 0, img.pixelColor(33 + i, 67)); + } + + QVERIFY(imageRGBAEquals(result, referenceImage)); + } + + // Copy from 2D texture to 1D texture array + { + const int WIDTH = 256; + const int HEIGHT = 256; + const int LAYERS = 64; + + QScopedPointer<QRhiTexture> srcTexture(rhi->newTexture( + QRhiTexture::RGBA8, WIDTH, HEIGHT, 0, 1, QRhiTexture::Flag::UsedAsTransferSource)); + QVERIFY(srcTexture->create()); + + QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch(); + QVERIFY(batch); + + QImage img(WIDTH, HEIGHT, QImage::Format_RGBA8888); + for (int x = 0; x < WIDTH; ++x) { + for (int y = 0; y < HEIGHT; ++y) { + img.setPixelColor(x, y, QColor::fromRgb(x, y, 0)); + } + } + QRhiTextureUploadEntry upload(0, 0, QRhiTextureSubresourceUploadDescription(img)); + batch->uploadTexture(srcTexture.data(), upload); + + QScopedPointer<QRhiTexture> dstTexture( + rhi->newTextureArray(QRhiTexture::RGBA8, LAYERS, QSize(WIDTH, 0), 1, + QRhiTexture::Flag::UsedAsTransferSource)); + QVERIFY(dstTexture->create()); + + QRhiTextureCopyDescription copy; + copy.setPixelSize(QSize(WIDTH / 2, 1)); + copy.setDestinationTopLeft(QPoint(WIDTH / 2, 0)); + copy.setSourceTopLeft(QPoint(33, 67)); + copy.setDestinationLayer(12); + batch->copyTexture(dstTexture.data(), srcTexture.data(), copy); + + copy.setDestinationTopLeft(QPoint(0, 0)); + copy.setSourceTopLeft(QPoint(99, 12)); + batch->copyTexture(dstTexture.data(), srcTexture.data(), copy); + + QRhiReadbackResult readResult; + QImage result; + readResult.completed = [&readResult, &result] { + result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()), + readResult.pixelSize.width(), readResult.pixelSize.height(), + QImage::Format_RGBA8888); + }; + + QRhiReadbackDescription readbackDescription(dstTexture.data()); + readbackDescription.setLayer(12); + batch->readBackTexture(readbackDescription, &readResult); + QVERIFY(submitResourceUpdates(rhi.data(), batch)); + QVERIFY(!result.isNull()); + QImage referenceImage(WIDTH, 1, result.format()); + for (int i = 0; i < WIDTH / 2; ++i) { + referenceImage.setPixelColor(i, 0, img.pixelColor(99 + i, 12)); + referenceImage.setPixelColor(WIDTH / 2 + i, 0, img.pixelColor(33 + i, 67)); + } + + QVERIFY(imageRGBAEquals(result, referenceImage)); + } + + // Copy from 1D texture array to 1D texture + { + const int WIDTH = 256; + const int LAYERS = 256; + + QScopedPointer<QRhiTexture> srcTexture( + rhi->newTextureArray(QRhiTexture::RGBA8, LAYERS, QSize(WIDTH, 0), 1, + QRhiTexture::Flag::UsedAsTransferSource)); + QVERIFY(srcTexture->create()); + + QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch(); + QVERIFY(batch); + + for (int y = 0; y < LAYERS; ++y) { + QImage img(WIDTH, 1, QImage::Format_RGBA8888); + for (int x = 0; x < WIDTH; ++x) { + img.setPixelColor(x, 0, QColor::fromRgb(x, y, 0)); + } + QRhiTextureUploadEntry upload(y, 0, QRhiTextureSubresourceUploadDescription(img)); + batch->uploadTexture(srcTexture.data(), upload); + } + + QScopedPointer<QRhiTexture> dstTexture(rhi->newTexture( + QRhiTexture::RGBA8, WIDTH, 0, 0, 1, QRhiTexture::Flag::UsedAsTransferSource)); + QVERIFY(dstTexture->create()); + + QRhiTextureCopyDescription copy; + copy.setPixelSize(QSize(WIDTH / 2, 1)); + copy.setDestinationTopLeft(QPoint(WIDTH / 2, 0)); + copy.setSourceLayer(67); + copy.setSourceTopLeft(QPoint(33, 0)); + batch->copyTexture(dstTexture.data(), srcTexture.data(), copy); + + copy.setDestinationTopLeft(QPoint(0, 0)); + copy.setSourceLayer(12); + copy.setSourceTopLeft(QPoint(99, 0)); + batch->copyTexture(dstTexture.data(), srcTexture.data(), copy); + + QRhiReadbackResult readResult; + QImage result; + readResult.completed = [&readResult, &result] { + result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()), + readResult.pixelSize.width(), readResult.pixelSize.height(), + QImage::Format_RGBA8888); + }; + + QRhiReadbackDescription readbackDescription(dstTexture.data()); + batch->readBackTexture(readbackDescription, &readResult); + QVERIFY(submitResourceUpdates(rhi.data(), batch)); + QVERIFY(!result.isNull()); + QImage referenceImage(WIDTH, 1, result.format()); + for (int i = 0; i < WIDTH / 2; ++i) { + referenceImage.setPixelColor(i, 0, QColor::fromRgb(99 + i, 12, 0)); + referenceImage.setPixelColor(WIDTH / 2 + i, 0, QColor::fromRgb(33 + i, 67, 0)); + } + + QVERIFY(imageRGBAEquals(result, referenceImage)); + } + + // Copy from 1D texture to 1D texture array + { + const int WIDTH = 256; + const int LAYERS = 256; + + QScopedPointer<QRhiTexture> srcTexture(rhi->newTexture( + QRhiTexture::RGBA8, WIDTH, 0, 0, 1, QRhiTexture::Flag::UsedAsTransferSource)); + QVERIFY(srcTexture->create()); + + QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch(); + QVERIFY(batch); + + QImage img(WIDTH, 1, QImage::Format_RGBA8888); + for (int x = 0; x < WIDTH; ++x) { + img.setPixelColor(x, 0, QColor::fromRgb(x, 0, 0)); + } + QRhiTextureUploadEntry upload(0, 0, QRhiTextureSubresourceUploadDescription(img)); + batch->uploadTexture(srcTexture.data(), upload); + + QScopedPointer<QRhiTexture> dstTexture( + rhi->newTextureArray(QRhiTexture::RGBA8, LAYERS, QSize(WIDTH, 0), 1, + QRhiTexture::Flag::UsedAsTransferSource)); + QVERIFY(dstTexture->create()); + + QRhiTextureCopyDescription copy; + copy.setPixelSize(QSize(WIDTH / 2, 1)); + copy.setDestinationTopLeft(QPoint(WIDTH / 2, 0)); + copy.setDestinationLayer(67); + copy.setSourceTopLeft(QPoint(33, 0)); + batch->copyTexture(dstTexture.data(), srcTexture.data(), copy); + + copy.setDestinationTopLeft(QPoint(0, 0)); + copy.setSourceTopLeft(QPoint(99, 0)); + batch->copyTexture(dstTexture.data(), srcTexture.data(), copy); + + QRhiReadbackResult readResult; + QImage result; + readResult.completed = [&readResult, &result] { + result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()), + readResult.pixelSize.width(), readResult.pixelSize.height(), + QImage::Format_RGBA8888); + }; + + QRhiReadbackDescription readbackDescription(dstTexture.data()); + readbackDescription.setLayer(67); + batch->readBackTexture(readbackDescription, &readResult); + QVERIFY(submitResourceUpdates(rhi.data(), batch)); + QVERIFY(!result.isNull()); + QImage referenceImage(WIDTH, 1, result.format()); + for (int i = 0; i < WIDTH / 2; ++i) { + referenceImage.setPixelColor(i, 0, QColor::fromRgb(99 + i, 0, 0)); + referenceImage.setPixelColor(WIDTH / 2 + i, 0, QColor::fromRgb(33 + i, 0, 0)); + } + + QVERIFY(imageRGBAEquals(result, referenceImage)); + } + + // mipmaps and 1D render target + if (!rhi->isFeatureSupported(QRhi::OneDimensionalTextureMipmaps) + || !rhi->isFeatureSupported(QRhi::RenderToOneDimensionalTexture)) + { + QSKIP("Skipping testing 1D texture mipmaps and 1D render target because they are reported as unsupported"); + } + + { + QScopedPointer<QRhiTexture> texture( + rhi->newTexture(QRhiTexture::RGBA8, WIDTH, 0, 0, 1, + QRhiTexture::MipMapped | QRhiTexture::UsedWithGenerateMips)); + QVERIFY(texture->create()); + + QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch(); + QVERIFY(batch); + + QImage img(WIDTH, 1, QImage::Format_RGBA8888); + img.fill(QColor::fromRgb(128, 0, 0)); + QRhiTextureUploadEntry upload(0, 0, QRhiTextureSubresourceUploadDescription(img)); + batch->uploadTexture(texture.data(), upload); + + batch->generateMips(texture.data()); + + QVERIFY(submitResourceUpdates(rhi.data(), batch)); + + // read back level 1 (256x1, #800000ff) + batch = rhi->nextResourceUpdateBatch(); + QRhiReadbackResult readResult; + QImage result; + readResult.completed = [&readResult, &result] { + result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()), + readResult.pixelSize.width(), readResult.pixelSize.height(), + QImage::Format_RGBA8888); + }; + QRhiReadbackDescription readbackDescription(texture.data()); + readbackDescription.setLevel(1); + readbackDescription.setLayer(0); + batch->readBackTexture(readbackDescription, &readResult); + QVERIFY(submitResourceUpdates(rhi.data(), batch)); + QVERIFY(!result.isNull()); + QImage referenceImage(WIDTH / 2, 1, result.format()); + referenceImage.fill(QColor::fromRgb(128, 0, 0)); + + QVERIFY(imageRGBAEquals(result, referenceImage, 2)); + } + + { + QScopedPointer<QRhiTexture> texture( + rhi->newTextureArray(QRhiTexture::RGBA8, LAYERS, QSize(WIDTH, 0), 1, + QRhiTexture::MipMapped | QRhiTexture::UsedWithGenerateMips)); + QVERIFY(texture->create()); + + QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch(); + QVERIFY(batch); + + for (int i = 0; i < LAYERS; ++i) { + QImage img(WIDTH, 1, QImage::Format_RGBA8888); + img.fill(QColor::fromRgb(i * 2, 0, 0)); + QRhiTextureUploadEntry sliceUpload(i, 0, QRhiTextureSubresourceUploadDescription(img)); + batch->uploadTexture(texture.data(), sliceUpload); + } + + batch->generateMips(texture.data()); + + QVERIFY(submitResourceUpdates(rhi.data(), batch)); + + // read back slice 63 of level 1 (256x1, #7E0000FF) + batch = rhi->nextResourceUpdateBatch(); + QRhiReadbackResult readResult; + QImage result; + readResult.completed = [&readResult, &result] { + result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()), + readResult.pixelSize.width(), readResult.pixelSize.height(), + QImage::Format_RGBA8888); + }; + QRhiReadbackDescription readbackDescription(texture.data()); + readbackDescription.setLevel(1); + readbackDescription.setLayer(63); + batch->readBackTexture(readbackDescription, &readResult); + QVERIFY(submitResourceUpdates(rhi.data(), batch)); + QVERIFY(!result.isNull()); + QImage referenceImage(WIDTH / 2, 1, result.format()); + referenceImage.fill(QColor::fromRgb(126, 0, 0)); + + // Now restrict the test a bit. The Null QRhi backend has broken support for + // mipmap generation of 1D texture arrays. + if (impl != QRhi::Null) + QVERIFY(imageRGBAEquals(result, referenceImage, 2)); + } + + // 1D texture render target + // NB with Vulkan we require Vulkan 1.1 for this to work. + // Metal does not allow 1D texture render targets + { + QScopedPointer<QRhiTexture> texture( + rhi->newTexture(QRhiTexture::RGBA8, WIDTH, 0, 0, 1, + QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource)); + QVERIFY(texture->create()); + + QRhiColorAttachment att(texture.data()); + QRhiTextureRenderTargetDescription rtDesc(att); + QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget(rtDesc)); + QScopedPointer<QRhiRenderPassDescriptor> rp(rt->newCompatibleRenderPassDescriptor()); + rt->setRenderPassDescriptor(rp.data()); + QVERIFY(rt->create()); + + QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch(); + QVERIFY(batch); + + QImage img(WIDTH, 1, QImage::Format_RGBA8888); + img.fill(QColor::fromRgb(128, 0, 0)); + QRhiTextureUploadEntry upload(0, 0, QRhiTextureSubresourceUploadDescription(img)); + batch->uploadTexture(texture.data(), upload); + + QRhiCommandBuffer *cb = nullptr; + QVERIFY(rhi->beginOffscreenFrame(&cb) == QRhi::FrameOpSuccess); + QVERIFY(cb); + cb->beginPass(rt.data(), Qt::blue, { 1.0f, 0 }, batch); + // texture is now blue + cb->endPass(); + rhi->endOffscreenFrame(); + + // read back texture (blue) + batch = rhi->nextResourceUpdateBatch(); + QRhiReadbackResult readResult; + QImage result; + readResult.completed = [&readResult, &result] { + result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()), + readResult.pixelSize.width(), readResult.pixelSize.height(), + QImage::Format_RGBA8888); + }; + QRhiReadbackDescription readbackDescription(texture.data()); + batch->readBackTexture(readbackDescription, &readResult); + QVERIFY(submitResourceUpdates(rhi.data(), batch)); + QVERIFY(!result.isNull()); + QImage referenceImage(WIDTH, 1, result.format()); + referenceImage.fill(QColor::fromRgbF(0.0f, 0.0f, 1.0f)); + // the Null backend does not render so skip the verification for that + if (impl != QRhi::Null) + QVERIFY(imageRGBAEquals(result, referenceImage)); + } + + // 1D array texture render target (one slice) + // NB with Vulkan we require Vulkan 1.1 for this to work. + // Metal does not allow 1D texture render targets + { + const int SLICE = 23; + QScopedPointer<QRhiTexture> texture(rhi->newTextureArray( + QRhiTexture::RGBA8, LAYERS, QSize(WIDTH, 0), 1, + QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource)); + QVERIFY(texture->create()); + + QRhiColorAttachment att(texture.data()); + att.setLayer(SLICE); + QRhiTextureRenderTargetDescription rtDesc(att); + QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget(rtDesc)); + QScopedPointer<QRhiRenderPassDescriptor> rp(rt->newCompatibleRenderPassDescriptor()); + rt->setRenderPassDescriptor(rp.data()); + QVERIFY(rt->create()); + + QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch(); + QVERIFY(batch); + + for (int i = 0; i < LAYERS; ++i) { + QImage img(WIDTH, 1, QImage::Format_RGBA8888); img.fill(QColor::fromRgb(i * 2, 0, 0)); QRhiTextureUploadEntry sliceUpload(i, 0, QRhiTextureSubresourceUploadDescription(img)); batch->uploadTexture(texture.data(), sliceUpload); @@ -4634,7 +5754,7 @@ void tst_QRhi::threeDimTexture() batch->readBackTexture(readbackDescription, &readResult); QVERIFY(submitResourceUpdates(rhi.data(), batch)); QVERIFY(!result.isNull()); - QImage referenceImage(WIDTH, HEIGHT, result.format()); + QImage referenceImage(WIDTH, 1, result.format()); referenceImage.fill(QColor::fromRgbF(0.0f, 0.0f, 1.0f)); // the Null backend does not render so skip the verification for that if (impl != QRhi::Null) @@ -4701,12 +5821,36 @@ void tst_QRhi::leakedResourceDestroy() rt->setRenderPassDescriptor(rpDesc.data()); QVERIFY(rt->create()); + QRhiRenderBuffer *rb = rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil, QSize(512, 512)); + QVERIFY(rb->create()); + + QRhiShaderResourceBindings *srb = rhi->newShaderResourceBindings(); + QVERIFY(srb->create()); + if (impl == QRhi::Vulkan) qDebug("Vulkan validation layer warnings may be printed below - this is expected"); + if (impl == QRhi::D3D12) + qDebug("QD3D12CpuDescriptorPool warnings may be printed below - this is expected"); + + qDebug("QRhi resource leak check warnings may be printed below - this is expected"); + + // make the QRhi go away early rhi.reset(); - // let the scoped ptr do its job with the resources + // see if the internal rhi backpointer got nulled out + QVERIFY(buffer->rhi() == nullptr); + QVERIFY(texture->rhi() == nullptr); + QVERIFY(rt->rhi() == nullptr); + QVERIFY(rpDesc->rhi() == nullptr); + QVERIFY(rb->rhi() == nullptr); + QVERIFY(srb->rhi() == nullptr); + + // test out deleteLater on some of the resources + rb->deleteLater(); + srb->deleteLater(); + + // let the scoped ptr do its job with the rest } void tst_QRhi::renderToFloatTexture_data() @@ -4886,5 +6030,1055 @@ void tst_QRhi::renderToRgb10Texture() QVERIFY(redCount > blueCount); // 1742 > 178 } +void tst_QRhi::tessellation_data() +{ + rhiTestData(); +} + +void tst_QRhi::tessellation() +{ +#ifdef Q_OS_ANDROID + if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) + QSKIP("Fails on Android 12 (QTBUG-108844)"); +#endif + QFETCH(QRhi::Implementation, impl); + QFETCH(QRhiInitParams *, initParams); + + QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr)); + if (!rhi) + QSKIP("QRhi could not be created, skipping testing rendering"); + + if (!rhi->isFeatureSupported(QRhi::Tessellation)) { + // From a Vulkan or Metal implementation we expect tessellation to work, + // even though it is optional (as per spec) for Vulkan. + QVERIFY(rhi->backend() != QRhi::Vulkan); + QVERIFY(rhi->backend() != QRhi::Metal); + QSKIP("Tessellation is not supported with this graphics API, skipping test"); + } + + if (rhi->backend() == QRhi::D3D11 || rhi->backend() == QRhi::D3D12) + QSKIP("Skipping tessellation test on D3D for now, test assets not prepared for HLSL yet"); + + QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8, QSize(1280, 720), 1, + QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource)); + QVERIFY(texture->create()); + + QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ texture.data() })); + QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor()); + rt->setRenderPassDescriptor(rpDesc.data()); + QVERIFY(rt->create()); + + static const float triangleVertices[] = { + 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, + -0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, + 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, + }; + + QRhiResourceUpdateBatch *u = rhi->nextResourceUpdateBatch(); + QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(triangleVertices))); + QVERIFY(vbuf->create()); + u->uploadStaticBuffer(vbuf.data(), triangleVertices); + + QScopedPointer<QRhiBuffer> ubuf(rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64)); + QVERIFY(ubuf->create()); + + // Use the 3D API specific correction matrix that flips Y, so we can use + // the OpenGL-targeted vertex data and the tessellation winding order of + // counter-clockwise to get uniform results. + QMatrix4x4 mvp = rhi->clipSpaceCorrMatrix(); + u->updateDynamicBuffer(ubuf.data(), 0, 64, mvp.constData()); + + QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings()); + srb->setBindings({ + QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::TessellationEvaluationStage, ubuf.data()), + }); + QVERIFY(srb->create()); + + QScopedPointer<QRhiGraphicsPipeline> pipeline(rhi->newGraphicsPipeline()); + + pipeline->setTopology(QRhiGraphicsPipeline::Patches); + pipeline->setPatchControlPointCount(3); + + pipeline->setShaderStages({ + { QRhiShaderStage::Vertex, loadShader(":/data/simpletess.vert.qsb") }, + { QRhiShaderStage::TessellationControl, loadShader(":/data/simpletess.tesc.qsb") }, + { QRhiShaderStage::TessellationEvaluation, loadShader(":/data/simpletess.tese.qsb") }, + { QRhiShaderStage::Fragment, loadShader(":/data/simpletess.frag.qsb") } + }); + + pipeline->setCullMode(QRhiGraphicsPipeline::Back); // to ensure the winding order is correct + + // won't get the wireframe with OpenGL ES + if (rhi->isFeatureSupported(QRhi::NonFillPolygonMode)) + pipeline->setPolygonMode(QRhiGraphicsPipeline::Line); + + QRhiVertexInputLayout inputLayout; + inputLayout.setBindings({ + { 6 * sizeof(float) } + }); + inputLayout.setAttributes({ + { 0, 0, QRhiVertexInputAttribute::Float3, 0 }, + { 0, 1, QRhiVertexInputAttribute::Float3, 3 * sizeof(float) } + }); + + pipeline->setVertexInputLayout(inputLayout); + pipeline->setShaderResourceBindings(srb.data()); + pipeline->setRenderPassDescriptor(rpDesc.data()); + + QVERIFY(pipeline->create()); + + QRhiCommandBuffer *cb = nullptr; + QCOMPARE(rhi->beginOffscreenFrame(&cb), QRhi::FrameOpSuccess); + + cb->beginPass(rt.data(), Qt::black, { 1.0f, 0 }, u); + cb->setGraphicsPipeline(pipeline.data()); + cb->setViewport({ 0, 0, float(rt->pixelSize().width()), float(rt->pixelSize().height()) }); + cb->setShaderResources(); + QRhiCommandBuffer::VertexInput vbufBinding(vbuf.data(), 0); + cb->setVertexInput(0, 1, &vbufBinding); + cb->draw(3); + + QRhiReadbackResult readResult; + QImage result; + readResult.completed = [&readResult, &result] { + result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()), + readResult.pixelSize.width(), readResult.pixelSize.height(), + QImage::Format_RGBA8888); + }; + QRhiResourceUpdateBatch *readbackBatch = rhi->nextResourceUpdateBatch(); + readbackBatch->readBackTexture({ texture.data() }, &readResult); + cb->endPass(readbackBatch); + + rhi->endOffscreenFrame(); + + if (rhi->isYUpInFramebuffer()) // we used clipSpaceCorrMatrix so this is different from many other tests + result = std::move(result).mirrored(); + + QCOMPARE(result.size(), rt->pixelSize()); + + // cannot check rendering results with Null, because there is no rendering there + if (impl == QRhi::Null) + return; + + int redCount = 0, greenCount = 0, blueCount = 0; + for (int y = 0; y < result.height(); ++y) { + const quint32 *p = reinterpret_cast<const quint32 *>(result.constScanLine(y)); + int x = result.width() - 1; + while (x-- >= 0) { + const QRgb c(*p++); + const int red = qRed(c); + const int green = qGreen(c); + const int blue = qBlue(c); + // just count the color components that are above a certain threshold + if (red > 240) + ++redCount; + if (green > 240) + ++greenCount; + if (blue > 240) + ++blueCount; + } + } + + // Line drawing can be different between the 3D APIs. What we will check if + // the number of strong-enough r/g/b components above a certain threshold. + // That is good enough to ensure that something got rendered, i.e. that + // tessellation is not completely broken. + // + // For the record the actual values are something like: + // OpenGL (NVIDIA, Windows) 59 82 82 + // Metal (Intel, macOS 12.5) 59 79 79 + // Vulkan (NVIDIA, Windows) 71 85 85 + + QVERIFY(redCount > 50); + QVERIFY(blueCount > 50); + QVERIFY(greenCount > 50); +} + +void tst_QRhi::tessellationInterfaceBlocks_data() +{ + rhiTestData(); +} + +void tst_QRhi::tessellationInterfaceBlocks() +{ +#ifdef Q_OS_ANDROID + if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) + QSKIP("Fails on Android 12 (QTBUG-108844)"); +#endif + QFETCH(QRhi::Implementation, impl); + QFETCH(QRhiInitParams *, initParams); + + // This test is intended for Metal, but will run on other tessellation render pipelines + // + // Metal tessellation uses a combination of compute pipelines for the vert and tesc, and a + // render pipeline for the tese and frag. This test uses input output interface blocks between + // the tesc and tese, and all tese stage builtin inputs to check that the Metal tese-frag + // pipeline vertex inputs are correctly configured. The tese writes the values to a storage + // buffer whose values are checked by the unit test. MSL 2.1 is required for this test. + // (requires support for writing to a storage buffer in the vertex shader within a render + // pipeline) + + QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr)); + if (!rhi) + QSKIP("QRhi could not be created, skipping testing rendering"); + + if (!rhi->isFeatureSupported(QRhi::Tessellation)) { + // From a Vulkan or Metal implementation we expect tessellation to work, + // even though it is optional (as per spec) for Vulkan. + QVERIFY(rhi->backend() != QRhi::Vulkan); + QVERIFY(rhi->backend() != QRhi::Metal); + QSKIP("Tessellation is not supported with this graphics API, skipping test"); + } + + if (rhi->backend() == QRhi::D3D11 || rhi->backend() == QRhi::D3D12) + QSKIP("Skipping tessellation test on D3D for now, test assets not prepared for HLSL yet"); + + if (rhi->backend() == QRhi::OpenGLES2) + QSKIP("Skipping test on OpenGL as gl_ClipDistance[] support inconsistent"); + + QScopedPointer<QRhiTexture> texture( + rhi->newTexture(QRhiTexture::RGBA8, QSize(1280, 720), 1, + QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource)); + QVERIFY(texture->create()); + + QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ texture.data() })); + QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor()); + rt->setRenderPassDescriptor(rpDesc.data()); + QVERIFY(rt->create()); + + static const float triangleVertices[] = { + 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, -0.5f, -0.5f, 0.0f, + 1.0f, 0.0f, 0.0f, 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, + }; + + QRhiResourceUpdateBatch *u = rhi->nextResourceUpdateBatch(); + QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, + sizeof(triangleVertices))); + QVERIFY(vbuf->create()); + u->uploadStaticBuffer(vbuf.data(), triangleVertices); + + QScopedPointer<QRhiBuffer> ubuf( + rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64)); + QVERIFY(ubuf->create()); + + // Use the 3D API specific correction matrix that flips Y, so we can use + // the OpenGL-targeted vertex data and the tessellation winding order of + // counter-clockwise to get uniform results. + QMatrix4x4 mvp = rhi->clipSpaceCorrMatrix(); + u->updateDynamicBuffer(ubuf.data(), 0, 64, mvp.constData()); + + QScopedPointer<QRhiBuffer> buffer( + rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::UsageFlag::StorageBuffer, 1024)); + QVERIFY(buffer->create()); + + u->uploadStaticBuffer(buffer.data(), 0, 1024, QByteArray(1024, 0).constData()); + + QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings()); + srb->setBindings( + { QRhiShaderResourceBinding::uniformBuffer( + 0, QRhiShaderResourceBinding::TessellationEvaluationStage, ubuf.data()), + QRhiShaderResourceBinding::bufferLoadStore( + 1, QRhiShaderResourceBinding::TessellationEvaluationStage, buffer.data()) }); + QVERIFY(srb->create()); + + QScopedPointer<QRhiGraphicsPipeline> pipeline(rhi->newGraphicsPipeline()); + + pipeline->setTopology(QRhiGraphicsPipeline::Patches); + pipeline->setPatchControlPointCount(3); + + pipeline->setShaderStages( + { { QRhiShaderStage::Vertex, loadShader(":/data/tessinterfaceblocks.vert.qsb") }, + { QRhiShaderStage::TessellationControl, + loadShader(":/data/tessinterfaceblocks.tesc.qsb") }, + { QRhiShaderStage::TessellationEvaluation, + loadShader(":/data/tessinterfaceblocks.tese.qsb") }, + { QRhiShaderStage::Fragment, loadShader(":/data/tessinterfaceblocks.frag.qsb") } }); + + pipeline->setCullMode(QRhiGraphicsPipeline::Back); // to ensure the winding order is correct + + // won't get the wireframe with OpenGL ES + if (rhi->isFeatureSupported(QRhi::NonFillPolygonMode)) + pipeline->setPolygonMode(QRhiGraphicsPipeline::Line); + + QRhiVertexInputLayout inputLayout; + inputLayout.setBindings({ { 6 * sizeof(float) } }); + inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Float3, 0 }, + { 0, 1, QRhiVertexInputAttribute::Float3, 3 * sizeof(float) } }); + + pipeline->setVertexInputLayout(inputLayout); + pipeline->setShaderResourceBindings(srb.data()); + pipeline->setRenderPassDescriptor(rpDesc.data()); + + QVERIFY(pipeline->create()); + + QRhiCommandBuffer *cb = nullptr; + QCOMPARE(rhi->beginOffscreenFrame(&cb), QRhi::FrameOpSuccess); + + cb->beginPass(rt.data(), Qt::black, { 1.0f, 0 }, u); + cb->setGraphicsPipeline(pipeline.data()); + cb->setViewport({ 0, 0, float(rt->pixelSize().width()), float(rt->pixelSize().height()) }); + cb->setShaderResources(); + QRhiCommandBuffer::VertexInput vbufBinding(vbuf.data(), 0); + cb->setVertexInput(0, 1, &vbufBinding); + cb->draw(3); + + QRhiReadbackResult readResult; + QImage result; + readResult.completed = [&readResult, &result] { + result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()), + readResult.pixelSize.width(), readResult.pixelSize.height(), + QImage::Format_RGBA8888); + }; + QRhiResourceUpdateBatch *readbackBatch = rhi->nextResourceUpdateBatch(); + readbackBatch->readBackTexture({ texture.data() }, &readResult); + + QRhiReadbackResult bufferReadResult; + bufferReadResult.completed = []() {}; + readbackBatch->readBackBuffer(buffer.data(), 0, 1024, &bufferReadResult); + + cb->endPass(readbackBatch); + + rhi->endOffscreenFrame(); + + if (rhi->isYUpInFramebuffer()) // we used clipSpaceCorrMatrix so this is different from many + // other tests + result = std::move(result).mirrored(); + + QCOMPARE(result.size(), rt->pixelSize()); + + // cannot check rendering results with Null, because there is no rendering there + if (impl == QRhi::Null) + return; + + int redCount = 0, greenCount = 0, blueCount = 0; + for (int y = 0; y < result.height(); ++y) { + const quint32 *p = reinterpret_cast<const quint32 *>(result.constScanLine(y)); + int x = result.width() - 1; + while (x-- >= 0) { + const QRgb c(*p++); + const int red = qRed(c); + const int green = qGreen(c); + const int blue = qBlue(c); + // just count the color components that are above a certain threshold + if (red > 240) + ++redCount; + if (green > 240) + ++greenCount; + if (blue > 240) + ++blueCount; + } + } + + // make sure we drew something + QVERIFY(redCount > 50); + QVERIFY(blueCount > 50); + QVERIFY(greenCount > 50); + + // StorageBlock("result" "" knownSize=16 binding=1 set=0 runtimeArrayStride=336 QList( + // BlockVariable("int" "count" offset=0 size=4), + // BlockVariable("struct" "elements" offset=16 size=0 array=QList(0) structMembers=QList( + // BlockVariable("struct" "a" offset=0 size=48 array=QList(3) structMembers=QList( + // BlockVariable("vec3" "color" offset=0 size=12), + // BlockVariable("int" "id" offset=12 size=4))), + // BlockVariable("struct" "b" offset=48 size=144 array=QList(3) structMembers=QList( + // BlockVariable("vec2" "some" offset=0 size=8), + // BlockVariable("int" "other" offset=8 size=12 array=QList(3)), + // BlockVariable("vec3" "variables" offset=32 size=12))), + // BlockVariable("struct" "c" offset=192 size=16 structMembers=QList( + // BlockVariable("vec3" "stuff" offset=0 size=12), + // BlockVariable("float" "more_stuff" offset=12 size=4))), + // BlockVariable("vec4" "tesslevelOuter" offset=208 size=16), + // BlockVariable("vec2" "tessLevelInner" offset=224 size=8), + // BlockVariable("float" "pointSize" offset=232 size=12 array=QList(3)), + // BlockVariable("float" "clipDistance" offset=244 size=60 array=QList(5, 3)), + // BlockVariable("vec3" "tessCoord" offset=304 size=12), + // BlockVariable("int" "patchVerticesIn" offset=316 size=4), + // BlockVariable("int" "primitiveID" offset=320 size=4))))) + + // int count + QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[0])[0], 1); + + // a[0].color + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 0 + 0])[0], 0.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 0 + 0])[1], 0.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 0 + 0])[2], 1.0f); + + // a[0].id + QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 0 + 12])[0], 91); + + // a[1].color + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 16 + 0])[0], 1.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 16 + 0])[1], 0.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 16 + 0])[2], 0.0f); + + // a[1].id + QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 16 + 12])[0], 92); + + // a[2].color + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 32 + 0])[0], 0.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 32 + 0])[1], 1.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 32 + 0])[2], 0.0f); + + // a[2].id + QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 32 + 12])[0], 93); + + // b[0].some + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 48 + 0])[0], 0.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 48 + 0])[1], 0.0f); + + // b[0].other[0] + QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 48 + 8])[0], 10.0f); + QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 48 + 8])[1], 20.0f); + QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 48 + 8])[2], 30.0f); + + // b[0].variables + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 48 + 32])[0], 3.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 48 + 32])[1], 13.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 48 + 32])[2], 17.0f); + + // b[1].some + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 96 + 0])[0], 1.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 96 + 0])[1], 1.0f); + + // b[1].other[0] + QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 96 + 8])[0], 10.0f); + QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 96 + 8])[1], 20.0f); + QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 96 + 8])[2], 30.0f); + + // b[1].variables + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 96 + 32])[0], 3.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 96 + 32])[1], 14.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 96 + 32])[2], 17.0f); + + // b[2].some + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 144 + 0])[0], 2.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 144 + 0])[1], 2.0f); + + // b[2].other[0] + QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 144 + 8])[0], 10.0f); + QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 144 + 8])[1], 20.0f); + QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 144 + 8])[2], 30.0f); + + // b[2].variables + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 144 + 32])[0], 3.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 144 + 32])[1], 15.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 144 + 32])[2], 17.0f); + + // c.stuff + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 192 + 0])[0], 1.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 192 + 0])[1], 2.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 192 + 0])[2], 3.0f); + + // c.more_stuff + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 192 + 12])[0], 4.0f); + + // tessLevelOuter + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 208 + 0])[0], 1.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 208 + 0])[1], 2.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 208 + 0])[2], 3.0f); + + // tessLevelInner + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 224 + 0])[0], 5.0f); + + // pointSize[0] + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 232 + 0])[0], 10.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 232 + 0])[1], 11.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 232 + 0])[2], 12.0f); + + // clipDistance[0][0] + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 0])[0], 20.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 0])[1], 40.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 0])[2], 60.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 0])[3], 80.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 0])[4], 100.0f); + + // clipDistance[1][0] + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 20])[0], 21.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 20])[1], 41.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 20])[2], 61.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 20])[3], 81.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 20])[4], 101.0f); + + // clipDistance[2][0] + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 40])[0], 22.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 40])[1], 42.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 40])[2], 62.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 40])[3], 82.0f); + QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 40])[4], 102.0f); + + // patchVerticesIn + QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 316 + 0])[0], 3); + + // primitiveID + QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 320 + 0])[0], 0); +} + +void tst_QRhi::storageBuffer_data() +{ + rhiTestData(); +} + +void tst_QRhi::storageBuffer() +{ + // Use a compute shader to copy from one storage buffer of float types to + // another of int types. We fill the "toGpu" buffer with known float type + // data generated and uploaded from the CPU, then dispatch a compute shader + // to copy from the "toGpu" buffer to the "fromGpu" buffer. We then + // readback the "fromGpu" buffer and verify that the results are as + // expected. + + QFETCH(QRhi::Implementation, impl); + QFETCH(QRhiInitParams *, initParams); + + // we can't test with Null as there is no compute + if (impl == QRhi::Null) + return; + + QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr)); + if (!rhi) + QSKIP("QRhi could not be created, skipping testing"); + + if (!rhi->isFeatureSupported(QRhi::Feature::Compute)) + QSKIP("Compute is not supported with this graphics API, skipping test"); + + QShader s = loadShader(":/data/storagebuffer.comp.qsb"); + QVERIFY(s.isValid()); + QCOMPARE(s.description().storageBlocks().size(), 2); + + QMap<QByteArray, QShaderDescription::StorageBlock> blocks; + for (const QShaderDescription::StorageBlock &block : s.description().storageBlocks()) + blocks[block.blockName] = block; + + QMap<QByteArray, QShaderDescription::BlockVariable> toGpuMembers; + for (const QShaderDescription::BlockVariable &member: blocks["toGpu"].members) + toGpuMembers[member.name] = member; + + QMap<QByteArray, QShaderDescription::BlockVariable> fromGpuMembers; + for (const QShaderDescription::BlockVariable &member: blocks["fromGpu"].members) + fromGpuMembers[member.name] = member; + + for (QRhiBuffer::Type type : {QRhiBuffer::Type::Immutable, QRhiBuffer::Type::Static}) { + + QRhiCommandBuffer *cb = nullptr; + rhi->beginOffscreenFrame(&cb); + QVERIFY(cb); + + QRhiResourceUpdateBatch *u = rhi->nextResourceUpdateBatch(); + QVERIFY(u); + + QScopedPointer<QRhiBuffer> toGpuBuffer(rhi->newBuffer(type, QRhiBuffer::UsageFlag::StorageBuffer, blocks["toGpu"].knownSize)); + QVERIFY(toGpuBuffer->create()); + + QScopedPointer<QRhiBuffer> fromGpuBuffer(rhi->newBuffer(type, QRhiBuffer::UsageFlag::StorageBuffer, blocks["fromGpu"].knownSize)); + QVERIFY(fromGpuBuffer->create()); + + QByteArray toGpuData(blocks["toGpu"].knownSize, 0); + reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_float"].offset])[0] = 1.0f; + reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_vec2"].offset])[0] = 2.0f; + reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_vec2"].offset])[1] = 3.0f; + reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_vec3"].offset])[0] = 4.0f; + reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_vec3"].offset])[1] = 5.0f; + reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_vec3"].offset])[2] = 6.0f; + reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_vec4"].offset])[0] = 7.0f; + reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_vec4"].offset])[1] = 8.0f; + reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_vec4"].offset])[2] = 9.0f; + reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_vec4"].offset])[3] = 10.0f; + + u->uploadStaticBuffer(toGpuBuffer.data(), 0, toGpuData.size(), toGpuData.constData()); + u->uploadStaticBuffer(fromGpuBuffer.data(), 0, blocks["fromGpu"].knownSize, QByteArray(blocks["fromGpu"].knownSize, 0).constData()); + + QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings()); + srb->setBindings({QRhiShaderResourceBinding::bufferLoad(blocks["toGpu"].binding, QRhiShaderResourceBinding::ComputeStage, toGpuBuffer.data()), + QRhiShaderResourceBinding::bufferLoadStore(blocks["fromGpu"].binding, QRhiShaderResourceBinding::ComputeStage, fromGpuBuffer.data())}); + + QVERIFY(srb->create()); + + QScopedPointer<QRhiComputePipeline> pipeline(rhi->newComputePipeline()); + pipeline->setShaderStage({QRhiShaderStage::Compute, s}); + pipeline->setShaderResourceBindings(srb.data()); + QVERIFY(pipeline->create()); + + cb->beginComputePass(u); + + cb->setComputePipeline(pipeline.data()); + cb->setShaderResources(); + cb->dispatch(1, 1, 1); + + u = rhi->nextResourceUpdateBatch(); + QVERIFY(u); + + int readCompletedNotifications = 0; + QRhiReadbackResult result; + result.completed = [&readCompletedNotifications]() { readCompletedNotifications++; }; + u->readBackBuffer(fromGpuBuffer.data(), 0, blocks["fromGpu"].knownSize, &result); + + cb->endComputePass(u); + + rhi->endOffscreenFrame(); + + QCOMPARE(readCompletedNotifications, 1); + + QCOMPARE(result.data.size(), blocks["fromGpu"].knownSize); + QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_int"].offset])[0], 1); + QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_ivec2"].offset])[0], 2); + QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_ivec2"].offset])[1], 3); + QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_ivec3"].offset])[0], 4); + QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_ivec3"].offset])[1], 5); + QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_ivec3"].offset])[2], 6); + QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_ivec4"].offset])[0], 7); + QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_ivec4"].offset])[1], 8); + QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_ivec4"].offset])[2], 9); + QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_ivec4"].offset])[3], 10); + + } +} + + void tst_QRhi::storageBufferRuntimeSizeCompute_data() +{ + rhiTestData(); +} + + void tst_QRhi::storageBufferRuntimeSizeCompute() +{ + // Use a compute shader to copy from one storage buffer with std430 runtime + // float array to another with std140 runtime int array. We fill the + // "toGpu" buffer with known float data generated and uploaded from the + // CPU, then dispatch a compute shader to copy from the "toGpu" buffer to + // the "fromGpu" buffer. We then readback the "fromGpu" buffer and verify + // that the results are as expected. This is primarily to test Metal + // SPIRV-Cross buffer size buffers. + + QFETCH(QRhi::Implementation, impl); + QFETCH(QRhiInitParams *, initParams); + + // we can't test with Null as there is no compute + if (impl == QRhi::Null) + return; + + QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr)); + if (!rhi) + QSKIP("QRhi could not be created, skipping testing"); + + if (!rhi->isFeatureSupported(QRhi::Feature::Compute)) + QSKIP("Compute is not supported with this graphics API, skipping test"); + + QShader s = loadShader(":/data/storagebuffer_runtime.comp.qsb"); + QVERIFY(s.isValid()); + QCOMPARE(s.description().storageBlocks().size(), 2); + + QMap<QByteArray, QShaderDescription::StorageBlock> blocks; + for (const QShaderDescription::StorageBlock &block : s.description().storageBlocks()) + blocks[block.blockName] = block; + + QMap<QByteArray, QShaderDescription::BlockVariable> toGpuMembers; + for (const QShaderDescription::BlockVariable &member : blocks["toGpu"].members) + toGpuMembers[member.name] = member; + + QMap<QByteArray, QShaderDescription::BlockVariable> fromGpuMembers; + for (const QShaderDescription::BlockVariable &member : blocks["fromGpu"].members) + fromGpuMembers[member.name] = member; + + for (QRhiBuffer::Type type : { QRhiBuffer::Type::Immutable, QRhiBuffer::Type::Static }) { + QRhiCommandBuffer *cb = nullptr; + + rhi->beginOffscreenFrame(&cb); + QVERIFY(cb); + + QRhiResourceUpdateBatch *u = rhi->nextResourceUpdateBatch(); + QVERIFY(u); + + const int stride430 = sizeof(float); + const int stride140 = 4 * sizeof(float); + const int length = 32; + + QScopedPointer<QRhiBuffer> toGpuBuffer( + rhi->newBuffer(type, QRhiBuffer::UsageFlag::StorageBuffer, + blocks["toGpu"].knownSize + length * stride430)); + QVERIFY(toGpuBuffer->create()); + + QScopedPointer<QRhiBuffer> fromGpuBuffer( + rhi->newBuffer(type, QRhiBuffer::UsageFlag::StorageBuffer, + blocks["fromGpu"].knownSize + length * stride140)); + QVERIFY(fromGpuBuffer->create()); + + QByteArray toGpuData(toGpuBuffer->size(), 0); + for (int i = 0; i < length; ++i) + reinterpret_cast<float &>(toGpuData.data()[toGpuMembers["_float"].offset + i * stride430]) = float(i); + + u->uploadStaticBuffer(toGpuBuffer.data(), 0, toGpuData.size(), toGpuData.constData()); + u->uploadStaticBuffer(fromGpuBuffer.data(), 0, blocks["fromGpu"].knownSize, + QByteArray(fromGpuBuffer->size(), 0).constData()); + + QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings()); + srb->setBindings( + { QRhiShaderResourceBinding::bufferLoadStore( + blocks["toGpu"].binding, QRhiShaderResourceBinding::ComputeStage, + toGpuBuffer.data()), + QRhiShaderResourceBinding::bufferLoadStore( + blocks["fromGpu"].binding, QRhiShaderResourceBinding::ComputeStage, + fromGpuBuffer.data()) }); + QVERIFY(srb->create()); + + QScopedPointer<QRhiComputePipeline> pipeline(rhi->newComputePipeline()); + pipeline->setShaderStage({ QRhiShaderStage::Compute, s }); + pipeline->setShaderResourceBindings(srb.data()); + QVERIFY(pipeline->create()); + + cb->beginComputePass(u); + + cb->setComputePipeline(pipeline.data()); + cb->setShaderResources(); + cb->dispatch(1, 1, 1); + + u = rhi->nextResourceUpdateBatch(); + QVERIFY(u); + int readbackCompleted = 0; + QRhiReadbackResult result; + result.completed = [&readbackCompleted]() { readbackCompleted++; }; + u->readBackBuffer(fromGpuBuffer.data(), 0, fromGpuBuffer->size(), &result); + + cb->endComputePass(u); + + rhi->endOffscreenFrame(); + + QVERIFY(readbackCompleted > 0); + QCOMPARE(result.data.size(), fromGpuBuffer->size()); + + for (int i = 0; i < length; ++i) + QCOMPARE(reinterpret_cast<const int &>(result.data.constData()[fromGpuMembers["_int"].offset + i * stride140]), i); + + QCOMPARE(readbackCompleted, 1); + + } + +} + +void tst_QRhi::storageBufferRuntimeSizeGraphics_data() +{ + rhiTestData(); +} + +void tst_QRhi::storageBufferRuntimeSizeGraphics() +{ +#ifdef Q_OS_ANDROID + if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) + QSKIP("Fails on Android 12 (QTBUG-108844)"); +#endif + // Draws a tessellated triangle with color determined by the length of + // buffers bound to shader stages. This is primarily to test Metal + // SPIRV-Cross buffer size buffers. + + QFETCH(QRhi::Implementation, impl); + QFETCH(QRhiInitParams *, initParams); + + QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr)); + if (!rhi) + QSKIP("QRhi could not be created, skipping testing rendering"); + + if (!rhi->isFeatureSupported(QRhi::Tessellation)) { + // From a Vulkan or Metal implementation we expect tessellation to work, + // even though it is optional (as per spec) for Vulkan. + QVERIFY(rhi->backend() != QRhi::Vulkan); + QVERIFY(rhi->backend() != QRhi::Metal); + QSKIP("Tessellation is not supported with this graphics API, skipping test"); + } + + if (rhi->backend() == QRhi::D3D11 || rhi->backend() == QRhi::D3D12) + QSKIP("Skipping tessellation test on D3D for now, test assets not prepared for HLSL yet"); + + QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8, QSize(64, 64), 1, + QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource)); + QVERIFY(texture->create()); + + QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ texture.data() })); + QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor()); + rt->setRenderPassDescriptor(rpDesc.data()); + QVERIFY(rt->create()); + + static const float triangleVertices[] = { + 0.0f, 0.5f, 0.0f, + -0.5f, -0.5f, 0.0f, + 0.5f, -0.5f, 0.0f, + }; + + QRhiResourceUpdateBatch *u = rhi->nextResourceUpdateBatch(); + QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(triangleVertices))); + QVERIFY(vbuf->create()); + u->uploadStaticBuffer(vbuf.data(), triangleVertices); + + QScopedPointer<QRhiBuffer> ubuf(rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64)); + QVERIFY(ubuf->create()); + + QMatrix4x4 mvp = rhi->clipSpaceCorrMatrix(); + u->updateDynamicBuffer(ubuf.data(), 0, 64, mvp.constData()); + + QScopedPointer<QRhiBuffer> ssbo5(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, 256)); + QVERIFY(ssbo5->create()); + + QScopedPointer<QRhiBuffer> ssbo3(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, 16)); + QVERIFY(ssbo3->create()); + + u->uploadStaticBuffer(ssbo3.data(), QVector<float>({ 1.0f, 1.0f, 1.0f, 1.0f }).constData()); + + QScopedPointer<QRhiBuffer> ssbo4(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, 128)); + QVERIFY(ssbo4->create()); + + const int red = 79; + const int green = 43; + const int blue = 251; + + QScopedPointer<QRhiBuffer> ssboR(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, red * sizeof(float))); + QVERIFY(ssboR->create()); + + QScopedPointer<QRhiBuffer> ssboG(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, green * sizeof(float))); + QVERIFY(ssboG->create()); + + QScopedPointer<QRhiBuffer> ssboB(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, blue * sizeof(float))); + QVERIFY(ssboB->create()); + + const int tessOuter0 = 1; + const int tessOuter1 = 2; + const int tessOuter2 = 3; + const int tessInner0 = 4; + + QScopedPointer<QRhiBuffer> ssboTessOuter0(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, tessOuter0 * sizeof(float))); + QVERIFY(ssboTessOuter0->create()); + + QScopedPointer<QRhiBuffer> ssboTessOuter1(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, tessOuter1 * sizeof(float))); + QVERIFY(ssboTessOuter1->create()); + + QScopedPointer<QRhiBuffer> ssboTessOuter2(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, tessOuter2 * sizeof(float))); + QVERIFY(ssboTessOuter2->create()); + + QScopedPointer<QRhiBuffer> ssboTessInner0(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, tessInner0 * sizeof(float))); + QVERIFY(ssboTessInner0->create()); + + + QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings()); + srb->setBindings({ QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::TessellationEvaluationStage, ubuf.data()), + QRhiShaderResourceBinding::bufferLoad(5, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::TessellationEvaluationStage, ssbo5.data()), + QRhiShaderResourceBinding::bufferLoad(3, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::TessellationEvaluationStage | QRhiShaderResourceBinding::FragmentStage, ssbo3.data()), + QRhiShaderResourceBinding::bufferLoad(4, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::TessellationEvaluationStage, ssbo4.data()), + QRhiShaderResourceBinding::bufferLoad(7, QRhiShaderResourceBinding::TessellationControlStage, ssboTessOuter0.data()), + QRhiShaderResourceBinding::bufferLoad(8, QRhiShaderResourceBinding::TessellationControlStage | QRhiShaderResourceBinding::TessellationEvaluationStage, ssboTessOuter1.data()), + QRhiShaderResourceBinding::bufferLoad(9, QRhiShaderResourceBinding::TessellationControlStage, ssboTessOuter2.data()), + QRhiShaderResourceBinding::bufferLoad(10, QRhiShaderResourceBinding::TessellationControlStage, ssboTessInner0.data()), + QRhiShaderResourceBinding::bufferLoad(1, QRhiShaderResourceBinding::FragmentStage, ssboG.data()), + QRhiShaderResourceBinding::bufferLoad(2, QRhiShaderResourceBinding::FragmentStage, ssboB.data()), + QRhiShaderResourceBinding::bufferLoad(6, QRhiShaderResourceBinding::FragmentStage, ssboR.data()) }); + + QVERIFY(srb->create()); + + QScopedPointer<QRhiGraphicsPipeline> pipeline(rhi->newGraphicsPipeline()); + + pipeline->setTopology(QRhiGraphicsPipeline::Patches); + pipeline->setPatchControlPointCount(3); + + pipeline->setShaderStages({ + { QRhiShaderStage::Vertex, loadShader(":/data/storagebuffer_runtime.vert.qsb") }, + { QRhiShaderStage::TessellationControl, loadShader(":/data/storagebuffer_runtime.tesc.qsb") }, + { QRhiShaderStage::TessellationEvaluation, loadShader(":/data/storagebuffer_runtime.tese.qsb") }, + { QRhiShaderStage::Fragment, loadShader(":/data/storagebuffer_runtime.frag.qsb") } + }); + + pipeline->setCullMode(QRhiGraphicsPipeline::None); + + QRhiVertexInputLayout inputLayout; + inputLayout.setBindings({ + { 3 * sizeof(float) } + }); + inputLayout.setAttributes({ + { 0, 0, QRhiVertexInputAttribute::Float3, 0 }, + }); + + pipeline->setVertexInputLayout(inputLayout); + pipeline->setShaderResourceBindings(srb.data()); + pipeline->setRenderPassDescriptor(rpDesc.data()); + + QVERIFY(pipeline->create()); + + QRhiCommandBuffer *cb = nullptr; + QCOMPARE(rhi->beginOffscreenFrame(&cb), QRhi::FrameOpSuccess); + + cb->beginPass(rt.data(), Qt::black, { 1.0f, 0 }, u); + cb->setGraphicsPipeline(pipeline.data()); + cb->setViewport({ 0, 0, float(rt->pixelSize().width()), float(rt->pixelSize().height()) }); + cb->setShaderResources(); + QRhiCommandBuffer::VertexInput vbufBinding(vbuf.data(), 0); + cb->setVertexInput(0, 1, &vbufBinding); + cb->draw(3); + + QRhiReadbackResult readResult; + QImage result; + readResult.completed = [&readResult, &result] { + result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()), + readResult.pixelSize.width(), readResult.pixelSize.height(), + QImage::Format_RGBA8888); + }; + QRhiResourceUpdateBatch *readbackBatch = rhi->nextResourceUpdateBatch(); + readbackBatch->readBackTexture({ texture.data() }, &readResult); + cb->endPass(readbackBatch); + + rhi->endOffscreenFrame(); + + QCOMPARE(result.size(), rt->pixelSize()); + + // cannot check rendering results with Null, because there is no rendering there + if (impl == QRhi::Null) + return; + + QCOMPARE(result.pixel(32, 32), qRgb(red, green, blue)); +} + +void tst_QRhi::halfPrecisionAttributes_data() +{ + rhiTestData(); +} + +void tst_QRhi::halfPrecisionAttributes() +{ +#ifdef Q_OS_ANDROID + if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) + QSKIP("Fails on Android 12 (QTBUG-108844)"); +#endif + QFETCH(QRhi::Implementation, impl); + QFETCH(QRhiInitParams *, initParams); + + QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr)); + if (!rhi) + QSKIP("QRhi could not be created, skipping testing rendering"); + + if (!rhi->isFeatureSupported(QRhi::HalfAttributes)) { + QVERIFY(rhi->backend() != QRhi::Vulkan); + QVERIFY(rhi->backend() != QRhi::Metal); + QVERIFY(rhi->backend() != QRhi::D3D11); + QVERIFY(rhi->backend() != QRhi::D3D12); + QSKIP("Half precision vertex attributes are not supported with this graphics API, skipping test"); + } + + const QSize outputSize(1920, 1080); + QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8, outputSize, 1, + QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource)); + QVERIFY(texture->create()); + + QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ texture.data() })); + QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor()); + rt->setRenderPassDescriptor(rpDesc.data()); + QVERIFY(rt->create()); + + QRhiCommandBuffer *cb = nullptr; + QVERIFY(rhi->beginOffscreenFrame(&cb) == QRhi::FrameOpSuccess); + QVERIFY(cb); + + QRhiResourceUpdateBatch *updates = rhi->nextResourceUpdateBatch(); + + // + // This test uses half3 vertices + // + // Note: D3D does not support half3 - rhi passes it through as half4. Because of this, D3D will + // report the following warning and error if we don't take precautions: + // + // D3D11 WARNING: ID3D11DeviceContext::Draw: Input vertex slot 0 has stride 6 which is less than + // the minimum stride logically expected from the current Input Layout (8 bytes). This is OK, as + // hardware is perfectly capable of reading overlapping data. However the developer probably did + // not intend to make use of this behavior. [ EXECUTION WARNING #355: + // DEVICE_DRAW_VERTEX_BUFFER_STRIDE_TOO_SMALL] + // + // D3D11 ERROR: ID3D11DeviceContext::Draw: Vertex Buffer Stride (6) at the input vertex slot 0 + // is not aligned properly. The current Input Layout imposes an alignment of (4) because of the + // Formats used with this slot. [ EXECUTION ERROR #367: DEVICE_DRAW_VERTEX_STRIDE_UNALIGNED] + // + // The same warning and error are produced for D3D12. The rendered output is correct despite + // the warning and error. + // + // To avoid these errors, we pad the vertices to 8 byte stride. + // + static const qfloat16 vertices[] = { + qfloat16(-1.0), qfloat16(-1.0), qfloat16(0.0), qfloat16(0.0), + qfloat16(1.0), qfloat16(-1.0), qfloat16(0.0), qfloat16(0.0), + qfloat16(0.0), qfloat16(1.0), qfloat16(0.0), qfloat16(0.0), + }; + + QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(vertices))); + QVERIFY(vbuf->create()); + updates->uploadStaticBuffer(vbuf.data(), vertices); + + QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings()); + QVERIFY(srb->create()); + + QScopedPointer<QRhiGraphicsPipeline> pipeline(rhi->newGraphicsPipeline()); + QShader vs = loadShader(":/data/half.vert.qsb"); + QVERIFY(vs.isValid()); + QShader fs = loadShader(":/data/simple.frag.qsb"); + QVERIFY(fs.isValid()); + pipeline->setShaderStages({ { QRhiShaderStage::Vertex, vs }, { QRhiShaderStage::Fragment, fs } }); + QRhiVertexInputLayout inputLayout; + inputLayout.setBindings({ { 4 * sizeof(qfloat16) } }); // 8 byte vertex stride for D3D + inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Half3, 0 } }); + pipeline->setVertexInputLayout(inputLayout); + pipeline->setShaderResourceBindings(srb.data()); + pipeline->setRenderPassDescriptor(rpDesc.data()); + QVERIFY(pipeline->create()); + + cb->beginPass(rt.data(), Qt::blue, { 1.0f, 0 }, updates); + cb->setGraphicsPipeline(pipeline.data()); + cb->setViewport({ 0, 0, float(outputSize.width()), float(outputSize.height()) }); + QRhiCommandBuffer::VertexInput vbindings(vbuf.data(), 0); + cb->setVertexInput(0, 1, &vbindings); + cb->draw(3); + + QRhiReadbackResult readResult; + QImage result; + readResult.completed = [&readResult, &result] { + result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()), + readResult.pixelSize.width(), readResult.pixelSize.height(), + QImage::Format_RGBA8888_Premultiplied); // non-owning, no copy needed because readResult outlives result + }; + QRhiResourceUpdateBatch *readbackBatch = rhi->nextResourceUpdateBatch(); + readbackBatch->readBackTexture({ texture.data() }, &readResult); + cb->endPass(readbackBatch); + + rhi->endOffscreenFrame(); + // Offscreen frames are synchronous, so the readback is guaranteed to + // complete at this point. This would not be the case with swapchain-based + // frames. + QCOMPARE(result.size(), texture->pixelSize()); + + if (impl == QRhi::Null) + return; + + // Now we have a red rectangle on blue background. + const int y = 100; + const quint32 *p = reinterpret_cast<const quint32 *>(result.constScanLine(y)); + int x = result.width() - 1; + int redCount = 0; + int blueCount = 0; + const int maxFuzz = 1; + while (x-- >= 0) { + const QRgb c(*p++); + if (qRed(c) >= (255 - maxFuzz) && qGreen(c) == 0 && qBlue(c) == 0) + ++redCount; + else if (qRed(c) == 0 && qGreen(c) == 0 && qBlue(c) >= (255 - maxFuzz)) + ++blueCount; + else + QFAIL("Encountered a pixel that is neither red or blue"); + } + + QCOMPARE(redCount + blueCount, texture->pixelSize().width()); + QVERIFY(redCount != 0); + QVERIFY(blueCount != 0); + + // The triangle is "pointing up" in the resulting image with OpenGL + // (because Y is up both in normalized device coordinates and in images) + // and Vulkan (because Y is down in both and the vertex data was specified + // with Y up in mind), but "pointing down" with D3D (because Y is up in NDC + // but down in images). + if (rhi->isYUpInFramebuffer() == rhi->isYUpInNDC()) + QVERIFY(redCount < blueCount); + else + QVERIFY(redCount > blueCount); + +} + #include <tst_qrhi.moc> QTEST_MAIN(tst_QRhi) diff --git a/tests/auto/gui/rhi/qshader/CMakeLists.txt b/tests/auto/gui/rhi/qshader/CMakeLists.txt index 9807b19e53..09bf0d585d 100644 --- a/tests/auto/gui/rhi/qshader/CMakeLists.txt +++ b/tests/auto/gui/rhi/qshader/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from qshader.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qshader Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qshader LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Resources: file(GLOB_RECURSE qshader_resource_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" @@ -13,7 +20,7 @@ file(GLOB_RECURSE qshader_resource_files qt_internal_add_test(tst_qshader SOURCES tst_qshader.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate TESTDATA ${qshader_resource_files} diff --git a/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.frag.qsb b/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.frag.qsb Binary files differnew file mode 100644 index 0000000000..4d49ede3ff --- /dev/null +++ b/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.frag.qsb diff --git a/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.tesc.qsb b/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.tesc.qsb Binary files differnew file mode 100644 index 0000000000..ea68da7eb4 --- /dev/null +++ b/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.tesc.qsb diff --git a/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.tese.qsb b/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.tese.qsb Binary files differnew file mode 100644 index 0000000000..41005f76bc --- /dev/null +++ b/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.tese.qsb diff --git a/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.vert.qsb b/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.vert.qsb Binary files differnew file mode 100644 index 0000000000..39734b6d5d --- /dev/null +++ b/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.vert.qsb diff --git a/tests/auto/gui/rhi/qshader/data/storage_buffer_info_v8.comp.qsb b/tests/auto/gui/rhi/qshader/data/storage_buffer_info_v8.comp.qsb Binary files differnew file mode 100644 index 0000000000..edcd84cbe6 --- /dev/null +++ b/tests/auto/gui/rhi/qshader/data/storage_buffer_info_v8.comp.qsb diff --git a/tests/auto/gui/rhi/qshader/data/color.vert b/tests/auto/gui/rhi/qshader/data_src/color.vert index c92f71b9e1..c92f71b9e1 100644 --- a/tests/auto/gui/rhi/qshader/data/color.vert +++ b/tests/auto/gui/rhi/qshader/data_src/color.vert diff --git a/tests/auto/gui/rhi/qshader/data/texture.frag b/tests/auto/gui/rhi/qshader/data_src/texture.frag index bd22f817e0..bd22f817e0 100644 --- a/tests/auto/gui/rhi/qshader/data/texture.frag +++ b/tests/auto/gui/rhi/qshader/data_src/texture.frag diff --git a/tests/auto/gui/rhi/qshader/data/texture_sep.frag b/tests/auto/gui/rhi/qshader/data_src/texture_sep.frag index 368e851bb4..368e851bb4 100644 --- a/tests/auto/gui/rhi/qshader/data/texture_sep.frag +++ b/tests/auto/gui/rhi/qshader/data_src/texture_sep.frag diff --git a/tests/auto/gui/rhi/qshader/tst_qshader.cpp b/tests/auto/gui/rhi/qshader/tst_qshader.cpp index cd883b34d9..9e179c95c3 100644 --- a/tests/auto/gui/rhi/qshader/tst_qshader.cpp +++ b/tests/auto/gui/rhi/qshader/tst_qshader.cpp @@ -1,12 +1,12 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QFile> #include <QBuffer> -#include <QtGui/private/qshaderdescription_p_p.h> -#include <QtGui/private/qshader_p_p.h> +#include <private/qshaderdescription_p.h> +#include <private/qshader_p.h> class tst_QShader : public QObject { @@ -18,12 +18,15 @@ private slots: void genVariants(); void shaderDescImplicitSharing(); void bakedShaderImplicitSharing(); + void sortedKeys(); void mslResourceMapping(); void serializeShaderDesc(); void comparison(); void loadV4(); void manualShaderPackCreation(); void loadV6WithSeparateImagesAndSamplers(); + void loadV7(); + void loadV8(); }; static QShader getShader(const QString &name) @@ -56,7 +59,7 @@ void tst_QShader::simpleCompileCheckResults() QShader s = getShader(QLatin1String(":/data/color_spirv_v5.vert.qsb")); QVERIFY(s.isValid()); QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 5); - QCOMPARE(s.availableShaders().count(), 1); + QCOMPARE(s.availableShaders().size(), 1); const QShaderCode shader = s.shader(QShaderKey(QShader::SpirvShader, QShaderVersion(100))); @@ -65,7 +68,7 @@ void tst_QShader::simpleCompileCheckResults() const QShaderDescription desc = s.description(); QVERIFY(desc.isValid()); - QCOMPARE(desc.inputVariables().count(), 2); + QCOMPARE(desc.inputVariables().size(), 2); for (const QShaderDescription::InOutVariable &v : desc.inputVariables()) { switch (v.location) { case 0: @@ -81,7 +84,7 @@ void tst_QShader::simpleCompileCheckResults() break; } } - QCOMPARE(desc.outputVariables().count(), 1); + QCOMPARE(desc.outputVariables().size(), 1); for (const QShaderDescription::InOutVariable &v : desc.outputVariables()) { switch (v.location) { case 0: @@ -93,15 +96,15 @@ void tst_QShader::simpleCompileCheckResults() break; } } - QCOMPARE(desc.uniformBlocks().count(), 1); + QCOMPARE(desc.uniformBlocks().size(), 1); const QShaderDescription::UniformBlock blk = desc.uniformBlocks().first(); QCOMPARE(blk.blockName, QByteArrayLiteral("buf")); QCOMPARE(blk.structName, QByteArrayLiteral("ubuf")); QCOMPARE(blk.size, 68); QCOMPARE(blk.binding, 0); QCOMPARE(blk.descriptorSet, 0); - QCOMPARE(blk.members.count(), 2); - for (int i = 0; i < blk.members.count(); ++i) { + QCOMPARE(blk.members.size(), 2); + for (int i = 0; i < blk.members.size(); ++i) { const QShaderDescription::BlockVariable v = blk.members[i]; switch (i) { case 0: @@ -118,7 +121,7 @@ void tst_QShader::simpleCompileCheckResults() QCOMPARE(v.type, QShaderDescription::Float); break; default: - QFAIL(qPrintable(QStringLiteral("Too many blocks: %1").arg(blk.members.count()))); + QFAIL(qPrintable(QStringLiteral("Too many blocks: %1").arg(blk.members.size()))); break; } } @@ -131,7 +134,7 @@ void tst_QShader::genVariants() // + batchable variants QVERIFY(s.isValid()); QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 5); - QCOMPARE(s.availableShaders().count(), 2 * 6); + QCOMPARE(s.availableShaders().size(), 2 * 6); int batchableVariantCount = 0; int batchableGlslVariantCount = 0; @@ -154,33 +157,33 @@ void tst_QShader::shaderDescImplicitSharing() QShader s = getShader(QLatin1String(":/data/color_spirv_v5.vert.qsb")); QVERIFY(s.isValid()); QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 5); - QCOMPARE(s.availableShaders().count(), 1); + QCOMPARE(s.availableShaders().size(), 1); QVERIFY(s.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); QShaderDescription d0 = s.description(); QVERIFY(d0.isValid()); - QCOMPARE(d0.inputVariables().count(), 2); - QCOMPARE(d0.outputVariables().count(), 1); - QCOMPARE(d0.uniformBlocks().count(), 1); + QCOMPARE(d0.inputVariables().size(), 2); + QCOMPARE(d0.outputVariables().size(), 1); + QCOMPARE(d0.uniformBlocks().size(), 1); QShaderDescription d1 = d0; QVERIFY(QShaderDescriptionPrivate::get(&d0) == QShaderDescriptionPrivate::get(&d1)); - QCOMPARE(d0.inputVariables().count(), 2); - QCOMPARE(d0.outputVariables().count(), 1); - QCOMPARE(d0.uniformBlocks().count(), 1); - QCOMPARE(d1.inputVariables().count(), 2); - QCOMPARE(d1.outputVariables().count(), 1); - QCOMPARE(d1.uniformBlocks().count(), 1); + QCOMPARE(d0.inputVariables().size(), 2); + QCOMPARE(d0.outputVariables().size(), 1); + QCOMPARE(d0.uniformBlocks().size(), 1); + QCOMPARE(d1.inputVariables().size(), 2); + QCOMPARE(d1.outputVariables().size(), 1); + QCOMPARE(d1.uniformBlocks().size(), 1); QCOMPARE(d0, d1); d1.detach(); QVERIFY(QShaderDescriptionPrivate::get(&d0) != QShaderDescriptionPrivate::get(&d1)); - QCOMPARE(d0.inputVariables().count(), 2); - QCOMPARE(d0.outputVariables().count(), 1); - QCOMPARE(d0.uniformBlocks().count(), 1); - QCOMPARE(d1.inputVariables().count(), 2); - QCOMPARE(d1.outputVariables().count(), 1); - QCOMPARE(d1.uniformBlocks().count(), 1); + QCOMPARE(d0.inputVariables().size(), 2); + QCOMPARE(d0.outputVariables().size(), 1); + QCOMPARE(d0.uniformBlocks().size(), 1); + QCOMPARE(d1.inputVariables().size(), 2); + QCOMPARE(d1.outputVariables().size(), 1); + QCOMPARE(d1.uniformBlocks().size(), 1); QCOMPARE(d0, d1); d1 = QShaderDescription(); @@ -192,24 +195,24 @@ void tst_QShader::bakedShaderImplicitSharing() QShader s0 = getShader(QLatin1String(":/data/color_spirv_v5.vert.qsb")); QVERIFY(s0.isValid()); QCOMPARE(QShaderPrivate::get(&s0)->qsbVersion, 5); - QCOMPARE(s0.availableShaders().count(), 1); + QCOMPARE(s0.availableShaders().size(), 1); QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); { QShader s1 = s0; QVERIFY(QShaderPrivate::get(&s0) == QShaderPrivate::get(&s1)); - QCOMPARE(s0.availableShaders().count(), 1); + QCOMPARE(s0.availableShaders().size(), 1); QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); - QCOMPARE(s1.availableShaders().count(), 1); + QCOMPARE(s1.availableShaders().size(), 1); QVERIFY(s1.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); QCOMPARE(s0.stage(), s1.stage()); QCOMPARE(s0, s1); s1.detach(); QVERIFY(QShaderPrivate::get(&s0) != QShaderPrivate::get(&s1)); - QCOMPARE(s0.availableShaders().count(), 1); + QCOMPARE(s0.availableShaders().size(), 1); QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); - QCOMPARE(s1.availableShaders().count(), 1); + QCOMPARE(s1.availableShaders().size(), 1); QVERIFY(s1.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); QCOMPARE(s0.stage(), s1.stage()); QCOMPARE(s0, s1); @@ -222,22 +225,32 @@ void tst_QShader::bakedShaderImplicitSharing() s1.setStage(QShader::FragmentStage); // call a setter to trigger a detach QVERIFY(QShaderPrivate::get(&s0) != QShaderPrivate::get(&s1)); - QCOMPARE(s0.availableShaders().count(), 1); + QCOMPARE(s0.availableShaders().size(), 1); QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); - QCOMPARE(s1.availableShaders().count(), 1); + QCOMPARE(s1.availableShaders().size(), 1); QVERIFY(s1.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); QShaderDescription d0 = s0.description(); - QCOMPARE(d0.inputVariables().count(), 2); - QCOMPARE(d0.outputVariables().count(), 1); - QCOMPARE(d0.uniformBlocks().count(), 1); + QCOMPARE(d0.inputVariables().size(), 2); + QCOMPARE(d0.outputVariables().size(), 1); + QCOMPARE(d0.uniformBlocks().size(), 1); QShaderDescription d1 = s1.description(); - QCOMPARE(d1.inputVariables().count(), 2); - QCOMPARE(d1.outputVariables().count(), 1); - QCOMPARE(d1.uniformBlocks().count(), 1); + QCOMPARE(d1.inputVariables().size(), 2); + QCOMPARE(d1.outputVariables().size(), 1); + QCOMPARE(d1.uniformBlocks().size(), 1); QVERIFY(s0 != s1); } } +void tst_QShader::sortedKeys() +{ + QShader s = getShader(QLatin1String(":/data/texture_all_v4.frag.qsb")); + QVERIFY(s.isValid()); + QList<QShaderKey> availableShaders = s.availableShaders(); + QCOMPARE(availableShaders.size(), 7); + std::sort(availableShaders.begin(), availableShaders.end()); + QCOMPARE(availableShaders, s.availableShaders()); +} + void tst_QShader::mslResourceMapping() { QShader s = getShader(QLatin1String(":/data/texture_all_v4.frag.qsb")); @@ -245,7 +258,7 @@ void tst_QShader::mslResourceMapping() QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 4); const QList<QShaderKey> availableShaders = s.availableShaders(); - QCOMPARE(availableShaders.count(), 7); + QCOMPARE(availableShaders.size(), 7); QVERIFY(availableShaders.contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); QVERIFY(availableShaders.contains(QShaderKey(QShader::MslShader, QShaderVersion(12)))); QVERIFY(availableShaders.contains(QShaderKey(QShader::HlslShader, QShaderVersion(50)))); @@ -264,7 +277,7 @@ void tst_QShader::mslResourceMapping() resMap = s.nativeResourceBindingMap(QShaderKey(QShader::MslShader, QShaderVersion(12))); QVERIFY(!resMap.isEmpty()); - QCOMPARE(resMap.count(), 2); + QCOMPARE(resMap.size(), 2); QCOMPARE(resMap.value(0).first, 0); // mapped to native buffer index 0 QCOMPARE(resMap.value(1), qMakePair(0, 0)); // mapped to native texture index 0 and sampler index 0 } @@ -281,7 +294,7 @@ void tst_QShader::serializeShaderDesc() QBuffer buf(&data); QDataStream ds(&buf); QVERIFY(buf.open(QIODevice::WriteOnly)); - desc.serialize(&ds); + desc.serialize(&ds, QShaderPrivate::QSB_VERSION); } QVERIFY(!data.isEmpty()); @@ -306,7 +319,7 @@ void tst_QShader::serializeShaderDesc() QBuffer buf(&data); QDataStream ds(&buf); QVERIFY(buf.open(QIODevice::WriteOnly)); - desc.serialize(&ds); + desc.serialize(&ds, QShaderPrivate::QSB_VERSION); } QVERIFY(!data.isEmpty()); @@ -366,7 +379,7 @@ void tst_QShader::loadV4() QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 4); const QList<QShaderKey> availableShaders = s.availableShaders(); - QCOMPARE(availableShaders.count(), 7); + QCOMPARE(availableShaders.size(), 7); QVERIFY(availableShaders.contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); QVERIFY(availableShaders.contains(QShaderKey(QShader::MslShader, QShaderVersion(12)))); QVERIFY(availableShaders.contains(QShaderKey(QShader::HlslShader, QShaderVersion(50)))); @@ -377,7 +390,7 @@ void tst_QShader::loadV4() const QShaderDescription desc = s.description(); QVERIFY(desc.isValid()); - QCOMPARE(desc.inputVariables().count(), 1); + QCOMPARE(desc.inputVariables().size(), 1); for (const QShaderDescription::InOutVariable &v : desc.inputVariables()) { switch (v.location) { case 0: @@ -389,7 +402,7 @@ void tst_QShader::loadV4() break; } } - QCOMPARE(desc.outputVariables().count(), 1); + QCOMPARE(desc.outputVariables().size(), 1); for (const QShaderDescription::InOutVariable &v : desc.outputVariables()) { switch (v.location) { case 0: @@ -401,15 +414,15 @@ void tst_QShader::loadV4() break; } } - QCOMPARE(desc.uniformBlocks().count(), 1); + QCOMPARE(desc.uniformBlocks().size(), 1); const QShaderDescription::UniformBlock blk = desc.uniformBlocks().first(); QCOMPARE(blk.blockName, QByteArrayLiteral("buf")); QCOMPARE(blk.structName, QByteArrayLiteral("ubuf")); QCOMPARE(blk.size, 68); QCOMPARE(blk.binding, 0); QCOMPARE(blk.descriptorSet, 0); - QCOMPARE(blk.members.count(), 2); - for (int i = 0; i < blk.members.count(); ++i) { + QCOMPARE(blk.members.size(), 2); + for (int i = 0; i < blk.members.size(); ++i) { const QShaderDescription::BlockVariable v = blk.members[i]; switch (i) { case 0: @@ -426,7 +439,7 @@ void tst_QShader::loadV4() QCOMPARE(v.type, QShaderDescription::Float); break; default: - QFAIL(qPrintable(QStringLiteral("Bad many blocks: %1").arg(blk.members.count()))); + QFAIL(qPrintable(QStringLiteral("Bad many blocks: %1").arg(blk.members.size()))); break; } } @@ -537,11 +550,11 @@ void tst_QShader::manualShaderPackCreation() const QByteArray serialized = shaderPack.serialized(); QShader newShaderPack = QShader::fromSerialized(serialized); - QCOMPARE(newShaderPack.availableShaders().count(), 2); - QCOMPARE(newShaderPack.description().inputVariables().count(), 1); - QCOMPARE(newShaderPack.description().outputVariables().count(), 1); - QCOMPARE(newShaderPack.description().uniformBlocks().count(), 1); - QCOMPARE(newShaderPack.description().combinedImageSamplers().count(), 1); + QCOMPARE(newShaderPack.availableShaders().size(), 2); + QCOMPARE(newShaderPack.description().inputVariables().size(), 1); + QCOMPARE(newShaderPack.description().outputVariables().size(), 1); + QCOMPARE(newShaderPack.description().uniformBlocks().size(), 1); + QCOMPARE(newShaderPack.description().combinedImageSamplers().size(), 1); QCOMPARE(newShaderPack.shader(QShaderKey(QShader::GlslShader, QShaderVersion(100, QShaderVersion::GlslEs))).shader(), fs_gles); QCOMPARE(newShaderPack.shader(QShaderKey(QShader::GlslShader, QShaderVersion(120))).shader(), fs_gl); } @@ -553,7 +566,7 @@ void tst_QShader::loadV6WithSeparateImagesAndSamplers() QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 6); const QList<QShaderKey> availableShaders = s.availableShaders(); - QCOMPARE(availableShaders.count(), 6); + QCOMPARE(availableShaders.size(), 6); QVERIFY(availableShaders.contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); QVERIFY(availableShaders.contains(QShaderKey(QShader::MslShader, QShaderVersion(12)))); QVERIFY(availableShaders.contains(QShaderKey(QShader::HlslShader, QShaderVersion(50)))); @@ -563,10 +576,10 @@ void tst_QShader::loadV6WithSeparateImagesAndSamplers() QShader::NativeResourceBindingMap resMap = s.nativeResourceBindingMap(QShaderKey(QShader::HlslShader, QShaderVersion(50))); - QVERIFY(resMap.count() == 4); + QVERIFY(resMap.size() == 4); QVERIFY(s.separateToCombinedImageSamplerMappingList(QShaderKey(QShader::HlslShader, QShaderVersion(50))).isEmpty()); resMap = s.nativeResourceBindingMap(QShaderKey(QShader::MslShader, QShaderVersion(12))); - QVERIFY(resMap.count() == 4); + QVERIFY(resMap.size() == 4); QVERIFY(s.separateToCombinedImageSamplerMappingList(QShaderKey(QShader::MslShader, QShaderVersion(12))).isEmpty()); for (auto key : { @@ -575,8 +588,112 @@ void tst_QShader::loadV6WithSeparateImagesAndSamplers() QShaderKey(QShader::GlslShader, QShaderVersion(150)) }) { auto list = s.separateToCombinedImageSamplerMappingList(key); - QCOMPARE(list.count(), 2); + QCOMPARE(list.size(), 2); + } +} + +void tst_QShader::loadV7() +{ + QShader vert = getShader(QLatin1String(":/data/metal_enabled_tessellation_v7.vert.qsb")); + QVERIFY(vert.isValid()); + QCOMPARE(QShaderPrivate::get(&vert)->qsbVersion, 7); + QCOMPARE(vert.availableShaders().size(), 8); + + QCOMPARE(vert.description().inputVariables().size(), 2); + QCOMPARE(vert.description().outputBuiltinVariables().size(), 1); + QCOMPARE(vert.description().outputBuiltinVariables()[0].type, QShaderDescription::PositionBuiltin); + QCOMPARE(vert.description().outputVariables().size(), 1); + QCOMPARE(vert.description().outputVariables()[0].name, QByteArrayLiteral("v_color")); + + QVERIFY(vert.availableShaders().contains(QShaderKey(QShader::MslShader, QShaderVersion(12)))); + QVERIFY(!vert.shader(QShaderKey(QShader::MslShader, QShaderVersion(12), QShader::NonIndexedVertexAsComputeShader)).shader().isEmpty()); + QVERIFY(!vert.shader(QShaderKey(QShader::MslShader, QShaderVersion(12), QShader::UInt16IndexedVertexAsComputeShader)).shader().isEmpty()); + QVERIFY(!vert.shader(QShaderKey(QShader::MslShader, QShaderVersion(12), QShader::UInt32IndexedVertexAsComputeShader)).shader().isEmpty()); + + QShader tesc = getShader(QLatin1String(":/data/metal_enabled_tessellation_v7.tesc.qsb")); + QVERIFY(tesc.isValid()); + QCOMPARE(QShaderPrivate::get(&tesc)->qsbVersion, 7); + QCOMPARE(tesc.availableShaders().size(), 5); + QCOMPARE(tesc.description().tessellationOutputVertexCount(), 3u); + + QCOMPARE(tesc.description().inputBuiltinVariables().size(), 2); + QCOMPARE(tesc.description().outputBuiltinVariables().size(), 3); + // builtins must be sorted based on the type + QCOMPARE(tesc.description().inputBuiltinVariables()[0].type, QShaderDescription::PositionBuiltin); + QCOMPARE(tesc.description().inputBuiltinVariables()[1].type, QShaderDescription::InvocationIdBuiltin); + QCOMPARE(tesc.description().outputBuiltinVariables()[0].type, QShaderDescription::PositionBuiltin); + QCOMPARE(tesc.description().outputBuiltinVariables()[1].type, QShaderDescription::TessLevelOuterBuiltin); + QCOMPARE(tesc.description().outputBuiltinVariables()[2].type, QShaderDescription::TessLevelInnerBuiltin); + + QCOMPARE(tesc.description().outputVariables().size(), 3); + for (const QShaderDescription::InOutVariable &v : tesc.description().outputVariables()) { + switch (v.location) { + case 0: + QCOMPARE(v.name, QByteArrayLiteral("outColor")); + QCOMPARE(v.type, QShaderDescription::Vec3); + QCOMPARE(v.perPatch, false); + break; + case 1: + QCOMPARE(v.name, QByteArrayLiteral("stuff")); + QCOMPARE(v.type, QShaderDescription::Vec3); + QCOMPARE(v.perPatch, true); + break; + case 2: + QCOMPARE(v.name, QByteArrayLiteral("more_stuff")); + QCOMPARE(v.type, QShaderDescription::Float); + QCOMPARE(v.perPatch, true); + break; + default: + QFAIL(qPrintable(QStringLiteral("Bad location: %1").arg(v.location))); + break; + } } + + QVERIFY(!tesc.shader(QShaderKey(QShader::MslShader, QShaderVersion(12))).shader().isEmpty()); + QCOMPARE(tesc.nativeShaderInfo(QShaderKey(QShader::SpirvShader, QShaderVersion(100))).extraBufferBindings.size(), 0); + QCOMPARE(tesc.nativeShaderInfo(QShaderKey(QShader::MslShader, QShaderVersion(12))).extraBufferBindings.size(), 5); + + QShader tese = getShader(QLatin1String(":/data/metal_enabled_tessellation_v7.tese.qsb")); + QVERIFY(tese.isValid()); + QCOMPARE(QShaderPrivate::get(&tese)->qsbVersion, 7); + QCOMPARE(tese.availableShaders().size(), 5); + QCOMPARE(tese.description().tessellationMode(), QShaderDescription::TrianglesTessellationMode); + QCOMPARE(tese.description().tessellationWindingOrder(), QShaderDescription::CcwTessellationWindingOrder); + QCOMPARE(tese.description().tessellationPartitioning(), QShaderDescription::FractionalOddTessellationPartitioning); + + QCOMPARE(tese.description().inputBuiltinVariables()[0].type, QShaderDescription::PositionBuiltin); + QCOMPARE(tese.description().inputBuiltinVariables()[1].type, QShaderDescription::TessLevelOuterBuiltin); + QCOMPARE(tese.description().inputBuiltinVariables()[2].type, QShaderDescription::TessLevelInnerBuiltin); + QCOMPARE(tese.description().inputBuiltinVariables()[3].type, QShaderDescription::TessCoordBuiltin); + + QCOMPARE(tese.nativeResourceBindingMap(QShaderKey(QShader::MslShader, QShaderVersion(12))).size(), 1); + QCOMPARE(tese.nativeResourceBindingMap(QShaderKey(QShader::MslShader, QShaderVersion(12))).value(0), qMakePair(0, -1)); + + QShader frag = getShader(QLatin1String(":/data/metal_enabled_tessellation_v7.frag.qsb")); + QVERIFY(frag.isValid()); + QCOMPARE(QShaderPrivate::get(&frag)->qsbVersion, 7); +} + +void tst_QShader::loadV8() +{ + QShader s = getShader(QLatin1String(":/data/storage_buffer_info_v8.comp.qsb")); + QVERIFY(s.isValid()); + QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 8); + + const QList<QShaderKey> availableShaders = s.availableShaders(); + QCOMPARE(availableShaders.size(), 5); + QVERIFY(availableShaders.contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); + QVERIFY(availableShaders.contains(QShaderKey(QShader::MslShader, QShaderVersion(12)))); + QVERIFY(availableShaders.contains(QShaderKey(QShader::HlslShader, QShaderVersion(50)))); + QVERIFY(availableShaders.contains( + QShaderKey(QShader::GlslShader, QShaderVersion(310, QShaderVersion::GlslEs)))); + QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(430)))); + + QCOMPARE(s.description().storageBlocks().size(), 1); + QCOMPARE(s.description().storageBlocks().last().runtimeArrayStride, 4); + QCOMPARE(s.description().storageBlocks().last().qualifierFlags, + QShaderDescription::QualifierFlags(QShaderDescription::QualifierWriteOnly + | QShaderDescription::QualifierRestrict)); } #include <tst_qshader.moc> diff --git a/tests/auto/gui/text/CMakeLists.txt b/tests/auto/gui/text/CMakeLists.txt index 5040060a33..30b35fb10a 100644 --- a/tests/auto/gui/text/CMakeLists.txt +++ b/tests/auto/gui/text/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from text.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause add_subdirectory(qabstracttextdocumentlayout) add_subdirectory(qfont) @@ -10,12 +11,15 @@ add_subdirectory(qstatictext) add_subdirectory(qsyntaxhighlighter) add_subdirectory(qtextblock) add_subdirectory(qtextcursor) -add_subdirectory(qtextdocumentfragment) +if(QT_FEATURE_texthtmlparser) + add_subdirectory(qtextdocumentfragment) +endif() add_subdirectory(qtextdocumentlayout) add_subdirectory(qtextformat) +add_subdirectory(qtextimagehandler) add_subdirectory(qtextlist) add_subdirectory(qtextobject) -# add_subdirectory(qtextscriptengine) # disable until system_harfbuzz feature is available # special case +# add_subdirectory(qtextscriptengine) # disable until system_harfbuzz feature is available add_subdirectory(qtexttable) add_subdirectory(qinputcontrol) if(QT_FEATURE_private_tests AND TARGET Qt::Xml) @@ -24,7 +28,6 @@ endif() if(QT_FEATURE_private_tests) add_subdirectory(qfontcache) add_subdirectory(qtextlayout) - add_subdirectory(qzip) add_subdirectory(qtextodfwriter) endif() if(TARGET Qt::Xml) diff --git a/tests/auto/gui/text/qabstracttextdocumentlayout/CMakeLists.txt b/tests/auto/gui/text/qabstracttextdocumentlayout/CMakeLists.txt index f78e1d81c7..316b9cd3c6 100644 --- a/tests/auto/gui/text/qabstracttextdocumentlayout/CMakeLists.txt +++ b/tests/auto/gui/text/qabstracttextdocumentlayout/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qabstracttextdocumentlayout.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qabstracttextdocumentlayout Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qabstracttextdocumentlayout LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qabstracttextdocumentlayout SOURCES tst_qabstracttextdocumentlayout.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/text/qabstracttextdocumentlayout/tst_qabstracttextdocumentlayout.cpp b/tests/auto/gui/text/qabstracttextdocumentlayout/tst_qabstracttextdocumentlayout.cpp index 4ab2d1adb3..3d0fab4603 100644 --- a/tests/auto/gui/text/qabstracttextdocumentlayout/tst_qabstracttextdocumentlayout.cpp +++ b/tests/auto/gui/text/qabstracttextdocumentlayout/tst_qabstracttextdocumentlayout.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -22,9 +22,11 @@ public: private slots: void getSetCheck(); void maximumBlockCount(); +#ifndef QT_NO_TEXTHTMLPARSER void anchorAt(); void imageAt(); void formatAt(); +#endif }; tst_QAbstractTextDocumentLayout::tst_QAbstractTextDocumentLayout() @@ -119,6 +121,7 @@ void tst_QAbstractTextDocumentLayout::maximumBlockCount() QCOMPARE(layout.blockCount, 10); } +#ifndef QT_NO_TEXTHTMLPARSER void tst_QAbstractTextDocumentLayout::anchorAt() { QTextDocument doc; @@ -126,7 +129,7 @@ void tst_QAbstractTextDocumentLayout::anchorAt() QAbstractTextDocumentLayout *documentLayout = doc.documentLayout(); QTextBlock firstBlock = doc.begin(); QTextLayout *layout = firstBlock.layout(); - layout->setPreeditArea(doc.toPlainText().length(), "xxx"); + layout->setPreeditArea(doc.toPlainText().size(), "xxx"); doc.setPageSize(QSizeF(1000, 1000)); QFontMetrics metrics(layout->font()); @@ -156,7 +159,7 @@ void tst_QAbstractTextDocumentLayout::imageAt() QAbstractTextDocumentLayout *documentLayout = doc.documentLayout(); QTextBlock firstBlock = doc.begin(); QTextLayout *layout = firstBlock.layout(); - layout->setPreeditArea(doc.toPlainText().length(), "xxx"); + layout->setPreeditArea(doc.toPlainText().size(), "xxx"); doc.setPageSize(QSizeF(1000, 1000)); QFontMetrics metrics(layout->font()); @@ -181,7 +184,7 @@ void tst_QAbstractTextDocumentLayout::formatAt() QAbstractTextDocumentLayout *documentLayout = doc.documentLayout(); QTextBlock firstBlock = doc.begin(); QTextLayout *layout = firstBlock.layout(); - layout->setPreeditArea(doc.toPlainText().length(), "xxx"); + layout->setPreeditArea(doc.toPlainText().size(), "xxx"); doc.setPageSize(QSizeF(1000, 1000)); QFontMetrics metrics(layout->font()); @@ -204,6 +207,7 @@ void tst_QAbstractTextDocumentLayout::formatAt() QVERIFY(!format.toCharFormat().fontItalic()); QVERIFY(!format.isImageFormat()); } +#endif QTEST_MAIN(tst_QAbstractTextDocumentLayout) #include "tst_qabstracttextdocumentlayout.moc" diff --git a/tests/auto/gui/text/qcssparser/CMakeLists.txt b/tests/auto/gui/text/qcssparser/CMakeLists.txt index bd9ca00d60..e766ec5484 100644 --- a/tests/auto/gui/text/qcssparser/CMakeLists.txt +++ b/tests/auto/gui/text/qcssparser/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from qcssparser.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qcssparser Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qcssparser LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data file(GLOB_RECURSE test_data RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} @@ -13,7 +20,7 @@ file(GLOB_RECURSE test_data qt_internal_add_test(tst_qcssparser SOURCES tst_qcssparser.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate Qt::Xml diff --git a/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp b/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp index 3b20068f17..203fe003a0 100644 --- a/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp +++ b/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp @@ -1,5 +1,6 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + #include <QTest> #include <QtXml/QtXml> #include <QtGui/QFontInfo> @@ -55,6 +56,10 @@ private slots: void quotedAndUnquotedIdentifiers(); void whitespaceValues_data(); void whitespaceValues(); + void strokeLineCapValues_data(); + void strokeLineCapValues(); + void strokeLineJoinValues_data(); + void strokeLineJoinValues(); }; void tst_QCssParser::scanner_data() @@ -69,7 +74,8 @@ void tst_QCssParser::scanner_data() #endif d.cd("testdata"); d.cd("scanner"); - foreach (QFileInfo test, d.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) { + const auto entries = d.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); + for (const QFileInfo &test : entries) { QString dir = test.absoluteFilePath() + QDir::separator(); QTest::newRow(qPrintable(test.baseName())) << dir + "input" @@ -126,7 +132,7 @@ static const char *tokenName(QCss::TokenType t) static void debug(const QList<QCss::Symbol> &symbols, int index = -1) { qDebug() << "all symbols:"; - for (int i = 0; i < symbols.count(); ++i) + for (int i = 0; i < symbols.size(); ++i) qDebug() << '(' << i << "); Token:" << tokenName(symbols.at(i).token) << "; Lexem:" << symbols.at(i).lexem(); if (index != -1) qDebug() << "failure at index" << index; @@ -144,10 +150,10 @@ void tst_QCssParser::scanner() QList<QCss::Symbol> symbols; QCss::Scanner::scan(QCss::Scanner::preprocess(QString::fromUtf8(inputFile.readAll())), &symbols); - QVERIFY(symbols.count() > 1); + QVERIFY(symbols.size() > 1); QCOMPARE(symbols.last().token, QCss::S); QCOMPARE(symbols.last().lexem(), QLatin1String("\n")); - symbols.remove(symbols.count() - 1, 1); + symbols.remove(symbols.size() - 1, 1); QFile outputFile(output); QVERIFY(outputFile.open(QIODevice::ReadOnly|QIODevice::Text)); @@ -159,14 +165,14 @@ void tst_QCssParser::scanner() lines.append(line); } - if (lines.count() != symbols.count()) { + if (lines.size() != symbols.size()) { debug(symbols); - QCOMPARE(lines.count(), symbols.count()); + QCOMPARE(lines.size(), symbols.size()); } - for (int i = 0; i < lines.count(); ++i) { + for (int i = 0; i < lines.size(); ++i) { QStringList l = lines.at(i).split(QChar::fromLatin1('|')); - QCOMPARE(l.count(), 2); + QCOMPARE(l.size(), 2); const QString expectedToken = l.at(0); const QString expectedLexem = l.at(1); QString actualToken = QString::fromLatin1(tokenName(symbols.at(i).token)); @@ -350,9 +356,9 @@ void tst_QCssParser::expr() QVERIFY(parser.testExpr()); QCOMPARE(parser.parseExpr(&values), parseSuccess); if (parseSuccess) { - QCOMPARE(values.count(), expectedValues.count()); + QCOMPARE(values.size(), expectedValues.size()); - for (int i = 0; i < values.count(); ++i) { + for (int i = 0; i < values.size(); ++i) { QCOMPARE(int(values.at(i).type), int(expectedValues.at(i).type)); QCOMPARE(values.at(i).variant, expectedValues.at(i).variant); } @@ -371,7 +377,7 @@ void tst_QCssParser::import() QVERIFY(parser.testImport()); QVERIFY(parser.parseImport(&rule)); QCOMPARE(rule.href, QString("www.kde.org")); - QCOMPARE(rule.media.count(), 2); + QCOMPARE(rule.media.size(), 2); QCOMPARE(rule.media.at(0), QString("print")); QCOMPARE(rule.media.at(1), QString("screen")); } @@ -382,7 +388,7 @@ void tst_QCssParser::media() QVERIFY(parser.testMedia()); QCss::MediaRule rule; QVERIFY(parser.parseMedia(&rule)); - QCOMPARE(rule.media.count(), 2); + QCOMPARE(rule.media.size(), 2); QCOMPARE(rule.media.at(0), QString("print")); QCOMPARE(rule.media.at(1), QString("screen")); QVERIFY(rule.styleRules.isEmpty()); @@ -405,8 +411,8 @@ void tst_QCssParser::ruleset() QVERIFY(parser.testRuleset()); QCss::StyleRule rule; QVERIFY(parser.parseRuleset(&rule)); - QCOMPARE(rule.selectors.count(), 1); - QCOMPARE(rule.selectors.at(0).basicSelectors.count(), 1); + QCOMPARE(rule.selectors.size(), 1); + QCOMPARE(rule.selectors.at(0).basicSelectors.size(), 1); QCOMPARE(rule.selectors.at(0).basicSelectors.at(0).elementName, QString("p")); QVERIFY(rule.declarations.isEmpty()); } @@ -416,10 +422,10 @@ void tst_QCssParser::ruleset() QVERIFY(parser.testRuleset()); QCss::StyleRule rule; QVERIFY(parser.parseRuleset(&rule)); - QCOMPARE(rule.selectors.count(), 2); - QCOMPARE(rule.selectors.at(0).basicSelectors.count(), 1); + QCOMPARE(rule.selectors.size(), 2); + QCOMPARE(rule.selectors.at(0).basicSelectors.size(), 1); QCOMPARE(rule.selectors.at(0).basicSelectors.at(0).elementName, QString("p")); - QCOMPARE(rule.selectors.at(1).basicSelectors.count(), 1); + QCOMPARE(rule.selectors.at(1).basicSelectors.size(), 1); QCOMPARE(rule.selectors.at(1).basicSelectors.at(0).elementName, QString("div")); QVERIFY(rule.declarations.isEmpty()); } @@ -429,14 +435,14 @@ void tst_QCssParser::ruleset() QVERIFY(parser.testRuleset()); QCss::StyleRule rule; QVERIFY(parser.parseRuleset(&rule)); - QCOMPARE(rule.selectors.count(), 2); + QCOMPARE(rule.selectors.size(), 2); - QCOMPARE(rule.selectors.at(0).basicSelectors.count(), 1); - QCOMPARE(rule.selectors.at(0).basicSelectors.at(0).pseudos.count(), 1); + QCOMPARE(rule.selectors.at(0).basicSelectors.size(), 1); + QCOMPARE(rule.selectors.at(0).basicSelectors.at(0).pseudos.size(), 1); QCOMPARE(rule.selectors.at(0).basicSelectors.at(0).pseudos.at(0).name, QString("before")); - QCOMPARE(rule.selectors.at(1).basicSelectors.count(), 1); - QCOMPARE(rule.selectors.at(1).basicSelectors.at(0).pseudos.count(), 1); + QCOMPARE(rule.selectors.at(1).basicSelectors.size(), 1); + QCOMPARE(rule.selectors.at(1).basicSelectors.at(0).pseudos.size(), 1); QCOMPARE(rule.selectors.at(1).basicSelectors.at(0).pseudos.at(0).name, QString("after")); QVERIFY(rule.declarations.isEmpty()); @@ -688,21 +694,21 @@ void tst_QCssParser::selector() QCss::Selector selector; QVERIFY(parser.parseSelector(&selector)); - QCOMPARE(selector.basicSelectors.count(), expectedSelector.basicSelectors.count()); - for (int i = 0; i < selector.basicSelectors.count(); ++i) { + QCOMPARE(selector.basicSelectors.size(), expectedSelector.basicSelectors.size()); + for (int i = 0; i < selector.basicSelectors.size(); ++i) { const QCss::BasicSelector sel = selector.basicSelectors.at(i); const QCss::BasicSelector expectedSel = expectedSelector.basicSelectors.at(i); QCOMPARE(sel.elementName, expectedSel.elementName); QCOMPARE(int(sel.relationToNext), int(expectedSel.relationToNext)); - QCOMPARE(sel.pseudos.count(), expectedSel.pseudos.count()); - for (int i = 0; i < sel.pseudos.count(); ++i) { + QCOMPARE(sel.pseudos.size(), expectedSel.pseudos.size()); + for (int i = 0; i < sel.pseudos.size(); ++i) { QCOMPARE(sel.pseudos.at(i).name, expectedSel.pseudos.at(i).name); QCOMPARE(sel.pseudos.at(i).function, expectedSel.pseudos.at(i).function); } - QCOMPARE(sel.attributeSelectors.count(), expectedSel.attributeSelectors.count()); - for (int i = 0; i < sel.attributeSelectors.count(); ++i) { + QCOMPARE(sel.attributeSelectors.size(), expectedSel.attributeSelectors.size()); + for (int i = 0; i < sel.attributeSelectors.size(); ++i) { QCOMPARE(sel.attributeSelectors.at(i).name, expectedSel.attributeSelectors.at(i).name); QCOMPARE(sel.attributeSelectors.at(i).value, expectedSel.attributeSelectors.at(i).value); QCOMPARE(int(sel.attributeSelectors.at(i).valueMatchCriterium), int(expectedSel.attributeSelectors.at(i).valueMatchCriterium)); @@ -760,13 +766,13 @@ void tst_QCssParser::malformedDeclarations() QCss::StyleRule rule; QVERIFY(parser.parseRuleset(&rule)); - QCOMPARE(rule.selectors.count(), 1); - QCOMPARE(rule.selectors.at(0).basicSelectors.count(), 1); + QCOMPARE(rule.selectors.size(), 1); + QCOMPARE(rule.selectors.at(0).basicSelectors.size(), 1); QCOMPARE(rule.selectors.at(0).basicSelectors.at(0).elementName, QString("p")); - QVERIFY(rule.declarations.count() >= 1); + QVERIFY(rule.declarations.size() >= 1); QCOMPARE(int(rule.declarations.last().d->propertyId), int(QCss::Color)); - QCOMPARE(rule.declarations.last().d->values.count(), 1); + QCOMPARE(rule.declarations.last().d->values.size(), 1); QCOMPARE(int(rule.declarations.last().d->values.at(0).type), int(QCss::Value::Identifier)); QCOMPARE(rule.declarations.last().d->values.at(0).variant.toString(), QString("green")); } @@ -786,17 +792,17 @@ void tst_QCssParser::invalidAtKeywords() QCss::StyleSheet sheet; QVERIFY(parser.parse(&sheet)); - QCOMPARE(sheet.styleRules.count() + sheet.nameIndex.count(), 1); + QCOMPARE(sheet.styleRules.size() + sheet.nameIndex.size(), 1); QCss::StyleRule rule = (!sheet.styleRules.isEmpty()) ? sheet.styleRules.at(0) : *sheet.nameIndex.begin(); - QCOMPARE(rule.selectors.count(), 1); - QCOMPARE(rule.selectors.at(0).basicSelectors.count(), 1); + QCOMPARE(rule.selectors.size(), 1); + QCOMPARE(rule.selectors.at(0).basicSelectors.size(), 1); QCOMPARE(rule.selectors.at(0).basicSelectors.at(0).elementName, QString("h1")); - QCOMPARE(rule.declarations.count(), 1); + QCOMPARE(rule.declarations.size(), 1); QCOMPARE(int(rule.declarations.at(0).d->propertyId), int(QCss::Color)); - QCOMPARE(rule.declarations.at(0).d->values.count(), 1); + QCOMPARE(rule.declarations.at(0).d->values.size(), 1); QCOMPARE(int(rule.declarations.at(0).d->values.at(0).type), int(QCss::Value::Identifier)); QCOMPARE(rule.declarations.at(0).d->values.at(0).variant.toString(), QString("blue")); } @@ -1141,9 +1147,9 @@ void tst_QCssParser::styleSelector() QList<QCss::Declaration> decls = testSelector.declarationsForNode(n); if (match) { - QCOMPARE(decls.count(), 1); + QCOMPARE(decls.size(), 1); QCOMPARE(int(decls.at(0).d->propertyId), int(QCss::BackgroundColor)); - QCOMPARE(decls.at(0).d->values.count(), 1); + QCOMPARE(decls.at(0).d->values.size(), 1); QCOMPARE(int(decls.at(0).d->values.at(0).type), int(QCss::Value::Identifier)); QCOMPARE(decls.at(0).d->values.at(0).variant.toString(), QString("green")); } else { @@ -1183,11 +1189,11 @@ void tst_QCssParser::specificity() QCss::StyleSheet sheet; QVERIFY(parser.parse(&sheet)); - QCOMPARE(sheet.styleRules.count() + sheet.nameIndex.count() + sheet.idIndex.count() , 1); + QCOMPARE(sheet.styleRules.size() + sheet.nameIndex.size() + sheet.idIndex.size() , 1); QCss::StyleRule rule = (!sheet.styleRules.isEmpty()) ? sheet.styleRules.at(0) : (!sheet.nameIndex.isEmpty()) ? *sheet.nameIndex.begin() : *sheet.idIndex.begin(); - QCOMPARE(rule.selectors.count(), 1); + QCOMPARE(rule.selectors.size(), 1); QTEST(rule.selectors.at(0).specificity(), "specificity"); } @@ -1236,15 +1242,15 @@ void tst_QCssParser::specificitySort() n.ptr = &e; QList<QCss::Declaration> decls = testSelector.declarationsForNode(n); - QCOMPARE(decls.count(), 2); + QCOMPARE(decls.size(), 2); QCOMPARE(int(decls.at(0).d->propertyId), int(QCss::Color)); - QCOMPARE(decls.at(0).d->values.count(), 1); + QCOMPARE(decls.at(0).d->values.size(), 1); QCOMPARE(int(decls.at(0).d->values.at(0).type), int(QCss::Value::Identifier)); QCOMPARE(decls.at(0).d->values.at(0).variant.toString(), QString("green")); QCOMPARE(int(decls.at(1).d->propertyId), int(QCss::Color)); - QCOMPARE(decls.at(1).d->values.count(), 1); + QCOMPARE(decls.at(1).d->values.size(), 1); QCOMPARE(int(decls.at(1).d->values.at(0).type), int(QCss::Value::Identifier)); QCOMPARE(decls.at(1).d->values.at(0).variant.toString(), QString("red")); } @@ -1319,7 +1325,7 @@ void tst_QCssParser::rulesForNode() QList<QCss::StyleRule> rules = testSelector.styleRulesForNode(n); QList<QCss::Declaration> decls; - for (int i = 0; i < rules.count(); i++) { + for (int i = 0; i < rules.size(); i++) { const QCss::Selector &selector = rules.at(i).selectors.at(0); quint64 negated = 0; quint64 cssClass = selector.pseudoClass(&negated); @@ -1328,7 +1334,7 @@ void tst_QCssParser::rulesForNode() decls += rules.at(i).declarations; } - QCOMPARE(decls.count(), declCount); + QCOMPARE(decls.size(), declCount); if (declCount > 0) QCOMPARE(decls.at(0).d->values.at(0).variant.toString(), value0); @@ -1455,14 +1461,14 @@ void tst_QCssParser::pseudoElement() n.ptr = &e; QList<QCss::StyleRule> rules = testSelector.styleRulesForNode(n); QList<QCss::Declaration> decls; - for (int i = 0; i < rules.count(); i++) { + for (int i = 0; i < rules.size(); i++) { const QCss::Selector& selector = rules.at(i).selectors.at(0); if (pseudoElement.compare(selector.pseudoElement(), Qt::CaseInsensitive) != 0) continue; decls += rules.at(i).declarations; } - QCOMPARE(decls.count(), declCount); + QCOMPARE(decls.size(), declCount); } void tst_QCssParser::gradient_data() @@ -1543,20 +1549,26 @@ void tst_QCssParser::gradient() QList<QCss::StyleRule> rules = testSelector.styleRulesForNode(n); QList<QCss::Declaration> decls = rules.at(0).declarations; QCss::ValueExtractor ve(decls); - QBrush fg, sfg; - QBrush sbg, abg; - QVERIFY(ve.extractPalette(&fg, &sfg, &sbg, &abg)); + QBrush foreground; + QBrush selectedForeground; + QBrush selectedBackground; + QBrush alternateBackground; + QBrush placeHolderTextForeground; + QBrush accent; + QVERIFY(ve.extractPalette(&foreground, &selectedForeground, &selectedBackground, + &alternateBackground, &placeHolderTextForeground, &accent)); + if (type == "linear") { - QCOMPARE(sbg.style(), Qt::LinearGradientPattern); - const QLinearGradient *lg = static_cast<const QLinearGradient *>(sbg.gradient()); + QCOMPARE(selectedBackground.style(), Qt::LinearGradientPattern); + const auto *lg = static_cast<const QLinearGradient *>(selectedBackground.gradient()); QCOMPARE(lg->start(), start); QCOMPARE(lg->finalStop(), finalStop); } else if (type == "conical") { - QCOMPARE(sbg.style(), Qt::ConicalGradientPattern); - const QConicalGradient *cg = static_cast<const QConicalGradient *>(sbg.gradient()); + QCOMPARE(selectedBackground.style(), Qt::ConicalGradientPattern); + const auto *cg = static_cast<const QConicalGradient *>(selectedBackground.gradient()); QCOMPARE(cg->center(), start); } - const QGradient *g = sbg.gradient(); + const QGradient *g = selectedBackground.gradient(); QCOMPARE(g->spread(), QGradient::Spread(spread)); QCOMPARE(g->stops().at(0).first, stop0); QCOMPARE(g->stops().at(0).second, color0); @@ -1596,7 +1608,7 @@ void tst_QCssParser::extractFontFamily() QCss::StyleSheet sheet; QVERIFY(parser.parse(&sheet)); - QCOMPARE(sheet.styleRules.count() + sheet.nameIndex.count(), 1); + QCOMPARE(sheet.styleRules.size() + sheet.nameIndex.size(), 1); QCss::StyleRule rule = (!sheet.styleRules.isEmpty()) ? sheet.styleRules.at(0) : *sheet.nameIndex.begin(); @@ -1654,7 +1666,7 @@ void tst_QCssParser::extractBorder() QCss::StyleSheet sheet; QVERIFY(parser.parse(&sheet)); - QCOMPARE(sheet.styleRules.count() + sheet.nameIndex.count(), 1); + QCOMPARE(sheet.styleRules.size() + sheet.nameIndex.size(), 1); QCss::StyleRule rule = (!sheet.styleRules.isEmpty()) ? sheet.styleRules.at(0) : *sheet.nameIndex.begin(); const QList<QCss::Declaration> decls = rule.declarations; @@ -1684,7 +1696,7 @@ void tst_QCssParser::noTextDecoration() QCss::StyleSheet sheet; QVERIFY(parser.parse(&sheet)); - QCOMPARE(sheet.styleRules.count() + sheet.nameIndex.count(), 1); + QCOMPARE(sheet.styleRules.size() + sheet.nameIndex.size(), 1); QCss::StyleRule rule = (!sheet.styleRules.isEmpty()) ? sheet.styleRules.at(0) : *sheet.nameIndex.begin(); const QList<QCss::Declaration> decls = rule.declarations; @@ -1709,7 +1721,7 @@ void tst_QCssParser::quotedAndUnquotedIdentifiers() QCss::StyleSheet sheet; QVERIFY(parser.parse(&sheet)); - QCOMPARE(sheet.styleRules.count() + sheet.nameIndex.count(), 1); + QCOMPARE(sheet.styleRules.size() + sheet.nameIndex.size(), 1); QCss::StyleRule rule = (!sheet.styleRules.isEmpty()) ? sheet.styleRules.at(0) : *sheet.nameIndex.begin(); const QList<QCss::Declaration> decls = rule.declarations; @@ -1751,6 +1763,57 @@ void tst_QCssParser::whitespaceValues() QCOMPARE(rule.declarations.at(0).d->values.first().toString(), value); } +void tst_QCssParser::strokeLineCapValues_data() +{ + QTest::addColumn<QString>("value"); + + QTest::newRow("flatcap") << "flatcap"; + QTest::newRow("roundcap") << "roundcap"; + QTest::newRow("squarecap") << "squarecap"; +} + +void tst_QCssParser::strokeLineCapValues() +{ + QFETCH(QString, value); + QCss::Parser parser(QString("foo { -qt-stroke-linecap: %1 }").arg(value)); + QCss::StyleSheet sheet; + QVERIFY(parser.parse(&sheet)); + + QCss::StyleRule rule = (!sheet.styleRules.isEmpty()) ? + sheet.styleRules.at(0) : *sheet.nameIndex.begin(); + QCOMPARE(rule.declarations.size(), 1); + + QCOMPARE(rule.declarations.at(0).d->property, QLatin1String("-qt-stroke-linecap")); + QCOMPARE(rule.declarations.at(0).d->values.first().type, QCss::Value::KnownIdentifier); + QCOMPARE(rule.declarations.at(0).d->values.first().toString(), value); +} + +void tst_QCssParser::strokeLineJoinValues_data() +{ + QTest::addColumn<QString>("value"); + + QTest::newRow("beveljoin") << "beveljoin"; + QTest::newRow("miterjoin") << "miterjoin"; + QTest::newRow("roundjoin") << "roundjoin"; + QTest::newRow("svgmiterjoin") << "svgmiterjoin"; +} + +void tst_QCssParser::strokeLineJoinValues() +{ + QFETCH(QString, value); + QCss::Parser parser(QString("foo { -qt-stroke-linejoin: %1 }").arg(value)); + QCss::StyleSheet sheet; + QVERIFY(parser.parse(&sheet)); + + QCss::StyleRule rule = (!sheet.styleRules.isEmpty()) ? + sheet.styleRules.at(0) : *sheet.nameIndex.begin(); + QCOMPARE(rule.declarations.size(), 1); + + QCOMPARE(rule.declarations.at(0).d->property, QLatin1String("-qt-stroke-linejoin")); + QCOMPARE(rule.declarations.at(0).d->values.first().type, QCss::Value::KnownIdentifier); + QCOMPARE(rule.declarations.at(0).d->values.first().toString(), value); +} + QTEST_MAIN(tst_QCssParser) #include "tst_qcssparser.moc" diff --git a/tests/auto/gui/text/qfont/BLACKLIST b/tests/auto/gui/text/qfont/BLACKLIST index 3629f1fee6..f85d8ceebb 100644 --- a/tests/auto/gui/text/qfont/BLACKLIST +++ b/tests/auto/gui/text/qfont/BLACKLIST @@ -1,10 +1,8 @@ [defaultFamily:cursive] -ubuntu-20.04 centos b2qt rhel [defaultFamily:fantasy] -ubuntu-20.04 centos b2qt rhel diff --git a/tests/auto/gui/text/qfont/CMakeLists.txt b/tests/auto/gui/text/qfont/CMakeLists.txt index 048416495b..88ae9959e4 100644 --- a/tests/auto/gui/text/qfont/CMakeLists.txt +++ b/tests/auto/gui/text/qfont/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from qfont.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qfont Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qfont LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Resources: set(testfont_resource_files "datastream.515" @@ -13,7 +20,7 @@ set(testfont_resource_files qt_internal_add_test(tst_qfont SOURCES tst_qfont.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate @@ -26,6 +33,6 @@ qt_internal_add_test(tst_qfont ##################################################################### qt_internal_extend_target(tst_qfont CONDITION TARGET Qt::Widgets - PUBLIC_LIBRARIES + LIBRARIES Qt::Widgets ) diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp index a663468d0f..5426d7b117 100644 --- a/tests/auto/gui/text/qfont/tst_qfont.cpp +++ b/tests/auto/gui/text/qfont/tst_qfont.cpp @@ -1,5 +1,7 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses #include <QTest> #include <QBuffer> @@ -19,6 +21,9 @@ #endif #include <qlist.h> #include <QtTest/private/qemulationdetector_p.h> +#include <private/qcomparisontesthelper_p.h> + +using namespace Qt::StringLiterals; class tst_QFont : public QObject { @@ -54,6 +59,9 @@ private slots: void setFamilies(); void setFamiliesAndFamily_data(); void setFamiliesAndFamily(); + void featureAccessors(); + void tagCompares_data(); + void tagCompares(); }; // Testing get/set functions @@ -150,7 +158,7 @@ void tst_QFont::italicOblique() continue; } QFont f = QFontDatabase::font(family, style, 12); - QVERIFY(f.italic()); + QVERIFY2(f.italic(), qPrintable(QString::asprintf("Failed for font \"%ls\"", qUtf16Printable(f.family())))); } } } @@ -357,15 +365,15 @@ void tst_QFont::insertAndRemoveSubstitutions() // inserting Foo QFont::insertSubstitution("BogusFontFamily", "Foo"); - QCOMPARE(QFont::substitutes("BogusFontFamily").count(), 1); - QCOMPARE(QFont::substitutes("bogusfontfamily").count(), 1); + QCOMPARE(QFont::substitutes("BogusFontFamily").size(), 1); + QCOMPARE(QFont::substitutes("bogusfontfamily").size(), 1); // inserting Bar and Baz QStringList moreFonts; moreFonts << "Bar" << "Baz"; QFont::insertSubstitutions("BogusFontFamily", moreFonts); - QCOMPARE(QFont::substitutes("BogusFontFamily").count(), 3); - QCOMPARE(QFont::substitutes("bogusfontfamily").count(), 3); + QCOMPARE(QFont::substitutes("BogusFontFamily").size(), 3); + QCOMPARE(QFont::substitutes("bogusfontfamily").size(), 3); QFont::removeSubstitutions("BogusFontFamily"); // make sure it is empty again @@ -392,7 +400,7 @@ void tst_QFont::serialize_data() QTest::newRow("defaultConstructed") << font << QDataStream::Qt_1_0; font.setLetterSpacing(QFont::AbsoluteSpacing, 105); - QTest::newRow("letterSpacing") << font << QDataStream::Qt_4_5; + QTest::newRow("letterSpacing=105") << font << QDataStream::Qt_4_5; font = basicFont; font.setWordSpacing(50.0); @@ -436,7 +444,7 @@ void tst_QFont::serialize_data() font = basicFont; font.setLetterSpacing(QFont::AbsoluteSpacing, 10); // Fails for 4.4 because letterSpacing wasn't read until 4.5. - QTest::newRow("letterSpacing") << font << QDataStream::Qt_4_5; + QTest::newRow("letterSpacing=10") << font << QDataStream::Qt_4_5; font = basicFont; font.setKerning(false); @@ -589,6 +597,11 @@ void tst_QFont::defaultFamily() break; } } + +#if defined(Q_OS_UNIX) && defined(QT_NO_FONTCONFIG) + QSKIP("This platform does not support checking for default font acceptability"); +#endif + #ifdef Q_PROCESSOR_ARM_32 if (QTestPrivate::isRunningArmOnX86()) QEXPECT_FAIL("", "Fails on ARMv7 QEMU (QTQAINFRA-4127)", Continue); @@ -836,5 +849,83 @@ void tst_QFont::setFamiliesAndFamily() QFontDatabase::removeApplicationFont(weirdFontId); } +void tst_QFont::featureAccessors() +{ + const QFont::Tag abcdTag("abcd"); + QCOMPARE(abcdTag.toString(), "abcd"); + QVERIFY(abcdTag.isValid()); + + QFont font; + QVERIFY(font.featureTags().isEmpty()); + font.setFeature("abcd", 0xc0ffee); + + QVERIFY(font.isFeatureSet(abcdTag)); + QVERIFY(!font.isFeatureSet("bcde")); + QCOMPARE(font.featureTags().size(), 1); + QCOMPARE(font.featureTags().first(), abcdTag); + QCOMPARE(font.featureTags().first(), "abcd"); + QCOMPARE(font.featureValue(abcdTag), 0xc0ffeeU); + QCOMPARE(font.featureValue("bcde"), 0U); + font.setFeature(abcdTag, 0xf00d); + QCOMPARE(font.featureTags().size(), 1); + QCOMPARE(font.featureValue(abcdTag), 0xf00dU); + + QFont::Tag invalidTag; + QVERIFY(!invalidTag.isValid()); + font.setFeature(invalidTag, 0xcaca0); + QVERIFY(!font.isFeatureSet(invalidTag)); + QCOMPARE(font.featureTags().size(), 1); + QFont font2 = font; + + font.unsetFeature("abcd"); + QVERIFY(!font.isFeatureSet("abcd")); + QVERIFY(font.featureTags().isEmpty()); + + QVERIFY(font2.isFeatureSet("abcd")); + font2.clearFeatures(); + QVERIFY(font.featureTags().isEmpty()); + + // various constructor compile tests + QFont::Tag tag; + tag = QFont::Tag("1234"); + QVERIFY(QFont::Tag::fromString(QByteArray("abcd"))); + QVERIFY(QFont::Tag::fromString(u"frac"_s)); + + // named constructors with invalid input + QTest::ignoreMessage(QtWarningMsg, "The tag name must be exactly 4 characters long!"); + QVERIFY(!QFont::Tag::fromString(u"fraction"_s)); + QVERIFY(!QFont::Tag::fromValue(0)); + QVERIFY(QFont::Tag::fromValue(abcdTag.value())); + + enum Features { + Frac = QFont::Tag("frac").value() + }; +} + +void tst_QFont::tagCompares_data() +{ + QTestPrivate::testAllComparisonOperatorsCompile<QFont::Tag>(); + + QTest::addColumn<QFont::Tag>("lhs"); + QTest::addColumn<QFont::Tag>("rhs"); + QTest::addColumn<Qt::strong_ordering>("expectedOrder"); + + auto row = [](QFont::Tag left, QFont::Tag right) { + QTest::addRow("%s<=>%s", left.toString().constData(), right.toString().constData()) + << left << right << Qt::compareThreeWay(left.value(), right.value()); + }; + row("frac", "wght"); +} + +void tst_QFont::tagCompares() +{ + QFETCH(QFont::Tag, lhs); + QFETCH(QFont::Tag, rhs); + QFETCH(Qt::strong_ordering, expectedOrder); + + QVERIFY(comparesEqual(lhs, lhs)); + QCOMPARE(compareThreeWay(lhs, rhs), expectedOrder); +} + QTEST_MAIN(tst_QFont) #include "tst_qfont.moc" diff --git a/tests/auto/gui/text/qfontcache/CMakeLists.txt b/tests/auto/gui/text/qfontcache/CMakeLists.txt index fb93c91e0c..d9645c115a 100644 --- a/tests/auto/gui/text/qfontcache/CMakeLists.txt +++ b/tests/auto/gui/text/qfontcache/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qfontcache.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qfontcache Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qfontcache LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qfontcache SOURCES tst_qfontcache.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp b/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp index 7d30baf876..79f24a2f0d 100644 --- a/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp +++ b/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/gui/text/qfontdatabase/CMakeLists.txt b/tests/auto/gui/text/qfontdatabase/CMakeLists.txt index 73ab56d49f..0cb6e8d7c8 100644 --- a/tests/auto/gui/text/qfontdatabase/CMakeLists.txt +++ b/tests/auto/gui/text/qfontdatabase/CMakeLists.txt @@ -1,16 +1,23 @@ -# Generated from qfontdatabase.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qfontdatabase Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qfontdatabase LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data list(APPEND test_data "LED_REAL.TTF") qt_internal_add_test(tst_qfontdatabase SOURCES tst_qfontdatabase.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate @@ -30,12 +37,18 @@ set_source_files_properties("../../../shared/resources/testfont_italic.ttf" set_source_files_properties("../../../shared/resources/testfont_open.otf" PROPERTIES QT_RESOURCE_ALIAS "testfont_open.otf" ) +set_source_files_properties("../../../shared/resources/testfont_variable.ttf" + PROPERTIES QT_RESOURCE_ALIAS "testfont_variable.ttf" +) set(testdata_resource_files "../../../shared/resources/testfont.ttf" "../../../shared/resources/testfont_condensed.ttf" "../../../shared/resources/testfont_italic.ttf" "../../../shared/resources/testfont_open.otf" + "../../../shared/resources/testfont_variable.ttf" "LED_REAL.TTF" + "QtTestLimitedFont-Regular.ttf" + "QtTestFallbackFont-Regular.ttf" ) qt_internal_add_resource(tst_qfontdatabase "testdata" diff --git a/tests/auto/gui/text/qfontdatabase/QtTestFallbackFont-Regular.ttf b/tests/auto/gui/text/qfontdatabase/QtTestFallbackFont-Regular.ttf Binary files differnew file mode 100644 index 0000000000..ae21fec9a5 --- /dev/null +++ b/tests/auto/gui/text/qfontdatabase/QtTestFallbackFont-Regular.ttf diff --git a/tests/auto/gui/text/qfontdatabase/QtTestLimitedFont-Regular.ttf b/tests/auto/gui/text/qfontdatabase/QtTestLimitedFont-Regular.ttf Binary files differnew file mode 100644 index 0000000000..2891f8aeff --- /dev/null +++ b/tests/auto/gui/text/qfontdatabase/QtTestLimitedFont-Regular.ttf diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp index 9c56d9b2d2..8733f64d97 100644 --- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp +++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QSignalSpy> @@ -12,6 +12,9 @@ #include <private/qfont_p.h> #include <private/qfontengine_p.h> #include <qpa/qplatformfontdatabase.h> +#include <qpa/qplatformintegration.h> + +#include <QtGui/private/qguiapplication_p.h> using namespace Qt::StringLiterals; @@ -61,15 +64,22 @@ private slots: void stretchRespected(); + void variableFont(); + #ifdef Q_OS_WIN void findCourier(); #endif + void addApplicationFontFallback(); + private: QString m_ledFont; QString m_testFont; QString m_testFontCondensed; QString m_testFontItalic; + QString m_testFontVariable; + QString m_limitedFont; + QString m_fallbackFont; }; tst_QFontDatabase::tst_QFontDatabase() @@ -82,10 +92,16 @@ void tst_QFontDatabase::initTestCase() m_testFont = QFINDTESTDATA("testfont.ttf"); m_testFontCondensed = QFINDTESTDATA("testfont_condensed.ttf"); m_testFontItalic = QFINDTESTDATA("testfont_italic.ttf"); + m_testFontVariable = QFINDTESTDATA("testfont_variable.ttf"); + m_limitedFont = QFINDTESTDATA("QtTestLimitedFont-Regular.ttf"); + m_fallbackFont = QFINDTESTDATA("QtTestFallbackFont-Regular.ttf"); QVERIFY(!m_ledFont.isEmpty()); QVERIFY(!m_testFont.isEmpty()); QVERIFY(!m_testFontCondensed.isEmpty()); QVERIFY(!m_testFontItalic.isEmpty()); + QVERIFY(!m_testFontVariable.isEmpty()); + QVERIFY(!m_limitedFont.isEmpty()); + QVERIFY(!m_fallbackFont.isEmpty()); } void tst_QFontDatabase::styles_data() @@ -223,7 +239,7 @@ void tst_QFontDatabase::addAppFont() int id; if (useMemoryFont) { QFile fontfile(m_ledFont); - fontfile.open(QIODevice::ReadOnly); + QVERIFY(fontfile.open(QIODevice::ReadOnly)); QByteArray fontdata = fontfile.readAll(); QVERIFY(!fontdata.isEmpty()); id = QFontDatabase::addApplicationFontFromData(fontdata); @@ -236,7 +252,7 @@ void tst_QFontDatabase::addAppFont() QCOMPARE(id, -1); return; #endif - QCOMPARE(fontDbChangedSpy.count(), 1); + QCOMPARE(fontDbChangedSpy.size(), 1); if (id == -1) QSKIP("Skip the test since app fonts are not supported on this system"); @@ -245,9 +261,9 @@ void tst_QFontDatabase::addAppFont() const QStringList newFamilies = QFontDatabase::families(); QVERIFY(!newFamilies.isEmpty()); - QVERIFY(newFamilies.count() >= oldFamilies.count()); + QVERIFY(newFamilies.size() >= oldFamilies.size()); - for (int i = 0; i < addedFamilies.count(); ++i) { + for (int i = 0; i < addedFamilies.size(); ++i) { QString family = addedFamilies.at(i); QVERIFY(newFamilies.contains(family)); QFont qfont(family); @@ -256,9 +272,9 @@ void tst_QFontDatabase::addAppFont() } QVERIFY(QFontDatabase::removeApplicationFont(id)); - QCOMPARE(fontDbChangedSpy.count(), 2); + QCOMPARE(fontDbChangedSpy.size(), 2); - QVERIFY(QFontDatabase::families().count() <= oldFamilies.count()); + QVERIFY(QFontDatabase::families().size() <= oldFamilies.size()); } void tst_QFontDatabase::addTwoAppFontsFromFamily() @@ -319,8 +335,8 @@ void tst_QFontDatabase::fallbackFonts() layout.createLine(); layout.endLayout(); - QList<QGlyphRun> runs = layout.glyphRuns(0, 1); - foreach (QGlyphRun run, runs) { + const QList<QGlyphRun> runs = layout.glyphRuns(0, 1); + for (QGlyphRun run : runs) { QRawFont rawFont = run.rawFont(); QVERIFY(rawFont.isValid()); @@ -381,8 +397,14 @@ void tst_QFontDatabase::condensedFontWidthNoFontMerging() void tst_QFontDatabase::condensedFontWidth() { - QFontDatabase::addApplicationFont(m_testFont); - QFontDatabase::addApplicationFont(m_testFontCondensed); + int testFontId = QFontDatabase::addApplicationFont(m_testFont); + int testFontCondensedId = QFontDatabase::addApplicationFont(m_testFontCondensed); + auto cleanup = qScopeGuard([&testFontId, &testFontCondensedId] { + if (testFontId >= 0) + QFontDatabase::removeApplicationFont(testFontId); + if (testFontCondensedId >= 0) + QFontDatabase::removeApplicationFont(testFontCondensedId); + }); QVERIFY(QFontDatabase::hasFamily("QtBidiTestFont")); if (!QFontDatabase::hasFamily("QtBidiTestFontCondensed")) @@ -400,10 +422,16 @@ void tst_QFontDatabase::condensedFontWidth() void tst_QFontDatabase::condensedFontMatching() { QFontDatabase::removeAllApplicationFonts(); - QFontDatabase::addApplicationFont(m_testFontCondensed); + int testFontCondensedId = QFontDatabase::addApplicationFont(m_testFontCondensed); if (!QFontDatabase::hasFamily("QtBidiTestFont")) QSKIP("This platform doesn't support preferred font family names (QTBUG-53478)"); - QFontDatabase::addApplicationFont(m_testFont); + int testFontId = QFontDatabase::addApplicationFont(m_testFont); + auto cleanup = qScopeGuard([&testFontId, &testFontCondensedId] { + if (testFontId >= 0) + QFontDatabase::removeApplicationFont(testFontId); + if (testFontCondensedId >= 0) + QFontDatabase::removeApplicationFont(testFontCondensedId); + }); // Test we correctly get the condensed font using different font matching methods: QFont tfcByStretch("QtBidiTestFont"); @@ -415,8 +443,10 @@ void tst_QFontDatabase::condensedFontMatching() QFont f; f.setStyleStrategy(QFont::NoFontMerging); QFontPrivate *font_d = QFontPrivate::get(f); - if (font_d->engineForScript(QChar::Script_Common)->type() != QFontEngine::Freetype) + if (font_d->engineForScript(QChar::Script_Common)->type() != QFontEngine::Freetype + && font_d->engineForScript(QChar::Script_Common)->type() != QFontEngine::DirectWrite) { QEXPECT_FAIL("","No matching of sub-family by stretch on Windows", Continue); + } #endif QCOMPARE(QFontMetrics(tfcByStretch).horizontalAdvance(testString()), @@ -505,5 +535,230 @@ void tst_QFontDatabase::findCourier() } #endif +void tst_QFontDatabase::variableFont() +{ + { + QPlatformFontDatabase *pfdb = QGuiApplicationPrivate::platformIntegration()->fontDatabase(); + if (!pfdb->supportsVariableApplicationFonts()) + QSKIP("Variable application fonts not supported on this platform"); + } + + int id = QFontDatabase::addApplicationFont(m_testFontVariable); + if (id == -1) + QSKIP("Skip the test since app fonts are not supported on this system"); + + QString family = QFontDatabase::applicationFontFamilies(id).first(); + { + QFont font(family); + QCOMPARE(QFontInfo(font).styleName(), u"Regular"_s); + QCOMPARE(QFontInfo(font).weight(), QFont::Normal); + } + + { + QFont font(family); + font.setWeight(QFont::Black); + QCOMPARE(QFontInfo(font).styleName(), u"QtExtraBold"_s); + QCOMPARE(QFontInfo(font).weight(), int(QFont::Black)); + } + + { + QFont regularFont(family); + QFont extraBoldFont(family); + extraBoldFont.setStyleName(u"QtExtraBold"_s); + + QFontMetricsF regularFm(regularFont); + QFontMetricsF extraBoldFm(extraBoldFont); + + QVERIFY(regularFm.horizontalAdvance(QLatin1Char('1')) < extraBoldFm.horizontalAdvance(QLatin1Char('1'))); + } + + QFontDatabase::removeApplicationFont(id); +} + +void tst_QFontDatabase::addApplicationFontFallback() +{ + int ledId = -1; + int id = -1; + int limitedId = -1; + int fallbackId = -1; + auto cleanup = qScopeGuard([&id, &ledId, &limitedId, &fallbackId] { + if (id >= 0) + QFontDatabase::removeApplicationFont(id); + if (ledId >= 0) + QFontDatabase::removeApplicationFont(ledId); + if (limitedId >= 0) + QFontDatabase::removeApplicationFont(limitedId); + if (fallbackId >= 0) + QFontDatabase::removeApplicationFont(fallbackId); + }); + + const QChar hebrewChar(0x05D0); // Hebrew 'aleph' + + ledId = QFontDatabase::addApplicationFont(m_ledFont); + if (ledId < 0) + QSKIP("Skip the test since app fonts are not supported on this system"); + + auto getHebrewFont = [&]() { + QTextLayout layout; + layout.setText(hebrewChar); + layout.setFont(QFont(u"LED Real"_s)); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + QList<QGlyphRun> glyphRuns = layout.glyphRuns(); + if (glyphRuns.isEmpty()) + return QString{}; + + return glyphRuns.first().rawFont().familyName(); + }; + + QString defaultHebrewFont = getHebrewFont(); + if (defaultHebrewFont.isEmpty()) + QSKIP("Skip the test since Hebrew is not supported on this system"); + + QVERIFY(QFontDatabase::applicationFallbackFontFamilies(QChar::Script_Hebrew).isEmpty()); + QFontDatabase::addApplicationFallbackFontFamily(QChar::Script_Hebrew, u"QtBidiTestFont"_s); + + QCOMPARE(QFontDatabase::applicationFallbackFontFamilies(QChar::Script_Hebrew).size(), 1); + QCOMPARE(QFontDatabase::applicationFallbackFontFamilies(QChar::Script_Hebrew).first(), u"QtBidiTestFont"_s); + + { + QString hebrewFontNow = getHebrewFont(); + QCOMPARE(hebrewFontNow, defaultHebrewFont); + } + + id = QFontDatabase::addApplicationFont(m_testFont); + QVERIFY(id >= 0); + + { + QString hebrewFontNow = getHebrewFont(); + QCOMPARE(hebrewFontNow, u"QtBidiTestFont"_s); + } + + QFontDatabase::removeApplicationFallbackFontFamily(QChar::Script_Hebrew, u"QtBidiTestFont"_s); + + { + QString hebrewFontNow = getHebrewFont(); + QCOMPARE(hebrewFontNow, defaultHebrewFont); + } + + QFontDatabase::setApplicationFallbackFontFamilies(QChar::Script_Hebrew, QStringList(u"QtBidiTestFont"_s)); + + { + QString hebrewFontNow = getHebrewFont(); + QCOMPARE(hebrewFontNow, u"QtBidiTestFont"_s); + } + + QFontDatabase::setApplicationFallbackFontFamilies(QChar::Script_Hebrew, QStringList{}); + + { + QString hebrewFontNow = getHebrewFont(); + QCOMPARE(hebrewFontNow, defaultHebrewFont); + } + + limitedId = QFontDatabase::addApplicationFont(m_limitedFont); + QVERIFY(limitedId >= 0); + + fallbackId = QFontDatabase::addApplicationFont(m_fallbackFont); + QVERIFY(fallbackId >= 0); + + QFontDatabase::addApplicationFallbackFontFamily(QChar::Script_Common, u"QtTestFallbackFont"_s); + + // The fallback for Common will be used also for Latin, because Latin and Common are + // considered the same script by the font matching engine. + { + QTextLayout layout; + layout.setText(u"A'B,"_s); + layout.setFont(QFont(u"QtTestLimitedFont"_s)); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + QList<QGlyphRun> glyphRuns = layout.glyphRuns(); + QVERIFY(glyphRuns.size() > 1); + for (int i = 0; i < glyphRuns.size(); ++i) { + QVERIFY(glyphRuns.at(i).rawFont().familyName() == u"QtTestFallbackFont"_s + || glyphRuns.at(i).rawFont().familyName() == u"QtTestLimitedFont"_s); + } + } + + // When the text only consists of common script characters, the fallback font will also be used. + { + QTextLayout layout; + layout.setText(u"',"_s); + layout.setFont(QFont(u"QtTestLimitedFont"_s)); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + QList<QGlyphRun> glyphRuns = layout.glyphRuns(); + QCOMPARE(glyphRuns.size(), 2); + for (int i = 0; i < glyphRuns.size(); ++i) { + QVERIFY(glyphRuns.at(i).rawFont().familyName() == u"QtTestFallbackFont"_s + || glyphRuns.at(i).rawFont().familyName() == u"QtTestLimitedFont"_s); + } + } + + QVERIFY(QFontDatabase::removeApplicationFallbackFontFamily(QChar::Script_Common, u"QtTestFallbackFont"_s)); + QFontDatabase::addApplicationFallbackFontFamily(QChar::Script_Latin, u"QtTestFallbackFont"_s); + + // Latin fallback works just the same as Common fallback + { + QTextLayout layout; + layout.setText(u"A'B,"_s); + layout.setFont(QFont(u"QtTestLimitedFont"_s)); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + QList<QGlyphRun> glyphRuns = layout.glyphRuns(); + QCOMPARE(glyphRuns.size(), 2); + for (int i = 0; i < glyphRuns.size(); ++i) { + QVERIFY(glyphRuns.at(i).rawFont().familyName() == u"QtTestFallbackFont"_s + || glyphRuns.at(i).rawFont().familyName() == u"QtTestLimitedFont"_s); + } + } + + // When the common character is placed next to a Cyrillic characters, it gets adapted to this, + // so the fallback font will not be selected, even if it supports the character in question + { + QTextLayout layout; + layout.setText(u"A'Đ‘,"_s); + layout.setFont(QFont(u"QtTestLimitedFont"_s)); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + QList<QGlyphRun> glyphRuns = layout.glyphRuns(); + QCOMPARE(glyphRuns.size(), 2); + for (int i = 0; i < glyphRuns.size(); ++i) { + QVERIFY(glyphRuns.at(i).rawFont().familyName() != u"QtTestFallbackFont"_s); + } + } + + QFontDatabase::addApplicationFallbackFontFamily(QChar::Script_Cyrillic, u"QtTestFallbackFont"_s); + + // When we set the fallback font for Cyrillic as well, it gets selected + { + QTextLayout layout; + layout.setText(u"A'Đ‘,"_s); + layout.setFont(QFont(u"QtTestLimitedFont"_s)); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + QList<QGlyphRun> glyphRuns = layout.glyphRuns(); + QCOMPARE(glyphRuns.size(), 2); + for (int i = 0; i < glyphRuns.size(); ++i) { + QVERIFY(glyphRuns.at(i).rawFont().familyName() == u"QtTestFallbackFont"_s + || glyphRuns.at(i).rawFont().familyName() == u"QtTestLimitedFont"_s); + } + } + + QVERIFY(QFontDatabase::removeApplicationFallbackFontFamily(QChar::Script_Cyrillic, u"QtTestFallbackFont"_s)); + QVERIFY(QFontDatabase::removeApplicationFallbackFontFamily(QChar::Script_Latin, u"QtTestFallbackFont"_s)); +} + QTEST_MAIN(tst_QFontDatabase) #include "tst_qfontdatabase.moc" diff --git a/tests/auto/gui/text/qfontmetrics/CMakeLists.txt b/tests/auto/gui/text/qfontmetrics/CMakeLists.txt index d7a22671d6..ee2f76ef76 100644 --- a/tests/auto/gui/text/qfontmetrics/CMakeLists.txt +++ b/tests/auto/gui/text/qfontmetrics/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qfontmetrics.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qfontmetrics Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qfontmetrics LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qfontmetrics SOURCES tst_qfontmetrics.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate @@ -17,8 +24,12 @@ qt_internal_add_test(tst_qfontmetrics set_source_files_properties("../../../shared/resources/testfont.ttf" PROPERTIES QT_RESOURCE_ALIAS "testfont.ttf" ) +set_source_files_properties("../../../shared/resources/testfont_linemetrics.otf" + PROPERTIES QT_RESOURCE_ALIAS "testfont_linemetrics.otf" +) set(testfont_resource_files "../../../shared/resources/testfont.ttf" + "../../../shared/resources/testfont_linemetrics.otf" "ucs4font.ttf" ) diff --git a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp index 5516492365..bad33ab0a4 100644 --- a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp +++ b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -34,6 +34,9 @@ private slots: void zeroWidthMetrics(); void verticalMetrics_data(); void verticalMetrics(); + void largeText_data(); + void largeText(); // QTBUG-123339 + void typoLineMetrics(); }; void tst_QFontMetrics::same() @@ -261,7 +264,7 @@ void tst_QFontMetrics::inFontUcs4() glyphs.glyphs[0] = 0; QVERIFY(engine->stringToCMap(string.constData(), string.size(), &glyphs, &glyphs.numGlyphs, - QFontEngine::GlyphIndicesOnly)); + QFontEngine::GlyphIndicesOnly) > 0); QCOMPARE(glyphs.numGlyphs, 1); QCOMPARE(glyphs.glyphs[0], uint(1)); } @@ -273,7 +276,7 @@ void tst_QFontMetrics::inFontUcs4() glyphs.glyphs[0] = 0; QVERIFY(engine->stringToCMap(string.constData(), string.size(), &glyphs, &glyphs.numGlyphs, - QFontEngine::GlyphIndicesOnly)); + QFontEngine::GlyphIndicesOnly) >= 0); QVERIFY(glyphs.glyphs[0] != 1); } } @@ -388,5 +391,68 @@ void tst_QFontMetrics::verticalMetrics() QVERIFY(fm.ascent() != 0 || fm.descent() != 0); } +void tst_QFontMetrics::largeText_data() +{ + QTest::addColumn<qsizetype>("size"); + for (int i = 1; i < 20; ++i) { + qsizetype size = qsizetype(1) << i; + QByteArray rowText = QByteArray::number(size); + QTest::newRow(rowText.constData()) << size; + } +} + +void tst_QFontMetrics::largeText() +{ + QFont font; + QFontMetrics fm(font); + QFETCH(qsizetype, size); + QString string(size, QLatin1Char('A')); + QRect boundingRect = fm.boundingRect(string); + QVERIFY(boundingRect.isValid()); +} + +void tst_QFontMetrics::typoLineMetrics() +{ + QString testFont = QFINDTESTDATA("fonts/testfont_linemetrics.otf"); + QVERIFY(!testFont.isEmpty()); + + int id = QFontDatabase::addApplicationFont(testFont); + QVERIFY(id >= 0); + + { + auto cleanup = qScopeGuard([&id] { + if (id >= 0) + QFontDatabase::removeApplicationFont(id); + }); + + QImage img(100, 100, QImage::Format_ARGB32); + img.setDevicePixelRatio(1.0); + QFont font(QFontDatabase::applicationFontFamilies(id).at(0), &img); + font.setPixelSize(18); + + const qreal unitsPerEm = 1000.0; + + QFontMetrics defaultFm(font); + const int defaultAscent = defaultFm.ascent(); + const int defaultDescent = defaultFm.descent(); + const int defaultLeading = defaultFm.leading(); + + QCOMPARE(defaultAscent, qRound(1234.0 / unitsPerEm * font.pixelSize())); + QCOMPARE(defaultDescent, qRound(5678.0 / unitsPerEm * font.pixelSize())); + QCOMPARE(defaultLeading, 0.0); + + font.setStyleStrategy(QFont::PreferTypoLineMetrics); + const QFontMetrics typoFm(font); + + const int typoAscent = typoFm.ascent(); + const int typoDescent = typoFm.descent(); + const int typoLeading = typoFm.leading(); + + QCOMPARE(typoAscent, qRound(2000.0 / unitsPerEm * font.pixelSize())); + QCOMPARE(typoDescent, qRound(3000.0 / unitsPerEm * font.pixelSize())); + QCOMPARE(typoLeading, qRound(1000.0 / unitsPerEm * font.pixelSize())); + } +} + QTEST_MAIN(tst_QFontMetrics) #include "tst_qfontmetrics.moc" diff --git a/tests/auto/gui/text/qglyphrun/BLACKLIST b/tests/auto/gui/text/qglyphrun/BLACKLIST deleted file mode 100644 index 72b20ca4b1..0000000000 --- a/tests/auto/gui/text/qglyphrun/BLACKLIST +++ /dev/null @@ -1,6 +0,0 @@ -# QTBUG-68860 -[mixedScripts] -ubuntu-18.04 -ubuntu-20.04 -# QTBUG-100928 -qnx diff --git a/tests/auto/gui/text/qglyphrun/CMakeLists.txt b/tests/auto/gui/text/qglyphrun/CMakeLists.txt index 4c5a7c44c0..a9ffd3729d 100644 --- a/tests/auto/gui/text/qglyphrun/CMakeLists.txt +++ b/tests/auto/gui/text/qglyphrun/CMakeLists.txt @@ -1,21 +1,29 @@ -# Generated from qglyphrun.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qglyphrun Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qglyphrun LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Resources: set_source_files_properties("../../../shared/resources/test.ttf" PROPERTIES QT_RESOURCE_ALIAS "test.ttf" ) set(testdata_resource_files "../../../shared/resources/test.ttf" + "Ligatures.otf" ) qt_internal_add_test(tst_qglyphrun SOURCES tst_qglyphrun.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui TESTDATA ${testdata_resource_files} BUILTIN_TESTDATA diff --git a/tests/auto/gui/text/qglyphrun/Ligatures.otf b/tests/auto/gui/text/qglyphrun/Ligatures.otf Binary files differnew file mode 100644 index 0000000000..194218a0f6 --- /dev/null +++ b/tests/auto/gui/text/qglyphrun/Ligatures.otf diff --git a/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp b/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp index 1569a4bf84..8c0c0324c9 100644 --- a/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp +++ b/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -39,6 +39,10 @@ private slots: void mixedScripts(); void multiLineBoundingRect(); void defaultIgnorables(); + void stringIndexes(); + void retrievalFlags_data(); + void retrievalFlags(); + void objectReplacementCharacter(); private: int m_testFontId; @@ -404,7 +408,7 @@ void tst_QGlyphRun::drawMultiScriptText1() QPixmap drawGlyphs(1000, 1000); drawGlyphs.fill(Qt::white); - QList<QGlyphRun> glyphsList = textLayout.glyphRuns(); + const QList<QGlyphRun> glyphsList = textLayout.glyphRuns(); QCOMPARE(glyphsList.size(), 1); { @@ -414,8 +418,7 @@ void tst_QGlyphRun::drawMultiScriptText1() { QPainter p(&drawGlyphs); - foreach (QGlyphRun glyphs, glyphsList) - p.drawGlyphRun(QPointF(50, 50), glyphs); + p.drawGlyphRun(QPointF(50, 50), glyphsList.first()); } #if defined(DEBUG_SAVE_IMAGE) @@ -445,7 +448,7 @@ void tst_QGlyphRun::drawMultiScriptText2() QPixmap drawGlyphs(1000, 1000); drawGlyphs.fill(Qt::white); - QList<QGlyphRun> glyphsList = textLayout.glyphRuns(); + const QList<QGlyphRun> glyphsList = textLayout.glyphRuns(); QCOMPARE(glyphsList.size(), 2); { @@ -455,7 +458,7 @@ void tst_QGlyphRun::drawMultiScriptText2() { QPainter p(&drawGlyphs); - foreach (QGlyphRun glyphs, glyphsList) + for (const QGlyphRun &glyphs : glyphsList) p.drawGlyphRun(QPointF(50, 50), glyphs); } @@ -560,6 +563,9 @@ void tst_QGlyphRun::boundingRect() void tst_QGlyphRun::mixedScripts() { + if (QFontDatabase::families(QFontDatabase::Korean).isEmpty()) + QSKIP("This test requires support for Hangul text"); + QString s; s += QChar(0x31); // The character '1' s += QChar(0xbc14); // Hangul character @@ -605,17 +611,365 @@ void tst_QGlyphRun::multiLineBoundingRect() void tst_QGlyphRun::defaultIgnorables() { + { + QTextLayout layout; + layout.setFont(QFont("QtsSpecialTestFont")); + layout.setText(QChar(0x200D)); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + QList<QGlyphRun> runs = layout.glyphRuns(); + QCOMPARE(runs.size(), 0); + } + + { + QTextLayout layout; + layout.setFont(QFont("QtsSpecialTestFont")); + layout.setText(QStringLiteral("AAA") + QChar(0xFE0F) + QStringLiteral("111")); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + QList<QGlyphRun> runs = layout.glyphRuns(); + QVERIFY(!runs.isEmpty()); + + bool hasFullMainFontRun = false; + for (const QGlyphRun &run : runs) { + // QtsSpecialFont will be used for at least five characters: AA[...]111 + // Depending on the font selected for the 0xFE0F variant selector, the + // third 'A' may be in QtsSpecialFont or in the fallback. This is platform-specific, + // so we accept either. + if (run.rawFont().familyName() == QStringLiteral("QtsSpecialTestFont") + && run.glyphIndexes().size() >= 5) { + hasFullMainFontRun = true; + break; + } + } + QVERIFY(hasFullMainFontRun); + } +} + +void tst_QGlyphRun::stringIndexes() +{ + int ligatureFontId = QFontDatabase::addApplicationFont(QFINDTESTDATA("Ligatures.otf")); + QVERIFY(ligatureFontId >= 0); + + QFont ligatureFont = QFont("QtLigatures"); + QCOMPARE(QFontInfo(ligatureFont).family(), QString::fromLatin1("QtLigatures")); + + QTextLayout::GlyphRunRetrievalFlags retrievalFlags + = QTextLayout::RetrieveGlyphIndexes | QTextLayout::RetrieveStringIndexes; + + // Three characters -> three glyphs + { + QTextLayout layout; + layout.setText("f i"); + layout.setFont(ligatureFont); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + { + QList<QGlyphRun> glyphRuns = layout.glyphRuns(-1, -1, retrievalFlags); + QCOMPARE(glyphRuns.size(), 1); + + QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes(); + QCOMPARE(stringIndexes.size(), 3); + QCOMPARE(stringIndexes.at(0), 0); + QCOMPARE(stringIndexes.at(1), 1); + QCOMPARE(stringIndexes.at(2), 2); + } + + { + QList<QGlyphRun> glyphRuns = layout.glyphRuns(2, -1, retrievalFlags); + QCOMPARE(glyphRuns.size(), 1); + + QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes(); + QCOMPARE(stringIndexes.size(), 1); + QCOMPARE(stringIndexes.at(0), 2); + } + } + + // Two characters -> one glyph + { + QTextLayout layout; + layout.setText("fi"); + layout.setFont(ligatureFont); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + { + QList<QGlyphRun> glyphRuns = layout.glyphRuns(-1, -1, retrievalFlags); + QCOMPARE(glyphRuns.size(), 1); + + QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 1); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(233)); + + QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes(); + QCOMPARE(stringIndexes.size(), 1); + QCOMPARE(stringIndexes.at(0), 0); + } + + { + QList<QGlyphRun> glyphRuns = layout.glyphRuns(1, -1, retrievalFlags); + QCOMPARE(glyphRuns.size(), 1); + + QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 1); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(233)); + + QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes(); + QCOMPARE(stringIndexes.size(), 1); + QCOMPARE(stringIndexes.at(0), 1); + } + } + + // Four characters -> three glyphs + { + QTextLayout layout; + layout.setText("ffii"); + layout.setFont(ligatureFont); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + { + QList<QGlyphRun> glyphRuns = layout.glyphRuns(-1, -1, retrievalFlags); + QCOMPARE(glyphRuns.size(), 1); + + QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 3); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(71)); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(1), uint(233)); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(2), uint(74)); + + QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes(); + QCOMPARE(stringIndexes.size(), 3); + QCOMPARE(stringIndexes.at(0), uint(0)); + QCOMPARE(stringIndexes.at(1), uint(1)); + QCOMPARE(stringIndexes.at(2), uint(3)); + } + + { + QList<QGlyphRun> glyphRuns = layout.glyphRuns(1, 1, retrievalFlags); + QCOMPARE(glyphRuns.size(), 1); + + QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 1); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(233)); + + QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes(); + QCOMPARE(stringIndexes.size(), 1); + QCOMPARE(stringIndexes.at(0), uint(1)); + } + + { + QList<QGlyphRun> glyphRuns = layout.glyphRuns(1, 2, retrievalFlags); + QCOMPARE(glyphRuns.size(), 1); + + QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 1); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(233)); + + QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes(); + QCOMPARE(stringIndexes.size(), 1); + QCOMPARE(stringIndexes.at(0), uint(1)); + } + + { + QList<QGlyphRun> glyphRuns = layout.glyphRuns(1, 3, retrievalFlags); + QCOMPARE(glyphRuns.size(), 1); + + QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 2); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(233)); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(1), uint(74)); + + QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes(); + QCOMPARE(stringIndexes.size(), 2); + QCOMPARE(stringIndexes.at(0), 1); + QCOMPARE(stringIndexes.at(1), 3); + } + + } + + // One character -> two glyphs + { + QTextLayout layout; + layout.setText(QChar(0xe6)); // LATIN SMALL LETTER AE + layout.setFont(ligatureFont); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + QList<QGlyphRun> glyphRuns = layout.glyphRuns(-1, -1, retrievalFlags); + QCOMPARE(glyphRuns.size(), 1); + + QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 2); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(66)); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(1), uint(70)); + + QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes(); + QCOMPARE(stringIndexes.size(), 2); + QCOMPARE(stringIndexes.at(0), uint(0)); + QCOMPARE(stringIndexes.at(1), uint(0)); + } + + // Three characters -> four glyphs + { + QTextLayout layout; + layout.setText(QString('f') + QChar(0xe6) + QChar('i')); + layout.setFont(ligatureFont); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + { + QList<QGlyphRun> glyphRuns = layout.glyphRuns(-1, -1, retrievalFlags); + QCOMPARE(glyphRuns.size(), 1); + + QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 4); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(71)); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(1), uint(66)); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(2), uint(70)); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(3), uint(74)); + + QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes(); + QCOMPARE(stringIndexes.size(), 4); + QCOMPARE(stringIndexes.at(0), 0); + QCOMPARE(stringIndexes.at(1), 1); + QCOMPARE(stringIndexes.at(2), 1); + QCOMPARE(stringIndexes.at(3), 2); + } + + { + QList<QGlyphRun> glyphRuns = layout.glyphRuns(1, -1, retrievalFlags); + QCOMPARE(glyphRuns.size(), 1); + + QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 3); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(66)); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(1), uint(70)); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(2), uint(74)); + + QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes(); + QCOMPARE(stringIndexes.size(), 3); + QCOMPARE(stringIndexes.at(0), 1); + QCOMPARE(stringIndexes.at(1), 1); + QCOMPARE(stringIndexes.at(2), 2); + } + + { + QList<QGlyphRun> glyphRuns = layout.glyphRuns(0, 2, retrievalFlags); + QCOMPARE(glyphRuns.size(), 1); + + QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 3); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(71)); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(1), uint(66)); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(2), uint(70)); + + QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes(); + QCOMPARE(stringIndexes.size(), 3); + QCOMPARE(stringIndexes.at(0), 0); + QCOMPARE(stringIndexes.at(1), 1); + QCOMPARE(stringIndexes.at(2), 1); + } + + + } + + // Five characters -> five glyphs + { + QTextLayout layout; + layout.setText(QLatin1String("ffi") + QChar(0xe6) + QLatin1Char('i')); + layout.setFont(ligatureFont); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + QList<QGlyphRun> glyphRuns = layout.glyphRuns(-1, -1, retrievalFlags); + QCOMPARE(glyphRuns.size(), 1); + + QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 5); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(71)); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(1), uint(233)); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(2), uint(66)); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(3), uint(70)); + QCOMPARE(glyphRuns.at(0).glyphIndexes().at(4), uint(74)); + + QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes(); + QCOMPARE(stringIndexes.size(), 5); + QCOMPARE(stringIndexes.at(0), 0); + QCOMPARE(stringIndexes.at(1), 1); + QCOMPARE(stringIndexes.at(2), 3); + QCOMPARE(stringIndexes.at(3), 3); + QCOMPARE(stringIndexes.at(4), 4); + } + +} + +void tst_QGlyphRun::retrievalFlags_data() +{ + QTest::addColumn<QTextLayout::GlyphRunRetrievalFlags>("flags"); + QTest::addColumn<bool>("expectedGlyphIndexes"); + QTest::addColumn<bool>("expectedStringIndexes"); + QTest::addColumn<bool>("expectedString"); + QTest::addColumn<bool>("expectedGlyphPositions"); + + QTest::newRow("Glyph indexes") + << QTextLayout::GlyphRunRetrievalFlags(QTextLayout::RetrieveGlyphIndexes) + << true << false << false << false; + QTest::newRow("Glyph Positions") + << QTextLayout::GlyphRunRetrievalFlags(QTextLayout::RetrieveGlyphPositions) + << false << false << false << true; + QTest::newRow("String indexes") + << QTextLayout::GlyphRunRetrievalFlags(QTextLayout::RetrieveStringIndexes) + << false << true << false << false; + QTest::newRow("String") + << QTextLayout::GlyphRunRetrievalFlags(QTextLayout::RetrieveString) + << false << false << true << false; + + QTest::newRow("Default") + << QTextLayout::GlyphRunRetrievalFlags(QTextLayout::DefaultRetrievalFlags) + << true << false << false << true; + QTest::newRow("All") + << QTextLayout::GlyphRunRetrievalFlags(QTextLayout::RetrieveAll) + << true << true << true << true; +} + +void tst_QGlyphRun::retrievalFlags() +{ + QFETCH(QTextLayout::GlyphRunRetrievalFlags, flags); + QFETCH(bool, expectedGlyphIndexes); + QFETCH(bool, expectedStringIndexes); + QFETCH(bool, expectedString); + QFETCH(bool, expectedGlyphPositions); + QTextLayout layout; - layout.setFont(QFont("QtsSpecialTestFont")); - layout.setText(QChar(0x200D)); + layout.setText(QLatin1String("abc")); layout.beginLayout(); layout.createLine(); layout.endLayout(); - QList<QGlyphRun> runs = layout.glyphRuns(); - QCOMPARE(runs.size(), 1); - QCOMPARE(runs.at(0).glyphIndexes().size(), 1); - QCOMPARE(runs.at(0).glyphIndexes()[0], uint(0)); + QList<QGlyphRun> glyphRuns = layout.glyphRuns(-1, -1, flags); + QVERIFY(!glyphRuns.isEmpty()); + + QGlyphRun firstGlyphRun = glyphRuns.first(); + QCOMPARE(firstGlyphRun.glyphIndexes().isEmpty(), !expectedGlyphIndexes); + QCOMPARE(firstGlyphRun.stringIndexes().isEmpty(), !expectedStringIndexes); + QCOMPARE(firstGlyphRun.sourceString().isEmpty(), !expectedString); + QCOMPARE(firstGlyphRun.positions().isEmpty(), !expectedGlyphPositions); +} + +void tst_QGlyphRun::objectReplacementCharacter() +{ + QTextLayout layout; + layout.setFont(m_testFont); + layout.setText(QStringLiteral("\uFFFC")); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + QList<QGlyphRun> glyphRuns = layout.glyphRuns(); + QCOMPARE(glyphRuns.size(), 1); + QCOMPARE(glyphRuns.first().glyphIndexes().size(), 1); + QCOMPARE(glyphRuns.first().glyphIndexes().first(), uint(5)); } #endif // QT_NO_RAWFONT diff --git a/tests/auto/gui/text/qinputcontrol/CMakeLists.txt b/tests/auto/gui/text/qinputcontrol/CMakeLists.txt index 048a96ef77..75fc85bc39 100644 --- a/tests/auto/gui/text/qinputcontrol/CMakeLists.txt +++ b/tests/auto/gui/text/qinputcontrol/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qinputcontrol.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qinputcontrol Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qinputcontrol LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qinputcontrol SOURCES tst_qinputcontrol.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate ) diff --git a/tests/auto/gui/text/qinputcontrol/tst_qinputcontrol.cpp b/tests/auto/gui/text/qinputcontrol/tst_qinputcontrol.cpp index a75975664b..678f4491c4 100644 --- a/tests/auto/gui/text/qinputcontrol/tst_qinputcontrol.cpp +++ b/tests/auto/gui/text/qinputcontrol/tst_qinputcontrol.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/gui/text/qrawfont/BLACKLIST b/tests/auto/gui/text/qrawfont/BLACKLIST deleted file mode 100644 index 44b3d7d481..0000000000 --- a/tests/auto/gui/text/qrawfont/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -# QTBUG-85364 -windows-10 gcc cmake diff --git a/tests/auto/gui/text/qrawfont/CMakeLists.txt b/tests/auto/gui/text/qrawfont/CMakeLists.txt index c7a883d9ce..d2a318a2a3 100644 --- a/tests/auto/gui/text/qrawfont/CMakeLists.txt +++ b/tests/auto/gui/text/qrawfont/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from qrawfont.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qrawfont Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qrawfont LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Resources: set_source_files_properties("../../../shared/resources/testfont.ttf" PROPERTIES QT_RESOURCE_ALIAS "testfont.ttf" @@ -17,7 +24,7 @@ set(testdata_resource_files qt_internal_add_test(tst_qrawfont SOURCES tst_qrawfont.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp index 0e90572709..5ec2536718 100644 --- a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp +++ b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtGui/QFontDatabase> @@ -96,7 +96,7 @@ void tst_QRawFont::initTestCase() if (testFont.isEmpty() || testFontBoldItalic.isEmpty()) QFAIL("qrawfont unittest font files not found!"); - if (QFontDatabase::families().count() == 0) + if (QFontDatabase::families().size() == 0) QSKIP("No fonts available!!!"); } @@ -398,13 +398,13 @@ void tst_QRawFont::textLayout() void tst_QRawFont::fontTable_data() { - QTest::addColumn<QByteArray>("tagName"); + QTest::addColumn<QFont::Tag>("tag"); QTest::addColumn<QFont::HintingPreference>("hintingPreference"); QTest::addColumn<int>("offset"); QTest::addColumn<quint32>("expectedValue"); QTest::newRow("Head table, magic number, default hinting") - << QByteArray("head") + << QFont::Tag("head") << QFont::PreferDefaultHinting << 12 << (QSysInfo::ByteOrder == QSysInfo::BigEndian @@ -412,7 +412,7 @@ void tst_QRawFont::fontTable_data() : 0xF53C0F5F); QTest::newRow("Head table, magic number, no hinting") - << QByteArray("head") + << QFont::Tag("head") << QFont::PreferNoHinting << 12 << (QSysInfo::ByteOrder == QSysInfo::BigEndian @@ -420,7 +420,7 @@ void tst_QRawFont::fontTable_data() : 0xF53C0F5F); QTest::newRow("Head table, magic number, vertical hinting") - << QByteArray("head") + << QFont::Tag("head") << QFont::PreferVerticalHinting << 12 << (QSysInfo::ByteOrder == QSysInfo::BigEndian @@ -428,7 +428,7 @@ void tst_QRawFont::fontTable_data() : 0xF53C0F5F); QTest::newRow("Head table, magic number, full hinting") - << QByteArray("head") + << QFont::Tag("head") << QFont::PreferFullHinting << 12 << (QSysInfo::ByteOrder == QSysInfo::BigEndian @@ -438,7 +438,7 @@ void tst_QRawFont::fontTable_data() void tst_QRawFont::fontTable() { - QFETCH(QByteArray, tagName); + QFETCH(QFont::Tag, tag); QFETCH(QFont::HintingPreference, hintingPreference); QFETCH(int, offset); QFETCH(quint32, expectedValue); @@ -446,11 +446,13 @@ void tst_QRawFont::fontTable() QRawFont font(testFont, 10, hintingPreference); QVERIFY(font.isValid()); - QByteArray table = font.fontTable(tagName); + QByteArray table = font.fontTable(tag); QVERIFY(!table.isEmpty()); const quint32 *value = reinterpret_cast<const quint32 *>(table.constData() + offset); QCOMPARE(*value, expectedValue); + + QCOMPARE(font.fontTable(tag.toString()), table); } typedef QList<QFontDatabase::WritingSystem> WritingSystemList; @@ -490,7 +492,7 @@ void tst_QRawFont::supportedWritingSystems_data() void tst_QRawFont::supportedWritingSystems() { QFETCH(QString, fileName); - QFETCH(WritingSystemList, writingSystems); + QFETCH(const WritingSystemList, writingSystems); QFETCH(QFont::HintingPreference, hintingPreference); QRawFont font(fileName, 10, hintingPreference); @@ -499,7 +501,7 @@ void tst_QRawFont::supportedWritingSystems() WritingSystemList actualWritingSystems = font.supportedWritingSystems(); QCOMPARE(actualWritingSystems.size(), writingSystems.size()); - foreach (QFontDatabase::WritingSystem writingSystem, writingSystems) + for (QFontDatabase::WritingSystem writingSystem : writingSystems) QVERIFY(actualWritingSystems.contains(writingSystem)); } @@ -1052,7 +1054,7 @@ void tst_QRawFont::qtbug65923_partal_clone_data() void tst_QRawFont::qtbug65923_partal_clone() { QFile file(testFont); - file.open(QIODevice::ReadOnly); + QVERIFY(file.open(QIODevice::ReadOnly)); QByteArray fontData = file.readAll(); QRawFont outerFont; diff --git a/tests/auto/gui/text/qstatictext/CMakeLists.txt b/tests/auto/gui/text/qstatictext/CMakeLists.txt index a7ba4e392a..bdad2609fe 100644 --- a/tests/auto/gui/text/qstatictext/CMakeLists.txt +++ b/tests/auto/gui/text/qstatictext/CMakeLists.txt @@ -1,21 +1,28 @@ -# Generated from qstatictext.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qstatictext Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qstatictext LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qstatictext SOURCES tst_qstatictext.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) ## Scopes: ##################################################################### -qt_internal_extend_target(tst_qstatictext CONDITION QT_FEATURE_private_tests - PUBLIC_LIBRARIES +qt_internal_extend_target(tst_qstatictext CONDITION QT_FEATURE_developer_build + LIBRARIES Qt::CorePrivate Qt::GuiPrivate ) diff --git a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp index 397a116a73..add2303199 100644 --- a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp +++ b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtCore/QSet> @@ -50,10 +50,6 @@ private slots: void rotatedPainter(); void scaledPainter(); void projectedPainter(); -#if 0 - void rotatedScaledAndTranslatedPainter_data(); - void rotatedScaledAndTranslatedPainter(); -#endif void transformationChanged(); void plainTextVsRichText(); @@ -82,11 +78,6 @@ private: Q_DECLARE_METATYPE(QImage::Format); -static bool isPlatformWayland() -{ - return QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive); -} - void tst_QStaticText::constructionAndDestruction() { QStaticText text("My text"); @@ -148,8 +139,6 @@ void tst_QStaticText::drawToPoint() } QVERIFY(imageDrawText.toImage() != m_whiteSquare); - if (isPlatformWayland()) - QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100982.", Abort); QCOMPARE(imageDrawStaticText, imageDrawText); } @@ -190,8 +179,6 @@ void tst_QStaticText::drawToRect() #endif QVERIFY(imageDrawText.toImage() != m_whiteSquare); - if (isPlatformWayland()) - QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100982.", Abort); QCOMPARE(imageDrawStaticText, imageDrawText); } @@ -246,13 +233,11 @@ void tst_QStaticText::compareToDrawText() #if defined(DEBUG_SAVE_IMAGE) imageDrawText.save("compareToDrawText_imageDrawText.png"); - imageDrawStaticText.save("compareToDrawText_imageDrawStaticPlainText.png"); - imageDrawStaticText.save("compareToDrawText_imageDrawStaticRichText.png"); + imageDrawStaticPlainText.save("compareToDrawText_imageDrawStaticPlainText.png"); + imageDrawStaticRichText.save("compareToDrawText_imageDrawStaticRichText.png"); #endif QVERIFY(imageDrawText.toImage() != m_whiteSquare); - if (isPlatformWayland() && font == QFont()) - QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100982.", Abort); QCOMPARE(imageDrawStaticPlainText, imageDrawText); QCOMPARE(imageDrawStaticRichText, imageDrawText); } @@ -360,8 +345,6 @@ void tst_QStaticText::setFont() #endif QVERIFY(imageDrawText.toImage() != m_whiteSquare); - if (isPlatformWayland()) - QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100982.", Abort); QCOMPARE(imageDrawStaticText, imageDrawText); } @@ -385,8 +368,6 @@ void tst_QStaticText::setTextWidth() } QVERIFY(imageDrawText.toImage() != m_whiteSquare); - if (isPlatformWayland()) - QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100982.", Abort); QCOMPARE(imageDrawStaticText, imageDrawText); } @@ -414,8 +395,6 @@ void tst_QStaticText::translatedPainter() } QVERIFY(imageDrawText.toImage() != m_whiteSquare); - if (isPlatformWayland()) - QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100982.", Abort); QCOMPARE(imageDrawStaticText, imageDrawText); } @@ -456,8 +435,6 @@ void tst_QStaticText::rotatedPainter() if (!supportsTransformations()) QEXPECT_FAIL("", "Graphics system does not support transformed text on this platform", Abort); - if (isPlatformWayland()) - QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100982.", Abort); QCOMPARE(imageDrawStaticText, imageDrawText); } @@ -488,8 +465,6 @@ void tst_QStaticText::scaledPainter() if (!supportsTransformations()) QEXPECT_FAIL("", "Graphics system does not support transformed text on this platform", Abort); - if (isPlatformWayland()) - QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100982.", Abort); QCOMPARE(imageDrawStaticText, imageDrawText); } @@ -522,61 +497,6 @@ void tst_QStaticText::projectedPainter() QCOMPARE(imageDrawStaticText, imageDrawText); } -#if 0 -void tst_QStaticText::rotatedScaledAndTranslatedPainter_data() -{ - QTest::addColumn<qreal>("offset"); - - for (int i=0; i<100; ++i) { - qreal offset = 300 + i / 100.; - QTest::newRow(QByteArray::number(offset).constData()) << offset; - } -} - -void tst_QStaticText::rotatedScaledAndTranslatedPainter() -{ - QFETCH(qreal, offset); - - QPixmap imageDrawText(1000, 1000); - imageDrawText.fill(Qt::white); - { - QPainter p(&imageDrawText); - p.translate(offset, 0); - p.rotate(45.0); - p.scale(2.0, 2.0); - p.translate(100, 200); - - p.drawText(11, 12, "Lorem ipsum dolor sit amet, consectetur adipiscing elit."); - } - - QPixmap imageDrawStaticText(1000, 1000); - imageDrawStaticText.fill(Qt::white); - { - QPainter p(&imageDrawStaticText); - p.translate(offset, 0); - p.rotate(45.0); - p.scale(2.0, 2.0); - p.translate(100, 200); - - QStaticText text("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); - text.setTextFormat(Qt::PlainText); - - p.drawStaticText(QPointF(11, 12 - QFontMetricsF(p.font()).ascent()), text); - } - -#if defined(DEBUG_SAVE_IMAGE) - imageDrawText.save("rotatedScaledAndPainter_imageDrawText.png"); - imageDrawStaticText.save("rotatedScaledAndPainter_imageDrawStaticText.png"); -#endif - - QVERIFY(imageDrawText.toImage() != m_whiteSquare); - - if (!supportsTransformations()) - QEXPECT_FAIL("", "Graphics system does not support transformed text on this platform", Abort); - QCOMPARE(imageDrawStaticText, imageDrawText); -} -#endif - void tst_QStaticText::transformationChanged() { QPixmap imageDrawText(1000, 1000); @@ -617,8 +537,6 @@ void tst_QStaticText::transformationChanged() if (!supportsTransformations()) QEXPECT_FAIL("", "Graphics system does not support transformed text on this platform", Abort); - if (isPlatformWayland()) - QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100982.", Abort); QCOMPARE(imageDrawStaticText, imageDrawText); } diff --git a/tests/auto/gui/text/qsyntaxhighlighter/CMakeLists.txt b/tests/auto/gui/text/qsyntaxhighlighter/CMakeLists.txt index 9ac732cee0..f1c9146ce1 100644 --- a/tests/auto/gui/text/qsyntaxhighlighter/CMakeLists.txt +++ b/tests/auto/gui/text/qsyntaxhighlighter/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qsyntaxhighlighter.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qsyntaxhighlighter Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qsyntaxhighlighter LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qsyntaxhighlighter SOURCES tst_qsyntaxhighlighter.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) @@ -15,6 +22,6 @@ qt_internal_add_test(tst_qsyntaxhighlighter ##################################################################### qt_internal_extend_target(tst_qsyntaxhighlighter CONDITION TARGET Qt::Widgets - PUBLIC_LIBRARIES + LIBRARIES Qt::Widgets ) diff --git a/tests/auto/gui/text/qsyntaxhighlighter/tst_qsyntaxhighlighter.cpp b/tests/auto/gui/text/qsyntaxhighlighter/tst_qsyntaxhighlighter.cpp index 202d07ea1e..748f494a41 100644 --- a/tests/auto/gui/text/qsyntaxhighlighter/tst_qsyntaxhighlighter.cpp +++ b/tests/auto/gui/text/qsyntaxhighlighter/tst_qsyntaxhighlighter.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -100,7 +100,7 @@ public: virtual void highlightBlock(const QString &text) override { - for (int i = 0; i < formats.count(); ++i) { + for (int i = 0; i < formats.size(); ++i) { const QTextLayout::FormatRange &range = formats.at(i); setFormat(range.start, range.length, range.format); } @@ -161,7 +161,7 @@ public: commentFormat.setForeground(Qt::darkGreen); commentFormat.setFontWeight(QFont::StyleItalic); commentFormat.setFontFixedPitch(true); - int textLength = text.length(); + int textLength = text.size(); if (text.startsWith(QLatin1Char(';'))){ // The entire line is a comment @@ -414,7 +414,7 @@ void tst_QSyntaxHighlighter::preservePreeditArea() QCOMPARE(hl->callCount, 1); formats = layout->formats(); - QCOMPARE(formats.count(), 3); + QCOMPARE(formats.size(), 3); range = formats.at(0); @@ -493,7 +493,7 @@ void tst_QSyntaxHighlighter::noContentsChangedDuringHighlight() QSignalSpy contentsChangedSpy(doc, SIGNAL(contentsChanged())); cursor.insertText("Hello World"); - QCOMPARE(contentsChangedSpy.count(), 1); + QCOMPARE(contentsChangedSpy.size(), 1); QVERIFY(hl->highlighted); QVERIFY(lout->documentChangedCalled); } diff --git a/tests/auto/gui/text/qtextblock/CMakeLists.txt b/tests/auto/gui/text/qtextblock/CMakeLists.txt index aedd6c27a3..83cc1ce08e 100644 --- a/tests/auto/gui/text/qtextblock/CMakeLists.txt +++ b/tests/auto/gui/text/qtextblock/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qtextblock.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtextblock Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtextblock LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtextblock SOURCES tst_qtextblock.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/text/qtextblock/tst_qtextblock.cpp b/tests/auto/gui/text/qtextblock/tst_qtextblock.cpp index e6400fafb0..50331ddef2 100644 --- a/tests/auto/gui/text/qtextblock/tst_qtextblock.cpp +++ b/tests/auto/gui/text/qtextblock/tst_qtextblock.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtTest/QTest> diff --git a/tests/auto/gui/text/qtextcursor/CMakeLists.txt b/tests/auto/gui/text/qtextcursor/CMakeLists.txt index a82dc928e9..487965f9f8 100644 --- a/tests/auto/gui/text/qtextcursor/CMakeLists.txt +++ b/tests/auto/gui/text/qtextcursor/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qtextcursor.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtextcursor Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtextcursor LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtextcursor SOURCES tst_qtextcursor.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp b/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp index cc6722af40..8f5cacae4a 100644 --- a/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp +++ b/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -39,7 +39,9 @@ private slots: void navigation7(); void navigation8(); void navigation9(); +#ifndef QT_NO_TEXTHTMLPARSER void navigation10(); +#endif void movePositionEndOfLine(); void insertBlock(); void insertWithBlockSeparator1(); @@ -431,6 +433,7 @@ void tst_QTextCursor::navigation9() QCOMPARE(cursor.position(), 15); } +#ifndef QT_NO_TEXTHTMLPARSER void tst_QTextCursor::navigation10() { doc->setHtml("<html><p>just a simple paragraph.</p>" @@ -542,6 +545,7 @@ void tst_QTextCursor::navigation10() QVERIFY(ok); QCOMPARE(cursor.position(), 1); // a } +#endif void tst_QTextCursor::insertBlock() { @@ -1545,15 +1549,20 @@ void tst_QTextCursor::insertMarkdown_data() << 6 << QString("0) eggs\n1) maple syrup\n") << QString("bread\u2029eggs\u2029maple syrup\u2029milk") << QString("bread\neggs\nmaple syrup\nmilk") - << QString("1) bread\n2) eggs\n1) maple syrup\n2) milk\n"); - // renumbering would happen if we re-read the whole document + << QString("1) bread\n2) eggs\n0) maple syrup\n1) milk\n"); + // Renumbering would happen if we re-read the whole document. + // Currently insertion only uses the new list format after a paragraph separator. + // For that reason "bread" and "eggs" use the original list format, while "maple syrup" and + // "milk" use the format from the just inserted list. QTest::newRow("list after a list") << "1) bread\n2) milk\n\n" << 2 << 13 << QString("\n0) eggs\n1) maple syrup\n") << QString("bread\u2029milk\u2029eggs\u2029maple syrup") << QString("bread\nmilk\neggs\nmaple syrup") - << QString("1) bread\n2) milk\n3) eggs\n1) maple syrup\n"); + << QString("1) bread\n2) milk\n3) eggs\n0) maple syrup\n"); + // Same behavior as above. "eggs" uses the original list format, but "maple syrup" uses the + // format of the inserted list, which means "maple syrup" now has a start of 0. const QString markdownHeadingString("# Hello\nWorld\n"); @@ -1754,26 +1763,26 @@ void tst_QTextCursor::update_data() QTest::newRow("removeInsideSelection") << text << /*position*/ 0 - << /*anchor*/ int(text.length()) + << /*anchor*/ int(text.size()) // delete 'big' << 6 << 6 + charsToDelete << QString() // don't insert anything, just remove << /*expectedPosition*/ 0 - << /*expectedAnchor*/ int(text.length() - charsToDelete) + << /*expectedAnchor*/ int(text.size() - charsToDelete) ; text = "Hello big world"; charsToDelete = 3; QTest::newRow("removeInsideSelectionWithSwappedAnchorAndPosition") << text - << /*position*/ int(text.length()) + << /*position*/ int(text.size()) << /*anchor*/ 0 // delete 'big' << 6 << 6 + charsToDelete << QString() // don't insert anything, just remove - << /*expectedPosition*/ int(text.length() - charsToDelete) + << /*expectedPosition*/ int(text.size() - charsToDelete) << /*expectedAnchor*/ 0 ; @@ -1784,13 +1793,13 @@ void tst_QTextCursor::update_data() QTest::newRow("replaceInsideSelection") << text << /*position*/ 0 - << /*anchor*/ int(text.length()) + << /*anchor*/ int(text.size()) // delete 'big' ... << 6 << 6 + charsToDelete << textToInsert // ... and replace 'big' with 'small' << /*expectedPosition*/ 0 - << /*expectedAnchor*/ int(text.length() - charsToDelete + textToInsert.length()) + << /*expectedAnchor*/ int(text.size() - charsToDelete + textToInsert.size()) ; text = "Hello big world"; @@ -1798,13 +1807,13 @@ void tst_QTextCursor::update_data() textToInsert = "small"; QTest::newRow("replaceInsideSelectionWithSwappedAnchorAndPosition") << text - << /*position*/ int(text.length()) + << /*position*/ int(text.size()) << /*anchor*/ 0 // delete 'big' ... << 6 << 6 + charsToDelete << textToInsert // ... and replace 'big' with 'small' - << /*expectedPosition*/ int(text.length() - charsToDelete + textToInsert.length()) + << /*expectedPosition*/ int(text.size() - charsToDelete + textToInsert.size()) << /*expectedAnchor*/ 0 ; @@ -1813,14 +1822,14 @@ void tst_QTextCursor::update_data() charsToDelete = 3; QTest::newRow("removeBeforeSelection") << text - << /*position*/ int(text.length() - 5) - << /*anchor*/ int(text.length()) + << /*position*/ int(text.size() - 5) + << /*anchor*/ int(text.size()) // delete 'big' << 6 << 6 + charsToDelete << QString() // don't insert anything, just remove - << /*expectedPosition*/ int(text.length() - 5 - charsToDelete) - << /*expectedAnchor*/ int(text.length() - charsToDelete) + << /*expectedPosition*/ int(text.size() - 5 - charsToDelete) + << /*expectedAnchor*/ int(text.size() - charsToDelete) ; text = "Hello big world"; diff --git a/tests/auto/gui/text/qtextdocument/CMakeLists.txt b/tests/auto/gui/text/qtextdocument/CMakeLists.txt index bff5cabfb7..62fa1d46ca 100644 --- a/tests/auto/gui/text/qtextdocument/CMakeLists.txt +++ b/tests/auto/gui/text/qtextdocument/CMakeLists.txt @@ -1,14 +1,21 @@ -# Generated from qtextdocument.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtextdocument Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtextdocument LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtextdocument SOURCES common.h tst_qtextdocument.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/text/qtextdocument/common.h b/tests/auto/gui/text/qtextdocument/common.h index 5b45315704..3c05913008 100644 --- a/tests/auto/gui/text/qtextdocument/common.h +++ b/tests/auto/gui/text/qtextdocument/common.h @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QAbstractTextDocumentLayout> #include <private/qtextdocument_p.h> diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp index 5344e6881c..600b45575f 100644 --- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -180,6 +180,12 @@ private slots: void insertHtmlWithComments_data(); void insertHtmlWithComments(); + void delayedLayout(); + void undoContentChangeIndices(); + + void restoreStrokeFromHtml(); + void restoreForegroundGradientFromHtml(); + private: void backgroundImage_checkExpectedHtml(const QTextDocument &doc); void buildRegExpData(); @@ -272,6 +278,8 @@ void tst_QTextDocument::init() "<html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "hr { height: 1px; border-width: 0; }\n" + "li.unchecked::marker { content: \"\\2610\"; }\n" + "li.checked::marker { content: \"\\2612\"; }\n" "</style></head>" "<body style=\" font-family:'%1'; font-size:%2; font-weight:%3; font-style:%4;\">\n"); htmlHead = htmlHead.arg(defaultFont.family()) @@ -461,17 +469,17 @@ void tst_QTextDocument::basicIsModifiedChecks() QVERIFY(!doc->isModified()); cursor.insertText("Hello World"); QVERIFY(doc->isModified()); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QVERIFY(spy.takeFirst().at(0).toBool()); doc->undo(); QVERIFY(!doc->isModified()); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QVERIFY(!spy.takeFirst().at(0).toBool()); doc->redo(); QVERIFY(doc->isModified()); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QVERIFY(spy.takeFirst().at(0).toBool()); } @@ -562,16 +570,16 @@ void tst_QTextDocument::noundo_basicIsModifiedChecks() QVERIFY(!doc->isModified()); cursor.insertText("Hello World"); QVERIFY(doc->isModified()); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QVERIFY(spy.takeFirst().at(0).toBool()); doc->undo(); QVERIFY(doc->isModified()); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); doc->redo(); QVERIFY(doc->isModified()); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); } void tst_QTextDocument::task240325() @@ -739,6 +747,9 @@ void tst_QTextDocument::mightBeRichText_data() " PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">\n" "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">"; QVERIFY(Qt::mightBeRichText(QString::fromLatin1(qtDocuHeader))); + QVERIFY(Qt::mightBeRichText(QLatin1StringView(qtDocuHeader))); + QVERIFY(QUtf8StringView(qtDocuHeader).isValidUtf8()); + QVERIFY(Qt::mightBeRichText(QUtf8StringView(qtDocuHeader))); QTest::addColumn<QString>("input"); QTest::addColumn<bool>("result"); @@ -758,6 +769,10 @@ void tst_QTextDocument::mightBeRichText() QFETCH(QString, input); QFETCH(bool, result); QCOMPARE(result, Qt::mightBeRichText(input)); + QCOMPARE(result, Qt::mightBeRichText(QStringView(input))); + QCOMPARE(result, Qt::mightBeRichText(QUtf8StringView(input.toUtf8()))); + QVERIFY(QtPrivate::isLatin1(input)); + QCOMPARE(result, Qt::mightBeRichText(QLatin1StringView(input.toLatin1()))); } Q_DECLARE_METATYPE(QTextDocumentFragment) @@ -1157,7 +1172,7 @@ void tst_QTextDocument::toHtml_data() cursor.insertTable(2, 2); QTest::newRow("simpletable") << QTextDocumentFragment(&doc) - << QString("<table border=\"1\" cellspacing=\"2\">" + << QString("<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">" "\n<tr>\n<td></td>\n<td></td></tr>" "\n<tr>\n<td></td>\n<td></td></tr>" "</table>"); @@ -1171,7 +1186,7 @@ void tst_QTextDocument::toHtml_data() table->mergeCells(0, 2, 1, 2); QTest::newRow("tablespans") << QTextDocumentFragment(&doc) - << QString("<table border=\"1\" cellspacing=\"2\">" + << QString("<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">" "\n<tr>\n<td colspan=\"2\"></td>\n<td colspan=\"2\"></td></tr>" "</table>"); } @@ -1190,7 +1205,7 @@ void tst_QTextDocument::toHtml_data() cursor.insertTable(2, 2, fmt); QTest::newRow("tableattrs") << QTextDocumentFragment(&doc) - << QString("<table border=\"1\" style=\" float: right;\" align=\"center\" width=\"50%\" cellspacing=\"3\" cellpadding=\"3\" bgcolor=\"#ff00ff\">" + << QString("<table border=\"1\" style=\" float: right; border-collapse:collapse;\" align=\"center\" width=\"50%\" cellspacing=\"3\" cellpadding=\"3\" bgcolor=\"#ff00ff\">" "\n<tr>\n<td></td>\n<td></td></tr>" "\n<tr>\n<td></td>\n<td></td></tr>" "</table>"); @@ -1212,7 +1227,7 @@ void tst_QTextDocument::toHtml_data() cursor.insertTable(2, 2, fmt); QTest::newRow("tableattrs2") << QTextDocumentFragment(&doc) - << QString("<table border=\"1\" style=\" float: right; margin-top:0px; margin-bottom:35px; margin-left:25px; margin-right:0px;\" align=\"center\" width=\"50%\" cellspacing=\"3\" cellpadding=\"3\" bgcolor=\"#ff00ff\">" + << QString("<table border=\"1\" style=\" float: right; margin-top:0px; margin-bottom:35px; margin-left:25px; margin-right:0px; border-collapse:collapse;\" align=\"center\" width=\"50%\" cellspacing=\"3\" cellpadding=\"3\" bgcolor=\"#ff00ff\">" "\n<tr>\n<td></td>\n<td></td></tr>" "\n<tr>\n<td></td>\n<td></td></tr>" "</table>"); @@ -1226,7 +1241,7 @@ void tst_QTextDocument::toHtml_data() cursor.insertTable(4, 2, fmt); QTest::newRow("tableheader") << QTextDocumentFragment(&doc) - << QString("<table border=\"1\" cellspacing=\"2\">" + << QString("<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">" "<thead>\n<tr>\n<td></td>\n<td></td></tr>" "\n<tr>\n<td></td>\n<td></td></tr></thead>" "\n<tr>\n<td></td>\n<td></td></tr>" @@ -1242,8 +1257,8 @@ void tst_QTextDocument::toHtml_data() subTable->cellAt(0, 0).firstCursorPosition().insertText("Hey"); QTest::newRow("nestedtable") << QTextDocumentFragment(&doc) - << QString("<table border=\"1\" cellspacing=\"2\">" - "\n<tr>\n<td></td>\n<td>\n<table border=\"1\" cellspacing=\"2\">\n<tr>\n<td>\n<p DEFAULTBLOCKSTYLE>Hey</p></td></tr></table></td></tr>" + << QString("<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">" + "\n<tr>\n<td></td>\n<td>\n<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">\n<tr>\n<td>\n<p DEFAULTBLOCKSTYLE>Hey</p></td></tr></table></td></tr>" "\n<tr>\n<td></td>\n<td></td></tr>" "</table>"); } @@ -1260,7 +1275,7 @@ void tst_QTextDocument::toHtml_data() cursor.insertTable(1, 3, fmt); QTest::newRow("colwidths") << QTextDocumentFragment(&doc) - << QString("<table border=\"1\" cellspacing=\"2\">" + << QString("<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">" "\n<tr>\n<td></td>\n<td width=\"30%\"></td>\n<td width=\"40\"></td></tr>" "</table>"); } @@ -1277,7 +1292,7 @@ void tst_QTextDocument::toHtml_data() cellCurs.mergeBlockCharFormat(fmt); QTest::newRow("cellproperties") << QTextDocumentFragment(&doc) - << QString("<table border=\"1\" cellspacing=\"2\">" + << QString("<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">" "\n<tr>\n<td bgcolor=\"#ffffff\"></td></tr>" "</table>"); } @@ -1369,7 +1384,7 @@ void tst_QTextDocument::toHtml_data() QTest::newRow("lists") << QTextDocumentFragment(&doc) << QString("EMPTYBLOCK") + - QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\"><li DEFAULTBLOCKSTYLE>Blubb</li>\n<li DEFAULTBLOCKSTYLE>Blah</li></ul>"); + QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\">\n<li DEFAULTBLOCKSTYLE>Blubb</li>\n<li DEFAULTBLOCKSTYLE>Blah</li></ul>"); } { @@ -1392,7 +1407,7 @@ void tst_QTextDocument::toHtml_data() QTest::newRow("charfmt-for-list-item") << QTextDocumentFragment(&doc) << QString("EMPTYBLOCK") + - QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\"><li DEFAULTBLOCKSTYLE>Blubb</li>\n<li style=\" color:#0000ff;\" DEFAULTBLOCKSTYLE><span style=\" color:#ff0000;\">Blah</span></li></ul>"); + QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\">\n<li DEFAULTBLOCKSTYLE>Blubb</li>\n<li style=\" color:#0000ff;\" DEFAULTBLOCKSTYLE><span style=\" color:#ff0000;\">Blah</span></li></ul>"); } { @@ -1422,7 +1437,7 @@ void tst_QTextDocument::toHtml_data() QTest::newRow("list-indent") << QTextDocumentFragment(&doc) << QString("EMPTYBLOCK") + - QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 4;\"><li DEFAULTBLOCKSTYLE>Blah</li></ul>"); + QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 4;\">\n<li DEFAULTBLOCKSTYLE>Blah</li></ul>"); } { @@ -1544,7 +1559,7 @@ void tst_QTextDocument::toHtml_data() table->setFormat(fmt); QTest::newRow("mergedtablecolwidths") << QTextDocumentFragment(&doc) - << QString("<table border=\"1\" cellspacing=\"2\">" + << QString("<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">" "\n<tr>\n<td colspan=\"2\"></td></tr>" "\n<tr>\n<td width=\"20\"></td>\n<td width=\"40\"></td></tr>" "</table>"); @@ -1607,7 +1622,7 @@ void tst_QTextDocument::toHtml_data() table->cellAt(0, 0).firstCursorPosition().insertText("Blah"); QTest::newRow("table-vertical-alignment") << QTextDocumentFragment(&doc) - << QString("<table border=\"1\" cellspacing=\"2\">" + << QString("<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">" "\n<tr>\n<td style=\" vertical-align:middle;\">\n" "<p DEFAULTBLOCKSTYLE>Blah</p></td>" "\n<td style=\" vertical-align:top;\"></td></tr>" @@ -1636,7 +1651,7 @@ void tst_QTextDocument::toHtml_data() table->cellAt(0, 0).firstCursorPosition().insertText("Blah"); QTest::newRow("table-cell-paddings") << QTextDocumentFragment(&doc) - << QString("<table border=\"1\" cellspacing=\"2\">" + << QString("<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">" "\n<tr>\n<td style=\" padding-left:1;\">\n" "<p DEFAULTBLOCKSTYLE>Blah</p></td>" "\n<td style=\" padding-right:1;\"></td></tr>" @@ -1654,7 +1669,7 @@ void tst_QTextDocument::toHtml_data() cursor.insertTable(2, 2, fmt); QTest::newRow("tableborder") << QTextDocumentFragment(&doc) - << QString("<table border=\"1\" style=\" border-color:#0000ff; border-style:solid;\" cellspacing=\"2\">" + << QString("<table border=\"1\" style=\" border-color:#0000ff; border-style:solid; border-collapse:collapse;\" cellpadding=\"4\">" "\n<tr>\n<td></td>\n<td></td></tr>" "\n<tr>\n<td></td>\n<td></td></tr>" "</table>"); @@ -1696,7 +1711,7 @@ void tst_QTextDocument::toHtml_data() << QString("EMPTYBLOCK") + QString("<p OPENDEFAULTBLOCKSTYLE page-break-before:always;\">Foo</p>" "\n<p OPENDEFAULTBLOCKSTYLE page-break-before:always; page-break-after:always;\">Bar</p>" - "\n<table border=\"1\" style=\" page-break-after:always;\" cellspacing=\"2\">\n<tr>\n<td></td></tr></table>"); + "\n<table border=\"1\" style=\" page-break-after:always; border-collapse:collapse;\" cellpadding=\"4\">\n<tr>\n<td></td></tr></table>"); } { @@ -1710,7 +1725,7 @@ void tst_QTextDocument::toHtml_data() QTest::newRow("list-ul-margin") << QTextDocumentFragment(&doc) << QString("EMPTYBLOCK") + - QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\"><li DEFAULTBLOCKSTYLE>Blah</li></ul>"); + QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\">\n<li DEFAULTBLOCKSTYLE>Blah</li></ul>"); } { CREATE_DOC_AND_CURSOR(); @@ -1720,12 +1735,12 @@ void tst_QTextDocument::toHtml_data() cursor.insertHtml(listHtml); QTest::newRow("nested-lists-one") << QTextDocumentFragment(&doc) - << QString("<ul DEFAULTULSTYLE 1;\"><li style=\" margin-top:12px; margin-bottom:0px; " + << QString("<ul DEFAULTULSTYLE 1;\">\n<li style=\" margin-top:12px; margin-bottom:0px; " "margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" - "item-1</li>\n<li DEFAULTBLOCKSTYLE>item-2\n<ul DEFAULTULSTYLE 2;\"><li " + "item-1</li>\n<li DEFAULTBLOCKSTYLE>item-2\n<ul DEFAULTULSTYLE 2;\">\n<li " "DEFAULTBLOCKSTYLE>item-2.1</li>\n<li DEFAULTBLOCKSTYLE>item-2.2\n<ul " - "DEFAULTULSTYLE 3;\"><li DEFAULTBLOCKSTYLE>item-2.2.1</li></ul></li>\n" - "<li DEFAULTBLOCKSTYLE>item-2.3\n<ul DEFAULTULSTYLE 3;\"><li DEFAULTBLOCKSTYLE>" + "DEFAULTULSTYLE 3;\">\n<li DEFAULTBLOCKSTYLE>item-2.2.1</li></ul></li>\n" + "<li DEFAULTBLOCKSTYLE>item-2.3\n<ul DEFAULTULSTYLE 3;\">\n<li DEFAULTBLOCKSTYLE>" "item-2.3.1</li></ul></li></ul></li>\n<li DEFAULTLASTLISTYLE>item-3</li></ul>"); } { @@ -1734,9 +1749,9 @@ void tst_QTextDocument::toHtml_data() cursor.insertHtml(listHtml); QTest::newRow("nested-lists-two") << QTextDocumentFragment(&doc) - << QString("<ul DEFAULTULSTYLE 1;\"><li style=\" margin-top:12px; margin-bottom:0px; " + << QString("<ul DEFAULTULSTYLE 1;\">\n<li style=\" margin-top:12px; margin-bottom:0px; " "margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" - "item-1</li>\n<li DEFAULTLASTLISTYLE>item-2\n<ul DEFAULTULSTYLE 2;\"><li " + "item-1</li>\n<li DEFAULTLASTLISTYLE>item-2\n<ul DEFAULTULSTYLE 2;\">\n<li " "DEFAULTBLOCKSTYLE>item-2.1</li></ul></li></ul>"); } { @@ -1746,9 +1761,9 @@ void tst_QTextDocument::toHtml_data() cursor.insertHtml(listHtml); QTest::newRow("nested-lists-three") << QTextDocumentFragment(&doc) - << QString("<ul DEFAULTULSTYLE 1;\"><li style=\" margin-top:12px; margin-bottom:0px; " + << QString("<ul DEFAULTULSTYLE 1;\">\n<li style=\" margin-top:12px; margin-bottom:0px; " "margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" - "item-1</li>\n<li DEFAULTLASTLISTYLE>item-2\n<ul DEFAULTULSTYLE 2;\"><li " + "item-1</li>\n<li DEFAULTLASTLISTYLE>item-2\n<ul DEFAULTULSTYLE 2;\">\n<li " "DEFAULTBLOCKSTYLE>item-2.1</li>\n<li DEFAULTBLOCKSTYLE>item-2.2</li></ul>" "</li></ul>"); } @@ -1759,12 +1774,39 @@ void tst_QTextDocument::toHtml_data() cursor.insertHtml(listHtml); QTest::newRow("not-nested-list") << QTextDocumentFragment(&doc) - << QString("<ul DEFAULTULSTYLE 1;\"><li style=\" margin-top:12px; margin-bottom:0px; " + << QString("<ul DEFAULTULSTYLE 1;\">\n<li style=\" margin-top:12px; margin-bottom:0px; " "margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" - "item-1.1</li>\n<li DEFAULTBLOCKSTYLE>item-1.2</li></ul>\n<ul DEFAULTULSTYLE 1;\">" + "item-1.1</li>\n<li DEFAULTBLOCKSTYLE>item-1.2</li></ul>\n<ul DEFAULTULSTYLE 1;\">\n" "<li style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; " "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">item-2.1</li></ul>"); } + { + CREATE_DOC_AND_CURSOR(); + const QString listHtml = "<ul><li>bullet</li><li class=\"unchecked\">unchecked item</li><li class=\"checked\">checked item</li></ul>"; + cursor.insertHtml(listHtml); + + QTest::newRow("list with and without checkboxes") << QTextDocumentFragment(&doc) + << QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\">\n" + "<li style=\" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">bullet</li>\n" + "<li class=\"unchecked\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">unchecked item</li>\n" + "<li class=\"checked\" style=\" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">checked item</li></ul>"); + } + + { + CREATE_DOC_AND_CURSOR(); + + QTextListFormat fmt; + fmt.setStyle(QTextListFormat::ListDecimal); + fmt.setStart(4); + cursor.insertList(fmt); + cursor.insertText("Blah"); + cursor.insertBlock(); + cursor.insertText("Bleh"); + + QTest::newRow("ordered list with start") << QTextDocumentFragment(&doc) + << QString("EMPTYBLOCK") + + QString("<ol start=\"4\" style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\">\n<li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</li>\n<li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Bleh</li></ol>"); + } } void tst_QTextDocument::toHtml() @@ -1930,7 +1972,7 @@ void tst_QTextDocument::toHtmlBodyBgColor() doc.rootFrame()->setFrameFormat(fmt); QString expectedHtml = htmlHead; - expectedHtml.insert(htmlHead.length() - 2, " bgcolor=\"#0000ff\""); + expectedHtml.insert(htmlHead.size() - 2, " bgcolor=\"#0000ff\""); expectedHtml += "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>" + htmlTail; @@ -1950,7 +1992,7 @@ void tst_QTextDocument::toHtmlBodyBgColorRgba() doc.rootFrame()->setFrameFormat(fmt); QString expectedHtml = htmlHead; - expectedHtml.insert(htmlHead.length() - 2, " bgcolor=\"rgba(255,0,0,0.2)\""); + expectedHtml.insert(htmlHead.size() - 2, " bgcolor=\"rgba(255,0,0,0.2)\""); expectedHtml += "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>" + htmlTail; @@ -1970,7 +2012,7 @@ void tst_QTextDocument::toHtmlBodyBgColorTransparent() doc.rootFrame()->setFrameFormat(fmt); QString expectedHtml = htmlHead; - expectedHtml.insert(htmlHead.length() - 2, " bgcolor=\"transparent\""); + expectedHtml.insert(htmlHead.size() - 2, " bgcolor=\"transparent\""); expectedHtml += "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>" + htmlTail; @@ -2036,7 +2078,7 @@ void tst_QTextDocument::toHtmlDefaultFontSpacingProperties() doc.setDefaultFont(fnt); QString expectedOutput = htmlHead; - expectedOutput.insert(htmlHead.length() - 3, " letter-spacing:13px; word-spacing:15px;"); + expectedOutput.insert(htmlHead.size() - 3, " letter-spacing:13px; word-spacing:15px;"); expectedOutput += "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>" + htmlTail; @@ -2056,7 +2098,7 @@ void tst_QTextDocument::toHtmlTextDecorationUnderline() doc.setDefaultFont(fnt); QString expectedOutput = htmlHead; - expectedOutput.insert(htmlHead.length() - 3, " text-decoration: underline;"); + expectedOutput.insert(htmlHead.size() - 3, " text-decoration: underline;"); expectedOutput += "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Some text</p>" + htmlTail; @@ -2071,7 +2113,7 @@ void tst_QTextDocument::toHtmlTextDecorationUnderline() cursor.mergeCharFormat(format); expectedOutput = htmlHead; - expectedOutput.insert(htmlHead.length() - 3, " text-decoration: underline;"); + expectedOutput.insert(htmlHead.size() - 3, " text-decoration: underline;"); expectedOutput += "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; " "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" @@ -2725,11 +2767,11 @@ void tst_QTextDocument::defaultTableStyle() brushes << sideProperty.value<QBrush>(); } auto errorDetails = qScopeGuard([&]{ - if (brushes.count() != borderBrushes.count()) { - qWarning("Different count: %lld vs %lld", brushes.count(), borderBrushes.count()); + if (brushes.size() != borderBrushes.size()) { + qWarning("Different count: %lld vs %lld", brushes.size(), borderBrushes.size()); return; } - for (int i = 0; i < brushes.count(); ++i) { + for (int i = 0; i < brushes.size(); ++i) { QString side; QDebug(&side) << QTextFormat::Property(QTextFormat::TableCellTopBorderBrush + i); QString actual; @@ -2853,13 +2895,13 @@ void tst_QTextDocument::blockCountChanged() doc->setPlainText("Foo"); QCOMPARE(doc->blockCount(), 1); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); spy.clear(); doc->setPlainText("Foo\nBar"); QCOMPARE(doc->blockCount(), 2); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCOMPARE(spy.at(0).value(0).toInt(), 2); spy.clear(); @@ -2867,16 +2909,16 @@ void tst_QTextDocument::blockCountChanged() cursor.movePosition(QTextCursor::End); cursor.insertText("Blahblah"); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); cursor.insertBlock(); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCOMPARE(spy.at(0).value(0).toInt(), 3); spy.clear(); doc->undo(); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCOMPARE(spy.at(0).value(0).toInt(), 2); } @@ -3055,12 +3097,12 @@ void tst_QTextDocument::characterAt() QString text("12345\n67890"); cursor.insertText(text); int length = doc.characterCount(); - QCOMPARE(length, text.length() + 1); + QCOMPARE(length, text.size() + 1); QCOMPARE(doc.characterAt(length-1), QChar(QChar::ParagraphSeparator)); QCOMPARE(doc.characterAt(-1), QChar()); QCOMPARE(doc.characterAt(length), QChar()); QCOMPARE(doc.characterAt(length + 1), QChar()); - for (int i = 0; i < text.length(); ++i) { + for (int i = 0; i < text.size(); ++i) { QChar c = text.at(i); if (c == QLatin1Char('\n')) c = QChar(QChar::ParagraphSeparator); @@ -3140,11 +3182,11 @@ void tst_QTextDocument::testUndoCommandAdded() QVERIFY(spy.isEmpty()); cursor.insertText("a"); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); cursor.insertText("b"); // should be merged - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); cursor.insertText("c"); // should be merged - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCOMPARE(doc->toPlainText(), QString("abc")); doc->undo(); QCOMPARE(doc->toPlainText(), QString("")); @@ -3152,11 +3194,11 @@ void tst_QTextDocument::testUndoCommandAdded() doc->clear(); spy.clear(); cursor.insertText("aaa"); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); spy.clear(); cursor.insertText("aaaa\nbcd"); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); spy.clear(); cursor.beginEditBlock(); @@ -3166,11 +3208,11 @@ void tst_QTextDocument::testUndoCommandAdded() cursor.insertText("\nccc"); QVERIFY(spy.isEmpty()); cursor.endEditBlock(); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); spy.clear(); cursor.insertBlock(); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); spy.clear(); cursor.setPosition(5); @@ -3182,18 +3224,18 @@ void tst_QTextDocument::testUndoCommandAdded() QTextCharFormat cf; cf.setFontItalic(true); cursor.mergeCharFormat(cf); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); spy.clear(); doc->undo(); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); doc->undo(); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); spy.clear(); doc->redo(); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); doc->redo(); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); } void tst_QTextDocument::testUndoBlocks() @@ -3773,7 +3815,7 @@ void tst_QTextDocument::mergeFontFamilies() QTextCursor cursor = QTextCursor(&td); cursor.setPosition(0); - cursor.setPosition(QByteArray("Hello World").length(), QTextCursor::KeepAnchor); + cursor.setPosition(QByteArray("Hello World").size(), QTextCursor::KeepAnchor); cursor.mergeCharFormat(newFormat); QVERIFY(td.toHtml().contains(QLatin1String("font-family:'Jokerman';"))); @@ -3919,7 +3961,7 @@ void tst_QTextDocument::insertHtmlWithComments() QTextDocument doc; doc.setHtml(html); - QCOMPARE(doc.blockCount(), expectedBlocks.count()); + QCOMPARE(doc.blockCount(), expectedBlocks.size()); QStringList blockContent; auto currentBlock = doc.begin(); @@ -3931,5 +3973,277 @@ void tst_QTextDocument::insertHtmlWithComments() QCOMPARE(blockContent, expectedBlocks); } +void tst_QTextDocument::delayedLayout() +{ + QTextDocument doc; + doc.setHtml("<html>Foobar</html>"); + QCOMPARE(doc.blockCount(), 1); + + doc.setLayoutEnabled(false); + + // Force creation of a layout + QVERIFY(doc.documentLayout()); + + QTextBlock block = doc.begin(); + QTextLayout *layout = block.layout(); + QCOMPARE(layout->lineCount(), 0); // layout didn't happen yet + + doc.setLayoutEnabled(true); + QCOMPARE(layout->lineCount(), 1); // layout happened +} + +void tst_QTextDocument::undoContentChangeIndices() // QTBUG-113865 +{ + QTextDocument doc; + QTestDocumentLayout *layout = new QTestDocumentLayout(&doc); + QString content = QString("<html><body>" + "<ul><li>Undo</li></ul>" + "<ul><li>operation</li></ul>" + "<ul><li>of</li></ul>" + "<ul><li>unnumbered</li></ul>" + "<ul><li>lists</li></ul>" + "<ul><li>shows</li></ul>" + "<ul><li>invalid</li></ul>" + "<ul><li>content</li></ul>" + "<ul><li>indices</li></ul>" + "</body></html>"); + doc.setDocumentLayout(layout); + doc.setHtml(content); + + // Select the entire document content + QTextCursor cursor(&doc); + cursor.select(QTextCursor::Document); + cursor.removeSelectedText(); + + // Undo above operation + doc.undo(); + + // Move the cursor to the end + cursor.movePosition(QTextCursor::End); + cursor.insertHtml(content); + + // Select the whole document and remove the content + cursor.select(QTextCursor::Document); + cursor.removeSelectedText(); + + int documentLength = 0; + int changeRemoved = 0; + int changeAdded = 0; + int changePos = 0; + connect(&doc, &QTextDocument::contentsChange, this, [&](int pos, int removed, int added){ + documentLength = doc.characterCount(); + changeRemoved = removed; + changeAdded = added; + changePos = pos; + }); + + // Undo above operation + doc.undo(); + + const int changeEnd = changeAdded + changeRemoved; + + QVERIFY(documentLength > 0); + QCOMPARE(changePos, 0); + QVERIFY(changeRemoved >= 0); + QVERIFY(documentLength >= changeEnd); +} + +void tst_QTextDocument::restoreStrokeFromHtml() +{ + QTextDocument document; + QTextCursor textCursor(&document); + QTextCharFormat textOutline; + + // Set stroke color and width + { + QPen pen(Qt::red, 2.3, Qt::SolidLine); + textOutline.setTextOutline(pen); + textCursor.insertText("Outlined text", textOutline); + } + + // Set Cap and Join styles + { + QPen pen; + pen.setCapStyle(Qt::FlatCap); + pen.setJoinStyle(Qt::RoundJoin); + textOutline.setTextOutline(pen); + textCursor.insertBlock(); + textCursor.insertText("Cap and Join Style", textOutline); + } + + // Set Miter limit + { + QPen pen; + pen.setJoinStyle(Qt::MiterJoin); + pen.setMiterLimit(4); + textOutline.setTextOutline(pen); + textCursor.insertBlock(); + textCursor.insertText("Miter Limit", textOutline); + } + + // Set Dash Array and Dash Offset + { + QPen pen; + QList<qreal> pattern; + const int dash = 2; + const int gap = 4; + pattern << dash << gap << dash << gap << dash << gap; + pen.setDashPattern(pattern); + pen.setDashOffset(3); + textOutline.setTextOutline(pen); + textCursor.insertBlock(); + textCursor.insertText("Dash Pattern", textOutline); + } + + { + QTextDocument otherDocument; + otherDocument.setHtml(document.toHtml()); + QCOMPARE(otherDocument.blockCount(), document.blockCount()); + + QTextBlock block; + QTextFragment fragment; + QTextCharFormat fmt; + QPen pen; + + { + block = otherDocument.findBlockByNumber(0); + fragment = block.begin().fragment(); + QCOMPARE(fragment.text(), QStringLiteral("Outlined text")); + fmt = fragment.charFormat(); + QVERIFY(fmt.hasProperty(QTextCharFormat::TextOutline)); + pen = fmt.textOutline(); + QCOMPARE(pen.color(), QColor(Qt::red)); + QCOMPARE(pen.widthF(), 2.3); + } + + { + block = otherDocument.findBlockByNumber(1); + qDebug() << block.text(); + fragment = block.begin().fragment(); + QCOMPARE(fragment.text(), QStringLiteral("Cap and Join Style")); + fmt = fragment.charFormat(); + QVERIFY(fmt.hasProperty(QTextCharFormat::TextOutline)); + pen = fmt.textOutline(); + QCOMPARE(pen.capStyle(), Qt::FlatCap); + QCOMPARE(pen.joinStyle(), Qt::RoundJoin); + } + + { + block = otherDocument.findBlockByNumber(2); + fragment = block.begin().fragment(); + QCOMPARE(fragment.text(), QStringLiteral("Miter Limit")); + fmt = fragment.charFormat(); + QVERIFY(fmt.hasProperty(QTextCharFormat::TextOutline)); + pen = fmt.textOutline(); + QCOMPARE(pen.joinStyle(), Qt::MiterJoin); + QCOMPARE(pen.miterLimit(), 4); + } + + + { + block = otherDocument.findBlockByNumber(3); + fragment = block.begin().fragment(); + QCOMPARE(fragment.text(), QStringLiteral("Dash Pattern")); + fmt = fragment.charFormat(); + QVERIFY(fmt.hasProperty(QTextCharFormat::TextOutline)); + pen = fmt.textOutline(); + QCOMPARE(pen.dashOffset(), 3); + QList<qreal> pattern; + const int dash = 2; + const int gap = 4; + pattern << dash << gap << dash << gap << dash << gap; + QCOMPARE(pen.dashPattern(), pattern); + } + } +} + +void tst_QTextDocument::restoreForegroundGradientFromHtml() +{ + QTextDocument document; + + QTextCursor textCursor(&document); + + QTextCharFormat foregroundGradient; + QLinearGradient lg; + lg.setColorAt(0.0, Qt::green); + lg.setColorAt(1.0, Qt::blue); + lg.setStart(QPointF(0,0)); + lg.setFinalStop(QPointF(800, 1000)); + foregroundGradient.setForeground(QBrush(lg)); + textCursor.insertText("Linear gradient text\n", foregroundGradient); + + QRadialGradient rg; + rg.setCoordinateMode(QGradient::ObjectBoundingMode); + rg.setSpread(QGradient::ReflectSpread); + rg.setColorAt(0.0, Qt::green); + rg.setColorAt(1.0, Qt::blue); + QPointF center(0.5, 0.5); + rg.setCenter(center); + rg.setFocalPoint(center); + rg.setRadius(0.5); + foregroundGradient.setForeground(QBrush(rg)); + textCursor.insertText("Radial gradient text\n", foregroundGradient); + + QConicalGradient cg; + cg.setCoordinateMode(QGradient::ObjectMode); + cg.setSpread(QGradient::RepeatSpread); + cg.setColorAt(0.0, Qt::green); + cg.setColorAt(1.0, Qt::blue); + cg.setCenter(QPointF(0.5, 0.5)); + cg.setAngle(0.0); + foregroundGradient.setForeground(QBrush(cg)); + textCursor.insertText("Conical gradient text\n", foregroundGradient); + + { + QTextDocument otherDocument; + otherDocument.setHtml(document.toHtml()); + + QCOMPARE(otherDocument.blockCount(), document.blockCount()); + + QTextBlock block = otherDocument.firstBlock(); + QTextFragment fragment = block.begin().fragment(); + + QCOMPARE(fragment.text(), QStringLiteral("Linear gradient text")); + + QTextCharFormat fmt = fragment.charFormat(); + QVERIFY(fmt.hasProperty(QTextCharFormat::ForegroundBrush)); + + QBrush brush = fmt.foreground(); + QCOMPARE(brush.style(), Qt::LinearGradientPattern); + QCOMPARE(brush.gradient()->coordinateMode(), lg.coordinateMode()); + QCOMPARE(brush.gradient()->spread(), lg.spread()); + QCOMPARE(brush.gradient()->stops().size(), lg.stops().size()); + QCOMPARE(static_cast<const QLinearGradient *>(brush.gradient())->start(), lg.start()); + QCOMPARE(static_cast<const QLinearGradient *>(brush.gradient())->finalStop(), lg.finalStop()); + + block = block.next(); + fragment = block.begin().fragment(); + + fmt = fragment.charFormat(); + QVERIFY(fmt.hasProperty(QTextCharFormat::ForegroundBrush)); + + brush = fmt.foreground(); + QCOMPARE(brush.style(), Qt::RadialGradientPattern); + QCOMPARE(brush.gradient()->coordinateMode(), rg.coordinateMode()); + QCOMPARE(brush.gradient()->spread(), rg.spread()); + QCOMPARE(static_cast<const QRadialGradient *>(brush.gradient())->center(), rg.center()); + QCOMPARE(static_cast<const QRadialGradient *>(brush.gradient())->focalPoint(), rg.focalPoint()); + QCOMPARE(static_cast<const QRadialGradient *>(brush.gradient())->radius(), rg.radius()); + + block = block.next(); + fragment = block.begin().fragment(); + + fmt = fragment.charFormat(); + QVERIFY(fmt.hasProperty(QTextCharFormat::ForegroundBrush)); + + brush = fmt.foreground(); + QCOMPARE(brush.style(), Qt::ConicalGradientPattern); + QCOMPARE(brush.gradient()->coordinateMode(), cg.coordinateMode()); + QCOMPARE(brush.gradient()->spread(), cg.spread()); + QCOMPARE(static_cast<const QConicalGradient *>(brush.gradient())->center(), cg.center()); + QCOMPARE(static_cast<const QConicalGradient *>(brush.gradient())->angle(), cg.angle()); + } +} + QTEST_MAIN(tst_QTextDocument) #include "tst_qtextdocument.moc" diff --git a/tests/auto/gui/text/qtextdocumentfragment/CMakeLists.txt b/tests/auto/gui/text/qtextdocumentfragment/CMakeLists.txt index 6f1207c49a..4a4075106e 100644 --- a/tests/auto/gui/text/qtextdocumentfragment/CMakeLists.txt +++ b/tests/auto/gui/text/qtextdocumentfragment/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qtextdocumentfragment.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtextdocumentfragment Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtextdocumentfragment LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtextdocumentfragment SOURCES tst_qtextdocumentfragment.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp index 52708e1b14..f2c3b36dcd 100644 --- a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp +++ b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -16,6 +16,8 @@ #include <qtextcursor.h> +using namespace Qt::StringLiterals; + QT_FORWARD_DECLARE_CLASS(QTextDocument) class tst_QTextDocumentFragment : public QObject @@ -96,6 +98,7 @@ private slots: void html_thCentered(); void orderedListNumbering(); void html_blockAfterList(); + void html_listStartAttribute(); void html_subAndSuperScript(); void html_cssColors(); void obeyFragmentMarkersInImport(); @@ -244,6 +247,7 @@ private slots: void html_fromFirefox(); void html_emptyInlineInsideBlock(); void css_fontAndWordSpacing(); + void html_brWithWhitespaceAfterList(); private: inline void setHtml(const QString &html) @@ -1175,7 +1179,7 @@ void tst_QTextDocumentFragment::copySubTable() table->cellAt(row, col).firstCursorPosition().insertText(rowS + QString::number(col)); } - QCOMPARE(table->format().columnWidthConstraints().count(), table->columns()); + QCOMPARE(table->format().columnWidthConstraints().size(), table->columns()); // select 2x2 subtable cursor = table->cellAt(1, 1).firstCursorPosition(); @@ -1471,6 +1475,22 @@ void tst_QTextDocumentFragment::html_blockAfterList() QCOMPARE(cursor.blockFormat().indent(), 0); } +void tst_QTextDocumentFragment::html_listStartAttribute() +{ + const char html[] = "<ol start=-1><li>Foo</ol><ol><li>Bar</ol>"; + cursor.insertFragment(QTextDocumentFragment::fromHtml(html)); + + cursor.movePosition(QTextCursor::Start); + + QVERIFY(cursor.currentList()); + QCOMPARE(cursor.currentList()->format().start(), -1); + + QVERIFY(cursor.movePosition(QTextCursor::NextBlock)); + + QVERIFY(cursor.currentList()); + QCOMPARE(cursor.currentList()->format().start(), 1); +} + void tst_QTextDocumentFragment::html_subAndSuperScript() { const char subHtml[] = "<sub>Subby</sub>"; @@ -2235,7 +2255,7 @@ void tst_QTextDocumentFragment::html_frameImport() cursor.insertFragment(frag); QList<QTextFrame *> childFrames = doc->rootFrame()->childFrames(); - QCOMPARE(childFrames.count(), 1); + QCOMPARE(childFrames.size(), 1); QTextFrame *frame = childFrames.first(); QCOMPARE(frame->frameFormat().margin(), ffmt.margin()); QCOMPARE(frame->frameFormat().border(), ffmt.border()); @@ -2263,7 +2283,7 @@ void tst_QTextDocumentFragment::html_frameImport2() cursor.insertFragment(frag); QList<QTextFrame *> childFrames = doc->rootFrame()->childFrames(); - QCOMPARE(childFrames.count(), 1); + QCOMPARE(childFrames.size(), 1); QTextFrame *frame = childFrames.first(); QCOMPARE(frame->frameFormat().topMargin(), ffmt.topMargin()); QCOMPARE(frame->frameFormat().bottomMargin(), ffmt.bottomMargin()); @@ -2278,7 +2298,7 @@ void tst_QTextDocumentFragment::html_dontAddMarginsAcrossTableCells() cursor.insertFragment(QTextDocumentFragment::fromHtml(QString::fromLatin1(html))); QList<QTextFrame *> childFrames = doc->rootFrame()->childFrames(); - QCOMPARE(childFrames.count(), 1); + QCOMPARE(childFrames.size(), 1); QTextFrame *frame = childFrames.first(); cursor = frame->firstCursorPosition(); QCOMPARE(cursor.blockFormat().leftMargin(), qreal(50.0)); @@ -2760,7 +2780,7 @@ void tst_QTextDocumentFragment::html_columnWidths() QTextTableFormat fmt = table->format(); const QList<QTextLength> columnWidths = fmt.columnWidthConstraints(); - QCOMPARE(columnWidths.count(), 2); + QCOMPARE(columnWidths.size(), 2); QCOMPARE(columnWidths.at(0).type(), QTextLength::VariableLength); QCOMPARE(columnWidths.at(1).type(), QTextLength::PercentageLength); QCOMPARE(columnWidths.at(1).rawValue(), qreal(1)); @@ -4168,7 +4188,7 @@ void tst_QTextDocumentFragment::html_entities() setHtml(html); QCOMPARE(doc->blockCount(), 1); QString txt = doc->begin().text(); - QCOMPARE(txt.length(), 1); + QCOMPARE(txt.size(), 1); QCOMPARE(txt.at(0).unicode(), code); } @@ -4303,5 +4323,24 @@ void tst_QTextDocumentFragment::css_fontAndWordSpacing() } } +void tst_QTextDocumentFragment::html_brWithWhitespaceAfterList() // QTBUG-81662 +{ + setHtml(QString::fromLatin1("<ul><li>one</li><li>two</li></ul>\n <br/>\nhello")); + + QCOMPARE(doc->blockCount(), 3); + + QTextBlock block = doc->begin(); + QVERIFY(block.textList()); + + block = block.next(); + QVERIFY(block.textList()); + + block = block.next(); + QCOMPARE(block.text(), u"\u2028hello"_s); + + block = block.next(); + QVERIFY(block.text().isEmpty()); +} + QTEST_MAIN(tst_QTextDocumentFragment) #include "tst_qtextdocumentfragment.moc" diff --git a/tests/auto/gui/text/qtextdocumentlayout/BLACKLIST b/tests/auto/gui/text/qtextdocumentlayout/BLACKLIST index 5a2f81c448..ed85376c92 100644 --- a/tests/auto/gui/text/qtextdocumentlayout/BLACKLIST +++ b/tests/auto/gui/text/qtextdocumentlayout/BLACKLIST @@ -1,6 +1,3 @@ [imageAtRightAlignedTab] -rhel-6.6 -rhel-7.4 -rhel-7.6 sles centos diff --git a/tests/auto/gui/text/qtextdocumentlayout/CMakeLists.txt b/tests/auto/gui/text/qtextdocumentlayout/CMakeLists.txt index da41073962..07386d4e24 100644 --- a/tests/auto/gui/text/qtextdocumentlayout/CMakeLists.txt +++ b/tests/auto/gui/text/qtextdocumentlayout/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qtextdocumentlayout.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtextdocumentlayout Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtextdocumentlayout LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtextdocumentlayout SOURCES tst_qtextdocumentlayout.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) @@ -15,6 +22,6 @@ qt_internal_add_test(tst_qtextdocumentlayout ##################################################################### qt_internal_extend_target(tst_qtextdocumentlayout CONDITION TARGET Qt::Widgets - PUBLIC_LIBRARIES + LIBRARIES Qt::Widgets ) diff --git a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp index 01c4005bfe..2ae31849bf 100644 --- a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp +++ b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -24,17 +24,24 @@ private slots: void cleanupTestCase(); void defaultPageSizeHandling(); void idealWidth(); +#ifndef QT_NO_TEXTHTMLPARSER void lineSeparatorFollowingTable(); +#endif #ifndef QT_NO_WIDGETS void wrapAtWordBoundaryOrAnywhere(); #endif void inlineImage(); +#ifndef QT_NO_TEXTHTMLPARSER void clippedTableCell(); +#endif void floatingTablePageBreak(); void imageAtRightAlignedTab(); void blockVisibility(); +#ifndef QT_NO_TEXTHTMLPARSER + void testHitTest(); void largeImage(); +#endif private: QTextDocument *doc; @@ -98,6 +105,7 @@ void tst_QTextDocumentLayout::idealWidth() QVERIFY(doc->idealWidth() > 0); } +#ifndef QT_NO_TEXTHTMLPARSER // none of the QTextLine items in the document should intersect with the margin rect void tst_QTextDocumentLayout::lineSeparatorFollowingTable() { @@ -144,6 +152,7 @@ void tst_QTextDocumentLayout::lineSeparatorFollowingTable() } } } +#endif #ifndef QT_NO_WIDGETS void tst_QTextDocumentLayout::wrapAtWordBoundaryOrAnywhere() @@ -183,6 +192,7 @@ void tst_QTextDocumentLayout::inlineImage() QCOMPARE(doc->pageCount(), 1); } +#ifndef QT_NO_TEXTHTMLPARSER void tst_QTextDocumentLayout::clippedTableCell() { const char *html = @@ -223,6 +233,7 @@ void tst_QTextDocumentLayout::clippedTableCell() expected.save("expected.png"); QCOMPARE(img, expected); } +#endif void tst_QTextDocumentLayout::floatingTablePageBreak() { @@ -322,6 +333,7 @@ void tst_QTextDocumentLayout::blockVisibility() QCOMPARE(doc->size(), halfSize); } +#ifndef QT_NO_TEXTHTMLPARSER void tst_QTextDocumentLayout::largeImage() { auto img = QImage(400, 500, QImage::Format_ARGB32_Premultiplied); @@ -380,5 +392,42 @@ void tst_QTextDocumentLayout::largeImage() } } +void tst_QTextDocumentLayout::testHitTest() +{ + QTextDocument document; + QTextCursor cur(&document); + int topMargin = 20; + + //insert 500 blocks into textedit + for (int i = 0; i < 500; i++) { + cur.insertBlock(); + cur.insertHtml(QString("block %1").arg(i)); + } + + //randomly set half the blocks invisible + QTextBlock blk=document.begin(); + for (int i = 0; i < 500; i++) { + if (i % 7) + blk.setVisible(0); + blk = blk.next(); + } + + //set margin for all blocks (not strictly necessary, but makes easier to click in between blocks) + QTextBlockFormat blkfmt; + blkfmt.setTopMargin(topMargin); + cur.movePosition(QTextCursor::Start); + cur.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); + cur.mergeBlockFormat(blkfmt); + + for (int y = cur.selectionStart(); y < cur.selectionEnd(); y += 10) { + QPoint mousePoint(1, y); + int cursorPos = document.documentLayout()->hitTest(mousePoint, Qt::FuzzyHit); + int positionY = document.findBlock(cursorPos).layout()->position().toPoint().y(); + //mousePoint is in the rect of the current Block + QVERIFY(positionY - topMargin <= y); + } +} +#endif + QTEST_MAIN(tst_QTextDocumentLayout) #include "tst_qtextdocumentlayout.moc" diff --git a/tests/auto/gui/text/qtextformat/CMakeLists.txt b/tests/auto/gui/text/qtextformat/CMakeLists.txt index cacd7fbd18..4dea90900e 100644 --- a/tests/auto/gui/text/qtextformat/CMakeLists.txt +++ b/tests/auto/gui/text/qtextformat/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qtextformat.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtextformat Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtextformat LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtextformat SOURCES tst_qtextformat.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp index a998bbd482..6c6145561d 100644 --- a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp +++ b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -7,7 +7,9 @@ #include <qcoreapplication.h> #include <qdebug.h> +#if QT_CONFIG(settings) #include <qsettings.h> +#endif #include <qtextformat.h> #include <private/qtextformat_p.h> #include <qtextdocument.h> @@ -27,7 +29,9 @@ Q_OBJECT private slots: void getSetCheck(); void defaultAlignment(); +#if QT_CONFIG(settings) void testQTextCharFormat() const; +#endif void testUnderlinePropertyPrecedence(); void toFormat(); void resolveFont(); @@ -47,6 +51,7 @@ private slots: #endif }; +#if QT_CONFIG(settings) /*! \internal This (used to) trigger a crash in: @@ -61,6 +66,7 @@ void tst_QTextFormat::testQTextCharFormat() const settings.value("test", test); } +#endif // Testing get/set functions void tst_QTextFormat::getSetCheck() @@ -187,7 +193,7 @@ void tst_QTextFormat::resolveFont() QTextCursor(&doc).insertText("Test", fmt); QList<QTextFormat> formats = doc.allFormats(); - QCOMPARE(formats.count(), 3); + QCOMPARE(formats.size(), 3); QCOMPARE(formats.at(2).type(), int(QTextFormat::CharFormat)); fmt = formats.at(2).toCharFormat(); @@ -312,8 +318,8 @@ void tst_QTextFormat::getSetTabs() public: Comparator(const QList<QTextOption::Tab> &tabs, const QList<QTextOption::Tab> &tabs2) { - QCOMPARE(tabs.count(), tabs2.count()); - for(int i=0; i < tabs.count(); i++) { + QCOMPARE(tabs.size(), tabs2.size()); + for(int i=0; i < tabs.size(); i++) { QTextOption::Tab t1 = tabs[i]; QTextOption::Tab t2 = tabs2[i]; QCOMPARE(t1.position, t2.position); @@ -364,7 +370,7 @@ void tst_QTextFormat::testTabsUsed() QCOMPARE(line.cursorToX(4), 100.); QTextOption option = layout->textOption(); - QCOMPARE(option.tabs().count(), tabs.count()); + QCOMPARE(option.tabs().size(), tabs.size()); } @@ -648,16 +654,16 @@ void tst_QTextFormat::clearCollection() charFormat2.setUnderlineStyle(QTextCharFormat::SingleUnderline); int formatIndex2 = collection.indexForFormat(charFormat2); QCOMPARE(formatIndex2, 1); - QCOMPARE(collection.formats.count(), 2); - QCOMPARE(collection.hashes.count(), 2); + QCOMPARE(collection.formats.size(), 2); + QCOMPARE(collection.hashes.size(), 2); QCOMPARE(collection.defaultFont(), f); collection.clear(); - QCOMPARE(collection.formats.count(), 0); - QCOMPARE(collection.hashes.count(), 0); + QCOMPARE(collection.formats.size(), 0); + QCOMPARE(collection.hashes.size(), 0); QCOMPARE(collection.indexForFormat(charFormat2), 0); - QCOMPARE(collection.formats.count(), 1); - QCOMPARE(collection.hashes.count(), 1); + QCOMPARE(collection.formats.size(), 1); + QCOMPARE(collection.hashes.size(), 1); QCOMPARE(collection.defaultFont(), f); // kept, QTextDocument::clear or setPlainText should not reset the font set by setDefaultFont } @@ -679,7 +685,7 @@ void tst_QTextFormat::dataStreamCompatibility() QVERIFY(properties.contains(QTextFormat::FontFamilies)); QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType)); QVERIFY(!properties.contains(QTextFormat::OldFontStretch)); - QVERIFY(!properties.contains(QTextFormat::FontFamily)); + QVERIFY(!properties.contains(QTextFormat::OldFontFamily)); } QByteArray memory; @@ -710,7 +716,7 @@ void tst_QTextFormat::dataStreamCompatibility() QVERIFY(properties.contains(QTextFormat::FontFamilies)); QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType)); QVERIFY(!properties.contains(QTextFormat::OldFontStretch)); - QVERIFY(!properties.contains(QTextFormat::FontFamily)); + QVERIFY(!properties.contains(QTextFormat::OldFontFamily)); } } @@ -730,7 +736,7 @@ void tst_QTextFormat::dataStreamCompatibility() QVERIFY(properties.contains(QTextFormat::FontFamilies)); QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType)); QVERIFY(!properties.contains(QTextFormat::OldFontStretch)); - QVERIFY(!properties.contains(QTextFormat::FontFamily)); + QVERIFY(!properties.contains(QTextFormat::OldFontFamily)); } } @@ -763,7 +769,7 @@ void tst_QTextFormat::dataStreamCompatibility() QVERIFY(properties.contains(QTextFormat::FontFamilies)); QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType)); QVERIFY(!properties.contains(QTextFormat::OldFontStretch)); - QVERIFY(!properties.contains(QTextFormat::FontFamily)); + QVERIFY(!properties.contains(QTextFormat::OldFontFamily)); } } @@ -785,7 +791,7 @@ void tst_QTextFormat::dataStreamCompatibility() QVERIFY(!properties.contains(QTextFormat::FontFamilies)); QVERIFY(properties.contains(QTextFormat::OldFontLetterSpacingType)); QVERIFY(properties.contains(QTextFormat::OldFontStretch)); - QVERIFY(properties.contains(QTextFormat::FontFamily)); + QVERIFY(properties.contains(QTextFormat::OldFontFamily)); } } diff --git a/tests/auto/gui/text/qtextimagehandler/CMakeLists.txt b/tests/auto/gui/text/qtextimagehandler/CMakeLists.txt new file mode 100644 index 0000000000..8d282b8f2c --- /dev/null +++ b/tests/auto/gui/text/qtextimagehandler/CMakeLists.txt @@ -0,0 +1,29 @@ +# 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_qtextimagehandler LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +list(APPEND test_data "data/image.png") +list(APPEND test_data "data/image@2x.png") + +qt_internal_add_test(tst_qtextimagehandler + SOURCES + tst_qtextimagehandler.cpp + LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + TESTDATA + ${test_data} +) + +qt_internal_add_resource(tst_qtextimagehandler "qtextimagehandler" + PREFIX + "/" + FILES + ${test_data} +) diff --git a/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp b/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp index a1d9b2c6cf..0048623d0e 100644 --- a/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp +++ b/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp @@ -1,11 +1,15 @@ -// Copyright (C) 2020 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QPainter> #include <private/qtextimagehandler_p.h> +using namespace Qt::StringLiterals; + +// #define DEBUG_WRITE_HTML + class tst_QTextImageHandler : public QObject { Q_OBJECT @@ -17,7 +21,12 @@ private slots: void init(); void cleanup(); void cleanupTestCase(); + void loadAtNImages_data(); +#ifndef QT_NO_TEXTHTMLPARSER void loadAtNImages(); + void maxWidth_data(); + void maxWidth(); +#endif }; tst_QTextImageHandler::tst_QTextImageHandler() @@ -36,27 +45,103 @@ void tst_QTextImageHandler::cleanupTestCase() { } +void tst_QTextImageHandler::loadAtNImages_data() +{ + QTest::addColumn<QString>("imageFile"); + + QTest::addRow("file") << QFINDTESTDATA("data/image.png"); + QTest::addRow("file_url") << QUrl::fromLocalFile(QFINDTESTDATA("data/image.png")).toString(); + QTest::addRow("resource") << ":/data/image.png"; + QTest::addRow("qrc_url") << "qrc:/data/image.png"; +} + +#ifndef QT_NO_TEXTHTMLPARSER void tst_QTextImageHandler::loadAtNImages() { + QFETCH(QString, imageFile); + QTextDocument doc; QTextCursor c(&doc); - c.insertHtml("<img src=\"data/image.png\">"); + c.insertHtml("<img src=\"" + imageFile + "\">"); + const auto formats = doc.allFormats(); + const auto it = std::find_if(formats.begin(), formats.end(), [](const auto &format){ + return format.objectType() == QTextFormat::ImageObject; + }); + QCOMPARE_NE(it, formats.end()); + const QTextImageFormat format = (*it).toImageFormat(); QTextImageHandler handler; - QTextImageFormat fmt; - fmt.setName("data/image.png"); - for (int i = 1; i < 3; ++i) { + for (const auto &dpr : {1, 2}) { QImage img(20, 20, QImage::Format_ARGB32_Premultiplied); img.fill(Qt::white); - img.setDevicePixelRatio(i); + img.setDevicePixelRatio(dpr); QPainter p(&img); - handler.drawObject(&p, QRect(0, 0, 20, 20), &doc, 0, fmt); + handler.drawObject(&p, QRect(0, 0, 20, 20), &doc, 0, format); p.end(); QVERIFY(!img.isNull()); - const auto expectedColor = i == 1 ? Qt::red : Qt::green; + const auto expectedColor = dpr == 1 ? Qt::red : Qt::green; QCOMPARE(img.pixelColor(0, 0), expectedColor); } } +void tst_QTextImageHandler::maxWidth_data() +{ + QTest::addColumn<QString>("imageFile"); + QTest::addColumn<QSizeF>("pageSize"); + QTest::addColumn<QTextLength>("maxWidth"); + QTest::addColumn<QSizeF>("expectedSize"); + + QTest::addRow("constrained-percentage") << QFINDTESTDATA("data/image.png") << QSizeF(16, 16) << QTextLength(QTextLength::PercentageLength, 100) << QSizeF(12, 12); + QTest::addRow("not-constrained-percentage") << QFINDTESTDATA("data/image.png") << QSizeF(200, 200) << QTextLength(QTextLength::PercentageLength, 100) << QSizeF(16, 16); + QTest::addRow("constrained-fixed") << QFINDTESTDATA("data/image.png") << QSizeF(16, 16) << QTextLength(QTextLength::FixedLength, 5) << QSizeF(5, 5); + QTest::addRow("not-constrained-fixed") << QFINDTESTDATA("data/image.png") << QSizeF(200, 200) << QTextLength(QTextLength::FixedLength, 5) << QSizeF(5, 5); + QTest::addRow("not-constrained-default") << QFINDTESTDATA("data/image.png") << QSizeF(200, 200) << QTextLength(QTextLength::VariableLength, 5) << QSizeF(16, 16); +} + +void tst_QTextImageHandler::maxWidth() +{ + QFETCH(QString, imageFile); + QFETCH(QSizeF, pageSize); + QFETCH(QTextLength, maxWidth); + QFETCH(QSizeF, expectedSize); + + QTextDocument doc; + doc.setPageSize(pageSize); + doc.setDocumentMargin(2); + QTextCursor c(&doc); + QString style; + if (maxWidth.type() == QTextLength::PercentageLength) + style = " style=\"max-width:"_L1 + QString::number(maxWidth.rawValue()) + "%;\""_L1; + else if (maxWidth.type() == QTextLength::FixedLength) + style = " style=\"max-width:"_L1 + QString::number(maxWidth.rawValue()) + "px;\""_L1; + const QString html = "<img src=\"" + imageFile + u'\"' + style + "\">"; + c.insertHtml(html); + +#ifdef DEBUG_WRITE_HTML + { + QFile out("/tmp/" + QLatin1String(QTest::currentDataTag()) + ".html"); + out.open(QFile::WriteOnly); + out.write(html.toLatin1()); + out.close(); + } + { + QFile out("/tmp/" + QLatin1String(QTest::currentDataTag()) + "_rewrite.html"); + out.open(QFile::WriteOnly); + out.write(doc.toHtml().toLatin1()); + out.close(); + } +#endif + const auto formats = doc.allFormats(); + const auto it = std::find_if(formats.begin(), formats.end(), [](const auto &format){ + return format.objectType() == QTextFormat::ImageObject; + }); + QCOMPARE_NE(it, formats.end()); + const QTextImageFormat format = (*it).toImageFormat(); + QTextImageHandler handler; + + QCOMPARE(handler.intrinsicSize(&doc, 0, format), expectedSize); +} +#endif + QTEST_MAIN(tst_QTextImageHandler) #include "tst_qtextimagehandler.moc" diff --git a/tests/auto/gui/text/qtextlayout/CMakeLists.txt b/tests/auto/gui/text/qtextlayout/CMakeLists.txt index 3fb5dea8b9..655c0985a0 100644 --- a/tests/auto/gui/text/qtextlayout/CMakeLists.txt +++ b/tests/auto/gui/text/qtextlayout/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qtextlayout.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtextlayout Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtextlayout LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtextlayout SOURCES tst_qtextlayout.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp index def7c88593..209f5a56e2 100644 --- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp @@ -1,6 +1,7 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only +#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses /* !!!!!! Warning !!!!! @@ -124,7 +125,9 @@ private slots: void tooManyDirectionalCharctersCrash_qtbug77819(); void softHyphens_data(); void softHyphens(); + void min_maximumWidth_data(); void min_maximumWidth(); + void negativeLineWidth(); private: QFont testFont; @@ -289,14 +292,14 @@ void tst_QTextLayout::simpleBoundingRect() QString hello("hello world"); - const int width = hello.length() * testFont.pixelSize(); + const int width = hello.size() * testFont.pixelSize(); QTextLayout layout(hello, testFont); layout.beginLayout(); QTextLine line = layout.createLine(); line.setLineWidth(width); - QCOMPARE(line.textLength(), hello.length()); + QCOMPARE(line.textLength(), hello.size()); QCOMPARE(layout.boundingRect(), QRectF(0, 0, width, QFontMetrics(testFont).height())); } @@ -331,18 +334,18 @@ void tst_QTextLayout::threeLineBoundingRect() QString thirdWord("world"); QString text(firstWord + wordBoundary1 + secondWord + wordBoundary2 + thirdWord); - int firstLineWidth = firstWord.length() * testFont.pixelSize(); - int secondLineWidth = secondWord.length() * testFont.pixelSize(); - int thirdLineWidth = thirdWord.length() * testFont.pixelSize(); + int firstLineWidth = firstWord.size() * testFont.pixelSize(); + int secondLineWidth = secondWord.size() * testFont.pixelSize(); + int thirdLineWidth = thirdWord.size() * testFont.pixelSize(); // Trailing spaces do not count to line width: if (!wordBoundary1.isSpace()) firstLineWidth += testFont.pixelSize(); if (!wordBoundary2.isSpace()) secondLineWidth += testFont.pixelSize(); // But trailing spaces do count to line length: - const int firstLineLength = firstWord.length() + 1; - const int secondLineLength = secondWord.length() + 1; - const int thirdLineLength = thirdWord.length(); + const int firstLineLength = firstWord.size() + 1; + const int secondLineLength = secondWord.size() + 1; + const int thirdLineLength = thirdWord.size(); const int longestLine = qMax(firstLineWidth, qMax(secondLineWidth, thirdLineWidth)); @@ -386,7 +389,7 @@ void tst_QTextLayout::boundingRectWithLongLineAndNoWrap() { QString longString("thisisaverylongstringthatcannotbewrappedatallitjustgoesonandonlikeonebigword"); - const int width = longString.length() * testFont.pixelSize() / 20; // very small widthx + const int width = longString.size() * testFont.pixelSize() / 20; // very small widthx QTextLayout layout(longString, testFont); layout.beginLayout(); @@ -511,18 +514,24 @@ void tst_QTextLayout::noWrap() void tst_QTextLayout::cursorToXForInlineObjects() { - QChar ch(QChar::ObjectReplacementCharacter); - QString text(ch); - QTextLayout layout(text, testFont); - layout.beginLayout(); + QString text = QStringLiteral("<html><body><img src=\"\" width=\"32\" height=\"32\" /></body></html>"); - QTextEngine *engine = layout.engine(); - const int item = engine->findItem(0); - engine->layoutData->items[item].width = 32; + QTextDocument document; + document.setHtml(text); + QCOMPARE(document.blockCount(), 1); - QTextLine line = layout.createLine(); - line.setLineWidth(0x10000); + // Trigger layout + { + QImage img(1, 1, QImage::Format_ARGB32_Premultiplied); + QPainter p(&img); + document.drawContents(&p); + } + QTextLayout *layout = document.firstBlock().layout(); + QVERIFY(layout != nullptr); + QCOMPARE(layout->lineCount(), 1); + + QTextLine line = layout->lineAt(0); QCOMPARE(line.cursorToX(0), qreal(0)); QCOMPARE(line.cursorToX(1), qreal(32)); } @@ -720,29 +729,29 @@ void tst_QTextLayout::cursorToXForBidiBoundaries_data() QTest::addColumn<Qt::LayoutDirection>("textDirection"); QTest::addColumn<QString>("text"); QTest::addColumn<int>("cursorPosition"); - QTest::addColumn<int>("expectedX"); + QTest::addColumn<int>("runsToInclude"); QTest::addRow("LTR, abcشزذabc, 0") << Qt::LeftToRight << "abcشزذabc" << 0 << 0; QTest::addRow("RTL, abcشزذabc, 9") << Qt::RightToLeft << "abcشزذabc" - << 9 << TESTFONT_SIZE * 3; + << 9 << 1; QTest::addRow("LTR, abcشزذabc, 3") << Qt::LeftToRight << "abcشزذabc" << 0 << 0; QTest::addRow("RTL, abcشزذabc, 6") << Qt::RightToLeft << "abcشزذabc" - << 9 << TESTFONT_SIZE * 3; + << 9 << 1; QTest::addRow("LTR, شزذabcشزذ, 0") << Qt::LeftToRight << "شزذabcشزذ" - << 0 << TESTFONT_SIZE * 2; + << 0 << 1; QTest::addRow("RTL, شزذabcشزذ, 9") << Qt::RightToLeft << "شزذabcشزذ" << 9 << 0; QTest::addRow("LTR, شزذabcشزذ, 3") << Qt::LeftToRight << "شزذabcشزذ" - << 3 << TESTFONT_SIZE * 2; + << 3 << 1; QTest::addRow("RTL, شزذabcشزذ, 3") << Qt::RightToLeft << "شزذabcشزذ" - << 3 << TESTFONT_SIZE * 5; + << 3 << 2; QTest::addRow("LTR, شزذabcشزذ, 6") << Qt::LeftToRight << "شزذabcشزذ" - << 6 << TESTFONT_SIZE * 5; + << 6 << 2; QTest::addRow("RTL, شزذabcشزذ, 6") << Qt::RightToLeft << "شزذabcشزذ" - << 6 << TESTFONT_SIZE * 2; + << 6 << 1; } void tst_QTextLayout::cursorToXForBidiBoundaries() @@ -750,7 +759,7 @@ void tst_QTextLayout::cursorToXForBidiBoundaries() QFETCH(Qt::LayoutDirection, textDirection); QFETCH(QString, text); QFETCH(int, cursorPosition); - QFETCH(int, expectedX); + QFETCH(int, runsToInclude); QTextOption option; option.setTextDirection(textDirection); @@ -759,12 +768,30 @@ void tst_QTextLayout::cursorToXForBidiBoundaries() layout.setTextOption(option); layout.beginLayout(); - QTextLine line = layout.createLine(); - line.setLineWidth(0x10000); + { + QTextLine line = layout.createLine(); + line.setLineWidth(0x10000); + } + layout.endLayout(); - QCOMPARE(line.cursorToX(cursorPosition), expectedX); + QTextLine line = layout.lineAt(0); + QList<QGlyphRun> glyphRuns = line.glyphRuns(-1, + -1, + QTextLayout::RetrieveStringIndexes + | QTextLayout::RetrieveGlyphIndexes); + QVERIFY(runsToInclude <= glyphRuns.size()); + + std::sort(glyphRuns.begin(), glyphRuns.end(), + [](const QGlyphRun &first, const QGlyphRun &second) { + return first.stringIndexes().first() < second.stringIndexes().first(); + }); + + qreal expectedX = 0.0; + for (int i = 0; i < runsToInclude; ++i) { + expectedX += glyphRuns.at(i).boundingRect().width(); + } - layout.endLayout(); + QCOMPARE(line.cursorToX(cursorPosition), expectedX); } void tst_QTextLayout::horizontalAlignment_data() @@ -1139,7 +1166,7 @@ void tst_QTextLayout::xToCursorAtEndOfLine() QString text = "FirstLine SecondLine"; text.replace('\n', QChar::LineSeparator); - const qreal firstLineWidth = QString("FirstLine").length() * testFont.pixelSize(); + const qreal firstLineWidth = QString("FirstLine").size() * testFont.pixelSize(); QTextLayout layout(text, testFont); layout.setCacheEnabled(true); @@ -1282,7 +1309,7 @@ void tst_QTextLayout::integerOverflow() QVERIFY(line.isValid()); line.setLineWidth(INT_MAX); - QCOMPARE(line.textLength(), txt.length()); + QCOMPARE(line.textLength(), txt.size()); QVERIFY(!layout.createLine().isValid()); @@ -1857,7 +1884,7 @@ void tst_QTextLayout::capitalization_allUpperCase() QTextEngine *engine = layout.engine(); engine->itemize(); - QCOMPARE(engine->layoutData->items.count(), 1); + QCOMPARE(engine->layoutData->items.size(), 1); QCOMPARE(engine->layoutData->items.at(0).analysis.flags, ushort(QScriptAnalysis::Uppercase)); } @@ -1877,7 +1904,7 @@ void tst_QTextLayout::capitalization_allUpperCase_newline() QTextEngine *engine = layout.engine(); engine->itemize(); - QCOMPARE(engine->layoutData->items.count(), 3); + QCOMPARE(engine->layoutData->items.size(), 3); QCOMPARE(engine->layoutData->items.at(0).analysis.flags, ushort(QScriptAnalysis::Uppercase)); QCOMPARE(engine->layoutData->items.at(1).analysis.flags, ushort(QScriptAnalysis::LineOrParagraphSeparator)); QCOMPARE(engine->layoutData->items.at(2).analysis.flags, ushort(QScriptAnalysis::Uppercase)); @@ -1895,7 +1922,7 @@ void tst_QTextLayout::capitalization_allLowerCase() QTextEngine *engine = layout.engine(); engine->itemize(); - QCOMPARE(engine->layoutData->items.count(), 1); + QCOMPARE(engine->layoutData->items.size(), 1); QCOMPARE(engine->layoutData->items.at(0).analysis.flags, ushort(QScriptAnalysis::Lowercase)); } @@ -1911,7 +1938,7 @@ void tst_QTextLayout::capitalization_smallCaps() QTextEngine *engine = layout.engine(); engine->itemize(); - QCOMPARE(engine->layoutData->items.count(), 2); + QCOMPARE(engine->layoutData->items.size(), 2); QCOMPARE(engine->layoutData->items.at(0).analysis.flags, ushort(QScriptAnalysis::None)); QCOMPARE(engine->layoutData->items.at(1).analysis.flags, ushort(QScriptAnalysis::SmallCaps)); } @@ -1928,7 +1955,7 @@ void tst_QTextLayout::capitalization_capitalize() QTextEngine *engine = layout.engine(); engine->itemize(); - QCOMPARE(engine->layoutData->items.count(), 5); + QCOMPARE(engine->layoutData->items.size(), 5); QCOMPARE(engine->layoutData->items.at(0).analysis.flags, ushort(QScriptAnalysis::Uppercase)); QCOMPARE(engine->layoutData->items.at(1).analysis.flags, ushort(QScriptAnalysis::None)); QCOMPARE(engine->layoutData->items.at(2).analysis.flags, ushort(QScriptAnalysis::Tab)); @@ -2039,7 +2066,7 @@ void tst_QTextLayout::columnWrapWithTabs() textLayout.beginLayout(); QTextLine line = textLayout.createLine(); line.setNumColumns(30); - QCOMPARE(line.textLength(), text.length()); + QCOMPARE(line.textLength(), text.size()); textLayout.endLayout(); } @@ -2050,7 +2077,7 @@ void tst_QTextLayout::columnWrapWithTabs() textLayout.beginLayout(); QTextLine line = textLayout.createLine(); line.setNumColumns(30); - QVERIFY(line.textLength() < text.length()); + QVERIFY(line.textLength() < text.size()); textLayout.endLayout(); } @@ -2454,7 +2481,7 @@ void tst_QTextLayout::nbspWithFormat() layout.setText(s1 + s2 + nbsp + s3); QTextLayout::FormatRange formatRange; - formatRange.start = s1.length() + s2.length(); + formatRange.start = s1.size() + s2.size(); formatRange.length = 1; formatRange.format.setFontUnderline(true); @@ -2471,9 +2498,9 @@ void tst_QTextLayout::nbspWithFormat() QCOMPARE(layout.lineCount(), 2); QCOMPARE(layout.lineAt(0).textStart(), 0); - QCOMPARE(layout.lineAt(0).textLength(), s1.length()); - QCOMPARE(layout.lineAt(1).textStart(), s1.length()); - QCOMPARE(layout.lineAt(1).textLength(), s2.length() + 1 + s3.length()); + QCOMPARE(layout.lineAt(0).textLength(), s1.size()); + QCOMPARE(layout.lineAt(1).textStart(), s1.size()); + QCOMPARE(layout.lineAt(1).textLength(), s2.size() + 1 + s3.size()); } void tst_QTextLayout::koreanWordWrap() @@ -2647,13 +2674,35 @@ void tst_QTextLayout::softHyphens() } } +void tst_QTextLayout::min_maximumWidth_data() +{ + QTest::addColumn<QString>("text"); + + QTest::newRow("long string") << QStringLiteral("lmong_long_crazy_87235982735_23857239682376923876923876-fuwhfhfw-names-AAAA-deeaois2019-03-03.and.more"); + QTest::newRow("QTBUG-106947") << QStringLiteral("text text"); + QTest::newRow("spaces") << QStringLiteral(" text text "); + QTest::newRow("QTBUG-104986") << QStringLiteral("text\ntext\ntext"); + QTest::newRow("spaces + line breaks") << QStringLiteral(" \n text\n \ntext \n "); +} + void tst_QTextLayout::min_maximumWidth() { - QString longString("lmong_long_crazy_87235982735_23857239682376923876923876-fuwhfhfw-names-AAAA-deeaois2019-03-03.and.more"); - QTextLayout layout(longString, testFont); + QFETCH(QString, text); + text.replace('\n', QChar::LineSeparator); + + QTextLayout layout(text, testFont); + layout.setCacheEnabled(true); + + QTextOption opt; + opt.setWrapMode(QTextOption::NoWrap); + layout.setTextOption(opt); + layout.beginLayout(); + while (layout.createLine().isValid()) { } + layout.endLayout(); + + const qreal nonWrappedMaxWidth = layout.maximumWidth(); for (int wrapMode = QTextOption::NoWrap; wrapMode <= QTextOption::WrapAtWordBoundaryOrAnywhere; ++wrapMode) { - QTextOption opt; opt.setWrapMode((QTextOption::WrapMode)wrapMode); layout.setTextOption(opt); layout.beginLayout(); @@ -2662,6 +2711,9 @@ void tst_QTextLayout::min_maximumWidth() const qreal minWidth = layout.minimumWidth(); const qreal maxWidth = layout.maximumWidth(); + QCOMPARE_LE(minWidth, maxWidth); + QCOMPARE_LE(maxWidth, nonWrappedMaxWidth); // maxWidth for wrapped text shouldn't exceed maxWidth for the text without wrapping. + // Try the layout from slightly wider than the widest (maxWidth) // and narrow it down to slighly narrower than minWidth // layout.maximumWidth() should return the same regardless @@ -2683,5 +2735,28 @@ void tst_QTextLayout::min_maximumWidth() } } +void tst_QTextLayout::negativeLineWidth() +{ + { + QTextLayout layout; + layout.setText("Foo bar"); + layout.beginLayout(); + QTextLine line = layout.createLine(); + line.setLineWidth(-1); + QVERIFY(line.textLength() > 0); + layout.endLayout(); + } + + { + QTextLayout layout; + layout.setText("Foo bar"); + layout.beginLayout(); + QTextLine line = layout.createLine(); + line.setNumColumns(2, -1); + QVERIFY(line.textLength() > 0); + layout.endLayout(); + } +} + QTEST_MAIN(tst_QTextLayout) #include "tst_qtextlayout.moc" diff --git a/tests/auto/gui/text/qtextlist/CMakeLists.txt b/tests/auto/gui/text/qtextlist/CMakeLists.txt index 2f325d5e17..5764df3e99 100644 --- a/tests/auto/gui/text/qtextlist/CMakeLists.txt +++ b/tests/auto/gui/text/qtextlist/CMakeLists.txt @@ -1,14 +1,21 @@ -# Generated from qtextlist.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtextlist Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtextlist LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtextlist SOURCES ../qtextdocument/common.h tst_qtextlist.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp b/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp index 134249ee83..10d44f6d70 100644 --- a/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp +++ b/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -36,6 +36,8 @@ private slots: void blockUpdate(); void numbering_data(); void numbering(); + void start_data(); + void start(); private: QTextDocument *doc; @@ -138,6 +140,7 @@ void tst_QTextList::autoNumberingPrefixAndSuffixHtmlExportImport() QCOMPARE(list->count(), 28); +#ifndef QT_NO_TEXTHTMLPARSER QString htmlExport = doc->toHtml(); QTextDocument importDoc; importDoc.setHtml(htmlExport); @@ -150,6 +153,7 @@ void tst_QTextList::autoNumberingPrefixAndSuffixHtmlExportImport() QCOMPARE(importCursor.currentList()->itemNumber(importCursor.block()), 27); QCOMPARE(importCursor.currentList()->itemText(importCursor.block()), QLatin1String("\"ab#")); QCOMPARE(importCursor.currentList()->format().indent(), 10); +#endif } void tst_QTextList::autoNumberingRTL() @@ -400,5 +404,61 @@ void tst_QTextList::numbering() QCOMPARE(cursor.currentList()->itemText(cursor.block()), result); } +void tst_QTextList::start_data() +{ + QTest::addColumn<int>("format"); + QTest::addColumn<int>("start"); + QTest::addColumn<QStringList>("expectedItemTexts"); + + QTest::newRow("-1.") << int(QTextListFormat::ListDecimal) << -1 + << QStringList{ "-1.", "0.", "1." }; + QTest::newRow("0.") << int(QTextListFormat::ListDecimal) << 0 + << QStringList{ "0.", "1.", "2." }; + QTest::newRow("1.") << int(QTextListFormat::ListDecimal) << 1 + << QStringList{ "1.", "2.", "3." }; + + QTest::newRow("A. -1") << int(QTextListFormat::ListUpperAlpha) << -1 + << QStringList{ "-1.", "0.", "A." }; + QTest::newRow("A. 0.") << int(QTextListFormat::ListUpperAlpha) << 0 + << QStringList{ "0.", "A.", "B." }; + QTest::newRow("a. -1") << int(QTextListFormat::ListLowerAlpha) << -1 + << QStringList{ "-1.", "0.", "a." }; + QTest::newRow("a. 0.") << int(QTextListFormat::ListLowerAlpha) << 0 + << QStringList{ "0.", "a.", "b." }; + QTest::newRow("d. 4.") << int(QTextListFormat::ListLowerAlpha) << 4 + << QStringList{ "d.", "e.", "f." }; + + QTest::newRow("I. -1") << int(QTextListFormat::ListUpperRoman) << -1 + << QStringList{ "-1.", "0.", "I." }; + QTest::newRow("I. 0.") << int(QTextListFormat::ListUpperRoman) << 0 + << QStringList{ "0.", "I.", "II." }; + QTest::newRow("i. -1") << int(QTextListFormat::ListLowerRoman) << -1 + << QStringList{ "-1.", "0.", "i." }; + QTest::newRow("i. 0.") << int(QTextListFormat::ListLowerRoman) << 0 + << QStringList{ "0.", "i.", "ii." }; +} + +void tst_QTextList::start() +{ + QFETCH(int, format); + QFETCH(int, start); + QFETCH(QStringList, expectedItemTexts); + + QTextListFormat fmt; + fmt.setStyle(QTextListFormat::Style(format)); + fmt.setStart(start); + QTextList *list = cursor.createList(fmt); + QVERIFY(list); + + while (list->count() < int(expectedItemTexts.size())) + cursor.insertBlock(); + + QCOMPARE(list->count(), expectedItemTexts.size()); + + for (int i = 0; i < list->count(); ++i) + QCOMPARE(cursor.currentList()->itemText(cursor.currentList()->item(i)), + expectedItemTexts[i]); +} + QTEST_MAIN(tst_QTextList) #include "tst_qtextlist.moc" diff --git a/tests/auto/gui/text/qtextmarkdownimporter/BLACKLIST b/tests/auto/gui/text/qtextmarkdownimporter/BLACKLIST deleted file mode 100644 index ee09d02090..0000000000 --- a/tests/auto/gui/text/qtextmarkdownimporter/BLACKLIST +++ /dev/null @@ -1,3 +0,0 @@ -# QTBUG-89819 -[lists] -ci b2qt 32bit diff --git a/tests/auto/gui/text/qtextmarkdownimporter/CMakeLists.txt b/tests/auto/gui/text/qtextmarkdownimporter/CMakeLists.txt index 3f23f03c3d..937dd5bd80 100644 --- a/tests/auto/gui/text/qtextmarkdownimporter/CMakeLists.txt +++ b/tests/auto/gui/text/qtextmarkdownimporter/CMakeLists.txt @@ -1,19 +1,26 @@ -# Generated from qtextmarkdownimporter.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtextmarkdownimporter Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtextmarkdownimporter LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data -list(APPEND test_data "data/thematicBreaks.md") -list(APPEND test_data "data/headingBulletsContinuations.md") -list(APPEND test_data "data/fuzz20450.md") -list(APPEND test_data "data/fuzz20580.md") +file(GLOB_RECURSE test_data + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + data/* +) qt_internal_add_test(tst_qtextmarkdownimporter SOURCES tst_qtextmarkdownimporter.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/text/qtextmarkdownimporter/data/paragraphs.md b/tests/auto/gui/text/qtextmarkdownimporter/data/paragraphs.md new file mode 100644 index 0000000000..3d89536376 --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownimporter/data/paragraphs.md @@ -0,0 +1,9 @@ +This paragraph has enough text to auto-wrap when QTextMarkdownWriter writes it +to a markdown file. The wrapping should be around 80 columns. + +This paragrah has been broken up into shorter lines. +Each line break is created +by hitting shift-enter in QTextEdit. +But it's treated as one QTextBlock. + +This paragraph also has short lines.
Each ends with a Unicode LineSeparator.
 diff --git a/tests/auto/gui/text/qtextmarkdownimporter/data/thematicBreaks.md b/tests/auto/gui/text/qtextmarkdownimporter/data/thematicBreaks.md index 7a0d5388ad..e784879326 100644 --- a/tests/auto/gui/text/qtextmarkdownimporter/data/thematicBreaks.md +++ b/tests/auto/gui/text/qtextmarkdownimporter/data/thematicBreaks.md @@ -11,6 +11,7 @@ stars stars with tabs between *** stars with whitespace after + --- hyphens with whitespace after _____ diff --git a/tests/auto/gui/text/qtextmarkdownimporter/data/yaml-only.md b/tests/auto/gui/text/qtextmarkdownimporter/data/yaml-only.md new file mode 100644 index 0000000000..1eff4db37f --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownimporter/data/yaml-only.md @@ -0,0 +1,6 @@ +--- +name: "Space" +title: "Outer space" +keywords: + - astronomy +--- diff --git a/tests/auto/gui/text/qtextmarkdownimporter/data/yaml.md b/tests/auto/gui/text/qtextmarkdownimporter/data/yaml.md new file mode 100644 index 0000000000..41303a0187 --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownimporter/data/yaml.md @@ -0,0 +1,11 @@ +--- +name: "Venus" +discoverer: "Galileo Galilei" +title: "A description of the planet Venus" +keywords: + - planets + - solar system + - astronomy +--- +*Venus* is the second planet from the Sun, orbiting it every 224.7 Earth days. + diff --git a/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp b/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp index 4fc6e9ebc8..d9fe000253 100644 --- a/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp +++ b/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2019 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QBuffer> @@ -29,6 +29,7 @@ class tst_QTextMarkdownImporter : public QObject Q_OBJECT private slots: + void paragraphs(); void headingBulletsContinuations(); void thematicBreaks(); void lists_data(); @@ -41,6 +42,15 @@ private slots: void fragmentsAndProperties(); void pathological_data(); void pathological(); + void fencedCodeBlocks_data(); + void fencedCodeBlocks(); + void frontMatter_data(); + void frontMatter(); + void toRawText_data(); + void toRawText(); + +private: + bool isMainFontFixed(); public: enum CharFormat { @@ -59,6 +69,55 @@ public: Q_DECLARE_METATYPE(tst_QTextMarkdownImporter::CharFormats) Q_DECLARE_OPERATORS_FOR_FLAGS(tst_QTextMarkdownImporter::CharFormats) +bool tst_QTextMarkdownImporter::isMainFontFixed() +{ + bool ret = QFontInfo(QGuiApplication::font()).fixedPitch(); + if (ret) { + qCWarning(lcTests) << "QFontDatabase::GeneralFont is monospaced: markdown writing is likely to use too many backticks"; + qCWarning(lcTests) << "system fonts: fixed" << QFontDatabase::systemFont(QFontDatabase::FixedFont) + << "fixed?" << QFontInfo(QFontDatabase::systemFont(QFontDatabase::FixedFont)).fixedPitch() + << "general" << QFontDatabase::systemFont(QFontDatabase::GeneralFont); + } + return ret; +} + +void tst_QTextMarkdownImporter::paragraphs() +{ + QFile f(QFINDTESTDATA("data/paragraphs.md")); + QVERIFY(f.open(QFile::ReadOnly | QIODevice::Text)); + QString md = QString::fromUtf8(f.readAll()); + f.close(); + + int lineSeparatorCount = 0; + QTextDocument doc; + QTextMarkdownImporter(&doc, QTextMarkdownImporter::DialectGitHub).import(md); + QTextFrame::iterator iterator = doc.rootFrame()->begin(); + int i = 0; + while (!iterator.atEnd()) { + QTextBlock block = iterator.currentBlock(); + int lineSeparatorPos = block.text().indexOf(QChar::LineSeparator); + qCDebug(lcTests) << i << block.text(); + while (lineSeparatorPos > 0) { + ++lineSeparatorCount; + qCDebug(lcTests) << " LineSeparator @" << lineSeparatorPos; + lineSeparatorPos = block.text().indexOf(QChar::LineSeparator, lineSeparatorPos + 1); + } + ++iterator; + ++i; + } + QCOMPARE(doc.blockCount(), 3); + QCOMPARE(lineSeparatorCount, 2); + +#ifdef DEBUG_WRITE_HTML + { + QFile out("/tmp/paragraphs.html"); + out.open(QFile::WriteOnly); + out.write(doc.toHtml().toLatin1()); + out.close(); + } +#endif +} + void tst_QTextMarkdownImporter::headingBulletsContinuations() { const QStringList expectedBlocks = QStringList() << @@ -84,7 +143,7 @@ void tst_QTextMarkdownImporter::headingBulletsContinuations() f.close(); QTextDocument doc; - QTextMarkdownImporter(QTextMarkdownImporter::DialectGitHub).import(&doc, md); + QTextMarkdownImporter(&doc, QTextMarkdownImporter::DialectGitHub).import(md); QTextFrame::iterator iterator = doc.rootFrame()->begin(); QTextFrame *currentFrame = iterator.currentFrame(); QStringList::const_iterator expectedIt = expectedBlocks.constBegin(); @@ -132,7 +191,7 @@ void tst_QTextMarkdownImporter::thematicBreaks() f.close(); QTextDocument doc; - QTextMarkdownImporter(QTextMarkdownImporter::DialectGitHub).import(&doc, md); + QTextMarkdownImporter(&doc, QTextMarkdownImporter::DialectGitHub).import(md); QTextFrame::iterator iterator = doc.rootFrame()->begin(); QTextFrame *currentFrame = iterator.currentFrame(); int i = 0; @@ -165,36 +224,58 @@ void tst_QTextMarkdownImporter::thematicBreaks() void tst_QTextMarkdownImporter::lists_data() { QTest::addColumn<QString>("input"); + QTest::addColumn<int>("skipToCheckStart"); + QTest::addColumn<int>("expectedListStart"); QTest::addColumn<int>("expectedItemCount"); QTest::addColumn<bool>("expectedEmptyItems"); QTest::addColumn<QString>("rewrite"); // Some of these cases show odd behavior, which is subject to change // as the importer and the writer are tweaked to fix bugs over time. - QTest::newRow("dot newline") << ".\n" << 0 << true << ".\n\n"; - QTest::newRow("number dot newline") << "1.\n" << 1 << true << "1. \n"; - QTest::newRow("star newline") << "*\n" << 1 << true << "* \n"; - QTest::newRow("hyphen newline") << "-\n" << 1 << true << "- \n"; - QTest::newRow("hyphen space newline") << "- \n" << 1 << true << "- \n"; - QTest::newRow("hyphen space letter newline") << "- a\n" << 1 << false << "- a\n"; + QTest::newRow("dot newline") << ".\n" << 0 << 1 << 0 << true << ".\n\n"; + QTest::newRow("number dot newline") << "1.\n" << 0 << 1 << 1 << true << "1. \n"; + QTest::newRow("number offset start") << "2. text\n" << 0 << 2 << 1 << false << "2. text\n"; + QTest::newRow("second list offset start") + << "1. text\n\nintervening paragraph\n\n4. second list item" + << 2 << 4 << 2 << false + << "1. text\n\nintervening paragraph\n\n4. second list item\n"; + QTest::newRow("list continuation offset start") + << "3. text\n\n next paragraph in item 1\n10. second list item" + << 2 << 3 << 2 << false + << "3. text\n\n next paragraph in item 1\n\n4. second list item\n"; + QTest::newRow("nested list offset start") + << "1. text\n\n 0. indented list item\n\n4. second item in first list" + << 1 << 0 << 3 << false + << "1. text\n 0. indented list item\n2. second item in first list\n"; + QTest::newRow("offset start after nested list") + << "1. text\n\n 0. indented list item\n\n4. second item in first list" + << 2 << 1 << 3 << false + << "1. text\n 0. indented list item\n2. second item in first list\n"; + QTest::newRow("star newline") << "*\n" << 0 << 1 << 1 << true << "* \n"; + QTest::newRow("hyphen newline") << "-\n" << 0 << 1 << 1 << true << "- \n"; + QTest::newRow("hyphen space newline") << "- \n" << 0 << 1 << 1 << true << "- \n"; + QTest::newRow("hyphen space letter newline") << "- a\n" << 0 << 1 << 1 << false << "- a\n"; QTest::newRow("hyphen nbsp newline") << - QString::fromUtf8("-\u00A0\n") << 0 << true << "-\u00A0\n\n"; - QTest::newRow("nested empty lists") << "*\n *\n *\n" << 1 << true << " * \n"; - QTest::newRow("list nested in empty list") << "-\n * a\n" << 2 << false << "- \n * a\n"; + QString::fromUtf8("-\u00A0\n") << 0 << 1 << 0 << true << "\\-\u00A0\n\n"; + QTest::newRow("nested empty lists") << "*\n *\n *\n" << 0 << 1 << 1 << true << " * \n"; + QTest::newRow("list nested in empty list") << "-\n * a\n" << 0 << 1 << 2 << false << "- \n * a\n"; QTest::newRow("lists nested in empty lists") - << "-\n * a\n * b\n- c\n *\n + d\n" << 5 << false + << "-\n * a\n * b\n- c\n *\n + d\n" << 0 << 1 << 5 << false << "- \n * a\n * b\n- c *\n + d\n"; QTest::newRow("numeric lists nested in empty lists") - << "- \n 1. a\n 2. b\n- c\n 1.\n + d\n" << 4 << false + << "- \n 1. a\n 2. b\n- c\n 1.\n + d\n" << 0 << 1 << 4 << false << "- \n 1. a\n 2. b\n- c 1. + d\n"; QTest::newRow("styled spans in list items") - << "1. normal text\n2. **bold** text\n3. `code` in the item\n4. *italic* text\n5. _underlined_ text\n" << 5 << false + << "1. normal text\n2. **bold** text\n3. `code` in the item\n4. *italic* text\n5. _underlined_ text\n" + << 0 << 1 << 5 << false << "1. normal text\n2. **bold** text\n3. `code` in the item\n4. *italic* text\n5. _underlined_ text\n"; } void tst_QTextMarkdownImporter::lists() { QFETCH(QString, input); + QFETCH(int, skipToCheckStart); + QFETCH(int, expectedListStart); QFETCH(int, expectedItemCount); QFETCH(bool, expectedEmptyItems); QFETCH(QString, rewrite); @@ -210,6 +291,8 @@ void tst_QTextMarkdownImporter::lists() out.close(); } #endif + qCDebug(lcTests) << " original:" << input; + qCDebug(lcTests) << "rewritten:" << doc.toMarkdown(); QTextFrame::iterator iterator = doc.rootFrame()->begin(); QTextFrame *currentFrame = iterator.currentFrame(); @@ -222,10 +305,12 @@ void tst_QTextMarkdownImporter::lists() QCOMPARE(iterator.currentFrame(), currentFrame); // Check whether the block is text or a horizontal rule QTextBlock block = iterator.currentBlock(); + QTextListFormat listFmt; if (block.textList()) { ++itemCount; if (!block.text().isEmpty()) emptyItems = false; + listFmt = block.textList()->format(); } qCDebug(lcTests, "%d %s%s", i, (block.textList() ? "<li>" : "<p>"), qPrintable(block.text())); @@ -244,11 +329,18 @@ void tst_QTextMarkdownImporter::lists() QCOMPARE(listItemFmt.fontItalic(), false); QCOMPARE(listItemFmt.fontUnderline(), false); QCOMPARE(listItemFmt.fontFixedPitch(), false); + if (i == skipToCheckStart) { + qCDebug(lcTests) << "skipped to list item" << i << block.text() + << "start" << listFmt.start() << "expected" << expectedListStart; + QCOMPARE(listFmt.start(), expectedListStart); + } ++iterator; ++i; } QCOMPARE(itemCount, expectedItemCount); QCOMPARE(emptyItems, expectedEmptyItems); + if (doc.toMarkdown() != rewrite && isMainFontFixed()) + QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue); QCOMPARE(doc.toMarkdown(), rewrite); } @@ -361,7 +453,7 @@ void tst_QTextMarkdownImporter::avoidBlankLineAtBeginning_data() QTest::newRow("Text block") << QString("Markdown text") << 1; QTest::newRow("Headline") << QString("Markdown text\n============") << 1; - QTest::newRow("Code block") << QString(" Markdown text") << 2; + QTest::newRow("Code block") << QString(" Markdown text") << 1; QTest::newRow("Unordered list") << QString("* Markdown text") << 1; QTest::newRow("Ordered list") << QString("1. Markdown text") << 1; QTest::newRow("Blockquote") << QString("> Markdown text") << 1; @@ -373,7 +465,7 @@ void tst_QTextMarkdownImporter::avoidBlankLineAtBeginning() // QTBUG-81060 QFETCH(int, expectedNumberOfParagraphs); QTextDocument doc; - QTextMarkdownImporter(QTextMarkdownImporter::DialectGitHub).import(&doc, input); + QTextMarkdownImporter(&doc, QTextMarkdownImporter::DialectGitHub).import(input); QTextFrame::iterator iterator = doc.rootFrame()->begin(); int i = 0; while (!iterator.atEnd()) { @@ -418,7 +510,7 @@ void tst_QTextMarkdownImporter::fragmentsAndProperties() QFETCH(int, expectedNumberOfFragments); QTextDocument doc; - QTextMarkdownImporter(QTextMarkdownImporter::DialectGitHub).import(&doc, input); + QTextMarkdownImporter(&doc, QTextMarkdownImporter::DialectGitHub).import(input); #ifdef DEBUG_WRITE_HTML { QFile out("/tmp/" + QLatin1String(QTest::currentDataTag()) + ".html"); @@ -473,5 +565,211 @@ void tst_QTextMarkdownImporter::pathological() // avoid crashing on crazy input QTextDocument().setMarkdown(f.readAll()); } +void tst_QTextMarkdownImporter::fencedCodeBlocks_data() +{ + QTest::addColumn<QString>("input"); + QTest::addColumn<int>("expectedCodeBlockCount"); + QTest::addColumn<int>("expectedPlainBlockCount"); + QTest::addColumn<QString>("expectedLanguage"); + QTest::addColumn<QString>("expectedFenceChar"); + QTest::addColumn<QString>("rewrite"); + + QTest::newRow("backtick fence with language") + << "```pseudocode\nprint('hello world\\n')\n```\n" + << 1 << 0 << "pseudocode" << "`" + << "```pseudocode\nprint('hello world\\n')\n```\n\n"; + QTest::newRow("backtick fence with punctuated language") + << "```html+js\n<html><head><script>function hi() { console.log('\\\"hello world') }</script></head>blah</html>\n```\n" + << 1 << 0 << "html+js" << "`" + << "```html+js\n<html><head><script>function hi() { console.log('\\\"hello world') }</script></head>blah</html>\n```\n\n"; + QTest::newRow("tilde fence with language") + << "~~~pseudocode\nprint('hello world\\n')\n~~~\n" + << 1 << 0 << "pseudocode" << "~" + << "~~~pseudocode\nprint('hello world\\n')\n~~~\n\n"; + QTest::newRow("embedded backticks") + << "```\nnone `one` ``two``\n```\nplain\n```\n```three``` ````four````\n```\nplain\n" + << 2 << 2 << QString() << "`" + << "```\nnone `one` ``two``\n```\nplain\n\n```\n```three``` ````four````\n```\nplain\n\n"; +} + +void tst_QTextMarkdownImporter::fencedCodeBlocks() +{ + QFETCH(QString, input); + QFETCH(int, expectedCodeBlockCount); + QFETCH(int, expectedPlainBlockCount); + QFETCH(QString, expectedLanguage); + QFETCH(QString, expectedFenceChar); + QFETCH(QString, rewrite); + + QTextDocument doc; + doc.setMarkdown(input); + +#ifdef DEBUG_WRITE_HTML + { + QFile out("/tmp/" + QLatin1String(QTest::currentDataTag()) + ".html"); + out.open(QFile::WriteOnly); + out.write(doc.toHtml().toLatin1()); + out.close(); + } +#endif + + QTextFrame::iterator iterator = doc.rootFrame()->begin(); + QTextFrame *currentFrame = iterator.currentFrame(); + int codeBlockCount = 0; + int plainBlockCount = 0; + while (!iterator.atEnd()) { + // There are no child frames + QCOMPARE(iterator.currentFrame(), currentFrame); + // Check whether the block is code or plain + QTextBlock block = iterator.currentBlock(); + const bool codeBlock = block.blockFormat().hasProperty(QTextFormat::BlockCodeFence); + QCOMPARE(block.blockFormat().nonBreakableLines(), codeBlock); + QCOMPARE(block.blockFormat().stringProperty(QTextFormat::BlockCodeLanguage), codeBlock ? expectedLanguage : QString()); + if (codeBlock) { + QCOMPARE(block.blockFormat().stringProperty(QTextFormat::BlockCodeFence), expectedFenceChar); + ++codeBlockCount; + } else { + ++plainBlockCount; + } + qCDebug(lcTests) << (codeBlock ? "code" : "text") << block.text() << block.charFormat().fontFamilies(); + ++iterator; + } + QCOMPARE(codeBlockCount, expectedCodeBlockCount); + QCOMPARE(plainBlockCount, expectedPlainBlockCount); + if (doc.toMarkdown() != rewrite && isMainFontFixed()) + QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue); + QCOMPARE(doc.toMarkdown(), rewrite); +} + +void tst_QTextMarkdownImporter::frontMatter_data() +{ + QTest::addColumn<QString>("inputFile"); + QTest::addColumn<int>("expectedBlockCount"); + + QTest::newRow("yaml + markdown") << QFINDTESTDATA("data/yaml.md") << 1; + QTest::newRow("yaml only") << QFINDTESTDATA("data/yaml-only.md") << 0; +} + +void tst_QTextMarkdownImporter::frontMatter() +{ + QFETCH(QString, inputFile); + QFETCH(int, expectedBlockCount); + + QFile f(inputFile); + QVERIFY(f.open(QFile::ReadOnly | QIODevice::Text)); + QString md = QString::fromUtf8(f.readAll()); + f.close(); + const int yamlBegin = md.indexOf("name:"); + const int yamlEnd = md.indexOf("---", yamlBegin); + const QString yaml = md.sliced(yamlBegin, yamlEnd - yamlBegin); + + QTextDocument doc; + QTextMarkdownImporter(&doc, QTextMarkdownImporter::DialectGitHub).import(md); + int blockCount = 0; + for (QTextFrame::iterator iterator = doc.rootFrame()->begin(); !iterator.atEnd(); ++iterator) { + // Check whether the block is text or a horizontal rule + if (!iterator.currentBlock().text().isEmpty()) + ++blockCount; + } + QCOMPARE(blockCount, expectedBlockCount); // yaml is not part of the markdown text + QCOMPARE(doc.metaInformation(QTextDocument::FrontMatter), yaml); // without fences +} + +void tst_QTextMarkdownImporter::toRawText_data() +{ + QTest::addColumn<QString>("input"); + QTest::addColumn<QString>("expectedRawText"); + + // tests to verify that fixing QTBUG-122083 is safe + // https://spec.commonmark.org/0.31.2/#example-12 + QTest::newRow("punctuation backslash escapes") << + R"(\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~)" << + R"(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)"; + // https://spec.commonmark.org/0.31.2/#example-13 + QTest::newRow("literal backslashes") << + QString(uR"(\→\A\a\ \3\φ\«)") << + QString(uR"(\→\A\a\ \3\φ\«)"); + // https://spec.commonmark.org/0.31.2/#example-14 + QTest::newRow("escape to avoid em") << + R"(\*not emphasized*)" << + R"(*not emphasized*)"; + QTest::newRow("escape to avoid html") << + R"(\<br/> not a tag)" << + R"(<br/> not a tag)"; + QTest::newRow("escape to avoid link") << + R"(\[not a link](/foo))" << + R"([not a link](/foo))"; + QTest::newRow("escape to avoid mono") << + R"(\`not code`)" << + R"(`not code`)"; + QTest::newRow("escape to avoid num list") << + R"(1\. not a list)" << + R"(1. not a list)"; + QTest::newRow("escape to avoid list") << + R"(\* not a list)" << + R"(* not a list)"; + QTest::newRow("escape to avoid heading") << + R"(\# not a heading)" << + R"(# not a heading)"; + QTest::newRow("escape to avoid reflink") << + R"(\[foo]: /url "not a reference")" << + R"([foo]: /url "not a reference")"; + QTest::newRow("escape to avoid entity") << + R"(\ö not a character entity)" << + R"(ö not a character entity)"; + // https://spec.commonmark.org/0.31.2/#example-15 + QTest::newRow("escape backslash only") << + R"(\\*emphasis*)" << + R"(\emphasis)"; + // https://spec.commonmark.org/0.31.2/#example-16 + QTest::newRow("backslash line break") << + "foo\\\nbar" << + "foo\u2029bar"; + // https://spec.commonmark.org/0.31.2/#example-17 + QTest::newRow("backslash in mono span") << + R"(`` \[\` ``)" << + R"(\[\`)"; + // https://spec.commonmark.org/0.31.2/#example-18 + QTest::newRow("backslash in indented code") << + R"( \[\])" << + R"(\[\])"; + // https://spec.commonmark.org/0.31.2/#example-19 + QTest::newRow("backslash in fenced code") << + "~~~\n\\[\\]\n~~~" << + R"(\[\])"; + // https://spec.commonmark.org/0.31.2/#example-20 + QTest::newRow("backslash in autolink") << + R"(<https://example.com?find=\*>)" << + R"(https://example.com?find=\*)"; + // https://spec.commonmark.org/0.31.2/#example-21 + QTest::newRow("backslash in autolink") << + "<a href=\"/bar\\/)\"" << + "<a href=\"/bar/)\""; + // https://spec.commonmark.org/0.31.2/#example-22 + QTest::newRow("escapes in link") << + R"([foo](/bar\* "ti\*tle"))" << + R"(foo)"; + // https://spec.commonmark.org/0.31.2/#example-24 + QTest::newRow("backslash in code lang") << + "```\nfoo\\+bar\nfoo\n```" << + "foo\\+bar\u2029foo"; + // end of tests to verify that fixing QTBUG-122083 is safe + // (it's ok to add unrelated markdown-to-rawtext cases later) +} + +void tst_QTextMarkdownImporter::toRawText() +{ + QFETCH(QString, input); + QFETCH(QString, expectedRawText); + + QTextDocument doc; + doc.setMarkdown(input); + + // These are testing md4c more than Qt, so any change may be an md4c bug, or a fix + QCOMPARE(doc.toRawText(), expectedRawText); + if (doc.blockCount() == 1) + QCOMPARE(doc.firstBlock().text(), expectedRawText); +} + QTEST_MAIN(tst_QTextMarkdownImporter) #include "tst_qtextmarkdownimporter.moc" diff --git a/tests/auto/gui/text/qtextmarkdownwriter/BLACKLIST b/tests/auto/gui/text/qtextmarkdownwriter/BLACKLIST deleted file mode 100644 index 9aa61c46cd..0000000000 --- a/tests/auto/gui/text/qtextmarkdownwriter/BLACKLIST +++ /dev/null @@ -1,4 +0,0 @@ -# QTBUG-89819 -ci b2qt 32bit -[fromHtml:preformats with embedded backticks] -qnx ci diff --git a/tests/auto/gui/text/qtextmarkdownwriter/CMakeLists.txt b/tests/auto/gui/text/qtextmarkdownwriter/CMakeLists.txt index 884195345c..0cdf1d9225 100644 --- a/tests/auto/gui/text/qtextmarkdownwriter/CMakeLists.txt +++ b/tests/auto/gui/text/qtextmarkdownwriter/CMakeLists.txt @@ -1,17 +1,26 @@ -# Generated from qtextmarkdownwriter.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtextmarkdownwriter Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtextmarkdownwriter LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data -list(APPEND test_data "data/example.md") -list(APPEND test_data "data/blockquotes.md") +file(GLOB_RECURSE test_data + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + data/* +) qt_internal_add_test(tst_qtextmarkdownwriter SOURCES tst_qtextmarkdownwriter.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md b/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md index 702ccef134..8e605ef7e6 100644 --- a/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md +++ b/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md @@ -8,18 +8,17 @@ MacFarlane writes: > What distinguishes Markdown from many other lightweight markup syntaxes, > which are often easier to write, is its readability. As Gruber writes: - +> > > The overriding design goal for Markdown's formatting syntax is to make it > > as readable as possible. The idea is that a Markdown-formatted document should > > be publishable as-is, as plain text, without looking like it's been marked up > > with tags or formatting instructions. ( -> > [http://daringfireball.net/projects/markdown/](http://daringfireball.net/projects/markdown/) -> > ) - +> > <http://daringfireball.net/projects/markdown/> ) +> > The point can be illustrated by comparing a sample of AsciiDoc with an > equivalent sample of Markdown. Here is a sample of AsciiDoc from the AsciiDoc > manual: - +> > ```AsciiDoc > 1. List item one. > + @@ -50,6 +49,7 @@ Now let's have an indented code block: } and end with a fenced code block: + ~~~pseudocode #include <something.h> #include <else.h> diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotesWithLists.md b/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotesWithLists.md new file mode 100644 index 0000000000..1728889adc --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotesWithLists.md @@ -0,0 +1,14 @@ +What if we have a quotation containing a list? + +> First some quoted text, and then a list: +> +> - one +> - two is longer and has enough words to form a paragraph with text continuing +> onto the next line +> +> enough of that, let's try a numbered list +> +> 1. List item one +> 2. List item two is longer and has enough words to form a paragraph with +> text continuing onto the next line. +>
\ No newline at end of file diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/example.md b/tests/auto/gui/text/qtextmarkdownwriter/data/example.md index a9a157f25a..8fdad207ae 100644 --- a/tests/auto/gui/text/qtextmarkdownwriter/data/example.md +++ b/tests/auto/gui/text/qtextmarkdownwriter/data/example.md @@ -40,7 +40,7 @@ numerals in the same list structure: 1. Introduction 2. Qt Tools 1) Qt Assistant - 2) Qt Designer + 2) Qt Widgets Designer 1. Form Editor 2. Component Architecture 3) Qt Linguist @@ -70,7 +70,7 @@ column spans, text formatting within cells, and size constraints for columns. |-------------|------------------------------------|---------------------------|-------------------------| |9:00 - 11:00 |Introduction to Qt ||| |11:00 - 13:00|Using qmake |Object-oriented Programming|Layouts in Qt | -|13:00 - 15:00|Qt Designer Tutorial |Extreme Programming |Writing Custom Styles | +|13:00 - 15:00|Qt Widgets Designer Tutorial |Extreme Programming |Writing Custom Styles | |15:00 - 17:00|Qt Linguist and Internationalization|Test-Driven Development | | *Try adding text to the cells in the table and experiment with the alignment of @@ -83,7 +83,7 @@ is used extensively in [Qt Assistant](http://doc.qt.io/qt-5/qtassistant-index.html). Hyperlinks are automatically created when an HTML file is imported into an editor. Since the rich text framework supports hyperlinks natively, they can also be created -programatically. +programmatically. ## Undo and Redo diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/links.md b/tests/auto/gui/text/qtextmarkdownwriter/data/links.md index 33cdb2b3ab..c9aae80c67 100644 --- a/tests/auto/gui/text/qtextmarkdownwriter/data/links.md +++ b/tests/auto/gui/text/qtextmarkdownwriter/data/links.md @@ -23,3 +23,6 @@ title") * [link](/url "title title title") * nonlink + +Qt has the <https://qt.io> site + diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/listItemWithBlockquote.md b/tests/auto/gui/text/qtextmarkdownwriter/data/listItemWithBlockquote.md new file mode 100644 index 0000000000..c417125fea --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownwriter/data/listItemWithBlockquote.md @@ -0,0 +1,6 @@ +What if we have a list item containing a block quote? + +- one +- > two is longer and has enough words to form a paragraph with text continuing + > onto the next line + diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/longHeadings.md b/tests/auto/gui/text/qtextmarkdownwriter/data/longHeadings.md new file mode 100644 index 0000000000..72692b4845 --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownwriter/data/longHeadings.md @@ -0,0 +1,9 @@ +# The quick brown fox jumped over the lazy dog while the cat played the fiddle and the cow jumped over the moon + +Hey diddle diddle + +## This document has a verbose subheading too, which we do not expect to wrap in the output + +Qt can write it right. Long text here in this paragraph will actually wrap, +even though its heading doesn't. + diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/yaml.md b/tests/auto/gui/text/qtextmarkdownwriter/data/yaml.md new file mode 100644 index 0000000000..41303a0187 --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownwriter/data/yaml.md @@ -0,0 +1,11 @@ +--- +name: "Venus" +discoverer: "Galileo Galilei" +title: "A description of the planet Venus" +keywords: + - planets + - solar system + - astronomy +--- +*Venus* is the second planet from the Sun, orbiting it every 224.7 Earth days. + diff --git a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp index 4551197865..0d261bc27e 100644 --- a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp +++ b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2019 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QTextDocument> @@ -9,9 +9,13 @@ #include <QTextTable> #include <QBuffer> #include <QDebug> +#include <QFontInfo> +#include <QLoggingCategory> #include <private/qtextmarkdownwriter_p.h> +Q_LOGGING_CATEGORY(lcTests, "qt.text.tests") + // #define DEBUG_WRITE_OUTPUT class tst_QTextMarkdownWriter : public QObject @@ -30,17 +34,31 @@ private slots: void testWriteNestedBulletLists_data(); void testWriteNestedBulletLists(); void testWriteNestedNumericLists(); + void testWriteNumericListWithStart(); void testWriteTable(); + void frontMatter(); + void charFormatWrapping_data(); + void charFormatWrapping(); + void charFormat_data(); + void charFormat(); void rewriteDocument_data(); void rewriteDocument(); void fromHtml_data(); void fromHtml(); + void fromPlainTextAndBack_data(); + void fromPlainTextAndBack(); + void escapeSpecialCharacters_data(); + void escapeSpecialCharacters(); private: + bool isMainFontFixed(); + bool isFixedFontProportional(); QString documentToUnixMarkdown(); private: QTextDocument *document; + QFont m_monoFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); + QFont m_defaultFont; }; void tst_QTextMarkdownWriter::init() @@ -53,10 +71,39 @@ void tst_QTextMarkdownWriter::cleanup() delete document; } +bool tst_QTextMarkdownWriter::isMainFontFixed() +{ + bool ret = QFontInfo(QGuiApplication::font()).fixedPitch(); + if (ret) { + qCWarning(lcTests) << "QFontDatabase::GeneralFont is monospaced: markdown writing is likely to use too many backticks" + << QFontDatabase::systemFont(QFontDatabase::GeneralFont); + } + return ret; +} + +bool tst_QTextMarkdownWriter::isFixedFontProportional() +{ + bool ret = !QFontInfo(QFontDatabase::systemFont(QFontDatabase::FixedFont)).fixedPitch(); + if (ret) { + qCWarning(lcTests) << "QFontDatabase::FixedFont is NOT monospaced: markdown writing is likely to use too few backticks" + << QFontDatabase::systemFont(QFontDatabase::FixedFont); + } + return ret; +} + +QString tst_QTextMarkdownWriter::documentToUnixMarkdown() +{ + QString ret; + QTextStream ts(&ret, QIODevice::WriteOnly); + QTextMarkdownWriter writer(ts, QTextDocument::MarkdownDialectGitHub); + writer.writeAll(document); + return ret; +} + void tst_QTextMarkdownWriter::testWriteParagraph_data() { QTest::addColumn<QString>("input"); - QTest::addColumn<QString>("output"); + QTest::addColumn<QString>("expectedOutput"); QTest::newRow("empty") << "" << ""; @@ -79,12 +126,15 @@ void tst_QTextMarkdownWriter::testWriteParagraph_data() void tst_QTextMarkdownWriter::testWriteParagraph() { QFETCH(QString, input); - QFETCH(QString, output); + QFETCH(QString, expectedOutput); QTextCursor cursor(document); cursor.insertText(input); - QCOMPARE(documentToUnixMarkdown(), output); + const QString output = documentToUnixMarkdown(); + if (output != expectedOutput && isMainFontFixed()) + QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue); + QCOMPARE(output, expectedOutput); } void tst_QTextMarkdownWriter::testWriteList() @@ -97,8 +147,11 @@ void tst_QTextMarkdownWriter::testWriteList() cursor.insertText("ListItem 2"); list->add(cursor.block()); - QCOMPARE(documentToUnixMarkdown(), QString::fromLatin1( - "- ListItem 1\n- ListItem 2\n")); + const QString output = documentToUnixMarkdown(); + const QString expected = QString::fromLatin1("- ListItem 1\n- ListItem 2\n"); + if (output != expected && isMainFontFixed()) + QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue); + QCOMPARE(output, expected); } void tst_QTextMarkdownWriter::testWriteEmptyList() @@ -133,8 +186,12 @@ void tst_QTextMarkdownWriter::testWriteCheckboxListItemEndingWithCode() QCOMPARE(cursor.selectedText(), QString::fromLatin1("Image.originalSize")); cursor.setCharFormat(fmt); - QCOMPARE(documentToUnixMarkdown(), QString::fromLatin1( - "- [ ] `Image.originalSize` property (not necessary; `PdfDocument.pagePointSize()`\n substitutes)\n")); + const QString output = documentToUnixMarkdown(); + const QString expected = QString::fromLatin1( + "- [ ] `Image.originalSize` property (not necessary; `PdfDocument.pagePointSize()`\n substitutes)\n"); + if (output != expected && isMainFontFixed()) + QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue); + QCOMPARE(output, expected); } void tst_QTextMarkdownWriter::testWriteNestedBulletLists_data() @@ -216,7 +273,7 @@ void tst_QTextMarkdownWriter::testWriteNestedBulletLists() cursor.insertText("continuation"); } - QString output = documentToUnixMarkdown(); + const QString output = documentToUnixMarkdown(); #ifdef DEBUG_WRITE_OUTPUT { QFile out("/tmp/" + QLatin1String(QTest::currentDataTag()) + ".md"); @@ -225,7 +282,9 @@ void tst_QTextMarkdownWriter::testWriteNestedBulletLists() out.close(); } #endif - QCOMPARE(documentToUnixMarkdown(), expectedOutput); + if (output != expectedOutput && isMainFontFixed()) + QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue); + QCOMPARE(output, expectedOutput); } void tst_QTextMarkdownWriter::testWriteNestedNumericLists() @@ -237,29 +296,137 @@ void tst_QTextMarkdownWriter::testWriteNestedNumericLists() list1->add(cursor.block()); QTextListFormat fmt2; + // Alpha "numbering" is not supported in markdown, so we'll actually get decimal. + fmt2.setStyle(QTextListFormat::ListLowerAlpha); + fmt2.setNumberSuffix(QLatin1String(")")); + fmt2.setIndent(2); + QTextList *list2 = cursor.insertList(fmt2); + cursor.insertText("ListItem 2"); + + QTextListFormat fmt3; + fmt3.setStyle(QTextListFormat::ListDecimal); + fmt3.setIndent(3); + cursor.insertList(fmt3); + cursor.insertText("ListItem 3"); + + cursor.insertBlock(); + cursor.insertText("ListItem 4"); + list1->add(cursor.block()); + + cursor.insertBlock(); + cursor.insertText("ListItem 5"); + list2->add(cursor.block()); + + const QString output = documentToUnixMarkdown(); + + #ifdef DEBUG_WRITE_OUTPUT + { + QFile out(QDir::temp().filePath(QLatin1String(QTest::currentTestFunction()) + ".md")); + out.open(QFile::WriteOnly); + out.write(output.toUtf8()); + out.close(); + } + { + QFile out(QDir::temp().filePath(QLatin1String(QTest::currentTestFunction()) + ".html")); + out.open(QFile::WriteOnly); + out.write(document->toHtml().toUtf8()); + out.close(); + } +#endif + + // While we can set the start index for a block, if list items intersect each other, they will + // still use the list numbering. + const QString expected = QString::fromLatin1( + "1. ListItem 1\n 1) ListItem 2\n 1. ListItem 3\n2. ListItem 4\n 2) ListItem 5\n"); + if (output != expected && isMainFontFixed()) + QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue); + QCOMPARE(output, expected); +} + +void tst_QTextMarkdownWriter::testWriteNumericListWithStart() +{ + QTextCursor cursor(document); + + // The first list will start at 2. + QTextListFormat fmt1; + fmt1.setStyle(QTextListFormat::ListDecimal); + fmt1.setStart(2); + QTextList *list1 = cursor.createList(fmt1); + cursor.insertText("ListItem 1"); + list1->add(cursor.block()); + + // This list uses the default start (1) again. + QTextListFormat fmt2; + // Alpha "numbering" is not supported in markdown, so we'll actually get decimal. fmt2.setStyle(QTextListFormat::ListLowerAlpha); fmt2.setNumberSuffix(QLatin1String(")")); fmt2.setIndent(2); QTextList *list2 = cursor.insertList(fmt2); cursor.insertText("ListItem 2"); + // Negative list numbers are disallowed by most Markdown implementations. This list will start + // at 1 for that reason. QTextListFormat fmt3; fmt3.setStyle(QTextListFormat::ListDecimal); fmt3.setIndent(3); + fmt3.setStart(-1); cursor.insertList(fmt3); cursor.insertText("ListItem 3"); + // Continuing list1, so the second item will have the number 3. cursor.insertBlock(); cursor.insertText("ListItem 4"); list1->add(cursor.block()); + // This will look out of place: it's in a different position than its list would suggest. + // Generates invalid markdown numbering (OK for humans, but md4c will parse it differently than we "meant"). + // TODO QTBUG-111707: the writer needs to add newlines, otherwise ListItem 5 becomes part of the text for ListItem 4. cursor.insertBlock(); cursor.insertText("ListItem 5"); list2->add(cursor.block()); - // There's no QTextList API to set the starting number so we hard-coded all lists to start at 1 (QTBUG-65384) - QCOMPARE(documentToUnixMarkdown(), QString::fromLatin1( - "1. ListItem 1\n 1) ListItem 2\n 1. ListItem 3\n2. ListItem 4\n 2) ListItem 5\n")); + // 0 indexed lists are fine. + QTextListFormat fmt4; + fmt4.setStyle(QTextListFormat::ListDecimal); + fmt4.setStart(0); + QTextList *list4 = cursor.insertList(fmt4); + cursor.insertText("SecondList Item 0"); + list4->add(cursor.block()); + + // Ensure list numbers are incremented properly. + cursor.insertBlock(); + cursor.insertText("SecondList Item 1"); + list4->add(cursor.block()); + + const QString output = documentToUnixMarkdown(); + const QString expected = QString::fromLatin1( + R"(2. ListItem 1 + 1) ListItem 2 + 1. ListItem 3 +3. ListItem 4 + 2) ListItem 5 +0. SecondList Item 0 +1. SecondList Item 1 +)"); + +#ifdef DEBUG_WRITE_OUTPUT + { + QFile out(QDir::temp().filePath(QLatin1String(QTest::currentTestFunction()) + ".md")); + out.open(QFile::WriteOnly); + out.write(output.toUtf8()); + out.close(); + } + { + QFile out(QDir::temp().filePath(QLatin1String(QTest::currentTestFunction()) + ".html")); + out.open(QFile::WriteOnly); + out.write(document->toHtml().toUtf8()); + out.close(); + } +#endif + + if (output != expected && isMainFontFixed()) + QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue); + QCOMPARE(output, expected); } void tst_QTextMarkdownWriter::testWriteTable() @@ -312,6 +479,8 @@ void tst_QTextMarkdownWriter::testWriteTable() QString expected = QString::fromLatin1( "\n|one |two |three|\n|------|----|-----|\n|alice |bob |carl |\n|dennis|eric|fiona|\n|gina | | |\n\n"); + if (md != expected && isMainFontFixed()) + QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue); QCOMPARE(md, expected); // create table with merged cells @@ -361,7 +530,221 @@ void tst_QTextMarkdownWriter::testWriteTable() } #endif - QCOMPARE(md, QString::fromLatin1("\n|a ||b|\n|-|-|-|\n|c|d ||\n|e|f| |\n\n")); + expected = QString::fromLatin1("\n|a ||b|\n|-|-|-|\n|c|d ||\n|e|f| |\n\n"); + if (md != expected && isMainFontFixed()) + QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue); + QCOMPARE(md, expected); +} + +void tst_QTextMarkdownWriter::frontMatter() +{ + QTextCursor cursor(document); + cursor.insertText("bar"); + document->setMetaInformation(QTextDocument::FrontMatter, "foo"); + + const QString output = documentToUnixMarkdown(); + const QString expectedOutput("---\nfoo\n---\nbar\n\n"); + if (output != expectedOutput && isMainFontFixed()) + QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue); + QCOMPARE(output, expectedOutput); +} + +void tst_QTextMarkdownWriter::charFormatWrapping_data() +{ + QTest::addColumn<QTextFormat::Property>("property"); + QTest::addColumn<QVariant>("propertyValue"); + QTest::addColumn<QString>("followingText"); + QTest::addColumn<QString>("expectedIndicator"); + + const QString spaced = " after"; + const QString unspaced = ", and some more after"; + + QTest::newRow("FontFixedPitch-spaced") + << QTextFormat::FontFixedPitch << QVariant(true) << spaced << "`"; + QTest::newRow("FontFixedPitch-unspaced") + << QTextFormat::FontFixedPitch << QVariant(true) << unspaced << "`"; + QTest::newRow("FontItalic") + << QTextFormat::FontItalic << QVariant(true) << spaced << "*"; + QTest::newRow("FontUnderline") + << QTextFormat::FontUnderline << QVariant(true) << spaced << "_"; + QTest::newRow("FontStrikeOut") + << QTextFormat::FontStrikeOut << QVariant(true) << spaced << "~~"; + QTest::newRow("FontWeight-spaced") + << QTextFormat::FontWeight << QVariant(700) << spaced << "**"; + QTest::newRow("FontWeight-unspaced") + << QTextFormat::FontWeight << QVariant(700) << unspaced << "**"; +} + +void tst_QTextMarkdownWriter::charFormatWrapping() // QTBUG-116927 +{ + QFETCH(QTextFormat::Property, property); + QFETCH(QVariant, propertyValue); + QFETCH(QString, expectedIndicator); + QFETCH(QString, followingText); + + const QString newLine("\n"); + QTextCursor cursor(document); + cursor.insertText("around sixty-four characters to go before some formatted words "); + QTextCharFormat fmt; + fmt.setProperty(property, propertyValue); + cursor.setCharFormat(fmt); + cursor.insertText("formatted text"); + + cursor.setCharFormat({}); + cursor.insertText(followingText); + qsizetype lastNewLineIndex = 100; + + for (int push = 0; push < 10; ++push) { + if (push > 0) { + cursor.movePosition(QTextCursor::StartOfBlock); + cursor.insertText("a"); + } + + const QString output = documentToUnixMarkdown().trimmed(); // get rid of trailing newlines + const auto nlIdx = output.indexOf(newLine); + qCDebug(lcTests) << "push" << push << ":" << output << "newline @" << nlIdx; + // we're always wrapping in this test: expect to find a newline + QCOMPARE_GT(nlIdx, 70); + // don't expect the newline to be more than one character to the right of where we found it last time + // i.e. if we already started breaking in the middle: "`formatted\ntext`", + // then we would not expect that prepending one more character would make it go + // back to breaking afterwards: "`formatted text`\n" (because then the line becomes longer than necessary) + QCOMPARE_LE(nlIdx, lastNewLineIndex + 1); + lastNewLineIndex = nlIdx; + const QString nextChars = output.sliced(nlIdx + newLine.size(), expectedIndicator.size()); + const auto startingIndicatorIdx = output.indexOf(expectedIndicator); + // the starting indicator always exists, except in case of font problems on some CI platforms + if (startingIndicatorIdx <= 0) + QSKIP("starting indicator not found, probably due to platform font problems (QTBUG-103484 etc.)"); + const auto endingIndicatorIdx = output.indexOf(expectedIndicator, startingIndicatorIdx + 5); + qCDebug(lcTests) << "next chars past newline" << nextChars + << "indicators @" << startingIndicatorIdx << endingIndicatorIdx; + // the closing indicator must exist + QCOMPARE_GT(endingIndicatorIdx, startingIndicatorIdx); + // don't start a new line with an ending indicator: + // we can have "**formatted\ntext**" or "**formatted text**\n" or "\n**formatted text**" + // but not "**formatted text\n**" + if (startingIndicatorIdx < nlIdx) + QCOMPARE_NE(nextChars, expectedIndicator); + } +} + +void tst_QTextMarkdownWriter::charFormat_data() +{ + QTest::addColumn<QTextFormat::Property>("property"); + QTest::addColumn<QVariant>("propertyValue"); + QTest::addColumn<QFont>("explicitFont"); + QTest::addColumn<QString>("expectedOutput"); + + const QTextFormat::Property NoProperty = QTextFormat::ObjectIndex; + + QTest::newRow("FontFixedPitch") + << QTextFormat::FontFixedPitch << QVariant(true) << m_defaultFont + << "before `formatted` after"; + if (!isFixedFontProportional()) { + // QTBUG-54623 QTBUG-75649 QTBUG-79900 QTBUG-103484 etc. + QTest::newRow("mono font") << NoProperty << QVariant() << m_monoFont + << "before `formatted` after"; + } + + { + QFont font; + font.setItalic(true); + QTest::newRow("italic font") + << NoProperty << QVariant() << font + << "before *formatted* after"; + } + QTest::newRow("FontItalic") + << QTextFormat::FontItalic << QVariant(true) << m_defaultFont + << "before *formatted* after"; + + { + QFont font; + font.setUnderline(true); + QTest::newRow("underline font") + << NoProperty << QVariant() << font + << "before _formatted_ after"; + } + QTest::newRow("FontUnderline") + << QTextFormat::FontUnderline << QVariant(true) << m_defaultFont + << "before _formatted_ after"; + + { + QFont font; + font.setStrikeOut(true); + QTest::newRow("strikeout font") + << NoProperty << QVariant() << font + << "before ~~formatted~~ after"; + } + QTest::newRow("FontStrikeOut") + << QTextFormat::FontStrikeOut << QVariant(true) << m_defaultFont + << "before ~~formatted~~ after"; + + { + QFont font; + font.setBold(true); + QTest::newRow("bold font") + << NoProperty << QVariant() << font + << "before **formatted** after"; + } + { + QFont font; + font.setWeight(QFont::Black); + QTest::newRow("black font") + << NoProperty << QVariant() << font + << "before **formatted** after"; + } + QTest::newRow("FontWeight") + << QTextFormat::FontWeight << QVariant(700) << m_defaultFont + << "before **formatted** after"; + + QTest::newRow("AnchorHref") + << QTextFormat::AnchorHref << QVariant("linky linky") << m_defaultFont + << "before [formatted](linky linky) after"; + + QTest::newRow("TextToolTip") // no effect without AnchorHref + << QTextFormat::TextToolTip << QVariant("such a tool") << m_defaultFont + << "before formatted after"; +} + +void tst_QTextMarkdownWriter::charFormat() +{ + if (isMainFontFixed()) + QSKIP("QTextMarkdownWriter would generate bogus backticks"); + + QFETCH(QTextFormat::Property, property); + QFETCH(QVariant, propertyValue); + QFETCH(QFont, explicitFont); + QFETCH(QString, expectedOutput); + + QTextCursor cursor(document); + cursor.insertText("before "); + + QTextCharFormat fmt; + if (explicitFont != m_defaultFont) + fmt.setFont(explicitFont); + if (property != QTextFormat::ObjectIndex) // != 0 + fmt.setProperty(property, propertyValue); + if (explicitFont == m_monoFont) { + QFontInfo fontInfo(fmt.font()); + qCDebug(lcTests) << "mono font" << explicitFont << "fontInfo fixedPitch" << fontInfo.fixedPitch() << "fmt fixedPitch" << fmt.fontFixedPitch(); + } + cursor.setCharFormat(fmt); + cursor.insertText("formatted"); + + cursor.setCharFormat({}); + cursor.insertText(" after"); + + const QString output = documentToUnixMarkdown(); +#ifdef DEBUG_WRITE_OUTPUT + { + QFile out(QDir::temp().filePath(QLatin1String(QTest::currentDataTag()) + ".md")); + out.open(QFile::WriteOnly); + out.write(output.toUtf8()); + out.close(); + } +#endif + QCOMPARE(output.trimmed(), expectedOutput); } void tst_QTextMarkdownWriter::rewriteDocument_data() @@ -369,11 +752,15 @@ void tst_QTextMarkdownWriter::rewriteDocument_data() QTest::addColumn<QString>("inputFile"); QTest::newRow("block quotes") << "blockquotes.md"; + QTest::newRow("block quotes with lists") << "blockquotesWithLists.md"; + // QTest::newRow("list item with block quote") << "listItemWithBlockquote.md"; // not supported for now QTest::newRow("example") << "example.md"; QTest::newRow("list items after headings") << "headingsAndLists.md"; QTest::newRow("word wrap") << "wordWrap.md"; QTest::newRow("links") << "links.md"; QTest::newRow("lists and code blocks") << "listsAndCodeBlocks.md"; + QTest::newRow("front matter") << "yaml.md"; + QTest::newRow("long headings") << "longHeadings.md"; } void tst_QTextMarkdownWriter::rewriteDocument() @@ -394,17 +781,19 @@ void tst_QTextMarkdownWriter::rewriteDocument() out.close(); #endif + if (md != orig && isMainFontFixed()) + QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue); QCOMPARE(md, orig); } void tst_QTextMarkdownWriter::fromHtml_data() { - QTest::addColumn<QString>("expectedInput"); + QTest::addColumn<QString>("input"); QTest::addColumn<QString>("expectedOutput"); QTest::newRow("long URL") << "<span style=\"font-style:italic;\">https://www.example.com/dir/subdir/subsubdir/subsubsubdir/subsubsubsubdir/subsubsubsubsubdir/</span>" << - "*https://www.example.com/dir/subdir/subsubdir/subsubsubdir/subsubsubsubdir/subsubsubsubsubdir/*\n\n"; + "\n*https://www.example.com/dir/subdir/subsubdir/subsubsubdir/subsubsubsubdir/subsubsubsubsubdir/*\n\n"; QTest::newRow("non-emphasis inline asterisk") << "3 * 4" << "3 * 4\n\n"; QTest::newRow("arithmetic") << "(2 * a * x + b)^2 = b^2 - 4 * a * c" << "(2 * a * x + b)^2 = b^2 - 4 * a * c\n\n"; QTest::newRow("escaped asterisk after newline") << @@ -436,22 +825,51 @@ void tst_QTextMarkdownWriter::fromHtml_data() "![foo](/url \"title\")\n\n"; QTest::newRow("code") << "<pre class=\"language-pseudocode\">\n#include \"foo.h\"\n\nblock {\n statement();\n}\n\n</pre>" << - "```pseudocode\n#include \"foo.h\"\n\nblock {\n statement();\n}\n```\n\n"; - // TODO -// QTest::newRow("escaped number and paren after double newline") << -// "<p>(The first sentence of this paragraph is a line, the next paragraph has a number</p>13) but that's not part of an ordered list" << -// "(The first sentence of this paragraph is a line, the next paragraph has a number\n\n13\\) but that's not part of an ordered list\n\n"; + "```pseudocode\n#include \"foo.h\"\n\nblock {\n statement();\n}\n\n```\n\n"; + QTest::newRow("escaped number and paren after single newline") << + "<p>(The first sentence of this paragraph is a line, next paragraph has a number 13) but that's not part of an ordered list</p>" << + "(The first sentence of this paragraph is a line, next paragraph has a number\n13\\) but that's not part of an ordered list\n\n"; + QTest::newRow("escaped number and paren after double newline") << + "<p>(The first sentence of this paragraph is a line, the next paragraph has a number</p>13) but that's not part of an ordered list" << + "(The first sentence of this paragraph is a line, the next paragraph has a number\n\n13\\) but that's not part of an ordered list\n\n"; QTest::newRow("preformats with embedded backticks") << - "<pre>none `one` ``two``</pre><pre>```three``` ````four````</pre>plain" << - "``` none `one` ``two`` ```\n\n````` ```three``` ````four```` `````\n\nplain\n\n"; + "<pre>none `one` ``two``</pre>plain<pre>```three``` ````four````</pre>plain" << + "```\nnone `one` ``two``\n\n```\nplain\n\n```\n```three``` ````four````\n\n```\nplain\n\n"; + QTest::newRow("list items with and without checkboxes") << + "<ul><li>bullet</li><li class=\"unchecked\">unchecked item</li><li class=\"checked\">checked item</li></ul>" << + "- bullet\n- [ ] unchecked item\n- [x] checked item\n"; + QTest::newRow("table with backslash in cell") << // QTBUG-96051 + "<table><tr><td>1011011 [</td><td>1011100 backslash \\</td></tr></table>" << + "|1011011 [|1011100 backslash \\\\|"; + // https://spec.commonmark.org/0.31.2/#example-12 + // escaping punctuation is ok, but QTextMarkdownWriter currently doesn't do that (which is also ok) + QTest::newRow("punctuation") << + R"(<p>!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~</p>)" << + R"(!"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~)"; + // https://spec.commonmark.org/0.31.2/#example-14 + QTest::newRow("backslash asterisk no emphasis") << // QTBUG-122083 + R"(\*no emphasis*)" << + R"(\\\*no emphasis*)"; + // https://spec.commonmark.org/0.31.2/#example-15 + QTest::newRow("backslash before emphasis") << + R"(\<em>emphasis</em>)" << + R"(\\*emphasis*)"; + // https://spec.commonmark.org/0.31.2/#example-20 + QTest::newRow("backslash-asterisk in autolink") << + R"(<p><a href="https://example.com?find=\\*">https://example.com?find=\*</a></p>)" << + R"(<https://example.com?find=\\*>)"; + // https://spec.commonmark.org/0.31.2/#example-24 + QTest::newRow("plus in fenced code lang") << + "<pre class=\"language-foo+bar\">foo</pre>" << + "```foo+bar\nfoo\n```"; } void tst_QTextMarkdownWriter::fromHtml() { - QFETCH(QString, expectedInput); + QFETCH(QString, input); QFETCH(QString, expectedOutput); - document->setHtml(expectedInput); + document->setHtml(input); QString output = documentToUnixMarkdown(); #ifdef DEBUG_WRITE_OUTPUT @@ -463,16 +881,140 @@ void tst_QTextMarkdownWriter::fromHtml() } #endif + output = output.trimmed(); + expectedOutput = expectedOutput.trimmed(); + if (output != expectedOutput && (isMainFontFixed() || isFixedFontProportional())) + QEXPECT_FAIL("", "fixed main font or proportional fixed font (QTBUG-103484)", Continue); QCOMPARE(output, expectedOutput); } -QString tst_QTextMarkdownWriter::documentToUnixMarkdown() +void tst_QTextMarkdownWriter::fromPlainTextAndBack_data() { - QString ret; - QTextStream ts(&ret, QIODevice::WriteOnly); - QTextMarkdownWriter writer(ts, QTextDocument::MarkdownDialectGitHub); - writer.writeAll(document); - return ret; + QTest::addColumn<QString>("input"); + QTest::addColumn<QString>("expectedMarkdown"); + + // tests to verify that fixing QTBUG-122083 is safe + QTest::newRow("single backslashes") << + R"(\ again: \ not esc: \* \-\-\ \*abc*)" << + R"(\\ again: \\ not esc: \\* \\-\\-\\ \\\*abc*)"; + // https://spec.commonmark.org/0.31.2/#example-12 + QTest::newRow("punctuation") << + R"(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)" << + R"(!"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~)"; + // https://spec.commonmark.org/0.31.2/#example-13 + QTest::newRow("literal backslashes") << + QString(uR"(\→\A\a\ \3\φ\«)") << + "\\\\\u2192\\\\A\\\\a\\\\ \\\\3\\\\\u03C6\\\\\u00AB"; + // https://spec.commonmark.org/0.31.2/#example-14 + QTest::newRow("escape to avoid em") << + R"(*not emphasized*)" << + R"(\*not emphasized*)"; + QTest::newRow("escape to avoid html") << + R"(<br/> not a tag)" << + R"(\<br/> not a tag)"; + QTest::newRow("escape to avoid link") << + R"([not a link](/foo))" << + R"(\[not a link](/foo))"; + QTest::newRow("escape to avoid mono") << + R"(`not code`)" << + R"(\`not code`)"; + QTest::newRow("escape to avoid num list") << + R"(1. not a list)" << + R"(1\. not a list)"; + QTest::newRow("escape to avoid list") << + R"(* not a list)" << + R"(\* not a list)"; + QTest::newRow("escape to avoid heading") << + R"(# not a heading)" << + R"(\# not a heading)"; + QTest::newRow("escape to avoid reflink") << + R"([foo]: /url "not a reference")" << + R"(\[foo]: /url "not a reference")"; + QTest::newRow("escape to avoid entity") << + R"(ö not a character entity)" << + R"(\ö not a character entity)"; + // end of tests to verify that fixing QTBUG-122083 is safe + // (it's ok to add unrelated plain-to-markdown-to-plaintext cases later) +} + +void tst_QTextMarkdownWriter::fromPlainTextAndBack() +{ + QFETCH(QString, input); + QFETCH(QString, expectedMarkdown); + + document->setPlainText(input); + QString output = documentToUnixMarkdown(); + +#ifdef DEBUG_WRITE_OUTPUT + { + QFile out("/tmp/" + QLatin1String(QTest::currentDataTag()) + ".md"); + out.open(QFile::WriteOnly); + out.write(output.toUtf8()); + out.close(); + } +#endif + + output = output.trimmed(); + expectedMarkdown = expectedMarkdown.trimmed(); + if (output != expectedMarkdown && (isMainFontFixed() || isFixedFontProportional())) + QSKIP("", "fixed main font or proportional fixed font (QTBUG-103484)"); + QCOMPARE(output, expectedMarkdown); + QCOMPARE(document->toPlainText(), input); + document->setMarkdown(output); + QCOMPARE(document->toPlainText(), input); + if (document->blockCount() == 1) + QCOMPARE(document->firstBlock().text(), input); +} + +void tst_QTextMarkdownWriter::escapeSpecialCharacters_data() +{ + QTest::addColumn<QString>("input"); + QTest::addColumn<QString>("expectedOutput"); + + QTest::newRow("backslash") << "foo \\ bar \\\\ baz \\" << "foo \\\\ bar \\\\\\\\ baz \\\\"; + QTest::newRow("not emphasized") << "*normal* **normal too**" << "\\*normal* \\**normal too**"; + QTest::newRow("not code") << "`normal` `normal too`" << "\\`normal` \\`normal too`"; + QTest::newRow("code fence") << "```not a fence; ``` no risk here; ```not a fence" // TODO slightly inconsistent + << "\\```not a fence; ``` no risk here; \\```not a fence"; + QTest::newRow("not html") << "<p>not a tag: <br/> nope</p>" << "\\<p>not a tag: \\<br/> nope\\</p>"; + QTest::newRow("not a link") << "text [not a link](/foo)" << "text \\[not a link](/foo)"; + QTest::newRow("not a circle") << "* polaris" << "\\* polaris"; + QTest::newRow("not a square") << "+ groovy" << "\\+ groovy"; + QTest::newRow("not a bullet") << "- stayin alive" << "\\- stayin alive"; + QTest::newRow("arithmetic") << "1 + 2 - 3 * 4" << "1 + 2 - 3 * 4"; + QTest::newRow("not a list") << "1. not a list" << "1\\. not a list"; + QTest::newRow("not a list either") << "Jupiter and 10." << "Jupiter and 10."; + QTest::newRow("not a heading") << "# not a heading" << "\\# not a heading"; + QTest::newRow("a non-entity") << "ö not a character entity" << "\\ö not a character entity"; +} + +/*! \internal + If the user types into a Qt-based editor plain text that the + markdown parser would misinterpret, escape it when we save to markdown + to clarify that it's plain text. + https://spec.commonmark.org/0.31.2/#backslash-escapes +*/ +void tst_QTextMarkdownWriter::escapeSpecialCharacters() // QTBUG-96051, QTBUG-122083 +{ + QFETCH(QString, input); + QFETCH(QString, expectedOutput); + + document->setPlainText(input); + QString output = documentToUnixMarkdown(); + +#ifdef DEBUG_WRITE_OUTPUT + { + QFile out("/tmp/" + QLatin1String(QTest::currentDataTag()) + ".md"); + out.open(QFile::WriteOnly); + out.write(output.toUtf8()); + out.close(); + } +#endif + + output = output.trimmed(); + if (output != expectedOutput && (isMainFontFixed() || isFixedFontProportional())) + QEXPECT_FAIL("", "fixed main font or proportional fixed font (QTBUG-103484)", Continue); + QCOMPARE(output, expectedOutput); } QTEST_MAIN(tst_QTextMarkdownWriter) diff --git a/tests/auto/gui/text/qtextobject/CMakeLists.txt b/tests/auto/gui/text/qtextobject/CMakeLists.txt index 07ea132de0..dd7aeae60e 100644 --- a/tests/auto/gui/text/qtextobject/CMakeLists.txt +++ b/tests/auto/gui/text/qtextobject/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qtextobject.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtextobject Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtextobject LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtextobject SOURCES tst_qtextobject.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) @@ -15,6 +22,6 @@ qt_internal_add_test(tst_qtextobject ##################################################################### qt_internal_extend_target(tst_qtextobject CONDITION TARGET Qt::Widgets - PUBLIC_LIBRARIES + LIBRARIES Qt::Widgets ) diff --git a/tests/auto/gui/text/qtextobject/tst_qtextobject.cpp b/tests/auto/gui/text/qtextobject/tst_qtextobject.cpp index 8a84dfd40c..e75dfcb270 100644 --- a/tests/auto/gui/text/qtextobject/tst_qtextobject.cpp +++ b/tests/auto/gui/text/qtextobject/tst_qtextobject.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/gui/text/qtextodfwriter/CMakeLists.txt b/tests/auto/gui/text/qtextodfwriter/CMakeLists.txt index 2a468b0c5e..d371fe2ee1 100644 --- a/tests/auto/gui/text/qtextodfwriter/CMakeLists.txt +++ b/tests/auto/gui/text/qtextodfwriter/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qtextodfwriter.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtextodfwriter Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtextodfwriter LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtextodfwriter SOURCES tst_qtextodfwriter.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/text/qtextodfwriter/tst_qtextodfwriter.cpp b/tests/auto/gui/text/qtextodfwriter/tst_qtextodfwriter.cpp index 30185e83b9..6b56e7c727 100644 --- a/tests/auto/gui/text/qtextodfwriter/tst_qtextodfwriter.cpp +++ b/tests/auto/gui/text/qtextodfwriter/tst_qtextodfwriter.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QTextDocument> @@ -79,7 +79,7 @@ QString tst_QTextOdfWriter::getContentFromXml() if (index > 0) { index = stringContent.indexOf('>', index); if (index > 0) - ret = stringContent.mid(index+1, stringContent.length() - index - 10); + ret = stringContent.mid(index+1, stringContent.size() - index - 10); } return ret; } @@ -279,7 +279,7 @@ file.open(QIODevice::WriteOnly); file.write(buffer->data()); file.close(); */ - QVERIFY(buffer->data().length() > 80); + QVERIFY(buffer->data().size() > 80); QCOMPARE(buffer->data()[0], 'P'); // its a zip :) QCOMPARE(buffer->data()[1], 'K'); QString mimetype(buffer->data().mid(38, 39)); diff --git a/tests/auto/gui/text/qtextpiecetable/CMakeLists.txt b/tests/auto/gui/text/qtextpiecetable/CMakeLists.txt index 49cfcfab6a..8bdf17890c 100644 --- a/tests/auto/gui/text/qtextpiecetable/CMakeLists.txt +++ b/tests/auto/gui/text/qtextpiecetable/CMakeLists.txt @@ -1,4 +1,11 @@ -# Generated from qtextpiecetable.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_qtextpiecetable LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() if(WIN32) return() @@ -15,11 +22,8 @@ qt_internal_add_test(tst_qtextpiecetable SOURCES ../qtextdocument/common.h tst_qtextpiecetable.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate ) - -#### Keys ignored in scope 1:.:.:qtextpiecetable.pro:<TRUE>: -# _REQUIREMENTS = "!win32" "qtConfig(private_tests)" diff --git a/tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp b/tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp index 71afd31574..f47d5dc0d6 100644 --- a/tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp +++ b/tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -99,21 +99,21 @@ void tst_QTextPieceTable::cleanup() void tst_QTextPieceTable::insertion1() { - table->insert(0, "aacc", charFormatIndex); + table->insert(0, u"aacc", charFormatIndex); QCOMPARE(table->plainText(), QString("aacc")); - table->insert(2, "bb", charFormatIndex); + table->insert(2, u"bb", charFormatIndex); QCOMPARE(table->plainText(), QString("aabbcc")); - table->insert(1, "1", charFormatIndex); + table->insert(1, u"1", charFormatIndex); QCOMPARE(table->plainText(), QString("a1abbcc")); - table->insert(6, "d", charFormatIndex); + table->insert(6, u"d", charFormatIndex); QCOMPARE(table->plainText(), QString("a1abbcdc")); - table->insert(8, "z", charFormatIndex); + table->insert(8, u"z", charFormatIndex); QCOMPARE(table->plainText(), QString("a1abbcdcz")); } void tst_QTextPieceTable::insertion2() { - table->insert(0, "bb", charFormatIndex); + table->insert(0, u"bb", charFormatIndex); QCOMPARE(table->plainText(), QString("bb")); } @@ -176,21 +176,21 @@ void tst_QTextPieceTable::insertion5() void tst_QTextPieceTable::removal1() { - table->insert(0, "abbccc", charFormatIndex); + table->insert(0, u"abbccc", charFormatIndex); QCOMPARE(table->plainText(), QString("abbccc")); table->remove(1, 2); QCOMPARE(table->plainText(), QString("accc")); - table->insert(1, "1", charFormatIndex); + table->insert(1, u"1", charFormatIndex); QCOMPARE(table->plainText(), QString("a1ccc")); table->remove(4, 1); QCOMPARE(table->plainText(), QString("a1cc")); - table->insert(4, "z", charFormatIndex); + table->insert(4, u"z", charFormatIndex); QCOMPARE(table->plainText(), QString("a1ccz")); } void tst_QTextPieceTable::removal2() { - table->insert(0, "bb", charFormatIndex); + table->insert(0, u"bb", charFormatIndex); QCOMPARE(table->plainText(), QString("bb")); table->remove(0, 2); QCOMPARE(table->plainText(), QString("")); @@ -199,7 +199,7 @@ void tst_QTextPieceTable::removal2() table->remove(0, 1); QCOMPARE(table->plainText(), QString("")); - table->insert(0, "bb", charFormatIndex); + table->insert(0, u"bb", charFormatIndex); QCOMPARE(table->plainText(), QString("bb")); table->insertBlock(1, blockFormatIndex, charFormatIndex); QCOMPARE(table->plainText(), QString("b") + QString(QChar(QChar::ParagraphSeparator)) + QString("b")); @@ -270,16 +270,16 @@ void tst_QTextPieceTable::removal4() void tst_QTextPieceTable::undoRedo1() { - table->insert(0, "01234567", charFormatIndex); - table->insert(0, "a", charFormatIndex); - table->insert(1, "b", charFormatIndex); + table->insert(0, u"01234567", charFormatIndex); + table->insert(0, u"a", charFormatIndex); + table->insert(1, u"b", charFormatIndex); QCOMPARE(table->plainText(), QString("ab01234567")); table->undo(); QCOMPARE(table->plainText(), QString("01234567")); table->redo(); QCOMPARE(table->plainText(), QString("ab01234567")); table->undo(); - table->insert(1, "c", charFormatIndex); + table->insert(1, u"c", charFormatIndex); QCOMPARE(table->plainText(), QString("0c1234567")); table->undo(); QCOMPARE(table->plainText(), QString("01234567")); @@ -289,8 +289,8 @@ void tst_QTextPieceTable::undoRedo1() void tst_QTextPieceTable::undoRedo2() { - table->insert(0, "01", charFormatIndex); - table->insert(1, "a", charFormatIndex); + table->insert(0, u"01", charFormatIndex); + table->insert(1, u"a", charFormatIndex); QCOMPARE(table->plainText(), QString("0a1")); table->undo(); QCOMPARE(table->plainText(), QString("01")); @@ -304,8 +304,8 @@ void tst_QTextPieceTable::undoRedo2() void tst_QTextPieceTable::undoRedo3() { - table->insert(0, "01", charFormatIndex); - table->insert(2, "ab", charFormatIndex); + table->insert(0, u"01", charFormatIndex); + table->insert(2, u"ab", charFormatIndex); table->remove(2, 1); QCOMPARE(table->plainText(), QString("01b")); table->undo(); @@ -320,8 +320,8 @@ void tst_QTextPieceTable::undoRedo3() void tst_QTextPieceTable::undoRedo4() { - table->insert(0, "01", charFormatIndex); - table->insert(0, "ab", charFormatIndex); + table->insert(0, u"01", charFormatIndex); + table->insert(0, u"ab", charFormatIndex); table->remove(0, 1); QCOMPARE(table->plainText(), QString("b01")); table->undo(); @@ -341,7 +341,7 @@ void tst_QTextPieceTable::undoRedo4() void tst_QTextPieceTable::undoRedo5() { table->beginEditBlock(); - table->insert(0, "01", charFormatIndex); + table->insert(0, u"01", charFormatIndex); table->remove(1, 1); table->endEditBlock(); QCOMPARE(table->plainText(), QString("0")); @@ -384,8 +384,8 @@ void tst_QTextPieceTable::undoRedo6() void tst_QTextPieceTable::undoRedo7() { - table->insert(0, "a", charFormatIndex); - table->insert(1, "b", charFormatIndex); + table->insert(0, u"a", charFormatIndex); + table->insert(1, u"b", charFormatIndex); QCOMPARE(table->plainText(), QString("ab")); table->undo(); @@ -394,8 +394,8 @@ void tst_QTextPieceTable::undoRedo7() void tst_QTextPieceTable::undoRedo8() { - table->insert(0, "a", charFormatIndex); - table->insert(1, "b", charFormatIndex); + table->insert(0, u"a", charFormatIndex); + table->insert(1, u"b", charFormatIndex); QCOMPARE(table->plainText(), QString("ab")); table->remove(0, 1); @@ -408,8 +408,8 @@ void tst_QTextPieceTable::undoRedo8() void tst_QTextPieceTable::undoRedo9() { - table->insert(0, "a", charFormatIndex); - table->insert(1, "b", charFormatIndex); + table->insert(0, u"a", charFormatIndex); + table->insert(1, u"b", charFormatIndex); QCOMPARE(table->plainText(), QString("ab")); table->remove(1, 1); @@ -430,9 +430,9 @@ void tst_QTextPieceTable::undoRedo10() QTextBlockFormat f; int idx = table->formatCollection()->indexForFormat(f); - table->insert(0, "a", cfIdx); + table->insert(0, u"a", cfIdx); table->insertBlock(1, idx, cfIdx); - table->insert(1, "b", cfIdx); + table->insert(1, u"b", cfIdx); cf.setForeground(Qt::red); int newCfIdx = table->formatCollection()->indexForFormat(cf); @@ -485,7 +485,7 @@ void tst_QTextPieceTable::checkDocumentChanged() // single insert layout->expect(0, 0, 15); - table->insert(0, "012345678901234", charFormatIndex); + table->insert(0, u"012345678901234", charFormatIndex); QVERIFY(!layout->error); // single remove @@ -496,7 +496,7 @@ void tst_QTextPieceTable::checkDocumentChanged() // symmetric insert/remove layout->expect(0, 0, 0); table->beginEditBlock(); - table->insert(0, "01234", charFormatIndex); + table->insert(0, u"01234", charFormatIndex); table->remove(0, 5); table->endEditBlock(); QVERIFY(!layout->error); @@ -504,7 +504,7 @@ void tst_QTextPieceTable::checkDocumentChanged() layout->expect(0, 5, 5); table->beginEditBlock(); table->remove(0, 5); - table->insert(0, "01234", charFormatIndex); + table->insert(0, u"01234", charFormatIndex); table->endEditBlock(); QVERIFY(!layout->error); @@ -512,13 +512,13 @@ void tst_QTextPieceTable::checkDocumentChanged() layout->expect(0, 3, 5); table->beginEditBlock(); table->remove(0, 3); - table->insert(0, "01234", charFormatIndex); + table->insert(0, u"01234", charFormatIndex); table->endEditBlock(); QVERIFY(!layout->error); layout->expect(0, 0, 2); table->beginEditBlock(); - table->insert(0, "01234", charFormatIndex); + table->insert(0, u"01234", charFormatIndex); table->remove(0, 3); table->endEditBlock(); QVERIFY(!layout->error); @@ -526,14 +526,14 @@ void tst_QTextPieceTable::checkDocumentChanged() // insert + remove inside insert block layout->expect(0, 0, 2); table->beginEditBlock(); - table->insert(0, "01234", charFormatIndex); + table->insert(0, u"01234", charFormatIndex); table->remove(1, 3); table->endEditBlock(); QVERIFY(!layout->error); layout->expect(0, 0, 2); table->beginEditBlock(); - table->insert(0, "01234", charFormatIndex); + table->insert(0, u"01234", charFormatIndex); table->remove(2, 3); table->endEditBlock(); QVERIFY(!layout->error); @@ -541,42 +541,42 @@ void tst_QTextPieceTable::checkDocumentChanged() // insert + remove partly outside layout->expect(0, 1, 0); table->beginEditBlock(); - table->insert(1, "0", charFormatIndex); + table->insert(1, u"0", charFormatIndex); table->remove(0, 2); table->endEditBlock(); QVERIFY(!layout->error); layout->expect(0, 1, 1); table->beginEditBlock(); - table->insert(1, "01", charFormatIndex); + table->insert(1, u"01", charFormatIndex); table->remove(0, 2); table->endEditBlock(); QVERIFY(!layout->error); layout->expect(0, 1, 2); table->beginEditBlock(); - table->insert(1, "012", charFormatIndex); + table->insert(1, u"012", charFormatIndex); table->remove(0, 2); table->endEditBlock(); QVERIFY(!layout->error); layout->expect(1, 1, 0); table->beginEditBlock(); - table->insert(1, "0", charFormatIndex); + table->insert(1, u"0", charFormatIndex); table->remove(1, 2); table->endEditBlock(); QVERIFY(!layout->error); layout->expect(1, 1, 1); table->beginEditBlock(); - table->insert(1, "01", charFormatIndex); + table->insert(1, u"01", charFormatIndex); table->remove(2, 2); table->endEditBlock(); QVERIFY(!layout->error); layout->expect(1, 1, 2); table->beginEditBlock(); - table->insert(1, "012", charFormatIndex); + table->insert(1, u"012", charFormatIndex); table->remove(3, 2); table->endEditBlock(); QVERIFY(!layout->error); @@ -584,14 +584,14 @@ void tst_QTextPieceTable::checkDocumentChanged() // insert + remove non overlapping layout->expect(0, 1, 1); table->beginEditBlock(); - table->insert(1, "0", charFormatIndex); + table->insert(1, u"0", charFormatIndex); table->remove(0, 1); table->endEditBlock(); QVERIFY(!layout->error); layout->expect(0, 2, 2); table->beginEditBlock(); - table->insert(2, "1", charFormatIndex); + table->insert(2, u"1", charFormatIndex); table->remove(0, 1); table->endEditBlock(); QVERIFY(!layout->error); @@ -599,14 +599,14 @@ void tst_QTextPieceTable::checkDocumentChanged() layout->expect(0, 2, 2); table->beginEditBlock(); table->remove(0, 1); - table->insert(1, "0", charFormatIndex); + table->insert(1, u"0", charFormatIndex); table->endEditBlock(); QVERIFY(!layout->error); layout->expect(0, 3, 3); table->beginEditBlock(); table->remove(0, 1); - table->insert(2, "1", charFormatIndex); + table->insert(2, u"1", charFormatIndex); table->endEditBlock(); @@ -631,9 +631,9 @@ void tst_QTextPieceTable::checkDocumentChanged2() layout->expect(0, 0, 12); table->beginEditBlock(); - table->insert(0, "0123", charFormatIndex); - table->insert(4, "4567", anotherCharFormatIndex); - table->insert(8, "8901", charFormatIndex); + table->insert(0, u"0123", charFormatIndex); + table->insert(4, u"4567", anotherCharFormatIndex); + table->insert(8, u"8901", charFormatIndex); table->endEditBlock(); QVERIFY(!layout->error); @@ -696,7 +696,7 @@ void tst_QTextPieceTable::blockInsertion2() int pos = 0; table->insertBlock(pos, blockFormatIndex, charFormatIndex); pos += 1; - table->insert(pos, "a", charFormatIndex); + table->insert(pos, u"a", charFormatIndex); pos += 1; pos -= 1; @@ -719,11 +719,11 @@ void tst_QTextPieceTable::blockRemoval1() int idx1 = table->formatCollection()->indexForFormat(fmt1); int idx2 = table->formatCollection()->indexForFormat(fmt2); - table->insert(0, "0123", charFormatIndex); + table->insert(0, u"0123", charFormatIndex); table->insertBlock(4, idx1, charFormatIndex); - table->insert(5, "5678", charFormatIndex); + table->insert(5, u"5678", charFormatIndex); table->insertBlock(9, idx2, charFormatIndex); - table->insert(10, "0123", charFormatIndex); + table->insert(10, u"0123", charFormatIndex); QCOMPARE(table->blocksFind(0).blockFormat(), QTextBlockFormat()); QCOMPARE(table->blocksFind(4).blockFormat(), QTextBlockFormat()); @@ -767,11 +767,11 @@ void tst_QTextPieceTable::blockRemoval2() int idx1 = table->formatCollection()->indexForFormat(fmt1); int idx2 = table->formatCollection()->indexForFormat(fmt2); - table->insert(0, "0123", charFormatIndex); + table->insert(0, u"0123", charFormatIndex); table->insertBlock(4, idx1, charFormatIndex); - table->insert(5, "5678", charFormatIndex); + table->insert(5, u"5678", charFormatIndex); table->insertBlock(9, idx2, charFormatIndex); - table->insert(10, "0123", charFormatIndex); + table->insert(10, u"0123", charFormatIndex); QCOMPARE(table->blocksFind(0).blockFormat(), QTextBlockFormat()); QCOMPARE(table->blocksFind(4).blockFormat(), QTextBlockFormat()); @@ -813,11 +813,11 @@ void tst_QTextPieceTable::blockRemoval3() int idx1 = table->formatCollection()->indexForFormat(fmt1); int idx2 = table->formatCollection()->indexForFormat(fmt2); - table->insert(0, "0123", charFormatIndex); + table->insert(0, u"0123", charFormatIndex); table->insertBlock(4, idx1, charFormatIndex); - table->insert(5, "5678", charFormatIndex); + table->insert(5, u"5678", charFormatIndex); table->insertBlock(9, idx2, charFormatIndex); - table->insert(10, "0123", charFormatIndex); + table->insert(10, u"0123", charFormatIndex); QCOMPARE(table->blocksFind(0).blockFormat(), QTextBlockFormat()); QCOMPARE(table->blocksFind(4).blockFormat(), QTextBlockFormat()); @@ -910,11 +910,11 @@ void tst_QTextPieceTable::blockRemoval5() int idx1 = table->formatCollection()->indexForFormat(fmt1); int idx2 = table->formatCollection()->indexForFormat(fmt2); - table->insert(0, "0123", charFormatIndex); + table->insert(0, u"0123", charFormatIndex); table->insertBlock(4, idx1, charFormatIndex); - table->insert(5, "5678", charFormatIndex); + table->insert(5, u"5678", charFormatIndex); table->insertBlock(9, idx2, charFormatIndex); - table->insert(10, "0123", charFormatIndex); + table->insert(10, u"0123", charFormatIndex); QCOMPARE(table->blocksFind(0).blockFormat(), QTextBlockFormat()); QCOMPARE(table->blocksFind(4).blockFormat(), QTextBlockFormat()); @@ -962,7 +962,7 @@ void tst_QTextPieceTable::checkBlockSeparation() void tst_QTextPieceTable::checkFrames1() { QTextFrameFormat ffmt; - table->insert(0, "Hello", charFormatIndex); + table->insert(0, u"Hello", charFormatIndex); QPointer<QTextFrame> frame = table->insertFrame(1, 3, ffmt); QTextFrame *root = table->rootFrame(); @@ -971,7 +971,7 @@ void tst_QTextPieceTable::checkFrames1() QVERIFY(root); QVERIFY(!root->parentFrame()); - QCOMPARE(root->childFrames().count(), 1); + QCOMPARE(root->childFrames().size(), 1); QVERIFY(frame->format() == ffmt); QCOMPARE(frame->firstPosition(), 2); QCOMPARE(frame->lastPosition(), 4); @@ -979,10 +979,10 @@ void tst_QTextPieceTable::checkFrames1() QPointer<QTextFrame> frame2 = table->insertFrame(2, 3, ffmt); - QCOMPARE(root->childFrames().count(), 1); + QCOMPARE(root->childFrames().size(), 1); QCOMPARE(root->childFrames().at(0), frame.data()); - QCOMPARE(frame->childFrames().count(), 1); - QCOMPARE(frame2->childFrames().count(), 0); + QCOMPARE(frame->childFrames().size(), 1); + QCOMPARE(frame2->childFrames().size(), 0); QCOMPARE(frame2->parentFrame(), frame.data()); QCOMPARE(frame2->firstPosition(), 3); QCOMPARE(frame2->lastPosition(), 4); @@ -993,10 +993,10 @@ void tst_QTextPieceTable::checkFrames1() table->removeFrame(frame); - QCOMPARE(root->childFrames().count(), 1); + QCOMPARE(root->childFrames().size(), 1); QCOMPARE(root->childFrames().at(0), frame2.data()); QVERIFY(!frame); - QCOMPARE(frame2->childFrames().count(), 0); + QCOMPARE(frame2->childFrames().size(), 0); QCOMPARE(frame2->parentFrame(), root); QCOMPARE(frame2->firstPosition(), 2); QCOMPARE(frame2->lastPosition(), 3); @@ -1005,11 +1005,11 @@ void tst_QTextPieceTable::checkFrames1() frame = table->frameAt(2); - QCOMPARE(root->childFrames().count(), 1); + QCOMPARE(root->childFrames().size(), 1); QCOMPARE(root->childFrames().at(0), frame.data()); - QCOMPARE(frame->childFrames().count(), 1); + QCOMPARE(frame->childFrames().size(), 1); QCOMPARE(frame->childFrames().at(0), frame2.data()); - QCOMPARE(frame2->childFrames().count(), 0); + QCOMPARE(frame2->childFrames().size(), 0); QCOMPARE(frame2->parentFrame(), frame.data()); QCOMPARE(frame2->firstPosition(), 3); QCOMPARE(frame2->lastPosition(), 4); @@ -1019,9 +1019,9 @@ void tst_QTextPieceTable::checkFrames1() table->undo(); - QCOMPARE(root->childFrames().count(), 1); + QCOMPARE(root->childFrames().size(), 1); QCOMPARE(root->childFrames().at(0), frame.data()); - QCOMPARE(frame->childFrames().count(), 0); + QCOMPARE(frame->childFrames().size(), 0); QVERIFY(!frame2); QCOMPARE(frame->firstPosition(), 2); @@ -1031,7 +1031,7 @@ void tst_QTextPieceTable::checkFrames1() void tst_QTextPieceTable::removeFrameDirect() { QTextFrameFormat ffmt; - table->insert(0, "Hello", charFormatIndex); + table->insert(0, u"Hello", charFormatIndex); QTextFrame *frame = table->insertFrame(1, 5, ffmt); @@ -1065,7 +1065,7 @@ void tst_QTextPieceTable::removeWithChildFrame() In this case frameAt(2) != frameAt(6), so the assertion in remove() needed an adjustement. */ QTextFrameFormat ffmt; - table->insert(0, "Hello World", charFormatIndex); + table->insert(0, u"Hello World", charFormatIndex); QTextFrame *frame = table->insertFrame(1, 6, ffmt); QTextFrame *childFrame = table->insertFrame(3, 5, ffmt); @@ -1095,7 +1095,7 @@ void tst_QTextPieceTable::clearWithFrames() The idea is to remove from [1] until [7]. */ QTextFrameFormat ffmt; - table->insert(0, "Hello World", charFormatIndex); + table->insert(0, u"Hello World", charFormatIndex); QTextFrame *firstFrame = table->insertFrame(1, 2, ffmt); QTextFrame *secondFrame = table->insertFrame(4, 6, ffmt); diff --git a/tests/auto/gui/text/qtextscriptengine/CMakeLists.txt b/tests/auto/gui/text/qtextscriptengine/CMakeLists.txt index 01d418ebd4..9bb9e4c13b 100644 --- a/tests/auto/gui/text/qtextscriptengine/CMakeLists.txt +++ b/tests/auto/gui/text/qtextscriptengine/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qtextscriptengine.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtextscriptengine Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtextscriptengine LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtextscriptengine SOURCES tst_qtextscriptengine.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/gui/text/qtextscriptengine/generate/CMakeLists.txt b/tests/auto/gui/text/qtextscriptengine/generate/CMakeLists.txt index d3b6b1dc6d..db284b2e1c 100644 --- a/tests/auto/gui/text/qtextscriptengine/generate/CMakeLists.txt +++ b/tests/auto/gui/text/qtextscriptengine/generate/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from generate.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## generate Binary: @@ -9,9 +10,8 @@ qt_internal_add_executable(generate SOURCES main.cpp INCLUDE_DIRECTORIES - . /usr/include/freetype2 - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui ) diff --git a/tests/auto/gui/text/qtextscriptengine/generate/main.cpp b/tests/auto/gui/text/qtextscriptengine/generate/main.cpp index fa0512fb50..5082c2b406 100644 --- a/tests/auto/gui/text/qtextscriptengine/generate/main.cpp +++ b/tests/auto/gui/text/qtextscriptengine/generate/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QApplication> diff --git a/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp b/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp index f28478dafd..975658005e 100644 --- a/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp +++ b/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <private/qfontengine_p.h> @@ -1094,11 +1094,12 @@ void tst_QTextScriptEngine::combiningMarks_qtbug15675_data() bool hasTests = false; - QStringList families; - families << QStringLiteral("Monaco"); - families << QStringLiteral("DejaVu Sans Mono"); + const QString families[] = { + QStringLiteral("Monaco"), + QStringLiteral("DejaVu Sans Mono"), + }; - foreach (const QString &family, families) { + for (const QString &family : families) { QFont font(family); font.setStyleStrategy(QFont::NoFontMerging); if (QFontInfo(font).family() != family) diff --git a/tests/auto/gui/text/qtexttable/CMakeLists.txt b/tests/auto/gui/text/qtexttable/CMakeLists.txt index 94d33d3530..e83a38f087 100644 --- a/tests/auto/gui/text/qtexttable/CMakeLists.txt +++ b/tests/auto/gui/text/qtexttable/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qtexttable.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtexttable Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtexttable LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtexttable SOURCES tst_qtexttable.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate ) @@ -16,6 +23,6 @@ qt_internal_add_test(tst_qtexttable ##################################################################### qt_internal_extend_target(tst_qtexttable CONDITION TARGET Qt::Widgets - PUBLIC_LIBRARIES + LIBRARIES Qt::Widgets ) diff --git a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp index bfead23d4d..a7e319ef62 100644 --- a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp +++ b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -75,6 +75,8 @@ private slots: #endif void checkBorderAttributes_data(); void checkBorderAttributes(); + void checkTableBorderAttributes_data(); + void checkTableBorderAttributes(); #ifndef QT_NO_WIDGETS void columnWidthWithSpans(); @@ -121,7 +123,7 @@ void tst_QTextTable::variousTableModifications() QTextTableFormat tableFmt; QTextTable *tab = cursor.insertTable(2, 2, tableFmt); - QCOMPARE(doc->toPlainText().length(), 5); + QCOMPARE(doc->toPlainText().size(), 5); QCOMPARE(tab, cursor.currentTable()); QCOMPARE(tab->columns(), 2); QCOMPARE(tab->rows(), 2); @@ -176,14 +178,14 @@ void tst_QTextTable::variousTableModifications() cursor.movePosition(QTextCursor::NextBlock); QCOMPARE(cursor.position(), 1); cursor.deleteChar(); - QCOMPARE(doc->toPlainText().length(), 5); + QCOMPARE(doc->toPlainText().size(), 5); cursor.movePosition(QTextCursor::NextBlock); QCOMPARE(cursor.position(), 2); cursor.deleteChar(); - QCOMPARE(doc->toPlainText().length(), 5); + QCOMPARE(doc->toPlainText().size(), 5); cursor.deletePreviousChar(); QCOMPARE(cursor.position(), 2); - QCOMPARE(doc->toPlainText().length(), 5); + QCOMPARE(doc->toPlainText().size(), 5); QTextTable *table = cursor.currentTable(); QCOMPARE(table->rows(), 2); @@ -192,16 +194,16 @@ void tst_QTextTable::variousTableModifications() table->insertRows(2, 1); QCOMPARE(table->rows(), 3); QCOMPARE(table->columns(), 2); - QCOMPARE(doc->toPlainText().length(), 7); + QCOMPARE(doc->toPlainText().size(), 7); table->insertColumns(2, 2); QCOMPARE(table->rows(), 3); QCOMPARE(table->columns(), 4); - QCOMPARE(doc->toPlainText().length(), 13); + QCOMPARE(doc->toPlainText().size(), 13); table->resize(4, 5); QCOMPARE(table->rows(), 4); QCOMPARE(table->columns(), 5); - QCOMPARE(doc->toPlainText().length(), 21); + QCOMPARE(doc->toPlainText().size(), 21); } void tst_QTextTable::tableShrinking() @@ -209,7 +211,7 @@ void tst_QTextTable::tableShrinking() QTextTableFormat tableFmt; cursor.insertTable(3, 4, tableFmt); - QCOMPARE(doc->toPlainText().length(), 13); + QCOMPARE(doc->toPlainText().size(), 13); QTextTable *table = cursor.currentTable(); QCOMPARE(table->rows(), 3); @@ -218,16 +220,16 @@ void tst_QTextTable::tableShrinking() table->removeRows(1, 1); QCOMPARE(table->rows(), 2); QCOMPARE(table->columns(), 4); - QCOMPARE(doc->toPlainText().length(), 9); + QCOMPARE(doc->toPlainText().size(), 9); table->removeColumns(1, 2); QCOMPARE(table->rows(), 2); QCOMPARE(table->columns(), 2); - QCOMPARE(doc->toPlainText().length(), 5); + QCOMPARE(doc->toPlainText().size(), 5); table->resize(1, 1); QCOMPARE(table->rows(), 1); QCOMPARE(table->columns(), 1); - QCOMPARE(doc->toPlainText().length(), 2); + QCOMPARE(doc->toPlainText().size(), 2); } void tst_QTextTable::spans() @@ -252,7 +254,7 @@ void tst_QTextTable::variousModifications2() QTextTableFormat tableFmt; cursor.insertTable(2, 5, tableFmt); - QCOMPARE(doc->toPlainText().length(), 11); + QCOMPARE(doc->toPlainText().size(), 11); QTextTable *table = cursor.currentTable(); QCOMPARE(cursor.position(), 1); QCOMPARE(table->rows(), 2); @@ -1148,8 +1150,8 @@ void tst_QTextTable::QTBUG31330_renderBackground() doc.print(&paintDevice); QVERIFY(paintDevice.pages >= 2); - QCOMPARE(engine.rects.count(), paintDevice.pages); - for (int i = 0; i < engine.rects.count(); ++i) { + QCOMPARE(engine.rects.size(), paintDevice.pages); + for (int i = 0; i < engine.rects.size(); ++i) { QRectF rect = engine.rects[i]; QVERIFY(rect.top() > 0); QVERIFY(rect.bottom() < 1000); @@ -1234,6 +1236,7 @@ void tst_QTextTable::checkBorderAttributes() QFETCH(QBrush, leftBorderBrush); QFETCH(QBrush, rightBorderBrush); +#ifndef QT_NO_TEXTHTMLPARSER QTextDocument doc; doc.setHtml(html); QTextCursor cursor(doc.firstBlock()); @@ -1259,6 +1262,75 @@ void tst_QTextTable::checkBorderAttributes() QCOMPARE(cellFormat.brushProperty(QTextFormat::TableCellRightBorderBrush), rightBorderBrush); } } +#endif +} + +void tst_QTextTable::checkTableBorderAttributes_data() +{ + QTest::addColumn<QString>("html"); + QTest::addColumn<qreal>("tableBorderWidth"); + QTest::addColumn<QTextFrameFormat::BorderStyle>("tableBorderStyle"); + QTest::addColumn<QBrush>("tableBorderBrush"); + + const QString tableHtmlStart = QStringLiteral("<html><head><style>"); + const QString tableHtmlEnd1 = QStringLiteral("</style></head><body>" + "<table><tr><td>One</td><td>Two</td></tr></table>" + "</body></html>"); + const QString tableHtmlEnd2 = QStringLiteral("</style></head><body>" + "<table border=10><tr><td>One</td><td>Two</td></tr></table>" + "</body></html>"); + + QTest::newRow("table-border-attributes-shorthand") + << QString("%1" + "table {" + "border: 2px solid red;" + "}" + "%2").arg(tableHtmlStart).arg(tableHtmlEnd1) + << 2.0 << QTextFrameFormat::BorderStyle_Solid << QBrush(Qt::red); + + QTest::newRow("table-border-attributes-explicit") + << QString("%1" + "table {" + "border-width: 2px;" + "border-color: red;" + "border-style: dashed;" + "}" + "%2").arg(tableHtmlStart).arg(tableHtmlEnd1) + << 2.0 << QTextFrameFormat::BorderStyle_Dashed << QBrush(Qt::red); + + QTest::newRow("table-border-override") + << QString("%1" + "table {" + "border: 2px solid red;" + "}" + "%2").arg(tableHtmlStart).arg(tableHtmlEnd2) + << 2.0 << QTextFrameFormat::BorderStyle_Solid << QBrush(Qt::red); + + QTest::newRow("table-border-default") + << QString("%1" + "%2").arg(tableHtmlStart).arg(tableHtmlEnd2) + << 10.0 << QTextFrameFormat::BorderStyle_Outset << QBrush(Qt::darkGray); +} + +void tst_QTextTable::checkTableBorderAttributes() +{ + QFETCH(QString, html); + QFETCH(qreal, tableBorderWidth); + QFETCH(QTextFrameFormat::BorderStyle, tableBorderStyle); + QFETCH(QBrush, tableBorderBrush); + +#ifndef QT_NO_TEXTHTMLPARSER + QTextDocument doc; + doc.setHtml(html); + QTextCursor cursor(doc.firstBlock()); + cursor.movePosition(QTextCursor::Right); + + QTextTable *currentTable = cursor.currentTable(); + QVERIFY(currentTable); + QCOMPARE(currentTable->format().border(), tableBorderWidth); + QCOMPARE(currentTable->format().borderStyle(), tableBorderStyle); + QCOMPARE(currentTable->format().borderBrush(), tableBorderBrush); +#endif } #ifndef QT_NO_WIDGETS @@ -1317,6 +1389,7 @@ void tst_QTextTable::columnWidthWithImage() QFETCH(QString, rightHtml); QFETCH(QSize, imageSize); +#ifndef QT_NO_TEXTHTMLPARSER QTextDocument doc; doc.setHtml(tableTemplate.arg(leftHtml).arg(rightHtml)); QTextEdit textEdit; @@ -1336,6 +1409,7 @@ void tst_QTextTable::columnWidthWithImage() const QRectF rightRect = currentTable->document()->documentLayout()->blockBoundingRect(block); QCOMPARE(leftRect.size().toSize(), imageSize); QVERIFY(rightRect.left() > leftRect.right()); +#endif } #endif diff --git a/tests/auto/gui/text/qzip/.gitignore b/tests/auto/gui/text/qzip/.gitignore deleted file mode 100644 index 2d7dfbe70c..0000000000 --- a/tests/auto/gui/text/qzip/.gitignore +++ /dev/null @@ -1 +0,0 @@ -tst_qzip diff --git a/tests/auto/gui/text/qzip/CMakeLists.txt b/tests/auto/gui/text/qzip/CMakeLists.txt deleted file mode 100644 index dceda50251..0000000000 --- a/tests/auto/gui/text/qzip/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -# Generated from qzip.pro. - -##################################################################### -## tst_qzip Test: -##################################################################### - -# Collect test data -file(GLOB_RECURSE test_data - RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - testdata/* -) - -qt_internal_add_test(tst_qzip - SOURCES - tst_qzip.cpp - PUBLIC_LIBRARIES - Qt::Gui - Qt::GuiPrivate - TESTDATA ${test_data} -) diff --git a/tests/auto/gui/text/qzip/testdata/symlink.zip b/tests/auto/gui/text/qzip/testdata/symlink.zip Binary files differdeleted file mode 100644 index 027f96477a..0000000000 --- a/tests/auto/gui/text/qzip/testdata/symlink.zip +++ /dev/null diff --git a/tests/auto/gui/text/qzip/testdata/test.zip b/tests/auto/gui/text/qzip/testdata/test.zip Binary files differdeleted file mode 100644 index a57ba4e2a9..0000000000 --- a/tests/auto/gui/text/qzip/testdata/test.zip +++ /dev/null diff --git a/tests/auto/gui/text/qzip/tst_qzip.cpp b/tests/auto/gui/text/qzip/tst_qzip.cpp deleted file mode 100644 index 128f0b3200..0000000000 --- a/tests/auto/gui/text/qzip/tst_qzip.cpp +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#include <QTest> -#include <QDebug> -#include <QBuffer> - -#include <private/qzipwriter_p.h> -#include <private/qzipreader_p.h> - -class tst_QZip : public QObject -{ - Q_OBJECT - -private slots: - void basicUnpack(); - void symlinks(); - void readTest(); - void createArchive(); -}; - -void tst_QZip::basicUnpack() -{ - QZipReader zip(QFINDTESTDATA("/testdata/test.zip"), QIODevice::ReadOnly); - QList<QZipReader::FileInfo> files = zip.fileInfoList(); - QCOMPARE(files.count(), 2); - - QZipReader::FileInfo fi = files.at(0); - QVERIFY(fi.isValid()); - QCOMPARE(fi.filePath, QString("test")); - QCOMPARE(uint(fi.isDir), (uint) 1); - QCOMPARE(uint(fi.isFile), (uint) 0); - QCOMPARE(uint(fi.isSymLink), (uint) 0); - - QCOMPARE(fi.permissions,QFile::Permissions( QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner - | QFile::ReadUser | QFile::WriteUser | QFile::ExeUser )); - - QCOMPARE(fi.lastModified, QDateTime::fromString("2005.11.11 13:08:02", "yyyy.MM.dd HH:mm:ss")); - - fi = files.at(1); - QVERIFY(fi.isValid()); - QCOMPARE(fi.filePath, QString("test/test.txt")); - QCOMPARE(uint(fi.isDir), (uint) 0); - QCOMPARE(uint(fi.isFile), (uint) 1); - QCOMPARE(uint(fi.isSymLink), (uint) 0); - - QVERIFY(fi.permissions == QFile::Permissions( QFile::ReadOwner | QFile::WriteOwner - | QFile::ReadUser | QFile::WriteUser )); - - QCOMPARE(fi.lastModified, QDateTime::fromString("2005.11.11 13:08:02", "yyyy.MM.dd HH:mm:ss")); - - QCOMPARE(zip.fileData("test/test.txt"), QByteArray("content\n")); - - fi = zip.entryInfoAt(-1); - QVERIFY(!fi.isValid()); -} - -void tst_QZip::symlinks() -{ - QZipReader zip(QFINDTESTDATA("/testdata/symlink.zip"), QIODevice::ReadOnly); - QList<QZipReader::FileInfo> files = zip.fileInfoList(); - QCOMPARE(files.count(), 2); - - QZipReader::FileInfo fi = files.at(0); - QVERIFY(fi.isValid()); - QCOMPARE(fi.filePath, QString("symlink")); - QVERIFY(!fi.isDir); - QVERIFY(!fi.isFile); - QVERIFY(fi.isSymLink); - - QCOMPARE(zip.fileData("symlink"), QByteArray("destination")); - - fi = files.at(1); - QVERIFY(fi.isValid()); - QCOMPARE(fi.filePath, QString("destination")); - QVERIFY(!fi.isDir); - QVERIFY(fi.isFile); - QVERIFY(!fi.isSymLink); -} - -void tst_QZip::readTest() -{ - QZipReader zip("foobar.zip", QIODevice::ReadOnly); // non existing file. - QList<QZipReader::FileInfo> files = zip.fileInfoList(); - QCOMPARE(files.count(), 0); - QByteArray b = zip.fileData("foobar"); - QCOMPARE(b.size(), 0); -} - -void tst_QZip::createArchive() -{ - QBuffer buffer; - QZipWriter zip(&buffer); - QByteArray fileContents("simple file contents\nline2\n"); - zip.addFile("My Filename", fileContents); - zip.close(); - QByteArray zipFile = buffer.buffer(); - - // QFile f("createArchiveTest.zip"); f.open(QIODevice::WriteOnly); f.write(zipFile); f.close(); - - QBuffer buffer2(&zipFile); - QZipReader zip2(&buffer2); - QList<QZipReader::FileInfo> files = zip2.fileInfoList(); - QCOMPARE(files.count(), 1); - QZipReader::FileInfo file = files.at(0); - QCOMPARE(file.filePath, QString("My Filename")); - QCOMPARE(uint(file.isDir), (uint) 0); - QCOMPARE(uint(file.isFile), (uint) 1); - QCOMPARE(uint(file.isSymLink), (uint) 0); - QCOMPARE(file.permissions, QFile::Permissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ReadUser | QFile::WriteUser) ); - QCOMPARE(file.size, (long long) 27); - QCOMPARE(zip2.fileData("My Filename"), fileContents); -} - -QTEST_MAIN(tst_QZip) -#include "tst_qzip.moc" diff --git a/tests/auto/gui/util/CMakeLists.txt b/tests/auto/gui/util/CMakeLists.txt index 048e18360c..1efdf85b97 100644 --- a/tests/auto/gui/util/CMakeLists.txt +++ b/tests/auto/gui/util/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from util.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause -add_subdirectory(qdesktopservices) +if(QT_FEATURE_desktopservices) + add_subdirectory(qdesktopservices) +endif() add_subdirectory(qdoublevalidator) add_subdirectory(qintvalidator) add_subdirectory(qregularexpressionvalidator) add_subdirectory(qtexturefilereader) -add_subdirectory(qundogroup) -add_subdirectory(qundostack) +if(QT_FEATURE_undogroup) + add_subdirectory(qundogroup) +endif() +if(QT_FEATURE_undocommand) + add_subdirectory(qundostack) +endif() diff --git a/tests/auto/gui/util/qdesktopservices/CMakeLists.txt b/tests/auto/gui/util/qdesktopservices/CMakeLists.txt index 475a3405c0..64a1aaa930 100644 --- a/tests/auto/gui/util/qdesktopservices/CMakeLists.txt +++ b/tests/auto/gui/util/qdesktopservices/CMakeLists.txt @@ -1,14 +1,19 @@ -# Generated from qdesktopservices.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdesktopservices Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdesktopservices LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qdesktopservices SOURCES tst_qdesktopservices.cpp - DEFINES - # QT_DISABLE_DEPRECATED_BEFORE=0 # special case - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp b/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp index b338e01684..e75626eda7 100644 --- a/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp +++ b/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -42,10 +42,6 @@ public slots: } }; -#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0) -# define CAN_IMPLICITLY_UNSET -#endif - void tst_qdesktopservices::handlers() { MyUrlHandler fooHandler; @@ -53,12 +49,10 @@ void tst_qdesktopservices::handlers() QDesktopServices::setUrlHandler(QString("foo"), &fooHandler, "handle"); QDesktopServices::setUrlHandler(QString("bar"), &barHandler, "handle"); -#ifndef CAN_IMPLICITLY_UNSET const auto unsetHandlers = qScopeGuard([] { QDesktopServices::unsetUrlHandler(u"bar"_s); QDesktopServices::unsetUrlHandler(u"foo"_s); }); -#endif QUrl fooUrl("foo://blub/meh"); QUrl barUrl("bar://hmm/hmmmm"); @@ -68,15 +62,6 @@ void tst_qdesktopservices::handlers() QCOMPARE(fooHandler.lastHandledUrl.toString(), fooUrl.toString()); QCOMPARE(barHandler.lastHandledUrl.toString(), barUrl.toString()); - -#ifdef CAN_IMPLICITLY_UNSET - for (int i = 0; i < 2; ++i) - QTest::ignoreMessage(QtWarningMsg, - "Please call QDesktopServices::unsetUrlHandler() before destroying a " - "registered URL handler object.\n" - "Support for destroying a registered URL handler object is deprecated, " - "and will be removed in Qt 6.6."); -#endif } QTEST_MAIN(tst_qdesktopservices) diff --git a/tests/auto/gui/util/qdoublevalidator/CMakeLists.txt b/tests/auto/gui/util/qdoublevalidator/CMakeLists.txt index 27996300d7..f79fe8b00c 100644 --- a/tests/auto/gui/util/qdoublevalidator/CMakeLists.txt +++ b/tests/auto/gui/util/qdoublevalidator/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qdoublevalidator.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdoublevalidator Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdoublevalidator LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qdoublevalidator SOURCES tst_qdoublevalidator.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp b/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp index 7818e83f09..b44975ea0b 100644 --- a/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp +++ b/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -143,6 +143,7 @@ void tst_QDoubleValidator::validate_data() QTest::newRow("data56") << "C" << 1229.0 << 1231.0 << -1 << QString("123E+") << ITM << INV; QTest::newRow("data57") << "C" << 1229.0 << 1231.0 << -1 << QString("123E+1") << ACC << INV; QTest::newRow("data58") << "C" << 0.0 << 100.0 << -1 << QString("0.0") << ACC << ACC; + QTest::newRow("overlong") << "C" << 0.0 << 99.9 << 2 << QString("1234.0") << ITM << INV; QTest::newRow("data_de0") << "de" << 0.0 << 100.0 << 1 << QString("50,0") << ACC << ACC; QTest::newRow("data_de1") << "de" << 00.0 << 100.0 << 1 << QString("500,0") << ITM << ITM; @@ -310,74 +311,74 @@ void tst_QDoubleValidator::notifySignals() QCOMPARE(dv.decimals(), 10); dv.setTop(0.8); - QCOMPARE(topSpy.count(), 1); - QCOMPARE(changedSpy.count(), 1); + QCOMPARE(topSpy.size(), 1); + QCOMPARE(changedSpy.size(), 1); QCOMPARE(dv.top(), 0.8); dv.setBottom(0.2); - QCOMPARE(bottomSpy.count(), 1); - QCOMPARE(changedSpy.count(), 2); + QCOMPARE(bottomSpy.size(), 1); + QCOMPARE(changedSpy.size(), 2); QCOMPARE(dv.bottom(), 0.2); dv.setRange(0.2, 0.7); - QCOMPARE(topSpy.count(), 2); - QCOMPARE(bottomSpy.count(), 1); - QCOMPARE(decSpy.count(), 0); - QCOMPARE(changedSpy.count(), 3); + QCOMPARE(topSpy.size(), 2); + QCOMPARE(bottomSpy.size(), 1); + QCOMPARE(decSpy.size(), 0); + QCOMPARE(changedSpy.size(), 3); QCOMPARE(dv.bottom(), 0.2); QCOMPARE(dv.top(), 0.7); QCOMPARE(dv.decimals(), 10); dv.setRange(0.3, 0.7); - QCOMPARE(topSpy.count(), 2); - QCOMPARE(bottomSpy.count(), 2); - QCOMPARE(changedSpy.count(), 4); + QCOMPARE(topSpy.size(), 2); + QCOMPARE(bottomSpy.size(), 2); + QCOMPARE(changedSpy.size(), 4); QCOMPARE(dv.bottom(), 0.3); QCOMPARE(dv.top(), 0.7); QCOMPARE(dv.decimals(), 10); dv.setRange(0.4, 0.6); - QCOMPARE(topSpy.count(), 3); - QCOMPARE(bottomSpy.count(), 3); - QCOMPARE(changedSpy.count(), 5); + QCOMPARE(topSpy.size(), 3); + QCOMPARE(bottomSpy.size(), 3); + QCOMPARE(changedSpy.size(), 5); QCOMPARE(dv.bottom(), 0.4); QCOMPARE(dv.top(), 0.6); QCOMPARE(dv.decimals(), 10); dv.setDecimals(5); - QCOMPARE(decSpy.count(), 1); - QCOMPARE(changedSpy.count(), 6); + QCOMPARE(decSpy.size(), 1); + QCOMPARE(changedSpy.size(), 6); QCOMPARE(dv.decimals(), 5); dv.setRange(0.4, 0.6, 100); - QCOMPARE(topSpy.count(), 3); - QCOMPARE(bottomSpy.count(), 3); - QCOMPARE(decSpy.count(), 2); - QCOMPARE(changedSpy.count(), 7); + QCOMPARE(topSpy.size(), 3); + QCOMPARE(bottomSpy.size(), 3); + QCOMPARE(decSpy.size(), 2); + QCOMPARE(changedSpy.size(), 7); QCOMPARE(dv.bottom(), 0.4); QCOMPARE(dv.top(), 0.6); QCOMPARE(dv.decimals(), 100); dv.setNotation(QDoubleValidator::StandardNotation); - QCOMPARE(notSpy.count(), 1); - QCOMPARE(changedSpy.count(), 8); + QCOMPARE(notSpy.size(), 1); + QCOMPARE(changedSpy.size(), 8); QCOMPARE(dv.notation(), QDoubleValidator::StandardNotation); dv.setRange(dv.bottom(), dv.top(), dv.decimals()); - QCOMPARE(topSpy.count(), 3); - QCOMPARE(bottomSpy.count(), 3); - QCOMPARE(decSpy.count(), 2); - QCOMPARE(changedSpy.count(), 8); + QCOMPARE(topSpy.size(), 3); + QCOMPARE(bottomSpy.size(), 3); + QCOMPARE(decSpy.size(), 2); + QCOMPARE(changedSpy.size(), 8); dv.setNotation(dv.notation()); - QCOMPARE(notSpy.count(), 1); - QCOMPARE(changedSpy.count(), 8); + QCOMPARE(notSpy.size(), 1); + QCOMPARE(changedSpy.size(), 8); dv.setLocale(QLocale("C")); - QCOMPARE(changedSpy.count(), 8); + QCOMPARE(changedSpy.size(), 8); dv.setLocale(QLocale("en")); - QCOMPARE(changedSpy.count(), 9); + QCOMPARE(changedSpy.size(), 9); } void tst_QDoubleValidator::fixup() @@ -416,7 +417,7 @@ void tst_QDoubleValidator::fixup_data() QTest::newRow("C standard with invalid digit grouping") << "C" << QDoubleValidator::StandardNotation << -1 << "1,234,5.678" << "12345.678"; - QTest::newRow("C standard with invalid number of decimals") + QTest::newRow("C standard with invalid group size") << "C" << QDoubleValidator::StandardNotation << 2 << "-12,34.678" << "-1234.68"; QTest::newRow("C standard truncate decimals") @@ -445,7 +446,7 @@ void tst_QDoubleValidator::fixup_data() QTest::newRow("C scientific with invalid digit grouping") << "C" << QDoubleValidator::ScientificNotation << -1 << "12,34.98765e2" << "1.23498765e+05"; - QTest::newRow("C scientific with invalid number of decimals") + QTest::newRow("C scientific with invalid group size") << "C" << QDoubleValidator::ScientificNotation << 2 << "-12,34.98765e2" << "-1.23e+05"; QTest::newRow("C scientific truncate decimals") @@ -485,7 +486,7 @@ void tst_QDoubleValidator::fixup_data() QTest::newRow("en standard with invalid digit grouping") << "en" << QDoubleValidator::StandardNotation << -1 << "-1,234,5.678" << "-12,345.678"; - QTest::newRow("en standard with invalid number of decimals") + QTest::newRow("en standard with invalid group size") << "en" << QDoubleValidator::StandardNotation << 2 << "12,34.678" << "1,234.68"; QTest::newRow("en standard no fractional part") @@ -501,7 +502,7 @@ void tst_QDoubleValidator::fixup_data() QTest::newRow("en scientific with invalid digit grouping") << "en" << QDoubleValidator::ScientificNotation << -1 << "-12,34.98765e2" << "-1.23498765E+05"; - QTest::newRow("en scientific with invalid number of decimals") + QTest::newRow("en scientific with invalid group size") << "en" << QDoubleValidator::ScientificNotation << 2 << "12,34.98765e2" << "1.23E+05"; QTest::newRow("en scientific no fractional part") @@ -528,7 +529,7 @@ void tst_QDoubleValidator::fixup_data() QTest::newRow("de standard with invalid digit grouping") << "de" << QDoubleValidator::StandardNotation << -1 << "1.234.5,678" << "12.345,678"; - QTest::newRow("de standard with invalid number of decimals") + QTest::newRow("de standard with invalid group size") << "de" << QDoubleValidator::StandardNotation << 2 << "-12.34,678" << "-1.234,68"; QTest::newRow("de standard no fractional part") @@ -543,7 +544,7 @@ void tst_QDoubleValidator::fixup_data() QTest::newRow("de scientific with invalid digit grouping") << "de" << QDoubleValidator::ScientificNotation << -1 << "12.34,98765e2" << "1,23498765E+05"; - QTest::newRow("de scientific with invalid number of decimals") + QTest::newRow("de scientific with invalid group size") << "de" << QDoubleValidator::ScientificNotation << 2 << "-12.34,98765e2" << "-1,23E+05"; QTest::newRow("de scientific no fractional part") @@ -559,6 +560,22 @@ void tst_QDoubleValidator::fixup_data() << "de" << QDoubleValidator::ScientificNotation << -1 << "-12.34" << "-1,234E+03"; + // es locale uses ',' as decimal point and '.' as grouping separator. + // It doesn't apply grouping unless the the next-to-least significant group + // has more than one digit in it. + QTest::newRow("es standard no digit grouping") + << "es" << QDoubleValidator::StandardNotation << -1 << "1234,567" << "1234,567"; + QTest::newRow("es standard with digit grouping") + << "es" << QDoubleValidator::StandardNotation << -1 << "-12.345,678" << "-12.345,678"; + QTest::newRow("es standard with invalid group size") + << "es" << QDoubleValidator::StandardNotation << -1 << "1.234.5,678" << "12.345,678"; + QTest::newRow("es standard with invalid digit grouping") + << "es" << QDoubleValidator::StandardNotation << 2 << "-1.234,678" << "-1234,68"; + QTest::newRow("es standard big with invalid digit grouping") + << "es" << QDoubleValidator::StandardNotation << 2 << "-1234.678,9" << "-1.234.678,9"; + QTest::newRow("es standard no fractional part") + << "es" << QDoubleValidator::StandardNotation << -1 << "12.34" << "1234"; + // hi locale uses '.' as decimal point and ',' as grouping separator. // The rightmost group is of three digits, all the others contain two // digits. @@ -641,7 +658,7 @@ void tst_QDoubleValidator::setRangeOverloads_data() QTest::newRow("scientific, 1 digits after point") << QDoubleValidator::ScientificNotation << -1 << -100.0 << 100.0 << 0 << QString("1.2e1") << ACC << INV; - QTest::newRow("scientific, 3 digits after point, not in range") + QTest::newRow("scientific, 3 digits after point, demand fewer") << QDoubleValidator::ScientificNotation << 3 << -100.0 << 100.0 << 1 << QString("10.234e-1") << ACC << INV; QTest::newRow("scientific, 3 digits after point, not in range") diff --git a/tests/auto/gui/util/qintvalidator/CMakeLists.txt b/tests/auto/gui/util/qintvalidator/CMakeLists.txt index 83891a3541..841b83a8e0 100644 --- a/tests/auto/gui/util/qintvalidator/CMakeLists.txt +++ b/tests/auto/gui/util/qintvalidator/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qintvalidator.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qintvalidator Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qintvalidator LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qintvalidator SOURCES tst_qintvalidator.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp b/tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp index 6e380bdcaa..bfa69c90b8 100644 --- a/tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp +++ b/tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -165,8 +165,10 @@ void tst_QIntValidator::validateFrench() QIntValidator validator(-2000, 2000, 0); validator.setLocale(QLocale::French); int i; + // Grouping separator is a narrow no-break space; QLocale accepts a space as it. QString s = QLatin1String("1 "); - QCOMPARE(validator.validate(s, i), QValidator::Acceptable); + // Shouldn't end with a group separator + QCOMPARE(validator.validate(s, i), QValidator::Intermediate); validator.fixup(s); QCOMPARE(s, s); @@ -211,45 +213,45 @@ void tst_QIntValidator::notifySignals() QSignalSpy changedSpy(&iv, SIGNAL(changed())); iv.setTop(9); - QCOMPARE(topSpy.count(), 1); - QCOMPARE(changedSpy.count(), 1); + QCOMPARE(topSpy.size(), 1); + QCOMPARE(changedSpy.size(), 1); QCOMPARE(iv.top(), 9); iv.setBottom(1); - QCOMPARE(bottomSpy.count(), 1); - QCOMPARE(changedSpy.count(), 2); + QCOMPARE(bottomSpy.size(), 1); + QCOMPARE(changedSpy.size(), 2); QCOMPARE(iv.bottom(), 1); iv.setRange(1, 8); - QCOMPARE(topSpy.count(), 2); - QCOMPARE(bottomSpy.count(), 1); - QCOMPARE(changedSpy.count(), 3); + QCOMPARE(topSpy.size(), 2); + QCOMPARE(bottomSpy.size(), 1); + QCOMPARE(changedSpy.size(), 3); QCOMPARE(iv.top(), 8); QCOMPARE(iv.bottom(), 1); iv.setRange(2, 8); - QCOMPARE(topSpy.count(), 2); - QCOMPARE(bottomSpy.count(), 2); - QCOMPARE(changedSpy.count(), 4); + QCOMPARE(topSpy.size(), 2); + QCOMPARE(bottomSpy.size(), 2); + QCOMPARE(changedSpy.size(), 4); QCOMPARE(iv.top(), 8); QCOMPARE(iv.bottom(), 2); iv.setRange(3, 7); - QCOMPARE(topSpy.count(), 3); - QCOMPARE(bottomSpy.count(), 3); - QCOMPARE(changedSpy.count(), 5); + QCOMPARE(topSpy.size(), 3); + QCOMPARE(bottomSpy.size(), 3); + QCOMPARE(changedSpy.size(), 5); QCOMPARE(iv.top(), 7); QCOMPARE(iv.bottom(), 3); iv.setRange(3, 7); - QCOMPARE(topSpy.count(), 3); - QCOMPARE(bottomSpy.count(), 3); - QCOMPARE(changedSpy.count(), 5); + QCOMPARE(topSpy.size(), 3); + QCOMPARE(bottomSpy.size(), 3); + QCOMPARE(changedSpy.size(), 5); iv.setLocale(QLocale("C")); - QCOMPARE(changedSpy.count(), 5); + QCOMPARE(changedSpy.size(), 5); iv.setLocale(QLocale("en")); - QCOMPARE(changedSpy.count(), 6); + QCOMPARE(changedSpy.size(), 6); } void tst_QIntValidator::fixup() @@ -306,9 +308,9 @@ void tst_QIntValidator::fixup_data() // Normally the groups contain three digits, but the leftmost group should // have at least two digits. QTest::newRow("es no digit grouping 1000") << "es" << "1000" << "1000"; - QTest::newRow("es no digit grouping 10000") << "es" << "10000" << "10.000"; - QTest::newRow("es with digit grouping") << "es" << "1000.000" << "1000.000"; - QTest::newRow("es invalid digit grouping") << "es" << "1.000.000" << "1000.000"; + QTest::newRow("es with digit grouping 10000") << "es" << "10000" << "10.000"; + QTest::newRow("es with digit grouping million") << "es" << "1.000.000" << "1.000.000"; + QTest::newRow("es invalid digit grouping") << "es" << "1000.000" << "1.000.000"; } QTEST_APPLESS_MAIN(tst_QIntValidator) diff --git a/tests/auto/gui/util/qregularexpressionvalidator/CMakeLists.txt b/tests/auto/gui/util/qregularexpressionvalidator/CMakeLists.txt index 9caf7a1596..1d48205537 100644 --- a/tests/auto/gui/util/qregularexpressionvalidator/CMakeLists.txt +++ b/tests/auto/gui/util/qregularexpressionvalidator/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qregularexpressionvalidator.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qregularexpressionvalidator Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qregularexpressionvalidator LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qregularexpressionvalidator SOURCES tst_qregularexpressionvalidator.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/util/qregularexpressionvalidator/tst_qregularexpressionvalidator.cpp b/tests/auto/gui/util/qregularexpressionvalidator/tst_qregularexpressionvalidator.cpp index d78ee31864..17f9e6a1bd 100644 --- a/tests/auto/gui/util/qregularexpressionvalidator/tst_qregularexpressionvalidator.cpp +++ b/tests/auto/gui/util/qregularexpressionvalidator/tst_qregularexpressionvalidator.cpp @@ -1,6 +1,6 @@ // Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtGui/QRegularExpressionValidator> #include <QTest> @@ -73,12 +73,12 @@ void tst_QRegularExpressionValidator::validate() QTEST(result, "state"); if (result == QValidator::Invalid) - QCOMPARE(pos, value.length()); + QCOMPARE(pos, value.size()); else QCOMPARE(pos, -1); // ensure pos is not modified if validate returned Acceptable or Intermediate - QCOMPARE(spy.count(), signalCount); - QCOMPARE(changedSpy.count(), signalCount); + QCOMPARE(spy.size(), signalCount); + QCOMPARE(changedSpy.size(), signalCount); } QTEST_GUILESS_MAIN(tst_QRegularExpressionValidator) diff --git a/tests/auto/gui/util/qtexturefilereader/CMakeLists.txt b/tests/auto/gui/util/qtexturefilereader/CMakeLists.txt index b7fc79854e..70e2c02417 100644 --- a/tests/auto/gui/util/qtexturefilereader/CMakeLists.txt +++ b/tests/auto/gui/util/qtexturefilereader/CMakeLists.txt @@ -1,15 +1,23 @@ -# Generated from qtexturefilereader.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtexturefilereader Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtexturefilereader LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Resources: set(qtexturefilereader_resource_files "texturefiles/car.ktx" "texturefiles/car_mips.ktx" "texturefiles/cubemap_float32_rgba.ktx" "texturefiles/cubemap_metadata.ktx" + "texturefiles/invalid.ktx" "texturefiles/newlogo.astc" "texturefiles/newlogo_srgb.astc" "texturefiles/pattern.pkm" @@ -18,7 +26,7 @@ set(qtexturefilereader_resource_files qt_internal_add_test(tst_qtexturefilereader SOURCES tst_qtexturefilereader.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate TESTDATA ${qtexturefilereader_resource_files} diff --git a/tests/auto/gui/util/qtexturefilereader/texturefiles/invalid.ktx b/tests/auto/gui/util/qtexturefilereader/texturefiles/invalid.ktx Binary files differnew file mode 100644 index 0000000000..68a92221db --- /dev/null +++ b/tests/auto/gui/util/qtexturefilereader/texturefiles/invalid.ktx diff --git a/tests/auto/gui/util/qtexturefilereader/tst_qtexturefilereader.cpp b/tests/auto/gui/util/qtexturefilereader/tst_qtexturefilereader.cpp index 9d7205a921..62760e3844 100644 --- a/tests/auto/gui/util/qtexturefilereader/tst_qtexturefilereader.cpp +++ b/tests/auto/gui/util/qtexturefilereader/tst_qtexturefilereader.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2018 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <private/qtexturefilereader_p.h> #include <QTest> @@ -11,6 +11,7 @@ class tst_qtexturefilereader : public QObject private slots: void checkHandlers_data(); void checkHandlers(); + void checkInvalid(); void checkMetadata(); }; @@ -140,6 +141,18 @@ void tst_qtexturefilereader::checkMetadata() QCOMPARE(kvs.value("test C"), QByteArrayLiteral("3\x0000")); } +void tst_qtexturefilereader::checkInvalid() +{ + QFile f(":/texturefiles/invalid.ktx"); + QVERIFY(f.open(QIODevice::ReadOnly)); + QTextureFileReader r(&f); + QTextureFileData d = r.read(); + auto kvs = d.keyValueMetadata(); + + // Basically just checking that we don't crash on and invalid file + QVERIFY(kvs.empty()); +} + QTEST_MAIN(tst_qtexturefilereader) #include "tst_qtexturefilereader.moc" diff --git a/tests/auto/gui/util/qundogroup/CMakeLists.txt b/tests/auto/gui/util/qundogroup/CMakeLists.txt index c1396326f7..98c2f64f88 100644 --- a/tests/auto/gui/util/qundogroup/CMakeLists.txt +++ b/tests/auto/gui/util/qundogroup/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qundogroup.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qundogroup Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qundogroup LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qundogroup SOURCES tst_qundogroup.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/util/qundogroup/tst_qundogroup.cpp b/tests/auto/gui/util/qundogroup/tst_qundogroup.cpp index bcecfc26b9..36f72b2ca0 100644 --- a/tests/auto/gui/util/qundogroup/tst_qundogroup.cpp +++ b/tests/auto/gui/util/qundogroup/tst_qundogroup.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QUndoGroup> #include <QUndoStack> @@ -65,7 +65,7 @@ InsertCommand::InsertCommand(QString *str, int idx, const QString &text, QUndoCommand *parent) : QUndoCommand(parent) { - QVERIFY(str->length() >= idx); + QVERIFY(str->size() >= idx); setText("insert"); @@ -76,22 +76,22 @@ InsertCommand::InsertCommand(QString *str, int idx, const QString &text, void InsertCommand::redo() { - QVERIFY(m_str->length() >= m_idx); + QVERIFY(m_str->size() >= m_idx); m_str->insert(m_idx, m_text); } void InsertCommand::undo() { - QCOMPARE(m_str->mid(m_idx, m_text.length()), m_text); + QCOMPARE(m_str->mid(m_idx, m_text.size()), m_text); - m_str->remove(m_idx, m_text.length()); + m_str->remove(m_idx, m_text.size()); } RemoveCommand::RemoveCommand(QString *str, int idx, int len, QUndoCommand *parent) : QUndoCommand(parent) { - QVERIFY(str->length() >= idx + len); + QVERIFY(str->size() >= idx + len); setText("remove"); @@ -102,14 +102,14 @@ RemoveCommand::RemoveCommand(QString *str, int idx, int len, QUndoCommand *paren void RemoveCommand::redo() { - QCOMPARE(m_str->mid(m_idx, m_text.length()), m_text); + QCOMPARE(m_str->mid(m_idx, m_text.size()), m_text); - m_str->remove(m_idx, m_text.length()); + m_str->remove(m_idx, m_text.size()); } void RemoveCommand::undo() { - QVERIFY(m_str->length() >= m_idx); + QVERIFY(m_str->size() >= m_idx); m_str->insert(m_idx, m_text); } @@ -131,9 +131,9 @@ void AppendCommand::redo() void AppendCommand::undo() { - QCOMPARE(m_str->mid(m_str->length() - m_text.length()), m_text); + QCOMPARE(m_str->mid(m_str->size() - m_text.size()), m_text); - m_str->truncate(m_str->length() - m_text.length()); + m_str->truncate(m_str->size() - m_text.size()); } int AppendCommand::id() const diff --git a/tests/auto/gui/util/qundostack/CMakeLists.txt b/tests/auto/gui/util/qundostack/CMakeLists.txt index 0e56171add..de36f4a1ad 100644 --- a/tests/auto/gui/util/qundostack/CMakeLists.txt +++ b/tests/auto/gui/util/qundostack/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qundostack.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qundostack Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qundostack LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qundostack SOURCES tst_qundostack.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/util/qundostack/tst_qundostack.cpp b/tests/auto/gui/util/qundostack/tst_qundostack.cpp index bdb664ad7e..3567bc6097 100644 --- a/tests/auto/gui/util/qundostack/tst_qundostack.cpp +++ b/tests/auto/gui/util/qundostack/tst_qundostack.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -97,7 +97,7 @@ InsertCommand::InsertCommand(QString *str, int idx, const QString &text, QUndoCommand *parent) : QUndoCommand(parent) { - QVERIFY(str->length() >= idx); + QVERIFY(str->size() >= idx); setText("insert"); @@ -108,22 +108,22 @@ InsertCommand::InsertCommand(QString *str, int idx, const QString &text, void InsertCommand::redo() { - QVERIFY(m_str->length() >= m_idx); + QVERIFY(m_str->size() >= m_idx); m_str->insert(m_idx, m_text); } void InsertCommand::undo() { - QCOMPARE(m_str->mid(m_idx, m_text.length()), m_text); + QCOMPARE(m_str->mid(m_idx, m_text.size()), m_text); - m_str->remove(m_idx, m_text.length()); + m_str->remove(m_idx, m_text.size()); } RemoveCommand::RemoveCommand(QString *str, int idx, int len, QUndoCommand *parent) : QUndoCommand(parent) { - QVERIFY(str->length() >= idx + len); + QVERIFY(str->size() >= idx + len); setText("remove"); @@ -134,14 +134,14 @@ RemoveCommand::RemoveCommand(QString *str, int idx, int len, QUndoCommand *paren void RemoveCommand::redo() { - QCOMPARE(m_str->mid(m_idx, m_text.length()), m_text); + QCOMPARE(m_str->mid(m_idx, m_text.size()), m_text); - m_str->remove(m_idx, m_text.length()); + m_str->remove(m_idx, m_text.size()); } void RemoveCommand::undo() { - QVERIFY(m_str->length() >= m_idx); + QVERIFY(m_str->size() >= m_idx); m_str->insert(m_idx, m_text); } @@ -172,9 +172,9 @@ void AppendCommand::redo() void AppendCommand::undo() { - QCOMPARE(m_str->mid(m_str->length() - m_text.length()), m_text); + QCOMPARE(m_str->mid(m_str->size() - m_text.size()), m_text); - m_str->truncate(m_str->length() - m_text.length()); + m_str->truncate(m_str->size() - m_text.size()); } int AppendCommand::id() const @@ -324,44 +324,44 @@ static void checkState(QSignalSpy &redoTextChangedSpy, QCOMPARE(stack.canRedo(), _canRedo); QCOMPARE(stack.redoText(), QString(_redoText)); if (_indexChanged) { - QCOMPARE(indexChangedSpy.count(), 1); + QCOMPARE(indexChangedSpy.size(), 1); QCOMPARE(indexChangedSpy.at(0).at(0).toInt(), _index); indexChangedSpy.clear(); } else { - QCOMPARE(indexChangedSpy.count(), 0); + QCOMPARE(indexChangedSpy.size(), 0); } if (_cleanChanged) { - QCOMPARE(cleanChangedSpy.count(), 1); + QCOMPARE(cleanChangedSpy.size(), 1); QCOMPARE(cleanChangedSpy.at(0).at(0).toBool(), _clean); cleanChangedSpy.clear(); } else { - QCOMPARE(cleanChangedSpy.count(), 0); + QCOMPARE(cleanChangedSpy.size(), 0); } if (_undoChanged) { - QCOMPARE(canUndoChangedSpy.count(), 1); + QCOMPARE(canUndoChangedSpy.size(), 1); QCOMPARE(canUndoChangedSpy.at(0).at(0).toBool(), _canUndo); QCOMPARE(undoAction->isEnabled(), _canUndo); - QCOMPARE(undoTextChangedSpy.count(), 1); + QCOMPARE(undoTextChangedSpy.size(), 1); QCOMPARE(undoTextChangedSpy.at(0).at(0).toString(), QString(_undoText)); QCOMPARE(undoAction->text(), glue("foo", _undoText)); canUndoChangedSpy.clear(); undoTextChangedSpy.clear(); } else { - QCOMPARE(canUndoChangedSpy.count(), 0); - QCOMPARE(undoTextChangedSpy.count(), 0); + QCOMPARE(canUndoChangedSpy.size(), 0); + QCOMPARE(undoTextChangedSpy.size(), 0); } if (_redoChanged) { - QCOMPARE(canRedoChangedSpy.count(), 1); + QCOMPARE(canRedoChangedSpy.size(), 1); QCOMPARE(canRedoChangedSpy.at(0).at(0).toBool(), _canRedo); QCOMPARE(redoAction->isEnabled(), _canRedo); - QCOMPARE(redoTextChangedSpy.count(), 1); + QCOMPARE(redoTextChangedSpy.size(), 1); QCOMPARE(redoTextChangedSpy.at(0).at(0).toString(), QString(_redoText)); QCOMPARE(redoAction->text(), glue("bar", _redoText)); canRedoChangedSpy.clear(); redoTextChangedSpy.clear(); } else { - QCOMPARE(canRedoChangedSpy.count(), 0); - QCOMPARE(redoTextChangedSpy.count(), 0); + QCOMPARE(canRedoChangedSpy.size(), 0); + QCOMPARE(redoTextChangedSpy.size(), 0); } } |