From d0d393d86f3cc0300fe6329733b409e713263cb3 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Tue, 3 May 2011 11:48:40 +1000 Subject: Remove Q_ASSERT's from QMetaType autotest. Instead of asserting in debug mode and doing nothing in release mode, put specific warnings in the test output and fail the test gracefully. Change-Id: I453a0ab7ddef5b2acf55f77f71a59a940d93ae54 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern (cherry picked from commit a3b2fa3f1beffa7709c11522d4e2db9ec8f952e0) --- tests/auto/qmetatype/tst_qmetatype.cpp | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'tests/auto/qmetatype') diff --git a/tests/auto/qmetatype/tst_qmetatype.cpp b/tests/auto/qmetatype/tst_qmetatype.cpp index 67bbac217a..fcb949fbeb 100644 --- a/tests/auto/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/qmetatype/tst_qmetatype.cpp @@ -113,17 +113,35 @@ protected: #ifdef Q_OS_LINUX pthread_yield(); #endif - Q_ASSERT(QMetaType::isRegistered(tp)); - Q_ASSERT(QMetaType::type(nm) == tp); - Q_ASSERT(QMetaType::typeName(tp) == name); + if (!QMetaType::isRegistered(tp)) { + ++failureCount; + qWarning() << name << "is not a registered metatype"; + } + if (QMetaType::type(nm) != tp) { + ++failureCount; + qWarning() << "Wrong metatype returned for" << name; + } + if (QMetaType::typeName(tp) != name) { + ++failureCount; + qWarning() << "Wrong typeName returned for" << tp; + } void *buf = QMetaType::construct(tp, 0); void *buf2 = QMetaType::construct(tp, buf); - Q_ASSERT(buf); - Q_ASSERT(buf2); + if (!buf) { + ++failureCount; + qWarning() << "Null buffer returned by QMetaType::construct(tp, 0)"; + } + if (!buf2) { + ++failureCount; + qWarning() << "Null buffer returned by QMetaType::construct(tp, buf)"; + } QMetaType::destroy(tp, buf); QMetaType::destroy(tp, buf2); } } +public: + MetaTypeTorturer() : failureCount(0) { } + int failureCount; }; void tst_QMetaType::threadSafety() @@ -139,6 +157,10 @@ void tst_QMetaType::threadSafety() QVERIFY(t1.wait()); QVERIFY(t2.wait()); QVERIFY(t3.wait()); + + QCOMPARE(t1.failureCount, 0); + QCOMPARE(t2.failureCount, 0); + QCOMPARE(t3.failureCount, 0); } namespace TestSpace -- cgit v1.2.3 From e3ee32848d19c767e51e1ce87f61c9e5c74c1daf 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 (cherry picked from commit 8512dc16553ecf511c40a2ba7a815f777d7d5c59) --- tests/auto/qmetatype/tst_qmetatype.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'tests/auto/qmetatype') diff --git a/tests/auto/qmetatype/tst_qmetatype.cpp b/tests/auto/qmetatype/tst_qmetatype.cpp index fcb949fbeb..ccf0ac5836 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 v1.2.3