From e6f7509f18ae88069373d59073cbdcda88fd19c8 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 6 May 2011 13:12:10 +1000 Subject: Remove Q_ASSERT's from qabstractfileengine test Rather than aborting in debug builds and failing silently in release builds, report a meaningful warning message and skip setting the filename, which should cause a subsequent test failure. Change-Id: I3ae4f4de7b02bf2194019047fa87d8ae06d95634 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qabstractfileengine/tst_qabstractfileengine.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/auto/qabstractfileengine/tst_qabstractfileengine.cpp b/tests/auto/qabstractfileengine/tst_qabstractfileengine.cpp index fc4835a..e77b7bb 100644 --- a/tests/auto/qabstractfileengine/tst_qabstractfileengine.cpp +++ b/tests/auto/qabstractfileengine/tst_qabstractfileengine.cpp @@ -360,10 +360,10 @@ public: void setFileName(const QString &file) { - Q_ASSERT(!openForRead_); - Q_ASSERT(!openForWrite_); - - fileName_ = file; + if (openForRead_ || openForWrite_) + qWarning("%s: Can't set file name while file is open", Q_FUNC_INFO); + else + fileName_ = file; } // typedef QAbstractFileEngineIterator Iterator; -- cgit v0.12 From 57fd8c5ac803398238982c4b74bc5ce048671201 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 6 May 2011 13:35:14 +1000 Subject: Remove Q_ASSERT from qabstractxmlnodemodel test Constructing a model index from a null pointer will cause the test to crash later. Instead of crashing this way in a release build and aborting in a debug build, report the fatal error in all builds. Change-Id: I43ce4c8fa48caa05aaf09ac3c1453d35a2de65bf Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qabstractxmlnodemodel/LoadingModel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp b/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp index cf85486..63fad67 100644 --- a/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp +++ b/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp @@ -77,8 +77,8 @@ const LoadingModel::Node *LoadingModel::toInternal(const QXmlNodeModelIndex &ni) QXmlNodeModelIndex LoadingModel::createIndex(const Node *const internal) const { - Q_ASSERT_X(internal, Q_FUNC_INFO, - "We shouldn't construct from null pointers."); + if (!internal) + qFatal("%s: cannot construct a model index from a null pointer", Q_FUNC_INFO); return QAbstractXmlNodeModel::createIndex(const_cast(internal)); } -- cgit v0.12 From 68027b186fe547a5579d07480e097bfb69c79de9 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 6 May 2011 13:51:20 +1000 Subject: Remove Q_ASSERT from qabstractxmlnodemodel test Instead of aborting in a debug build and failing silently in a release build when the internal state of the model is incorrect, report a meaningful fatal error in all builds. Change-Id: I64ca4dde070cb7fbe69684a36092d53e5b84d80a Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qabstractxmlnodemodel/LoadingModel.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp b/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp index 63fad67..c68857b 100644 --- a/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp +++ b/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp @@ -98,8 +98,10 @@ QXmlNodeModelIndex::DocumentOrder LoadingModel::compareOrder(const QXmlNodeModel { const Node *const in1 = toInternal(n1); const Node *const in2 = toInternal(n2); - Q_ASSERT(m_nodes.indexOf(in1) != -1); - Q_ASSERT(m_nodes.indexOf(in2) != -1); + if (m_nodes.indexOf(in1) == -1) + qFatal("%s: node n1 is not in internal node list", Q_FUNC_INFO); + if (m_nodes.indexOf(in2) == -1) + qFatal("%s: node n2 is not in internal node list", Q_FUNC_INFO); if(in1 == in2) return QXmlNodeModelIndex::Is; -- cgit v0.12 From a80ecc34565d6efc474bca2322046f4200ad51db Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 6 May 2011 14:00:00 +1000 Subject: Remove Q_ASSERT from qabstractxmlnodemodel test Rather than aborting in a debug build and failing silently in a release build, report a warning and return a null model index if the first (root) node of the model is not a document. The null return value will cause initTestCase() to fail gracefully. Change-Id: I15e9456929bbb3f0bd50d30333c49143b6f0aad7 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qabstractxmlnodemodel/LoadingModel.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp b/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp index c68857b..01d3164 100644 --- a/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp +++ b/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp @@ -113,7 +113,10 @@ QXmlNodeModelIndex::DocumentOrder LoadingModel::compareOrder(const QXmlNodeModel QXmlNodeModelIndex LoadingModel::root(const QXmlNodeModelIndex &) const { - Q_ASSERT(kind(createIndex(m_nodes.first())) == QXmlNodeModelIndex::Document); + if (kind(createIndex(m_nodes.first())) != QXmlNodeModelIndex::Document) { + qWarning("%s: first node must be a Document node", Q_FUNC_INFO); + return QXmlNodeModelIndex(); + } return createIndex(m_nodes.first()); } -- cgit v0.12 From a0496d1db09dfaa6a2b31a5c23e154de7b4a2eb7 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 6 May 2011 14:08:10 +1000 Subject: Remove Q_ASSERT from qabstractxmlnodemodel test Instead of aborting in debug builds and failing silently in release builds, print a meaningful warning message into the test output and return a null QVariant. Change-Id: Idcd70f5cb01528b522d84e391f6f8692a189f420 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qabstractxmlnodemodel/LoadingModel.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp b/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp index 01d3164..2ce9466 100644 --- a/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp +++ b/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp @@ -129,8 +129,11 @@ QVariant LoadingModel::typedValue(const QXmlNodeModelIndex &ni) const { const Node *const internal = toInternal(ni); - Q_ASSERT(internal->kind == QXmlNodeModelIndex::Attribute - || internal->kind == QXmlNodeModelIndex::Element); + if (internal->kind != QXmlNodeModelIndex::Attribute + && internal->kind != QXmlNodeModelIndex::Element) { + qWarning("%s: node must be an attribute or element", Q_FUNC_INFO); + return QVariant(); + } return internal->value; } -- cgit v0.12 From 75767c69fbba3149a4505287ed441886188a9fd3 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 6 May 2011 14:43:03 +1000 Subject: Remove Q_ASSERT from algorithms autotest Report a meaningful warning message rather than aborting in a debug build and failing silently in a release build. Change-Id: Ic77589143ff0d22c95c7b10f2e511f68b3da4d86 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qalgorithms/tst_qalgorithms.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/auto/qalgorithms/tst_qalgorithms.cpp b/tests/auto/qalgorithms/tst_qalgorithms.cpp index 8dd7cbc..f0ae08c 100644 --- a/tests/auto/qalgorithms/tst_qalgorithms.cpp +++ b/tests/auto/qalgorithms/tst_qalgorithms.cpp @@ -241,7 +241,8 @@ QList testAlgorithm(Algorithm &algorithm, QStringList dataSetTypes, foreach(QString dataSetType, dataSetTypes) { QVector container = generateData(dataSetType, size); results.append(testRun(container, algorithm, time)); - Q_ASSERT(isSorted(container)); + if (!isSorted(container)) + qWarning("%s: container is not sorted after test", Q_FUNC_INFO); } return results; } -- cgit v0.12 From 6b2e89843a573cd7c143bca17cec8e69209d2fbd Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 6 May 2011 15:22:07 +1000 Subject: Remove Q_ASSERT from qitemmodel autotest If populateTestData() is passed an unknown type of model, report a meaningful fatal error rather than failing silently in a release build and aborting with an uninformative error message in a debug build. Change-Id: I7ee8d1262bbced304f9f24c2ec9b40a38704d982 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qitemmodel/modelstotest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/qitemmodel/modelstotest.cpp b/tests/auto/qitemmodel/modelstotest.cpp index cec1703..4e63307 100644 --- a/tests/auto/qitemmodel/modelstotest.cpp +++ b/tests/auto/qitemmodel/modelstotest.cpp @@ -372,7 +372,7 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model) return QModelIndex(); } - Q_ASSERT(false); + qFatal("%s: unknown type of model", Q_FUNC_INFO); return QModelIndex(); } -- cgit v0.12 From 7cb0a3baeb361c9909e8ab2caf436e8e44b6a3b6 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 6 May 2011 16:22:25 +1000 Subject: Remove Q_ASSERT's in qitemview autotest Rather than aborting in debug builds and failing silently in release builds, report a meaningful warning message and return an appropriate value to indicate the error. Change-Id: I0ceb0a0bfaef34cc6127d768cc75ecfc5a24e3c9 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qitemview/tst_qitemview.cpp | 65 +++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/tests/auto/qitemview/tst_qitemview.cpp b/tests/auto/qitemview/tst_qitemview.cpp index c987c8f..fa8367e 100644 --- a/tests/auto/qitemview/tst_qitemview.cpp +++ b/tests/auto/qitemview/tst_qitemview.cpp @@ -148,12 +148,18 @@ public: CheckerModel() : QStandardItemModel() {}; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole ) const { - Q_ASSERT(index.isValid()); + if (!index.isValid()) { + qWarning("%s: index is not valid", Q_FUNC_INFO); + return QVariant(); + } return QStandardItemModel::data(index, role); }; Qt::ItemFlags flags(const QModelIndex & index) const { - Q_ASSERT(index.isValid()); + if (!index.isValid()) { + qWarning("%s: index is not valid", Q_FUNC_INFO); + return Qt::ItemFlags(); + } if (index.row() == 2 || index.row() == rowCount() - 3 || index.column() == 2 || index.column() == columnCount() - 3) { Qt::ItemFlags f = QStandardItemModel::flags(index); @@ -164,14 +170,26 @@ public: }; QModelIndex parent ( const QModelIndex & child ) const { - Q_ASSERT(child.isValid()); + if (!child.isValid()) { + qWarning("%s: child index is not valid", Q_FUNC_INFO); + return QModelIndex(); + } return QStandardItemModel::parent(child); }; QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const { - Q_ASSERT(section >= 0); - if (orientation == Qt::Horizontal) { Q_ASSERT(section <= columnCount());}; - if (orientation == Qt::Vertical) { Q_ASSERT(section <= rowCount());}; + if (orientation == Qt::Horizontal + && (section < 0 || section > columnCount())) { + qWarning("%s: invalid section %d, must be in range 0..%d", + Q_FUNC_INFO, section, columnCount()); + return QVariant(); + } + if (orientation == Qt::Vertical + && (section < 0 || section > rowCount())) { + qWarning("%s: invalid section %d, must be in range 0..%d", + Q_FUNC_INFO, section, rowCount()); + return QVariant(); + } return QStandardItemModel::headerData(section, orientation, role); } @@ -180,23 +198,46 @@ public: }; bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ) { - Q_ASSERT(index.isValid()); + if (!index.isValid()) { + qWarning("%s: index is not valid", Q_FUNC_INFO); + return false; + } return QStandardItemModel::setData(index, value, role); } void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) { - Q_ASSERT(column >= 0 && column <= columnCount()); - QStandardItemModel::sort(column, order); + if (column < 0 || column > columnCount()) + qWarning("%s: invalid column %d, must be in range 0..%d", + Q_FUNC_INFO, column, columnCount()); + else + QStandardItemModel::sort(column, order); }; QModelIndexList match ( const QModelIndex & start, int role, const QVariant & value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags( Qt::MatchStartsWith | Qt::MatchWrap ) ) const { - Q_ASSERT(hits > 0); - Q_ASSERT(value.isValid()); + if (hits <= 0) { + qWarning("%s: hits must be greater than zero", Q_FUNC_INFO); + return QModelIndexList(); + } + if (!value.isValid()) { + qWarning("%s: value is not valid", Q_FUNC_INFO); + return QModelIndexList(); + } return QAbstractItemModel::match(start, role, value, hits, flags); }; bool setHeaderData ( int section, Qt::Orientation orientation, const QVariant & value, int role = Qt::EditRole ) { - Q_ASSERT(section >= 0); + if (orientation == Qt::Horizontal + && (section < 0 || section > columnCount())) { + qWarning("%s: invalid section %d, must be in range 0..%d", + Q_FUNC_INFO, section, columnCount()); + return false; + } + if (orientation == Qt::Vertical + && (section < 0 || section > rowCount())) { + qWarning("%s: invalid section %d, must be in range 0..%d", + Q_FUNC_INFO, section, rowCount()); + return false; + } return QAbstractItemModel::setHeaderData(section, orientation, value, role); }; }; -- cgit v0.12 From 8512dc16553ecf511c40a2ba7a815f777d7d5c59 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 6 May 2011 16:34:15 +1000 Subject: Remove Q_ASSERT from QMetaType autotest Replace Q_ASSERT in helper class with code to count failures and report meaningful warnings. The test function then fails the test if any failures were recorded. Change-Id: I0d6650e6036c8e45729c16d1dbb7543b4fb42553 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qmetatype/tst_qmetatype.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/auto/qmetatype/tst_qmetatype.cpp b/tests/auto/qmetatype/tst_qmetatype.cpp index fcb949f..ccf0ac5 100644 --- a/tests/auto/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/qmetatype/tst_qmetatype.cpp @@ -96,10 +96,18 @@ struct Bar Bar() { // check re-entrancy - Q_ASSERT(QMetaType::isRegistered(qRegisterMetaType("Foo"))); + if (!QMetaType::isRegistered(qRegisterMetaType("Foo"))) { + qWarning("%s: re-entrancy test failed", Q_FUNC_INFO); + ++failureCount; + } } + +public: + static int failureCount; }; +int Bar::failureCount = 0; + class MetaTypeTorturer: public QThread { Q_OBJECT @@ -161,6 +169,7 @@ void tst_QMetaType::threadSafety() QCOMPARE(t1.failureCount, 0); QCOMPARE(t2.failureCount, 0); QCOMPARE(t3.failureCount, 0); + QCOMPARE(Bar::failureCount, 0); } namespace TestSpace -- cgit v0.12 From 8d2127d44e6c8af6b041688376de0e5747a1810a Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 6 May 2011 16:55:31 +1000 Subject: Remove Q_ASSERT's from QMutex autotest Don't perform actions needed for the test inside Q_ASSERT, because these actions won't happen in a non-debug build. Instead count the number of failures and verify that the count is zero at the end of the test. Change-Id: Ibe0d194111e5247118d59a7760f0946d2c44faf9 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qmutex/tst_qmutex.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/auto/qmutex/tst_qmutex.cpp b/tests/auto/qmutex/tst_qmutex.cpp index dc3ffa4..e1ad2d2 100644 --- a/tests/auto/qmutex/tst_qmutex.cpp +++ b/tests/auto/qmutex/tst_qmutex.cpp @@ -393,6 +393,7 @@ public: static QBasicAtomicInt lockCount; static QBasicAtomicInt sentinel; static QMutex mutex; + static int errorCount; void start() { t.start(); @@ -402,13 +403,13 @@ public: { while (t.elapsed() < one_minute) { mutex.lock(); - Q_ASSERT(!sentinel.ref()); - Q_ASSERT(sentinel.deref()); + if (sentinel.ref()) ++errorCount; + if (!sentinel.deref()) ++errorCount; lockCount.ref(); mutex.unlock(); if (mutex.tryLock()) { - Q_ASSERT(!sentinel.ref()); - Q_ASSERT(sentinel.deref()); + if (sentinel.ref()) ++errorCount; + if (!sentinel.deref()) ++errorCount; lockCount.ref(); mutex.unlock(); } @@ -418,6 +419,7 @@ public: QMutex StressTestThread::mutex; QBasicAtomicInt StressTestThread::lockCount = Q_BASIC_ATOMIC_INITIALIZER(0); QBasicAtomicInt StressTestThread::sentinel = Q_BASIC_ATOMIC_INITIALIZER(-1); +int StressTestThread::errorCount = 0; void tst_QMutex::stressTest() { @@ -427,6 +429,7 @@ void tst_QMutex::stressTest() QVERIFY(threads[0].wait(one_minute + 10000)); for (int i = 1; i < threadCount; ++i) QVERIFY(threads[i].wait(10000)); + QCOMPARE(StressTestThread::errorCount, 0); qDebug("locked %d times", int(StressTestThread::lockCount)); } -- cgit v0.12