Fix qmltestrunner hang bug when no TestCase item
authorCharles Yin <charles.yin@nokia.com>
Mon, 24 Oct 2011 00:44:16 +0000 (10:44 +1000)
committerQt by Nokia <qt-info@nokia.com>
Mon, 24 Oct 2011 01:02:19 +0000 (03:02 +0200)
Add a hasTestCase property to the global qtest object, set it to true
in each TestCase's onCompleted handler. qmltestrunner only enter the
event loop if this property is true to avoid infinite waiting.

Task-number:QTBUG-22281
Change-Id: Id609432210ae795d8c128901e64ba0aef4551f01
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Reviewed-by: Charles Yin <charles.yin@nokia.com>
src/imports/testlib/TestCase.qml
src/qmltest/quicktest.cpp

index 432f96c..bb97481 100644 (file)
@@ -684,6 +684,8 @@ Item {
     }
 
     Component.onCompleted: {
+        qtest.hasTestCase = true;
+
         if (util.printAvailableFunctions) {
             var testList = []
             for (var prop in testCase) {
index 3c726d4..601f5dc 100644 (file)
@@ -72,23 +72,28 @@ class QTestRootObject : public QObject
 {
     Q_OBJECT
     Q_PROPERTY(bool windowShown READ windowShown NOTIFY windowShownChanged)
+    Q_PROPERTY(bool hasTestCase READ hasTestCase WRITE setHasTestCase NOTIFY hasTestCaseChanged)
 public:
     QTestRootObject(QObject *parent = 0)
-        : QObject(parent), hasQuit(false), m_windowShown(false) {}
+        : QObject(parent), hasQuit(false), m_hasTestCase(false), m_windowShown(false) {}
 
-    bool hasQuit;
+    bool hasQuit:1;
+    bool hasTestCase() const { return m_hasTestCase; }
+    void setHasTestCase(bool value) { m_hasTestCase = value; emit hasTestCaseChanged(); }
 
     bool windowShown() const { return m_windowShown; }
     void setWindowShown(bool value) { m_windowShown = value; emit windowShownChanged(); }
 
 Q_SIGNALS:
     void windowShownChanged();
+    void hasTestCaseChanged();
 
 private Q_SLOTS:
     void quit() { hasQuit = true; }
 
 private:
-    bool m_windowShown;
+    bool m_windowShown : 1;
+    bool m_hasTestCase :1;
 };
 
 static inline QString stripQuotes(const QString &s)
@@ -192,11 +197,14 @@ int quick_test_main(int argc, char **argv, const char *name, quick_test_viewport
             if (!fi.exists())
                 continue;
 
+            rootobj.setHasTestCase(false);
+
             QString path = fi.absoluteFilePath();
             if (path.startsWith(QLatin1String(":/")))
                 view.setSource(QUrl(QLatin1String("qrc:") + path.mid(2)));
             else
                 view.setSource(QUrl::fromLocalFile(path));
+
             if (QTest::printAvailableFunctions)
                 continue;
             if (view.status() == QQuickView::Error) {
@@ -224,7 +232,7 @@ int quick_test_main(int argc, char **argv, const char *name, quick_test_viewport
                 view.show();
                 QTest::qWaitForWindowShown(&view);
                 rootobj.setWindowShown(true);
-                if (!rootobj.hasQuit)
+                if (!rootobj.hasQuit && rootobj.hasTestCase())
                     eventLoop.exec();
             }
         }