tst_bench_qpainter: compile with QT_NO_FOREACH

Use C arrays for data known at compile time.

Drive-by change: verify the two containers that are iterated in tandem
have the same size.

Task-number: QTBUG-115839
Change-Id: I457ddca8aa98e2f15a833a40ff45bd208701bf6b
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Ahmad Samir 2023-08-14 18:22:11 +03:00
parent 7bd47fb708
commit b5e4657307

View File

@ -1,8 +1,6 @@
// Copyright (C) 2016 The Qt Company Ltd. // Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include <qtest.h> #include <qtest.h>
#include <QPainter> #include <QPainter>
#include <QPainterPath> #include <QPainterPath>
@ -14,6 +12,8 @@
#include <private/qpixmap_raster_p.h> #include <private/qpixmap_raster_p.h>
using namespace Qt::StringLiterals;
Q_DECLARE_METATYPE(QPainterPath) Q_DECLARE_METATYPE(QPainterPath)
Q_DECLARE_METATYPE(QPainter::RenderHint) Q_DECLARE_METATYPE(QPainter::RenderHint)
Q_DECLARE_METATYPE(QPainter::CompositionMode) Q_DECLARE_METATYPE(QPainter::CompositionMode)
@ -293,29 +293,33 @@ void tst_QPainter::drawLine_data()
QTest::addColumn<QLine>("line"); QTest::addColumn<QLine>("line");
QTest::addColumn<QPen>("pen"); QTest::addColumn<QPen>("pen");
QList<QPen> pens; const QPen pens[] = {
pens << QPen(Qt::black) QPen(Qt::black),
<< QPen(Qt::black, 0, Qt::DashDotLine) QPen(Qt::black, 0, Qt::DashDotLine),
<< QPen(Qt::black, 4) QPen(Qt::black, 4),
<< QPen(Qt::black, 4, Qt::DashDotLine) QPen(Qt::black, 4, Qt::DashDotLine),
<< QPen(QColor(255, 0, 0, 200)) QPen(QColor(255, 0, 0, 200)),
<< QPen(QColor(255, 0, 0, 200), 0, Qt::DashDotLine) QPen(QColor(255, 0, 0, 200), 0, Qt::DashDotLine),
<< QPen(QColor(255, 0, 0, 200), 4) QPen(QColor(255, 0, 0, 200), 4),
<< QPen(QColor(255, 0, 0, 200), 4, Qt::DashDotLine); QPen(QColor(255, 0, 0, 200), 4, Qt::DashDotLine)
};
QStringList penNames; const char *penNames[] = {
penNames << "black-0" "black-0",
<< "black-0-dashdot" "black-0-dashdot",
<< "black-4" "black-4",
<< "black-4-dashdot" "black-4-dashdot",
<< "alpha-0" "alpha-0",
<< "alpha-0-dashdot" "alpha-0-dashdot",
<< "alpha-4" "alpha-4",
<< "alpha-4-dashdot"; "alpha-4-dashdot",
};
int i = 0; QCOMPARE(std::size(pens), std::size(penNames));
foreach (QPen pen, pens) {
const QString s = QString(QLatin1String("%1:%2")).arg(penNames[i]); for (size_t i = 0; i < std::size(pens); ++i) {
const QPen &pen = pens[i];
const QString s = QString("%1:%2"_L1).arg(QLatin1StringView(penNames[i]));
QTest::newRow(qPrintable(s.arg("horizontal"))) QTest::newRow(qPrintable(s.arg("horizontal")))
<< QLine(0, 20, 100, 20) << pen; << QLine(0, 20, 100, 20) << pen;
QTest::newRow(qPrintable(s.arg("vertical:"))) QTest::newRow(qPrintable(s.arg("vertical:")))
@ -336,7 +340,6 @@ void tst_QPainter::drawLine_data()
<< QLine(0, 0, 20, 100) << pen; << QLine(0, 0, 20, 100) << pen;
QTest::newRow(qPrintable(s.arg("315-360:"))) QTest::newRow(qPrintable(s.arg("315-360:")))
<< QLine(0, 0, 100, 20) << pen; << QLine(0, 0, 100, 20) << pen;
++i;
} }
} }