From: Jason McDonald Date: Thu, 5 May 2011 01:58:24 +0000 (+1000) Subject: Remove Q_ASSERT's from modeltest X-Git-Tag: qt-v5.0.0-alpha1~4297^2~23 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=97e0db61c788a59bff48e33800802d4c4a0b0e70;p=profile%2Fivi%2Fqtbase.git 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 (cherry picked from commit 11254ff409395b67cb28453b3c069860bc28c14d) --- 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 m_persistentSourceIndexes; QList m_persistentProxyIndexes; +public: + int storePersistentFailureCount; + int checkPersistentFailureCount; }; void tst_ModelTest::moveSourceItems() @@ -280,6 +306,9 @@ void tst_ModelTest::moveSourceItems() moveCommand->setDestAncestors(QList() << 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); }