Stabilize tst_qfontdialog test case.
authorMiikka Heikkinen <miikka.heikkinen@digia.com>
Mon, 22 Oct 2012 12:03:06 +0000 (15:03 +0300)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 23 Oct 2012 10:03:50 +0000 (12:03 +0200)
The delayed quit signal used as failsafe to ensure exit from event
loops interfere with later test if the test case works normally,
as closing the last toplevel window will also exit the event loop.

Fixed by stopping the quit timer if nested application exec loop
is exited.

Change-Id: If87655f1f28f50e27a64f3430c9f65bb3ab7dd70
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Janne Anttila <janne.anttila@digia.com>
tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp

index 2d39dda..958128d 100644 (file)
@@ -76,6 +76,9 @@ private slots:
     void defaultOkButton();
     void setFont();
     void task256466_wrongStyle();
+
+private:
+    void runSlotWithFailsafeTimer(const char *member);
 };
 
 tst_QFontDialog::tst_QFontDialog()
@@ -124,12 +127,24 @@ void tst_QFontDialog::testGetFont()
     QVERIFY(ok);
 }
 
+void tst_QFontDialog::runSlotWithFailsafeTimer(const char *member)
+{
+    // FailSafeTimer quits the nested event loop if the dialog closing doesn't do it.
+    QTimer failSafeTimer;
+    failSafeTimer.setInterval(4000);
+    failSafeTimer.setSingleShot(true);
+    connect(&failSafeTimer, SIGNAL(timeout()), qApp, SLOT(quit()));
+    failSafeTimer.start();
+
+    QTimer::singleShot(0, this, member);
+    qApp->exec();
+
+    // FailSafeTimer stops once it goes out of scope.
+}
 
 void tst_QFontDialog::defaultOkButton()
 {
-    QTimer::singleShot(4000, qApp, SLOT(quit()));
-    QTimer::singleShot(0, this, SLOT(testGetFont()));
-    qApp->exec();
+    runSlotWithFailsafeTimer(SLOT(testGetFont()));
 }
 
 void tst_QFontDialog::testSetFont()
@@ -158,9 +173,7 @@ void tst_QFontDialog::setFont()
               while the font dialog was open.
               Task #27662
     */
-    QTimer::singleShot(4000, qApp, SLOT(quit()));
-    QTimer::singleShot(0, this, SLOT(testSetFont()));
-    qApp->exec();
+    runSlotWithFailsafeTimer(SLOT(testSetFont()));
 }