From df9d882d41b741fef7c5beeddb0abe9d904443d8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 30 Sep 2022 14:09:04 +0200 Subject: Port from container.count()/length() to size() This is semantic patch using ClangTidyTransformator: auto QtContainerClass = expr(hasType(namedDecl(hasAnyName()))).bind(o) makeRule(cxxMemberCallExpr(on(QtContainerClass), callee(cxxMethodDecl(hasAnyName({"count", "length"), parameterCountIs(0))))), changeTo(cat(access(o, cat("size"), "()"))), cat("use 'size()' instead of 'count()/length()'")) a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'. are: // sequential: "QByteArray", "QList", "QQueue", "QStack", "QString", "QVarLengthArray", "QVector", // associative: "QHash", "QMultiHash", "QMap", "QMultiMap", "QSet", // Qt has no QMultiSet Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af Reviewed-by: Qt CI Bot Reviewed-by: Volker Hilsheimer --- tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp | 2 +- tests/auto/corelib/global/qglobal/tst_qglobal.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'tests/auto/corelib/global') diff --git a/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp b/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp index f914ee5f23..832319a652 100644 --- a/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp +++ b/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp @@ -191,7 +191,7 @@ void tst_QGetPutEnv::intValue() bool actualOk = !ok; // Self-test: confirm that it was like the docs said it should be - if (value.length() < maxlen) { + if (value.size() < maxlen) { QCOMPARE(value.toInt(&actualOk, 0), expected); QCOMPARE(actualOk, ok); } diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index 3923b6d6ac..4b0b97de0b 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -85,7 +85,7 @@ void tst_QGlobal::for_each() foreach(int i, list) { QCOMPARE(i, counter++); } - QCOMPARE(counter, list.count()); + QCOMPARE(counter, list.size()); // do it again, to make sure we don't have any for-scoping // problems with older compilers @@ -93,21 +93,21 @@ void tst_QGlobal::for_each() foreach(int i, list) { QCOMPARE(i, counter++); } - QCOMPARE(counter, list.count()); + QCOMPARE(counter, list.size()); // check whether we can pass a constructor as container argument counter = 0; foreach (int i, QList(list)) { QCOMPARE(i, counter++); } - QCOMPARE(counter, list.count()); + QCOMPARE(counter, list.size()); // check whether we can use a lambda counter = 0; foreach (int i, [&](){ return list; }()) { QCOMPARE(i, counter++); } - QCOMPARE(counter, list.count()); + QCOMPARE(counter, list.size()); // Should also work with an existing variable int local = 0; @@ -115,7 +115,7 @@ void tst_QGlobal::for_each() foreach (local, list) { QCOMPARE(local, counter++); } - QCOMPARE(counter, list.count()); + QCOMPARE(counter, list.size()); QCOMPARE(local, counter - 1); // Test the macro does not mess if/else conditions @@ -125,7 +125,7 @@ void tst_QGlobal::for_each() QCOMPARE(i, counter++); else QFAIL("If/Else mismatch"); - QCOMPARE(counter, list.count()); + QCOMPARE(counter, list.size()); counter = 0; if (false) @@ -136,7 +136,7 @@ void tst_QGlobal::for_each() foreach (int i, list) if (false) { } else QCOMPARE(i, counter++); - QCOMPARE(counter, list.count()); + QCOMPARE(counter, list.size()); // break and continue counter = 0; -- cgit v1.2.3