From a591c272820c623e3bfcf0aea39209f4a03d341d Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 22 May 2014 16:37:49 +0200 Subject: Stabilize and speed up tst_QGraphicsItem::cursor(). Use QTRY_COMPARE instead of hard-coded timeouts, ensure window is shown. Change-Id: I4f23144ee14150c4fba9c6fbd8c4ee2da472cc75 Reviewed-by: Robin Burchell --- .../qgraphicsitem/tst_qgraphicsitem.cpp | 34 ++++++++++++++-------- 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 84466b92d1..e9aae1ec59 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -141,6 +142,17 @@ static void sendKeyClick(QGraphicsScene *scene, Qt::Key key) sendKeyRelease(scene, key); } +static inline void centerOnScreen(QWidget *w, const QSize &size) +{ + const QPoint offset = QPoint(size.width() / 2, size.height() / 2); + w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset); +} + +static inline void centerOnScreen(QWidget *w) +{ + centerOnScreen(w, w->geometry().size()); +} + class EventSpy : public QGraphicsWidget { Q_OBJECT @@ -4211,14 +4223,18 @@ void tst_QGraphicsItem::cursor() item2->setCursor(Qt::PointingHandCursor); QWidget topLevel; + topLevel.resize(250, 150); + centerOnScreen(&topLevel); QGraphicsView view(&scene,&topLevel); view.setFixedSize(200, 100); topLevel.show(); + QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); + QTest::mouseMove(&view, view.rect().center()); QTest::qWait(25); - QCursor cursor = view.viewport()->cursor(); + const Qt::CursorShape viewportShape = view.viewport()->cursor().shape(); { QTest::mouseMove(view.viewport(), QPoint(100, 50)); @@ -4226,9 +4242,7 @@ void tst_QGraphicsItem::cursor() QApplication::sendEvent(view.viewport(), &event); } - QTest::qWait(25); - - QCOMPARE(view.viewport()->cursor().shape(), cursor.shape()); + QTRY_COMPARE(view.viewport()->cursor().shape(), viewportShape); { QTest::mouseMove(view.viewport(), view.mapFromScene(item1->sceneBoundingRect().center())); @@ -4236,7 +4250,7 @@ void tst_QGraphicsItem::cursor() QApplication::sendEvent(view.viewport(), &event); } - QCOMPARE(view.viewport()->cursor().shape(), item1->cursor().shape()); + QTRY_COMPARE(view.viewport()->cursor().shape(), item1->cursor().shape()); { QTest::mouseMove(view.viewport(), view.mapFromScene(item2->sceneBoundingRect().center())); @@ -4244,9 +4258,7 @@ void tst_QGraphicsItem::cursor() QApplication::sendEvent(view.viewport(), &event); } - QTest::qWait(25); - - QCOMPARE(view.viewport()->cursor().shape(), item2->cursor().shape()); + QTRY_COMPARE(view.viewport()->cursor().shape(), item2->cursor().shape()); { QTest::mouseMove(view.viewport(), view.rect().center()); @@ -4254,9 +4266,7 @@ void tst_QGraphicsItem::cursor() QApplication::sendEvent(view.viewport(), &event); } - QTest::qWait(25); - - QCOMPARE(view.viewport()->cursor().shape(), cursor.shape()); + QTRY_COMPARE(view.viewport()->cursor().shape(), viewportShape); } #endif /* -- cgit v1.2.3