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.cpp328
1 files changed, 72 insertions, 256 deletions
diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
index 0e6689b413..8524b4212c 100644
--- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
+++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -40,10 +15,13 @@
#include <QVBoxLayout>
#include <QLabel>
#include <QPlainTextEdit>
+#include <QTranslator>
#include <qscreen.h>
#include <qobject.h>
+#include <QtWidgets/private/qapplication_p.h>
+
QT_FORWARD_DECLARE_CLASS(QMainWindow)
#include <qmenubar.h>
@@ -115,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();
@@ -144,6 +115,8 @@ private slots:
#ifdef Q_OS_MACOS
void taskQTBUG56275_reinsertMenuInParentlessQMenuBar();
void QTBUG_57404_existingMenuItemException();
+ void defaultEditMenuItems();
+
#endif
void QTBUG_25669_menubarActionDoubleTriggered();
void taskQTBUG55966_subMenuRemoved();
@@ -356,7 +329,7 @@ void tst_QMenuBar::accel()
QMainWindow w;
const TestMenu menu = initWindowWithSimpleMenuBar(w);
w.show();
- QApplication::setActiveWindow(&w);
+ 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 );
@@ -378,7 +351,7 @@ void tst_QMenuBar::activatedCount()
QFETCH( bool, forceNonNative );
initWindowWithSimpleMenuBar(w, forceNonNative);
w.show();
- QApplication::setActiveWindow(&w);
+ QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_A, Qt::ControlModifier );
@@ -578,7 +551,7 @@ void tst_QMenuBar::check_accelKeys()
QMainWindow w;
initWindowWithComplexMenuBar(w);
w.show();
- QApplication::setActiveWindow(&w);
+ QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
// start with a bogus key that shouldn't trigger anything
@@ -657,7 +630,7 @@ void tst_QMenuBar::check_cursorKeys1()
QMainWindow w;
initWindowWithComplexMenuBar(w);
w.show();
- QApplication::setActiveWindow(&w);
+ QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
// start with a ALT + 1 that activates the first popupmenu
@@ -697,7 +670,7 @@ void tst_QMenuBar::check_cursorKeys2()
QMainWindow w;
initWindowWithComplexMenuBar(w);
w.show();
- QApplication::setActiveWindow(&w);
+ QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
// select popupmenu2
@@ -736,7 +709,7 @@ void tst_QMenuBar::check_cursorKeys3()
QMainWindow w;
initWindowWithComplexMenuBar(w);
w.show();
- QApplication::setActiveWindow(&w);
+ QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
// select Popupmenu 2
@@ -778,7 +751,7 @@ void tst_QMenuBar::taskQTBUG56860_focus()
w.setCentralWidget(e);
w.show();
- QApplication::setActiveWindow(&w);
+ QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
QTRY_COMPARE(QApplication::focusWidget(), e);
@@ -805,85 +778,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();
- QApplication::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();
- QApplication::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.
@@ -900,7 +794,7 @@ void tst_QMenuBar::check_escKey()
const TestMenu menu = initWindowWithComplexMenuBar(w);
w.show();
w.setFocus();
- QApplication::setActiveWindow(&w);
+ QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
QVERIFY( !menu.menus.at(0)->isActiveWindow() );
@@ -921,7 +815,7 @@ void tst_QMenuBar::check_escKey()
if (!QGuiApplication::platformName().compare(QLatin1String("minimal"), Qt::CaseInsensitive)
|| !QGuiApplication::platformName().compare(QLatin1String("offscreen"), Qt::CaseInsensitive)) {
- QWARN("Skipping menu button test on minimal/offscreen platforms");
+ qWarning("Skipping menu button test on minimal/offscreen platforms");
return;
}
@@ -938,112 +832,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;
@@ -1098,7 +886,7 @@ void tst_QMenuBar::check_altPress()
initWindowWithSimpleMenuBar(w);
w.show();
w.setFocus();
- QApplication::setActiveWindow(&w);
+ QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
QTest::keyClick( &w, Qt::Key_Alt );
@@ -1128,7 +916,7 @@ void tst_QMenuBar::check_altClosePress()
w.show();
w.move(QGuiApplication::primaryScreen()->availableGeometry().center());
- QApplication::setActiveWindow(&w);
+ QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
QTest::keyClick(&w, Qt::Key_F, Qt::AltModifier);
@@ -1149,7 +937,7 @@ void tst_QMenuBar::check_shortcutPress()
const TestMenu menu = initWindowWithComplexMenuBar(w);
w.show();
w.setFocus();
- QApplication::setActiveWindow(&w);
+ QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
QCOMPARE(m_complexTriggerCount[3], 0);
@@ -1206,7 +994,7 @@ void tst_QMenuBar::check_menuPosition()
QAction *menu_action = w.menuBar()->addMenu(&menu);
centerOnScreen(&w);
w.show();
- qApp->setActiveWindow(&w);
+ QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
//the menu should be below the menubar item
@@ -1290,9 +1078,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();
@@ -1300,9 +1088,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()
@@ -1325,7 +1113,7 @@ void tst_QMenuBar::task256322_highlight()
centerOnScreen(&win);
win.show();
- QApplication::setActiveWindow(&win);
+ QApplicationPrivate::setActiveWindow(&win);
QVERIFY(QTest::qWaitForWindowActive(&win));
const QPoint filePos = menuBarActionWindowPos(win.menuBar(), file);
@@ -1356,7 +1144,8 @@ void tst_QMenuBar::menubarSizeHint()
{
MyStyle() : QProxyStyle(QStyleFactory::create("windows")) { }
- virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0 ) const
+ int pixelMetric(PixelMetric metric, const QStyleOption *option = 0,
+ const QWidget *widget = 0) const override
{
// I chose strange values (prime numbers to be more sure that the size of the menubar is correct)
switch (metric)
@@ -1380,8 +1169,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);
@@ -1392,7 +1181,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);
@@ -1428,11 +1218,11 @@ void tst_QMenuBar::taskQTBUG4965_escapeEaten()
QMenu menu("menu1");
QAction *first = menubar.addMenu(&menu);
#if QT_CONFIG(shortcut)
- menu.addAction("quit", &menubar, SLOT(close()), QKeySequence("ESC"));
+ menu.addAction("quit", QKeySequence("ESC"), &menubar, SLOT(close()));
#endif
centerOnScreen(&menubar);
menubar.show();
- QApplication::setActiveWindow(&menubar);
+ QApplicationPrivate::setActiveWindow(&menubar);
QVERIFY(QTest::qWaitForWindowExposed(&menubar));
menubar.setActiveAction(first);
QTRY_VERIFY(menu.isVisible());
@@ -1463,7 +1253,7 @@ void tst_QMenuBar::taskQTBUG11823_crashwithInvisibleActions()
centerOnScreen(&menubar);
menubar.show();
- QApplication::setActiveWindow(&menubar);
+ QApplicationPrivate::setActiveWindow(&menubar);
QVERIFY(QTest::qWaitForWindowActive(&menubar));
menubar.setActiveAction(m);
QCOMPARE(menubar.activeAction(), m);
@@ -1494,7 +1284,7 @@ void tst_QMenuBar::closeOnSecondClickAndOpenOnThirdClick() // QTBUG-32807, menu
QMenu *fileMenu = menuBar->addMenu(QStringLiteral("OpenCloseOpen"));
fileMenu->addAction(QStringLiteral("Quit"));
mainWindow.show();
- QApplication::setActiveWindow(&mainWindow);
+ QApplicationPrivate::setActiveWindow(&mainWindow);
QVERIFY(QTest::qWaitForWindowActive(&mainWindow));
const QPoint center = menuBarActionWindowPos(mainWindow.menuBar(), fileMenu->menuAction());
@@ -1589,7 +1379,7 @@ void tst_QMenuBar::taskQTBUG53205_crashReparentNested()
mainWindow.resize(300, 200);
centerOnScreen(&mainWindow);
const TestMenu testMenus = initWindowWithComplexMenuBar(mainWindow);
- QApplication::setActiveWindow(&mainWindow);
+ QApplicationPrivate::setActiveWindow(&mainWindow);
// they can't be windows
QWidget hiddenParent(&mainWindow, {});
@@ -1639,12 +1429,12 @@ 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();
- QApplication::setActiveWindow(&win);
+ 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
@@ -1711,20 +1501,20 @@ void tst_QMenuBar::QTBUG_25669_menubarActionDoubleTriggered()
QSignalSpy spy(win.menuBar(), &QMenuBar::triggered);
win.show();
- QApplication::setActiveWindow(&win);
+ 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()
@@ -1748,7 +1538,7 @@ void tst_QMenuBar::taskQTBUG46812_doNotLeaveMenubarHighlighted()
initWindowWithSimpleMenuBar(mainWindow);
mainWindow.show();
- QApplication::setActiveWindow(&mainWindow);
+ QApplicationPrivate::setActiveWindow(&mainWindow);
QVERIFY(QTest::qWaitForWindowActive(&mainWindow));
QVERIFY(!mainWindow.menuBar()->hasFocus());
@@ -1817,6 +1607,32 @@ void tst_QMenuBar::QTBUG_57404_existingMenuItemException()
QTest::qWait(100);
// No crash, all fine. Ideally, there should be only one warning.
}
+
+void tst_QMenuBar::defaultEditMenuItems()
+{
+ class TestTranslator : public QTranslator
+ {
+ public:
+ QString translate(const char *context, const char *sourceText,
+ const char *disambiguation = nullptr, int n = -1) const override
+ {
+ if (QByteArrayView(context) == "QCocoaMenu" && QByteArrayView(sourceText) == "Edit")
+ return QString("Editieren");
+ return QTranslator::translate(context, sourceText, disambiguation, n);
+ }
+ } testTranslator;
+ qApp->installTranslator(&testTranslator);
+
+ QMainWindow mw;
+ mw.show();
+ QVERIFY(QTest::qWaitForWindowActive(&mw));
+
+ mw.menuBar()->addMenu("Editieren")->addAction("Undo");
+
+ mw.hide();
+ mw.show();
+ // this should not crash with infinite recursion
+}
#endif // Q_OS_MACOS
void tst_QMenuBar::taskQTBUG55966_subMenuRemoved()
@@ -1834,7 +1650,7 @@ void tst_QMenuBar::taskQTBUG55966_subMenuRemoved()
delete subMenu;
window.show();
- QApplication::setActiveWindow(&window);
+ QApplicationPrivate::setActiveWindow(&window);
QVERIFY(QTest::qWaitForWindowActive(&window));
QTest::qWait(500);
}