diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-05-22 16:37:49 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-22 21:44:01 +0200 |
commit | a591c272820c623e3bfcf0aea39209f4a03d341d (patch) | |
tree | 34eedefa1d3079a72928fffdf9bf1c297ff52655 /tests/auto | |
parent | 37fd82b9625db0aa90bb41f454956d3d84fa2573 (diff) |
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 <robin+qt@viroteck.net>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 34 |
1 files changed, 22 insertions, 12 deletions
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 <QAbstractTextDocumentLayout> #include <QBitmap> #include <QCursor> +#include <QScreen> #include <QLabel> #include <QDial> #include <QGraphicsItem> @@ -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 /* |