From cd0bed6d7189fe338043e5dbdf5e8b110da7b06f Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 2 Jun 2015 10:17:38 +0200 Subject: Polish and stabilize tst_qtooltip. - Implement init() and cleanup() to verify that no top level widgets are leaked. - Position widget in tst_QToolTip::task183679() and set window title. - Remove hardcoded wait in tst_QToolTip::whatsThis() and use a find function within QTRY_VERIFY(). - Rearrange and clean code a bit. Change-Id: I0b1ad88444fc9441c1071a2527f75de1f68ea9e5 Reviewed-by: Simon Hausmann --- .../auto/widgets/kernel/qtooltip/tst_qtooltip.cpp | 62 +++++++++++++--------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp b/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp index ebd99be786..0de9e188a0 100644 --- a/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp +++ b/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp @@ -34,30 +34,32 @@ #include #include +#include +#include class tst_QToolTip : public QObject { Q_OBJECT -public: - tst_QToolTip() {} - virtual ~tst_QToolTip() {} - -public slots: - void initTestCase() {} - void cleanupTestCase() {} - void init() {} - void cleanup() {} - private slots: - - // task-specific tests below me + void init(); + void cleanup(); void task183679_data(); void task183679(); void whatsThis(); void setPalette(); }; +void tst_QToolTip::init() +{ + QVERIFY(!QToolTip::isVisible()); +} + +void tst_QToolTip::cleanup() +{ + QTRY_VERIFY(QApplication::topLevelWidgets().isEmpty()); +} + class Widget_task183679 : public QWidget { Q_OBJECT @@ -100,12 +102,14 @@ void tst_QToolTip::task183679() #endif Widget_task183679 widget; + widget.move(QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(50, 50)); + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + + QLatin1Char(' ') + QLatin1String(QTest::currentDataTag())); widget.show(); QApplication::setActiveWindow(&widget); QVERIFY(QTest::qWaitForWindowActive(&widget)); widget.showDelayedToolTip(100); - QTest::qWait(300); QTRY_VERIFY(QToolTip::isVisible()); QTest::keyPress(&widget, key); @@ -116,26 +120,31 @@ void tst_QToolTip::task183679() QTest::qWait(1500); QCOMPARE(QToolTip::isVisible(), visible); + if (visible) + QToolTip::hideText(); } -#include +static QWidget *findWhatsThat() +{ + foreach (QWidget *widget, QApplication::topLevelWidgets()) { + if (widget->inherits("QWhatsThat")) + return widget; + } + return Q_NULLPTR; +} void tst_QToolTip::whatsThis() { qApp->setStyleSheet( "QWidget { font-size: 72px; }" ); - QWhatsThis::showText(QPoint(0,0), "THis is text"); - QTest::qWait(400); - QWidget *whatsthis = 0; - foreach (QWidget *widget, QApplication::topLevelWidgets()) { - if (widget->inherits("QWhatsThat")) { - whatsthis = widget; - break; - } - } - QVERIFY(whatsthis); + QWhatsThis::showText(QPoint(0, 0), "This is text"); + + QWidget *whatsthis = Q_NULLPTR; + QTRY_VERIFY( (whatsthis = findWhatsThat()) ); QVERIFY(whatsthis->isVisible()); - QVERIFY(whatsthis->height() > 100); // Test QTBUG-2416 - qApp->setStyleSheet(""); + const int whatsThisHeight = whatsthis->height(); + qApp->setStyleSheet(QString()); + QWhatsThis::hideText(); + QVERIFY2(whatsThisHeight > 100, QByteArray::number(whatsThisHeight)); // Test QTBUG-2416 } @@ -167,6 +176,7 @@ void tst_QToolTip::setPalette() newPalette.setColor(QPalette::ToolTipText, Qt::blue); QToolTip::setPalette(newPalette); QCOMPARE(toolTip->palette(), newPalette); + QToolTip::hideText(); } QTEST_MAIN(tst_QToolTip) -- cgit v1.2.3