diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-09-08 08:45:57 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-09-08 08:49:39 (GMT) |
commit | fa889cf4b80868249c70715275069eb150b597cc (patch) | |
tree | ab98dc0979d7c2874902e7f2a9812843104e1c49 /tests/auto/qmdisubwindow | |
parent | deff8fcf0ed060b949c3ec0fa0ec4bd81c253825 (diff) | |
download | Qt-fa889cf4b80868249c70715275069eb150b597cc.zip Qt-fa889cf4b80868249c70715275069eb150b597cc.tar.gz Qt-fa889cf4b80868249c70715275069eb150b597cc.tar.bz2 |
Try to make test more robust.
By using QTRY_{COMPARE,VERIFY} instead of waiting an arbitrary amount of
time waiting for the window manager to do his job.
Also use QApplication::setActiveWindow which seems to be more robust
then QWidget::activateWindow
Diffstat (limited to 'tests/auto/qmdisubwindow')
-rw-r--r-- | tests/auto/qmdisubwindow/tst_qmdisubwindow.cpp | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/tests/auto/qmdisubwindow/tst_qmdisubwindow.cpp b/tests/auto/qmdisubwindow/tst_qmdisubwindow.cpp index 78ba46b..4d5160b 100644 --- a/tests/auto/qmdisubwindow/tst_qmdisubwindow.cpp +++ b/tests/auto/qmdisubwindow/tst_qmdisubwindow.cpp @@ -63,6 +63,9 @@ #include <QMacStyle> #endif +#include "../../shared/util.h" + + QT_BEGIN_NAMESPACE #if defined(Q_WS_X11) extern void qt_x11_wait_for_window_manager(QWidget *w); @@ -1004,15 +1007,16 @@ void tst_QMdiSubWindow::setSystemMenu() qt_x11_wait_for_window_manager(&mainWindow); #endif - QVERIFY(subWindow->isVisible()); - QPoint globalPopupPos = subWindow->mapToGlobal(subWindow->contentsRect().topLeft()); + QTRY_VERIFY(subWindow->isVisible()); + QPoint globalPopupPos; // Show system menu QVERIFY(!qApp->activePopupWidget()); subWindow->showSystemMenu(); - QTest::qWait(250); - QCOMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); - QCOMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); + QTest::qWait(25); + QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); + QTRY_COMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), + (globalPopupPos = subWindow->mapToGlobal(subWindow->contentsRect().topLeft())) ); systemMenu->hide(); QVERIFY(!qApp->activePopupWidget()); @@ -1034,9 +1038,9 @@ void tst_QMdiSubWindow::setSystemMenu() // Show the new system menu QVERIFY(!qApp->activePopupWidget()); subWindow->showSystemMenu(); - QTest::qWait(250); - QCOMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); - QCOMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); + QTest::qWait(25); + QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); + QTRY_COMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); systemMenu->hide(); QVERIFY(!qApp->activePopupWidget()); @@ -1048,12 +1052,12 @@ void tst_QMdiSubWindow::setSystemMenu() QWidget *menuLabel = subWindow->maximizedSystemMenuIconWidget(); QVERIFY(menuLabel); subWindow->showSystemMenu(); - QTest::qWait(250); - QCOMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); - globalPopupPos = menuLabel->mapToGlobal(QPoint(0, menuLabel->y() + menuLabel->height())); - QCOMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); + QTest::qWait(25); + QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); + QCOMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), + (globalPopupPos = menuLabel->mapToGlobal(QPoint(0, menuLabel->y() + menuLabel->height())))); systemMenu->hide(); - QVERIFY(!qApp->activePopupWidget()); + QTRY_VERIFY(!qApp->activePopupWidget()); subWindow->showNormal(); #endif @@ -1064,11 +1068,11 @@ void tst_QMdiSubWindow::setSystemMenu() subWindow->showSystemMenu(); QTest::qWait(250); - QCOMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); + QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); // + QPoint(1, 0) because topRight() == QPoint(left() + width() -1, top()) globalPopupPos = subWindow->mapToGlobal(subWindow->contentsRect().topRight()) + QPoint(1, 0); globalPopupPos -= QPoint(systemMenu->sizeHint().width(), 0); - QCOMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); + QTRY_COMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); systemMenu->hide(); QVERIFY(!qApp->activePopupWidget()); @@ -1081,10 +1085,10 @@ void tst_QMdiSubWindow::setSystemMenu() QVERIFY(menuLabel); subWindow->showSystemMenu(); QTest::qWait(250); - QCOMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); + QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); globalPopupPos = menuLabel->mapToGlobal(QPoint(menuLabel->width(), menuLabel->y() + menuLabel->height())); globalPopupPos -= QPoint(systemMenu->sizeHint().width(), 0); - QCOMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); + QTRY_COMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); #endif delete systemMenu; @@ -1902,7 +1906,7 @@ void tst_QMdiSubWindow::task_182852() mainWindow.show(); mainWindow.menuBar()->setVisible(true); qApp->setActiveWindow(&mainWindow); - + QString originalWindowTitle = QString::fromLatin1("MainWindow - [foo]"); mainWindow.setWindowTitle(originalWindowTitle); @@ -1917,7 +1921,7 @@ void tst_QMdiSubWindow::task_182852() window->showMaximized(); qApp->processEvents(); QVERIFY(window->isMaximized()); - + QCOMPARE(mainWindow.windowTitle(), QString::fromLatin1("%1 - [%2]") .arg(originalWindowTitle, window->widget()->windowTitle())); |