diff options
author | Jason McDonald <jason.mcdonald@nokia.com> | 2011-05-05 01:58:24 (GMT) |
---|---|---|
committer | Jason McDonald <jason.mcdonald@nokia.com> | 2011-05-06 02:54:31 (GMT) |
commit | 11254ff409395b67cb28453b3c069860bc28c14d (patch) | |
tree | 80a875509b5a585aca04e753b633ea1ec3177475 /tests/auto/modeltest | |
parent | 841cc610df61a266ebcca2bfef2542a7d4fea68d (diff) | |
download | Qt-11254ff409395b67cb28453b3c069860bc28c14d.zip Qt-11254ff409395b67cb28453b3c069860bc28c14d.tar.gz Qt-11254ff409395b67cb28453b3c069860bc28c14d.tar.bz2 |
Remove Q_ASSERT's from modeltest
Rather than aborting in debug builds and ignoring the failures in
release builds, report specific warnings on each failure, count the
failures, and fail the test if the failure counts are non-zero at the
end of the test.
The same change is also made for a QCOMPARE that appeared
inappropriately inside a helper class. QCOMPARE may only appear
directly in a test function.
Change-Id: I81f0ce80512fa72c67f5aa72c0511a4b650d5d20
Task-number: QTBUG-17582
Reviewed-by: Rohan McGovern
Diffstat (limited to 'tests/auto/modeltest')
-rw-r--r-- | tests/auto/modeltest/tst_modeltest.cpp | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/tests/auto/modeltest/tst_modeltest.cpp b/tests/auto/modeltest/tst_modeltest.cpp index a75fe5b..aedaffe 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); } |