From 844906474dd6905d36003143a03a2fbccf0ad0dd Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Mon, 9 May 2011 13:01:40 +1000 Subject: Remove Q_ASSERT's from QObject autotest Rather than aborting in debug builds and failing silently in release builds, report a meaningful fatal error in all builds. Change-Id: I3b874f187d482e9785a839cab1a3855b631404c3 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qobject/signalbug.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/auto/qobject/signalbug.cpp b/tests/auto/qobject/signalbug.cpp index f9c9650..55ef5b3 100644 --- a/tests/auto/qobject/signalbug.cpp +++ b/tests/auto/qobject/signalbug.cpp @@ -69,7 +69,8 @@ void Receiver::received () ::Step++; const int stepCopy = ::Step; TRACE (stepCopy, "Receiver::received()"); - Q_ASSERT (::Step == 2 || ::Step == 4); + if (::Step != 2 && ::Step != 4) + qFatal("%s: Incorrect Step: %d (should be 2 or 4)", Q_FUNC_INFO, ::Step); if (::Step == 2) s->fire (); @@ -91,7 +92,8 @@ void Disconnector::received () ::Step++; const int stepCopy = ::Step; TRACE (stepCopy, "Disconnector::received()"); - Q_ASSERT (::Step == 5 || ::Step == 6); + if (::Step != 5 && ::Step != 6) + qFatal("%s: Incorrect Step: %d (should be 5 or 6)", Q_FUNC_INFO, ::Step); fprintf (stderr, "Disconnector<%s>::received() sender=%s\n", (const char *) objectName ().toAscii (), sender ()->metaObject()->className()); @@ -124,7 +126,8 @@ void Sender::fire () ::Step++; const int stepCopy = ::Step; TRACE (stepCopy, "Sender::fire()"); - Q_ASSERT (::Step == 1 || ::Step == 3); + if (::Step != 1 && ::Step != 3) + qFatal("%s: Incorrect Step: %d (should be 1 or 3)", Q_FUNC_INFO, ::Step); emit fired (); TRACE (stepCopy, "ends Sender::fire()"); -- cgit v0.12 From 0c157af3e5aa7c56c53b9eabe1510cc639610969 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Mon, 9 May 2011 13:16:39 +1000 Subject: Remove Q_ASSERT's from QObject autotest Rather than aborting in debug builds and failing silently in release builds, report a fatal error in all builds if the helper class methods are called more than once. Change-Id: Id1fda8dc7caf008bbc8f6ae6384abee1aa8f50eb Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qobject/tst_qobject.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/auto/qobject/tst_qobject.cpp b/tests/auto/qobject/tst_qobject.cpp index 29b07af..0e5a087 100644 --- a/tests/auto/qobject/tst_qobject.cpp +++ b/tests/auto/qobject/tst_qobject.cpp @@ -1330,14 +1330,16 @@ public: void customEvent(QEvent *) { - Q_ASSERT(customEventThread == 0); + if (customEventThread) + qFatal("%s: customEventThread should be null", Q_FUNC_INFO); customEventThread = QThread::currentThread(); emit theSignal(); } void timerEvent(QTimerEvent *) { - Q_ASSERT(timerEventThread == 0); + if (timerEventThread) + qFatal("%s: timerEventThread should be null", Q_FUNC_INFO); timerEventThread = QThread::currentThread(); emit theSignal(); } @@ -1345,7 +1347,8 @@ public: public slots: void theSlot() { - Q_ASSERT(slotThread == 0); + if (slotThread) + qFatal("%s: slotThread should be null", Q_FUNC_INFO); slotThread = QThread::currentThread(); emit theSignal(); } -- cgit v0.12 From 00f724c943b83f10f9ca9475570708536947538e Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Mon, 9 May 2011 13:46:32 +1000 Subject: Remove Q_ASSERT's from qreadwritelock autotest The tryWriteLock testfunction didn't do anything useful in non-debug builds, due to the thread having the important code inside Q_ASSERT's, which are no-ops in non-debug builds. This commit removes the Q_ASSERT's, counts the number of failures in the thread and fails the test if there are any failures recorded. Change-Id: I4750f66eeba22ab51ba348ebc06704052421f1ae Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qreadwritelock/tst_qreadwritelock.cpp | 29 +++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/tests/auto/qreadwritelock/tst_qreadwritelock.cpp b/tests/auto/qreadwritelock/tst_qreadwritelock.cpp index e0cc2fa..0d575a1 100644 --- a/tests/auto/qreadwritelock/tst_qreadwritelock.cpp +++ b/tests/auto/qreadwritelock/tst_qreadwritelock.cpp @@ -362,34 +362,45 @@ void tst_QReadWriteLock::tryWriteLock() class Thread : public QThread { public: + Thread() : failureCount(0) { } void run() { testsTurn.release(); threadsTurn.acquire(); - Q_ASSERT(!readWriteLock.tryLockForWrite()); + if (readWriteLock.tryLockForWrite()) + failureCount++; testsTurn.release(); threadsTurn.acquire(); - Q_ASSERT(readWriteLock.tryLockForWrite()); - Q_ASSERT(lockCount.testAndSetRelaxed(0, 1)); - Q_ASSERT(lockCount.testAndSetRelaxed(1, 0)); + if (!readWriteLock.tryLockForWrite()) + failureCount++; + if (!lockCount.testAndSetRelaxed(0, 1)) + failureCount++; + if (!lockCount.testAndSetRelaxed(1, 0)) + failureCount++; readWriteLock.unlock(); testsTurn.release(); threadsTurn.acquire(); - Q_ASSERT(!readWriteLock.tryLockForWrite(1000)); + if (readWriteLock.tryLockForWrite(1000)) + failureCount++; testsTurn.release(); threadsTurn.acquire(); - Q_ASSERT(readWriteLock.tryLockForWrite(1000)); - Q_ASSERT(lockCount.testAndSetRelaxed(0, 1)); - Q_ASSERT(lockCount.testAndSetRelaxed(1, 0)); + if (!readWriteLock.tryLockForWrite(1000)) + failureCount++; + if (!lockCount.testAndSetRelaxed(0, 1)) + failureCount++; + if (!lockCount.testAndSetRelaxed(1, 0)) + failureCount++; readWriteLock.unlock(); testsTurn.release(); threadsTurn.acquire(); } + + int failureCount; }; Thread thread; @@ -419,6 +430,8 @@ void tst_QReadWriteLock::tryWriteLock() testsTurn.acquire(); threadsTurn.release(); thread.wait(); + + QCOMPARE(thread.failureCount, 0); } } -- cgit v0.12 From 3b7f3757efb038fe523a00d474d1b92920f9abe8 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Mon, 9 May 2011 14:52:46 +1000 Subject: Remove Q_ASSERT from qscriptengine autotest Rather than aborting in debug builds and failing silently in release builds, output a meaningful warning message and return a null QScriptValue which will cause the "isQObject" check in the testfunction to fail. Change-Id: I69fd9c15a69924d0abfde6710ea6ae4bf7e013fa Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qscriptengine/tst_qscriptengine.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index bc4091d..1a9db8f 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -5701,7 +5701,10 @@ void tst_QScriptEngine::collectGarbageAfterNativeArguments() static QScriptValue constructQObjectFromThisObject(QScriptContext *ctx, QScriptEngine *eng) { - Q_ASSERT(ctx->isCalledAsConstructor()); + if (!ctx->isCalledAsConstructor()) { + qWarning("%s: ctx->isCalledAsConstructor() returned false", Q_FUNC_INFO); + return QScriptValue(); + } return eng->newQObject(ctx->thisObject(), new QObject, QScriptEngine::ScriptOwnership); } -- cgit v0.12 From 20512cdab97b530ee8ec767254e553d80164b3c6 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Mon, 9 May 2011 15:02:54 +1000 Subject: Remove Q_ASSERT's from V8 autotest Report a fatal error when the realFail() function is missing or misbehaving rather than silently ignoring the failure in non-debug builds. Change-Id: I8b27aeb1c9dab5752a5dbedafc4d420bb4121d2b Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qscriptv8testsuite/tst_qscriptv8testsuite.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/auto/qscriptv8testsuite/tst_qscriptv8testsuite.cpp b/tests/auto/qscriptv8testsuite/tst_qscriptv8testsuite.cpp index 7328e1b..75c9acb 100644 --- a/tests/auto/qscriptv8testsuite/tst_qscriptv8testsuite.cpp +++ b/tests/auto/qscriptv8testsuite/tst_qscriptv8testsuite.cpp @@ -95,9 +95,11 @@ protected: static QScriptValue qscript_fail(QScriptContext *ctx, QScriptEngine *eng) { QScriptValue realFail = ctx->callee().data(); - Q_ASSERT(realFail.isFunction()); + if (!realFail.isFunction()) + qFatal("%s: realFail must be a function", Q_FUNC_INFO); QScriptValue ret = realFail.call(ctx->thisObject(), ctx->argumentsObject()); - Q_ASSERT(eng->hasUncaughtException()); + if (!eng->hasUncaughtException()) + qFatal("%s: realFail function did not throw an exception", Q_FUNC_INFO); ret.setProperty("expected", ctx->argument(0)); ret.setProperty("actual", ctx->argument(1)); ret.setProperty("message", ctx->argument(2)); -- cgit v0.12 From 385107ebc71a74dae031b713ea5a9c54635eeff8 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Mon, 9 May 2011 15:36:04 +1000 Subject: Remove Q_ASSERT's from qscriptvaluegenerated test Report a fatal error if there are problems reading from the input data stream rather than failing silently in non-debug builds. Change-Id: I7a913bf47dccb37bab09e1cd79e5022b04e42c27 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- .../testgen/testgenerator.cpp | 25 ++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/auto/qscriptvaluegenerated/testgen/testgenerator.cpp b/tests/auto/qscriptvaluegenerated/testgen/testgenerator.cpp index 4d20f89..df2d38a 100644 --- a/tests/auto/qscriptvaluegenerated/testgen/testgenerator.cpp +++ b/tests/auto/qscriptvaluegenerated/testgen/testgenerator.cpp @@ -545,6 +545,17 @@ static void squashTags(QString dataTag, const QVector& results, QList(s)); + } +} QHash TestGenerator::generateTest() { @@ -596,7 +607,10 @@ QHash TestGenerator::generateTest() m_tempFile.seek(0); QDataStream in(&m_tempFile); in >> dataTags; - Q_ASSERT(in.status() == in.Ok); + if (in.status() != in.Ok) + qFatal("%s: stream has bad status %s after reading dataTags", + Q_FUNC_INFO, + qPrintable(streamStatusString(in.status()))); while(!in.atEnd()) { @@ -720,10 +734,13 @@ QHash TestGenerator::generateTest() castUInt32List.append(QPair(dataTag, castUInt32Res)); castUInt16List.append(QPair(dataTag, castUInt16Res)); - Q_ASSERT(in.status() == in.Ok); + if (in.status() != in.Ok) + qFatal("%s: stream has bad status %s after reading data items", + Q_FUNC_INFO, + qPrintable(streamStatusString(in.status()))); } - - Q_ASSERT(in.atEnd()); + if (!in.atEnd()) + qFatal("%s: stream has more data after reading all data items", Q_FUNC_INFO); // Generate. QHash result; -- cgit v0.12 From a4f105070799d4b4362b80b77c5960b364f77000 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Mon, 9 May 2011 15:38:42 +1000 Subject: Remove Q_ASSERT from qscriptvaluegenerated test Report a fatal error if an empty test is generated rather than failing silently in non-debug builds. Change-Id: I79aa7a9eb09e387cef1960816a4bcce7b1af282d Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qscriptvaluegenerated/testgen/testgenerator.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/auto/qscriptvaluegenerated/testgen/testgenerator.h b/tests/auto/qscriptvaluegenerated/testgen/testgenerator.h index be4f79f..d3096c0 100644 --- a/tests/auto/qscriptvaluegenerated/testgen/testgenerator.h +++ b/tests/auto/qscriptvaluegenerated/testgen/testgenerator.h @@ -59,7 +59,8 @@ public: void run() { prepareData(); - Q_ASSERT(m_tempFile.size()); + if (!m_tempFile.size()) + qFatal("%s: prepareData failed to generate any data", Q_FUNC_INFO); save(generateTest()); } -- cgit v0.12 From 224050aae75fd5b1d6c57909d894a3eba7ac43fc Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Mon, 9 May 2011 15:47:20 +1000 Subject: Remove unused function from qtessellator autotest Change-Id: I24c1db8392370d19970421a014f7bb6c4bc7c6e8 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qtessellator/oldtessellator.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/tests/auto/qtessellator/oldtessellator.cpp b/tests/auto/qtessellator/oldtessellator.cpp index 10b8710..e6a0451 100644 --- a/tests/auto/qtessellator/oldtessellator.cpp +++ b/tests/auto/qtessellator/oldtessellator.cpp @@ -80,19 +80,6 @@ struct QEdge { horizontal = p1.y == p2.y; } - inline qreal xAt(const qreal &y) const - { - Q_ASSERT(p1.y != p2.y); - XFixed yf = XDoubleToFixed(y); - - if (yf == p1.y) - return XFixedToDouble(p1.x); - else if (yf == p2.y) - return XFixedToDouble(p2.x); - - return (!vertical) ? (((y - b)*im)) : pf1.x(); - } - QPointF pf1, pf2; XPointFixed p1, p2; qreal m; -- cgit v0.12 From c0c7e04c9248ce38278aceefeb527f29149cfb4e Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Mon, 9 May 2011 15:53:13 +1000 Subject: Remove Q_ASSERT from qtesselator autotest Report a fatal error rather than failing silently in non-debug builds. Change-Id: I625c5aa6f86a5764cd8f078baa074d6475a67736 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qtessellator/oldtessellator.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/auto/qtessellator/oldtessellator.cpp b/tests/auto/qtessellator/oldtessellator.cpp index e6a0451..bc24d7e 100644 --- a/tests/auto/qtessellator/oldtessellator.cpp +++ b/tests/auto/qtessellator/oldtessellator.cpp @@ -371,7 +371,8 @@ void old_tesselate_polygon(QVector *traps, const QPointF *pg, int pg isects[i].edge = edge; } - Q_ASSERT(isects.size()%2 == 1); + if (isects.size()%2 != 1) + qFatal("%s: number of intersection points must be odd", Q_FUNC_INFO); // sort intersection points qSort(&isects[0], &isects[isects.size()-1], compareIntersections); -- cgit v0.12 From e12b912de89088a307c3519a01198a5314b8dd1a Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Mon, 9 May 2011 17:14:39 +1000 Subject: Remove Q_ASSERT's from QTreeView autotest Report fatal errors instead of failing silently in non-debug builds. Change-Id: Ieaff30b71dba2a385a5fffc93d2a8c0f5864aa18 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qtreeview/tst_qtreeview.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp index 551b63f..1f0c2ce 100644 --- a/tests/auto/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/qtreeview/tst_qtreeview.cpp @@ -277,7 +277,8 @@ public: } int rowCount(const QModelIndex& parent = QModelIndex()) const { - Q_ASSERT(fetched); + if (!fetched) + qFatal("%s: rowCount should not be called before fetching", Q_FUNC_INFO); if ((parent.column() > 0) || (level(parent) > levels)) return 0; return rows; @@ -2567,7 +2568,8 @@ public: } } if (parent == 0) { - Q_ASSERT(children.isEmpty()); + if (!children.isEmpty()) + qFatal("%s: children should be empty when parent is null", Q_FUNC_INFO); populate(); } else { isDead = true; -- cgit v0.12