summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp')
-rw-r--r--tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp241
1 files changed, 15 insertions, 226 deletions
diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
index 461839ebd6..7c1fb97b97 100644
--- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
+++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -93,13 +93,6 @@ private slots:
#endif
void allowActiveAndDisabled();
void taskQTBUG56860_focus();
- void check_endKey();
- void check_homeKey();
-
-// void check_mouse1_data();
-// void check_mouse1();
-// void check_mouse2_data();
-// void check_mouse2();
void check_altPress();
void check_altClosePress();
@@ -336,7 +329,6 @@ void tst_QMenuBar::accel()
QMainWindow w;
const TestMenu menu = initWindowWithSimpleMenuBar(w);
w.show();
- QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
// shortcuts won't work unless the window is active
QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_A, Qt::ControlModifier );
@@ -358,7 +350,6 @@ void tst_QMenuBar::activatedCount()
QFETCH( bool, forceNonNative );
initWindowWithSimpleMenuBar(w, forceNonNative);
w.show();
- QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_A, Qt::ControlModifier );
@@ -558,7 +549,6 @@ void tst_QMenuBar::check_accelKeys()
QMainWindow w;
initWindowWithComplexMenuBar(w);
w.show();
- QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
// start with a bogus key that shouldn't trigger anything
@@ -637,7 +627,6 @@ void tst_QMenuBar::check_cursorKeys1()
QMainWindow w;
initWindowWithComplexMenuBar(w);
w.show();
- QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
// start with a ALT + 1 that activates the first popupmenu
@@ -677,7 +666,6 @@ void tst_QMenuBar::check_cursorKeys2()
QMainWindow w;
initWindowWithComplexMenuBar(w);
w.show();
- QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
// select popupmenu2
@@ -716,7 +704,6 @@ void tst_QMenuBar::check_cursorKeys3()
QMainWindow w;
initWindowWithComplexMenuBar(w);
w.show();
- QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
// select Popupmenu 2
@@ -758,7 +745,6 @@ void tst_QMenuBar::taskQTBUG56860_focus()
w.setCentralWidget(e);
w.show();
- QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
QTRY_COMPARE(QApplication::focusWidget(), e);
@@ -785,85 +771,6 @@ void tst_QMenuBar::taskQTBUG56860_focus()
}
/*!
- If a popupmenu is active you can use home to go quickly to the first item in the menu.
-*/
-void tst_QMenuBar::check_homeKey()
-{
- // I'm temporarily shutting up this testcase.
- // Seems like the behaviour i'm expecting isn't ok.
- QSKIP("This test has been \"temporarily\" disabled at least since 2009 :)");
-
- QEXPECT_FAIL( "0", "Popupmenu should respond to a Home key", Abort );
-
- QMainWindow w;
- initWindowWithComplexMenuBar(w);
- w.show();
- QApplicationPrivate::setActiveWindow(&w);
- QVERIFY(QTest::qWaitForWindowActive(&w));
-
- // select Popupmenu 2
- QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_2, Qt::AltModifier );
-
- // Simulate some keys
- QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_Down );
- QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_Down );
- QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_Down );
- QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_Home );
- // and press ENTER
- QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_Enter );
- // Let's see if the correct slot is called...
-// QVERIFY2( m_complexActionTriggerCount[int('c')] == 1, "Popupmenu should respond to a Home key" );
- QCOMPARE(m_complexTriggerCount[int('c')], 1);
- QCOMPARE(m_complexTriggerCount[3], 0);
- QCOMPARE(m_complexTriggerCount[4], 0);
- QCOMPARE(m_complexTriggerCount[int('a')], 0);
- QCOMPARE(m_complexTriggerCount[int('b')], 0);
- QCOMPARE(m_complexTriggerCount[int('d')], 0);
- QCOMPARE(m_complexTriggerCount[int('e')], 0);
- QCOMPARE(m_complexTriggerCount[int('f')], 0);
- QCOMPARE(m_complexTriggerCount[int('g')], 0);
- QCOMPARE(m_complexTriggerCount[int('h')], 0);
-}
-
-/*!
- If a popupmenu is active you can use end to go quickly to the last item in the menu.
-*/
-void tst_QMenuBar::check_endKey()
-{
- // I'm temporarily silenting this testcase.
- // Seems like the behaviour i'm expecting isn't ok.
- QSKIP("This test has been \"temporarily\" disabled at least since 2009 :)");
-
- QEXPECT_FAIL( "0", "Popupmenu should respond to an End key", Abort );
-
- QMainWindow w;
- initWindowWithComplexMenuBar(w);
- w.show();
- QApplicationPrivate::setActiveWindow(&w);
- QVERIFY(QTest::qWaitForWindowActive(&w));
-
- // select Popupmenu 2
- QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_2, Qt::AltModifier );
-
- // Simulate some keys
- QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_End );
- // and press ENTER
- QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_Enter );
- // Let's see if the correct slot is called...
-// QVERIFY2( m_complexActionTriggerCount[int('h')] == 1, "Popupmenu should respond to an End key" );
- QCOMPARE(m_complexTriggerCount[int('h')], 1);//, "Popupmenu should respond to an End key");
- QCOMPARE(m_complexTriggerCount[3], 0);
- QCOMPARE(m_complexTriggerCount[4], 0);
- QCOMPARE(m_complexTriggerCount[int('a')], 0);
- QCOMPARE(m_complexTriggerCount[int('b')], 0);
- QCOMPARE(m_complexTriggerCount[int('c')], 0);
- QCOMPARE(m_complexTriggerCount[int('d')], 0);
- QCOMPARE(m_complexTriggerCount[int('e')], 0);
- QCOMPARE(m_complexTriggerCount[int('f')], 0);
- QCOMPARE(m_complexTriggerCount[int('g')], 0);
-}
-
-/*!
If a popupmenu is active you can use esc to hide the menu and then the
menubar should become active.
If Down is pressed next the popup is activated again.
@@ -880,7 +787,6 @@ void tst_QMenuBar::check_escKey()
const TestMenu menu = initWindowWithComplexMenuBar(w);
w.show();
w.setFocus();
- QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
QVERIFY( !menu.menus.at(0)->isActiveWindow() );
@@ -918,112 +824,6 @@ void tst_QMenuBar::check_escKey()
#endif
-// void tst_QMenuBar::check_mouse1_data()
-// {
-// QTest::addColumn<QString>("popup_item");
-// QTest::addColumn<int>("itemA_count");
-// QTest::addColumn<int>("itemB_count");
-
-// QTest::newRow( "A" ) << QString( "Item A Ctrl+A" ) << 1 << 0;
-// QTest::newRow( "B" ) << QString( "Item B Ctrl+B" ) << 0 << 1;
-// }
-
-// /*!
-// Check if the correct signals are emitted if we select a popupmenu.
-// */
-// void tst_QMenuBar::check_mouse1()
-// {
-// if (QSystem::curStyle() == "Motif")
-// QSKIP("This fails in Motif due to a bug in the testing framework");
-// QFETCH( QString, popup_item );
-// QFETCH( int, itemA_count );
-// QFETCH( int, itemB_count );
-
-// // initComplexMenubar();
-// QVERIFY( !pm1->isActiveWindow() );
-// QVERIFY( !pm2->isActiveWindow() );
-
-// QTest::qWait(1000);
-// QtTestMouse mouse;
-// mouse.mouseEvent( QtTestMouse::MouseClick, mb, "Menu &1", Qt::LeftButton );
-
-// QVERIFY( pm1->isActiveWindow() );
-// QVERIFY( !pm2->isActiveWindow() );
-
-// QTest::qWait(1000);
-// mouse.mouseEvent( QtTestMouse::MouseClick, pm1, popup_item, Qt::LeftButton );
-
-// QCOMPARE(m_complexActionTriggerCount[3], 0);
-// QCOMPARE(m_complexActionTriggerCount[4], 0);
-// QCOMPARE(m_complexActionTriggerCount['a'], (uint)itemA_count); // this option should have fired
-// QCOMPARE(m_complexActionTriggerCount['b'], (uint)itemB_count);
-// QCOMPARE(m_complexActionTriggerCount['c'], 0);
-// QCOMPARE(m_complexActionTriggerCount['d'], 0);
-// QCOMPARE(m_complexActionTriggerCount['e'], 0);
-// QCOMPARE(m_complexActionTriggerCount['f'], 0);
-// QCOMPARE(m_complexActionTriggerCount['g'], 0);
-// }
-
-// void tst_QMenuBar::check_mouse2_data()
-// {
-// QTest::addColumn<QString>("label");
-// QTest::addColumn<int>("itemA_count");
-// QTest::addColumn<int>("itemB_count");
-// QTest::addColumn<int>("itemC_count");
-// QTest::addColumn<int>("itemD_count");
-// QTest::addColumn<int>("itemE_count");
-// QTest::addColumn<int>("itemF_count");
-// QTest::addColumn<int>("itemG_count");
-// QTest::addColumn<int>("itemH_count");
-// QTest::addColumn<int>("menu3_count");
-
-// QTest::newRow( "A" ) << QString( "Menu &1/Item A Ctrl+A" ) << 1 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0;
-// QTest::newRow( "B" ) << QString( "Menu &1/Item B Ctrl+B" ) << 0 << 1 << 0 << 0 << 0 << 0 << 0 << 0 << 0;
-// QTest::newRow( "C" ) << QString( "Menu &2/Item C Ctrl+C" ) << 0 << 0 << 1 << 0 << 0 << 0 << 0 << 0 << 0;
-// QTest::newRow( "D" ) << QString( "Menu &2/Item D Ctrl+D" ) << 0 << 0 << 0 << 1 << 0 << 0 << 0 << 0 << 0;
-// QTest::newRow( "E" ) << QString( "Menu &2/Item E Ctrl+E" ) << 0 << 0 << 0 << 0 << 1 << 0 << 0 << 0 << 0;
-// QTest::newRow( "F" ) << QString( "Menu &2/Item F Ctrl+F" ) << 0 << 0 << 0 << 0 << 0 << 1 << 0 << 0 << 0;
-// QTest::newRow( "G" ) << QString( "Menu &2/Item G Ctrl+G" ) << 0 << 0 << 0 << 0 << 0 << 0 << 1 << 0 << 0;
-// QTest::newRow( "H" ) << QString( "Menu &2/Item H Ctrl+H" ) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 1 << 0;
-// QTest::newRow( "menu 3" ) << QString( "M&enu 3" ) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 1;
-// }
-
-// /*!
-// Check if the correct signals are emitted if we select a popupmenu.
-// This time, we use a little bit more magic from the testframework.
-// */
-// void tst_QMenuBar::check_mouse2()
-// {
-// if (QSystem::curStyle() == "Motif")
-// QSKIP("This fails in Motif due to a bug in the testing framework");
-// QFETCH( QString, label );
-// QFETCH( int, itemA_count );
-// QFETCH( int, itemB_count );
-// QFETCH( int, itemC_count );
-// QFETCH( int, itemD_count );
-// QFETCH( int, itemE_count );
-// QFETCH( int, itemF_count );
-// QFETCH( int, itemG_count );
-// QFETCH( int, itemH_count );
-// QFETCH( int, menu3_count );
-
-// // initComplexMenubar();
-// QtTestMouse mouse;
-// mouse.click( QtTestMouse::Menu, label, Qt::LeftButton );
-
-// // check if the correct signals have fired
-// QCOMPARE(m_complexActionTriggerCount[3], (uint)menu3_count);
-// QCOMPARE(m_complexActionTriggerCount[4], 0);
-// QCOMPARE(m_complexActionTriggerCount['a'], (uint)itemA_count);
-// QCOMPARE(m_complexActionTriggerCount['b'], (uint)itemB_count);
-// QCOMPARE(m_complexActionTriggerCount['c'], (uint)itemC_count);
-// QCOMPARE(m_complexActionTriggerCount['d'], (uint)itemD_count);
-// QCOMPARE(m_complexActionTriggerCount['e'], (uint)itemE_count);
-// QCOMPARE(m_complexActionTriggerCount['f'], (uint)itemF_count);
-// QCOMPARE(m_complexActionTriggerCount['g'], (uint)itemG_count);
-// QCOMPARE(m_complexActionTriggerCount['h'], (uint)itemH_count);
-// }
-
void tst_QMenuBar::allowActiveAndDisabled()
{
QMenuBar menuBar;
@@ -1078,7 +878,6 @@ void tst_QMenuBar::check_altPress()
initWindowWithSimpleMenuBar(w);
w.show();
w.setFocus();
- QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
QTest::keyClick( &w, Qt::Key_Alt );
@@ -1108,7 +907,6 @@ void tst_QMenuBar::check_altClosePress()
w.show();
w.move(QGuiApplication::primaryScreen()->availableGeometry().center());
- QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
QTest::keyClick(&w, Qt::Key_F, Qt::AltModifier);
@@ -1129,7 +927,6 @@ void tst_QMenuBar::check_shortcutPress()
const TestMenu menu = initWindowWithComplexMenuBar(w);
w.show();
w.setFocus();
- QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
QCOMPARE(m_complexTriggerCount[3], 0);
@@ -1186,7 +983,6 @@ void tst_QMenuBar::check_menuPosition()
QAction *menu_action = w.menuBar()->addMenu(&menu);
centerOnScreen(&w);
w.show();
- QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
//the menu should be below the menubar item
@@ -1270,9 +1066,9 @@ void tst_QMenuBar::task223138_triggered()
//let's trigger the first action
top->trigger();
- QCOMPARE(menubarSpy.count(), 1);
- QCOMPARE(menuSpy.count(), 1);
- QCOMPARE(submenuSpy.count(), 0);
+ QCOMPARE(menubarSpy.size(), 1);
+ QCOMPARE(menuSpy.size(), 1);
+ QCOMPARE(submenuSpy.size(), 0);
menubarSpy.clear();
menuSpy.clear();
@@ -1280,9 +1076,9 @@ void tst_QMenuBar::task223138_triggered()
//let's trigger the sub action
action->trigger();
- QCOMPARE(menubarSpy.count(), 1);
- QCOMPARE(menuSpy.count(), 1);
- QCOMPARE(submenuSpy.count(), 1);
+ QCOMPARE(menubarSpy.size(), 1);
+ QCOMPARE(menuSpy.size(), 1);
+ QCOMPARE(submenuSpy.size(), 1);
}
void tst_QMenuBar::task256322_highlight()
@@ -1305,7 +1101,6 @@ void tst_QMenuBar::task256322_highlight()
centerOnScreen(&win);
win.show();
- QApplicationPrivate::setActiveWindow(&win);
QVERIFY(QTest::qWaitForWindowActive(&win));
const QPoint filePos = menuBarActionWindowPos(win.menuBar(), file);
@@ -1361,8 +1156,8 @@ void tst_QMenuBar::menubarSizeHint()
mb.setStyle(&style);
//this is a list of arbitrary strings so that we check the geometry
- QStringList list = QStringList() << "trer" << "ezrfgtgvqd" << "sdgzgzerzerzer" << "eerzertz" << "er";
- foreach(QString str, list)
+ const auto list = QStringList{"trer", "ezrfgtgvqd", "sdgzgzerzerzer", "eerzertz", "er"};
+ for (const QString &str : list)
mb.addAction(str);
const int panelWidth = style.pixelMetric(QStyle::PM_MenuBarPanelWidth);
@@ -1373,7 +1168,8 @@ void tst_QMenuBar::menubarSizeHint()
centerOnScreen(&mb);
mb.show();
QRect result;
- foreach(QAction *action, mb.actions()) {
+ const auto actions = mb.actions();
+ for (QAction *action : actions) {
const QRect actionRect = mb.actionGeometry(action);
if (!result.isNull()) //this is the first item
QCOMPARE(actionRect.left() - result.right() - 1, spacing);
@@ -1444,7 +1240,6 @@ void tst_QMenuBar::taskQTBUG11823_crashwithInvisibleActions()
centerOnScreen(&menubar);
menubar.show();
- QApplicationPrivate::setActiveWindow(&menubar);
QVERIFY(QTest::qWaitForWindowActive(&menubar));
menubar.setActiveAction(m);
QCOMPARE(menubar.activeAction(), m);
@@ -1475,7 +1270,6 @@ void tst_QMenuBar::closeOnSecondClickAndOpenOnThirdClick() // QTBUG-32807, menu
QMenu *fileMenu = menuBar->addMenu(QStringLiteral("OpenCloseOpen"));
fileMenu->addAction(QStringLiteral("Quit"));
mainWindow.show();
- QApplicationPrivate::setActiveWindow(&mainWindow);
QVERIFY(QTest::qWaitForWindowActive(&mainWindow));
const QPoint center = menuBarActionWindowPos(mainWindow.menuBar(), fileMenu->menuAction());
@@ -1570,7 +1364,6 @@ void tst_QMenuBar::taskQTBUG53205_crashReparentNested()
mainWindow.resize(300, 200);
centerOnScreen(&mainWindow);
const TestMenu testMenus = initWindowWithComplexMenuBar(mainWindow);
- QApplicationPrivate::setActiveWindow(&mainWindow);
// they can't be windows
QWidget hiddenParent(&mainWindow, {});
@@ -1620,12 +1413,11 @@ void tst_QMenuBar::QTBUG_65488_hiddenActionTriggered()
// resize to action's size to make Action1 hidden
win.resize(actRect.width() - 10, win.size().height());
win.show();
- QApplicationPrivate::setActiveWindow(&win);
QVERIFY(QTest::qWaitForWindowExposed(&win));
// click center of the blank area on the menubar where Action1 resided
QTest::mouseClick(win.windowHandle(), Qt::LeftButton, Qt::NoModifier, win.menuBar()->geometry().center());
QCoreApplication::sendPostedEvents(); // make sure all queued events also dispatched
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
}
// QTBUG-56526
@@ -1692,20 +1484,19 @@ void tst_QMenuBar::QTBUG_25669_menubarActionDoubleTriggered()
QSignalSpy spy(win.menuBar(), &QMenuBar::triggered);
win.show();
- QApplicationPrivate::setActiveWindow(&win);
QVERIFY(QTest::qWaitForWindowExposed(&win));
QPoint posAct1 = menuBarActionWindowPos(win.menuBar(), act1);
QPoint posAct2 = menuBarActionWindowPos(win.menuBar(), act2);
QTest::mouseClick(win.windowHandle(), Qt::LeftButton, Qt::NoModifier, posAct1);
- QTRY_COMPARE(spy.count(), 1);
+ QTRY_COMPARE(spy.size(), 1);
QTest::mouseClick(win.windowHandle(), Qt::LeftButton, Qt::NoModifier, posAct2);
- QTRY_COMPARE(spy.count(), 2);
+ QTRY_COMPARE(spy.size(), 2);
QTest::mouseClick(win.windowHandle(), Qt::LeftButton, Qt::NoModifier, posAct2);
- QTRY_COMPARE(spy.count(), 3);
+ QTRY_COMPARE(spy.size(), 3);
}
void tst_QMenuBar::slotForTaskQTBUG53205()
@@ -1729,7 +1520,6 @@ void tst_QMenuBar::taskQTBUG46812_doNotLeaveMenubarHighlighted()
initWindowWithSimpleMenuBar(mainWindow);
mainWindow.show();
- QApplicationPrivate::setActiveWindow(&mainWindow);
QVERIFY(QTest::qWaitForWindowActive(&mainWindow));
QVERIFY(!mainWindow.menuBar()->hasFocus());
@@ -1841,7 +1631,6 @@ void tst_QMenuBar::taskQTBUG55966_subMenuRemoved()
delete subMenu;
window.show();
- QApplicationPrivate::setActiveWindow(&window);
QVERIFY(QTest::qWaitForWindowActive(&window));
QTest::qWait(500);
}