Skip to content

Commit

Permalink
Stabilize tst_QGraphicsProxyWidget::tooltip_basic()
Browse files Browse the repository at this point in the history
Use QTRY_VERIFY instead of hard-coded wait for the tooltip to appear.
Also use QTRY_VERIFY to verify that no top level widgets are left over
to account for tooltips and effect windows.

Change-Id: Ia9835fdc480c6abb034f6fc4ad3d6b32751ee536
Reviewed-by: Sami Nurmenniemi <[email protected]>
Reviewed-by: Kari Oikarinen <[email protected]>
  • Loading branch information
FriedemannKleint committed Mar 29, 2018
1 parent 62da8e3 commit f3a461c
Showing 1 changed file with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void tst_QGraphicsProxyWidget::initTestCase()
// This will be called after every test function.
void tst_QGraphicsProxyWidget::cleanup()
{
QVERIFY(QApplication::topLevelWidgets().isEmpty());
QTRY_VERIFY(QApplication::topLevelWidgets().isEmpty());
}

void tst_QGraphicsProxyWidget::qgraphicsproxywidget_data()
Expand Down Expand Up @@ -2575,6 +2575,22 @@ void tst_QGraphicsProxyWidget::changingCursor_basic()
}
#endif

static bool findViewAndTipLabel(const QWidget *view)
{
bool foundView = false;
bool foundTipLabel = false;
const QWidgetList &topLevels = QApplication::topLevelWidgets();
for (const QWidget *widget : topLevels) {
if (widget == view)
foundView = true;
if (widget->inherits("QTipLabel"))
foundTipLabel = true;
if (foundView && foundTipLabel)
return true;
}
return false;
}

void tst_QGraphicsProxyWidget::tooltip_basic()
{
QString toolTip = "Qt rocks!";
Expand Down Expand Up @@ -2627,18 +2643,7 @@ void tst_QGraphicsProxyWidget::tooltip_basic()
QHelpEvent helpEvent(QEvent::ToolTip, view.mapFromScene(proxy->boundingRect().center()),
view.viewport()->mapToGlobal(view.mapFromScene(proxy->boundingRect().center())));
QApplication::sendEvent(view.viewport(), &helpEvent);
QTest::qWait(350);

bool foundView = false;
bool foundTipLabel = false;
foreach (QWidget *widget, QApplication::topLevelWidgets()) {
if (widget == &view)
foundView = true;
if (widget->inherits("QTipLabel"))
foundTipLabel = true;
}
QVERIFY(foundView);
QVERIFY(foundTipLabel);
QTRY_VERIFY(findViewAndTipLabel(&view));
}
}

Expand Down

0 comments on commit f3a461c

Please sign in to comment.