diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-05-23 20:12:12 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-05-23 18:18:44 +0000 |
commit | fe5a157cbe37d2516ca69c92c4ec989ce77a25a2 (patch) | |
tree | ab3033995e6e7d24dfd846913edce4827deef381 /tests/auto/qhelpprojectdata | |
parent | f377c9ce92be7f5ef82abbf585d88dd9f46a8811 (diff) |
tests: remove uses of Q_FOREACH
All pretty straight-forward, except two:
- in tst_QHelpPrjectData::filterSections(), use QCOMPARE() on two
lists instead of running it by hand. To allow for variation in
order, sort the list under test, and make sure the reference list is
sorted, too.
- in tst_QHelpEngineCore::files(), the trailing printing of 'lst' was
dead code: either the QCOMPARE succeeded, then 'lst' was empty, or
it failed, in which case QCOMPARE exits the function. The loop was
obviously meant to show the remaining items in case the test fails,
so stuff the loop (w/o Q_FOREACH) into a scope guard.
QtC tricked me into believing that these were the only occurrences in
this module. Alas, it just failed to parse large parts of the module's
pro-files. The module continues to be one of the worst offenders
w.r.t. Q_FOREACH with qdoc and linguist each containing ~150
instances, as well as macdeploy with a another dozen or two. The rest
is clean now.
Change-Id: I89f37ef07ab284da7881d624d9111e89cd2b2cbc
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'tests/auto/qhelpprojectdata')
-rw-r--r-- | tests/auto/qhelpprojectdata/tst_qhelpprojectdata.cpp | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/tests/auto/qhelpprojectdata/tst_qhelpprojectdata.cpp b/tests/auto/qhelpprojectdata/tst_qhelpprojectdata.cpp index a09135d7c..9b47be519 100644 --- a/tests/auto/qhelpprojectdata/tst_qhelpprojectdata.cpp +++ b/tests/auto/qhelpprojectdata/tst_qhelpprojectdata.cpp @@ -85,18 +85,18 @@ void tst_QHelpProjectData::customFilters() if (!data.readData(m_inputFile)) QFAIL("Cannot read qhp file!"); - QList<QHelpDataCustomFilter> filters = data.customFilters(); + const QList<QHelpDataCustomFilter> filters = data.customFilters(); QCOMPARE(filters.count(), 2); - foreach (QHelpDataCustomFilter f, filters) { + for (const QHelpDataCustomFilter &f : filters) { if (f.name == QLatin1String("Custom Filter 1")) { - foreach (QString id, f.filterAttributes) { + for (const QString &id : f.filterAttributes) { if (id != QLatin1String("test") && id != QLatin1String("filter1")) QFAIL("Wrong filter attribute!"); } } else if (f.name == QLatin1String("Custom Filter 2")) { - foreach (QString id, f.filterAttributes) { + for (const QString &id : f.filterAttributes) { if (id != QLatin1String("test") && id != QLatin1String("filter2")) QFAIL("Wrong filter attribute!"); @@ -113,13 +113,14 @@ void tst_QHelpProjectData::filterSections() if (!data.readData(m_inputFile)) QFAIL("Cannot read qhp file!"); - QList<QHelpDataFilterSection> sections = data.filterSections(); + const QList<QHelpDataFilterSection> sections = data.filterSections(); QCOMPARE(sections.count(), 2); - foreach (QHelpDataFilterSection s, sections) { + for (const QHelpDataFilterSection &s : sections) { if (s.filterAttributes().contains("filter1")) { - QCOMPARE(s.indices().count(), 5); - foreach (QHelpDataIndexItem idx, s.indices()) { + const auto indices = s.indices(); + QCOMPARE(indices.size(), 5); + for (const QHelpDataIndexItem &idx : indices) { if (idx.name == QLatin1String("foo")) { QCOMPARE(idx.identifier, QString("Test::foo")); } else if (idx.name == QLatin1String("bar")) { @@ -138,11 +139,14 @@ void tst_QHelpProjectData::filterSections() QCOMPARE(s.contents().first()->children().count(), 5); } else if (s.filterAttributes().contains("filter2")) { QCOMPARE(s.contents().count(), 1); - QStringList lst; - lst << "classic.css" << "fancy.html" << "cars.html"; - foreach (QString f, s.files()) - lst.removeAll(f); - QCOMPARE(lst.count(), 0); + const QStringList lst = { + "cars.html", + "classic.css", + "fancy.html", + }; + auto files = s.files(); + std::sort(files.begin(), files.end()); + QCOMPARE(files, lst); } else { QFAIL("Unexpected filter attribute!"); } |