summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorToby Tomkins <toby.tomkins@nokia.com>2010-03-18 05:44:10 (GMT)
committerToby Tomkins <toby.tomkins@nokia.com>2010-03-18 05:44:10 (GMT)
commitbbc16f62a3d3e53532c37672b23047302fbeb1a5 (patch)
tree73f7432b3936d4d81bc6511faea35100ffb6b9a5 /tests/auto
parent83e321747920c31d6fa4c860de3683630fbedb5d (diff)
downloadQt-bbc16f62a3d3e53532c37672b23047302fbeb1a5.zip
Qt-bbc16f62a3d3e53532c37672b23047302fbeb1a5.tar.gz
Qt-bbc16f62a3d3e53532c37672b23047302fbeb1a5.tar.bz2
Fixed stability issues in qgraphicswidget tests
Remove qWait functions as it is used in QTRY_* macros. Reviewed-by: rohan mcgovern
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp132
1 files changed, 47 insertions, 85 deletions
diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
index 00bf144..4a874be 100644
--- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
+++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
@@ -461,7 +461,7 @@ void tst_QGraphicsWidget::focusWidget()
QFETCH(int, childWithFocus);
SubQGraphicsWidget *widget = children[childWithFocus];
widget->setFocus();
- QVERIFY(widget->hasFocus());
+ QTRY_VERIFY(widget->hasFocus());
QCOMPARE(parent->focusWidget(), static_cast<QGraphicsWidget*>(widget));
}
}
@@ -478,23 +478,23 @@ void tst_QGraphicsWidget::focusWidget2()
scene.addItem(widget);
- QVERIFY(!widget->hasFocus());
+ QTRY_VERIFY(!widget->hasFocus());
widget->setFocusPolicy(Qt::StrongFocus);
- QVERIFY(!widget->hasFocus());
+ QTRY_VERIFY(!widget->hasFocus());
QGraphicsWidget *subWidget = new QGraphicsWidget(widget);
- QVERIFY(!subWidget->hasFocus());
+ QTRY_VERIFY(!subWidget->hasFocus());
scene.setFocus();
- QVERIFY(!widget->hasFocus());
- QVERIFY(!subWidget->hasFocus());
+ QTRY_VERIFY(!widget->hasFocus());
+ QTRY_VERIFY(!subWidget->hasFocus());
widget->setFocus();
- QVERIFY(widget->hasFocus());
- QCOMPARE(focusInSpy.count(), 1);
- QVERIFY(!subWidget->hasFocus());
+ QTRY_VERIFY(widget->hasFocus());
+ QTRY_COMPARE(focusInSpy.count(), 1);
+ QTRY_VERIFY(!subWidget->hasFocus());
QGraphicsWidget *otherSubWidget = new QGraphicsWidget;
EventSpy otherFocusInSpy(otherSubWidget, QEvent::FocusIn);
@@ -503,18 +503,18 @@ void tst_QGraphicsWidget::focusWidget2()
otherSubWidget->setFocusPolicy(Qt::StrongFocus);
otherSubWidget->setParentItem(widget);
- QVERIFY(widget->hasFocus());
+ QTRY_VERIFY(widget->hasFocus());
QCOMPARE(scene.focusItem(), (QGraphicsItem *)widget);
- QVERIFY(!subWidget->hasFocus());
- QVERIFY(!otherSubWidget->hasFocus());
+ QTRY_VERIFY(!subWidget->hasFocus());
+ QTRY_VERIFY(!otherSubWidget->hasFocus());
widget->hide();
- QVERIFY(!widget->hasFocus()); // lose but still has subfocus
+ QTRY_VERIFY(!widget->hasFocus()); // lose but still has subfocus
QCOMPARE(focusInSpy.count(), 1);
QCOMPARE(focusOutSpy.count(), 1);
widget->show();
- QVERIFY(!widget->hasFocus()); // no regain
+ QTRY_VERIFY(!widget->hasFocus()); // no regain
QCOMPARE(focusInSpy.count(), 1);
QCOMPARE(focusOutSpy.count(), 1);
@@ -522,24 +522,24 @@ void tst_QGraphicsWidget::focusWidget2()
// try to setup subFocus on item that can't take focus
subWidget->setFocus();
- QVERIFY(!subWidget->hasFocus());
+ QTRY_VERIFY(!subWidget->hasFocus());
QVERIFY(!scene.focusItem()); // but isn't the scene's focus item
// try to setup subFocus on item that can take focus
otherSubWidget->setFocus();
- QVERIFY(!otherSubWidget->hasFocus());
+ QTRY_VERIFY(!otherSubWidget->hasFocus());
QCOMPARE(widget->focusWidget(), otherSubWidget);
QVERIFY(!scene.focusItem()); // but isn't the scene's focus item
widget->show();
- QCOMPARE(scene.focusItem(), (QGraphicsItem *)otherSubWidget); // but isn't the scene's focus item
+ QTRY_COMPARE(scene.focusItem(), (QGraphicsItem *)otherSubWidget); // but isn't the scene's focus item
QCOMPARE(otherFocusInSpy.count(), 1);
QCOMPARE(otherFocusOutSpy.count(), 0);
delete otherSubWidget;
- QCOMPARE(otherFocusOutSpy.count(), 1);
+ QTRY_COMPARE(otherFocusOutSpy.count(), 1);
QVERIFY(!scene.focusItem());
QVERIFY(!widget->focusWidget());
}
@@ -578,16 +578,16 @@ void tst_QGraphicsWidget::focusPolicy()
SubQGraphicsWidget *widget = new SubQGraphicsWidget;
scene.addItem(widget);
- QCOMPARE(Qt::NoFocus, widget->focusPolicy());
+ QTRY_COMPARE(Qt::NoFocus, widget->focusPolicy());
QFETCH(Qt::FocusPolicy, focusPolicy1);
widget->setFocusPolicy(focusPolicy1);
- QCOMPARE(widget->focusPolicy(), focusPolicy1);
+ QTRY_COMPARE(widget->focusPolicy(), focusPolicy1);
bool isFocusable = widget->flags() & QGraphicsItem::ItemIsFocusable;
bool wasFocusable = isFocusable;
- QVERIFY(isFocusable == (focusPolicy1 != Qt::NoFocus));
+ QTRY_VERIFY(isFocusable == (focusPolicy1 != Qt::NoFocus));
widget->setFocus();
- QCOMPARE(widget->hasFocus(), isFocusable);
+ QTRY_COMPARE(widget->hasFocus(), isFocusable);
QFETCH(Qt::FocusPolicy, focusPolicy2);
widget->setFocusPolicy(focusPolicy2);
@@ -690,25 +690,21 @@ void tst_QGraphicsWidget::fontChangedEvent()
EventSpy rootSpyFont(root, QEvent::FontChange);
EventSpy rootSpyPolish(root, QEvent::Polish);
- QCOMPARE(rootSpyFont.count(), 0);
- QApplication::processEvents(); //The polish event is sent
- QCOMPARE(rootSpyPolish.count(), 1);
- QApplication::processEvents(); //Process events to see if we get the font change event
+ QTRY_COMPARE(rootSpyFont.count(), 0);
+ QTRY_COMPARE(rootSpyPolish.count(), 1);
//The font is still the same so no fontChangeEvent
- QCOMPARE(rootSpyFont.count(), 0);
+ QTRY_COMPARE(rootSpyFont.count(), 0);
QFont font;
font.setPointSize(43);
root->setFont(font);
- QApplication::processEvents(); //Process events to get the font change event
//The font changed
- QCOMPARE(rootSpyFont.count(), 1);
+ QTRY_COMPARE(rootSpyFont.count(), 1);
//then roll back to the default one.
root->setFont(appFont);
- QApplication::processEvents(); //Process events to get the font change event
//The font changed
- QCOMPARE(rootSpyFont.count(), 2);
+ QTRY_COMPARE(rootSpyFont.count(), 2);
}
void tst_QGraphicsWidget::fontPropagationWidgetItemWidget()
@@ -842,7 +838,6 @@ void tst_QGraphicsWidget::initStyleOption()
qt_x11_wait_for_window_manager(&view);
#endif
QApplication::setActiveWindow(&view);
- QTest::qWait(25);
QTRY_COMPARE(QApplication::activeWindow(), &view);
view.setAlignment(Qt::AlignTop | Qt::AlignLeft);
@@ -867,7 +862,6 @@ void tst_QGraphicsWidget::initStyleOption()
view.resize(300, 300);
view.show();
QTest::qWaitForWindowShown(&view);
- QTest::qWait(20);
sendMouseMove(view.viewport(), view.mapFromScene(widget->mapToScene(widget->boundingRect().center())));
}
@@ -920,9 +914,7 @@ void tst_QGraphicsWidget::layout()
}
widget.setLayout(layout);
- QTest::qWait(25);
-
- QCOMPARE(widget.layout(), static_cast<QGraphicsLayout*>(layout));
+ QTRY_COMPARE(widget.layout(), static_cast<QGraphicsLayout*>(layout));
for (int i = 0; i < children.count(); ++i) {
SubQGraphicsWidget *item = children[i];
QCOMPARE(item->parentWidget(), (QGraphicsWidget *)&widget);
@@ -962,10 +954,9 @@ void tst_QGraphicsWidget::layoutDirection()
view->show();
QTest::qWaitForWindowShown(view);
for (int i = 0; i < children.count(); ++i) {
- QCOMPARE(children[i]->layoutDirection(), layoutDirection);
- QCOMPARE(children[i]->testAttribute(Qt::WA_SetLayoutDirection), false);
+ QTRY_COMPARE(children[i]->layoutDirection(), layoutDirection);
+ QTRY_COMPARE(children[i]->testAttribute(Qt::WA_SetLayoutDirection), false);
view->repaint();
- QApplication::processEvents();
QTRY_COMPARE(children[i]->m_painterLayoutDirection, layoutDirection);
}
delete view;
@@ -1178,7 +1169,6 @@ void tst_QGraphicsWidget::setTabOrder()
qt_x11_wait_for_window_manager(&view);
#endif
QApplication::setActiveWindow(&view);
- QTest::qWait(25);
QTRY_COMPARE(QApplication::activeWindow(), &view);
QGraphicsWidget *lastItem = 0;
@@ -1199,7 +1189,6 @@ void tst_QGraphicsWidget::setTabOrder()
if (!children.isEmpty()) {
QGraphicsWidget *first = children.first();
view.viewport()->setFocus();
- QApplication::processEvents();
QTRY_VERIFY(view.viewport()->hasFocus());
first->setFocus();
QVERIFY(first->hasFocus());
@@ -1460,18 +1449,14 @@ void tst_QGraphicsWidget::verifyFocusChain()
QTest::qWaitForWindowShown(window);
lineEdit->setFocus();
- QTest::qWait(25);
QTRY_VERIFY(lineEdit->hasFocus());
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(25);
QTRY_VERIFY(w1_1->hasFocus());
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(25);
QTRY_VERIFY(w1_2->hasFocus());
// remove the tabFocusFirst and insert new item
delete w1_1; // calls _q_removeItemLater
- QTest::qWait(25);
SubQGraphicsWidget *w1_3 = new SubQGraphicsWidget;
w1_3->setFocusPolicy(Qt::StrongFocus);
w1_3->setData(0, "w1_3");
@@ -1479,14 +1464,11 @@ void tst_QGraphicsWidget::verifyFocusChain()
scene.addItem(w1_3);
QTRY_VERIFY(w1_2->hasFocus());
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
- QTest::qWait(25);
QTRY_VERIFY(lineEdit->hasFocus());
// tabFocusFirst should now point to w1_2
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(25);
QTRY_VERIFY(w1_2->hasFocus());
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(25);
QTRY_VERIFY(w1_3->hasFocus());
scene.removeItem(w1_2); // does not call _q_removeItemLater
delete w1_2; // calls _q_removeItemLater
@@ -1497,16 +1479,12 @@ void tst_QGraphicsWidget::verifyFocusChain()
w1_4->setGeometry(75,0,25, 25);
scene.addItem(w1_4);
QTRY_VERIFY(w1_3->hasFocus());
- QTest::qWait(25);
QTRY_VERIFY(compareFocusChain(view, QList<QGraphicsItem*>() << w1_3 << w1_4));
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
- QTest::qWait(25);
QTRY_VERIFY(lineEdit->hasFocus());
// tabFocusFirst should now point to w1_3
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(25);
QTRY_VERIFY(w1_3->hasFocus());
- QTest::qWait(25);
QTRY_VERIFY(compareFocusChain(view, QList<QGraphicsItem*>() << w1_3 << w1_4));
delete window;
}
@@ -1521,7 +1499,6 @@ void tst_QGraphicsWidget::updateFocusChainWhenChildDie()
qt_x11_wait_for_window_manager(&view);
#endif
QApplication::setActiveWindow(&view);
- QTest::qWait(25);
QTRY_COMPARE(QApplication::activeWindow(), &view);
// delete item in focus chain with no focus and verify chain
@@ -1755,31 +1732,29 @@ void tst_QGraphicsWidget::setSizes()
widget->setPreferredSize(pref);
widget->setMaximumSize(max);
- QApplication::processEvents();
-
for (i = 0; i < compareInstructions.count(); ++i) {
Inst input = compareInstructions.at(i);
switch (input.first) {
case MinimumSize:
- QCOMPARE(widget->minimumSize(), input.second.toSizeF());
+ QTRY_COMPARE(widget->minimumSize(), input.second.toSizeF());
break;
case PreferredSize:
- QCOMPARE(widget->preferredSize(), input.second.toSizeF());
+ QTRY_COMPARE(widget->preferredSize(), input.second.toSizeF());
break;
case MaximumSize:
- QCOMPARE(widget->maximumSize(), input.second.toSizeF());
+ QTRY_COMPARE(widget->maximumSize(), input.second.toSizeF());
break;
case Size:
- QCOMPARE(widget->size(), input.second.toSizeF());
+ QTRY_COMPARE(widget->size(), input.second.toSizeF());
break;
case MinimumWidth:
- QCOMPARE(widget->minimumWidth(), qreal(input.second.toDouble()));
+ QTRY_COMPARE(widget->minimumWidth(), qreal(input.second.toDouble()));
break;
case PreferredWidth:
- QCOMPARE(widget->preferredWidth(), qreal(input.second.toDouble()));
+ QTRY_COMPARE(widget->preferredWidth(), qreal(input.second.toDouble()));
break;
case MaximumWidth:
- QCOMPARE(widget->maximumWidth(), qreal(input.second.toDouble()));
+ QTRY_COMPARE(widget->maximumWidth(), qreal(input.second.toDouble()));
break;
default:
qWarning("instruction not implemented");
@@ -1834,14 +1809,13 @@ void tst_QGraphicsWidget::task236127_bspTreeIndexFails()
#ifdef Q_WS_X11
qt_x11_wait_for_window_manager(&view);
#endif
- QTest::qWait(100);
- QVERIFY(!scene.itemAt(25, 25));
+ QTRY_VERIFY(!scene.itemAt(25, 25));
widget->setGeometry(0, 112, 360, 528);
- QCOMPARE(scene.itemAt(15, 120), (QGraphicsItem *)widget);
+ QTRY_COMPARE(scene.itemAt(15, 120), (QGraphicsItem *)widget);
widget2->setGeometry(0, 573, 360, 67);
- QCOMPARE(scene.itemAt(15, 120), (QGraphicsItem *)widget);
- QCOMPARE(scene.itemAt(50, 585), (QGraphicsItem *)widget2);
+ QTRY_COMPARE(scene.itemAt(15, 120), (QGraphicsItem *)widget);
+ QTRY_COMPARE(scene.itemAt(50, 585), (QGraphicsItem *)widget2);
}
void tst_QGraphicsWidget::defaultSize()
@@ -1856,7 +1830,6 @@ void tst_QGraphicsWidget::defaultSize()
#ifdef Q_WS_X11
qt_x11_wait_for_window_manager(&view);
#endif
- QTest::qWait(50);
QSizeF initialSize = widget->size();
widget->resize(initialSize);
@@ -1866,9 +1839,8 @@ void tst_QGraphicsWidget::defaultSize()
widget->setPreferredSize(60, 60);
widget->setMaximumSize(110, 110);
widget->setVisible(true);
- QTest::qWait(50);
// should still have its size set to initialsize
- QCOMPARE(widget->geometry().size(), initialSize);
+ QTRY_COMPARE(widget->geometry().size(), initialSize);
}
@@ -2390,7 +2362,6 @@ void tst_QGraphicsWidget::painterStateProtectionOnWindowFrame()
scene.addItem(widget);
view.show();
QTest::qWaitForWindowShown(&view);
- QTest::qWait(500);
}
class ProxyStyle : public QCommonStyle
@@ -2479,7 +2450,6 @@ void tst_QGraphicsWidget::task250119_shortcutContext()
view.setScene(&scene);
view.show();
QApplication::setActiveWindow(&view);
- QTest::qWait(25);
QTRY_COMPARE(QApplication::activeWindow(), &view);
@@ -2734,9 +2704,7 @@ void tst_QGraphicsWidget::respectHFW()
QTest::qWaitForWindowShown(view);
{ // here we go - simulate a interactive resize of the window
- QTest::qWait(100);
QTest::mouseMove(view, view->mapFromScene(71, 71)); // bottom right corner
- QTest::qWait(100);
QTest::mousePress(view->viewport(), Qt::LeftButton, 0, view->mapFromScene(71, 71), 200);
view->grabMouse();
@@ -2750,10 +2718,9 @@ void tst_QGraphicsWidget::respectHFW()
QApplication::sendEvent(view->viewport(), &e);
view->releaseMouse();
}
- QTest::qWait(100);
const QSizeF winSize = window->size();
qreal minHFW = window->effectiveSizeHint(Qt::MinimumSize, QSizeF(winSize.width(), -1)).height();
- QVERIFY(qAbs(minHFW - winSize.height()) < 1);
+ QTRY_VERIFY(qAbs(minHFW - winSize.height()) < 1);
#endif
}
@@ -2805,7 +2772,7 @@ void tst_QGraphicsWidget::addChildInpolishEvent()
view.resize(200, 200);
view.show();
QTest::qWaitForWindowShown(&view);
- QCOMPARE(PolishWidget::numberOfPolish, 2);
+ QTRY_COMPARE(PolishWidget::numberOfPolish, 2);
}
void tst_QGraphicsWidget::polishEvent()
@@ -2852,10 +2819,8 @@ void tst_QGraphicsWidget::polishEvent2()
widget->events.clear();
- QApplication::processEvents();
-
// Make sure the item got polish event.
- QVERIFY(widget->events.contains(QEvent::Polish));
+ QTRY_VERIFY(widget->events.contains(QEvent::Polish));
}
void tst_QGraphicsWidget::initialShow()
@@ -2875,11 +2840,9 @@ void tst_QGraphicsWidget::initialShow()
view.show();
QTest::qWaitForWindowShown(&view);
- QTest::qWait(100);
scene.addItem(widget);
- QTest::qWait(100);
- QCOMPARE(widget->repaints, 1);
+ QTRY_COMPARE(widget->repaints, 1);
}
void tst_QGraphicsWidget::initialShow2()
@@ -2908,7 +2871,6 @@ void tst_QGraphicsWidget::initialShow2()
const int expectedRepaintCount = paintSpy.count();
delete dummyView;
dummyView = 0;
- QTest::qWait(200);
MyGraphicsWidget *widget = new MyGraphicsWidget;
widget->resize(100, 100);
@@ -2921,7 +2883,7 @@ void tst_QGraphicsWidget::initialShow2()
view.show();
QTest::qWaitForWindowShown(&view);
- QCOMPARE(widget->repaints, expectedRepaintCount);
+ QTRY_COMPARE(widget->repaints, expectedRepaintCount);
}
void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems()