summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorminiak <milan.burda@gmail.com>2010-04-07 09:01:05 (GMT)
committerBenjamin Poulain <benjamin.poulain@nokia.com>2010-04-07 09:01:20 (GMT)
commit6947390e5d331ae653e91acecad70108915328e7 (patch)
tree2220135c05cf7695d553e7dbdff6aad31f249bdc /tests
parentee3a237262071721755075d6ae958aec744f5c87 (diff)
downloadQt-6947390e5d331ae653e91acecad70108915328e7.zip
Qt-6947390e5d331ae653e91acecad70108915328e7.tar.gz
Qt-6947390e5d331ae653e91acecad70108915328e7.tar.bz2
Test case for QMenu::popup()
Verifies that the menu shown is fully contained on the screen. The actual menu position on the screen is checked as well. Merge-request: 551 Reviewed-by: Benjamin Poulain <benjamin.poulain@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qmenu/tst_qmenu.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/auto/qmenu/tst_qmenu.cpp b/tests/auto/qmenu/tst_qmenu.cpp
index e10d7ee..4be6fdd 100644
--- a/tests/auto/qmenu/tst_qmenu.cpp
+++ b/tests/auto/qmenu/tst_qmenu.cpp
@@ -106,6 +106,8 @@ private slots:
void pushButtonPopulateOnAboutToShow();
void QTBUG7907_submenus_autoselect();
void QTBUG7411_submenus_activate();
+ void menuGeometry_data();
+ void menuGeometry();
protected slots:
void onActivated(QAction*);
void onHighlighted(QAction*);
@@ -967,6 +969,60 @@ void tst_QMenu::QTBUG7411_submenus_activate()
QTRY_VERIFY(sub1.isVisible());
}
+void tst_QMenu::menuGeometry_data()
+{
+ QTest::addColumn<QRect>("screen");
+ QTest::addColumn<QPoint>("pos");
+ QTest::addColumn<QPoint>("expectedPos");
+
+ QMenu menu("Test Menu");
+ for (int i = 0; i < 3; ++i)
+ menu.addAction("Hello World!");
+
+ menu.adjustSize();
+
+ const int screenCount = QApplication::desktop()->screenCount();
+ const int desktopFrame = menu.style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, &menu);
+
+ for (int i = 0; i < screenCount; ++i) {
+ const QRect screen = QApplication::desktop()->screenGeometry(i);
+
+ if (screen.width() < menu.width() || screen.height() < menu.height())
+ continue;
+
+ QTest::newRow("topLeft") << screen << screen.topLeft()
+ << QPoint(screen.left() + desktopFrame, screen.top() + desktopFrame);
+
+ QTest::newRow("topRight") << screen << screen.topRight()
+ << QPoint(screen.right() - desktopFrame - menu.width() + 1, screen.top() + desktopFrame);
+
+ QTest::newRow("bottomLeft") << screen << screen.bottomLeft()
+ << QPoint(screen.left() + desktopFrame, screen.bottom() - desktopFrame - menu.height() + 1);
+
+ QTest::newRow("bottomRight") << screen << screen.bottomRight()
+ << QPoint(screen.right() - desktopFrame - menu.width() + 1, screen.bottom() - desktopFrame - menu.height() + 1);
+
+ const QPoint pos = QPoint(screen.right() - qMax(desktopFrame, 20), screen.bottom() - qMax(desktopFrame, 20));
+ QTest::newRow("position") << screen << pos
+ << QPoint(screen.right() - menu.width() + 1, pos.y() - menu.height() + 1);
+ }
+}
+
+void tst_QMenu::menuGeometry()
+{
+ QFETCH(QRect, screen);
+ QFETCH(QPoint, pos);
+ QFETCH(QPoint, expectedPos);
+
+ QMenu menu("Test Menu");
+ for (int i = 0; i < 3; ++i)
+ menu.addAction("Hello World!");
+
+ menu.popup(pos);
+ QTest::qWaitForWindowShown(&menu);
+ QVERIFY(screen.contains(menu.geometry()));
+ QCOMPARE(menu.pos(), expectedPos);
+}
QTEST_MAIN(tst_QMenu)