2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2012-09-19 12:28:29 +00:00
|
|
|
** 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
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 12:36:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** 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.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QPair>
|
|
|
|
#include <QList>
|
|
|
|
#include <QPointer>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QDialogButtonBox>
|
Expose QPA API under qpa/*
The main reasons for doing this are:
1. _qpa.h end up in the master QtGui include file. QtGui is meant for
userland applications. qpa code is neither binary nor source compatible.
Inadvertant use of QPA api makes the user code binary-incompatible.
2. syncqt creates forwarding headers for non-private header files. This
gives people the impression that this is public API.
As discussed on the mailing list, even though QPA api is internal and subject
to change, it needs to treated differently from private headers since they
will be used by in-qtbase and out-of-qtbase plugins.
This commit does the following:
1. The _qpa in QPA header files is dropped.
2. syncqt now treats any file with qplatform prefix as a special file and
moves it to qpa/ directory. The recommended way of using QPA API in plugins
is: #include <qpa/qplatformfoo.h>. This allows the user include QPA API
from multiple modules (for example, qplatformfoo might be in QtPrintSupport)
3. The user needs to explicitly add QT += <module>-private to get access to
the qpa api.
4. Creates compat headers for the olden style qplatformfoo_qpa.h and QPlatformFoo
includes.
This commit does not change the cpp filenames. This requires a more careful
merging of existing non qpa cpp files and existing cpp files on a case by
case basis. This can be done at anytime.
The following files are not renamed as part of this changed but will be fixed
as part of a future change:
src/gui/kernel/qgenericpluginfactory_qpa.h
src/gui/kernel/qgenericplugin_qpa.h
src/gui/kernel/qwindowsysteminterface_qpa.h
files were renamed using
for x in `find . -name "qplatform*_qpa.h"`; do git mv $x "${x/_qpa.h/.h}"; done
for x in `find . -name "qplatform*_qpa_p.h"`; do git mv $x "${x/_qpa_p.h/_p.h}"; done
includes were renamed using script
for file in `find . -name "*.h" -or -name "*.cpp" -or -name "*.mm"`; do
sed -i -e 's,.*#.*include.*<\(Qt.*/\)\?\(QPlatform.*\)>,#include <qpa/\L\2.h>,g' \
-e 's,.*#.*include.*"\(Qt.*/\)\?\(QPlatform.*\)",#include <qpa/\L\2.h>,g' \
-e 's,.*#.*include.* "\(qplatform.*\)_qpa.h",#include <qpa/\L\1.h>,g' \
-e 's,.*#.*include.*"\(qplatform.*\)_qpa_p.h",#include <qpa/\L\1_p.h>,g' \
-e 's,.*#.*include.*<\(Qt.*/\|Qt.*/private/\|private/\)\?\(qplatform.*\)_qpa\(.*\)>,#include <qpa/\2\3>,g' \
-e 's,.*#.*include.*"\(Qt.*/\|Qt.*/private/\|private/\)\?\(qplatform.*\)_qpa\(.*\)",#include <qpa/\2\3>,g' \
$file
done
Change-Id: I04a350314a45746e3911f54b3b21ad03315afb67
Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
2012-04-26 23:33:35 +00:00
|
|
|
#include <qpa/qplatformtheme.h>
|
2012-02-21 14:36:01 +00:00
|
|
|
#include <private/qguiapplication_p.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
class tst_QMessageBox : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void sanityTest();
|
|
|
|
void defaultButton();
|
|
|
|
void escapeButton();
|
|
|
|
void button();
|
|
|
|
void statics();
|
|
|
|
void about();
|
|
|
|
void detailsText();
|
|
|
|
void detailsButtonText();
|
2020-03-11 20:02:03 +00:00
|
|
|
void expandDetailsWithoutMoving();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-09-26 14:34:29 +00:00
|
|
|
#ifndef Q_OS_MAC
|
2011-04-27 10:05:43 +00:00
|
|
|
void shortcut();
|
2012-09-26 14:34:29 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void staticSourceCompat();
|
|
|
|
void instanceSourceCompat();
|
|
|
|
|
|
|
|
void incorrectDefaultButton();
|
|
|
|
void updateSize();
|
|
|
|
|
|
|
|
void setInformativeText();
|
|
|
|
void iconPixmap();
|
|
|
|
|
2018-12-07 15:04:33 +00:00
|
|
|
// QTBUG-44131
|
|
|
|
void acceptedRejectedSignals();
|
|
|
|
void acceptedRejectedSignals_data();
|
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
void cleanup();
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
2013-09-09 11:10:37 +00:00
|
|
|
class tst_ResizingMessageBox : public QMessageBox
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
tst_ResizingMessageBox() : QMessageBox(), resized(false) { }
|
|
|
|
bool resized;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void resizeEvent ( QResizeEvent * event ) {
|
|
|
|
resized = true;
|
|
|
|
QMessageBox::resizeEvent(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
// ExecCloseHelper: Closes a modal QDialog during its exec() function by either
|
|
|
|
// sending a key event or closing it (CloseWindow) once it becomes the active
|
|
|
|
// modal window. Pass nullptr to "autodetect" the instance for static methods.
|
|
|
|
class ExecCloseHelper : public QObject
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2015-11-04 13:01:58 +00:00
|
|
|
public:
|
|
|
|
enum { CloseWindow = -1 };
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2017-09-18 09:49:52 +00:00
|
|
|
explicit ExecCloseHelper(QObject *parent = nullptr)
|
|
|
|
: QObject(parent), m_key(0), m_timerId(0), m_testCandidate(nullptr) { }
|
2015-11-04 13:01:58 +00:00
|
|
|
|
2017-09-18 09:49:52 +00:00
|
|
|
void start(int key, QWidget *testCandidate = nullptr)
|
2015-11-04 13:01:58 +00:00
|
|
|
{
|
|
|
|
m_key = key;
|
|
|
|
m_testCandidate = testCandidate;
|
|
|
|
m_timerId = startTimer(50);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
bool done() const { return !m_timerId; }
|
|
|
|
|
|
|
|
protected:
|
2017-09-18 08:36:49 +00:00
|
|
|
void timerEvent(QTimerEvent *te) override;
|
2015-11-04 13:01:58 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
int m_key;
|
|
|
|
int m_timerId;
|
|
|
|
QWidget *m_testCandidate;
|
|
|
|
};
|
|
|
|
|
|
|
|
void ExecCloseHelper::timerEvent(QTimerEvent *te)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2015-11-04 13:01:58 +00:00
|
|
|
if (te->timerId() != m_timerId)
|
2011-04-27 10:05:43 +00:00
|
|
|
return;
|
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
QWidget *modalWidget = QApplication::activeModalWidget();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
if (!m_testCandidate && modalWidget)
|
|
|
|
m_testCandidate = modalWidget;
|
|
|
|
|
|
|
|
if (m_testCandidate && m_testCandidate == modalWidget) {
|
|
|
|
if (m_key == CloseWindow) {
|
|
|
|
m_testCandidate->close();
|
|
|
|
} else {
|
|
|
|
QKeyEvent *ke = new QKeyEvent(QEvent::KeyPress, m_key, Qt::NoModifier);
|
|
|
|
QCoreApplication::postEvent(m_testCandidate, ke);
|
|
|
|
}
|
2017-09-18 09:49:52 +00:00
|
|
|
m_testCandidate = nullptr;
|
2015-11-04 13:01:58 +00:00
|
|
|
killTimer(m_timerId);
|
|
|
|
m_timerId = m_key = 0;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
void tst_QMessageBox::cleanup()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2015-11-04 13:01:58 +00:00
|
|
|
QTRY_VERIFY(QApplication::topLevelWidgets().isEmpty()); // OS X requires TRY
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QMessageBox::sanityTest()
|
|
|
|
{
|
2017-08-02 22:34:31 +00:00
|
|
|
#if defined(Q_OS_MACOS)
|
|
|
|
if (QSysInfo::productVersion() == QLatin1String("10.12")) {
|
|
|
|
QSKIP("Test hangs on macOS 10.12 -- QTQAINFRA-1362");
|
|
|
|
return;
|
|
|
|
}
|
2018-05-17 13:18:03 +00:00
|
|
|
#elif defined(Q_OS_WINRT)
|
|
|
|
QSKIP("Test hangs on winrt -- QTBUG-68297");
|
2017-08-02 22:34:31 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setText("This is insane");
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
msgBox.setIcon(QMessageBox::Icon(i));
|
|
|
|
msgBox.setIconPixmap(QPixmap());
|
|
|
|
msgBox.setIconPixmap(QPixmap("whatever.png"));
|
|
|
|
msgBox.setTextFormat(Qt::RichText);
|
|
|
|
msgBox.setTextFormat(Qt::PlainText);
|
2015-11-04 13:01:58 +00:00
|
|
|
ExecCloseHelper closeHelper;
|
|
|
|
closeHelper.start(ExecCloseHelper::CloseWindow, &msgBox);
|
|
|
|
msgBox.exec();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QMessageBox::button()
|
|
|
|
{
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.addButton("retry", QMessageBox::DestructiveRole);
|
2018-12-07 16:21:50 +00:00
|
|
|
QVERIFY(msgBox.button(QMessageBox::Ok) == nullptr); // not added yet
|
2011-04-27 10:05:43 +00:00
|
|
|
QPushButton *b1 = msgBox.addButton(QMessageBox::Ok);
|
2018-12-07 16:21:50 +00:00
|
|
|
QCOMPARE(msgBox.button(QMessageBox::Ok), static_cast<QAbstractButton *>(b1)); // just added
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(msgBox.standardButton(b1), QMessageBox::Ok);
|
|
|
|
msgBox.addButton(QMessageBox::Cancel);
|
|
|
|
QCOMPARE(msgBox.standardButtons(), QMessageBox::Ok | QMessageBox::Cancel);
|
|
|
|
|
|
|
|
// remove the cancel, should not exist anymore
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
2015-07-30 13:16:36 +00:00
|
|
|
QVERIFY(!msgBox.button(QMessageBox::Cancel));
|
2018-12-07 16:21:50 +00:00
|
|
|
QVERIFY(msgBox.button(QMessageBox::Yes) != nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// should not crash
|
|
|
|
QPushButton *b4 = new QPushButton;
|
|
|
|
msgBox.addButton(b4, QMessageBox::DestructiveRole);
|
2018-12-07 16:21:50 +00:00
|
|
|
msgBox.addButton(nullptr, QMessageBox::ActionRole);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QMessageBox::defaultButton()
|
|
|
|
{
|
|
|
|
QMessageBox msgBox;
|
2015-07-30 13:16:36 +00:00
|
|
|
QVERIFY(!msgBox.defaultButton());
|
2011-04-27 10:05:43 +00:00
|
|
|
msgBox.addButton(QMessageBox::Ok);
|
|
|
|
msgBox.addButton(QMessageBox::Cancel);
|
2015-07-30 13:16:36 +00:00
|
|
|
QVERIFY(!msgBox.defaultButton());
|
2011-04-27 10:05:43 +00:00
|
|
|
QPushButton pushButton;
|
|
|
|
msgBox.setDefaultButton(&pushButton);
|
2018-12-07 16:21:50 +00:00
|
|
|
QVERIFY(msgBox.defaultButton() == nullptr); // we have not added it yet
|
2011-04-27 10:05:43 +00:00
|
|
|
QPushButton *retryButton = msgBox.addButton(QMessageBox::Retry);
|
|
|
|
msgBox.setDefaultButton(retryButton);
|
|
|
|
QCOMPARE(msgBox.defaultButton(), retryButton);
|
2015-11-04 13:01:58 +00:00
|
|
|
ExecCloseHelper closeHelper;
|
|
|
|
closeHelper.start(ExecCloseHelper::CloseWindow, &msgBox);
|
|
|
|
msgBox.exec();
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(msgBox.clickedButton(), msgBox.button(QMessageBox::Cancel));
|
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(Qt::Key_Enter, &msgBox);
|
|
|
|
msgBox.exec();
|
2018-12-07 16:21:50 +00:00
|
|
|
QCOMPARE(msgBox.clickedButton(), static_cast<QAbstractButton *>(retryButton));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QAbstractButton *okButton = msgBox.button(QMessageBox::Ok);
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
2018-12-07 16:21:50 +00:00
|
|
|
QCOMPARE(msgBox.defaultButton(), static_cast<QPushButton *>(okButton));
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(Qt::Key_Enter, &msgBox);
|
|
|
|
msgBox.exec();
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(msgBox.clickedButton(), okButton);
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Yes); // its not in there!
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(msgBox.defaultButton(), okButton);
|
2011-04-27 10:05:43 +00:00
|
|
|
msgBox.removeButton(okButton);
|
|
|
|
delete okButton;
|
2018-12-07 16:21:50 +00:00
|
|
|
okButton = nullptr;
|
2015-07-30 13:16:36 +00:00
|
|
|
QVERIFY(!msgBox.defaultButton());
|
2011-04-27 10:05:43 +00:00
|
|
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
2015-07-30 13:16:36 +00:00
|
|
|
QVERIFY(!msgBox.defaultButton());
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QMessageBox::escapeButton()
|
|
|
|
{
|
|
|
|
QMessageBox msgBox;
|
2015-07-30 13:16:36 +00:00
|
|
|
QVERIFY(!msgBox.escapeButton());
|
2011-04-27 10:05:43 +00:00
|
|
|
msgBox.addButton(QMessageBox::Ok);
|
2015-11-04 13:01:58 +00:00
|
|
|
ExecCloseHelper closeHelper;
|
|
|
|
closeHelper.start(ExecCloseHelper::CloseWindow, &msgBox);
|
|
|
|
msgBox.exec();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(msgBox.clickedButton() == msgBox.button(QMessageBox::Ok)); // auto detected (one button only)
|
|
|
|
msgBox.addButton(QMessageBox::Cancel);
|
2015-07-30 13:16:36 +00:00
|
|
|
QVERIFY(!msgBox.escapeButton());
|
2011-04-27 10:05:43 +00:00
|
|
|
QPushButton invalidButton;
|
|
|
|
msgBox.setEscapeButton(&invalidButton);
|
2015-07-30 13:16:36 +00:00
|
|
|
QVERIFY(!msgBox.escapeButton());
|
2011-04-27 10:05:43 +00:00
|
|
|
QAbstractButton *retryButton = msgBox.addButton(QMessageBox::Retry);
|
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(ExecCloseHelper::CloseWindow, &msgBox);
|
|
|
|
msgBox.exec();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(msgBox.clickedButton() == msgBox.button(QMessageBox::Cancel)); // auto detected (cancel)
|
|
|
|
|
|
|
|
msgBox.setEscapeButton(retryButton);
|
2018-12-07 16:21:50 +00:00
|
|
|
QCOMPARE(msgBox.escapeButton(), static_cast<QAbstractButton *>(retryButton));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// with escape
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(Qt::Key_Escape, &msgBox);
|
|
|
|
msgBox.exec();
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(msgBox.clickedButton(), retryButton);
|
|
|
|
|
|
|
|
// with close
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(ExecCloseHelper::CloseWindow, &msgBox);
|
|
|
|
msgBox.exec();
|
2018-12-07 16:21:50 +00:00
|
|
|
QCOMPARE(msgBox.clickedButton(), static_cast<QAbstractButton *>(retryButton));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QAbstractButton *okButton = msgBox.button(QMessageBox::Ok);
|
|
|
|
msgBox.setEscapeButton(QMessageBox::Ok);
|
|
|
|
QCOMPARE(msgBox.escapeButton(), okButton);
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(Qt::Key_Escape, &msgBox);
|
|
|
|
msgBox.exec();
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(msgBox.clickedButton(), okButton);
|
|
|
|
msgBox.setEscapeButton(QMessageBox::Yes); // its not in there!
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(msgBox.escapeButton(), okButton);
|
2011-04-27 10:05:43 +00:00
|
|
|
msgBox.removeButton(okButton);
|
|
|
|
delete okButton;
|
2018-12-07 16:21:50 +00:00
|
|
|
okButton = nullptr;
|
2015-07-30 13:16:36 +00:00
|
|
|
QVERIFY(!msgBox.escapeButton());
|
2011-04-27 10:05:43 +00:00
|
|
|
msgBox.setEscapeButton(QMessageBox::Ok);
|
2015-07-30 13:16:36 +00:00
|
|
|
QVERIFY(!msgBox.escapeButton());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QMessageBox msgBox2;
|
|
|
|
msgBox2.addButton(QMessageBox::Yes);
|
|
|
|
msgBox2.addButton(QMessageBox::No);
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(ExecCloseHelper::CloseWindow, &msgBox2);
|
|
|
|
msgBox2.exec();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(msgBox2.clickedButton() == msgBox2.button(QMessageBox::No)); // auto detected (one No button only)
|
|
|
|
|
|
|
|
QPushButton *rejectButton = new QPushButton;
|
|
|
|
msgBox2.addButton(rejectButton, QMessageBox::RejectRole);
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(ExecCloseHelper::CloseWindow, &msgBox2);
|
|
|
|
msgBox2.exec();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(msgBox2.clickedButton() == rejectButton); // auto detected (one reject button only)
|
|
|
|
|
|
|
|
msgBox2.addButton(new QPushButton, QMessageBox::RejectRole);
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(ExecCloseHelper::CloseWindow, &msgBox2);
|
|
|
|
msgBox2.exec();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(msgBox2.clickedButton() == msgBox2.button(QMessageBox::No)); // auto detected (one No button only)
|
2018-07-18 14:51:11 +00:00
|
|
|
|
|
|
|
QMessageBox msgBox3;
|
|
|
|
msgBox3.setDetailedText("Details");
|
|
|
|
closeHelper.start(ExecCloseHelper::CloseWindow, &msgBox3);
|
|
|
|
msgBox3.exec();
|
|
|
|
QVERIFY(msgBox3.clickedButton() == msgBox3.button(QMessageBox::Ok)); // auto detected
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QMessageBox::statics()
|
|
|
|
{
|
|
|
|
QMessageBox::StandardButton (*statics[4])(QWidget *, const QString &,
|
|
|
|
const QString&, QMessageBox::StandardButtons buttons,
|
|
|
|
QMessageBox::StandardButton);
|
|
|
|
|
|
|
|
statics[0] = QMessageBox::information;
|
|
|
|
statics[1] = QMessageBox::critical;
|
|
|
|
statics[2] = QMessageBox::question;
|
|
|
|
statics[3] = QMessageBox::warning;
|
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
ExecCloseHelper closeHelper;
|
2011-04-27 10:05:43 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(Qt::Key_Escape);
|
2018-12-07 16:21:50 +00:00
|
|
|
QMessageBox::StandardButton sb = (*statics[i])(nullptr, "caption",
|
2011-04-27 10:05:43 +00:00
|
|
|
"text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help | QMessageBox::Cancel,
|
|
|
|
QMessageBox::NoButton);
|
|
|
|
QCOMPARE(sb, QMessageBox::Cancel);
|
2015-11-04 13:01:58 +00:00
|
|
|
QVERIFY(closeHelper.done());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(ExecCloseHelper::CloseWindow);
|
2018-12-07 16:21:50 +00:00
|
|
|
sb = (*statics[i])(nullptr, "caption",
|
2011-04-27 10:05:43 +00:00
|
|
|
"text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help | QMessageBox::Cancel,
|
|
|
|
QMessageBox::NoButton);
|
|
|
|
QCOMPARE(sb, QMessageBox::Cancel);
|
2015-11-04 13:01:58 +00:00
|
|
|
QVERIFY(closeHelper.done());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(Qt::Key_Enter);
|
2018-12-07 16:21:50 +00:00
|
|
|
sb = (*statics[i])(nullptr, "caption",
|
2011-04-27 10:05:43 +00:00
|
|
|
"text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help,
|
|
|
|
QMessageBox::Yes);
|
|
|
|
QCOMPARE(sb, QMessageBox::Yes);
|
2015-11-04 13:01:58 +00:00
|
|
|
QVERIFY(closeHelper.done());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(Qt::Key_Enter);
|
2018-12-07 16:21:50 +00:00
|
|
|
sb = (*statics[i])(nullptr, "caption",
|
2011-04-27 10:05:43 +00:00
|
|
|
"text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help,
|
|
|
|
QMessageBox::No);
|
|
|
|
QCOMPARE(sb, QMessageBox::No);
|
2015-11-04 13:01:58 +00:00
|
|
|
QVERIFY(closeHelper.done());
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-28 10:45:48 +00:00
|
|
|
// shortcuts are not used on OS X
|
2012-09-26 14:34:29 +00:00
|
|
|
#ifndef Q_OS_MAC
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_QMessageBox::shortcut()
|
|
|
|
{
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.addButton("O&k", QMessageBox::YesRole);
|
|
|
|
msgBox.addButton("&No", QMessageBox::YesRole);
|
|
|
|
msgBox.addButton("&Maybe", QMessageBox::YesRole);
|
2015-11-04 13:01:58 +00:00
|
|
|
ExecCloseHelper closeHelper;
|
|
|
|
closeHelper.start(Qt::Key_M, &msgBox);
|
|
|
|
QCOMPARE(msgBox.exec(), 2);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2012-09-26 14:34:29 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void tst_QMessageBox::about()
|
|
|
|
{
|
2015-11-04 13:01:58 +00:00
|
|
|
ExecCloseHelper closeHelper;
|
|
|
|
closeHelper.start(Qt::Key_Escape);
|
2018-12-07 16:21:50 +00:00
|
|
|
QMessageBox::about(nullptr, "Caption", "This is an auto test");
|
2011-04-27 10:05:43 +00:00
|
|
|
// On Mac, about and aboutQt are not modal, so we need to
|
|
|
|
// explicitly run the event loop
|
2012-01-16 10:49:53 +00:00
|
|
|
#ifdef Q_OS_MAC
|
2015-11-04 13:01:58 +00:00
|
|
|
QTRY_VERIFY(closeHelper.done());
|
2011-04-27 10:05:43 +00:00
|
|
|
#else
|
2015-11-04 13:01:58 +00:00
|
|
|
QVERIFY(closeHelper.done());
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
const int keyToSend = Qt::Key_Enter;
|
2016-03-08 14:51:15 +00:00
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(keyToSend);
|
2018-12-07 16:21:50 +00:00
|
|
|
QMessageBox::aboutQt(nullptr, "Caption");
|
2012-01-16 10:49:53 +00:00
|
|
|
#ifdef Q_OS_MAC
|
2015-11-04 13:01:58 +00:00
|
|
|
QTRY_VERIFY(closeHelper.done());
|
2011-04-27 10:05:43 +00:00
|
|
|
#else
|
2015-11-04 13:01:58 +00:00
|
|
|
QVERIFY(closeHelper.done());
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QMessageBox::staticSourceCompat()
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
// source compat tests for < 4.2
|
2015-11-04 13:01:58 +00:00
|
|
|
ExecCloseHelper closeHelper;
|
|
|
|
closeHelper.start(Qt::Key_Enter);
|
2018-12-07 16:21:50 +00:00
|
|
|
ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes, QMessageBox::No);
|
2011-04-27 10:05:43 +00:00
|
|
|
int expectedButton = int(QMessageBox::Yes);
|
2012-02-21 14:36:01 +00:00
|
|
|
if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
|
|
|
|
const int dialogButtonBoxLayout = theme->themeHint(QPlatformTheme::DialogButtonBoxLayout).toInt();
|
|
|
|
if (dialogButtonBoxLayout == QDialogButtonBox::MacLayout
|
|
|
|
|| dialogButtonBoxLayout == QDialogButtonBox::GnomeLayout)
|
|
|
|
expectedButton = int(QMessageBox::No);
|
2012-02-10 16:17:36 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(ret, expectedButton);
|
2015-11-04 13:01:58 +00:00
|
|
|
QVERIFY(closeHelper.done());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(Qt::Key_Enter);
|
2018-12-07 16:21:50 +00:00
|
|
|
ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(ret, int(QMessageBox::Yes));
|
2015-11-04 13:01:58 +00:00
|
|
|
QVERIFY(closeHelper.done());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(Qt::Key_Enter);
|
2018-12-07 16:21:50 +00:00
|
|
|
ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes, QMessageBox::No | QMessageBox::Default);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(ret, int(QMessageBox::No));
|
2015-11-04 13:01:58 +00:00
|
|
|
QVERIFY(closeHelper.done());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(Qt::Key_Enter);
|
2018-12-07 16:21:50 +00:00
|
|
|
ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(ret, int(QMessageBox::Yes));
|
2015-11-04 13:01:58 +00:00
|
|
|
QVERIFY(closeHelper.done());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(Qt::Key_Enter);
|
2018-12-07 16:21:50 +00:00
|
|
|
ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes | QMessageBox::Escape, QMessageBox::No | QMessageBox::Default);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(ret, int(QMessageBox::No));
|
2015-11-04 13:01:58 +00:00
|
|
|
QVERIFY(closeHelper.done());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// the button text versions
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(Qt::Key_Enter);
|
2018-12-07 16:21:50 +00:00
|
|
|
ret = QMessageBox::information(nullptr, "title", "text", "Yes", "No", QString(), 1);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(ret, 1);
|
2015-11-04 13:01:58 +00:00
|
|
|
QVERIFY(closeHelper.done());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-10-24 22:11:03 +00:00
|
|
|
if (0) { // don't run these tests since the dialog won't close!
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(Qt::Key_Escape);
|
2018-12-07 16:21:50 +00:00
|
|
|
ret = QMessageBox::information(nullptr, "title", "text", "Yes", "No", QString(), 1);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(ret, -1);
|
2015-11-04 13:01:58 +00:00
|
|
|
QVERIFY(closeHelper.done());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(Qt::Key_Escape);
|
2018-12-07 16:21:50 +00:00
|
|
|
ret = QMessageBox::information(nullptr, "title", "text", "Yes", "No", QString(), 0, 1);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(ret, 1);
|
2015-11-04 13:01:58 +00:00
|
|
|
QVERIFY(closeHelper.done());
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QMessageBox::instanceSourceCompat()
|
|
|
|
{
|
|
|
|
QMessageBox mb("Application name here",
|
|
|
|
"Saving the file will overwrite the original file on the disk.\n"
|
|
|
|
"Do you really want to save?",
|
|
|
|
QMessageBox::Information,
|
|
|
|
QMessageBox::Yes | QMessageBox::Default,
|
|
|
|
QMessageBox::No,
|
|
|
|
QMessageBox::Cancel | QMessageBox::Escape);
|
|
|
|
mb.setButtonText(QMessageBox::Yes, "Save");
|
|
|
|
mb.setButtonText(QMessageBox::No, "Discard");
|
|
|
|
mb.addButton("&Revert", QMessageBox::RejectRole);
|
|
|
|
mb.addButton("&Zoo", QMessageBox::ActionRole);
|
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
ExecCloseHelper closeHelper;
|
|
|
|
closeHelper.start(Qt::Key_Enter, &mb);
|
|
|
|
QCOMPARE(mb.exec(), int(QMessageBox::Yes));
|
|
|
|
closeHelper.start(Qt::Key_Escape, &mb);
|
|
|
|
QCOMPARE(mb.exec(), int(QMessageBox::Cancel));
|
2012-01-16 10:49:53 +00:00
|
|
|
#ifndef Q_OS_MAC
|
2015-05-28 10:45:48 +00:00
|
|
|
// mnemonics are not used on OS X
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(Qt::ALT + Qt::Key_R, &mb);
|
|
|
|
QCOMPARE(mb.exec(), 0);
|
|
|
|
closeHelper.start(Qt::ALT + Qt::Key_Z, &mb);
|
|
|
|
QCOMPARE(mb.exec(), 1);
|
2011-10-04 03:23:23 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QMessageBox::detailsText()
|
|
|
|
{
|
|
|
|
QMessageBox box;
|
|
|
|
QString text("This is the details text.");
|
|
|
|
box.setDetailedText(text);
|
|
|
|
QCOMPARE(box.detailedText(), text);
|
2014-06-04 11:42:00 +00:00
|
|
|
box.show();
|
2017-09-08 16:42:25 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&box));
|
2014-06-04 11:42:00 +00:00
|
|
|
// QTBUG-39334, the box should now have the default "Ok" button as well as
|
|
|
|
// the "Show Details.." button.
|
|
|
|
QCOMPARE(box.findChildren<QAbstractButton *>().size(), 2);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QMessageBox::detailsButtonText()
|
|
|
|
{
|
|
|
|
QMessageBox box;
|
|
|
|
box.setDetailedText("bla");
|
|
|
|
box.open();
|
|
|
|
QApplication::postEvent(&box, new QEvent(QEvent::LanguageChange));
|
|
|
|
QApplication::processEvents();
|
|
|
|
QDialogButtonBox* bb = box.findChild<QDialogButtonBox*>("qt_msgbox_buttonbox");
|
|
|
|
QVERIFY(bb); //get the detail button
|
|
|
|
|
2018-12-07 16:21:50 +00:00
|
|
|
auto list = bb->buttons();
|
|
|
|
for (auto btn : list) {
|
2011-04-27 10:05:43 +00:00
|
|
|
if (btn && (btn->inherits("QPushButton"))) {
|
2015-10-13 07:46:56 +00:00
|
|
|
if (btn->text().remove(QLatin1Char('&')) != QMessageBox::tr("OK")
|
2011-11-14 09:18:22 +00:00
|
|
|
&& btn->text() != QMessageBox::tr("Show Details...")) {
|
2011-04-27 10:05:43 +00:00
|
|
|
QFAIL(qPrintable(QString("Unexpected messagebox button text: %1").arg(btn->text())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-11 20:02:03 +00:00
|
|
|
void tst_QMessageBox::expandDetailsWithoutMoving() // QTBUG-32473
|
2013-09-09 11:10:37 +00:00
|
|
|
{
|
|
|
|
tst_ResizingMessageBox box;
|
|
|
|
box.setDetailedText("bla");
|
|
|
|
box.show();
|
|
|
|
QApplication::postEvent(&box, new QEvent(QEvent::LanguageChange));
|
|
|
|
QApplication::processEvents();
|
|
|
|
QDialogButtonBox* bb = box.findChild<QDialogButtonBox*>("qt_msgbox_buttonbox");
|
|
|
|
QVERIFY(bb);
|
|
|
|
|
2018-12-07 16:21:50 +00:00
|
|
|
auto list = bb->buttons();
|
|
|
|
auto it = std::find_if(list.rbegin(), list.rend(), [&](QAbstractButton *btn) {
|
|
|
|
return btn && bb->buttonRole(btn) == QDialogButtonBox::ActionRole; });
|
|
|
|
QVERIFY(it != list.rend());
|
|
|
|
auto moreButton = *it;
|
|
|
|
|
2013-09-09 11:10:37 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&box));
|
2020-03-11 20:02:03 +00:00
|
|
|
QTRY_VERIFY2(!box.geometry().topLeft().isNull(), "window manager is expected to decorate and position the dialog");
|
2013-09-09 11:10:37 +00:00
|
|
|
QRect geom = box.geometry();
|
|
|
|
box.resized = false;
|
2020-03-11 20:02:03 +00:00
|
|
|
// now click the "more" button, and verify that the dialog resizes but does not move
|
2013-09-09 11:10:37 +00:00
|
|
|
moreButton->click();
|
|
|
|
QTRY_VERIFY(box.resized);
|
2020-03-11 20:02:03 +00:00
|
|
|
QVERIFY(box.geometry().height() > geom.height());
|
|
|
|
QCOMPARE(box.geometry().topLeft(), geom.topLeft());
|
2013-09-09 11:10:37 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_QMessageBox::incorrectDefaultButton()
|
|
|
|
{
|
2015-11-04 13:01:58 +00:00
|
|
|
ExecCloseHelper closeHelper;
|
|
|
|
closeHelper.start(Qt::Key_Escape);
|
2011-04-27 10:05:43 +00:00
|
|
|
//Do not crash here
|
|
|
|
QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added");
|
2018-12-07 16:21:50 +00:00
|
|
|
QMessageBox::question(nullptr, "", "I've been hit!",QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Save);
|
2015-11-04 13:01:58 +00:00
|
|
|
QVERIFY(closeHelper.done());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(Qt::Key_Escape);
|
2011-04-27 10:05:43 +00:00
|
|
|
QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added");
|
2018-12-07 16:21:50 +00:00
|
|
|
QMessageBox::question(nullptr, "", "I've been hit!",QFlag(QMessageBox::Ok | QMessageBox::Cancel),QMessageBox::Save);
|
2015-11-04 13:01:58 +00:00
|
|
|
QVERIFY(closeHelper.done());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-11-04 13:01:58 +00:00
|
|
|
closeHelper.start(Qt::Key_Escape);
|
2011-04-27 10:05:43 +00:00
|
|
|
QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added");
|
|
|
|
QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added");
|
|
|
|
//do not crash here -> call old function of QMessageBox in this case
|
2018-12-07 16:21:50 +00:00
|
|
|
QMessageBox::question(nullptr, "", "I've been hit!",QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Save | QMessageBox::Cancel,QMessageBox::Ok);
|
2015-11-04 13:01:58 +00:00
|
|
|
QVERIFY(closeHelper.done());
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QMessageBox::updateSize()
|
|
|
|
{
|
|
|
|
QMessageBox box;
|
|
|
|
box.setText("This is awesome");
|
|
|
|
box.show();
|
|
|
|
QSize oldSize = box.size();
|
|
|
|
QString longText;
|
|
|
|
for (int i = 0; i < 20; i++)
|
|
|
|
longText += box.text();
|
|
|
|
box.setText(longText);
|
|
|
|
QVERIFY(box.size() != oldSize); // should have grown
|
|
|
|
QVERIFY(box.width() > oldSize.width() || box.height() > oldSize.height());
|
|
|
|
oldSize = box.size();
|
|
|
|
box.setStandardButtons(QMessageBox::StandardButtons(0xFFFF));
|
|
|
|
QVERIFY(box.size() != oldSize); // should have grown
|
|
|
|
QVERIFY(box.width() > oldSize.width() || box.height() > oldSize.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QMessageBox::setInformativeText()
|
|
|
|
{
|
|
|
|
QMessageBox msgbox(QMessageBox::Warning, "", "", QMessageBox::Ok);
|
|
|
|
QString itext = "This is a very long message and it should make the dialog have enough width to fit this message in";
|
|
|
|
msgbox.setInformativeText(itext);
|
|
|
|
msgbox.show();
|
|
|
|
QCOMPARE(msgbox.informativeText(), itext);
|
|
|
|
QVERIFY2(msgbox.width() > 190, //verify it's big enough (task181688)
|
|
|
|
qPrintable(QString("%1 > 190").arg(msgbox.width())));
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QMessageBox::iconPixmap()
|
|
|
|
{
|
|
|
|
QMessageBox messageBox;
|
|
|
|
QCOMPARE(messageBox.iconPixmap(), QPixmap());
|
|
|
|
}
|
|
|
|
|
2018-12-07 15:04:33 +00:00
|
|
|
using SignalSignature = void(QDialog::*)();
|
|
|
|
Q_DECLARE_METATYPE(SignalSignature);
|
|
|
|
Q_DECLARE_METATYPE(QMessageBox::ButtonRole)
|
|
|
|
|
|
|
|
using ButtonsCreator = std::function<QVector<QPushButton*>(QMessageBox &)>;
|
|
|
|
Q_DECLARE_METATYPE(ButtonsCreator);
|
|
|
|
|
|
|
|
using RoleSet = QSet<QMessageBox::ButtonRole>;
|
|
|
|
Q_DECLARE_METATYPE(RoleSet);
|
|
|
|
|
|
|
|
void tst_QMessageBox::acceptedRejectedSignals()
|
|
|
|
{
|
|
|
|
QMessageBox messageBox(QMessageBox::Information, "Test window", "Test text");
|
|
|
|
|
|
|
|
QFETCH(ButtonsCreator, buttonsCreator);
|
|
|
|
QVERIFY(buttonsCreator);
|
|
|
|
|
|
|
|
const auto buttons = buttonsCreator(messageBox);
|
|
|
|
QVERIFY(!buttons.isEmpty());
|
|
|
|
|
|
|
|
QFETCH(RoleSet, roles);
|
|
|
|
QFETCH(SignalSignature, signalSignature);
|
|
|
|
for (auto button: buttons) {
|
|
|
|
QVERIFY(button);
|
|
|
|
|
|
|
|
messageBox.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&messageBox));
|
|
|
|
|
|
|
|
QSignalSpy spy(&messageBox, signalSignature);
|
|
|
|
QVERIFY(spy.isValid());
|
|
|
|
button->click();
|
|
|
|
|
|
|
|
if (roles.contains(messageBox.buttonRole(button)))
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
else
|
|
|
|
QVERIFY(spy.isEmpty());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void addAcceptedRow(const char *title, ButtonsCreator bc)
|
|
|
|
{
|
|
|
|
QTest::newRow(title) << (RoleSet() << QMessageBox::AcceptRole << QMessageBox::YesRole)
|
|
|
|
<< &QDialog::accepted << bc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void addRejectedRow(const char *title, ButtonsCreator bc)
|
|
|
|
{
|
|
|
|
QTest::newRow(title) << (RoleSet() << QMessageBox::RejectRole << QMessageBox::NoRole)
|
|
|
|
<< &QDialog::rejected << bc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void addCustomButtonsData()
|
|
|
|
{
|
|
|
|
ButtonsCreator buttonsCreator = [](QMessageBox &messageBox) {
|
|
|
|
QVector<QPushButton*> buttons(QMessageBox::NRoles);
|
|
|
|
for (int i = QMessageBox::AcceptRole; i < QMessageBox::NRoles; ++i) {
|
|
|
|
buttons[i] = messageBox.addButton(
|
|
|
|
QString("Button role: %1").arg(i), QMessageBox::ButtonRole(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return buttons;
|
|
|
|
};
|
|
|
|
|
|
|
|
addAcceptedRow("Accepted_CustomButtons", buttonsCreator);
|
|
|
|
addRejectedRow("Rejected_CustomButtons", buttonsCreator);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void addStandardButtonsData()
|
|
|
|
{
|
|
|
|
ButtonsCreator buttonsCreator = [](QMessageBox &messageBox) {
|
|
|
|
QVector<QPushButton*> buttons;
|
|
|
|
for (int i = QMessageBox::FirstButton; i <= QMessageBox::LastButton; i <<= 1)
|
|
|
|
buttons << messageBox.addButton(QMessageBox::StandardButton(i));
|
|
|
|
|
|
|
|
return buttons;
|
|
|
|
};
|
|
|
|
|
|
|
|
addAcceptedRow("Accepted_StandardButtons", buttonsCreator);
|
|
|
|
addRejectedRow("Rejected_StandardButtons", buttonsCreator);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QMessageBox::acceptedRejectedSignals_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<RoleSet>("roles");
|
|
|
|
QTest::addColumn<SignalSignature>("signalSignature");
|
|
|
|
QTest::addColumn<ButtonsCreator>("buttonsCreator");
|
|
|
|
|
|
|
|
addStandardButtonsData();
|
|
|
|
addCustomButtonsData();
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QTEST_MAIN(tst_QMessageBox)
|
|
|
|
#include "tst_qmessagebox.moc"
|