From 1c6bf3e09ea9722717caedcfcceaaf3d607615cf Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 30 Sep 2022 14:09:04 +0200 Subject: 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 classes) { auto exprOfDeclaredType = [&](auto decl) { return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o); }; return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes)))); }; auto renameMethod = [&] (ArrayRef 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(, "count", "size"); renameMethod(, "length", "size"); except that the on() matcher has been replaced by one that doesn't ignoreParens(). a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'. Added two NOLINTNEXTLINEs in tst_qbitarray and tst_qcontiguouscache, to avoid porting calls that explicitly test count(). Change-Id: Icfb8808c2ff4a30187e9935a51cad26987451c22 Reviewed-by: Ivan Solovev Reviewed-by: Qt CI Bot --- src/testlib/qpropertytesthelper_p.h | 18 +++++++++--------- src/testlib/qsignalspy.h | 4 ++-- src/testlib/qtestcase.cpp | 6 +++--- src/testlib/qtestevent.h | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) (limited to 'src/testlib') diff --git a/src/testlib/qpropertytesthelper_p.h b/src/testlib/qpropertytesthelper_p.h index b5bd8d2583..f2cb82cdd7 100644 --- a/src/testlib/qpropertytesthelper_p.h +++ b/src/testlib/qpropertytesthelper_p.h @@ -129,7 +129,7 @@ void testReadWritePropertyBasics( testedObj.property(propertyName).template value(), initial, comparator, represent); if (spy) - QCOMPARE(spy->count(), 1); + QCOMPARE(spy->size(), 1); QUntypedBindable bindable = metaProperty.bindable(&instance); @@ -148,7 +148,7 @@ void testReadWritePropertyBasics( QPROPERTY_TEST_COMPARISON_HELPER(propObserver.value(), changed, comparator, represent); QPROPERTY_TEST_COMPARISON_HELPER(propObserverLambda.value(), changed, comparator, represent); if (spy) - QCOMPARE(spy->count(), 2); + QCOMPARE(spy->size(), 2); // Bind object's property to other property QProperty propSetter(initial); @@ -162,7 +162,7 @@ void testReadWritePropertyBasics( QPROPERTY_TEST_COMPARISON_HELPER(propObserver.value(), initial, comparator, represent); QPROPERTY_TEST_COMPARISON_HELPER(propObserverLambda.value(), initial, comparator, represent); if (spy) - QCOMPARE(spy->count(), 3); + QCOMPARE(spy->size(), 3); // Count notifications triggered; should only happen on actual change. int updateCount = 0; @@ -177,7 +177,7 @@ void testReadWritePropertyBasics( QPROPERTY_TEST_COMPARISON_HELPER(propObserverLambda.value(), changed, comparator, represent); QCOMPARE(updateCount, 1); if (spy) - QCOMPARE(spy->count(), 4); + QCOMPARE(spy->size(), 4); // Test that manually setting the value (even the same one) breaks the // binding. @@ -188,7 +188,7 @@ void testReadWritePropertyBasics( // value didn't change -> the signal should not be emitted if (spy) - QCOMPARE(spy->count(), 4); + QCOMPARE(spy->size(), 4); } /*! @@ -287,7 +287,7 @@ void testWriteOncePropertyBasics( represent); QPROPERTY_TEST_COMPARISON_HELPER(propObserver.value(), changed, comparator, represent); if (spy) - QCOMPARE(spy->count(), 1); + QCOMPARE(spy->size(), 1); // Attempt to set back the 'prior' value and verify that it has no effect testedObj.setProperty(propertyName, QVariant::fromValue(prior)); @@ -296,7 +296,7 @@ void testWriteOncePropertyBasics( represent); QPROPERTY_TEST_COMPARISON_HELPER(propObserver.value(), changed, comparator, represent); if (spy) - QCOMPARE(spy->count(), 1); + QCOMPARE(spy->size(), 1); if (bindingPreservedOnWrite) QVERIFY(bindable.hasBinding()); else @@ -386,7 +386,7 @@ void testReadOnlyPropertyBasics( testedObj.property(propertyName).template value(), initial, comparator, represent); if (spy) - QCOMPARE(spy->count(), 0); + QCOMPARE(spy->size(), 0); QProperty propObserver; propObserver.setBinding(bindable.makeBinding()); @@ -402,7 +402,7 @@ void testReadOnlyPropertyBasics( QPROPERTY_TEST_COMPARISON_HELPER(propObserver.value(), changed, comparator, represent); if (spy) - QCOMPARE(spy->count(), 1); + QCOMPARE(spy->size(), 1); } } // namespace QTestPrivate diff --git a/src/testlib/qsignalspy.h b/src/testlib/qsignalspy.h index 7c85311856..61192cd9e8 100644 --- a/src/testlib/qsignalspy.h +++ b/src/testlib/qsignalspy.h @@ -97,11 +97,11 @@ public: bool wait(int timeout = 5000) { Q_ASSERT(!m_waiting); - const qsizetype origCount = count(); + const qsizetype origCount = size(); m_waiting = true; m_loop.enterLoopMSecs(timeout); m_waiting = false; - return count() > origCount; + return size() > origCount; } int qt_metacall(QMetaObject::Call call, int methodId, void **a) override diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 347008fe02..335b72f1fb 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -655,7 +655,7 @@ static void qPrintDataTags(FILE *stream) // Print all tag combinations: if (gTable->dataCount() == 0) { - if (localTags.count() == 0) { + if (localTags.size() == 0) { // No tags at all, so just print the test function: fprintf(stream, "%s %s\n", currTestMetaObj->className(), slot); } else { @@ -667,7 +667,7 @@ static void qPrintDataTags(FILE *stream) } } else { for (int j = 0; j < gTable->dataCount(); ++j) { - if (localTags.count() == 0) { + if (localTags.size() == 0) { // Only global tags, so print the current one: fprintf( stream, "%s %s __global__ %s\n", @@ -2431,7 +2431,7 @@ QTest::TestEntryFunction QTest::qGetTestCaseEntryFunction(const QString& name) */ int QTest::qExec(QObject *testObject, const QStringList &arguments) { - const int argc = arguments.count(); + const int argc = arguments.size(); QVarLengthArray argv(argc); QList args; diff --git a/src/testlib/qtestevent.h b/src/testlib/qtestevent.h index 80745ed9bf..8f092cf8c9 100644 --- a/src/testlib/qtestevent.h +++ b/src/testlib/qtestevent.h @@ -132,7 +132,7 @@ class QTestEventList: public QList public: inline QTestEventList() {} inline QTestEventList(const QTestEventList &other): QList() - { for (int i = 0; i < other.count(); ++i) append(other.at(i)->clone()); } + { for (int i = 0; i < other.size(); ++i) append(other.at(i)->clone()); } inline ~QTestEventList() { clear(); } inline void clear() @@ -182,7 +182,7 @@ public: #ifdef QT_WIDGETS_LIB inline void simulate(QWidget *w) { - for (int i = 0; i < count(); ++i) + for (int i = 0; i < size(); ++i) at(i)->simulate(w); } #endif -- cgit v1.2.3