From 32cbcca91122c61a1dddf45f23916424cd65829b Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 22 Oct 2012 15:03:06 +0300 Subject: Stabilize tst_qfontdialog test case. 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 Reviewed-by: Janne Anttila --- .../dialogs/qfontdialog/tst_qfontdialog.cpp | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'tests/auto/widgets/dialogs/qfontdialog') diff --git a/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp b/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp index 2d39ddaa2c..958128d58e 100644 --- a/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp +++ b/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp @@ -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())); } -- cgit v1.2.3