summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/painting
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/painting')
-rw-r--r--tests/auto/gui/painting/CMakeLists.txt9
-rw-r--r--tests/auto/gui/painting/qbrush/CMakeLists.txt8
-rw-r--r--tests/auto/gui/painting/qbrush/tst_qbrush.cpp2
-rw-r--r--tests/auto/gui/painting/qcolor/CMakeLists.txt8
-rw-r--r--tests/auto/gui/painting/qcolor/tst_qcolor.cpp4
-rw-r--r--tests/auto/gui/painting/qcolorspace/CMakeLists.txt8
-rw-r--r--tests/auto/gui/painting/qcolorspace/resources/CGATS001Compat-v2-micro.iccbin0 -> 8464 bytes
-rw-r--r--tests/auto/gui/painting/qcolorspace/resources/Rec. ITU-R BT.2100 PQ.iccbin0 -> 13300 bytes
-rw-r--r--tests/auto/gui/painting/qcolorspace/resources/VideoHD.iccbin0 -> 786 bytes
-rw-r--r--tests/auto/gui/painting/qcolorspace/resources/sGrey-v4.iccbin0 -> 360 bytes
-rw-r--r--tests/auto/gui/painting/qcolorspace/resources/sRGB_ICC_v4_Appearance.iccbin0 -> 63868 bytes
-rw-r--r--tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp398
-rw-r--r--tests/auto/gui/painting/qcolortransform/CMakeLists.txt6
-rw-r--r--tests/auto/gui/painting/qcolortransform/tst_qcolortransform.cpp37
-rw-r--r--tests/auto/gui/painting/qpagelayout/CMakeLists.txt8
-rw-r--r--tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp251
-rw-r--r--tests/auto/gui/painting/qpageranges/CMakeLists.txt8
-rw-r--r--tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp6
-rw-r--r--tests/auto/gui/painting/qpagesize/CMakeLists.txt8
-rw-r--r--tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp4
-rw-r--r--tests/auto/gui/painting/qpaintengine/CMakeLists.txt8
-rw-r--r--tests/auto/gui/painting/qpaintengine/tst_qpaintengine.cpp2
-rw-r--r--tests/auto/gui/painting/qpainter/CMakeLists.txt8
-rw-r--r--tests/auto/gui/painting/qpainter/tst_qpainter.cpp112
-rw-r--r--tests/auto/gui/painting/qpainter/utils/createImages/main.cpp2
-rw-r--r--tests/auto/gui/painting/qpainterpath/CMakeLists.txt8
-rw-r--r--tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp100
-rw-r--r--tests/auto/gui/painting/qpainterpathstroker/CMakeLists.txt8
-rw-r--r--tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp2
-rw-r--r--tests/auto/gui/painting/qpathclipper/CMakeLists.txt9
-rw-r--r--tests/auto/gui/painting/qpathclipper/pathcompare.h2
-rw-r--r--tests/auto/gui/painting/qpathclipper/paths.cpp2
-rw-r--r--tests/auto/gui/painting/qpathclipper/paths.h2
-rw-r--r--tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp30
-rw-r--r--tests/auto/gui/painting/qpdfwriter/CMakeLists.txt8
-rw-r--r--tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp2
-rw-r--r--tests/auto/gui/painting/qpen/CMakeLists.txt8
-rw-r--r--tests/auto/gui/painting/qpen/tst_qpen.cpp2
-rw-r--r--tests/auto/gui/painting/qpolygon/CMakeLists.txt8
-rw-r--r--tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp6
-rw-r--r--tests/auto/gui/painting/qregion/CMakeLists.txt8
-rw-r--r--tests/auto/gui/painting/qregion/tst_qregion.cpp26
-rw-r--r--tests/auto/gui/painting/qtransform/CMakeLists.txt8
-rw-r--r--tests/auto/gui/painting/qtransform/tst_qtransform.cpp2
44 files changed, 935 insertions, 203 deletions
diff --git a/tests/auto/gui/painting/CMakeLists.txt b/tests/auto/gui/painting/CMakeLists.txt
index b94a699886..b49a80b180 100644
--- a/tests/auto/gui/painting/CMakeLists.txt
+++ b/tests/auto/gui/painting/CMakeLists.txt
@@ -1,8 +1,6 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from painting.pro.
-
add_subdirectory(qpainterpath)
add_subdirectory(qpainterpathstroker)
add_subdirectory(qcolor)
@@ -12,12 +10,15 @@ 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)
diff --git a/tests/auto/gui/painting/qbrush/CMakeLists.txt b/tests/auto/gui/painting/qbrush/CMakeLists.txt
index eb2fac8a6c..313bce20a4 100644
--- a/tests/auto/gui/painting/qbrush/CMakeLists.txt
+++ b/tests/auto/gui/painting/qbrush/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qbrush.pro.
-
#####################################################################
## 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
diff --git a/tests/auto/gui/painting/qbrush/tst_qbrush.cpp b/tests/auto/gui/painting/qbrush/tst_qbrush.cpp
index 64513b89c6..678c8d9b32 100644
--- a/tests/auto/gui/painting/qbrush/tst_qbrush.cpp
+++ b/tests/auto/gui/painting/qbrush/tst_qbrush.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/painting/qcolor/CMakeLists.txt b/tests/auto/gui/painting/qcolor/CMakeLists.txt
index 53dc9e4c97..52e551855c 100644
--- a/tests/auto/gui/painting/qcolor/CMakeLists.txt
+++ b/tests/auto/gui/painting/qcolor/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qcolor.pro.
-
#####################################################################
## 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
diff --git a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
index 60a63fadcb..f592db5544 100644
--- a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
+++ b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2020 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -73,7 +73,7 @@ private slots:
void toCmykNonDestructive();
void toHsl_data();
- void toHsl();;
+ void toHsl();
void toHslNonDestructive();
void convertTo();
diff --git a/tests/auto/gui/painting/qcolorspace/CMakeLists.txt b/tests/auto/gui/painting/qcolorspace/CMakeLists.txt
index 9d2729897d..383c1bb890 100644
--- a/tests/auto/gui/painting/qcolorspace/CMakeLists.txt
+++ b/tests/auto/gui/painting/qcolorspace/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qcolorspace.pro.
-
#####################################################################
## tst_qcolorspace Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qcolorspace LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
# Collect test data
file(GLOB_RECURSE test_data
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
diff --git a/tests/auto/gui/painting/qcolorspace/resources/CGATS001Compat-v2-micro.icc b/tests/auto/gui/painting/qcolorspace/resources/CGATS001Compat-v2-micro.icc
new file mode 100644
index 0000000000..b5a73495bf
--- /dev/null
+++ b/tests/auto/gui/painting/qcolorspace/resources/CGATS001Compat-v2-micro.icc
Binary files differ
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
new file mode 100644
index 0000000000..e0ceaa12f8
--- /dev/null
+++ b/tests/auto/gui/painting/qcolorspace/resources/Rec. ITU-R BT.2100 PQ.icc
Binary files differ
diff --git a/tests/auto/gui/painting/qcolorspace/resources/VideoHD.icc b/tests/auto/gui/painting/qcolorspace/resources/VideoHD.icc
new file mode 100644
index 0000000000..b96eb68136
--- /dev/null
+++ b/tests/auto/gui/painting/qcolorspace/resources/VideoHD.icc
Binary files differ
diff --git a/tests/auto/gui/painting/qcolorspace/resources/sGrey-v4.icc b/tests/auto/gui/painting/qcolorspace/resources/sGrey-v4.icc
new file mode 100644
index 0000000000..2187b6786a
--- /dev/null
+++ b/tests/auto/gui/painting/qcolorspace/resources/sGrey-v4.icc
Binary files differ
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
new file mode 100644
index 0000000000..30da950907
--- /dev/null
+++ b/tests/auto/gui/painting/qcolorspace/resources/sRGB_ICC_v4_Appearance.icc
Binary files differ
diff --git a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp
index 08f45a2552..6c103ce4f3 100644
--- a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp
+++ b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2018 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -42,7 +42,12 @@ private slots:
void imageConversionOverLargerGamut();
void imageConversionOverLargerGamut2_data();
void imageConversionOverLargerGamut2();
-
+ void imageConversionOverAnyGamutFP_data();
+ void imageConversionOverAnyGamutFP();
+ void imageConversionOverAnyGamutFP2_data();
+ void imageConversionOverAnyGamutFP2();
+ void imageConversionOverNonThreeComponentMatrix_data();
+ void imageConversionOverNonThreeComponentMatrix();
void loadImage();
void primaries();
@@ -61,6 +66,13 @@ private slots:
void transferFunctionTable();
void description();
+ void whitePoint_data();
+ void whitePoint();
+ void setWhitePoint();
+ void grayColorSpace();
+ void grayColorSpaceEffectivelySRgb();
+
+ void scaleAlphaValue();
};
tst_QColorSpace::tst_QColorSpace()
@@ -111,6 +123,15 @@ void tst_QColorSpace::namedColorSpaces_data()
QTest::newRow("ProPhoto RGB") << QColorSpace::ProPhotoRgb << true
<< QColorSpace::Primaries::ProPhotoRgb
<< QColorSpace::TransferFunction::ProPhotoRgb;
+ QTest::newRow("BT.2020") << QColorSpace::Bt2020 << true
+ << QColorSpace::Primaries::Bt2020
+ << QColorSpace::TransferFunction::Bt2020;
+ QTest::newRow("BT.2100 PQ") << QColorSpace::Bt2100Pq << true
+ << QColorSpace::Primaries::Bt2020
+ << QColorSpace::TransferFunction::St2084;
+ QTest::newRow("BT.2100 HLG") << QColorSpace::Bt2100Hlg << true
+ << QColorSpace::Primaries::Bt2020
+ << QColorSpace::TransferFunction::Hlg;
QTest::newRow("0") << QColorSpace::NamedColorSpace(0)
<< false
<< QColorSpace::Primaries::Custom
@@ -178,15 +199,46 @@ void tst_QColorSpace::fromIccProfile_data()
QTest::addColumn<QString>("testProfile");
QTest::addColumn<QColorSpace::NamedColorSpace>("namedColorSpace");
QTest::addColumn<QColorSpace::TransferFunction>("transferFunction");
+ QTest::addColumn<QColorSpace::TransformModel>("transformModel");
+ QTest::addColumn<QColorSpace::ColorModel>("colorModel");
QTest::addColumn<QString>("description");
QString prefix = QFINDTESTDATA("resources/");
// Read the official sRGB ICCv2 profile:
QTest::newRow("sRGB2014 (ICCv2)") << prefix + "sRGB2014.icc" << QColorSpace::SRgb
- << QColorSpace::TransferFunction::SRgb << QString("sRGB2014");
+ << QColorSpace::TransferFunction::SRgb
+ << QColorSpace::TransformModel::ThreeComponentMatrix
+ << QColorSpace::ColorModel::Rgb << QString("sRGB2014");
// My monitor's profile:
QTest::newRow("HP ZR30w (ICCv4)") << prefix + "HP_ZR30w.icc" << QColorSpace::NamedColorSpace(0)
- << QColorSpace::TransferFunction::Gamma << QString("HP Z30i");
+ << QColorSpace::TransferFunction::Gamma
+ << QColorSpace::TransformModel::ThreeComponentMatrix
+ << QColorSpace::ColorModel::Rgb << QString("HP Z30i");
+ // A profile to HD TV
+ QTest::newRow("VideoHD") << prefix + "VideoHD.icc" << QColorSpace::NamedColorSpace(0)
+ << QColorSpace::TransferFunction::Custom
+ << QColorSpace::TransformModel::ElementListProcessing
+ << QColorSpace::ColorModel::Rgb << QString("HDTV (Rec. 709)");
+ // sRGB on PCSLab format
+ QTest::newRow("sRGB ICCv4 Appearance") << prefix + "sRGB_ICC_v4_Appearance.icc" << QColorSpace::NamedColorSpace(0)
+ << QColorSpace::TransferFunction::Custom
+ << QColorSpace::TransformModel::ElementListProcessing
+ << QColorSpace::ColorModel::Rgb << QString("sRGB_ICC_v4_Appearance.icc");
+ // Grayscale profile
+ QTest::newRow("sGrey-v4") << prefix + "sGrey-v4.icc" << QColorSpace::NamedColorSpace(0)
+ << QColorSpace::TransferFunction::SRgb
+ << QColorSpace::TransformModel::ThreeComponentMatrix
+ << QColorSpace::ColorModel::Gray << QString("sGry");
+ // CMYK profile
+ QTest::newRow("CGATS compat") << prefix + "CGATS001Compat-v2-micro.icc" << QColorSpace::NamedColorSpace(0)
+ << QColorSpace::TransferFunction::Custom
+ << QColorSpace::TransformModel::ElementListProcessing
+ << QColorSpace::ColorModel::Cmyk << QString("uCMY");
+ // BT.2100 PQ profile
+ QTest::newRow("BT.2100 PQ") << prefix + "Rec. ITU-R BT.2100 PQ.icc" << QColorSpace::Bt2100Pq
+ << QColorSpace::TransferFunction::St2084
+ << QColorSpace::TransformModel::ThreeComponentMatrix
+ << QColorSpace::ColorModel::Rgb << QString("Rec. ITU-R BT.2100 PQ");
}
void tst_QColorSpace::fromIccProfile()
@@ -194,10 +246,12 @@ void tst_QColorSpace::fromIccProfile()
QFETCH(QString, testProfile);
QFETCH(QColorSpace::NamedColorSpace, namedColorSpace);
QFETCH(QColorSpace::TransferFunction, transferFunction);
+ QFETCH(QColorSpace::TransformModel, transformModel);
+ QFETCH(QColorSpace::ColorModel, colorModel);
QFETCH(QString, description);
QFile file(testProfile);
- file.open(QIODevice::ReadOnly);
+ QVERIFY(file.open(QIODevice::ReadOnly));
QByteArray iccProfile = file.readAll();
QColorSpace fileColorSpace = QColorSpace::fromIccProfile(iccProfile);
QVERIFY(fileColorSpace.isValid());
@@ -206,7 +260,23 @@ void tst_QColorSpace::fromIccProfile()
QCOMPARE(fileColorSpace, namedColorSpace);
QCOMPARE(fileColorSpace.transferFunction(), transferFunction);
+ QCOMPARE(fileColorSpace.transformModel(), transformModel);
+ QCOMPARE(fileColorSpace.colorModel(), colorModel);
QCOMPARE(fileColorSpace.description(), description);
+
+ QByteArray iccProfile2 = fileColorSpace.iccProfile();
+ QCOMPARE(iccProfile, iccProfile2);
+ QColorSpace fileColorSpace2 = QColorSpace::fromIccProfile(iccProfile2);
+ QCOMPARE(fileColorSpace2, fileColorSpace);
+
+ // Change description to force generation of new icc profile data.
+ fileColorSpace2.setDescription("Hello my QTest description");
+ iccProfile2 = fileColorSpace2.iccProfile();
+ QCOMPARE_NE(iccProfile, iccProfile2);
+ fileColorSpace2 = QColorSpace::fromIccProfile(iccProfile2);
+ QVERIFY(fileColorSpace2.isValid());
+ // Note, we do not currently compare description in color space equality
+ QCOMPARE(fileColorSpace2, fileColorSpace);
}
void tst_QColorSpace::imageConversion_data()
@@ -217,9 +287,10 @@ void tst_QColorSpace::imageConversion_data()
QTest::newRow("sRGB -> Display-P3") << QColorSpace::SRgb << QColorSpace::DisplayP3 << 0;
QTest::newRow("sRGB -> Adobe RGB") << QColorSpace::SRgb << QColorSpace::AdobeRgb << 2;
- QTest::newRow("Display-P3 -> sRGB") << QColorSpace::DisplayP3 << QColorSpace::SRgb << 0;
QTest::newRow("Adobe RGB -> sRGB") << QColorSpace::AdobeRgb << QColorSpace::SRgb << 2;
+ QTest::newRow("Adobe RGB -> Display-P3") << QColorSpace::AdobeRgb << QColorSpace::DisplayP3 << 4;
QTest::newRow("Display-P3 -> Adobe RGB") << QColorSpace::DisplayP3 << QColorSpace::AdobeRgb << 2;
+ QTest::newRow("Display-P3 -> sRGB") << QColorSpace::DisplayP3 << QColorSpace::SRgb << 0;
QTest::newRow("sRGB -> sRGB Linear") << QColorSpace::SRgb << QColorSpace::SRgbLinear << 0;
QTest::newRow("sRGB Linear -> sRGB") << QColorSpace::SRgbLinear << QColorSpace::SRgb << 0;
}
@@ -246,9 +317,9 @@ void tst_QColorSpace::imageConversion()
int lastBlue = 0;
for (int i = 0; i < 256; ++i) {
QRgb p = testImage.pixel(i, 0);
- QVERIFY(qRed(p) >= lastRed);
- QVERIFY(qGreen(p) >= lastGreen);
- QVERIFY(qBlue(p) >= lastBlue);
+ QCOMPARE_GE(qRed(p), lastRed);
+ QCOMPARE_GE(qGreen(p), lastGreen);
+ QCOMPARE_GE(qBlue(p), lastBlue);
lastRed = qRed(p);
lastGreen = qGreen(p);
lastBlue = qBlue(p);
@@ -261,11 +332,12 @@ void tst_QColorSpace::imageConversion()
QCOMPARE(testImage.colorSpace(), QColorSpace(fromColorSpace));
for (int i = 0; i < 256; ++i) {
QRgb p = testImage.pixel(i, 0);
- QVERIFY(qAbs(qRed(p) - qGreen(p)) <= tolerance);
- QVERIFY(qAbs(qRed(p) - qBlue(p)) <= tolerance);
- QVERIFY((lastRed - qRed(p)) <= (tolerance / 2));
- QVERIFY((lastGreen - qGreen(p)) <= (tolerance / 2));
- QVERIFY((lastBlue - qBlue(p)) <= (tolerance / 2));
+ QCOMPARE_LE(qAbs(qRed(p) - qBlue(p)), tolerance);
+ QCOMPARE_LE(qAbs(qRed(p) - qGreen(p)), tolerance);
+ QCOMPARE_LE(qAbs(qGreen(p) - qBlue(p)), tolerance);
+ QCOMPARE_LE(lastRed - qRed(p), tolerance / 2);
+ QCOMPARE_LE(lastBlue - qBlue(p), tolerance / 2);
+ QCOMPARE_LE(lastGreen - qGreen(p), tolerance / 2);
lastRed = qRed(p);
lastGreen = qGreen(p);
lastBlue = qBlue(p);
@@ -306,9 +378,9 @@ void tst_QColorSpace::imageConversion64()
int lastBlue = 0;
for (int i = 0; i < 256; ++i) {
QRgb p = testImage.pixel(i, 0);
- QVERIFY(qRed(p) >= lastRed);
- QVERIFY(qGreen(p) >= lastGreen);
- QVERIFY(qBlue(p) >= lastBlue);
+ QCOMPARE_GE(qRed(p), lastRed);
+ QCOMPARE_GE(qGreen(p), lastGreen);
+ QCOMPARE_GE(qBlue(p), lastBlue);
lastRed = qRed(p);
lastGreen = qGreen(p);
lastBlue = qBlue(p);
@@ -323,9 +395,9 @@ void tst_QColorSpace::imageConversion64()
QRgb p = testImage.pixel(i, 0);
QCOMPARE(qRed(p), qGreen(p));
QCOMPARE(qRed(p), qBlue(p));
- QVERIFY((lastRed - qRed(p)) <= 0);
- QVERIFY((lastGreen - qGreen(p)) <= 0);
- QVERIFY((lastBlue - qBlue(p)) <= 0);
+ QCOMPARE_GE(qRed(p), lastRed);
+ QCOMPARE_GE(qGreen(p), lastGreen);
+ QCOMPARE_GE(qBlue(p), lastBlue);
lastRed = qRed(p);
lastGreen = qGreen(p);
lastBlue = qBlue(p);
@@ -349,8 +421,10 @@ void tst_QColorSpace::imageConversion64PM()
for (int j = 0; j < 16; ++j) {
int a = j * 15;
- for (int i = 0; i < 256; ++i)
- testImage.setPixel(i, j, qPremultiply(qRgba(i, i, i, a)));
+ for (int i = 0; i < 256; ++i) {
+ QRgba64 color = QRgba64::fromRgba(i, i, i, a);
+ testImage.setPixelColor(i, j, QColor::fromRgba64(color));
+ }
}
testImage.setColorSpace(fromColorSpace);
@@ -366,17 +440,17 @@ void tst_QColorSpace::imageConversion64PM()
const int expectedAlpha = j * 15;
for (int i = 0; i < 256; ++i) {
QRgb p = testImage.pixel(i, j);
- QVERIFY(qRed(p) >= lastRed);
- QVERIFY(qGreen(p) >= lastGreen);
- QVERIFY(qBlue(p) >= lastBlue);
+ QCOMPARE_GE(qRed(p), lastRed);
+ QCOMPARE_GE(qGreen(p), lastGreen);
+ QCOMPARE_GE(qBlue(p), lastBlue);
QCOMPARE(qAlpha(p), expectedAlpha);
lastRed = qRed(p);
lastGreen = qGreen(p);
lastBlue = qBlue(p);
}
- QVERIFY(lastRed <= expectedAlpha);
- QVERIFY(lastGreen <= expectedAlpha);
- QVERIFY(lastBlue <= expectedAlpha);
+ QCOMPARE_LE(lastRed, expectedAlpha);
+ QCOMPARE_LE(lastGreen, expectedAlpha);
+ QCOMPARE_LE(lastBlue, expectedAlpha);
lastRed = 0;
lastGreen = 0;
lastBlue = 0;
@@ -389,15 +463,15 @@ void tst_QColorSpace::imageConversion64PM()
for (int i = 0; i < 256; ++i) {
QRgb expected = qPremultiply(qRgba(i, i, i, expectedAlpha));
QRgb p = testImage.pixel(i, j);
- QCOMPARE(qRed(p), qGreen(p));
- QCOMPARE(qRed(p), qBlue(p));
+ QCOMPARE_LE(qAbs(qRed(p) - qGreen(p)), 1);
+ QCOMPARE_LE(qAbs(qRed(p) - qBlue(p)), 1);
QCOMPARE(qAlpha(p), expectedAlpha);
- QVERIFY((lastRed - qRed(p)) <= 0);
- QVERIFY((lastGreen - qGreen(p)) <= 0);
- QVERIFY((lastBlue - qBlue(p)) <= 0);
- QVERIFY(qAbs(qRed(p) - qRed(expected)) <= 1);
- QVERIFY(qAbs(qGreen(p) - qGreen(expected)) <= 1);
- QVERIFY(qAbs(qBlue(p) - qBlue(expected)) <= 1);
+ QCOMPARE_GE(qRed(p), lastRed);
+ QCOMPARE_GE(qGreen(p), lastGreen);
+ QCOMPARE_GE(qBlue(p), lastBlue);
+ QCOMPARE_LE(qAbs(qRed(p) - qRed(expected)), 1);
+ QCOMPARE_LE(qAbs(qGreen(p) - qGreen(expected)), 1);
+ QCOMPARE_LE(qAbs(qBlue(p) - qBlue(expected)), 1);
lastRed = qRed(p);
lastGreen = qGreen(p);
lastBlue = qBlue(p);
@@ -437,14 +511,14 @@ void tst_QColorSpace::imageConversionOverLargerGamut()
testImage.setColorSpace(csfrom);
for (int y = 0; y < 256; ++y)
for (int x = 0; x < 256; ++x)
- testImage.setPixel(x, y, qRgb(x, y, 0));
+ testImage.setPixel(x, y, qRgb(x, y, qAbs(x - y)));
QImage resultImage = testImage.convertedToColorSpace(csto);
for (int y = 0; y < 256; ++y) {
int lastRed = 0;
for (int x = 0; x < 256; ++x) {
QRgb p = resultImage.pixel(x, y);
- QVERIFY(qRed(p) >= lastRed);
+ QCOMPARE_GE(qRed(p), lastRed);
lastRed = qRed(p);
}
}
@@ -452,7 +526,7 @@ void tst_QColorSpace::imageConversionOverLargerGamut()
int lastGreen = 0;
for (int y = 0; y < 256; ++y) {
QRgb p = resultImage.pixel(x, y);
- QVERIFY(qGreen(p) >= lastGreen);
+ QCOMPARE_GE(qGreen(p), lastGreen);
lastGreen = qGreen(p);
}
}
@@ -515,6 +589,138 @@ void tst_QColorSpace::imageConversionOverLargerGamut2()
QVERIFY(resultImage.pixelColor(0, 255).greenF() > 1.0f);
}
+void tst_QColorSpace::imageConversionOverAnyGamutFP_data()
+{
+ QTest::addColumn<QColorSpace::NamedColorSpace>("fromColorSpace");
+ QTest::addColumn<QColorSpace::NamedColorSpace>("toColorSpace");
+
+ QTest::newRow("sRGB -> Display-P3") << QColorSpace::SRgb << QColorSpace::DisplayP3;
+ QTest::newRow("sRGB -> Adobe RGB") << QColorSpace::SRgb << QColorSpace::AdobeRgb;
+ QTest::newRow("sRGB -> ProPhoto RGB") << QColorSpace::SRgb << QColorSpace::ProPhotoRgb;
+ QTest::newRow("Adobe RGB -> sRGB") << QColorSpace::AdobeRgb << QColorSpace::SRgb;
+ QTest::newRow("Adobe RGB -> Display-P3") << QColorSpace::AdobeRgb << QColorSpace::DisplayP3;
+ QTest::newRow("Adobe RGB -> ProPhoto RGB") << QColorSpace::AdobeRgb << QColorSpace::ProPhotoRgb;
+ QTest::newRow("Display-P3 -> sRGB") << QColorSpace::DisplayP3 << QColorSpace::SRgb;
+ QTest::newRow("Display-P3 -> Adobe RGB") << QColorSpace::DisplayP3 << QColorSpace::AdobeRgb;
+ QTest::newRow("Display-P3 -> ProPhoto RGB") << QColorSpace::DisplayP3 << QColorSpace::ProPhotoRgb;
+}
+
+void tst_QColorSpace::imageConversionOverAnyGamutFP()
+{
+ QFETCH(QColorSpace::NamedColorSpace, fromColorSpace);
+ QFETCH(QColorSpace::NamedColorSpace, toColorSpace);
+
+ QColorSpace csfrom(fromColorSpace);
+ QColorSpace csto(toColorSpace);
+ csfrom.setTransferFunction(QColorSpace::TransferFunction::Linear);
+ csto.setTransferFunction(QColorSpace::TransferFunction::Linear);
+
+ QImage testImage(256, 256, QImage::Format_RGBX32FPx4);
+ testImage.setColorSpace(csfrom);
+ for (int y = 0; y < 256; ++y)
+ for (int x = 0; x < 256; ++x)
+ testImage.setPixel(x, y, qRgb(x, y, 0));
+
+ QImage resultImage = testImage.convertedToColorSpace(csto);
+ resultImage.convertToColorSpace(csfrom);
+
+ for (int y = 0; y < 256; ++y) {
+ for (int x = 0; x < 256; ++x) {
+ QCOMPARE(resultImage.pixel(x, y), testImage.pixel(x, y));
+ }
+ }
+}
+
+void tst_QColorSpace::imageConversionOverAnyGamutFP2_data()
+{
+ imageConversionOverAnyGamutFP_data();
+}
+
+void tst_QColorSpace::imageConversionOverAnyGamutFP2()
+{
+ QFETCH(QColorSpace::NamedColorSpace, fromColorSpace);
+ QFETCH(QColorSpace::NamedColorSpace, toColorSpace);
+
+ // Same as imageConversionOverAnyGamutFP but using format switching transform
+ QColorSpace csfrom(fromColorSpace);
+ QColorSpace csto(toColorSpace);
+ csfrom.setTransferFunction(QColorSpace::TransferFunction::Linear);
+ csto.setTransferFunction(QColorSpace::TransferFunction::Linear);
+
+ QImage testImage(256, 256, QImage::Format_RGB32);
+ testImage.setColorSpace(csfrom);
+ for (int y = 0; y < 256; ++y)
+ for (int x = 0; x < 256; ++x)
+ testImage.setPixel(x, y, qRgb(x, y, 0));
+
+ QImage resultImage = testImage.convertedToColorSpace(csto, QImage::Format_RGBX32FPx4);
+ resultImage.convertToColorSpace(csfrom, QImage::Format_RGB32);
+
+ for (int y = 0; y < 256; ++y) {
+ for (int x = 0; x < 256; ++x) {
+ QCOMPARE(resultImage.pixel(x, y), testImage.pixel(x, y));
+ }
+ }
+}
+
+void tst_QColorSpace::imageConversionOverNonThreeComponentMatrix_data()
+{
+ QTest::addColumn<QColorSpace>("fromColorSpace");
+ QTest::addColumn<QColorSpace>("toColorSpace");
+
+ QString prefix = QFINDTESTDATA("resources/");
+ QFile file1(prefix + "VideoHD.icc");
+ QFile file2(prefix + "sRGB_ICC_v4_Appearance.icc");
+ QVERIFY(file1.open(QFile::ReadOnly));
+ QVERIFY(file2.open(QFile::ReadOnly));
+ QByteArray iccProfile1 = file1.readAll();
+ QByteArray iccProfile2 = file2.readAll();
+ QColorSpace hdtvColorSpace = QColorSpace::fromIccProfile(iccProfile1);
+ QColorSpace srgbPcsColorSpace = QColorSpace::fromIccProfile(iccProfile2);
+
+ QTest::newRow("sRGB PCSLab -> sRGB") << srgbPcsColorSpace << QColorSpace(QColorSpace::SRgb);
+ QTest::newRow("sRGB -> sRGB PCSLab") << QColorSpace(QColorSpace::SRgb) << srgbPcsColorSpace;
+ QTest::newRow("HDTV -> sRGB") << hdtvColorSpace << QColorSpace(QColorSpace::SRgb);
+ QTest::newRow("sRGB -> HDTV") << QColorSpace(QColorSpace::SRgb) << hdtvColorSpace;
+ QTest::newRow("sRGB PCSLab -> HDTV") << srgbPcsColorSpace << hdtvColorSpace;
+ QTest::newRow("HDTV -> sRGB PCSLab") << hdtvColorSpace << srgbPcsColorSpace;
+}
+
+void tst_QColorSpace::imageConversionOverNonThreeComponentMatrix()
+{
+ QFETCH(QColorSpace, fromColorSpace);
+ QFETCH(QColorSpace, toColorSpace);
+ QVERIFY(fromColorSpace.isValid());
+ QVERIFY(toColorSpace.isValidTarget());
+
+ QVERIFY(!fromColorSpace.transformationToColorSpace(toColorSpace).isIdentity());
+
+ QImage testImage(256, 256, QImage::Format_RGBX64);
+ testImage.setColorSpace(fromColorSpace);
+ for (int y = 0; y < 256; ++y)
+ for (int x = 0; x < 256; ++x)
+ testImage.setPixel(x, y, qRgb(x, y, 0));
+
+ QImage resultImage = testImage.convertedToColorSpace(toColorSpace);
+ QCOMPARE(resultImage.size(), testImage.size());
+ for (int y = 0; y < 256; ++y) {
+ int lastRed = 0;
+ for (int x = 0; x < 256; ++x) {
+ QRgb p = resultImage.pixel(x, y);
+ QVERIFY(qRed(p) >= lastRed);
+ lastRed = qRed(p);
+ }
+ }
+ for (int x = 0; x < 256; ++x) {
+ int lastGreen = 0;
+ for (int y = 0; y < 256; ++y) {
+ QRgb p = resultImage.pixel(x, y);
+ QVERIFY(qGreen(p) >= lastGreen);
+ lastGreen = qGreen(p);
+ }
+ }
+}
+
void tst_QColorSpace::loadImage()
{
QString prefix = QFINDTESTDATA("resources/");
@@ -692,10 +898,28 @@ void tst_QColorSpace::changePrimaries()
cs.setPrimaries(QColorSpace::Primaries::DciP3D65);
QVERIFY(cs.isValid());
QCOMPARE(cs, QColorSpace(QColorSpace::DisplayP3));
+ QCOMPARE(cs.transformModel(), QColorSpace::TransformModel::ThreeComponentMatrix);
cs.setTransferFunction(QColorSpace::TransferFunction::Linear);
cs.setPrimaries(QPointF(0.3127, 0.3290), QPointF(0.640, 0.330),
QPointF(0.3000, 0.6000), QPointF(0.150, 0.060));
QCOMPARE(cs, QColorSpace(QColorSpace::SRgbLinear));
+
+
+ QFile iccFile(QFINDTESTDATA("resources/") + "VideoHD.icc");
+ QVERIFY(iccFile.open(QFile::ReadOnly));
+ QByteArray iccData = iccFile.readAll();
+ QColorSpace hdtvColorSpace = QColorSpace::fromIccProfile(iccData);
+ QVERIFY(hdtvColorSpace.isValid());
+ QCOMPARE(hdtvColorSpace.transformModel(), QColorSpace::TransformModel::ElementListProcessing);
+ QCOMPARE(hdtvColorSpace.primaries(), QColorSpace::Primaries::Custom);
+ QCOMPARE(hdtvColorSpace.transferFunction(), QColorSpace::TransferFunction::Custom);
+ // Unsets both primaries and transferfunction because they were inseparable in element list processing
+ hdtvColorSpace.setPrimaries(QColorSpace::Primaries::SRgb);
+ QVERIFY(!hdtvColorSpace.isValid());
+ hdtvColorSpace.setTransferFunction(QColorSpace::TransferFunction::SRgb);
+ QVERIFY(hdtvColorSpace.isValid());
+ QCOMPARE(hdtvColorSpace.transformModel(), QColorSpace::TransformModel::ThreeComponentMatrix);
+ QCOMPARE(hdtvColorSpace, QColorSpace(QColorSpace::SRgb));
}
void tst_QColorSpace::transferFunctionTable()
@@ -744,5 +968,101 @@ void tst_QColorSpace::description()
QCOMPARE(srgb.description(), QLatin1String("Linear sRGB")); // Set to empty returns default behavior
}
+void tst_QColorSpace::whitePoint_data()
+{
+ QTest::addColumn<QColorSpace::NamedColorSpace>("namedColorSpace");
+ QTest::addColumn<QPointF>("whitePoint");
+
+ QTest::newRow("sRGB") << QColorSpace::SRgb << QColorVector::D65Chromaticity();
+ QTest::newRow("Adobe RGB") << QColorSpace::AdobeRgb << QColorVector::D65Chromaticity();
+ QTest::newRow("Display-P3") << QColorSpace::DisplayP3 << QColorVector::D65Chromaticity();
+ QTest::newRow("ProPhoto RGB") << QColorSpace::ProPhotoRgb << QColorVector::D50Chromaticity();
+}
+
+void tst_QColorSpace::whitePoint()
+{
+ QFETCH(QColorSpace::NamedColorSpace, namedColorSpace);
+ QFETCH(QPointF, whitePoint);
+
+ QColorSpace colorSpace(namedColorSpace);
+ QPointF wpt = colorSpace.whitePoint();
+ QCOMPARE_LE(qAbs(wpt.x() - whitePoint.x()), 0.0000001);
+ QCOMPARE_LE(qAbs(wpt.y() - whitePoint.y()), 0.0000001);
+}
+
+void tst_QColorSpace::setWhitePoint()
+{
+ QColorSpace colorSpace(QColorSpace::SRgb);
+ colorSpace.setWhitePoint(QPointF(0.33, 0.33));
+ QCOMPARE_NE(colorSpace, QColorSpace(QColorSpace::SRgb));
+ colorSpace.setWhitePoint(QColorVector::D65Chromaticity());
+ // Check our matrix manipulations returned us to where we came from
+ QCOMPARE(colorSpace, QColorSpace(QColorSpace::SRgb));
+}
+
+void tst_QColorSpace::grayColorSpace()
+{
+ QColorSpace spc;
+ QCOMPARE(spc.colorModel(), QColorSpace::ColorModel::Undefined);
+ QVERIFY(!spc.isValid());
+ spc.setWhitePoint(QColorVector::D65Chromaticity());
+ spc.setTransferFunction(QColorSpace::TransferFunction::SRgb);
+ QVERIFY(spc.isValid());
+ QCOMPARE(spc.colorModel(), QColorSpace::ColorModel::Gray);
+
+ QColorSpace spc2(QColorVector::D65Chromaticity(), QColorSpace::TransferFunction::SRgb);
+ QVERIFY(spc2.isValid());
+ QCOMPARE(spc2.colorModel(), QColorSpace::ColorModel::Gray);
+ QCOMPARE(spc, spc2);
+
+ QImage rgbImage(1, 8, QImage::Format_RGB32);
+ QImage grayImage(1, 255, QImage::Format_Grayscale8);
+ // RGB images can not have gray color space
+ rgbImage.setColorSpace(spc2);
+ grayImage.setColorSpace(spc2);
+ QCOMPARE_NE(rgbImage.colorSpace(), spc2);
+ QCOMPARE(grayImage.colorSpace(), spc2);
+ // But gray images can have RGB color space
+ rgbImage.setColorSpace(QColorSpace::SRgb);
+ grayImage.setColorSpace(QColorSpace::SRgb);
+ QCOMPARE(rgbImage.colorSpace(), QColorSpace(QColorSpace::SRgb));
+ QCOMPARE(grayImage.colorSpace(), QColorSpace(QColorSpace::SRgb));
+
+ // While we can not set a grayscale color space on rgb image, we can convert to one
+ QImage grayImage2 = rgbImage.convertedToColorSpace(spc2);
+ QCOMPARE(grayImage2.colorSpace(), spc2);
+ QCOMPARE(grayImage2.format(), QImage::Format_Grayscale8);
+}
+
+void tst_QColorSpace::grayColorSpaceEffectivelySRgb()
+{
+ // Test grayscale colorspace conversion by making a gray color space that should act like sRGB on gray values.
+ QColorSpace sRgb(QColorSpace::SRgb);
+ QColorSpace sRgbGray(QColorVector::D65Chromaticity(), QColorSpace::TransferFunction::SRgb);
+
+ QImage grayImage1(256, 1, QImage::Format_Grayscale8);
+ QImage grayImage2(256, 1, QImage::Format_Grayscale8);
+ for (int i = 0; i < 256; ++i) {
+ grayImage1.bits()[i] = i;
+ grayImage2.bits()[i] = i;
+ }
+ grayImage1.setColorSpace(sRgb);
+ grayImage2.setColorSpace(sRgbGray);
+
+ QImage rgbImage1 = grayImage1.convertedTo(QImage::Format_RGB32);
+ QImage rgbImage2 = grayImage2.convertedToColorSpace(sRgb, QImage::Format_RGB32);
+
+ QCOMPARE(rgbImage1, rgbImage2);
+}
+
+void tst_QColorSpace::scaleAlphaValue()
+{
+ QImage image(1, 1, QImage::Format_ARGB32);
+ image.setPixel(0, 0, qRgba(255, 255, 255, 125));
+ image.setColorSpace(QColorSpace::SRgb);
+ image.convertToColorSpace(QColorSpace::SRgbLinear, QImage::Format_RGBA64);
+ QCOMPARE(reinterpret_cast<const QRgba64 *>(image.constBits())->alpha(), 257 * 125);
+}
+
QTEST_MAIN(tst_QColorSpace)
#include "tst_qcolorspace.moc"
diff --git a/tests/auto/gui/painting/qcolortransform/CMakeLists.txt b/tests/auto/gui/painting/qcolortransform/CMakeLists.txt
index 061902f175..4aa4a8bc4a 100644
--- a/tests/auto/gui/painting/qcolortransform/CMakeLists.txt
+++ b/tests/auto/gui/painting/qcolortransform/CMakeLists.txt
@@ -5,6 +5,12 @@
## 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
diff --git a/tests/auto/gui/painting/qcolortransform/tst_qcolortransform.cpp b/tests/auto/gui/painting/qcolortransform/tst_qcolortransform.cpp
index 6fbf7ddf27..7a976b5f5e 100644
--- a/tests/auto/gui/painting/qcolortransform/tst_qcolortransform.cpp
+++ b/tests/auto/gui/painting/qcolortransform/tst_qcolortransform.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2022 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -207,21 +182,21 @@ void tst_QColorTransform::mapRGBAFP16x4()
else
QVERIFY(result != testColor);
- testColor = QRgbaFloat16{0.0f, 0.0f, 0.0f, 1.0f};
+ testColor = QRgbaFloat16{qfloat16(0.0f), qfloat16(0.0f), qfloat16(0.0f), qfloat16(1.0f)};
result = transform.map(testColor);
QCOMPARE(result, testColor);
- testColor = QRgbaFloat16{1.0f, 1.0f, 1.0f, 1.0f};
+ testColor = QRgbaFloat16{qfloat16(1.0f), qfloat16(1.0f), qfloat16(1.0f), qfloat16(1.0f)};
result = transform.map(testColor);
QCOMPARE(result, testColor);
- testColor = QRgbaFloat16{1.0f, 1.0f, 0.0f, 1.0f};
+ 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{0.0f, 1.0f, 1.0f, 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);
diff --git a/tests/auto/gui/painting/qpagelayout/CMakeLists.txt b/tests/auto/gui/painting/qpagelayout/CMakeLists.txt
index 28eb6eb924..b19568592b 100644
--- a/tests/auto/gui/painting/qpagelayout/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpagelayout/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qpagelayout.pro.
-
#####################################################################
## 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
diff --git a/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp b/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp
index 123663a0e3..4490877e87 100644
--- a/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp
+++ b/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2014 John Layt <jlayt@kde.org>
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtGui/qpagelayout.h>
@@ -12,6 +12,9 @@ private slots:
void invalid();
void basics();
void setGetMargins();
+ void setGetClampedMargins();
+ void setUnits_data();
+ void setUnits();
};
void tst_QPageLayout::invalid()
@@ -88,12 +91,14 @@ void tst_QPageLayout::basics()
QCOMPARE(tenpoint.margins(QPageLayout::Millimeter), QMarginsF(3.53, 3.53, 3.53, 3.53));
QCOMPARE(tenpoint.marginsPoints(), QMargins(10, 10, 10, 10));
QCOMPARE(tenpoint.marginsPixels(72), QMargins(10, 10, 10, 10));
+ QCOMPARE(tenpoint.marginsPixels(600), QMargins(83, 83, 83, 83));
QCOMPARE(tenpoint.minimumMargins(), QMarginsF(0, 0, 0, 0));
QCOMPARE(tenpoint.maximumMargins(), QMarginsF(595, 842, 595, 842));
QCOMPARE(tenpoint.fullRect(), QRectF(0, 0, 595, 842));
QCOMPARE(tenpoint.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 210, 297));
QCOMPARE(tenpoint.fullRectPoints(), QRect(0, 0, 595, 842));
QCOMPARE(tenpoint.fullRectPixels(72), QRect(0, 0, 595, 842));
+ QCOMPARE(tenpoint.fullRectPixels(600), QRect(0, 0, 4958, 7016));
QCOMPARE(tenpoint.paintRect(), QRectF(10, 10, 575, 822));
QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter), QRectF(3.53, 3.53, 202.94, 289.94));
QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter).x(), 3.53);
@@ -106,6 +111,7 @@ void tst_QPageLayout::basics()
QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter).bottom(), 293.47);
QCOMPARE(tenpoint.paintRectPoints(), QRect(10, 10, 575, 822));
QCOMPARE(tenpoint.paintRectPixels(72), QRect(10, 10, 575, 822));
+ QCOMPARE(tenpoint.paintRectPixels(600), QRect(83, 83, 4792, 6850));
// Change orientation
tenpoint.setOrientation(QPageLayout::Landscape);
@@ -117,10 +123,12 @@ void tst_QPageLayout::basics()
QCOMPARE(tenpoint.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210));
QCOMPARE(tenpoint.fullRectPoints(), QRect(0, 0, 842, 595));
QCOMPARE(tenpoint.fullRectPixels(72), QRect(0, 0, 842, 595));
+ QCOMPARE(tenpoint.fullRectPixels(600), QRect(0, 0, 7016, 4958));
QCOMPARE(tenpoint.paintRect(), QRectF(10, 10, 822, 575));
QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter), QRectF(3.53, 3.53, 289.94, 202.94));
QCOMPARE(tenpoint.paintRectPoints(), QRect(10, 10, 822, 575));
QCOMPARE(tenpoint.paintRectPixels(72), QRect(10, 10, 822, 575));
+ QCOMPARE(tenpoint.paintRectPixels(600), QRect(83, 83, 6850, 4792));
// Change mode
QCOMPARE(tenpoint.mode(), QPageLayout::StandardMode);
@@ -134,15 +142,82 @@ void tst_QPageLayout::basics()
QCOMPARE(tenpoint.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210));
QCOMPARE(tenpoint.fullRectPoints(), QRect(0, 0, 842, 595));
QCOMPARE(tenpoint.fullRectPixels(72), QRect(0, 0, 842, 595));
+ QCOMPARE(tenpoint.fullRectPixels(600), QRect(0, 0, 7016, 4958));
QCOMPARE(tenpoint.paintRect(), QRectF(0, 0, 842, 595));
QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210));
QCOMPARE(tenpoint.paintRectPoints(), QRect(0, 0, 842, 595));
QCOMPARE(tenpoint.paintRectPixels(72), QRect(0, 0, 842, 595));
+ QCOMPARE(tenpoint.paintRectPixels(600), QRect(0, 0, 7016, 4958));
+
+ // A4, 8.4pt margins
+ QPageLayout fraction = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(8.4, 8.4, 8.4, 8.4));
+ QCOMPARE(fraction.isValid(), true);
+ QCOMPARE(fraction.margins(), QMarginsF(8.4, 8.4, 8.4, 8.4));
+ QCOMPARE(fraction.margins(QPageLayout::Millimeter), QMarginsF(2.96, 2.96, 2.96, 2.96));
+ QCOMPARE(fraction.marginsPoints(), QMarginsF(8, 8, 8, 8));
+ QCOMPARE(fraction.marginsPixels(72), QMargins(8, 8, 8, 8));
+ QCOMPARE(fraction.marginsPixels(600), QMargins(70, 70, 70, 70));
+ QCOMPARE(fraction.minimumMargins(), QMarginsF(0, 0, 0, 0));
+ QCOMPARE(fraction.maximumMargins(), QMarginsF(595, 842, 595, 842));
+ QCOMPARE(fraction.fullRect(), QRectF(0, 0, 595, 842));
+ QCOMPARE(fraction.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 210, 297));
+ QCOMPARE(fraction.fullRectPoints(), QRect(0, 0, 595, 842));
+ QCOMPARE(fraction.fullRectPixels(72), QRect(0, 0, 595, 842));
+ QCOMPARE(fraction.fullRectPixels(600), QRect(0, 0, 4958, 7016));
+ QCOMPARE(fraction.paintRect(), QRectF(8.4, 8.4, 578.2, 825.2));
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter), QRectF(2.96, 2.96, 204.08, 291.08));
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).x(), 2.96);
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).y(), 2.96);
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).width(), 204.08);
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).height(), 291.08);
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).left(), 2.96);
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).right(), 207.04);
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).top(), 2.96);
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).bottom(), 294.04);
+ QCOMPARE(fraction.paintRectPoints(), QRect(8, 8, 579, 826));
+ QCOMPARE(fraction.paintRectPixels(72), QRect(8, 8, 579, 826));
+ QCOMPARE(fraction.paintRectPixels(600), QRect(70, 70, 4818, 6876));
+
+ // Change orientation
+ fraction.setOrientation(QPageLayout::Landscape);
+ QCOMPARE(fraction.orientation(), QPageLayout::Landscape);
+ QCOMPARE(fraction.margins(), QMarginsF(8.4, 8.4, 8.4, 8.4));
+ QCOMPARE(fraction.minimumMargins(), QMarginsF(0, 0, 0, 0));
+ QCOMPARE(fraction.maximumMargins(), QMarginsF(842, 595, 842, 595));
+ QCOMPARE(fraction.fullRect(), QRectF(0, 0, 842, 595));
+ QCOMPARE(fraction.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210));
+ QCOMPARE(fraction.fullRectPoints(), QRect(0, 0, 842, 595));
+ QCOMPARE(fraction.fullRectPixels(72), QRect(0, 0, 842, 595));
+ QCOMPARE(fraction.fullRectPixels(600), QRect(0, 0, 7016, 4958));
+ QCOMPARE(fraction.paintRect(), QRectF(8.4, 8.4, 825.2, 578.2));
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter), QRectF(2.96, 2.96, 291.08, 204.08));
+ QCOMPARE(fraction.paintRectPoints(), QRect(8, 8, 826, 579));
+ QCOMPARE(fraction.paintRectPixels(72), QRect(8, 8, 826, 579));
+ QCOMPARE(fraction.paintRectPixels(600), QRect(70, 70, 6876, 4818));
+
+ // Change mode
+ QCOMPARE(fraction.mode(), QPageLayout::StandardMode);
+ fraction.setMode(QPageLayout::FullPageMode);
+ QCOMPARE(fraction.mode(), QPageLayout::FullPageMode);
+ QCOMPARE(fraction.orientation(), QPageLayout::Landscape);
+ QCOMPARE(fraction.margins(), QMarginsF(8.4, 8.4, 8.4, 8.4));
+ QCOMPARE(fraction.minimumMargins(), QMarginsF(0, 0, 0, 0));
+ QCOMPARE(fraction.maximumMargins(), QMarginsF(842, 595, 842, 595));
+ QCOMPARE(fraction.fullRect(), QRectF(0, 0, 842, 595));
+ QCOMPARE(fraction.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210));
+ QCOMPARE(fraction.fullRectPoints(), QRect(0, 0, 842, 595));
+ QCOMPARE(fraction.fullRectPixels(72), QRect(0, 0, 842, 595));
+ QCOMPARE(fraction.fullRectPixels(600), QRect(0, 0, 7016, 4958));
+ QCOMPARE(fraction.paintRect(), QRectF(0, 0, 842, 595));
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210));
+ QCOMPARE(fraction.paintRectPoints(), QRect(0, 0, 842, 595));
+ QCOMPARE(fraction.paintRectPixels(72), QRect(0, 0, 842, 595));
+ QCOMPARE(fraction.paintRectPixels(600), QRect(0, 0, 7016, 4958));
}
void tst_QPageLayout::setGetMargins()
{
- // A4, 20pt margins
+ // A4, 10pt margins
QMarginsF margins = QMarginsF(10, 10, 10, 10);
QMarginsF min = QMarginsF(10, 10, 10, 10);
QMarginsF max = QMarginsF(585, 832, 585, 832);
@@ -155,7 +230,7 @@ void tst_QPageLayout::setGetMargins()
QCOMPARE(change.minimumMargins(), min);
QCOMPARE(change.maximumMargins(), max);
- // Set magins within min/max ok
+ // Set margins within min/max ok
margins = QMarginsF(20, 20, 20, 20);
change.setMargins(margins);
QCOMPARE(change.margins(QPageLayout::Millimeter), QMarginsF(7.06, 7.06, 7.06, 7.06));
@@ -215,7 +290,7 @@ void tst_QPageLayout::setGetMargins()
fullPage.setMargins(margins);
QCOMPARE(fullPage.margins(), margins);
- // Set margins all above max is rejected
+ // Set margins all above max is accepted
margins = QMarginsF(1000, 1000, 1000, 1000);
fullPage.setMargins(margins);
QCOMPARE(fullPage.margins(), margins);
@@ -238,6 +313,174 @@ void tst_QPageLayout::setGetMargins()
QCOMPARE(fullPage.maximumMargins(), max);
}
+void tst_QPageLayout::setGetClampedMargins()
+{
+ // A4, 10pt margins
+ QMarginsF margins = QMarginsF(10, 10, 10, 10);
+ QMarginsF min = QMarginsF(10, 10, 10, 10);
+ QMarginsF max = QMarginsF(585, 832, 585, 832);
+ QPageLayout change = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, margins, QPageLayout::Point, min);
+ QCOMPARE(change.isValid(), true);
+
+ // Clamp margins within min/max ok
+ margins = QMarginsF(20, 20, 20, 20);
+ change.setMargins(margins, QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins(QPageLayout::Millimeter), QMarginsF(7.06, 7.06, 7.06, 7.06));
+ QCOMPARE(change.marginsPoints(), QMargins(20, 20, 20, 20));
+ QCOMPARE(change.marginsPixels(72), QMargins(20, 20, 20, 20));
+ QCOMPARE(change.margins(), margins);
+
+ // Clamp margins all below min
+ change.setMargins(QMarginsF(0, 0, 0, 0), QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins(), change.minimumMargins());
+
+ // Clamp margins all above max
+ change.setMargins(QMarginsF(1000, 1000, 1000, 1000), QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins(), change.maximumMargins());
+
+ // Only 1 wrong, clamp still works
+ change.setMargins(QMarginsF(50, 50, 50, 0), QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins(), QMarginsF(50, 50, 50, change.minimumMargins().bottom()));
+
+ // A4, 20pt margins
+ margins = QMarginsF(20, 20, 20, 20);
+ min = QMarginsF(10, 10, 10, 10);
+ max = QMarginsF(585, 832, 585, 832);
+ QPageLayout fullPage = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, margins, QPageLayout::Point, min);
+ fullPage.setMode(QPageLayout::FullPageMode);
+ QCOMPARE(fullPage.isValid(), true);
+ QCOMPARE(fullPage.margins(), margins);
+ QCOMPARE(fullPage.minimumMargins(), min);
+ QCOMPARE(fullPage.maximumMargins(), max);
+
+ // Clamp margins within min/max ok
+ margins = QMarginsF(50, 50, 50, 50);
+ fullPage.setMargins(margins, QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(fullPage.margins(), margins);
+
+ // Clamp margins all below min, no clamping
+ margins = QMarginsF(0, 0, 0, 0);
+ fullPage.setMargins(margins, QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(fullPage.margins(), margins);
+
+ // Clamp margins all above max, no clamping
+ margins = QMarginsF(1000, 1000, 1000, 1000);
+ fullPage.setMargins(margins, QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(fullPage.margins(), margins);
+
+ // Only 1 wrong, no clamping
+ margins = QMarginsF(50, 50, 50, 0);
+ fullPage.setMargins(margins, QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(fullPage.margins(), margins);
+
+ // Set page size, sets min/max, clamps existing margins
+ margins = QMarginsF(20, 500, 20, 500);
+ fullPage.setMargins(margins, QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(fullPage.margins(), margins);
+ min = QMarginsF(30, 30, 30, 30);
+ max = QMarginsF(267, 390, 267, 390);
+ fullPage.setPageSize(QPageSize(QPageSize::A6));
+ fullPage.setMinimumMargins(min);
+ QCOMPARE(fullPage.margins(), margins);
+ QCOMPARE(fullPage.minimumMargins(), min);
+ QCOMPARE(fullPage.maximumMargins(), max);
+
+ // Test set* API calls
+ min = QMarginsF(1, 2, 3, 4);
+ max = QMarginsF(595 - min.right(), 842 - min.bottom(), 595 - min.left(), 842 - min.top());
+ change = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, margins, QPageLayout::Point, min);
+ QCOMPARE(change.minimumMargins(), min);
+ QCOMPARE(change.maximumMargins(), max);
+
+ // Test setLeftMargin
+ change.setLeftMargin(0, QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins().left(), min.left());
+ change.setLeftMargin(change.fullRectPoints().width(), QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins().left(), max.left());
+ change.setLeftMargin(min.left(), QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins().left(), min.left());
+ change.setLeftMargin(max.left(), QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins().left(), max.left());
+
+ // Test setTopMargin
+ change.setTopMargin(0, QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins().top(), min.top());
+ change.setTopMargin(change.fullRectPoints().height(), QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins().top(), max.top());
+ change.setTopMargin(min.top(), QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins().top(), min.top());
+ change.setTopMargin(max.top(), QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins().top(), max.top());
+
+ // Test setRightMargin
+ change.setRightMargin(0, QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins().right(), min.right());
+ change.setRightMargin(change.fullRectPoints().width(), QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins().right(), max.right());
+ change.setRightMargin(min.right(), QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins().right(), min.right());
+ change.setRightMargin(max.right(), QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins().right(), max.right());
+
+ // Test setBottomMargin
+ change.setBottomMargin(0, QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins().bottom(), min.bottom());
+ change.setBottomMargin(change.fullRectPoints().height(), QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins().bottom(), max.bottom());
+ change.setBottomMargin(min.bottom(), QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins().bottom(), min.bottom());
+ change.setBottomMargin(max.bottom(), QPageLayout::OutOfBoundsPolicy::Clamp);
+ QCOMPARE(change.margins().bottom(), max.bottom());
+}
+
+void tst_QPageLayout::setUnits_data()
+{
+ QTest::addColumn<QPageLayout::Unit>("units");
+ QTest::newRow("Millimeter") << QPageLayout::Millimeter;
+ QTest::newRow("Point") << QPageLayout::Point;
+ QTest::newRow("Inch") << QPageLayout::Inch;
+ QTest::newRow("Pica") << QPageLayout::Pica;
+ QTest::newRow("Didot") << QPageLayout::Didot;
+ QTest::newRow("Cicero") << QPageLayout::Cicero;
+}
+
+void tst_QPageLayout::setUnits()
+{
+ QFETCH(QPageLayout::Unit, units);
+ QPageLayout pageLayout = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(), units);
+ int maxLeftX100 = qFloor(pageLayout.maximumMargins().left() * 100);
+ QVERIFY(maxLeftX100 > 0);
+ for (int i = 1; i <= maxLeftX100; ++i) {
+ const qreal margin = i / 100.;
+ const QMarginsF unitsMargins = QMarginsF(margin, margin, margin, margin);
+ pageLayout.setMargins(unitsMargins);
+ pageLayout.setUnits(QPageLayout::Point);
+ const QMarginsF pointsMargins = pageLayout.margins();
+ if (units == QPageLayout::Point) {
+ QCOMPARE(pointsMargins, unitsMargins);
+ } else {
+ QCOMPARE_GT(pointsMargins.left(), unitsMargins.left());
+ QCOMPARE_GT(pointsMargins.top(), unitsMargins.top());
+ QCOMPARE_GT(pointsMargins.right(), unitsMargins.right());
+ QCOMPARE_GT(pointsMargins.bottom(), unitsMargins.bottom());
+ }
+ pageLayout.setUnits(units);
+ const QMarginsF convertedUnitsMargins = pageLayout.margins();
+ if (units == QPageLayout::Didot) {
+ // When using Didot units, the small multiplier and ceiling function in conversion
+ // may cause the converted units to not match the original exactly. However, we
+ // can verify that the converted margins are always greater than or equal to the
+ // original.
+ QCOMPARE_GE(convertedUnitsMargins.left(), unitsMargins.left());
+ QCOMPARE_GE(convertedUnitsMargins.top(), unitsMargins.top());
+ QCOMPARE_GE(convertedUnitsMargins.right(), unitsMargins.right());
+ QCOMPARE_GE(convertedUnitsMargins.bottom(), unitsMargins.bottom());
+ } else {
+ QCOMPARE(convertedUnitsMargins, unitsMargins);
+ }
+ }
+}
+
QTEST_APPLESS_MAIN(tst_QPageLayout)
#include "tst_qpagelayout.moc"
diff --git a/tests/auto/gui/painting/qpageranges/CMakeLists.txt b/tests/auto/gui/painting/qpageranges/CMakeLists.txt
index ff89c69acf..99ab477eae 100644
--- a/tests/auto/gui/painting/qpageranges/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpageranges/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qpageranges.pro.
-
#####################################################################
## 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
diff --git a/tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp b/tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp
index 00975906ed..d2dbf990e3 100644
--- a/tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp
+++ b/tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2019 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <qpageranges.h>
@@ -70,7 +70,7 @@ void tst_QPageRanges::addPage()
QFETCH(PageRangeList, expected);
QPageRanges result;
- for (int pageNumber : qAsConst(pageNumbers)) {
+ for (int pageNumber : std::as_const(pageNumbers)) {
if (QByteArrayView(QTest::currentDataTag()) == "invalid")
QTest::ignoreMessage(QtWarningMsg, "QPageRanges::addPage: 'pageNumber' must be greater than 0");
result.addPage(pageNumber);
@@ -112,7 +112,7 @@ void tst_QPageRanges::addRange()
QFETCH(PageRangeList, expected);
QPageRanges result;
- for (const auto &range : qAsConst(ranges)) {
+ for (const auto &range : std::as_const(ranges)) {
const QByteArrayView testdata(QTest::currentDataTag());
if (testdata.startsWith("invalid"))
QTest::ignoreMessage(QtWarningMsg, "QPageRanges::addRange: 'from' and 'to' must be greater than 0");
diff --git a/tests/auto/gui/painting/qpagesize/CMakeLists.txt b/tests/auto/gui/painting/qpagesize/CMakeLists.txt
index c0a236107e..b16cd2714a 100644
--- a/tests/auto/gui/painting/qpagesize/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpagesize/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qpagesize.pro.
-
#####################################################################
## 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
diff --git a/tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp b/tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp
index bac7e9cdf8..de9b799902 100644
--- a/tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp
+++ b/tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtGlobal>
@@ -49,11 +49,13 @@ void tst_QPageSize::basics()
QCOMPARE(a4.size(QPageSize::Pica), QSizeF(49.58, 70.17));
QCOMPARE(a4.sizePoints(), QSize(595, 842));
QCOMPARE(a4.sizePixels(72), QSize(595, 842));
+ QCOMPARE(a4.sizePixels(600), QSize(4958, 7016)); // Rounded down
QCOMPARE(a4.rect(QPageSize::Millimeter), QRectF(0, 0, 210, 297));
QCOMPARE(a4.rect(QPageSize::Inch), QRectF(0, 0, 8.27, 11.69));
QCOMPARE(a4.rect(QPageSize::Pica), QRectF(0, 0, 49.58, 70.17));
QCOMPARE(a4.rectPoints(), QRect(0, 0, 595, 842));
QCOMPARE(a4.rectPixels(72), QRect(0, 0, 595, 842));
+ QCOMPARE(a4.rectPixels(600), QRect(0, 0, 4958, 7016)); // Rounded down
// Simple QPageSize::PaperSizeId later in list
QPageSize folio = QPageSize(QPageSize::Folio);
diff --git a/tests/auto/gui/painting/qpaintengine/CMakeLists.txt b/tests/auto/gui/painting/qpaintengine/CMakeLists.txt
index 15987b7420..4cd0151a01 100644
--- a/tests/auto/gui/painting/qpaintengine/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpaintengine/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qpaintengine.pro.
-
#####################################################################
## 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
diff --git a/tests/auto/gui/painting/qpaintengine/tst_qpaintengine.cpp b/tests/auto/gui/painting/qpaintengine/tst_qpaintengine.cpp
index 24e13c2821..02441de54c 100644
--- a/tests/auto/gui/painting/qpaintengine/tst_qpaintengine.cpp
+++ b/tests/auto/gui/painting/qpaintengine/tst_qpaintengine.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/painting/qpainter/CMakeLists.txt b/tests/auto/gui/painting/qpainter/CMakeLists.txt
index 39c601459a..261e1eb2cf 100644
--- a/tests/auto/gui/painting/qpainter/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpainter/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qpainter.pro.
-
#####################################################################
## 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}
diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
index 1a677ad445..92b28f65bd 100644
--- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
+++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
@@ -1,6 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <qpainter.h>
@@ -62,6 +61,7 @@ private slots:
#endif
void drawPixmapFragments();
void drawPixmapNegativeScale();
+ void drawPixmapRounding();
void drawLine_data();
void drawLine();
@@ -170,6 +170,7 @@ private slots:
void radialGradientRgb30();
#endif
+ void radialGradient_QTBUG120332_ubsan();
void fpe_pixmapTransform();
void fpe_zeroLengthLines();
void fpe_divByZero();
@@ -747,6 +748,16 @@ void tst_QPainter::drawPixmapNegativeScale()
QVERIFY(resultImage.pixel(12, 8) == qRgba(0, 0, 0, 255)); // and right strip is now black
}
+void tst_QPainter::drawPixmapRounding()
+{
+ // Just test that we don't assert
+ QBitmap bm(8, 8);
+ QImage out(64, 64, QImage::Format_RGB32);
+ QPainter p(&out);
+ qreal y = 26.499999999999996;
+ p.drawPixmap(QPointF(0, y), bm);
+}
+
void tst_QPainter::drawLine_data()
{
QTest::addColumn<QLine>("line");
@@ -2082,21 +2093,22 @@ void tst_QPainter::clippedLines_data()
QPen pen2(QColor(223, 223, 0, 223));
pen2.setWidth(2);
- QList<QLineF> lines;
- lines << QLineF(15, 15, 65, 65)
- << QLineF(14, 14, 66, 66)
- << QLineF(16, 16, 64, 64)
- << QLineF(65, 65, 15, 15)
- << QLineF(66, 66, 14, 14)
- << QLineF(64, 64, 14, 14)
- << QLineF(15, 50, 15, 64)
- << QLineF(15, 50, 15, 65)
- << QLineF(15, 50, 15, 66)
- << QLineF(15, 50, 64, 50)
- << QLineF(15, 50, 65, 50)
- << QLineF(15, 50, 66, 50);
-
- foreach (QLineF line, lines) {
+ const auto lines = {
+ QLineF(15, 15, 65, 65),
+ QLineF(14, 14, 66, 66),
+ QLineF(16, 16, 64, 64),
+ QLineF(65, 65, 15, 15),
+ QLineF(66, 66, 14, 14),
+ QLineF(64, 64, 14, 14),
+ QLineF(15, 50, 15, 64),
+ QLineF(15, 50, 15, 65),
+ QLineF(15, 50, 15, 66),
+ QLineF(15, 50, 64, 50),
+ QLineF(15, 50, 65, 50),
+ QLineF(15, 50, 66, 50),
+ };
+
+ for (QLineF line : lines) {
const QByteArray desc = "line (" + QByteArray::number(line.x1())
+ ", " + QByteArray::number(line.y1()) + ", "
+ QByteArray::number(line.x2()) + ", " + QByteArray::number(line.y2())
@@ -2497,6 +2509,12 @@ void tst_QPainter::drawhelper_blend_untransformed_data()
setOpacity_data();
}
+static const auto &defaultOpacities()
+{
+ static const std::array opacities = {qreal(0.0), 0.1 , 0.01, 0.4, 0.5, 0.6, 0.9, 1.0};
+ return opacities;
+}
+
void tst_QPainter::drawhelper_blend_untransformed()
{
QFETCH(QImage::Format, destFormat);
@@ -2517,9 +2535,7 @@ void tst_QPainter::drawhelper_blend_untransformed()
p.fillRect(paintRect, srcColor);
p.end();
- QList<qreal> opacities = (QList<qreal>() << 0.0 << 0.1 << 0.01 << 0.4
- << 0.5 << 0.6 << 0.9 << 1.0);
- foreach (qreal opacity, opacities) {
+ for (qreal opacity : defaultOpacities()) {
p.begin(&dest);
p.fillRect(paintRect, destColor);
@@ -2574,9 +2590,7 @@ void tst_QPainter::drawhelper_blend_tiled_untransformed()
const QBrush brush(src);
- QList<qreal> opacities = (QList<qreal>() << 0.0 << 0.1 << 0.01 << 0.4
- << 0.5 << 0.6 << 0.9 << 1.0);
- foreach (qreal opacity, opacities) {
+ for (qreal opacity : defaultOpacities()) {
p.begin(&dest);
p.fillRect(paintRect, destColor);
@@ -2770,7 +2784,7 @@ void tst_QPainter::monoImages()
for (int i = 1; i < QImage::NImageFormats; ++i) {
for (int j = 0; j < numColorPairs; ++j) {
const QImage::Format format = QImage::Format(i);
- if (format == QImage::Format_Indexed8)
+ if (format == QImage::Format_Indexed8 || format == QImage::Format_CMYK8888)
continue;
QImage img(2, 2, format);
@@ -3540,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",
@@ -3785,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);
@@ -3894,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);
@@ -4897,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));
@@ -5011,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;
@@ -5181,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 {
diff --git a/tests/auto/gui/painting/qpainter/utils/createImages/main.cpp b/tests/auto/gui/painting/qpainter/utils/createImages/main.cpp
index 092986045a..7cb9e74216 100644
--- a/tests/auto/gui/painting/qpainter/utils/createImages/main.cpp
+++ b/tests/auto/gui/painting/qpainter/utils/createImages/main.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qapplication.h>
diff --git a/tests/auto/gui/painting/qpainterpath/CMakeLists.txt b/tests/auto/gui/painting/qpainterpath/CMakeLists.txt
index 22e2448bba..1da6e25511 100644
--- a/tests/auto/gui/painting/qpainterpath/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpainterpath/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qpainterpath.pro.
-
#####################################################################
## 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
diff --git a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp
index 693c726792..c00dc3a78a 100644
--- a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp
+++ b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -81,6 +81,8 @@ private slots:
void intersectionEquality();
void intersectionPointOnEdge();
+
+ void boundsAtStartPoint();
};
void tst_QPainterPath::cleanupTestCase()
@@ -385,11 +387,11 @@ void tst_QPainterPath::contains_QRectF_data()
QTest::newRow("inside 2 rects (winding)") << path << QRectF(51, 51, 48, 48) << true;
path.addEllipse(0, 0, 150, 150);
- QTest::newRow("topRight 2 rects") << path << QRectF(100, 25, 24, 24) << true;
- QTest::newRow("bottomLeft 2 rects") << path << QRectF(25, 100, 24, 24) << true;
+ QTest::newRow("topRight rects+circle") << path << QRectF(100, 25, 24, 24) << true;
+ QTest::newRow("bottomLeft rects+circle") << path << QRectF(25, 100, 24, 24) << true;
path.setFillRule(Qt::OddEvenFill);
- QTest::newRow("inside 2 rects") << path << QRectF(50, 50, 49, 49) << false;
+ QTest::newRow("inside rects+circle") << path << QRectF(50, 50, 49, 49) << false;
}
void tst_QPainterPath::contains_QRectF()
@@ -763,6 +765,21 @@ void tst_QPainterPath::testOperatorDatastream()
}
QCOMPARE(other, path);
+
+ // Check reset & detach
+ QPainterPath p3;
+ p3.lineTo(1, 1);
+ QCOMPARE(p3.elementCount(), 2);
+ QPainterPath p4 = p3;
+ QCOMPARE(p4.elementCount(), 2);
+ {
+ QFile data(tempDir.path() + "/data");
+ QVERIFY(data.open(QFile::ReadOnly));
+ QDataStream stream(&data);
+ stream >> p3;
+ }
+ QCOMPARE(p3.elementCount(), path.elementCount());
+ QCOMPARE(p4.elementCount(), 2);
}
void tst_QPainterPath::closing()
@@ -893,17 +910,17 @@ void tst_QPainterPath::testArcMoveTo_data()
QRectF(100, 100, 100, -100),
QRectF(100, 100, -100, -100),
};
+ constexpr qreal tinyAngle = 1e-10;
- for (uint domain = 0; domain < sizeof rects / sizeof *rects; ++domain) {
- const QByteArray dB = QByteArray::number(domain);
- for (int i=-360; i<=360; ++i) {
- QTest::newRow(("test " + dB + ' ' + QByteArray::number(i)).constData())
- << rects[domain] << (qreal) i;
- }
+ int index = 0;
+ for (const auto &rect : rects) {
+ for (int i = -360; i <= 360; ++i)
+ QTest::addRow("test %d %d", index, i) << rect << qreal(i);
// test low angles
- QTest::newRow("low angles 1") << rects[domain] << (qreal) 1e-10;
- QTest::newRow("low angles 2") << rects[domain] << (qreal)-1e-10;
+ QTest::addRow("low +angle %d", index) << rect << tinyAngle;
+ QTest::addRow("low -angle %d", index) << rect << -tinyAngle;
+ ++index;
}
}
@@ -1220,38 +1237,65 @@ void tst_QPainterPath::testNaNandInfinites()
QPointF p3 = QPointF(qQNaN(), 1);
QPointF pInf = QPointF(qInf(), 1);
- // all these operations with NaN/Inf should be ignored
- // can't test operator>> reliably, as we can't create a path with NaN to << later
+ // All these operations with NaN/Inf should be ignored.
+ // Can't test operator>> reliably, as we can't create a path with NaN to << later.
+#ifdef QT_NO_DEBUG
+# define WARNS(name)
+#else
+# define WARNS(name) \
+ QTest::ignoreMessage(QtWarningMsg, "QPainterPath::" #name ": " \
+ "Adding point with invalid coordinates, ignoring call")
+#endif
+ WARNS(moveTo);
path1.moveTo(p1);
+ WARNS(moveTo);
path1.moveTo(qSNaN(), qQNaN());
+ WARNS(moveTo);
path1.moveTo(pInf);
+ WARNS(lineTo);
path1.lineTo(p1);
+ WARNS(lineTo);
path1.lineTo(qSNaN(), qQNaN());
+ WARNS(lineTo);
path1.lineTo(pInf);
+ WARNS(cubicTo);
path1.cubicTo(p1, p2, p3);
+ WARNS(cubicTo);
path1.cubicTo(p1, QPointF(1, 1), QPointF(2, 2));
+ WARNS(cubicTo);
path1.cubicTo(pInf, QPointF(10, 10), QPointF(5, 1));
+ WARNS(quadTo);
path1.quadTo(p1, p2);
+ WARNS(quadTo);
path1.quadTo(QPointF(1, 1), p3);
+ WARNS(quadTo);
path1.quadTo(QPointF(1, 1), pInf);
+ WARNS(arcTo);
path1.arcTo(QRectF(p1, p2), 5, 5);
+ WARNS(arcTo);
path1.arcTo(QRectF(pInf, QPointF(1, 1)), 5, 5);
+ WARNS(addRect);
path1.addRect(QRectF(p1, p2));
+ WARNS(addRect);
path1.addRect(QRectF(pInf, QPointF(1, 1)));
+ WARNS(addEllipse);
path1.addEllipse(QRectF(p1, p2));
+ WARNS(addEllipse);
path1.addEllipse(QRectF(pInf, QPointF(1, 1)));
+#undef WARNS
+
QCOMPARE(path1, path2);
path1.lineTo(QPointF(1, 1));
- QVERIFY(path1 != path2);
+ QCOMPARE_NE(path1, path2);
}
#endif // signaling_nan
@@ -1415,6 +1459,32 @@ void tst_QPainterPath::intersectionPointOnEdge()
QVERIFY(p.intersects(r));
}
+void tst_QPainterPath::boundsAtStartPoint()
+{
+ const QPointF startPoint(10, 10);
+ const QPainterPath constructedPath(startPoint);
+ {
+ const auto boundingRect = constructedPath.boundingRect();
+ const auto topLeft = boundingRect.topLeft();
+ QCOMPARE(topLeft, startPoint);
+ QCOMPARE(topLeft, constructedPath.elementAt(0));
+ QCOMPARE(boundingRect, constructedPath.controlPointRect());
+ }
+
+ QPainterPath defaultPath;
+ defaultPath.moveTo(startPoint);
+ {
+ const auto boundingRect = defaultPath.boundingRect();
+ const auto topLeft = boundingRect.topLeft();
+ QCOMPARE(topLeft, startPoint);
+ QCOMPARE(topLeft, defaultPath.elementAt(0));
+ QCOMPARE(boundingRect, defaultPath.controlPointRect());
+ }
+
+ QCOMPARE(constructedPath.boundingRect(), defaultPath.boundingRect());
+ QCOMPARE(constructedPath.controlPointRect(), defaultPath.controlPointRect());
+}
+
QTEST_APPLESS_MAIN(tst_QPainterPath)
#include "tst_qpainterpath.moc"
diff --git a/tests/auto/gui/painting/qpainterpathstroker/CMakeLists.txt b/tests/auto/gui/painting/qpainterpathstroker/CMakeLists.txt
index 170b824ab2..d30778de3f 100644
--- a/tests/auto/gui/painting/qpainterpathstroker/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpainterpathstroker/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qpainterpathstroker.pro.
-
#####################################################################
## 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
diff --git a/tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp b/tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp
index 3a3f8ff89f..ce80019273 100644
--- a/tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp
+++ b/tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/painting/qpathclipper/CMakeLists.txt b/tests/auto/gui/painting/qpathclipper/CMakeLists.txt
index d3c9fa822f..2cf25cfdf2 100644
--- a/tests/auto/gui/painting/qpathclipper/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpathclipper/CMakeLists.txt
@@ -1,7 +1,11 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qpathclipper.pro.
+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()
@@ -22,9 +26,6 @@ qt_internal_add_test(tst_qpathclipper
Qt::GuiPrivate
)
-#### Keys ignored in scope 1:.:.:qpathclipper.pro:<TRUE>:
-# _REQUIREMENTS = "qtConfig(private_tests)"
-
## Scopes:
#####################################################################
diff --git a/tests/auto/gui/painting/qpathclipper/pathcompare.h b/tests/auto/gui/painting/qpathclipper/pathcompare.h
index d1207cfdc0..593176686e 100644
--- a/tests/auto/gui/painting/qpathclipper/pathcompare.h
+++ b/tests/auto/gui/painting/qpathclipper/pathcompare.h
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef PATHCOMPARE_H
#define PATHCOMPARE_H
diff --git a/tests/auto/gui/painting/qpathclipper/paths.cpp b/tests/auto/gui/painting/qpathclipper/paths.cpp
index e6be402df7..7b1486152b 100644
--- a/tests/auto/gui/painting/qpathclipper/paths.cpp
+++ b/tests/auto/gui/painting/qpathclipper/paths.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "paths.h"
QPainterPath Paths::rect()
diff --git a/tests/auto/gui/painting/qpathclipper/paths.h b/tests/auto/gui/painting/qpathclipper/paths.h
index 8c421dec2e..73b41d324a 100644
--- a/tests/auto/gui/painting/qpathclipper/paths.h
+++ b/tests/auto/gui/painting/qpathclipper/paths.h
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef PATHS_H
#define PATHS_H
diff --git a/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp b/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp
index e93d0f4ba1..c5ef8373fd 100644
--- a/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp
+++ b/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "private/qpathclipper_p.h"
#include "paths.h"
#include "pathcompare.h"
@@ -470,15 +470,19 @@ void tst_QPathClipper::clipTest(int subjectIndex, int clipIndex, QPathClipper::O
break;
}
- if (expected != inResult) {
- char str[256];
- const char *opStr =
- op == QPathClipper::BoolAnd ? "and" :
- op == QPathClipper::BoolOr ? "or" : "sub";
- sprintf(str, "Expected: %d, actual: %d, subject: %d, clip: %d, op: %s\n",
- int(expected), int(inResult), subjectIndex, clipIndex, opStr);
- QFAIL(str);
- }
+ auto failLogger = qScopeGuard([&]{
+ qCritical().noquote().nospace()
+ << "\n\tExpected: " << expected
+ << "\n\tActual: " << inResult
+ << "\n\tSubject: " << subjectIndex
+ << "\n\tClip: " << clipIndex
+ << "\n\tOp: " << (op == QPathClipper::BoolAnd
+ ? "and"
+ : op == QPathClipper::BoolOr
+ ? "or" : "sub");
+ });
+ QCOMPARE(inResult, expected);
+ failLogger.dismiss();
}
}
@@ -772,7 +776,7 @@ void tst_QPathClipper::testIntersections7()
void tst_QPathClipper::testIntersections8()
{
QPainterPath path1 = Paths::node() * QTransform().translate(100, 50);
- QPainterPath path2 = Paths::node() * QTransform().translate(150, 50);;
+ QPainterPath path2 = Paths::node() * QTransform().translate(150, 50);
QVERIFY(path1.intersects(path2));
QVERIFY(path2.intersects(path1));
@@ -820,7 +824,7 @@ void tst_QPathClipper::testIntersections9()
QVERIFY(path1.intersects(path2));
QVERIFY(path2.intersects(path1));
- path1 = QPainterPath();;
+ path1 = QPainterPath();
path2 = QPainterPath();
path1.addRect(QRectF(-1,191, 136, 106));
@@ -828,7 +832,7 @@ void tst_QPathClipper::testIntersections9()
QVERIFY(path1.intersects(path2));
QVERIFY(path2.intersects(path1));
- path1 = QPainterPath();;
+ path1 = QPainterPath();
path2 = QPainterPath();
path1.moveTo(-1 , 143);
diff --git a/tests/auto/gui/painting/qpdfwriter/CMakeLists.txt b/tests/auto/gui/painting/qpdfwriter/CMakeLists.txt
index fcb8b74cbd..3a42d81600 100644
--- a/tests/auto/gui/painting/qpdfwriter/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpdfwriter/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qpdfwriter.pro.
-
#####################################################################
## 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
diff --git a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp
index aaa0877625..4d6b1f01b9 100644
--- a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp
+++ b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtGlobal>
diff --git a/tests/auto/gui/painting/qpen/CMakeLists.txt b/tests/auto/gui/painting/qpen/CMakeLists.txt
index f4075bf396..05fbbfb552 100644
--- a/tests/auto/gui/painting/qpen/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpen/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qpen.pro.
-
#####################################################################
## 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
diff --git a/tests/auto/gui/painting/qpen/tst_qpen.cpp b/tests/auto/gui/painting/qpen/tst_qpen.cpp
index e13a8e3270..b3ff1c76f9 100644
--- a/tests/auto/gui/painting/qpen/tst_qpen.cpp
+++ b/tests/auto/gui/painting/qpen/tst_qpen.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/painting/qpolygon/CMakeLists.txt b/tests/auto/gui/painting/qpolygon/CMakeLists.txt
index 58ea73881e..42b108efcd 100644
--- a/tests/auto/gui/painting/qpolygon/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpolygon/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qpolygon.pro.
-
#####################################################################
## 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
diff --git a/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp b/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp
index 87dda161d2..cd24135ac6 100644
--- a/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp
+++ b/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -168,8 +168,8 @@ void tst_QPolygon::swap()
QPolygon p2(QList<QPoint>() << QPoint(0, 0) << QPoint(0, 10) << QPoint(10, 10)
<< QPoint(10, 0));
p1.swap(p2);
- QCOMPARE(p1.count(),4);
- QCOMPARE(p2.count(),3);
+ QCOMPARE(p1.size(),4);
+ QCOMPARE(p2.size(),3);
}
void tst_QPolygon::intersections_data()
diff --git a/tests/auto/gui/painting/qregion/CMakeLists.txt b/tests/auto/gui/painting/qregion/CMakeLists.txt
index 024d04801f..ba580438cd 100644
--- a/tests/auto/gui/painting/qregion/CMakeLists.txt
+++ b/tests/auto/gui/painting/qregion/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qregion.pro.
-
#####################################################################
## 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
diff --git a/tests/auto/gui/painting/qregion/tst_qregion.cpp b/tests/auto/gui/painting/qregion/tst_qregion.cpp
index 14e210a056..934725844a 100644
--- a/tests/auto/gui/painting/qregion/tst_qregion.cpp
+++ b/tests/auto/gui/painting/qregion/tst_qregion.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -138,12 +138,15 @@ void tst_QRegion::rects()
QRegion region(rect);
QVERIFY(region.isEmpty());
QCOMPARE(region.begin(), region.end());
+ QVERIFY(region.rects().isEmpty());
}
{
QRect rect(10, -20, 30, 40);
QRegion region(rect);
QCOMPARE(region.end(), region.begin() + 1);
QCOMPARE(*region.begin(), rect);
+ QCOMPARE(region.rects().size(), 1);
+ QCOMPARE(region.rects()[0], rect);
}
{
QRect r(QPoint(10, 10), QPoint(40, 40));
@@ -190,6 +193,7 @@ void tst_QRegion::setRects()
QCOMPARE(region, QRegion());
QCOMPARE(region.begin(), region.end());
QVERIFY(!region.boundingRect().isValid());
+ QVERIFY(region.rects().isEmpty());
}
{
QRegion region;
@@ -197,12 +201,15 @@ void tst_QRegion::setRects()
region.setRects(&rect, 1);
QCOMPARE(region.begin(), region.end());
QVERIFY(!region.boundingRect().isValid());
+ QVERIFY(region.rects().isEmpty());
}
{
QRegion region;
QRect rect(10, -20, 30, 40);
region.setRects(&rect, 1);
QCOMPARE(region.end(), region.begin() + 1);
+ QCOMPARE(region.rects().size(), 1);
+ QCOMPARE(region.rects()[0], rect);
QCOMPARE(*region.begin(), rect);
}
}
@@ -316,10 +323,12 @@ void tst_QRegion::emptyPolygonRegion()
QRegion r(pa);
QTEST(r.isEmpty(), "isEmpty");
QTEST(int(std::distance(r.begin(), r.end())), "numRects");
- QList<QRect> rects;
- std::copy(r.begin(), r.end(), std::back_inserter(rects));
+ QList<QRect> rects{r.begin(), r.end()};
QTEST(int(rects.size()), "numRects");
QTEST(rects, "rects");
+ const auto span = r.rects();
+ rects.assign(span.begin(), span.end());
+ QTEST(rects, "rects");
}
@@ -862,6 +871,7 @@ void tst_QRegion::isEmpty()
QCOMPARE(region, QRegion());
QCOMPARE(region.rectCount(), 0);
QCOMPARE(region.boundingRect(), QRect());
+ QVERIFY(region.rects().isEmpty());
}
void tst_QRegion::regionFromPath()
@@ -877,6 +887,10 @@ void tst_QRegion::regionFromPath()
QCOMPARE(rgn.begin()[0], QRect(0, 0, 10, 10));
QCOMPARE(rgn.begin()[1], QRect(0, 100, 100, 1000));
+ QCOMPARE(rgn.rects().size(), 2);
+ QCOMPARE(rgn.rects()[0], QRect(0, 0, 10, 10));
+ QCOMPARE(rgn.rects()[1], QRect(0, 100, 100, 1000));
+
QCOMPARE(rgn.boundingRect(), QRect(0, 0, 100, 1100));
}
@@ -893,6 +907,12 @@ void tst_QRegion::regionFromPath()
QCOMPARE(rgn.begin()[2], QRect(90, 10, 10, 80));
QCOMPARE(rgn.begin()[3], QRect(0, 90, 100, 10));
+ QCOMPARE(rgn.rects().size(), 4);
+ QCOMPARE(rgn.rects()[0], QRect(0, 0, 100, 10));
+ QCOMPARE(rgn.rects()[1], QRect(0, 10, 10, 80));
+ QCOMPARE(rgn.rects()[2], QRect(90, 10, 10, 80));
+ QCOMPARE(rgn.rects()[3], QRect(0, 90, 100, 10));
+
QCOMPARE(rgn.boundingRect(), QRect(0, 0, 100, 100));
}
}
diff --git a/tests/auto/gui/painting/qtransform/CMakeLists.txt b/tests/auto/gui/painting/qtransform/CMakeLists.txt
index 03a98ed0b1..557e5fa742 100644
--- a/tests/auto/gui/painting/qtransform/CMakeLists.txt
+++ b/tests/auto/gui/painting/qtransform/CMakeLists.txt
@@ -1,12 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from qtransform.pro.
-
#####################################################################
## 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
diff --git a/tests/auto/gui/painting/qtransform/tst_qtransform.cpp b/tests/auto/gui/painting/qtransform/tst_qtransform.cpp
index ecc8f7e4cc..428174bfc6 100644
--- a/tests/auto/gui/painting/qtransform/tst_qtransform.cpp
+++ b/tests/auto/gui/painting/qtransform/tst_qtransform.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>