Silence the item model tests

Introduce a logging category for the qDebug()-output.

Add a meta type registration for QList<QPersistentModelIndex>, fixing
numerous warnings like:
WARN  : tst_QItemModel::remove(QStandardItemModel:invalid start, valid count 5) QSignalSpy: Unable to handle parameter 'parents' of type 'QList<QPersistentModelIndex>' of method 'layoutChanged', use qRegisterMetaType to register it.

Fix a Clang warning about potential misuse of operator ,

Task-number: QTBUG-73864
Change-Id: I60998403a44f5df8767926951ee13d1ed1e93c37
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Friedemann Kleint 2019-03-20 15:35:10 +01:00
parent e8a990c674
commit c45f2eab85
4 changed files with 12 additions and 4 deletions

View File

@ -32,10 +32,13 @@
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QStringListModel> #include <QStringListModel>
#include <QTest> #include <QTest>
#include <QLoggingCategory>
#include "dynamictreemodel.h" #include "dynamictreemodel.h"
#include "qidentityproxymodel.h" #include "qidentityproxymodel.h"
Q_LOGGING_CATEGORY(lcItemModels, "qt.corelib.tests.itemmodels")
class DataChangedModel : public QAbstractListModel class DataChangedModel : public QAbstractListModel
{ {
public: public:
@ -390,7 +393,7 @@ void dump(QAbstractItemModel* model, QString const& indent = " - ", QModelIndex
for (auto row = 0; row < model->rowCount(parent); ++row) for (auto row = 0; row < model->rowCount(parent); ++row)
{ {
auto idx = model->index(row, 0, parent); auto idx = model->index(row, 0, parent);
qDebug() << (indent + idx.data().toString()); qCDebug(lcItemModels) << (indent + idx.data().toString());
dump(model, indent + "- ", idx); dump(model, indent + "- ", idx);
} }
} }

View File

@ -125,6 +125,7 @@ private:
tst_QItemModel::tst_QItemModel() tst_QItemModel::tst_QItemModel()
{ {
qRegisterMetaType<QAbstractItemModel::LayoutChangeHint>(); qRegisterMetaType<QAbstractItemModel::LayoutChangeHint>();
qRegisterMetaType<QList<QPersistentModelIndex>>();
} }
void tst_QItemModel::init() void tst_QItemModel::init()
@ -181,7 +182,7 @@ void tst_QItemModel::nonDestructiveBasicTest()
currentModel->hasChildren(QModelIndex()); currentModel->hasChildren(QModelIndex());
currentModel->hasIndex(0, 0); currentModel->hasIndex(0, 0);
currentModel->headerData(0, Qt::Horizontal); currentModel->headerData(0, Qt::Horizontal);
currentModel->index(0,0), QModelIndex(); currentModel->index(0,0);
currentModel->itemData(QModelIndex()); currentModel->itemData(QModelIndex());
QVariant cache; QVariant cache;
currentModel->match(QModelIndex(), -1, cache); currentModel->match(QModelIndex(), -1, cache);

View File

@ -38,6 +38,8 @@
#include <qdebug.h> #include <qdebug.h>
Q_LOGGING_CATEGORY(lcItemModels, "qt.corelib.tests.itemmodels")
// Testing get/set functions // Testing get/set functions
void tst_QSortFilterProxyModel::getSetCheck() void tst_QSortFilterProxyModel::getSetCheck()
{ {
@ -4277,7 +4279,7 @@ public:
QModelIndex index(int, int, const QModelIndex& parent = QModelIndex()) const override QModelIndex index(int, int, const QModelIndex& parent = QModelIndex()) const override
{ {
// QTBUG-44962: Would we always expect the parent to belong to the model // QTBUG-44962: Would we always expect the parent to belong to the model
qDebug() << parent.model() << this; qCDebug(lcItemModels) << parent.model() << this;
Q_ASSERT(!parent.isValid() || parent.model() == this); Q_ASSERT(!parent.isValid() || parent.model() == this);
quintptr parentId = (parent.isValid()) ? parent.internalId() : 0; quintptr parentId = (parent.isValid()) ? parent.internalId() : 0;
@ -4363,7 +4365,7 @@ void tst_QSortFilterProxyModel::sourceLayoutChangeLeavesValidPersistentIndexes()
// The use of qDebug here makes sufficient use of the heap to // The use of qDebug here makes sufficient use of the heap to
// cause corruption at runtime with normal use on linux (before // cause corruption at runtime with normal use on linux (before
// the fix). valgrind confirms the fix. // the fix). valgrind confirms the fix.
qDebug() << persistentIndex.parent(); qCDebug(lcItemModels) << persistentIndex.parent();
QVERIFY(persistentIndex.parent().isValid()); QVERIFY(persistentIndex.parent().isValid());
} }

View File

@ -186,4 +186,6 @@ private:
Q_DECLARE_METATYPE(QAbstractItemModel::LayoutChangeHint) Q_DECLARE_METATYPE(QAbstractItemModel::LayoutChangeHint)
Q_DECLARE_LOGGING_CATEGORY(lcItemModels)
#endif // TST_QSORTFILTERPROXYMODEL_H #endif // TST_QSORTFILTERPROXYMODEL_H