summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/painting/qpainter/tst_qpainter.cpp')
-rw-r--r--tests/auto/gui/painting/qpainter/tst_qpainter.cpp110
1 files changed, 70 insertions, 40 deletions
diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
index eb705a0219..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;