diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-10-08 19:56:03 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-10-13 00:18:35 +0200 |
commit | 5eb52b725526c26d0efa3856b6aba1919010f8fd (patch) | |
tree | 64d1bde7a2cc624e586228c9768c7eb1ea360e6c /tests/auto/quick/qquicklistview/tst_qquicklistview.cpp | |
parent | e1a0596924766d62459740ed0271114a7bb99851 (diff) |
Port from container::count() and length() to size() - V5
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to
handle typedefs and accesses through pointers, too:
const std::string o = "object";
auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); };
auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) {
auto exprOfDeclaredType = [&](auto decl) {
return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o);
};
return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))));
};
auto renameMethod = [&] (ArrayRef<StringRef> classes,
StringRef from, StringRef to) {
return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)),
callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))),
changeTo(cat(access(o, cat(to)), "()")),
cat("use '", to, "' instead of '", from, "'"));
};
renameMethod(<classes>, "count", "size");
renameMethod(<classes>, "length", "size");
except that on() was replaced with a matcher that doesn't ignoreParens().
a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'.
Change-Id: I58e1b41b91c34d2e860dbb5847b3752edbfc6fc9
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/quick/qquicklistview/tst_qquicklistview.cpp')
-rw-r--r-- | tests/auto/quick/qquicklistview/tst_qquicklistview.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index c34d55f87b..bc372fd040 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -4913,7 +4913,7 @@ void tst_QQuickListView::onAdd() QTRY_COMPARE(listview->property("count").toInt(), model.count()); QVariantList result = listview->property("addedDelegates").toList(); - QCOMPARE(result.count(), items.size()); + QCOMPARE(result.size(), items.size()); for (int i=0; i<items.size(); i++) QCOMPARE(result[i].toString(), items[i].first); } @@ -7528,15 +7528,15 @@ void tst_QQuickListView::displacedTransitions() QTRY_VERIFY(listview->property("displaceTransitionsDone").toBool()); // check the correct number of target items and indexes were received - QCOMPARE(resultTargetIndexes.count(), expectedDisplacedIndexes.count()); - for (int i=0; i<resultTargetIndexes.count(); i++) + QCOMPARE(resultTargetIndexes.size(), expectedDisplacedIndexes.count()); + for (int i=0; i<resultTargetIndexes.size(); i++) QCOMPARE(resultTargetIndexes[i].value<QList<int> >().size(), change.count); - QCOMPARE(resultTargetItems.count(), expectedDisplacedIndexes.count()); - for (int i=0; i<resultTargetItems.count(); i++) + QCOMPARE(resultTargetItems.size(), expectedDisplacedIndexes.count()); + for (int i=0; i<resultTargetItems.size(); i++) QCOMPARE(resultTargetItems[i].toList().size(), change.count); } else { - QCOMPARE(resultTargetIndexes.count(), 0); - QCOMPARE(resultTargetItems.count(), 0); + QCOMPARE(resultTargetIndexes.size(), 0); + QCOMPARE(resultTargetItems.size(), 0); } if (change.type == ListChange::Inserted && useAddDisplaced && addDisplacedEnabled) @@ -7897,7 +7897,7 @@ QList<int> tst_QQuickListView::toIntList(const QVariantList &list) { QList<int> ret; bool ok = true; - for (int i=0; i<list.count(); i++) { + for (int i=0; i<list.size(); i++) { ret << list[i].toInt(&ok); if (!ok) qWarning() << "tst_QQuickListView::toIntList(): not a number:" << list[i]; @@ -7909,7 +7909,7 @@ QList<int> tst_QQuickListView::toIntList(const QVariantList &list) void tst_QQuickListView::matchIndexLists(const QVariantList &indexLists, const QList<int> &expectedIndexes) { const QSet<int> expectedIndexSet(expectedIndexes.cbegin(), expectedIndexes.cend()); - for (int i=0; i<indexLists.count(); i++) { + for (int i=0; i<indexLists.size(); i++) { const auto ¤tList = indexLists[i].value<QList<int> >(); const QSet<int> current(currentList.cbegin(), currentList.cend()); if (current != expectedIndexSet) @@ -7929,20 +7929,20 @@ void tst_QQuickListView::matchItemsAndIndexes(const QVariantMap &items, const Qa qDebug() << itemIndex; QCOMPARE(model.name(itemIndex), name); } - QCOMPARE(items.count(), expectedIndexes.size()); + QCOMPARE(items.size(), expectedIndexes.size()); } void tst_QQuickListView::matchItemLists(const QVariantList &itemLists, const QList<QQuickItem *> &expectedItems) { - for (int i=0; i<itemLists.count(); i++) { + for (int i=0; i<itemLists.size(); i++) { QCOMPARE(itemLists[i].typeId(), QMetaType::QVariantList); QVariantList current = itemLists[i].toList(); - for (int j=0; j<current.count(); j++) { + for (int j=0; j<current.size(); j++) { QQuickItem *o = qobject_cast<QQuickItem*>(current[j].value<QObject*>()); QVERIFY2(o, qPrintable(QString("Invalid actual item at %1").arg(j))); QVERIFY2(expectedItems.contains(o), qPrintable(QString("Cannot match item %1").arg(j))); } - QCOMPARE(current.count(), expectedItems.size()); + QCOMPARE(current.size(), expectedItems.size()); } } |