From 31bfd89f6c01d8219a738be01f3f285a98bcb121 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 7 Aug 2023 14:42:55 +0200 Subject: [PATCH] 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 (cherry picked from commit e0c1ae09fd79160015c8399980d2bec4df2273df) Reviewed-by: Qt Cherry-pick Bot --- .../widgets/dialogs/qwizard/tst_qwizard.cpp | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp index d4d36bb84f6..a7d4992c07d 100644 --- a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp +++ b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp @@ -1814,8 +1814,16 @@ public: class CombinationsTestData { TestGroup testGroup; - QList> pageOps; - QList> styleOps; + const QSharedPointer pageOps[3] = { + SetPage::create(0), + SetPage::create(1), + SetPage::create(2), + }; + const QSharedPointer styleOps[3] = { + SetStyle::create(QWizard::ClassicStyle), + SetStyle::create(QWizard::ModernStyle), + SetStyle::create(QWizard::MacStyle), + }; QMap>> setAllOptions; public: @@ -1824,11 +1832,8 @@ public: QTest::addColumn("ref"); QTest::addColumn("testEquality"); QTest::addColumn>>("operations"); - pageOps << SetPage::create(0) << SetPage::create(1) << SetPage::create(2); - styleOps << SetStyle::create(QWizard::ClassicStyle) << SetStyle::create(QWizard::ModernStyle) - << SetStyle::create(QWizard::MacStyle); -#define SETPAGE(page) pageOps.at(page) -#define SETSTYLE(style) styleOps.at(style) +#define SETPAGE(page) pageOps[page] +#define SETSTYLE(style) styleOps[style] #define OPT(option, on) OptionInfo::instance().operation(option, on) #define CLROPT(option) OPT(option, false) #define SETOPT(option) OPT(option, true) @@ -1906,7 +1911,7 @@ public: testGroup.createTestRows(); } - foreach (const QSharedPointer &pageOp, pageOps) { + for (const QSharedPointer &pageOp : pageOps) { testGroup.reset("testAll 4.1"); testGroup.add() << pageOp; testGroup.add() << pageOp << pageOp; @@ -1929,7 +1934,7 @@ public: } } - foreach (const QSharedPointer &styleOp, styleOps) { + for (const QSharedPointer &styleOp : styleOps) { testGroup.reset("testAll 5.1"); testGroup.add() << styleOp; testGroup.add() << styleOp << styleOp; @@ -1952,8 +1957,8 @@ public: } } - foreach (const QSharedPointer &pageOp, pageOps) { - foreach (const QSharedPointer &styleOp, styleOps) { + for (const QSharedPointer &pageOp : pageOps) { + for (const QSharedPointer &styleOp : styleOps) { testGroup.reset("testAll 6.1"); testGroup.add() << pageOp;