Reduce usage of Q_ASSERT in autotests.
authorJason McDonald <jason.mcdonald@nokia.com>
Wed, 18 May 2011 00:45:16 +0000 (10:45 +1000)
committerRohan McGovern <rohan.mcgovern@nokia.com>
Wed, 18 May 2011 01:00:07 +0000 (11:00 +1000)
Using Q_ASSERT does nothing in release-mode builds, and in debug builds
it causes tests to terminate prematurely.  It is much better to use
QVERIFY or QCOMPARE.

Task-number: QTBUG-17582
Reviewed-by: Rohan McGovern
(cherry picked from commit 3475168550c1a804f04f2a4edfeb30c04cd36551)

tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp
tests/auto/declarative/qdeclarativedebugclient/tst_qdeclarativedebugclient.cpp
tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp
tests/auto/declarative/qdeclarativefontloader/tst_qdeclarativefontloader.cpp

index e63b14e..dba2007 100644 (file)
@@ -80,7 +80,7 @@ private:
     void recursiveCompareObjects(const QDeclarativeDebugObjectReference &a, const QDeclarativeDebugObjectReference &b) const;
     void recursiveCompareContexts(const QDeclarativeDebugContextReference &a, const QDeclarativeDebugContextReference &b) const;
     void compareProperties(const QDeclarativeDebugPropertyReference &a, const QDeclarativeDebugPropertyReference &b) const;
-    
+
     QDeclarativeDebugConnection *m_conn;
     QDeclarativeEngineDebug *m_dbg;
     QDeclarativeEngine *m_engine;
@@ -134,7 +134,7 @@ QDeclarativeDebugObjectReference tst_QDeclarativeDebug::findRootObject(int conte
 {
     QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this);
     waitForQuery(q_engines);
-    
+
     if (q_engines->engines().count() == 0)
         return QDeclarativeDebugObjectReference();
     QDeclarativeDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this);
@@ -368,7 +368,7 @@ void tst_QDeclarativeDebug::initTestCase()
     for (int i=0; i<qml.count(); i++) {
         QDeclarativeComponent component(m_engine);
         component.setData(qml[i], QUrl::fromLocalFile(""));
-        Q_ASSERT(component.isReady());  // fails if bad syntax
+        QVERIFY(component.isReady());  // fails if bad syntax
         m_components << qobject_cast<QDeclarativeItem*>(component.create());
     }
     m_rootItem = qobject_cast<QDeclarativeItem*>(m_components.first());
@@ -382,7 +382,7 @@ void tst_QDeclarativeDebug::initTestCase()
 
     QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established");
     bool ok = m_conn->waitForConnected();
-    Q_ASSERT(ok);
+    QVERIFY(ok);
     QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient());
     m_dbg = new QDeclarativeEngineDebug(m_conn, this);
     QTRY_VERIFY(m_dbg->status() == QDeclarativeEngineDebug::Enabled);
@@ -439,7 +439,7 @@ void tst_QDeclarativeDebug::watch_property()
     QDeclarativeDebugPropertyReference prop = findProperty(obj.properties(), "width");
 
     QDeclarativeDebugPropertyWatch *watch;
-    
+
     QDeclarativeEngineDebug *unconnected = new QDeclarativeEngineDebug(0);
     watch = unconnected->addWatch(prop, this);
     QCOMPARE(watch->state(), QDeclarativeDebugWatch::Dead);
@@ -450,7 +450,7 @@ void tst_QDeclarativeDebug::watch_property()
     QVERIFY(QDeclarativeDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QDeclarativeDebugWatch::State))));
     QCOMPARE(watch->state(), QDeclarativeDebugWatch::Inactive);
     delete watch;
-    
+
     watch = m_dbg->addWatch(prop, this);
     QCOMPARE(watch->state(), QDeclarativeDebugWatch::Waiting);
     QCOMPARE(watch->objectDebugId(), obj.debugId());
@@ -482,12 +482,12 @@ void tst_QDeclarativeDebug::watch_object()
 {
     QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this);
     waitForQuery(q_engines);
-    
-    Q_ASSERT(q_engines->engines().count() > 0);
+
+    QVERIFY(q_engines->engines().count() > 0);
     QDeclarativeDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this);
     waitForQuery(q_context);
 
-    Q_ASSERT(q_context->rootContext().objects().count() > 0);
+    QVERIFY(q_context->rootContext().objects().count() > 0);
     QDeclarativeDebugObjectQuery *q_obj = m_dbg->queryObject(q_context->rootContext().objects()[0], this);
     waitForQuery(q_obj);
 
@@ -504,7 +504,7 @@ void tst_QDeclarativeDebug::watch_object()
     QCOMPARE(watch->state(), QDeclarativeDebugWatch::Dead);
     delete watch;
     delete unconnected;
-    
+
     watch = m_dbg->addWatch(QDeclarativeDebugObjectReference(), this);
     QVERIFY(QDeclarativeDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QDeclarativeDebugWatch::State))));
     QCOMPARE(watch->state(), QDeclarativeDebugWatch::Inactive);
@@ -558,7 +558,7 @@ void tst_QDeclarativeDebug::watch_expression()
     QFETCH(int, incrementCount);
 
     int origWidth = m_rootItem->property("width").toInt();
-    
+
     QDeclarativeDebugObjectReference obj = findRootObject();
 
     QDeclarativeDebugObjectExpressionWatch *watch;
@@ -568,12 +568,12 @@ void tst_QDeclarativeDebug::watch_expression()
     QCOMPARE(watch->state(), QDeclarativeDebugWatch::Dead);
     delete watch;
     delete unconnected;
-    
+
     watch = m_dbg->addWatch(QDeclarativeDebugObjectReference(), expr, this);
     QVERIFY(QDeclarativeDebugTest::waitForSignal(watch, SIGNAL(stateChanged(QDeclarativeDebugWatch::State))));
     QCOMPARE(watch->state(), QDeclarativeDebugWatch::Inactive);
     delete watch;
-    
+
     watch = m_dbg->addWatch(obj, expr, this);
     QCOMPARE(watch->state(), QDeclarativeDebugWatch::Waiting);
     QCOMPARE(watch->objectDebugId(), obj.debugId());
@@ -603,7 +603,7 @@ void tst_QDeclarativeDebug::watch_expression()
     delete watch;
 
     // restore original value and verify spy doesn't get a signal since watch has been removed
-    m_rootItem->setProperty("width", origWidth); 
+    m_rootItem->setProperty("width", origWidth);
     QTest::qWait(100);
     QCOMPARE(spy.count(), expectedSpyCount);
 
@@ -681,7 +681,7 @@ void tst_QDeclarativeDebug::queryRootContexts()
     delete q_engines;
 
     QDeclarativeDebugRootContextQuery *q_context;
-    
+
     QDeclarativeEngineDebug *unconnected = new QDeclarativeEngineDebug(0);
     q_context = unconnected->queryRootContexts(engineId, this);
     QCOMPARE(q_context->state(), QDeclarativeDebugQuery::Error);
@@ -725,7 +725,7 @@ void tst_QDeclarativeDebug::queryObject()
 
     QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this);
     waitForQuery(q_engines);
-    
+
     QDeclarativeDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this);
     waitForQuery(q_context);
     QDeclarativeDebugObjectReference rootObject = q_context->rootContext().objects()[0];
@@ -806,7 +806,7 @@ void tst_QDeclarativeDebug::queryExpressionResult()
 
     QDeclarativeDebugEnginesQuery *q_engines = m_dbg->queryAvailableEngines(this);
     waitForQuery(q_engines);    // check immediate deletion is ok
-    
+
     QDeclarativeDebugRootContextQuery *q_context = m_dbg->queryRootContexts(q_engines->engines()[0].debugId(), this);
     waitForQuery(q_context);
     int objectId = q_context->rootContext().objects()[0].debugId();
@@ -818,7 +818,7 @@ void tst_QDeclarativeDebug::queryExpressionResult()
     QCOMPARE(q_expr->state(), QDeclarativeDebugQuery::Error);
     delete q_expr;
     delete unconnected;
-    
+
     q_expr = m_dbg->queryExpressionResult(objectId, expr, this);
     delete q_expr;
 
@@ -964,7 +964,7 @@ void tst_QDeclarativeDebug::tst_QDeclarativeDebugPropertyReference()
     QDeclarativeDebugObjectQuery *query = m_dbg->queryObject(rootObject, this);
     waitForQuery(query);
     QDeclarativeDebugObjectReference obj = query->object();
-    delete query;   
+    delete query;
 
     QDeclarativeDebugPropertyReference ref = findProperty(obj.properties(), "scale");
     QVERIFY(ref.objectDebugId() > 0);
@@ -973,7 +973,7 @@ void tst_QDeclarativeDebug::tst_QDeclarativeDebugPropertyReference()
     QVERIFY(!ref.valueTypeName().isEmpty());
     QVERIFY(!ref.binding().isEmpty());
     QVERIFY(ref.hasNotifySignal());
-  
+
     QDeclarativeDebugPropertyReference copy(ref);
     QDeclarativeDebugPropertyReference copyAssign;
     copyAssign = ref;
index c182893..59214d1 100644 (file)
@@ -88,7 +88,7 @@ void tst_QDeclarativeDebugClient::initTestCase()
 
     QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established");
     bool ok = m_conn->waitForConnected();
-    Q_ASSERT(ok);
+    QVERIFY(ok);
 
     QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient());
     QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Enabled);
index 0911a83..a61f4a8 100644 (file)
@@ -87,7 +87,7 @@ void tst_QDeclarativeDebugService::initTestCase()
 
     QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established");
     bool ok = m_conn->waitForConnected();
-    Q_ASSERT(ok);
+    QVERIFY(ok);
 
     QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient());
 }
index e684bbe..2f0992c 100644 (file)
 #endif
 
 class tst_qdeclarativefontloader : public QObject
-
 {
     Q_OBJECT
 public:
     tst_qdeclarativefontloader();
 
 private slots:
+    void init();
     void noFont();
     void namedFont();
     void localFont();
@@ -71,8 +71,6 @@ private slots:
     void failWebFont();
     void changeFont();
 
-private slots:
-
 private:
     QDeclarativeEngine engine;
     TestHTTPServer server;
@@ -82,7 +80,11 @@ tst_qdeclarativefontloader::tst_qdeclarativefontloader() :
     server(SERVER_PORT)
 {
     server.serveDirectory(SRCDIR "/data");
-    Q_ASSERT(server.isValid());
+}
+
+void tst_qdeclarativefontloader::init()
+{
+    QVERIFY(server.isValid());
 }
 
 void tst_qdeclarativefontloader::noFont()