summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/global/qflags/qflags.pro3
-rw-r--r--tests/auto/corelib/global/qlogging/test/test.pro3
-rw-r--r--tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp43
-rw-r--r--tests/auto/corelib/thread/qthreadpool/BLACKLIST3
-rw-r--r--tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp2
-rw-r--r--tests/auto/corelib/tools/qlatin1string/qlatin1string.pro3
-rw-r--r--tests/auto/corelib/tools/qversionnumber/qversionnumber.pro3
-rw-r--r--tests/auto/gui/image/qicon/tst_qicon.cpp15
-rw-r--r--tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp10
-rw-r--r--tests/auto/other/compiler/compiler.pro3
-rw-r--r--tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp9
-rw-r--r--tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp78
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp4
-rw-r--r--tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp28
-rw-r--r--tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp56
-rw-r--r--tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp30
16 files changed, 154 insertions, 139 deletions
diff --git a/tests/auto/corelib/global/qflags/qflags.pro b/tests/auto/corelib/global/qflags/qflags.pro
index c88a9da396..29dfb0684c 100644
--- a/tests/auto/corelib/global/qflags/qflags.pro
+++ b/tests/auto/corelib/global/qflags/qflags.pro
@@ -2,4 +2,5 @@ CONFIG += testcase
TARGET = tst_qflags
QT = core testlib
SOURCES = tst_qflags.cpp
-contains(QT_CONFIG, c++11): CONFIG += c++11 c++14
+contains(QT_CONFIG, c++11): CONFIG += c++11
+contains(QT_CONFIG, c++14): CONFIG += c++14
diff --git a/tests/auto/corelib/global/qlogging/test/test.pro b/tests/auto/corelib/global/qlogging/test/test.pro
index d382001296..df002c5728 100644
--- a/tests/auto/corelib/global/qlogging/test/test.pro
+++ b/tests/auto/corelib/global/qlogging/test/test.pro
@@ -1,6 +1,7 @@
CONFIG += testcase
CONFIG -= app_bundle debug_and_release_target
-contains(QT_CONFIG, c++11): CONFIG += c++11 c++14
+contains(QT_CONFIG, c++11): CONFIG += c++11
+contains(QT_CONFIG, c++14): CONFIG += c++14
TARGET = ../tst_qlogging
QT = core testlib
SOURCES = ../tst_qlogging.cpp
diff --git a/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp b/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp
index e47b2e2e69..24765a82a8 100644
--- a/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp
+++ b/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp
@@ -78,6 +78,9 @@ public:
QList<test> tests;
static void setupDatabase();
+
+private:
+ QScopedPointer<QTemporaryDir> m_dirModelTempDir;
};
@@ -306,18 +309,20 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model)
}
if (QDirModel *dirModel = qobject_cast<QDirModel *>(model)) {
- if (!QDir::current().mkdir("test"))
- qFatal("%s: cannot create directory %s",
- Q_FUNC_INFO,
- qPrintable(QDir::toNativeSeparators(QDir::currentPath()+"/test")));
+ m_dirModelTempDir.reset(new QTemporaryDir);
+ if (!m_dirModelTempDir->isValid())
+ qFatal("Cannot create temporary directory \"%s\": %s",
+ qPrintable(QDir::toNativeSeparators(m_dirModelTempDir->path())),
+ qPrintable(m_dirModelTempDir->errorString()));
+
+ QDir tempDir(m_dirModelTempDir->path());
for (int i = 0; i < 26; ++i) {
- QString subdir = QLatin1String("test/foo_") + QString::number(i);
- if (!QDir::current().mkdir(subdir))
- qFatal("%s: cannot create directory %s",
- Q_FUNC_INFO,
- qPrintable(QDir::toNativeSeparators(QDir::currentPath()+"/"+subdir)));
+ const QString subdir = QLatin1String("foo_") + QString::number(i);
+ if (!tempDir.mkdir(subdir))
+ qFatal("Cannot create directory %s",
+ qPrintable(QDir::toNativeSeparators(tempDir.path() + QLatin1Char('/') +subdir)));
}
- return dirModel->index(QDir::currentPath()+"/test");
+ return dirModel->index(tempDir.path());
}
if (QSqlQueryModel *queryModel = qobject_cast<QSqlQueryModel *>(model)) {
@@ -383,22 +388,8 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model)
*/
void ModelsToTest::cleanupTestArea(QAbstractItemModel *model)
{
- if (qobject_cast<QDirModel *>(model))
- {
- if (QDir(QDir::currentPath()+"/test").exists())
- {
- for (int i = 0; i < 26; ++i) {
- QString subdir(QLatin1String("test/foo_") + QString::number(i));
- if (!QDir::current().rmdir(subdir))
- qFatal("%s: cannot remove directory %s",
- Q_FUNC_INFO,
- qPrintable(QDir::toNativeSeparators(QDir::currentPath()+"/"+subdir)));
- }
- if (!QDir::current().rmdir("test"))
- qFatal("%s: cannot remove directory %s",
- Q_FUNC_INFO,
- qPrintable(QDir::toNativeSeparators(QDir::currentPath()+"/test")));
- }
+ if (qobject_cast<QDirModel *>(model)) {
+ m_dirModelTempDir.reset();
} else if (qobject_cast<QSqlQueryModel *>(model)) {
QSqlQuery q("DROP TABLE test");
}
diff --git a/tests/auto/corelib/thread/qthreadpool/BLACKLIST b/tests/auto/corelib/thread/qthreadpool/BLACKLIST
index 684f650a72..1c392ce96c 100644
--- a/tests/auto/corelib/thread/qthreadpool/BLACKLIST
+++ b/tests/auto/corelib/thread/qthreadpool/BLACKLIST
@@ -1,5 +1,2 @@
[expiryTimeoutRace]
osx
-[tryStartCount]
-windows msvc-2012
-linux
diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
index c9fdb4b718..c465a07487 100644
--- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
+++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
@@ -821,7 +821,7 @@ void tst_QThreadPool::tryStartCount()
++count;
QCOMPARE(count, QThread::idealThreadCount());
- QTest::qWait(100);
+ QTRY_COMPARE(threadPool.activeThreadCount(), 0);
}
}
diff --git a/tests/auto/corelib/tools/qlatin1string/qlatin1string.pro b/tests/auto/corelib/tools/qlatin1string/qlatin1string.pro
index 219afa661b..a996dab23e 100644
--- a/tests/auto/corelib/tools/qlatin1string/qlatin1string.pro
+++ b/tests/auto/corelib/tools/qlatin1string/qlatin1string.pro
@@ -3,6 +3,7 @@ TARGET = tst_qlatin1string
QT = core testlib
SOURCES = tst_qlatin1string.cpp
DEFINES += QT_NO_CAST_TO_ASCII
-contains(QT_CONFIG,c++11): CONFIG += c++11 c++14
+contains(QT_CONFIG,c++11): CONFIG += c++11
+contains(QT_CONFIG,c++14): CONFIG += c++14
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/corelib/tools/qversionnumber/qversionnumber.pro b/tests/auto/corelib/tools/qversionnumber/qversionnumber.pro
index e3a231060c..834fc85a29 100644
--- a/tests/auto/corelib/tools/qversionnumber/qversionnumber.pro
+++ b/tests/auto/corelib/tools/qversionnumber/qversionnumber.pro
@@ -1,5 +1,6 @@
CONFIG += testcase
-contains(QT_CONFIG, c++11):CONFIG += c++11 c++14
+contains(QT_CONFIG, c++11):CONFIG += c++11
+contains(QT_CONFIG, c++14):CONFIG += c++14
TARGET = tst_qversionnumber
QT = core testlib
SOURCES = tst_qversionnumber.cpp
diff --git a/tests/auto/gui/image/qicon/tst_qicon.cpp b/tests/auto/gui/image/qicon/tst_qicon.cpp
index afa72f6922..329c3ae66d 100644
--- a/tests/auto/gui/image/qicon/tst_qicon.cpp
+++ b/tests/auto/gui/image/qicon/tst_qicon.cpp
@@ -53,6 +53,7 @@ private slots:
void actualSize2_data(); // test with 2 pixmaps with different aspect ratio
void actualSize2();
void isNull();
+ void isMask();
void swap();
void bestMatch();
void cacheKey();
@@ -219,6 +220,20 @@ void tst_QIcon::isNull() {
QVERIFY(iconSupportedFormat.actualSize(QSize(32, 32)).isValid());
}
+void tst_QIcon::isMask()
+{
+ QIcon icon;
+ icon.setIsMask(true);
+ icon.addPixmap(QPixmap());
+ QVERIFY(icon.isMask());
+
+ QIcon icon2;
+ icon2.setIsMask(true);
+ QVERIFY(icon2.isMask());
+ icon2.setIsMask(false);
+ QVERIFY(!icon2.isMask());
+}
+
void tst_QIcon::swap()
{
QPixmap p1(1, 1), p2(2, 2);
diff --git a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
index 84fdd81f6c..c45342cc06 100644
--- a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
+++ b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
@@ -250,6 +250,14 @@ void tst_QGuiVariant::toColor_data()
QColor c("red");
QTest::newRow( "string" ) << QVariant( QString( "red" ) ) << c;
QTest::newRow( "solid brush" ) << QVariant( QBrush(c) ) << c;
+ QTest::newRow("qbytearray") << QVariant(QByteArray("red")) << c;
+ QTest::newRow("same color") << QVariant(c) << c;
+ QTest::newRow("qstring(#ff0000)") << QVariant(QString::fromUtf8("#ff0000")) << c;
+ QTest::newRow("qbytearray(#ff0000)") << QVariant(QByteArray("#ff0000")) << c;
+
+ c.setNamedColor("#88112233");
+ QTest::newRow("qstring(#88112233)") << QVariant(QString::fromUtf8("#88112233")) << c;
+ QTest::newRow("qbytearray(#88112233)") << QVariant(QByteArray("#88112233")) << c;
}
void tst_QGuiVariant::toColor()
@@ -260,6 +268,8 @@ void tst_QGuiVariant::toColor()
QVERIFY( value.canConvert( QVariant::Color ) );
QColor d = qvariant_cast<QColor>(value);
QCOMPARE( d, result );
+ QVERIFY(value.convert(QMetaType::QColor));
+ QCOMPARE(d, QColor(value.toString()));
}
void tst_QGuiVariant::toPixmap_data()
diff --git a/tests/auto/other/compiler/compiler.pro b/tests/auto/other/compiler/compiler.pro
index 57871429d2..19f86582e9 100644
--- a/tests/auto/other/compiler/compiler.pro
+++ b/tests/auto/other/compiler/compiler.pro
@@ -3,6 +3,7 @@ TARGET = tst_compiler
SOURCES += tst_compiler.cpp baseclass.cpp derivedclass.cpp othersource.cpp
HEADERS += baseclass.h derivedclass.h
QT = core testlib
-contains(QT_CONFIG, c++11): CONFIG += c++14 c++11
+contains(QT_CONFIG, c++11): CONFIG += c++11
+contains(QT_CONFIG, c++14): CONFIG += c++14
diff --git a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
index ed4cc64410..32253674d8 100644
--- a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
+++ b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
@@ -165,6 +165,7 @@ private slots:
#endif // QT_BUILD_INTERNAL
#endif
void rejectModalDialogs();
+ void QTBUG49600_nativeIconProviderCrash();
private:
void cleanupSettingsFile();
@@ -1487,5 +1488,13 @@ void tst_QFiledialog::rejectModalDialogs()
QVERIFY(file.isEmpty());
}
+void tst_QFiledialog::QTBUG49600_nativeIconProviderCrash()
+{
+ if (!QGuiApplicationPrivate::platformTheme()->usePlatformNativeDialog(QPlatformTheme::FileDialog))
+ QSKIP("This platform always uses widgets to realize its QFileDialog, instead of the native file dialog.");
+ QFileDialog fd;
+ fd.iconProvider();
+}
+
QTEST_MAIN(tst_QFiledialog)
#include "tst_qfiledialog.moc"
diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
index acf45f8fb7..260aa25512 100644
--- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
+++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
@@ -78,10 +78,6 @@ private slots:
void indexPath();
void rootPath();
-#ifdef QT_BUILD_INTERNAL
- void naturalCompare_data();
- void naturalCompare();
-#endif
void readOnly();
void iconProvider();
@@ -242,80 +238,6 @@ void tst_QFileSystemModel::rootPath()
}
}
-#ifdef QT_BUILD_INTERNAL
-void tst_QFileSystemModel::naturalCompare_data()
-{
- QTest::addColumn<QString>("s1");
- QTest::addColumn<QString>("s2");
- QTest::addColumn<int>("caseSensitive");
- QTest::addColumn<int>("result");
- QTest::addColumn<int>("swap");
-
-#define ROWNAME(name) (("prefix=" + prefix.toLatin1() + ", postfix=" + postfix.toLatin1() \
- + ", num=" + num.toLatin1() + ", i=" + QByteArray::number(i) \
- + ", test=" + name).constData())
-
- for (int j = 0; j < 4; ++j) { // <- set a prefix and a postfix string (not numbers)
- QString prefix = (j == 0 || j == 1) ? "b" : "";
- QString postfix = (j == 1 || j == 2) ? "y" : "";
-
- for (int k = 0; k < 3; ++k) { // <- make 0 not a special case
- const QString num = QString::number(k);
- const QString nump = QString::number(k + 1);
- for (int i = 10; i < 12; ++i) { // <- swap s1 and s2 and reverse the result
- QTest::newRow(ROWNAME("basic")) << prefix + "0" + postfix << prefix + "0" + postfix << int(Qt::CaseInsensitive) << 0;
-
- // s1 should always be less then s2
- QTest::newRow(ROWNAME("just text")) << prefix + "fred" + postfix << prefix + "jane" + postfix << int(Qt::CaseInsensitive) << i;
- QTest::newRow(ROWNAME("just numbers")) << prefix + num + postfix << prefix + "9" + postfix << int(Qt::CaseInsensitive) << i;
- QTest::newRow(ROWNAME("zero")) << prefix + num + postfix << prefix + "0" + nump + postfix << int(Qt::CaseInsensitive) << i;
- QTest::newRow(ROWNAME("space b")) << prefix + num + postfix << prefix + " " + nump + postfix << int(Qt::CaseInsensitive) << i;
- QTest::newRow(ROWNAME("space a")) << prefix + num + postfix << prefix + nump + " " + postfix << int(Qt::CaseInsensitive) << i;
- QTest::newRow(ROWNAME("tab b")) << prefix + num + postfix << prefix + " " + nump + postfix << int(Qt::CaseInsensitive) << i;
- QTest::newRow(ROWNAME("tab a")) << prefix + num + postfix << prefix + nump + " " + postfix << int(Qt::CaseInsensitive) << i;
- QTest::newRow(ROWNAME("10 vs 2")) << prefix + num + postfix << prefix + "10" + postfix << int(Qt::CaseInsensitive) << i;
- QTest::newRow(ROWNAME("diff len")) << prefix + num + postfix << prefix + nump + postfix + "x" << int(Qt::CaseInsensitive) << i;
- QTest::newRow(ROWNAME("01 before 1")) << prefix + "0" + num + postfix << prefix + nump + postfix << int(Qt::CaseInsensitive) << i;
- QTest::newRow(ROWNAME("mul nums 2nd 1")) << prefix + "1-" + num + postfix << prefix + "1-" + nump + postfix << int(Qt::CaseInsensitive) << i;
- QTest::newRow(ROWNAME("mul nums 2nd 2")) << prefix + "10-" + num + postfix<< prefix + "10-10" + postfix << int(Qt::CaseInsensitive) << i;
- QTest::newRow(ROWNAME("mul nums 2nd 3")) << prefix + "10-0"+ num + postfix<< prefix + "10-10" + postfix << int(Qt::CaseInsensitive) << i;
- QTest::newRow(ROWNAME("mul nums 2nd 4")) << prefix + "10-" + num + postfix<< prefix + "10-010" + postfix << int(Qt::CaseInsensitive) << i;
- QTest::newRow(ROWNAME("mul nums big 1")) << prefix + "10-" + num + postfix<< prefix + "20-0" + postfix << int(Qt::CaseInsensitive) << i;
- QTest::newRow(ROWNAME("mul nums big 2")) << prefix + "2-" + num + postfix << prefix + "10-0" + postfix << int(Qt::CaseInsensitive) << i;
- QTest::newRow(ROWNAME("mul alphabet 1")) << prefix + num + "-a" + postfix << prefix + num + "-c" + postfix << int(Qt::CaseInsensitive) << i;
- QTest::newRow(ROWNAME("mul alphabet 2")) << prefix + num + "-a9" + postfix<< prefix + num + "-c0" + postfix << int(Qt::CaseInsensitive) << i;
- QTest::newRow(ROWNAME("mul nums w\\0")) << prefix + num + "-"+ num + postfix<< prefix + num+"-0"+nump + postfix << int(Qt::CaseInsensitive) << i;
- QTest::newRow(ROWNAME("num first")) << prefix + num + postfix << prefix + "a" + postfix << int(Qt::CaseInsensitive) << i;
- }
- }
- }
-#undef ROWNAME
-}
-#endif
-
-#ifdef QT_BUILD_INTERNAL
-void tst_QFileSystemModel::naturalCompare()
-{
- QFETCH(QString, s1);
- QFETCH(QString, s2);
- QFETCH(int, caseSensitive);
- QFETCH(int, result);
-
- if (result == 10)
- QCOMPARE(QFileSystemModelPrivate::naturalCompare(s1, s2, Qt::CaseSensitivity(caseSensitive)), -1);
- else
- if (result == 11)
- QCOMPARE(QFileSystemModelPrivate::naturalCompare(s2, s1, Qt::CaseSensitivity(caseSensitive)), 1);
- else
- QCOMPARE(QFileSystemModelPrivate::naturalCompare(s2, s1, Qt::CaseSensitivity(caseSensitive)), result);
-#if defined(Q_OS_WINCE)
- // On Windows CE we need to wait after each test, otherwise no new threads can be
- // created. The scheduler takes its time to recognize ended threads.
- QTest::qWait(300);
-#endif
-}
-#endif
-
void tst_QFileSystemModel::readOnly()
{
QCOMPARE(model->isReadOnly(), true);
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 54f279139f..f146955e95 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -1860,10 +1860,6 @@ void tst_QWidget::activation()
QCOMPARE(QApplication::activeWindow(), &widget1);
widget2.showNormal();
QTest::qWait(waitTime);
-#ifndef Q_OS_WINCE
- if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA)
- QEXPECT_FAIL("", "MS introduced new behavior after XP", Continue);
-#endif
QTest::qWait(waitTime);
QCOMPARE(QApplication::activeWindow(), &widget2);
widget2.hide();
diff --git a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp
index 789a280e80..d76dbf6b46 100644
--- a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp
+++ b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp
@@ -47,13 +47,12 @@
class Widget : public QWidget
{
+ Q_OBJECT
public:
- Widget() { }
-
QList<QEvent::Type> events;
protected:
- bool event(QEvent *ev) {
+ bool event(QEvent *ev) Q_DECL_OVERRIDE {
events.append(ev->type());
return QWidget::event(ev);
}
@@ -62,19 +61,14 @@ protected:
class tst_QLabel : public QObject
{
-Q_OBJECT
-
-public:
- tst_QLabel();
- virtual ~tst_QLabel();
-
+ Q_OBJECT
-public slots:
+private Q_SLOTS:
void initTestCase();
void cleanupTestCase();
void init();
void cleanup();
-private slots:
+
void getSetCheck();
void setText_data();
void setText();
@@ -143,15 +137,6 @@ void tst_QLabel::getSetCheck()
delete var3;
}
-
-tst_QLabel::tst_QLabel(): test_box(0)
-{
-}
-
-tst_QLabel::~tst_QLabel()
-{
-}
-
void tst_QLabel::initTestCase()
{
// Create the test class
@@ -164,8 +149,7 @@ void tst_QLabel::cleanupTestCase()
{
delete testWidget;
testWidget = 0;
- if (test_box)
- delete test_box;
+ delete test_box;
}
void tst_QLabel::init()
diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
index eaa277093c..ec46d7e625 100644
--- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
+++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
@@ -94,6 +94,7 @@ private slots:
void task208001_stylesheet();
void activeSubMenuPosition();
+ void activeSubMenuPositionExec();
void task242454_sizeHint();
void task176201_clear();
void task250673_activeMultiColumnSubMenuPosition();
@@ -694,6 +695,61 @@ void tst_QMenu::activeSubMenuPosition()
#endif
}
+// QTBUG-49588, QTBUG-48396: activeSubMenuPositionExec() is the same as
+// activeSubMenuPosition(), but uses QMenu::exec(), which produces a different
+// sequence of events. Verify that the sub menu is positioned to the right of the
+// main menu.
+class SubMenuPositionExecMenu : public QMenu
+{
+ Q_OBJECT
+public:
+ SubMenuPositionExecMenu() : QMenu("Menu-Title"), m_timerId(-1), m_timerTick(0)
+ {
+ addAction("Item 1");
+ m_subMenu = addMenu("Submenu");
+ m_subAction = m_subMenu->addAction("Sub-Item1");
+ setActiveAction(m_subMenu->menuAction());
+ }
+
+protected:
+ void showEvent(QShowEvent *e) Q_DECL_OVERRIDE
+ {
+ QVERIFY(m_subMenu->isVisible());
+ QVERIFY2(m_subMenu->x() > x(),
+ (QByteArray::number(m_subMenu->x()) + ' ' + QByteArray::number(x())).constData());
+ m_timerId = startTimer(50);
+ QMenu::showEvent(e);
+ }
+
+ void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE
+ {
+ if (e->timerId() == m_timerId) {
+ switch (m_timerTick++) {
+ case 0:
+ m_subMenu->close();
+ break;
+ case 1:
+ close();
+ break;
+ }
+ }
+ }
+
+private:
+ int m_timerId;
+ int m_timerTick;
+ QMenu *m_subMenu;
+ QAction *m_subAction;
+};
+
+void tst_QMenu::activeSubMenuPositionExec()
+{
+#ifndef Q_OS_WINCE
+ SubMenuPositionExecMenu menu;
+ menu.exec(QGuiApplication::primaryScreen()->availableGeometry().center());
+#endif // !Q_OS_WINCE
+}
+
void tst_QMenu::task242454_sizeHint()
{
QMenu menu;
diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
index baf60551c4..f787d73a02 100644
--- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
+++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
@@ -117,6 +117,7 @@ private slots:
// void check_mouse2();
void check_altPress();
+ void check_altClosePress();
#if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE)
void check_shortcutPress();
void check_menuPosition();
@@ -978,6 +979,35 @@ void tst_QMenuBar::check_altPress()
QTRY_VERIFY( ::qobject_cast<QMenuBar *>(qApp->focusWidget()) );
}
+// QTBUG-47377: Pressing 'Alt' after opening a menu by pressing 'Alt+Accelerator'
+// should close it and QMenuBar::activeAction() should be 0.
+void tst_QMenuBar::check_altClosePress()
+{
+ const QStyle *style = QApplication::style();
+ if (!style->styleHint(QStyle::SH_MenuBar_AltKeyNavigation) ) {
+ QSKIP(("This test is not supposed to work in the " + style->objectName().toLatin1()
+ + " style. Skipping.").constData());
+ }
+
+ QMainWindow w;
+ w.setWindowTitle(QTest::currentTestFunction());
+ QMenu *menuFile = w.menuBar()->addMenu(tr("&File"));
+ menuFile->addAction("Quit");
+ QMenu *menuEdit = w.menuBar()->addMenu(tr("&Edit"));
+ menuEdit->addAction("Copy");
+
+ w.show();
+ w.move(QGuiApplication::primaryScreen()->availableGeometry().center());
+ QApplication::setActiveWindow(&w);
+ QVERIFY(QTest::qWaitForWindowActive(&w));
+
+ QTest::keyClick(&w, Qt::Key_F, Qt::AltModifier);
+ QTRY_VERIFY(menuFile->isVisible());
+ QTest::keyClick(menuFile, Qt::Key_Alt, Qt::AltModifier);
+ QTRY_VERIFY(!menuFile->isVisible());
+ QTRY_VERIFY(!w.menuBar()->activeAction());
+}
+
// Qt/Mac,WinCE does not use the native popups/menubar
#if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE)
void tst_QMenuBar::check_shortcutPress()