summaryrefslogtreecommitdiffstats
path: root/tests/auto/modeltest
diff options
context:
space:
mode:
authorJyri Tahtela <jyri.tahtela@nokia.com>2011-05-18 10:41:09 +0300
committerJyri Tahtela <jyri.tahtela@nokia.com>2011-05-18 10:41:09 +0300
commit9cacde74f7de702689725882633073e60c0a2baa (patch)
tree330d22dadbd28b14a7d8896823d1c33597e9993e /tests/auto/modeltest
parent006c8e22075112eff6230d8168d716e44a9e29d5 (diff)
parent2c07b5d2cba8d8e499bd0861eefef12d4e00d99a (diff)
Merge remote-tracking branch 'qt/4.8'
Conflicts: doc/src/examples/wheel.qdoc src/gui/util/qflickgesture.cpp src/gui/util/qflickgesture_p.h src/gui/util/qscroller.cpp src/gui/util/qscroller.h src/gui/util/qscroller_p.h src/gui/util/qscrollerproperties.cpp src/gui/util/qscrollerproperties.h tests/auto/qscroller/tst_qscroller.cpp
Diffstat (limited to 'tests/auto/modeltest')
-rw-r--r--tests/auto/modeltest/dynamictreemodel.cpp10
-rw-r--r--tests/auto/modeltest/modeltest.cpp142
-rw-r--r--tests/auto/modeltest/tst_modeltest.cpp52
3 files changed, 119 insertions, 85 deletions
diff --git a/tests/auto/modeltest/dynamictreemodel.cpp b/tests/auto/modeltest/dynamictreemodel.cpp
index 1afe09e638..2f8bb0a730 100644
--- a/tests/auto/modeltest/dynamictreemodel.cpp
+++ b/tests/auto/modeltest/dynamictreemodel.cpp
@@ -44,6 +44,7 @@
#include <QtCore/QHash>
#include <QtCore/QList>
#include <QtCore/QTimer>
+#include <QtCore/QDebug>
DynamicTreeModel::DynamicTreeModel(QObject *parent)
@@ -66,9 +67,11 @@ QModelIndex DynamicTreeModel::index(int row, int column, const QModelIndex &pare
const qint64 grandParent = findParentId(parent.internalId());
if (grandParent >= 0) {
QList<QList<qint64> > parentTable = m_childItems.value(grandParent);
- Q_ASSERT(parent.column() < parentTable.size());
+ if (parent.column() >= parentTable.size())
+ qFatal("%s: parent.column() must be less than parentTable.size()", Q_FUNC_INFO);
QList<qint64> parentSiblings = parentTable.at(parent.column());
- Q_ASSERT(parent.row() < parentSiblings.size());
+ if (parent.row() >= parentSiblings.size())
+ qFatal("%s: parent.row() must be less than parentSiblings.size()", Q_FUNC_INFO);
}
if (childIdColumns.size() == 0)
@@ -189,7 +192,8 @@ QModelIndex ModelChangeCommand::findIndex(QList<int> rows)
while (i.hasNext())
{
parent = m_model->index(i.next(), col, parent);
- Q_ASSERT(parent.isValid());
+ if (!parent.isValid())
+ qFatal("%s: parent must be valid", Q_FUNC_INFO);
}
return parent;
}
diff --git a/tests/auto/modeltest/modeltest.cpp b/tests/auto/modeltest/modeltest.cpp
index e1e4094f44..e30d1f6644 100644
--- a/tests/auto/modeltest/modeltest.cpp
+++ b/tests/auto/modeltest/modeltest.cpp
@@ -45,8 +45,6 @@
#include "modeltest.h"
#include <QtTest/QtTest>
-#undef Q_ASSERT
-#define Q_ASSERT QVERIFY
Q_DECLARE_METATYPE ( QModelIndex )
@@ -55,7 +53,8 @@ Q_DECLARE_METATYPE ( QModelIndex )
*/
ModelTest::ModelTest ( QAbstractItemModel *_model, QObject *parent ) : QObject ( parent ), model ( _model ), fetchingMore ( false )
{
- Q_ASSERT ( model );
+ if (!model)
+ qFatal("%s: model must not be null", Q_FUNC_INFO);
connect ( model, SIGNAL ( columnsAboutToBeInserted ( const QModelIndex &, int, int ) ),
this, SLOT ( runAllTests() ) );
@@ -118,15 +117,15 @@ void ModelTest::runAllTests()
*/
void ModelTest::nonDestructiveBasicTest()
{
- Q_ASSERT ( model->buddy ( QModelIndex() ) == QModelIndex() );
+ QVERIFY( model->buddy ( QModelIndex() ) == QModelIndex() );
model->canFetchMore ( QModelIndex() );
- Q_ASSERT ( model->columnCount ( QModelIndex() ) >= 0 );
- Q_ASSERT ( model->data ( QModelIndex() ) == QVariant() );
+ QVERIFY( model->columnCount ( QModelIndex() ) >= 0 );
+ QVERIFY( model->data ( QModelIndex() ) == QVariant() );
fetchingMore = true;
model->fetchMore ( QModelIndex() );
fetchingMore = false;
Qt::ItemFlags flags = model->flags ( QModelIndex() );
- Q_ASSERT ( flags == Qt::ItemIsDropEnabled || flags == 0 );
+ QVERIFY( flags == Qt::ItemIsDropEnabled || flags == 0 );
model->hasChildren ( QModelIndex() );
model->hasIndex ( 0, 0 );
model->headerData ( 0, Qt::Horizontal );
@@ -135,8 +134,8 @@ void ModelTest::nonDestructiveBasicTest()
QVariant cache;
model->match ( QModelIndex(), -1, cache );
model->mimeTypes();
- Q_ASSERT ( model->parent ( QModelIndex() ) == QModelIndex() );
- Q_ASSERT ( model->rowCount() >= 0 );
+ QVERIFY( model->parent ( QModelIndex() ) == QModelIndex() );
+ QVERIFY( model->rowCount() >= 0 );
QVariant variant;
model->setData ( QModelIndex(), variant, -1 );
model->setHeaderData ( -1, Qt::Horizontal, QVariant() );
@@ -158,17 +157,17 @@ void ModelTest::rowCount()
// check top row
QModelIndex topIndex = model->index ( 0, 0, QModelIndex() );
int rows = model->rowCount ( topIndex );
- Q_ASSERT ( rows >= 0 );
+ QVERIFY( rows >= 0 );
if ( rows > 0 )
- Q_ASSERT ( model->hasChildren ( topIndex ) == true );
+ QVERIFY( model->hasChildren ( topIndex ) );
QModelIndex secondLevelIndex = model->index ( 0, 0, topIndex );
if ( secondLevelIndex.isValid() ) { // not the top level
// check a row count where parent is valid
rows = model->rowCount ( secondLevelIndex );
- Q_ASSERT ( rows >= 0 );
+ QVERIFY( rows >= 0 );
if ( rows > 0 )
- Q_ASSERT ( model->hasChildren ( secondLevelIndex ) == true );
+ QVERIFY( model->hasChildren ( secondLevelIndex ) );
}
// The models rowCount() is tested more extensively in checkChildren(),
@@ -182,12 +181,12 @@ void ModelTest::columnCount()
{
// check top row
QModelIndex topIndex = model->index ( 0, 0, QModelIndex() );
- Q_ASSERT ( model->columnCount ( topIndex ) >= 0 );
+ QVERIFY( model->columnCount ( topIndex ) >= 0 );
// check a column count where parent is valid
QModelIndex childIndex = model->index ( 0, 0, topIndex );
if ( childIndex.isValid() )
- Q_ASSERT ( model->columnCount ( childIndex ) >= 0 );
+ QVERIFY( model->columnCount ( childIndex ) >= 0 );
// columnCount() is tested more extensively in checkChildren(),
// but this catches the big mistakes
@@ -200,19 +199,19 @@ void ModelTest::hasIndex()
{
// qDebug() << "hi";
// Make sure that invalid values returns an invalid index
- Q_ASSERT ( model->hasIndex ( -2, -2 ) == false );
- Q_ASSERT ( model->hasIndex ( -2, 0 ) == false );
- Q_ASSERT ( model->hasIndex ( 0, -2 ) == false );
+ QVERIFY( !model->hasIndex ( -2, -2 ) );
+ QVERIFY( !model->hasIndex ( -2, 0 ) );
+ QVERIFY( !model->hasIndex ( 0, -2 ) );
int rows = model->rowCount();
int columns = model->columnCount();
// check out of bounds
- Q_ASSERT ( model->hasIndex ( rows, columns ) == false );
- Q_ASSERT ( model->hasIndex ( rows + 1, columns + 1 ) == false );
+ QVERIFY( !model->hasIndex ( rows, columns ) );
+ QVERIFY( !model->hasIndex ( rows + 1, columns + 1 ) );
if ( rows > 0 )
- Q_ASSERT ( model->hasIndex ( 0, 0 ) == true );
+ QVERIFY( model->hasIndex ( 0, 0 ) );
// hasIndex() is tested more extensively in checkChildren(),
// but this catches the big mistakes
@@ -225,9 +224,9 @@ void ModelTest::index()
{
// qDebug() << "i";
// Make sure that invalid values returns an invalid index
- Q_ASSERT ( model->index ( -2, -2 ) == QModelIndex() );
- Q_ASSERT ( model->index ( -2, 0 ) == QModelIndex() );
- Q_ASSERT ( model->index ( 0, -2 ) == QModelIndex() );
+ QVERIFY( model->index ( -2, -2 ) == QModelIndex() );
+ QVERIFY( model->index ( -2, 0 ) == QModelIndex() );
+ QVERIFY( model->index ( 0, -2 ) == QModelIndex() );
int rows = model->rowCount();
int columns = model->columnCount();
@@ -236,13 +235,13 @@ void ModelTest::index()
return;
// Catch off by one errors
- Q_ASSERT ( model->index ( rows, columns ) == QModelIndex() );
- Q_ASSERT ( model->index ( 0, 0 ).isValid() == true );
+ QVERIFY( model->index ( rows, columns ) == QModelIndex() );
+ QVERIFY( model->index ( 0, 0 ).isValid() );
// Make sure that the same index is *always* returned
QModelIndex a = model->index ( 0, 0 );
QModelIndex b = model->index ( 0, 0 );
- Q_ASSERT ( a == b );
+ QVERIFY( a == b );
// index() is tested more extensively in checkChildren(),
// but this catches the big mistakes
@@ -256,7 +255,7 @@ void ModelTest::parent()
// qDebug() << "p";
// Make sure the model wont crash and will return an invalid QModelIndex
// when asked for the parent of an invalid index.
- Q_ASSERT ( model->parent ( QModelIndex() ) == QModelIndex() );
+ QVERIFY( model->parent ( QModelIndex() ) == QModelIndex() );
if ( model->rowCount() == 0 )
return;
@@ -269,13 +268,13 @@ void ModelTest::parent()
// Common error test #1, make sure that a top level index has a parent
// that is a invalid QModelIndex.
QModelIndex topIndex = model->index ( 0, 0, QModelIndex() );
- Q_ASSERT ( model->parent ( topIndex ) == QModelIndex() );
+ QVERIFY( model->parent ( topIndex ) == QModelIndex() );
// Common error test #2, make sure that a second level index has a parent
// that is the first level index.
if ( model->rowCount ( topIndex ) > 0 ) {
QModelIndex childIndex = model->index ( 0, 0, topIndex );
- Q_ASSERT ( model->parent ( childIndex ) == topIndex );
+ QVERIFY( model->parent ( childIndex ) == topIndex );
}
// Common error test #3, the second column should NOT have the same children
@@ -285,7 +284,7 @@ void ModelTest::parent()
if ( model->rowCount ( topIndex1 ) > 0 ) {
QModelIndex childIndex = model->index ( 0, 0, topIndex );
QModelIndex childIndex1 = model->index ( 0, 0, topIndex1 );
- Q_ASSERT ( childIndex != childIndex1 );
+ QVERIFY( childIndex != childIndex1 );
}
// Full test, walk n levels deep through the model making sure that all
@@ -325,47 +324,47 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth )
int columns = model->columnCount ( parent );
if ( rows > 0 )
- Q_ASSERT ( model->hasChildren ( parent ) );
+ QVERIFY( model->hasChildren ( parent ) );
// Some further testing against rows(), columns(), and hasChildren()
- Q_ASSERT ( rows >= 0 );
- Q_ASSERT ( columns >= 0 );
+ QVERIFY( rows >= 0 );
+ QVERIFY( columns >= 0 );
if ( rows > 0 )
- Q_ASSERT ( model->hasChildren ( parent ) == true );
+ QVERIFY( model->hasChildren ( parent ) );
//qDebug() << "parent:" << model->data(parent).toString() << "rows:" << rows
// << "columns:" << columns << "parent column:" << parent.column();
- Q_ASSERT ( model->hasIndex ( rows + 1, 0, parent ) == false );
+ QVERIFY( !model->hasIndex ( rows + 1, 0, parent ) );
for ( int r = 0; r < rows; ++r ) {
if ( model->canFetchMore ( parent ) ) {
fetchingMore = true;
model->fetchMore ( parent );
fetchingMore = false;
}
- Q_ASSERT ( model->hasIndex ( r, columns + 1, parent ) == false );
+ QVERIFY( !model->hasIndex ( r, columns + 1, parent ) );
for ( int c = 0; c < columns; ++c ) {
- Q_ASSERT ( model->hasIndex ( r, c, parent ) == true );
+ QVERIFY( model->hasIndex ( r, c, parent ) );
QModelIndex index = model->index ( r, c, parent );
// rowCount() and columnCount() said that it existed...
- Q_ASSERT ( index.isValid() == true );
+ QVERIFY( index.isValid() );
// index() should always return the same index when called twice in a row
QModelIndex modifiedIndex = model->index ( r, c, parent );
- Q_ASSERT ( index == modifiedIndex );
+ QVERIFY( index == modifiedIndex );
// Make sure we get the same index if we request it twice in a row
QModelIndex a = model->index ( r, c, parent );
QModelIndex b = model->index ( r, c, parent );
- Q_ASSERT ( a == b );
+ QVERIFY( a == b );
// Some basic checking on the index that is returned
- Q_ASSERT ( index.model() == model );
- Q_ASSERT ( index.row() == r );
- Q_ASSERT ( index.column() == c );
+ QVERIFY( index.model() == model );
+ QCOMPARE( index.row(), r );
+ QCOMPARE( index.column(), c );
// While you can technically return a QVariant usually this is a sign
- // of an bug in data() Disable if this really is ok in your model.
-// Q_ASSERT ( model->data ( index, Qt::DisplayRole ).isValid() == true );
+ // of a bug in data(). Disable if this really is ok in your model.
+// QVERIFY( model->data ( index, Qt::DisplayRole ).isValid() );
// If the next test fails here is some somewhat useful debug you play with.
@@ -380,8 +379,7 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth )
}
// Check that we can get back our real parent.
-// qDebug() << model->parent ( index ) << parent ;
- Q_ASSERT ( model->parent ( index ) == parent );
+ QCOMPARE( model->parent ( index ), parent );
// recursively go down the children
if ( model->hasChildren ( index ) && currentDepth < 10 ) {
@@ -391,7 +389,7 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth )
// make sure that after testing the children that the index doesn't change.
QModelIndex newerIndex = model->index ( r, c, parent );
- Q_ASSERT ( index == newerIndex );
+ QVERIFY( index == newerIndex );
}
}
}
@@ -402,68 +400,68 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth )
void ModelTest::data()
{
// Invalid index should return an invalid qvariant
- Q_ASSERT ( !model->data ( QModelIndex() ).isValid() );
+ QVERIFY( !model->data ( QModelIndex() ).isValid() );
if ( model->rowCount() == 0 )
return;
// A valid index should have a valid QVariant data
- Q_ASSERT ( model->index ( 0, 0 ).isValid() );
+ QVERIFY( model->index ( 0, 0 ).isValid() );
// shouldn't be able to set data on an invalid index
- Q_ASSERT ( model->setData ( QModelIndex(), QLatin1String ( "foo" ), Qt::DisplayRole ) == false );
+ QVERIFY( !model->setData ( QModelIndex(), QLatin1String ( "foo" ), Qt::DisplayRole ) );
// General Purpose roles that should return a QString
QVariant variant = model->data ( model->index ( 0, 0 ), Qt::ToolTipRole );
if ( variant.isValid() ) {
- Q_ASSERT ( qVariantCanConvert<QString> ( variant ) );
+ QVERIFY( qVariantCanConvert<QString> ( variant ) );
}
variant = model->data ( model->index ( 0, 0 ), Qt::StatusTipRole );
if ( variant.isValid() ) {
- Q_ASSERT ( qVariantCanConvert<QString> ( variant ) );
+ QVERIFY( qVariantCanConvert<QString> ( variant ) );
}
variant = model->data ( model->index ( 0, 0 ), Qt::WhatsThisRole );
if ( variant.isValid() ) {
- Q_ASSERT ( qVariantCanConvert<QString> ( variant ) );
+ QVERIFY( qVariantCanConvert<QString> ( variant ) );
}
// General Purpose roles that should return a QSize
variant = model->data ( model->index ( 0, 0 ), Qt::SizeHintRole );
if ( variant.isValid() ) {
- Q_ASSERT ( qVariantCanConvert<QSize> ( variant ) );
+ QVERIFY( qVariantCanConvert<QSize> ( variant ) );
}
// General Purpose roles that should return a QFont
QVariant fontVariant = model->data ( model->index ( 0, 0 ), Qt::FontRole );
if ( fontVariant.isValid() ) {
- Q_ASSERT ( qVariantCanConvert<QFont> ( fontVariant ) );
+ QVERIFY( qVariantCanConvert<QFont> ( fontVariant ) );
}
// Check that the alignment is one we know about
QVariant textAlignmentVariant = model->data ( model->index ( 0, 0 ), Qt::TextAlignmentRole );
if ( textAlignmentVariant.isValid() ) {
int alignment = textAlignmentVariant.toInt();
- Q_ASSERT ( alignment == ( alignment & ( Qt::AlignHorizontal_Mask | Qt::AlignVertical_Mask ) ) );
+ QCOMPARE( alignment, ( alignment & ( Qt::AlignHorizontal_Mask | Qt::AlignVertical_Mask ) ) );
}
// General Purpose roles that should return a QColor
QVariant colorVariant = model->data ( model->index ( 0, 0 ), Qt::BackgroundColorRole );
if ( colorVariant.isValid() ) {
- Q_ASSERT ( qVariantCanConvert<QColor> ( colorVariant ) );
+ QVERIFY( qVariantCanConvert<QColor> ( colorVariant ) );
}
colorVariant = model->data ( model->index ( 0, 0 ), Qt::TextColorRole );
if ( colorVariant.isValid() ) {
- Q_ASSERT ( qVariantCanConvert<QColor> ( colorVariant ) );
+ QVERIFY( qVariantCanConvert<QColor> ( colorVariant ) );
}
// Check that the "check state" is one we know about.
QVariant checkStateVariant = model->data ( model->index ( 0, 0 ), Qt::CheckStateRole );
if ( checkStateVariant.isValid() ) {
int state = checkStateVariant.toInt();
- Q_ASSERT ( state == Qt::Unchecked ||
- state == Qt::PartiallyChecked ||
- state == Qt::Checked );
+ QVERIFY( state == Qt::Unchecked ||
+ state == Qt::PartiallyChecked ||
+ state == Qt::Checked );
}
}
@@ -494,7 +492,7 @@ void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int start, in
void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end )
{
Changing c = insert.pop();
- Q_ASSERT ( c.parent == parent );
+ QVERIFY( c.parent == parent );
// qDebug() << "rowsInserted" << "start=" << start << "end=" << end << "oldsize=" << c.oldSize
// << "parent=" << model->data ( parent ).toString() << "current rowcount of parent=" << model->rowCount ( parent );
@@ -504,8 +502,8 @@ void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end )
// }
// qDebug();
- Q_ASSERT ( c.oldSize + ( end - start + 1 ) == model->rowCount ( parent ) );
- Q_ASSERT ( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) );
+ QVERIFY( c.oldSize + ( end - start + 1 ) == model->rowCount ( parent ) );
+ QVERIFY( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) );
if (c.next != model->data(model->index(end + 1, 0, c.parent))) {
qDebug() << start << end;
@@ -514,7 +512,7 @@ void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end )
qDebug() << c.next << model->data(model->index(end + 1, 0, c.parent));
}
- Q_ASSERT ( c.next == model->data ( model->index ( end + 1, 0, c.parent ) ) );
+ QVERIFY( c.next == model->data ( model->index ( end + 1, 0, c.parent ) ) );
}
void ModelTest::layoutAboutToBeChanged()
@@ -527,7 +525,7 @@ void ModelTest::layoutChanged()
{
for ( int i = 0; i < changing.count(); ++i ) {
QPersistentModelIndex p = changing[i];
- Q_ASSERT ( p == model->index ( p.row(), p.column(), p.parent() ) );
+ QVERIFY( p == model->index ( p.row(), p.column(), p.parent() ) );
}
changing.clear();
}
@@ -557,10 +555,10 @@ void ModelTest::rowsRemoved ( const QModelIndex & parent, int start, int end )
{
qDebug() << "rr" << parent << start << end;
Changing c = remove.pop();
- Q_ASSERT ( c.parent == parent );
- Q_ASSERT ( c.oldSize - ( end - start + 1 ) == model->rowCount ( parent ) );
- Q_ASSERT ( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) );
- Q_ASSERT ( c.next == model->data ( model->index ( start, 0, c.parent ) ) );
+ QVERIFY( c.parent == parent );
+ QVERIFY( c.oldSize - ( end - start + 1 ) == model->rowCount ( parent ) );
+ QVERIFY( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) );
+ QVERIFY( c.next == model->data ( model->index ( start, 0, c.parent ) ) );
}
diff --git a/tests/auto/modeltest/tst_modeltest.cpp b/tests/auto/modeltest/tst_modeltest.cpp
index cfaf210523..aba0894c30 100644
--- a/tests/auto/modeltest/tst_modeltest.cpp
+++ b/tests/auto/modeltest/tst_modeltest.cpp
@@ -201,8 +201,10 @@ class ObservingObject : public QObject
Q_OBJECT
public:
ObservingObject(AccessibleProxyModel *proxy, QObject *parent = 0)
- : QObject(parent),
- m_proxy(proxy)
+ : QObject(parent)
+ , m_proxy(proxy)
+ , storePersistentFailureCount(0)
+ , checkPersistentFailureCount(0)
{
connect(m_proxy, SIGNAL(layoutAboutToBeChanged()), SLOT(storePersistent()));
connect(m_proxy, SIGNAL(layoutChanged()), SLOT(checkPersistent()));
@@ -215,8 +217,14 @@ public slots:
for (int row = 0; row < m_proxy->rowCount(parent); ++row) {
QModelIndex proxyIndex = m_proxy->index(row, 0, parent);
QModelIndex sourceIndex = m_proxy->mapToSource(proxyIndex);
- Q_ASSERT(proxyIndex.isValid());
- Q_ASSERT(sourceIndex.isValid());
+ if (!proxyIndex.isValid()) {
+ qWarning("%s: Invalid proxy index", Q_FUNC_INFO);
+ ++storePersistentFailureCount;
+ }
+ if (!sourceIndex.isValid()) {
+ qWarning("%s: invalid source index", Q_FUNC_INFO);
+ ++storePersistentFailureCount;
+ }
m_persistentSourceIndexes.append(sourceIndex);
m_persistentProxyIndexes.append(proxyIndex);
if (m_proxy->hasChildren(proxyIndex))
@@ -226,12 +234,24 @@ public slots:
void storePersistent()
{
- foreach(const QModelIndex &idx, m_persistentProxyIndexes)
- Q_ASSERT(idx.isValid()); // This is called from layoutAboutToBeChanged. Persistent indexes should be valid
-
- Q_ASSERT(m_proxy->persistent().isEmpty());
+ // This method is called from layoutAboutToBeChanged. Persistent indexes should be valid
+ foreach(const QModelIndex &idx, m_persistentProxyIndexes)
+ if (!idx.isValid()) {
+ qWarning("%s: persistentProxyIndexes contains invalid index", Q_FUNC_INFO);
+ ++storePersistentFailureCount;
+ }
+
+ if (!m_proxy->persistent().isEmpty()) {
+ qWarning("%s: proxy should have no persistent indexes when storePersistent called",
+ Q_FUNC_INFO);
+ ++storePersistentFailureCount;
+ }
storePersistent(QModelIndex());
- Q_ASSERT(!m_proxy->persistent().isEmpty());
+ if (m_proxy->persistent().isEmpty()) {
+ qWarning("%s: proxy should have persistent index after storePersistent called",
+ Q_FUNC_INFO);
+ ++storePersistentFailureCount;
+ }
}
void checkPersistent()
@@ -243,7 +263,10 @@ public slots:
for (int row = 0; row < m_persistentProxyIndexes.size(); ++row) {
QModelIndex updatedProxy = m_persistentProxyIndexes.at(row);
QModelIndex updatedSource = m_persistentSourceIndexes.at(row);
- QCOMPARE(m_proxy->mapToSource(updatedProxy), updatedSource);
+ if (m_proxy->mapToSource(updatedProxy) != updatedSource) {
+ qWarning("%s: check failed at row %d", Q_FUNC_INFO, row);
+ ++checkPersistentFailureCount;
+ }
}
m_persistentSourceIndexes.clear();
m_persistentProxyIndexes.clear();
@@ -253,6 +276,9 @@ private:
AccessibleProxyModel *m_proxy;
QList<QPersistentModelIndex> m_persistentSourceIndexes;
QList<QPersistentModelIndex> m_persistentProxyIndexes;
+public:
+ int storePersistentFailureCount;
+ int checkPersistentFailureCount;
};
void tst_ModelTest::moveSourceItems()
@@ -280,6 +306,9 @@ void tst_ModelTest::moveSourceItems()
moveCommand->setDestAncestors(QList<int>() << 1);
moveCommand->setDestRow(0);
moveCommand->doCommand();
+
+ QCOMPARE(observer.storePersistentFailureCount, 0);
+ QCOMPARE(observer.checkPersistentFailureCount, 0);
}
void tst_ModelTest::testResetThroughProxy()
@@ -302,6 +331,9 @@ void tst_ModelTest::testResetThroughProxy()
ModelResetCommand *resetCommand = new ModelResetCommand(model, this);
resetCommand->setNumCols(0);
resetCommand->doCommand();
+
+ QCOMPARE(observer.storePersistentFailureCount, 0);
+ QCOMPARE(observer.checkPersistentFailureCount, 0);
}