From 2c232cdbce3eba095da26362b964f411a9d3ba80 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 10 Sep 2009 11:03:11 +0200 Subject: Stabilize Graphics View tests Reviewed-by: Jesper --- .../tst_qgraphicsproxywidget.cpp | 45 +++++++++----- tests/auto/qgraphicsview/tst_qgraphicsview.cpp | 26 ++++++-- tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp | 70 +++++++++++++--------- 3 files changed, 93 insertions(+), 48 deletions(-) diff --git a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index 1ee8e51..626a691 100644 --- a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -786,7 +786,9 @@ void tst_QGraphicsProxyWidget::focusNextPrevChild() #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&view); #endif + QApplication::setActiveWindow(&view); QTest::qWait(250); + QTRY_COMPARE(QApplication::activeWindow(), &view); if (hasScene) { scene.addItem(proxy); proxy->show(); @@ -836,8 +838,9 @@ void tst_QGraphicsProxyWidget::focusOutEvent() QApplication::setActiveWindow(&view); view.activateWindow(); view.setFocus(); - QTRY_VERIFY(view.isVisible()); QTest::qWait(125); + QTRY_VERIFY(view.isVisible()); + QTRY_COMPARE(QApplication::activeWindow(), &view); QWidget *widget = new QWidget; widget->setFocusPolicy(Qt::WheelFocus); @@ -1098,7 +1101,9 @@ void tst_QGraphicsProxyWidget::keyPressEvent() #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&view); #endif + QApplication::setActiveWindow(&view); QTest::qWait(250); + QTRY_COMPARE(QApplication::activeWindow(), &view); SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; proxy->setFlag(QGraphicsItem::ItemIsFocusable, true); // ### remove me!!! @@ -1108,7 +1113,7 @@ void tst_QGraphicsProxyWidget::keyPressEvent() view.resize(100, 100); if (hasWidget) { proxy->setWidget(widget); - proxy->show(); + proxy->show(); } proxy->setPos(50, 0); scene.addItem(proxy); @@ -1140,7 +1145,10 @@ void tst_QGraphicsProxyWidget::keyReleaseEvent() #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&view); #endif + QApplication::setActiveWindow(&view); QTest::qWait(250); + QTRY_COMPARE(QApplication::activeWindow(), &view); + SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; proxy->setFlag(QGraphicsItem::ItemIsFocusable, true); // ### remove me!!! @@ -1150,7 +1158,7 @@ void tst_QGraphicsProxyWidget::keyReleaseEvent() view.resize(100, 100); if (hasWidget) { proxy->setWidget(widget); - proxy->show(); + proxy->show(); } proxy->setPos(50, 0); scene.addItem(proxy); @@ -1181,6 +1189,10 @@ void tst_QGraphicsProxyWidget::mouseDoubleClickEvent() QGraphicsView view(&scene); view.show(); + QApplication::setActiveWindow(&view); + QTest::qWait(250); + QTRY_COMPARE(QApplication::activeWindow(), &view); + SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; proxy->setFlag(QGraphicsItem::ItemIsFocusable, true); // ### remove me!!! QLineEdit *widget = new QLineEdit; @@ -1189,7 +1201,7 @@ void tst_QGraphicsProxyWidget::mouseDoubleClickEvent() view.resize(100, 100); if (hasWidget) { proxy->setWidget(widget); - proxy->show(); + proxy->show(); } proxy->setPos(50, 0); scene.addItem(proxy); @@ -1495,7 +1507,8 @@ void tst_QGraphicsProxyWidget::scrollUpdate() #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&view); #endif - QTest::qWait(200); + QTRY_COMPARE(view.npaints, 1); + QTest::qWait(20); widget->paintEventRegion = QRegion(); widget->npaints = 0; view.paintEventRegion = QRegion(); @@ -1709,7 +1722,7 @@ void tst_QGraphicsProxyWidget::tabFocus_simpleWidget() leftDial->setFocus(); QTest::qWait(125); - QVERIFY(leftDial->hasFocus()); + QTRY_VERIFY(leftDial->hasFocus()); EventSpy eventSpy(edit); @@ -1793,7 +1806,7 @@ void tst_QGraphicsProxyWidget::tabFocus_simpleTwoWidgets() leftDial->setFocus(); QTest::qWait(125); - QVERIFY(leftDial->hasFocus()); + QTRY_VERIFY(leftDial->hasFocus()); EventSpy eventSpy(edit); EventSpy eventSpy2(edit2); @@ -1927,7 +1940,7 @@ void tst_QGraphicsProxyWidget::tabFocus_complexWidget() leftDial->setFocus(); QTest::qWait(125); - QVERIFY(leftDial->hasFocus()); + QTRY_VERIFY(leftDial->hasFocus()); EventSpy eventSpy(edit1); EventSpy eventSpy2(edit2); @@ -2061,7 +2074,7 @@ void tst_QGraphicsProxyWidget::tabFocus_complexTwoWidgets() leftDial->setFocus(); QTest::qWait(125); - QVERIFY(leftDial->hasFocus()); + QTRY_VERIFY(leftDial->hasFocus()); EventSpy eventSpy(edit1); EventSpy eventSpy2(edit2); @@ -2197,7 +2210,7 @@ void tst_QGraphicsProxyWidget::setFocus_simpleWidget() leftDial->setFocus(); QTest::qWait(125); - QVERIFY(leftDial->hasFocus()); + QTRY_VERIFY(leftDial->hasFocus()); EventSpy eventSpy(edit); @@ -2269,7 +2282,7 @@ void tst_QGraphicsProxyWidget::setFocus_simpleTwoWidgets() leftDial->setFocus(); QTest::qWait(125); - QVERIFY(leftDial->hasFocus()); + QTRY_VERIFY(leftDial->hasFocus()); EventSpy eventSpy(edit); @@ -2348,7 +2361,7 @@ void tst_QGraphicsProxyWidget::setFocus_complexTwoWidgets() leftDial->setFocus(); QTest::qWait(125); - QVERIFY(leftDial->hasFocus()); + QTRY_VERIFY(leftDial->hasFocus()); EventSpy eventSpy(edit1); EventSpy eventSpy2(edit2); @@ -3249,7 +3262,8 @@ void tst_QGraphicsProxyWidget::updateAndDelete() #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&view); #endif - QTest::qWait(200); + QTest::qWait(20); + QTRY_VERIFY(view.npaints > 0); const QRect itemDeviceBoundingRect = proxy->deviceTransform(view.viewportTransform()) .mapRect(proxy->boundingRect()).toRect(); @@ -3346,9 +3360,10 @@ void tst_QGraphicsProxyWidget::clickFocus() QCOMPARE(widgetSpy.counts[QEvent::FocusIn], 0); QCOMPARE(widgetSpy.counts[QEvent::FocusOut], 0); - // Spontaneous mouse click sets focus on a clickable widget. QPointF lineEditCenter = proxy->mapToScene(proxy->boundingRect().center()); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(lineEditCenter)); + // Spontaneous mouse click sets focus on a clickable widget. + for (int retry = 0; retry < 50 && !proxy->hasFocus(); retry++) + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(lineEditCenter)); QVERIFY(proxy->hasFocus()); QVERIFY(proxy->widget()->hasFocus()); QCOMPARE(proxySpy.counts[QEvent::FocusIn], 1); diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp index 0b731d5..6c1ac54 100644 --- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp @@ -379,7 +379,7 @@ void tst_QGraphicsView::interactive() view.show(); QTestEventLoop::instance().enterLoop(1); - QCOMPARE(item->events.size(), 1); // activate + QTRY_COMPARE(item->events.size(), 1); // activate QPoint itemPoint = view.mapFromScene(item->scenePos()); @@ -1869,6 +1869,9 @@ void tst_QGraphicsView::sendEvent() QGraphicsView view(&scene); view.show(); + QApplication::setActiveWindow(&view); + QTest::qWait(20); + QTRY_COMPARE(QApplication::activeWindow(), &view); QTestEventLoop::instance().enterLoop(1); @@ -1938,7 +1941,10 @@ void tst_QGraphicsView::wheelEvent() #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&view); #endif - QTest::qWait(250); + QApplication::setActiveWindow(&view); + QTest::qWait(20); + QTRY_COMPARE(QApplication::activeWindow(), &view); + // Send a wheel event with horizontal orientation. { @@ -3128,12 +3134,15 @@ void tst_QGraphicsView::moveItemWhileScrolling() setScene(new QGraphicsScene(0, 0, 1000, 1000)); rect = scene()->addRect(0, 0, 10, 10); rect->setPos(50, 50); + painted = false; } QRegion lastPaintedRegion; QGraphicsItem *rect; + bool painted; protected: void paintEvent(QPaintEvent *event) { + painted = true; lastPaintedRegion = event->region(); QGraphicsView::paintEvent(event); } @@ -3152,12 +3161,15 @@ void tst_QGraphicsView::moveItemWhileScrolling() #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&view); #endif - QTest::qWait(200); + QTest::qWait(100); + QTRY_VERIFY(view.painted); + view.painted = false; view.lastPaintedRegion = QRegion(); view.horizontalScrollBar()->setValue(view.horizontalScrollBar()->value() + 10); view.rect->moveBy(0, 10); QTest::qWait(100); + QTRY_VERIFY(view.painted); QRegion expectedRegion; expectedRegion += QRect(0, 0, 200, 200); @@ -3509,7 +3521,9 @@ void tst_QGraphicsView::inputMethodSensitivity() #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&view); #endif - QTest::qWait(300); + QApplication::setActiveWindow(&view); + QTest::qWait(250); + QTRY_COMPARE(QApplication::activeWindow(), &view); QGraphicsRectItem *item = new QGraphicsRectItem; @@ -3599,7 +3613,9 @@ void tst_QGraphicsView::inputContextReset() #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&view); #endif - QTest::qWait(300); + QApplication::setActiveWindow(&view); + QTest::qWait(20); + QTRY_COMPARE(QApplication::activeWindow(), &view); QGraphicsItem *item1 = new QGraphicsRectItem; item1->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemAcceptsInputMethod); diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index 5296788..9045acf 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -230,7 +230,7 @@ public: int eventCount; Qt::LayoutDirection m_painterLayoutDirection; - + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { m_painterLayoutDirection = painter->layoutDirection(); @@ -276,15 +276,15 @@ class SizeHinter : public QGraphicsWidget { public: SizeHinter(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0, - const QSizeF &min = QSizeF(5,5), - const QSizeF &pref = QSizeF(50, 50), - const QSizeF &max = QSizeF(500, 500)) - : QGraphicsWidget(parent, wFlags) + const QSizeF &min = QSizeF(5,5), + const QSizeF &pref = QSizeF(50, 50), + const QSizeF &max = QSizeF(500, 500)) + : QGraphicsWidget(parent, wFlags) { m_sizes[Qt::MinimumSize] = min; m_sizes[Qt::PreferredSize] = pref; m_sizes[Qt::MaximumSize] = max; - + } void setSizeHint(Qt::SizeHint which, const QSizeF &newSizeHint) { @@ -324,11 +324,11 @@ void tst_QGraphicsWidget::qgraphicswidget() QCOMPARE(widget.type(), (int)QGraphicsWidget::Type); QCOMPARE(widget.call_propertyChange(QString(), QVariant()), QVariant()); widget.call_sizeHint(Qt::PreferredSize, QSizeF()); - + QGraphicsScene scene; QGraphicsWidget *parent = new QGraphicsWidget; SizeHinter *child = new SizeHinter(parent); - + QCOMPARE(child->minimumSize(), QSizeF(5, 5)); } @@ -482,7 +482,7 @@ void tst_QGraphicsWidget::focusWidget2() QVERIFY(!widget->hasFocus()); QVERIFY(!subWidget->hasFocus()); - widget->setFocus(); + widget->setFocus(); QVERIFY(widget->hasFocus()); QCOMPARE(focusInSpy.count(), 1); @@ -702,7 +702,7 @@ void tst_QGraphicsWidget::fontPropagationSceneChange() QFont font; font.setPointSize(47); scene.setFont(font); - + QFont font2; font2.setPointSize(74); scene2.setFont(font2); @@ -799,7 +799,9 @@ void tst_QGraphicsWidget::initStyleOption() #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&view); #endif - QTest::qWait(250); + QApplication::setActiveWindow(&view); + QTest::qWait(25); + QTRY_COMPARE(QApplication::activeWindow(), &view); view.setAlignment(Qt::AlignTop | Qt::AlignLeft); SubQGraphicsWidget *widget = new SubQGraphicsWidget; @@ -1132,6 +1134,9 @@ void tst_QGraphicsWidget::setTabOrder() #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&view); #endif + QApplication::setActiveWindow(&view); + QTest::qWait(25); + QTRY_COMPARE(QApplication::activeWindow(), &view); QGraphicsWidget *lastItem = 0; QTest::ignoreMessage(QtWarningMsg, "QGraphicsWidget::setTabOrder(0, 0) is undefined"); @@ -1196,7 +1201,9 @@ void tst_QGraphicsWidget::setTabOrderAndReparent() #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&view); #endif - QTest::qWait(250); + QApplication::setActiveWindow(&view); + QTest::qWait(25); + QTRY_COMPARE(QApplication::activeWindow(), &view); int i; QGraphicsWidget *w1, *w2, *w3, *w4; @@ -1214,29 +1221,29 @@ void tst_QGraphicsWidget::setTabOrderAndReparent() } w1->setFocus(); - QVERIFY(w1->hasFocus()); + QTRY_VERIFY(w1->hasFocus()); QVERIFY(compareFocusChain(&view, QList() << w1 << w2 << w3)); QGraphicsWidget *p = new QGraphicsWidget; p->setData(0, QLatin1String("parent")); p->setFocusPolicy(Qt::StrongFocus); - + w1->setFocus(); QVERIFY(compareFocusChain(&view, QList() << w1 << w2 << w3)); - + w1->setParentItem(p); w2->setFocus(); QVERIFY(compareFocusChain(&view, QList() << w2 << w3)); - + w2->setParentItem(p); w3->setFocus(); QVERIFY(compareFocusChain(&view, QList() << w3)); w3->setParentItem(p); QCOMPARE(scene.focusItem(), static_cast(0)); - + scene.addItem(p); p->setFocus(); - + QVERIFY(compareFocusChain(&view, QList() << p << w1 << w2 << w3)); delete p; @@ -1258,7 +1265,7 @@ void tst_QGraphicsWidget::setTabOrderAndReparent() QGraphicsWidget::setTabOrder(w1, w4); w1->setFocus(); QVERIFY(compareFocusChain(&view, QList() << w1 << w4 << w2 << w3)); - + p = new QGraphicsWidget; p->setData(0, QLatin1String("parent")); p->setFocusPolicy(Qt::StrongFocus); @@ -1266,7 +1273,7 @@ void tst_QGraphicsWidget::setTabOrderAndReparent() w1->setParentItem(p); w2->setFocus(); QVERIFY(compareFocusChain(&view, QList() << w2 << w3)); - + scene.addItem(p); w2->setFocus(); QVERIFY(compareFocusChain(&view, QList() << w2 << w3 << p << w1 << w4)); @@ -1337,7 +1344,10 @@ void tst_QGraphicsWidget::verifyFocusChain() #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&view); #endif - QTest::qWait(250); + QApplication::setActiveWindow(&view); + QTest::qWait(25); + QTRY_COMPARE(QApplication::activeWindow(), &view); + { // parent/child focus SubQGraphicsWidget *w = new SubQGraphicsWidget(0, Qt::Window); @@ -1412,7 +1422,7 @@ void tst_QGraphicsWidget::verifyFocusChain() #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(window); #endif - + lineEdit->setFocus(); QTest::qWait(250); QVERIFY(lineEdit->hasFocus()); @@ -1449,7 +1459,7 @@ void tst_QGraphicsWidget::verifyFocusChain() w1_4->setFocusPolicy(Qt::StrongFocus); w1_4->setData(0, "w1_4"); w1_4->setGeometry(75,0,25, 25); - scene.addItem(w1_4); + scene.addItem(w1_4); QVERIFY(w1_3->hasFocus()); QTest::qWait(250); QVERIFY(compareFocusChain(view, QList() << w1_3 << w1_4)); @@ -1459,7 +1469,7 @@ void tst_QGraphicsWidget::verifyFocusChain() // tabFocusFirst should now point to w1_3 QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); QTest::qWait(250); - QVERIFY(w1_3->hasFocus()); + QVERIFY(w1_3->hasFocus()); QTest::qWait(250); QVERIFY(compareFocusChain(view, QList() << w1_3 << w1_4)); delete window; @@ -1474,7 +1484,9 @@ void tst_QGraphicsWidget::updateFocusChainWhenChildDie() #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&view); #endif - QTest::qWait(250); + QApplication::setActiveWindow(&view); + QTest::qWait(25); + QTRY_COMPARE(QApplication::activeWindow(), &view); // delete item in focus chain with no focus and verify chain SubQGraphicsWidget *parent = new SubQGraphicsWidget(0, Qt::Window); @@ -1628,7 +1640,7 @@ void tst_QGraphicsWidget::setSizes_data() << (QVector() << Inst(MinimumSize, QSizeF(5, 5))); QTest::newRow("unsetMaxSize")<< (QVector() << Inst(Size, QSizeF(40, 40)) << Inst(MaximumSize, QSizeF(-1, -1))) << (QVector() << Inst(MaximumSize, QSizeF(500, 500))); - QTest::newRow("unsetMinSize, expand size to minimumSizeHint") << (QVector() + QTest::newRow("unsetMinSize, expand size to minimumSizeHint") << (QVector() << Inst(MinimumSize, QSize(0, 0)) << Inst(Size, QSize(1,1)) << Inst(MinimumSize, QSize(-1.0, -1.0)) @@ -1708,7 +1720,7 @@ void tst_QGraphicsWidget::setSizes() widget->setMaximumSize(max); QApplication::processEvents(); - + for (i = 0; i < compareInstructions.count(); ++i) { Inst input = compareInstructions.at(i); switch (input.first) { @@ -2432,7 +2444,9 @@ void tst_QGraphicsWidget::task250119_shortcutContext() QGraphicsView view; view.setScene(&scene); view.show(); - QTest::qWait(100); + QApplication::setActiveWindow(&view); + QTest::qWait(25); + QTRY_COMPARE(QApplication::activeWindow(), &view); // *** Event: *** -- cgit v0.12