tst_QWizard: port away from Q_FOREACH[5/5]: CombinationsTestData ctor

This is iterating over data member containers that are otherwise only
touched in the constructor of the same object. Luckily, the
initialization of these containers does not require *this, so use
NSDMI and mark the containers const, proving they can never be
modified and thus the protective copy of Q_FOREACH isn't required. Now
that we got rid of Q_FOREACH, we can and do make them arrays for extra
measure ("never use dynamically-sized containers for statically-sized
data").

Unfortunately, C++ neither allows us to use "flexible array
members" nor AAA in NSDMI, so grab the nettle and supply the array
size manually (ever so slightly violating DRY, but the compiler will
complain if we get it wrong).

Task-number: QTBUG-115803
Change-Id: Ibb2ce48b6dcaf2e9d3d1a625602f3865d280c7c6
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit e0c1ae09fd79160015c8399980d2bec4df2273df)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2023-08-07 14:42:55 +02:00 committed by Qt Cherry-pick Bot
parent 4f3b16c491
commit 31bfd89f6c

View File

@ -1814,8 +1814,16 @@ public:
class CombinationsTestData class CombinationsTestData
{ {
TestGroup testGroup; TestGroup testGroup;
QList<QSharedPointer<Operation>> pageOps; const QSharedPointer<Operation> pageOps[3] = {
QList<QSharedPointer<Operation>> styleOps; SetPage::create(0),
SetPage::create(1),
SetPage::create(2),
};
const QSharedPointer<Operation> styleOps[3] = {
SetStyle::create(QWizard::ClassicStyle),
SetStyle::create(QWizard::ModernStyle),
SetStyle::create(QWizard::MacStyle),
};
QMap<bool, QList<QSharedPointer<Operation>>> setAllOptions; QMap<bool, QList<QSharedPointer<Operation>>> setAllOptions;
public: public:
@ -1824,11 +1832,8 @@ public:
QTest::addColumn<bool>("ref"); QTest::addColumn<bool>("ref");
QTest::addColumn<bool>("testEquality"); QTest::addColumn<bool>("testEquality");
QTest::addColumn<QList<QSharedPointer<Operation>>>("operations"); QTest::addColumn<QList<QSharedPointer<Operation>>>("operations");
pageOps << SetPage::create(0) << SetPage::create(1) << SetPage::create(2); #define SETPAGE(page) pageOps[page]
styleOps << SetStyle::create(QWizard::ClassicStyle) << SetStyle::create(QWizard::ModernStyle) #define SETSTYLE(style) styleOps[style]
<< SetStyle::create(QWizard::MacStyle);
#define SETPAGE(page) pageOps.at(page)
#define SETSTYLE(style) styleOps.at(style)
#define OPT(option, on) OptionInfo::instance().operation(option, on) #define OPT(option, on) OptionInfo::instance().operation(option, on)
#define CLROPT(option) OPT(option, false) #define CLROPT(option) OPT(option, false)
#define SETOPT(option) OPT(option, true) #define SETOPT(option) OPT(option, true)
@ -1906,7 +1911,7 @@ public:
testGroup.createTestRows(); testGroup.createTestRows();
} }
foreach (const QSharedPointer<Operation> &pageOp, pageOps) { for (const QSharedPointer<Operation> &pageOp : pageOps) {
testGroup.reset("testAll 4.1"); testGroup.reset("testAll 4.1");
testGroup.add() << pageOp; testGroup.add() << pageOp;
testGroup.add() << pageOp << pageOp; testGroup.add() << pageOp << pageOp;
@ -1929,7 +1934,7 @@ public:
} }
} }
foreach (const QSharedPointer<Operation> &styleOp, styleOps) { for (const QSharedPointer<Operation> &styleOp : styleOps) {
testGroup.reset("testAll 5.1"); testGroup.reset("testAll 5.1");
testGroup.add() << styleOp; testGroup.add() << styleOp;
testGroup.add() << styleOp << styleOp; testGroup.add() << styleOp << styleOp;
@ -1952,8 +1957,8 @@ public:
} }
} }
foreach (const QSharedPointer<Operation> &pageOp, pageOps) { for (const QSharedPointer<Operation> &pageOp : pageOps) {
foreach (const QSharedPointer<Operation> &styleOp, styleOps) { for (const QSharedPointer<Operation> &styleOp : styleOps) {
testGroup.reset("testAll 6.1"); testGroup.reset("testAll 6.1");
testGroup.add() << pageOp; testGroup.add() << pageOp;