diff options
| author | Marc Mutz <marc.mutz@qt.io> | 2022-09-30 14:09:04 +0200 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2022-11-03 14:59:24 +0100 |
| commit | 1c6bf3e09ea9722717caedcfcceaaf3d607615cf (patch) | |
| tree | cad1814e104667a84ba7b5f403bbda015413e058 /tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp | |
| parent | 43cda7807b98552e9292ac09a1f6612d432a8b13 (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 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 <ivan.solovev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp')
| -rw-r--r-- | tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp b/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp index 8b7476b3e70..202fc1080cc 100644 --- a/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp +++ b/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp @@ -202,7 +202,7 @@ void tst_QSqlQueryModel::removeColumn() QCOMPARE(model.columnCount(), 3); QVERIFY(model.removeColumn(0)); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QVERIFY(*(QModelIndex *)spy.at(0).at(0).constData() == QModelIndex()); QCOMPARE(spy.at(0).at(1).toInt(), 0); QCOMPARE(spy.at(0).at(2).toInt(), 0); @@ -232,7 +232,7 @@ void tst_QSqlQueryModel::removeColumn() QVERIFY(model.removeColumn(2)); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); QVERIFY(*(QModelIndex *)spy.at(1).at(0).constData() == QModelIndex()); QCOMPARE(spy.at(1).at(1).toInt(), 2); QCOMPARE(spy.at(1).at(2).toInt(), 2); @@ -245,7 +245,7 @@ void tst_QSqlQueryModel::removeColumn() QVERIFY(model.removeColumn(1)); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); QVERIFY(*(QModelIndex *)spy.at(2).at(0).constData() == QModelIndex()); QCOMPARE(spy.at(2).at(1).toInt(), 1); QCOMPARE(spy.at(2).at(2).toInt(), 1); @@ -259,7 +259,7 @@ void tst_QSqlQueryModel::removeColumn() QVERIFY(model.removeColumn(0)); - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); QVERIFY(*(QModelIndex *)spy.at(3).at(0).constData() == QModelIndex()); QCOMPARE(spy.at(3).at(1).toInt(), 0); QCOMPARE(spy.at(3).at(2).toInt(), 0); @@ -301,7 +301,7 @@ void tst_QSqlQueryModel::insertColumn() QVERIFY(model.insertColumn(1)); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QVERIFY(*(QModelIndex *)spy.at(0).at(0).constData() == QModelIndex()); QCOMPARE(spy.at(0).at(1).toInt(), 1); QCOMPARE(spy.at(0).at(2).toInt(), 1); @@ -330,7 +330,7 @@ void tst_QSqlQueryModel::insertColumn() QVERIFY(model.insertColumn(0)); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); QVERIFY(*(QModelIndex *)spy.at(1).at(0).constData() == QModelIndex()); QCOMPARE(spy.at(1).at(1).toInt(), 0); QCOMPARE(spy.at(1).at(2).toInt(), 0); @@ -345,7 +345,7 @@ void tst_QSqlQueryModel::insertColumn() QVERIFY(!model.insertColumn(6)); QVERIFY(model.insertColumn(5)); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); QVERIFY(*(QModelIndex *)spy.at(2).at(0).constData() == QModelIndex()); QCOMPARE(spy.at(2).at(1).toInt(), 5); QCOMPARE(spy.at(2).at(2).toInt(), 5); @@ -424,7 +424,7 @@ void tst_QSqlQueryModel::setHeaderData() QSignalSpy spy(&model, SIGNAL(headerDataChanged(Qt::Orientation,int,int))); QVERIFY(model.setHeaderData(2, Qt::Horizontal, "bar")); QCOMPARE(model.headerData(2, Qt::Horizontal).toString(), QString("bar")); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCOMPARE(qvariant_cast<Qt::Orientation>(spy.value(0).value(0)), Qt::Horizontal); QCOMPARE(spy.value(0).value(1).toInt(), 2); QCOMPARE(spy.value(0).value(2).toInt(), 2); @@ -452,8 +452,8 @@ void tst_QSqlQueryModel::fetchMore() model.setQuery(QSqlQuery("select * from " + qTableName("many", __FILE__, db), db)); int rowCount = model.rowCount(); - QCOMPARE(modelAboutToBeResetSpy.count(), 1); - QCOMPARE(modelResetSpy.count(), 1); + QCOMPARE(modelAboutToBeResetSpy.size(), 1); + QCOMPARE(modelResetSpy.size(), 1); // If the driver doesn't return the query size fetchMore() causes the // model to grow and new signals are emitted @@ -499,11 +499,11 @@ void tst_QSqlQueryModel::withSortFilterProxyModel() QCOMPARE(proxy.rowCount(), 511); // setQuery() resets the model accompanied by begin and end signals - QCOMPARE(modelAboutToBeResetSpy.count(), 1); - QCOMPARE(modelResetSpy.count(), 1); + QCOMPARE(modelAboutToBeResetSpy.size(), 1); + QCOMPARE(modelResetSpy.size(), 1); // The call to scrollToBottom() forces the model to fetch additional rows. - QCOMPARE(modelRowsInsertedSpy.count(), 1); + QCOMPARE(modelRowsInsertedSpy.size(), 1); QCOMPARE(modelRowsInsertedSpy.value(0).value(1).toInt(), 256); QCOMPARE(modelRowsInsertedSpy.value(0).value(2).toInt(), 510); } @@ -523,14 +523,14 @@ void tst_QSqlQueryModel::setQuerySignalEmission() // First select, the model was empty and no rows had to be removed, but model resets anyway. model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test", __FILE__, db), db)); - QCOMPARE(modelAboutToBeResetSpy.count(), 1); - QCOMPARE(modelResetSpy.count(), 1); + QCOMPARE(modelAboutToBeResetSpy.size(), 1); + QCOMPARE(modelResetSpy.size(), 1); // Second select, the model wasn't empty and two rows had to be removed! // setQuery() resets the model accompanied by begin and end signals model.setQuery(QSqlQuery("SELECT * FROM " + qTableName("test", __FILE__, db), db)); - QCOMPARE(modelAboutToBeResetSpy.count(), 2); - QCOMPARE(modelResetSpy.count(), 2); + QCOMPARE(modelAboutToBeResetSpy.size(), 2); + QCOMPARE(modelResetSpy.size(), 2); } // For task 170783: When the query's result set is empty no rows should be inserted, @@ -549,8 +549,8 @@ void tst_QSqlQueryModel::setQueryWithNoRowsInResultSet() QSqlQuery query(db); QVERIFY_SQL(query, exec("SELECT * FROM " + qTableName("test", __FILE__, db) + " where 0 = 1")); model.setQuery(std::move(query)); - QCOMPARE(modelRowsAboutToBeInsertedSpy.count(), 0); - QCOMPARE(modelRowsInsertedSpy.count(), 0); + QCOMPARE(modelRowsAboutToBeInsertedSpy.size(), 0); + QCOMPARE(modelRowsInsertedSpy.size(), 0); } class NestedResetsTest: public QSqlQueryModel |
