diff options
Diffstat (limited to 'tests/auto/gui')
38 files changed, 1014 insertions, 81 deletions
diff --git a/tests/auto/gui/image/CMakeLists.txt b/tests/auto/gui/image/CMakeLists.txt index 9cc6d4d2bf..c7fc6f07d3 100644 --- a/tests/auto/gui/image/CMakeLists.txt +++ b/tests/auto/gui/image/CMakeLists.txt @@ -12,14 +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 -if(NOT ANDROID) - add_subdirectory(qicon) -endif() +add_subdirectory(qicon) diff --git a/tests/auto/gui/image/qicon/CMakeLists.txt b/tests/auto/gui/image/qicon/CMakeLists.txt index c693c559cc..93f75741c0 100644 --- a/tests/auto/gui/image/qicon/CMakeLists.txt +++ b/tests/auto/gui/image/qicon/CMakeLists.txt @@ -37,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 LIBRARIES Qt::Gui + TestIconPlugin TESTDATA ${test_data} ) @@ -105,3 +108,5 @@ qt_internal_extend_target(tst_qicon CONDITION TARGET Qt::Widgets LIBRARIES Qt::Widgets ) + +add_dependencies(tst_qicon TestIconPlugin) 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 99b4a0589e..d95ee66fb6 100644 --- a/tests/auto/gui/image/qicon/tst_qicon.cpp +++ b/tests/auto/gui/image/qicon/tst_qicon.cpp @@ -48,6 +48,9 @@ private slots: #endif void task223279_inconsistentAddFile(); + void themeFromPlugin_data(); + void themeFromPlugin(); + private: bool haveImageFormat(QByteArray const&); @@ -872,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/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 1d0cdfcc4e..8086ffcc28 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -15,6 +15,7 @@ #include <stdio.h> #include <qpainter.h> +#include <private/qcmyk_p.h> #include <private/qimage_p.h> #include <private/qdrawhelper_p.h> @@ -110,6 +111,8 @@ private slots: void smoothScaleFormats(); void smoothScaleNoConversion_data(); void smoothScaleNoConversion(); + void smoothScale_CMYK_data(); + void smoothScale_CMYK(); void transformed_data(); void transformed(); @@ -173,6 +176,10 @@ private slots: void colorSpaceRgbConversion(); void colorSpaceCmykConversion_data(); void colorSpaceCmykConversion(); + void colorSpaceFromGrayConversion_data(); + void colorSpaceFromGrayConversion(); + void colorSpaceToGrayConversion_data(); + void colorSpaceToGrayConversion(); void deepCopyWhenPaintingActive(); void scaled_QTBUG19157(); @@ -2091,6 +2098,76 @@ void tst_QImage::smoothScaleNoConversion() 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; @@ -3387,6 +3464,120 @@ void tst_QImage::colorSpaceCmykConversion() } } +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); @@ -3863,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()); diff --git a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp index 137439d98b..d8c553b521 100644 --- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp @@ -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); diff --git a/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp index 8ef0b6272a..4ba3ae11de 100644 --- a/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -117,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; @@ -382,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)) @@ -412,16 +406,16 @@ QModelIndex tst_QFileSystemModel::prepareTestModelRoot(QFileSystemModel *model, void tst_QFileSystemModel::rowCount() { - QSignalSpy *spy2 = nullptr; - QSignalSpy *spy3 = nullptr; QScopedPointer<QFileSystemModel> model(new QFileSystemModel); 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, &spy2, &spy3); + QModelIndex root = prepareTestModelRoot(model.data(), flatDirTestPath); QVERIFY(root.isValid()); - QVERIFY(spy2 && spy2->size() > 0); - QVERIFY(spy3 && spy3->size() > 0); + QCOMPARE_GT(rowsInsertedSpy.size(), 0); + QCOMPARE_GT(rowsAboutToBeInsertedSpy.size(), 0); } void tst_QFileSystemModel::rowsInserted_data() diff --git a/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp b/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp index 70fb2b39d3..093367c759 100644 --- a/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp +++ b/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp @@ -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)); @@ -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()); diff --git a/tests/auto/gui/kernel/qevent/tst_qevent.cpp b/tests/auto/gui/kernel/qevent/tst_qevent.cpp index 6960f99af2..8e8169b16c 100644 --- a/tests/auto/gui/kernel/qevent/tst_qevent.cpp +++ b/tests/auto/gui/kernel/qevent/tst_qevent.cpp @@ -6,7 +6,52 @@ #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 + +#if QT_CONFIG(shortcut) +#define X_QShortcutEvent(X) X(QShortcutEvent, ({}, 0)) +#else +#define X_QShortcutEvent(X) +#endif #define FOR_EACH_CORE_EVENT(X) \ /* qcoreevent.h */ \ @@ -15,7 +60,7 @@ X(QChildEvent, (QEvent::ChildAdded, nullptr)) \ X(QDynamicPropertyChangeEvent, ("size")) \ /* qfutureinterface_p.h */ \ - X(QFutureCallOutEvent, ()) \ + X_QFutureCallOutEvent(X) \ /* end */ #define FOR_EACH_GUI_EVENT(X) \ @@ -27,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})) \ @@ -50,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/qwindow/tst_foreignwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp index 526abd6ea3..fdb1b333ef 100644 --- a/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp @@ -172,6 +172,9 @@ void tst_ForeignWindow::destroyWhenParentIsDestroyed() // 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. @@ -184,6 +187,9 @@ void tst_ForeignWindow::destroyWhenParentIsDestroyed() foreignWindow->create(); QVERIFY(foreignWindow->handle()); QTRY_COMPARE(nativeWindow.parentWinId(), parentWindow.winId()); + + parentWindow.show(); + QVERIFY(QTest::qWaitForWindowExposed(&parentWindow)); } #include <tst_foreignwindow.moc> diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index a9e2c5f882..227fd77e1a 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -1509,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(); @@ -1529,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); @@ -1551,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() diff --git a/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp b/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp index 38ecaa7e44..e761f8cb3c 100644 --- a/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp +++ b/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp @@ -2343,7 +2343,7 @@ 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.map(v1); 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/tst_qcolorspace.cpp b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp index 7505d463ed..e23b3d21a1 100644 --- a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp +++ b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp @@ -7,6 +7,7 @@ #include <qcolorspace.h> #include <qimage.h> #include <qimagereader.h> +#include <qrgbafloat.h> #include <private/qcolorspace_p.h> @@ -71,6 +72,9 @@ private slots: void setWhitePoint(); void grayColorSpace(); void grayColorSpaceEffectivelySRgb(); + + void scaleAlphaValue(); + void hdrColorSpaces(); }; tst_QColorSpace::tst_QColorSpace() @@ -121,6 +125,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 @@ -223,6 +236,11 @@ void tst_QColorSpace::fromIccProfile_data() << 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() @@ -252,6 +270,15 @@ void tst_QColorSpace::fromIccProfile() 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() @@ -1030,5 +1057,74 @@ void tst_QColorSpace::grayColorSpaceEffectivelySRgb() 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); +} + +void tst_QColorSpace::hdrColorSpaces() +{ + QColorSpace bt2020linear(QColorSpace::Primaries::Bt2020, QColorSpace::TransferFunction::Linear); + QColorTransform pqToLinear = QColorSpace(QColorSpace::Bt2100Pq).transformationToColorSpace(bt2020linear); + QColorTransform hlgToLinear = QColorSpace(QColorSpace::Bt2100Hlg).transformationToColorSpace(bt2020linear); + + QColor maxWhite = QColor::fromRgbF(1.0f, 1.0f, 1.0f); + QColor hlgWhite = QColor::fromRgbF(0.5f, 0.5f, 0.5f); + QCOMPARE(hlgToLinear.map(maxWhite).redF(), 12.f); + QCOMPARE(hlgToLinear.map(maxWhite).greenF(), 12.f); + QCOMPARE(hlgToLinear.map(maxWhite).blueF(), 12.f); + QCOMPARE(hlgToLinear.map(hlgWhite).redF(), 1.f); + QCOMPARE(hlgToLinear.map(hlgWhite).greenF(), 1.f); + QCOMPARE(hlgToLinear.map(hlgWhite).blueF(), 1.f); + QCOMPARE(pqToLinear.map(maxWhite).redF(), 64.f); + QCOMPARE(pqToLinear.map(maxWhite).greenF(), 64.f); + QCOMPARE(pqToLinear.map(maxWhite).blueF(), 64.f); + + { + QImage image(1, 1, QImage::Format_RGBA32FPx4); + image.setPixel(0, 0, qRgba(255, 255, 255, 255)); + image.setColorSpace(QColorSpace::Bt2100Pq); + QImage image2 = image.convertedToColorSpace(bt2020linear); + QCOMPARE(image2.pixelColor(0, 0).redF(), 64.f); + image.setColorSpace(QColorSpace::Bt2100Hlg); + image2 = image.convertedToColorSpace(bt2020linear); + QCOMPARE(image2.pixelColor(0, 0).redF(), 12.f); + } + { + QImage image(1, 1, QImage::Format_RGBA32FPx4_Premultiplied); + image.setPixel(0, 0, qRgba(255, 255, 255, 255)); + image.setColorSpace(QColorSpace::Bt2100Pq); + QImage image2 = image.convertedToColorSpace(bt2020linear); + QCOMPARE(image2.pixelColor(0, 0).redF(), 64.f); + image.setColorSpace(QColorSpace::Bt2100Hlg); + image2 = image.convertedToColorSpace(bt2020linear); + QCOMPARE(image2.pixelColor(0, 0).redF(), 12.f); + } + { + QImage image(1, 1, QImage::Format_ARGB32); + image.setPixel(0, 0, qRgba(255, 255, 255, 255)); + image.setColorSpace(QColorSpace::Bt2100Pq); + QImage image2 = image.convertedToColorSpace(bt2020linear, QImage::Format_RGBA32FPx4); + QCOMPARE(image2.pixelColor(0, 0).redF(), 64.f); + image.setColorSpace(QColorSpace::Bt2100Hlg); + image2 = image.convertedToColorSpace(bt2020linear, QImage::Format_RGBA32FPx4); + QCOMPARE(image2.pixelColor(0, 0).redF(), 12.f); + } + { + QImage image(1, 1, QImage::Format_ARGB32_Premultiplied); + image.setPixel(0, 0, qRgba(255, 255, 255, 255)); + image.setColorSpace(QColorSpace::Bt2100Pq); + QImage image2 = image.convertedToColorSpace(bt2020linear, QImage::Format_RGBA32FPx4); + QCOMPARE(image2.pixelColor(0, 0).redF(), 64.f); + image.setColorSpace(QColorSpace::Bt2100Hlg); + image2 = image.convertedToColorSpace(bt2020linear, QImage::Format_RGBA32FPx4); + QCOMPARE(image2.pixelColor(0, 0).redF(), 12.f); + } +} + QTEST_MAIN(tst_QColorSpace) #include "tst_qcolorspace.moc" diff --git a/tests/auto/gui/painting/qregion/tst_qregion.cpp b/tests/auto/gui/painting/qregion/tst_qregion.cpp index 3d60e62fc1..934725844a 100644 --- a/tests/auto/gui/painting/qregion/tst_qregion.cpp +++ b/tests/auto/gui/painting/qregion/tst_qregion.cpp @@ -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/platform/qx11info/tst_qx11info.cpp b/tests/auto/gui/platform/qx11info/tst_qx11info.cpp index a4effb07cc..f71e644a8f 100644 --- a/tests/auto/gui/platform/qx11info/tst_qx11info.cpp +++ b/tests/auto/gui/platform/qx11info/tst_qx11info.cpp @@ -7,6 +7,8 @@ #include <QtGui/private/qtx11extras_p.h> +using namespace Qt::StringLiterals; + class tst_QX11Info : public QObject { Q_OBJECT @@ -83,12 +85,21 @@ void initialize() } Q_CONSTRUCTOR_FUNCTION(initialize) +static QString checkSkip() { + if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) + return "This test is only for X11, not Wayland."_L1; + if (QGuiApplication::platformName().startsWith(QLatin1String("offscreen"), Qt::CaseInsensitive)) + return "This test is only for X11, not offscreen."_L1; + return ""_L1; +} + void tst_QX11Info::startupId() { int argc = 0; QGuiApplication app(argc, 0); - if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("This test is only for X11, not Wayland."); + QString result = checkSkip(); + if (!result.isEmpty()) + QSKIP(result.toUtf8()); // This relies on the fact that no widget was shown yet, // so please make sure this method is always the first test. @@ -110,8 +121,9 @@ void tst_QX11Info::isPlatformX11() { int argc = 0; QGuiApplication app(argc, 0); - if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("This test is only for X11, not Wayland."); + QString result = checkSkip(); + if (!result.isEmpty()) + QSKIP(result.toUtf8()); QVERIFY(QX11Info::isPlatformX11()); } @@ -120,8 +132,9 @@ void tst_QX11Info::appTime() { int argc = 0; QGuiApplication app(argc, 0); - if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("This test is only for X11, not Wayland."); + QString result = checkSkip(); + if (!result.isEmpty()) + QSKIP(result.toUtf8()); // No X11 event received yet QCOMPARE(QX11Info::appTime(), 0ul); @@ -348,8 +361,9 @@ void tst_QX11Info::peeker() { int argc = 0; QGuiApplication app(argc, 0); - if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("This test is only for X11, not Wayland."); + QString result = checkSkip(); + if (!result.isEmpty()) + QSKIP(result.toUtf8()); PeekerTest test; test.show(); @@ -361,8 +375,9 @@ void tst_QX11Info::isCompositingManagerRunning() { int argc = 0; QGuiApplication app(argc, 0); - if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("This test is only for X11, not Wayland."); + QString result = checkSkip(); + if (!result.isEmpty()) + QSKIP(result.toUtf8()); const bool b = QX11Info::isCompositingManagerRunning(); Q_UNUSED(b); const bool b2 = QX11Info::isCompositingManagerRunning(0); diff --git a/tests/auto/gui/text/CMakeLists.txt b/tests/auto/gui/text/CMakeLists.txt index bad13de7dc..30b35fb10a 100644 --- a/tests/auto/gui/text/CMakeLists.txt +++ b/tests/auto/gui/text/CMakeLists.txt @@ -11,7 +11,9 @@ 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) diff --git a/tests/auto/gui/text/qabstracttextdocumentlayout/tst_qabstracttextdocumentlayout.cpp b/tests/auto/gui/text/qabstracttextdocumentlayout/tst_qabstracttextdocumentlayout.cpp index 2ae2ccda0a..3d0fab4603 100644 --- a/tests/auto/gui/text/qabstracttextdocumentlayout/tst_qabstracttextdocumentlayout.cpp +++ b/tests/auto/gui/text/qabstracttextdocumentlayout/tst_qabstracttextdocumentlayout.cpp @@ -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; @@ -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/tst_qcssparser.cpp b/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp index a438d7ebc8..203fe003a0 100644 --- a/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp +++ b/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp @@ -56,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() @@ -1759,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/qfontdatabase/CMakeLists.txt b/tests/auto/gui/text/qfontdatabase/CMakeLists.txt index 18b96ded5d..0cb6e8d7c8 100644 --- a/tests/auto/gui/text/qfontdatabase/CMakeLists.txt +++ b/tests/auto/gui/text/qfontdatabase/CMakeLists.txt @@ -47,6 +47,8 @@ set(testdata_resource_files "../../../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 849e7432d1..8733f64d97 100644 --- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp +++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp @@ -78,6 +78,8 @@ private: QString m_testFontCondensed; QString m_testFontItalic; QString m_testFontVariable; + QString m_limitedFont; + QString m_fallbackFont; }; tst_QFontDatabase::tst_QFontDatabase() @@ -91,11 +93,15 @@ void tst_QFontDatabase::initTestCase() 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() @@ -391,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")) @@ -410,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"); @@ -561,11 +579,17 @@ void tst_QFontDatabase::addApplicationFontFallback() { int ledId = -1; int id = -1; - auto cleanup = qScopeGuard([&id, &ledId] { + 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' @@ -633,6 +657,107 @@ void tst_QFontDatabase::addApplicationFontFallback() 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) diff --git a/tests/auto/gui/text/qfontmetrics/CMakeLists.txt b/tests/auto/gui/text/qfontmetrics/CMakeLists.txt index d014d27d46..ee2f76ef76 100644 --- a/tests/auto/gui/text/qfontmetrics/CMakeLists.txt +++ b/tests/auto/gui/text/qfontmetrics/CMakeLists.txt @@ -24,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 9471c1d93f..bad33ab0a4 100644 --- a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp +++ b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp @@ -36,6 +36,7 @@ private slots: void verticalMetrics(); void largeText_data(); void largeText(); // QTBUG-123339 + void typoLineMetrics(); }; void tst_QFontMetrics::same() @@ -410,5 +411,48 @@ void tst_QFontMetrics::largeText() 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/qtextcursor/tst_qtextcursor.cpp b/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp index 6984cd1bd2..8f5cacae4a 100644 --- a/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp +++ b/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp @@ -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() { diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp index 335ee06e2f..600b45575f 100644 --- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp @@ -4053,20 +4053,107 @@ void tst_QTextDocument::restoreStrokeFromHtml() QTextDocument document; QTextCursor textCursor(&document); QTextCharFormat textOutline; - textOutline.setTextOutline(QPen(Qt::red, 2.3)); - textCursor.insertText("Outlined text", 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(), 1); - QTextBlock block = otherDocument.firstBlock(); - QTextFragment fragment = block.begin().fragment(); - QCOMPARE(fragment.text(), QStringLiteral("Outlined text")); - QTextCharFormat fmt = fragment.charFormat(); - QVERIFY(fmt.hasProperty(QTextCharFormat::TextOutline)); - QPen pen = fmt.textOutline(); - QCOMPARE(pen.color(), QColor(Qt::red)); - QCOMPARE(pen.widthF(), 2.3); + 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); + } } } diff --git a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp index 2a279682ca..2ae31849bf 100644 --- a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp +++ b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp @@ -24,18 +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; @@ -99,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() { @@ -145,6 +152,7 @@ void tst_QTextDocumentLayout::lineSeparatorFollowingTable() } } } +#endif #ifndef QT_NO_WIDGETS void tst_QTextDocumentLayout::wrapAtWordBoundaryOrAnywhere() @@ -184,6 +192,7 @@ void tst_QTextDocumentLayout::inlineImage() QCOMPARE(doc->pageCount(), 1); } +#ifndef QT_NO_TEXTHTMLPARSER void tst_QTextDocumentLayout::clippedTableCell() { const char *html = @@ -224,6 +233,7 @@ void tst_QTextDocumentLayout::clippedTableCell() expected.save("expected.png"); QCOMPARE(img, expected); } +#endif void tst_QTextDocumentLayout::floatingTablePageBreak() { @@ -323,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); @@ -416,6 +427,7 @@ void tst_QTextDocumentLayout::testHitTest() QVERIFY(positionY - topMargin <= y); } } +#endif QTEST_MAIN(tst_QTextDocumentLayout) #include "tst_qtextdocumentlayout.moc" diff --git a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp index d20a2f1ea5..6c6145561d 100644 --- a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp +++ b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp @@ -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() diff --git a/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp b/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp index 5311aa6f2b..0048623d0e 100644 --- a/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp +++ b/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp @@ -6,6 +6,10 @@ #include <QPainter> #include <private/qtextimagehandler_p.h> +using namespace Qt::StringLiterals; + +// #define DEBUG_WRITE_HTML + class tst_QTextImageHandler : public QObject { Q_OBJECT @@ -18,7 +22,11 @@ private slots: void cleanup(); void cleanupTestCase(); void loadAtNImages_data(); +#ifndef QT_NO_TEXTHTMLPARSER void loadAtNImages(); + void maxWidth_data(); + void maxWidth(); +#endif }; tst_QTextImageHandler::tst_QTextImageHandler() @@ -47,6 +55,7 @@ void tst_QTextImageHandler::loadAtNImages_data() QTest::addRow("qrc_url") << "qrc:/data/image.png"; } +#ifndef QT_NO_TEXTHTMLPARSER void tst_QTextImageHandler::loadAtNImages() { QFETCH(QString, imageFile); @@ -58,7 +67,7 @@ void tst_QTextImageHandler::loadAtNImages() const auto it = std::find_if(formats.begin(), formats.end(), [](const auto &format){ return format.objectType() == QTextFormat::ImageObject; }); - QVERIFY(it != formats.end()); + QCOMPARE_NE(it, formats.end()); const QTextImageFormat format = (*it).toImageFormat(); QTextImageHandler handler; @@ -75,5 +84,64 @@ void tst_QTextImageHandler::loadAtNImages() } } +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/qtextlist/tst_qtextlist.cpp b/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp index 28eae93f6a..10d44f6d70 100644 --- a/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp +++ b/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp @@ -140,6 +140,7 @@ void tst_QTextList::autoNumberingPrefixAndSuffixHtmlExportImport() QCOMPARE(list->count(), 28); +#ifndef QT_NO_TEXTHTMLPARSER QString htmlExport = doc->toHtml(); QTextDocument importDoc; importDoc.setHtml(htmlExport); @@ -152,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() diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/example.md b/tests/auto/gui/text/qtextmarkdownwriter/data/example.md index 15b30598e6..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 diff --git a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp index d0e1e1cd74..a7e319ef62 100644 --- a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp +++ b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp @@ -1236,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()); @@ -1261,6 +1262,7 @@ void tst_QTextTable::checkBorderAttributes() QCOMPARE(cellFormat.brushProperty(QTextFormat::TableCellRightBorderBrush), rightBorderBrush); } } +#endif } void tst_QTextTable::checkTableBorderAttributes_data() @@ -1317,6 +1319,7 @@ void tst_QTextTable::checkTableBorderAttributes() QFETCH(QTextFrameFormat::BorderStyle, tableBorderStyle); QFETCH(QBrush, tableBorderBrush); +#ifndef QT_NO_TEXTHTMLPARSER QTextDocument doc; doc.setHtml(html); QTextCursor cursor(doc.firstBlock()); @@ -1327,6 +1330,7 @@ void tst_QTextTable::checkTableBorderAttributes() QCOMPARE(currentTable->format().border(), tableBorderWidth); QCOMPARE(currentTable->format().borderStyle(), tableBorderStyle); QCOMPARE(currentTable->format().borderBrush(), tableBorderBrush); +#endif } #ifndef QT_NO_WIDGETS @@ -1385,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; @@ -1404,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/util/CMakeLists.txt b/tests/auto/gui/util/CMakeLists.txt index 830a9ff2f0..1efdf85b97 100644 --- a/tests/auto/gui/util/CMakeLists.txt +++ b/tests/auto/gui/util/CMakeLists.txt @@ -1,10 +1,16 @@ # 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/tst_qdesktopservices.cpp b/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp index e08b299209..e75626eda7 100644 --- a/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp +++ b/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp @@ -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) |