diff options
Diffstat (limited to 'tests/auto/gui/painting')
45 files changed, 1695 insertions, 940 deletions
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 ea380e3cc9..678c8d9b32 100644 --- a/tests/auto/gui/painting/qbrush/tst_qbrush.cpp +++ b/tests/auto/gui/painting/qbrush/tst_qbrush.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/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 5c93a41b71..f592db5544 100644 --- a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp +++ b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -38,6 +13,12 @@ #include <private/qdrawingprimitive_sse2_p.h> #include <qrgba64.h> +#if QT_DEPRECATED_SINCE(6, 6) +# define DEPRECATED_IN_6_6(...) QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED __VA_ARGS__ QT_WARNING_POP +#else +# define DEPRECATED_IN_6_6(...) +#endif + class tst_QColor : public QObject { Q_OBJECT @@ -54,8 +35,8 @@ private slots: void name(); void namehex_data(); void namehex(); - void setNamedColor_data(); - void setNamedColor(); + void fromString_data(); + void fromString(); void constructNamedColorWithSpace(); @@ -92,7 +73,7 @@ private slots: void toCmykNonDestructive(); void toHsl_data(); - void toHsl();; + void toHsl(); void toHslNonDestructive(); void convertTo(); @@ -243,13 +224,13 @@ void tst_QColor::isValid_data() QTest::newRow("defaultConstructor") << QColor() << false; QTest::newRow("rgbConstructor-valid") << QColor(2,5,7) << true; QTest::newRow("rgbConstructor-invalid") << QColor(2,5,999) << false; - QTest::newRow("nameQStringConstructor-valid") << QColor(QString("#ffffff")) << true; - QTest::newRow("nameQStringConstructor-invalid") << QColor(QString("#ffffgg")) << false; - QTest::newRow("nameQStringConstructor-empty") << QColor(QString("")) << false; - QTest::newRow("nameQStringConstructor-named") << QColor(QString("red")) << true; - QTest::newRow("nameCharConstructor-valid") << QColor("#ffffff") << true; - QTest::newRow("nameCharConstructor-invalid") << QColor("#ffffgg") << false; - QTest::newRow("nameCharConstructor-invalid-2") << QColor("#fffffg") << false; + QTest::newRow("nameQStringConstructor-valid") << QColor::fromString("#ffffff") << true; + QTest::newRow("nameQStringConstructor-invalid") << QColor::fromString("#ffffgg") << false; + QTest::newRow("nameQStringConstructor-empty") << QColor::fromString("") << false; + QTest::newRow("nameQStringConstructor-named") << QColor::fromString("red") << true; + QTest::newRow("nameCharConstructor-valid") << QColor::fromString("#ffffff") << true; + QTest::newRow("nameCharConstructor-invalid") << QColor::fromString("#ffffgg") << false; + QTest::newRow("nameCharConstructor-invalid-2") << QColor::fromString("#fffffg") << false; } void tst_QColor::isValid() @@ -335,7 +316,10 @@ void tst_QColor::namehex() { QFETCH(QString, hexcolor); QFETCH(QColor, color); + DEPRECATED_IN_6_6( QCOMPARE(QColor(hexcolor), color); + ) + QCOMPARE(QColor::fromString(hexcolor), color); } void tst_QColor::globalColors_data() @@ -721,25 +705,36 @@ static const int rgbTblSize = sizeof(rgbTbl) / sizeof(RGBData); #undef rgb -void tst_QColor::setNamedColor_data() +void tst_QColor::fromString_data() { +#if QT_DEPRECATED_SINCE(6, 6) QTest::addColumn<QColor>("byCtor"); QTest::addColumn<QColor>("bySetNamedColor"); +#endif + QTest::addColumn<QColor>("byFromString"); QTest::addColumn<QColor>("expected"); for (const auto e : rgbTbl) { QColor expected; expected.setRgba(e.value); -#define ROW(expr) \ - do { \ - QColor bySetNamedColor; \ - bySetNamedColor.setNamedColor(expr); \ - auto byCtor = QColor(expr); \ - QTest::addRow("%s: %s", e.name, #expr) \ - << byCtor << bySetNamedColor << expected; \ - } while (0) \ - /*end*/ +#define ROW(expr) row(expr, #expr) + auto row = [&] (auto expr, const char *exprS) { + QT_WARNING_PUSH + #if QT_DEPRECATED_SINCE(6, 6) + QT_WARNING_DISABLE_DEPRECATED + QColor bySetNamedColor; + bySetNamedColor.setNamedColor(expr); + auto byCtor = QColor(expr); + #endif + QTest::addRow("%s: %s", e.name, exprS) + #if QT_DEPRECATED_SINCE(6, 6) + << byCtor << bySetNamedColor + #endif + << QColor::fromString(expr) + << expected; + QT_WARNING_POP + }; const auto l1 = QLatin1String(e.name); const auto l1UpperBA = QByteArray(e.name).toUpper(); @@ -766,29 +761,42 @@ void tst_QColor::setNamedColor_data() } } -void tst_QColor::setNamedColor() +void tst_QColor::fromString() { +#if QT_DEPRECATED_SINCE(6, 6) QFETCH(QColor, byCtor); QFETCH(QColor, bySetNamedColor); +#endif + QFETCH(QColor, byFromString); QFETCH(QColor, expected); +#if QT_DEPRECATED_SINCE(6, 6) QCOMPARE(byCtor, expected); QCOMPARE(bySetNamedColor, expected); +#endif + QCOMPARE(byFromString, expected); } void tst_QColor::constructNamedColorWithSpace() { + DEPRECATED_IN_6_6( QColor whiteSmoke("white smoke"); QCOMPARE(whiteSmoke, QColor(245, 245, 245)); + ) + QCOMPARE(QColor::fromString("white smoke"), QColorConstants::Svg::whitesmoke); } void tst_QColor::colorNames() { - QStringList all = QColor::colorNames(); + const QStringList all = QColor::colorNames(); QCOMPARE(all.size(), rgbTblSize); for (int i = 0; i < all.size(); ++i) QCOMPARE(all.at(i), QLatin1String(rgbTbl[i].name)); + for (const QString &name : all) + QVERIFY(QColor::isValidColorName(name)); + for (const auto &e : rgbTbl) + QVERIFY(QColor::isValidColorName(e.name)); } void tst_QColor::spec() diff --git a/tests/auto/gui/painting/qcolorspace/CMakeLists.txt b/tests/auto/gui/painting/qcolorspace/CMakeLists.txt index 9e3460d363..383c1bb890 100644 --- a/tests/auto/gui/painting/qcolorspace/CMakeLists.txt +++ b/tests/auto/gui/painting/qcolorspace/CMakeLists.txt @@ -1,39 +1,33 @@ -# 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_glob +file(GLOB_RECURSE test_data RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - resources/*) -list(APPEND test_data ${test_data_glob}) + resources/* +) + +foreach(file IN LISTS test_data) + set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/${file}" PROPERTIES QT_RESOURCE_ALIAS "${file}") +endforeach() qt_internal_add_test(tst_qcolorspace SOURCES tst_qcolorspace.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate TESTDATA ${test_data} + BUILTIN_TESTDATA ) - -file(GLOB resource_glob_0 RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "resources/*") -foreach(file IN LISTS resource_glob_0) - set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/${file}" PROPERTIES QT_RESOURCE_ALIAS "${file}") -endforeach() - -# Resources: -set(qmake_immediate_resource_files - ${resource_glob_0} -) - -qt_internal_add_resource(tst_qcolorspace "qmake_immediate" - PREFIX - "/" - FILES - ${qmake_immediate_resource_files} -) - 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 576885de34..e23b3d21a1 100644 --- a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp +++ b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -32,6 +7,7 @@ #include <qcolorspace.h> #include <qimage.h> #include <qimagereader.h> +#include <qrgbafloat.h> #include <private/qcolorspace_p.h> @@ -65,7 +41,14 @@ private slots: void imageConversion64PM(); void imageConversionOverLargerGamut_data(); 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(); @@ -84,6 +67,14 @@ private slots: void transferFunctionTable(); void description(); + void whitePoint_data(); + void whitePoint(); + void setWhitePoint(); + void grayColorSpace(); + void grayColorSpaceEffectivelySRgb(); + + void scaleAlphaValue(); + void hdrColorSpaces(); }; tst_QColorSpace::tst_QColorSpace() @@ -134,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 @@ -201,15 +201,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() @@ -217,10 +248,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()); @@ -229,7 +262,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() @@ -240,9 +289,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; } @@ -269,9 +319,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); @@ -284,11 +334,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); @@ -329,9 +380,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); @@ -346,9 +397,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); @@ -372,8 +423,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); @@ -389,17 +442,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; @@ -412,15 +465,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); @@ -460,14 +513,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); } } @@ -475,7 +528,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); } } @@ -489,6 +542,187 @@ void tst_QColorSpace::imageConversionOverLargerGamut() } } +void tst_QColorSpace::imageConversionOverLargerGamut2_data() +{ + QTest::addColumn<QImage::Format>("format"); + + QTest::newRow("rgbx16x4") << QImage::Format_RGBX16FPx4; + QTest::newRow("rgba16x4") << QImage::Format_RGBA16FPx4; + QTest::newRow("rgba16x4PM") << QImage::Format_RGBA16FPx4_Premultiplied; + QTest::newRow("rgbx32x4") << QImage::Format_RGBX32FPx4; + QTest::newRow("rgba32x4") << QImage::Format_RGBA32FPx4; + QTest::newRow("rgba32x4PM") << QImage::Format_RGBA32FPx4_Premultiplied; +} + +void tst_QColorSpace::imageConversionOverLargerGamut2() +{ + QFETCH(QImage::Format, format); + + QColorSpace csfrom = QColorSpace::DisplayP3; + QColorSpace csto = QColorSpace::SRgb; + + QImage testImage(256, 256, format); + testImage.setColorSpace(csfrom); + for (int y = 0; y < 256; ++y) + for (int x = 0; x < 256; ++x) + testImage.setPixel(x, y, qRgba(x, y, 16, 255)); + + QImage resultImage = testImage.convertedToColorSpace(csto); + for (int y = 0; y < 256; ++y) { + float lastRed = -256.0f; + for (int x = 0; x < 256; ++x) { + float pr = resultImage.pixelColor(x, y).redF(); + QVERIFY(pr >= lastRed); + lastRed = pr; + } + } + for (int x = 0; x < 256; ++x) { + float lastGreen = -256.0f; + for (int y = 0; y < 256; ++y) { + float pg = resultImage.pixelColor(x, y).greenF(); + QVERIFY(pg >= lastGreen); + lastGreen = pg; + } + } + // Test colors outside of sRGB are converted to values outside of 0-1 range. + QVERIFY(resultImage.pixelColor(255, 0).redF() > 1.0f); + QVERIFY(resultImage.pixelColor(255, 0).greenF() < 0.0f); + QVERIFY(resultImage.pixelColor(0, 255).redF() < 0.0f); + 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/"); @@ -666,10 +900,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() @@ -718,5 +970,161 @@ 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); +} + +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/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 830e0cd16c..4490877e87 100644 --- a/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp +++ b/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2014 John Layt <jlayt@kde.org> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2014 John Layt <jlayt@kde.org> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtGui/qpagelayout.h> @@ -37,6 +12,9 @@ private slots: void invalid(); void basics(); void setGetMargins(); + void setGetClampedMargins(); + void setUnits_data(); + void setUnits(); }; void tst_QPageLayout::invalid() @@ -113,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); @@ -131,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); @@ -142,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); @@ -159,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); @@ -180,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)); @@ -240,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); @@ -263,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 4912aa43c1..d2dbf990e3 100644 --- a/tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp +++ b/tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <qpageranges.h> @@ -95,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); @@ -137,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 838f7e59cd..de9b799902 100644 --- a/tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp +++ b/tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtGlobal> @@ -74,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 4363799702..02441de54c 100644 --- a/tests/auto/gui/painting/qpaintengine/tst_qpaintengine.cpp +++ b/tests/auto/gui/painting/qpaintengine/tst_qpaintengine.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/gui/painting/qpainter/CMakeLists.txt b/tests/auto/gui/painting/qpainter/CMakeLists.txt index 9466dddadd..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,202 +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 ) - -if(ANDROID) - # Resources: - set(testdata_resource_files - "drawEllipse/10x10SizeAt0x0.png" - "drawEllipse/10x10SizeAt100x100.png" - "drawEllipse/10x10SizeAt200x200.png" - "drawEllipse/13x100SizeAt0x0.png" - "drawEllipse/13x100SizeAt100x100.png" - "drawEllipse/13x100SizeAt200x200.png" - "drawEllipse/200x200SizeAt0x0.png" - "drawEllipse/200x200SizeAt100x100.png" - "drawEllipse/200x200SizeAt200x200.png" - "drawLine_rop_bitmap/dst.xbm" - "drawLine_rop_bitmap/res/res_AndNotROP.xbm" - "drawLine_rop_bitmap/res/res_AndROP.xbm" - "drawLine_rop_bitmap/res/res_ClearROP.xbm" - "drawLine_rop_bitmap/res/res_CopyROP.xbm" - "drawLine_rop_bitmap/res/res_NandROP.xbm" - "drawLine_rop_bitmap/res/res_NopROP.xbm" - "drawLine_rop_bitmap/res/res_NorROP.xbm" - "drawLine_rop_bitmap/res/res_NotAndROP.xbm" - "drawLine_rop_bitmap/res/res_NotCopyROP.xbm" - "drawLine_rop_bitmap/res/res_NotOrROP.xbm" - "drawLine_rop_bitmap/res/res_NotROP.xbm" - "drawLine_rop_bitmap/res/res_NotXorROP.xbm" - "drawLine_rop_bitmap/res/res_OrNotROP.xbm" - "drawLine_rop_bitmap/res/res_OrROP.xbm" - "drawLine_rop_bitmap/res/res_SetROP.xbm" - "drawLine_rop_bitmap/res/res_XorROP.xbm" - "drawPixmap_rop/dst1.png" - "drawPixmap_rop/dst2.png" - "drawPixmap_rop/dst3.png" - "drawPixmap_rop/res/res_AndNotROP0.png" - "drawPixmap_rop/res/res_AndNotROP1.png" - "drawPixmap_rop/res/res_AndNotROP2.png" - "drawPixmap_rop/res/res_AndNotROP3.png" - "drawPixmap_rop/res/res_AndNotROP4.png" - "drawPixmap_rop/res/res_AndNotROP5.png" - "drawPixmap_rop/res/res_AndNotROP6.png" - "drawPixmap_rop/res/res_AndNotROP7.png" - "drawPixmap_rop/res/res_AndROP0.png" - "drawPixmap_rop/res/res_AndROP1.png" - "drawPixmap_rop/res/res_AndROP2.png" - "drawPixmap_rop/res/res_AndROP3.png" - "drawPixmap_rop/res/res_AndROP4.png" - "drawPixmap_rop/res/res_AndROP5.png" - "drawPixmap_rop/res/res_AndROP6.png" - "drawPixmap_rop/res/res_AndROP7.png" - "drawPixmap_rop/res/res_ClearROP0.png" - "drawPixmap_rop/res/res_ClearROP1.png" - "drawPixmap_rop/res/res_ClearROP2.png" - "drawPixmap_rop/res/res_ClearROP3.png" - "drawPixmap_rop/res/res_ClearROP4.png" - "drawPixmap_rop/res/res_ClearROP5.png" - "drawPixmap_rop/res/res_ClearROP6.png" - "drawPixmap_rop/res/res_ClearROP7.png" - "drawPixmap_rop/res/res_CopyROP0.png" - "drawPixmap_rop/res/res_CopyROP1.png" - "drawPixmap_rop/res/res_CopyROP2.png" - "drawPixmap_rop/res/res_CopyROP3.png" - "drawPixmap_rop/res/res_CopyROP4.png" - "drawPixmap_rop/res/res_CopyROP5.png" - "drawPixmap_rop/res/res_CopyROP6.png" - "drawPixmap_rop/res/res_CopyROP7.png" - "drawPixmap_rop/res/res_NandROP0.png" - "drawPixmap_rop/res/res_NandROP1.png" - "drawPixmap_rop/res/res_NandROP2.png" - "drawPixmap_rop/res/res_NandROP3.png" - "drawPixmap_rop/res/res_NandROP4.png" - "drawPixmap_rop/res/res_NandROP5.png" - "drawPixmap_rop/res/res_NandROP6.png" - "drawPixmap_rop/res/res_NandROP7.png" - "drawPixmap_rop/res/res_NopROP0.png" - "drawPixmap_rop/res/res_NopROP1.png" - "drawPixmap_rop/res/res_NopROP2.png" - "drawPixmap_rop/res/res_NopROP3.png" - "drawPixmap_rop/res/res_NopROP4.png" - "drawPixmap_rop/res/res_NopROP5.png" - "drawPixmap_rop/res/res_NopROP6.png" - "drawPixmap_rop/res/res_NopROP7.png" - "drawPixmap_rop/res/res_NorROP0.png" - "drawPixmap_rop/res/res_NorROP1.png" - "drawPixmap_rop/res/res_NorROP2.png" - "drawPixmap_rop/res/res_NorROP3.png" - "drawPixmap_rop/res/res_NorROP4.png" - "drawPixmap_rop/res/res_NorROP5.png" - "drawPixmap_rop/res/res_NorROP6.png" - "drawPixmap_rop/res/res_NorROP7.png" - "drawPixmap_rop/res/res_NotAndROP0.png" - "drawPixmap_rop/res/res_NotAndROP1.png" - "drawPixmap_rop/res/res_NotAndROP2.png" - "drawPixmap_rop/res/res_NotAndROP3.png" - "drawPixmap_rop/res/res_NotAndROP4.png" - "drawPixmap_rop/res/res_NotAndROP5.png" - "drawPixmap_rop/res/res_NotAndROP6.png" - "drawPixmap_rop/res/res_NotAndROP7.png" - "drawPixmap_rop/res/res_NotCopyROP0.png" - "drawPixmap_rop/res/res_NotCopyROP1.png" - "drawPixmap_rop/res/res_NotCopyROP2.png" - "drawPixmap_rop/res/res_NotCopyROP3.png" - "drawPixmap_rop/res/res_NotCopyROP4.png" - "drawPixmap_rop/res/res_NotCopyROP5.png" - "drawPixmap_rop/res/res_NotCopyROP6.png" - "drawPixmap_rop/res/res_NotCopyROP7.png" - "drawPixmap_rop/res/res_NotOrROP0.png" - "drawPixmap_rop/res/res_NotOrROP1.png" - "drawPixmap_rop/res/res_NotOrROP2.png" - "drawPixmap_rop/res/res_NotOrROP3.png" - "drawPixmap_rop/res/res_NotOrROP4.png" - "drawPixmap_rop/res/res_NotOrROP5.png" - "drawPixmap_rop/res/res_NotOrROP6.png" - "drawPixmap_rop/res/res_NotOrROP7.png" - "drawPixmap_rop/res/res_NotROP0.png" - "drawPixmap_rop/res/res_NotROP1.png" - "drawPixmap_rop/res/res_NotROP2.png" - "drawPixmap_rop/res/res_NotROP3.png" - "drawPixmap_rop/res/res_NotROP4.png" - "drawPixmap_rop/res/res_NotROP5.png" - "drawPixmap_rop/res/res_NotROP6.png" - "drawPixmap_rop/res/res_NotROP7.png" - "drawPixmap_rop/res/res_NotXorROP0.png" - "drawPixmap_rop/res/res_NotXorROP1.png" - "drawPixmap_rop/res/res_NotXorROP2.png" - "drawPixmap_rop/res/res_NotXorROP3.png" - "drawPixmap_rop/res/res_NotXorROP4.png" - "drawPixmap_rop/res/res_NotXorROP5.png" - "drawPixmap_rop/res/res_NotXorROP6.png" - "drawPixmap_rop/res/res_NotXorROP7.png" - "drawPixmap_rop/res/res_OrNotROP0.png" - "drawPixmap_rop/res/res_OrNotROP1.png" - "drawPixmap_rop/res/res_OrNotROP2.png" - "drawPixmap_rop/res/res_OrNotROP3.png" - "drawPixmap_rop/res/res_OrNotROP4.png" - "drawPixmap_rop/res/res_OrNotROP5.png" - "drawPixmap_rop/res/res_OrNotROP6.png" - "drawPixmap_rop/res/res_OrNotROP7.png" - "drawPixmap_rop/res/res_OrROP0.png" - "drawPixmap_rop/res/res_OrROP1.png" - "drawPixmap_rop/res/res_OrROP2.png" - "drawPixmap_rop/res/res_OrROP3.png" - "drawPixmap_rop/res/res_OrROP4.png" - "drawPixmap_rop/res/res_OrROP5.png" - "drawPixmap_rop/res/res_OrROP6.png" - "drawPixmap_rop/res/res_OrROP7.png" - "drawPixmap_rop/res/res_SetROP0.png" - "drawPixmap_rop/res/res_SetROP1.png" - "drawPixmap_rop/res/res_SetROP2.png" - "drawPixmap_rop/res/res_SetROP3.png" - "drawPixmap_rop/res/res_SetROP4.png" - "drawPixmap_rop/res/res_SetROP5.png" - "drawPixmap_rop/res/res_SetROP6.png" - "drawPixmap_rop/res/res_SetROP7.png" - "drawPixmap_rop/res/res_XorROP0.png" - "drawPixmap_rop/res/res_XorROP1.png" - "drawPixmap_rop/res/res_XorROP2.png" - "drawPixmap_rop/res/res_XorROP3.png" - "drawPixmap_rop/res/res_XorROP4.png" - "drawPixmap_rop/res/res_XorROP5.png" - "drawPixmap_rop/res/res_XorROP6.png" - "drawPixmap_rop/res/res_XorROP7.png" - "drawPixmap_rop/src1.xbm" - "drawPixmap_rop/src2-mask.xbm" - "drawPixmap_rop/src2.xbm" - "drawPixmap_rop/src3.xbm" - "drawPixmap_rop_bitmap/dst.xbm" - "drawPixmap_rop_bitmap/res/res_AndNotROP.xbm" - "drawPixmap_rop_bitmap/res/res_AndROP.xbm" - "drawPixmap_rop_bitmap/res/res_ClearROP.xbm" - "drawPixmap_rop_bitmap/res/res_CopyROP.xbm" - "drawPixmap_rop_bitmap/res/res_NandROP.xbm" - "drawPixmap_rop_bitmap/res/res_NopROP.xbm" - "drawPixmap_rop_bitmap/res/res_NorROP.xbm" - "drawPixmap_rop_bitmap/res/res_NotAndROP.xbm" - "drawPixmap_rop_bitmap/res/res_NotCopyROP.xbm" - "drawPixmap_rop_bitmap/res/res_NotOrROP.xbm" - "drawPixmap_rop_bitmap/res/res_NotROP.xbm" - "drawPixmap_rop_bitmap/res/res_NotXorROP.xbm" - "drawPixmap_rop_bitmap/res/res_OrNotROP.xbm" - "drawPixmap_rop_bitmap/res/res_OrROP.xbm" - "drawPixmap_rop_bitmap/res/res_SetROP.xbm" - "drawPixmap_rop_bitmap/res/res_XorROP.xbm" - "drawPixmap_rop_bitmap/src1-mask.xbm" - "drawPixmap_rop_bitmap/src1.xbm" - "drawPixmap_rop_bitmap/src2.xbm" - "task217400.png" - ) - - qt_internal_add_resource(tst_qpainter "testdata" - PREFIX - "/" - FILES - ${testdata_resource_files} - ) -endif() diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp index cfcaf5b67e..92b28f65bd 100644 --- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp @@ -1,31 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <qpainter.h> @@ -69,6 +43,9 @@ Q_OBJECT public: tst_QPainter(); + enum ClipType { ClipRect, ClipRectF, ClipRegionSingle, ClipRegionMulti, ClipPathR, ClipPath }; + Q_ENUM(ClipType); + private slots: void cleanupTestCase(); void getSetCheck(); @@ -84,6 +61,7 @@ private slots: #endif void drawPixmapFragments(); void drawPixmapNegativeScale(); + void drawPixmapRounding(); void drawLine_data(); void drawLine(); @@ -155,6 +133,8 @@ private slots: void clipBoundingRect(); void transformedClip(); + void scaledClipConsistency_data(); + void scaledClipConsistency(); void setOpacity_data(); void setOpacity(); @@ -190,6 +170,7 @@ private slots: void radialGradientRgb30(); #endif + void radialGradient_QTBUG120332_ubsan(); void fpe_pixmapTransform(); void fpe_zeroLengthLines(); void fpe_divByZero(); @@ -767,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"); @@ -1752,10 +1743,11 @@ void tst_QPainter::setClipRect() /* Verify that the clipping works correctly. - The red outline should be covered by the blue rect on top and left, - while it should be clipped on the right and bottom and thus the red outline be visible + Just like fillRect, cliprect should snap rightwards and downwards in case of .5 coordinates. + The red outline should be covered by the blue rect on top, + while it should be clipped on the other edges and thus the red outline be visible - See: QTBUG-83229 + See: QTBUG-83229, modified by QTBUG-100329 */ void tst_QPainter::clipRect() { @@ -1781,7 +1773,7 @@ void tst_QPainter::clipRect() p.end(); QCOMPARE(image.pixelColor(clipRect.left() + 1, clipRect.top()), QColor(Qt::blue)); - QCOMPARE(image.pixelColor(clipRect.left(), clipRect.top() + 1), QColor(Qt::blue)); + QCOMPARE(image.pixelColor(clipRect.left(), clipRect.top() + 1), QColor(Qt::red)); QCOMPARE(image.pixelColor(clipRect.left() + 1, clipRect.bottom()), QColor(Qt::red)); QCOMPARE(image.pixelColor(clipRect.right(), clipRect.top() + 1), QColor(Qt::red)); } @@ -2101,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()) @@ -2516,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); @@ -2536,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); @@ -2593,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); @@ -2789,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); @@ -2849,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) @@ -3552,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", @@ -3797,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); @@ -3906,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); @@ -4583,6 +4604,96 @@ void tst_QPainter::transformedClip() } } +void tst_QPainter::scaledClipConsistency_data() +{ + QTest::addColumn<ClipType>("clipType"); + + QTest::newRow("clipRect") << ClipRect; + QTest::newRow("clipRectF") << ClipRectF; + QTest::newRow("clipRegionSingle") << ClipRegionSingle; + QTest::newRow("clipRegionMulti") << ClipRegionMulti; + QTest::newRow("clipPathR") << ClipPathR; + QTest::newRow("clipPath") << ClipPath; +} + +void tst_QPainter::scaledClipConsistency() +{ + QFETCH(ClipType, clipType); + + const QList<QRect> clipRects = { + // Varying odd and even coordinates and width/height + QRect(1, 1, 7, 8), + QRect(8, 0, 8, 9), + QRect(0, 9, 8, 7), + QRect(8, 9, 8, 7), + }; + // Assert that these are edge to edge: + QPointF center = QRectF(clipRects[0]).bottomRight(); + Q_ASSERT(QRectF(clipRects[1]).bottomLeft() == center); + Q_ASSERT(QRectF(clipRects[2]).topRight() == center); + Q_ASSERT(QRectF(clipRects[3]).topLeft() == center); + + QRegion multiRegion; + for (const QRect &clipRect : clipRects) + multiRegion += clipRect; + + QColor fillColor(Qt::black); + fillColor.setAlphaF(0.5); + + for (int i = 100; i <= 300; i++) { + qreal dpr = qreal(i) / 100.0; + QImage img(QSize(16, 16) * dpr, QImage::Format_RGB32); + img.fill(Qt::white); + img.setDevicePixelRatio(dpr); + + for (const QRect &clipRect : clipRects) { + QPainter p(&img); + switch (clipType) { + case ClipRect: + p.setClipRect(clipRect); + break; + case ClipRectF: + p.setClipRect(QRectF(clipRect)); + break; + case ClipRegionSingle: + p.setClipRegion(QRegion(clipRect)); + break; + case ClipRegionMulti: + p.setClipRegion(multiRegion); + break; + case ClipPath: + p.rotate(0.001); // Avoid the path being optimized to a rectf + Q_FALLTHROUGH(); + case ClipPathR: { + QPainterPath path; + path.addRect(clipRect); // Will be recognized and converted back to a rectf + p.setClipPath(path); + break; + } + default: + Q_ASSERT(false); + break; + } + p.fillRect(p.window(), fillColor); + if (clipType == ClipRegionMulti) + break; // once is enough, we're not using the clipRect anyway + } + + int qtWidth = img.width() / 4; + int qtHeight = img.height() / 4; + QPoint imgCenter = img.rect().center(); + const QRgb targetColor = img.pixel(qtWidth, qtHeight); + + // Test that there are no gaps or overlaps where the cliprects meet + for (int offset = -2; offset <= 2; offset++) { + QCOMPARE(img.pixel(imgCenter.x() + offset, qtHeight), targetColor); + QCOMPARE(img.pixel(imgCenter.x() + offset, img.height() - qtHeight), targetColor); + QCOMPARE(img.pixel(qtWidth, imgCenter.y() + offset), targetColor); + QCOMPARE(img.pixel(img.width() - qtWidth, imgCenter.y() + offset), targetColor); + } + } +} + #if defined(Q_OS_MAC) // Only Mac supports sub pixel positions in raster engine currently void tst_QPainter::drawText_subPixelPositionsInRaster_qtbug5053() @@ -4819,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)); @@ -4933,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; @@ -5103,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 { @@ -5428,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 53ea3ce9fb..7cb9e74216 100644 --- a/tests/auto/gui/painting/qpainter/utils/createImages/main.cpp +++ b/tests/auto/gui/painting/qpainter/utils/createImages/main.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <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 dcba95d33c..c00dc3a78a 100644 --- a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp +++ b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -106,6 +81,8 @@ private slots: void intersectionEquality(); void intersectionPointOnEdge(); + + void boundsAtStartPoint(); }; void tst_QPainterPath::cleanupTestCase() @@ -410,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() @@ -788,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() @@ -918,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; } } @@ -1245,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 @@ -1440,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 de3f612b10..ce80019273 100644 --- a/tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp +++ b/tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/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 4f855194a4..593176686e 100644 --- a/tests/auto/gui/painting/qpathclipper/pathcompare.h +++ b/tests/auto/gui/painting/qpathclipper/pathcompare.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef PATHCOMPARE_H #define PATHCOMPARE_H diff --git a/tests/auto/gui/painting/qpathclipper/paths.cpp b/tests/auto/gui/painting/qpathclipper/paths.cpp index a814958394..7b1486152b 100644 --- a/tests/auto/gui/painting/qpathclipper/paths.cpp +++ b/tests/auto/gui/painting/qpathclipper/paths.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "paths.h" QPainterPath Paths::rect() diff --git a/tests/auto/gui/painting/qpathclipper/paths.h b/tests/auto/gui/painting/qpathclipper/paths.h index 61daa0c3a4..73b41d324a 100644 --- a/tests/auto/gui/painting/qpathclipper/paths.h +++ b/tests/auto/gui/painting/qpathclipper/paths.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef 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 83a8d6bd47..c5ef8373fd 100644 --- a/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp +++ b/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "private/qpathclipper_p.h" #include "paths.h" #include "pathcompare.h" @@ -495,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(); } } @@ -797,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)); @@ -845,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)); @@ -853,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 c74baf0ba4..4d6b1f01b9 100644 --- a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp +++ b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <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 64c01a81b5..b3ff1c76f9 100644 --- a/tests/auto/gui/painting/qpen/tst_qpen.cpp +++ b/tests/auto/gui/painting/qpen/tst_qpen.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> diff --git a/tests/auto/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 4cde0aa549..cd24135ac6 100644 --- a/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp +++ b/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -41,6 +16,7 @@ class tst_QPolygon : public QObject private slots: void constructors(); + void toPolygonF(); void boundingRect_data(); void boundingRect(); void boundingRectF_data(); @@ -80,6 +56,17 @@ void tst_QPolygon::constructors() constructors_helperF(QRectF(1, 2, 3, 4)); } +void tst_QPolygon::toPolygonF() +{ + const QPolygon p = {{1, 1}, {-1, 1}, {-1, -1}, {1, -1}}; + auto pf = p.toPolygonF(); + static_assert(std::is_same_v<decltype(pf), QPolygonF>); + QCOMPARE(pf.size(), p.size()); + auto p2 = pf.toPolygon(); + static_assert(std::is_same_v<decltype(p2), QPolygon>); + QCOMPARE(p, p2); +} + void tst_QPolygon::boundingRect_data() { QTest::addColumn<QPolygon>("poly"); @@ -181,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 29179c44a0..934725844a 100644 --- a/tests/auto/gui/painting/qregion/tst_qregion.cpp +++ b/tests/auto/gui/painting/qregion/tst_qregion.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -163,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)); @@ -215,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; @@ -222,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); } } @@ -341,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"); } @@ -887,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() @@ -902,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)); } @@ -918,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 1bab7200f0..428174bfc6 100644 --- a/tests/auto/gui/painting/qtransform/tst_qtransform.cpp +++ b/tests/auto/gui/painting/qtransform/tst_qtransform.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> |