summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/dialogs
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@qt.io>2019-04-16 16:32:08 +0200
committerTobias Hunger <tobias.hunger@qt.io>2019-04-16 16:32:08 +0200
commit6630937e63ae5797487b86743a7733c8ae5cc42c (patch)
tree3d53dacf6430f9099e1fb20835881205de674961 /tests/auto/widgets/dialogs
parent37ed6dae00640f9cc980ffda05347c12a7eb5d7e (diff)
parentc7af193d2e49e9f10b86262e63d8d13abf72b5cf (diff)
Merge commit 'dev' into 'wip/cmake-merge'
Diffstat (limited to 'tests/auto/widgets/dialogs')
-rw-r--r--tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp8
-rw-r--r--tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp40
-rw-r--r--tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp13
-rw-r--r--tests/auto/widgets/dialogs/qfilesystemmodel/BLACKLIST11
-rw-r--r--tests/auto/widgets/dialogs/qfilesystemmodel/CMakeLists.txt30
-rw-r--r--tests/auto/widgets/dialogs/qfilesystemmodel/qfilesystemmodel.pro5
-rw-r--r--tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp83
-rw-r--r--tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp302
-rw-r--r--tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp4
9 files changed, 273 insertions, 223 deletions
diff --git a/tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp b/tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp
index 6a0ad4b3a4..413b865f04 100644
--- a/tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp
+++ b/tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp
@@ -116,10 +116,10 @@ void tst_QColorDialog::testGetRgba()
#ifdef Q_OS_MAC
QEXPECT_FAIL("", "Sending QTest::keyClick to OSX color dialog helper fails, see QTBUG-24320", Continue);
#endif
- bool ok = false;
- QTimer::singleShot(500, this, SLOT(postKeyReturn()));
- QColorDialog::getRgba(0xffffffff, &ok);
- QVERIFY(ok);
+ QTimer::singleShot(500, this, &tst_QColorDialog::postKeyReturn);
+ const QColor color = QColorDialog::getColor(QColor::fromRgba(0xffffffff), nullptr, QString(),
+ QColorDialog::ShowAlphaChannel);
+ QVERIFY(color.isValid());
}
void tst_QColorDialog::defaultOkButton()
diff --git a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
index ae8e4f7e04..f7482bae45 100644
--- a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
+++ b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
@@ -620,13 +620,13 @@ void tst_QFiledialog::acceptMode()
void tst_QFiledialog::confirmOverwrite()
{
QFileDialog fd;
- QCOMPARE(fd.confirmOverwrite(), true);
- fd.setConfirmOverwrite(true);
- QCOMPARE(fd.confirmOverwrite(), true);
- fd.setConfirmOverwrite(false);
- QCOMPARE(fd.confirmOverwrite(), false);
- fd.setConfirmOverwrite(true);
- QCOMPARE(fd.confirmOverwrite(), true);
+ QCOMPARE(fd.testOption(QFileDialog::DontConfirmOverwrite), false);
+ fd.setOption(QFileDialog::DontConfirmOverwrite, false);
+ QCOMPARE(fd.testOption(QFileDialog::DontConfirmOverwrite), false);
+ fd.setOption(QFileDialog::DontConfirmOverwrite, true);
+ QCOMPARE(fd.testOption(QFileDialog::DontConfirmOverwrite), true);
+ fd.setOption(QFileDialog::DontConfirmOverwrite, false);
+ QCOMPARE(fd.testOption(QFileDialog::DontConfirmOverwrite), false);
}
void tst_QFiledialog::defaultSuffix()
@@ -808,8 +808,8 @@ void tst_QFiledialog::isReadOnly()
//QCOMPARE(renameAction && renameAction->isEnabled(), true);
//QCOMPARE(deleteAction && deleteAction->isEnabled(), true);
- fd.setReadOnly(true);
- QCOMPARE(fd.isReadOnly(), true);
+ fd.setOption(QFileDialog::ReadOnly, true);
+ QCOMPARE(fd.testOption(QFileDialog::ReadOnly), true);
QCOMPARE(newButton && newButton->isEnabled(), false);
QCOMPARE(renameAction && renameAction->isEnabled(), false);
@@ -853,11 +853,11 @@ void tst_QFiledialog::resolveSymlinks()
QFileDialog fd;
// default
- QCOMPARE(fd.resolveSymlinks(), true);
- fd.setResolveSymlinks(false);
- QCOMPARE(fd.resolveSymlinks(), false);
- fd.setResolveSymlinks(true);
- QCOMPARE(fd.resolveSymlinks(), true);
+ QCOMPARE(fd.testOption(QFileDialog::DontResolveSymlinks), false);
+ fd.setOption(QFileDialog::DontResolveSymlinks, true);
+ QCOMPARE(fd.testOption(QFileDialog::DontResolveSymlinks), true);
+ fd.setOption(QFileDialog::DontResolveSymlinks, false);
+ QCOMPARE(fd.testOption(QFileDialog::DontResolveSymlinks), false);
// the file dialog doesn't do anything based upon this, just passes it to the model
// the model should fully test it, don't test it here
@@ -1119,7 +1119,7 @@ void tst_QFiledialog::setNameFilter()
QFileDialog fd;
fd.setNameFilters(filters);
- fd.setNameFilterDetailsVisible(nameFilterDetailsVisible);
+ fd.setOption(QFileDialog::HideNameFilterDetails, !nameFilterDetailsVisible);
fd.selectNameFilter(selectFilter);
QCOMPARE(fd.selectedNameFilter(), expectedSelectedFilter);
}
@@ -1421,6 +1421,16 @@ void tst_QFiledialog::clearLineEdit()
QTRY_VERIFY(fd.directory().absolutePath() != workDirPath);
QVERIFY(lineEdit->text().isEmpty());
+
+ // QTBUG-71415: When pressing back, the selection (activated
+ // directory) should be restored.
+ QToolButton *backButton = fd.findChild<QToolButton*>("backButton");
+ QVERIFY(backButton);
+ QTreeView *treeView = fd.findChildren<QTreeView*>("treeView").value(0);
+ QVERIFY(treeView);
+ backButton->click();
+ QTRY_COMPARE(treeView->selectionModel()->selectedIndexes().value(0).data().toString(),
+ dirName);
}
void tst_QFiledialog::enableChooseButton()
diff --git a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
index 8f9a8c11a7..869418371c 100644
--- a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
+++ b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
@@ -252,7 +252,7 @@ void tst_QFileDialog2::showNameFilterDetails()
QFileDialog fd;
QComboBox *filters = fd.findChild<QComboBox*>("fileTypeCombo");
QVERIFY(filters);
- QVERIFY(fd.isNameFilterDetailsVisible());
+ QVERIFY(!fd.testOption(QFileDialog::HideNameFilterDetails));
QStringList filterChoices;
@@ -261,12 +261,12 @@ void tst_QFileDialog2::showNameFilterDetails()
<< "Any files (*.*)";
fd.setNameFilters(filterChoices);
- fd.setNameFilterDetailsVisible(false);
+ fd.setOption(QFileDialog::HideNameFilterDetails, true);
QCOMPARE(filters->itemText(0), QString("Image files"));
QCOMPARE(filters->itemText(1), QString("Text files"));
QCOMPARE(filters->itemText(2), QString("Any files"));
- fd.setNameFilterDetailsVisible(true);
+ fd.setOption(QFileDialog::HideNameFilterDetails, false);
QCOMPARE(filters->itemText(0), filterChoices.at(0));
QCOMPARE(filters->itemText(1), filterChoices.at(1));
QCOMPARE(filters->itemText(2), filterChoices.at(2));
@@ -486,7 +486,7 @@ protected:
parentIndex = source_parent;
QString path;
- path = parentIndex.child(source_row,0).data(Qt::DisplayRole).toString();
+ path = sourceModel()->index(source_row, 0, parentIndex).data(Qt::DisplayRole).toString();
do {
path = parentIndex.data(Qt::DisplayRole).toString() + QLatin1Char('/') + path;
@@ -601,6 +601,11 @@ void tst_QFileDialog2::task227930_correctNavigationKeyboardBehavior()
fd.setDirectory(current.absolutePath());
fd.show();
QVERIFY(QTest::qWaitForWindowActive(&fd));
+
+ // Ensure LayoutRequest event is processed so that the list view
+ // is sorted correctly to have the directory entires at the top.
+ QCoreApplication::processEvents();
+
QListView *list = fd.findChild<QListView*>("listView");
QVERIFY(list);
QTest::keyClick(list, Qt::Key_Down);
diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/BLACKLIST b/tests/auto/widgets/dialogs/qfilesystemmodel/BLACKLIST
new file mode 100644
index 0000000000..01679eb6ee
--- /dev/null
+++ b/tests/auto/widgets/dialogs/qfilesystemmodel/BLACKLIST
@@ -0,0 +1,11 @@
+winrt
+[sort:QFileDialog usage]
+ubuntu
+b2qt
+[specialFiles]
+ubuntu
+b2qt
+[dirsBeforeFiles]
+ubuntu
+b2qt
+windows
diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/CMakeLists.txt b/tests/auto/widgets/dialogs/qfilesystemmodel/CMakeLists.txt
index bf615c6805..336ce4ca15 100644
--- a/tests/auto/widgets/dialogs/qfilesystemmodel/CMakeLists.txt
+++ b/tests/auto/widgets/dialogs/qfilesystemmodel/CMakeLists.txt
@@ -1,5 +1,31 @@
-add_qt_test("tst_qfilesystemmodel" SOURCES tst_qfilesystemmodel.cpp
+# Generated from qfilesystemmodel.pro.
+
+#####################################################################
+## tst_qfilesystemmodel Test:
+#####################################################################
+
+add_qt_test(tst_qfilesystemmodel
+ SOURCES
+ ../../../../shared/emulationdetector.h
+ tst_qfilesystemmodel.cpp
+ INCLUDE_DIRECTORIES
+ ../../../../shared
LIBRARIES
- Qt::WidgetsPrivate
Qt::CorePrivate
+ Qt::WidgetsPrivate
+ PUBLIC_LIBRARIES
+ Qt::Core
+ Qt::Widgets
)
+
+#### Keys ignored in scope 1:.:.:qfilesystemmodel.pro:<TRUE>:
+# CONFIG = "testcase"
+
+## Scopes:
+#####################################################################
+
+#### Keys ignored in scope 2:.:.:qfilesystemmodel.pro:WIN32:
+# testcase.timeout = "900"
+
+#### Keys ignored in scope 3:.:.:qfilesystemmodel.pro:APPLE_OSX:
+# testcase.timeout = "900"
diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/qfilesystemmodel.pro b/tests/auto/widgets/dialogs/qfilesystemmodel/qfilesystemmodel.pro
index bc4671f60c..db8cf7de3f 100644
--- a/tests/auto/widgets/dialogs/qfilesystemmodel/qfilesystemmodel.pro
+++ b/tests/auto/widgets/dialogs/qfilesystemmodel/qfilesystemmodel.pro
@@ -1,3 +1,6 @@
+INCLUDEPATH += ../../../../shared
+HEADERS += ../../../../shared/emulationdetector.h
+
CONFIG += testcase
# This testcase can be slow on Windows and OS X, and may interfere with other file system tests.
win32:testcase.timeout = 900
@@ -8,5 +11,3 @@ QT += core-private testlib
SOURCES += tst_qfilesystemmodel.cpp
TARGET = tst_qfilesystemmodel
-
-CONFIG += insignificant_test # QTBUG-29403
diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
index d8a680881a..665a116a3a 100644
--- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
+++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
@@ -27,6 +27,7 @@
****************************************************************************/
+#include <emulationdetector.h>
#include <QtTest/QtTest>
#ifdef QT_BUILD_INTERNAL
#include <private/qfilesystemmodel_p.h>
@@ -51,10 +52,15 @@
// Will try to wait for the condition while allowing event processing
// for a maximum of 5 seconds.
-#define TRY_WAIT(expr) \
+#define TRY_WAIT(expr, timedOut) \
do { \
+ *timedOut = true; \
const int step = 50; \
- for (int __i = 0; __i < 5000 && !(expr); __i+=step) { \
+ for (int __i = 0; __i < 5000; __i += step) { \
+ if (expr) { \
+ *timedOut = false; \
+ break; \
+ } \
QTest::qWait(step); \
} \
} while(0)
@@ -123,6 +129,8 @@ private slots:
protected:
bool createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount = 0, const QStringList &intial_dirs = QStringList());
+ QModelIndex prepareTestModelRoot(const QString &test_path, QSignalSpy **spy2 = nullptr,
+ QSignalSpy **spy3 = nullptr);
private:
QFileSystemModel *model;
@@ -306,7 +314,11 @@ void tst_QFileSystemModel::iconProvider()
bool tst_QFileSystemModel::createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount, const QStringList &initial_dirs)
{
//qDebug() << (model->rowCount(model->index(test_path))) << existingFileCount << initial_files;
- TRY_WAIT((model->rowCount(model->index(test_path)) == existingFileCount));
+ bool timedOut = false;
+ TRY_WAIT((model->rowCount(model->index(test_path)) == existingFileCount), &timedOut);
+ if (timedOut)
+ return false;
+
for (int i = 0; i < initial_dirs.count(); ++i) {
QDir dir(test_path);
if (!dir.exists()) {
@@ -363,23 +375,45 @@ bool tst_QFileSystemModel::createFiles(const QString &test_path, const QStringLi
return true;
}
-void tst_QFileSystemModel::rowCount()
+QModelIndex tst_QFileSystemModel::prepareTestModelRoot(const QString &test_path, QSignalSpy **spy2,
+ QSignalSpy **spy3)
{
- QString tmp = flatDirTestPath;
- QVERIFY(createFiles(tmp, QStringList()));
+ if (model->rowCount(model->index(test_path)) != 0)
+ return QModelIndex();
- QSignalSpy spy2(model, SIGNAL(rowsInserted(QModelIndex,int,int)));
- QSignalSpy spy3(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)));
+ if (spy2)
+ *spy2 = new QSignalSpy(model, &QFileSystemModel::rowsInserted);
+ if (spy3)
+ *spy3 = new QSignalSpy(model, &QFileSystemModel::rowsAboutToBeInserted);
- QStringList files = QStringList() << "b" << "d" << "f" << "h" << "j" << ".a" << ".c" << ".e" << ".g";
+ QStringList files = { "b", "d", "f", "h", "j", ".a", ".c", ".e", ".g" };
QString l = "b,d,f,h,j,.a,.c,.e,.g";
- QVERIFY(createFiles(tmp, files));
+ if (!createFiles(test_path, files))
+ return QModelIndex();
- QModelIndex root = model->setRootPath(tmp);
- QTRY_COMPARE(model->rowCount(root), 5);
- QVERIFY(spy2.count() > 0);
- QVERIFY(spy3.count() > 0);
+ QModelIndex root = model->setRootPath(test_path);
+ if (!root.isValid())
+ return QModelIndex();
+
+ bool timedOut = false;
+ TRY_WAIT(model->rowCount(root) == 5, &timedOut);
+ if (timedOut)
+ return QModelIndex();
+
+ return root;
+}
+
+void tst_QFileSystemModel::rowCount()
+{
+ const QString tmp = flatDirTestPath;
+ QSignalSpy *spy2 = nullptr;
+ QSignalSpy *spy3 = nullptr;
+ QModelIndex root = prepareTestModelRoot(flatDirTestPath, &spy2, &spy3);
+ QVERIFY(root.isValid());
+
+ QVERIFY(spy2 && spy2->count() > 0);
+ QVERIFY(spy3 && spy3->count() > 0);
}
void tst_QFileSystemModel::rowsInserted_data()
@@ -401,9 +435,9 @@ static inline QString lastEntry(const QModelIndex &root)
void tst_QFileSystemModel::rowsInserted()
{
- QString tmp = flatDirTestPath;
- rowCount();
- QModelIndex root = model->index(model->rootPath());
+ const QString tmp = flatDirTestPath;
+ QModelIndex root = prepareTestModelRoot(tmp);
+ QVERIFY(root.isValid());
QFETCH(int, ascending);
QFETCH(int, count);
@@ -454,9 +488,9 @@ void tst_QFileSystemModel::rowsRemoved_data()
void tst_QFileSystemModel::rowsRemoved()
{
- QString tmp = flatDirTestPath;
- rowCount();
- QModelIndex root = model->index(model->rootPath());
+ const QString tmp = flatDirTestPath;
+ QModelIndex root = prepareTestModelRoot(tmp);
+ QVERIFY(root.isValid());
QFETCH(int, count);
QFETCH(int, ascending);
@@ -509,9 +543,9 @@ void tst_QFileSystemModel::dataChanged()
{
QSKIP("This can't be tested right now since we don't watch files, only directories.");
- QString tmp = flatDirTestPath;
- rowCount();
- QModelIndex root = model->index(model->rootPath());
+ const QString tmp = flatDirTestPath;
+ QModelIndex root = prepareTestModelRoot(tmp);
+ QVERIFY(root.isValid());
QFETCH(int, count);
QFETCH(int, assending);
@@ -755,6 +789,9 @@ void tst_QFileSystemModel::sort()
MyFriendFileSystemModel *myModel = new MyFriendFileSystemModel();
QTreeView *tree = new QTreeView();
+ if (fileDialogMode && EmulationDetector::isRunningArmOnX86())
+ QSKIP("Crashes in QEMU. QTBUG-70572");
+
#ifdef QT_BUILD_INTERNAL
if (fileDialogMode)
myModel->d_func()->disableRecursiveSort = true;
diff --git a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp
index 049468fd7c..76314564f1 100644
--- a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp
+++ b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp
@@ -38,49 +38,6 @@
#include <qpa/qplatformtheme.h>
#include <private/qguiapplication_p.h>
-#define CONVENIENCE_FUNC_SYMS(func) \
- { \
- int x1 = QMessageBox::func(0, "Foo", "Bar"); \
- int x3 = QMessageBox::func(0, "Foo", "Bar", "Save"); \
- int x6 = QMessageBox::func(0, "Foo", "Bar", "Save", "Save As"); \
- int x7 = QMessageBox::func(0, "Foo", "Bar", "Save", "Save As", "Dont Save"); \
- int x8 = QMessageBox::func(0, "Foo", "Bar", "Save", "Save As", "Dont Save", 1); \
- int x9 = QMessageBox::func(0, "Foo", "Bar", "Save", "Save As", "Dont Save", 1, 2); \
- int x10 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::YesAll, QMessageBox::Yes); \
- int x11 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::YesAll, QMessageBox::Yes, \
- QMessageBox::No); \
- qDebug("%d %d %d %d %d %d %d %d", x1, x3, x6, x7, x8, x9, x10, x11); \
- { \
- int x4 = QMessageBox::func(0, "Foo", "Bar", (int)QMessageBox::Yes, (int)QMessageBox::No); \
- int x5 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes, (int)QMessageBox::No); \
- int x6 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes | QMessageBox::Default, (int)QMessageBox::No); \
- int x7 = QMessageBox::func(0, "Foo", "Bar", (int)QMessageBox::Yes, QMessageBox::No); \
- int x8 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes, QMessageBox::No); \
- int x9 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No); \
- int x10 = QMessageBox::func(0, "Foo", "Bar", (int)QMessageBox::Yes, (int)QMessageBox::No, (int)QMessageBox::Ok); \
- int x11 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes, (int)QMessageBox::No, (int)QMessageBox::Ok); \
- int x12 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes | QMessageBox::Default, (int)QMessageBox::No, (int)QMessageBox::Ok); \
- int x13 = QMessageBox::func(0, "Foo", "Bar", (int)QMessageBox::Yes, QMessageBox::No, (int)QMessageBox::Ok); \
- int x14 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes, QMessageBox::No, (int)QMessageBox::Ok); \
- int x15 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, (int)QMessageBox::Ok); \
- int x16 = QMessageBox::func(0, "Foo", "Bar", (int)QMessageBox::Yes, (int)QMessageBox::No, QMessageBox::Ok); \
- int x17 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes, (int)QMessageBox::No, QMessageBox::Ok); \
- int x18 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes | QMessageBox::Default, (int)QMessageBox::No, QMessageBox::Ok); \
- int x19 = QMessageBox::func(0, "Foo", "Bar", (int)QMessageBox::Yes, QMessageBox::No, QMessageBox::Ok); \
- int x20 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes, QMessageBox::No, QMessageBox::Ok); \
- int x21 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Ok); \
- qDebug("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21); \
- } \
- }
-
-#define CONVENIENCE_FUNC_SYMS_EXTRA(func) \
- { \
- int x1 = QMessageBox::func(0, "Foo", "Bar", (int)QMessageBox::Yes); \
- int x2 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes); \
- int x3 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes | QMessageBox::Default); \
- qDebug("%d %d %d", x1, x2, x3); \
- }
-
class tst_QMessageBox : public QObject
{
Q_OBJECT
@@ -103,13 +60,16 @@ private slots:
void staticSourceCompat();
void instanceSourceCompat();
- void testSymbols();
void incorrectDefaultButton();
void updateSize();
void setInformativeText();
void iconPixmap();
+ // QTBUG-44131
+ void acceptedRejectedSignals();
+ void acceptedRejectedSignals_data();
+
void cleanup();
};
@@ -210,9 +170,9 @@ void tst_QMessageBox::button()
{
QMessageBox msgBox;
msgBox.addButton("retry", QMessageBox::DestructiveRole);
- QVERIFY(msgBox.button(QMessageBox::Ok) == 0); // not added yet
+ QVERIFY(msgBox.button(QMessageBox::Ok) == nullptr); // not added yet
QPushButton *b1 = msgBox.addButton(QMessageBox::Ok);
- QCOMPARE(msgBox.button(QMessageBox::Ok), (QAbstractButton *)b1); // just added
+ QCOMPARE(msgBox.button(QMessageBox::Ok), static_cast<QAbstractButton *>(b1)); // just added
QCOMPARE(msgBox.standardButton(b1), QMessageBox::Ok);
msgBox.addButton(QMessageBox::Cancel);
QCOMPARE(msgBox.standardButtons(), QMessageBox::Ok | QMessageBox::Cancel);
@@ -220,12 +180,12 @@ void tst_QMessageBox::button()
// remove the cancel, should not exist anymore
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
QVERIFY(!msgBox.button(QMessageBox::Cancel));
- QVERIFY(msgBox.button(QMessageBox::Yes) != 0);
+ QVERIFY(msgBox.button(QMessageBox::Yes) != nullptr);
// should not crash
QPushButton *b4 = new QPushButton;
msgBox.addButton(b4, QMessageBox::DestructiveRole);
- msgBox.addButton(0, QMessageBox::ActionRole);
+ msgBox.addButton(nullptr, QMessageBox::ActionRole);
}
void tst_QMessageBox::defaultButton()
@@ -237,7 +197,7 @@ void tst_QMessageBox::defaultButton()
QVERIFY(!msgBox.defaultButton());
QPushButton pushButton;
msgBox.setDefaultButton(&pushButton);
- QVERIFY(msgBox.defaultButton() == 0); // we have not added it yet
+ QVERIFY(msgBox.defaultButton() == nullptr); // we have not added it yet
QPushButton *retryButton = msgBox.addButton(QMessageBox::Retry);
msgBox.setDefaultButton(retryButton);
QCOMPARE(msgBox.defaultButton(), retryButton);
@@ -248,11 +208,11 @@ void tst_QMessageBox::defaultButton()
closeHelper.start(Qt::Key_Enter, &msgBox);
msgBox.exec();
- QCOMPARE(msgBox.clickedButton(), (QAbstractButton *)retryButton);
+ QCOMPARE(msgBox.clickedButton(), static_cast<QAbstractButton *>(retryButton));
QAbstractButton *okButton = msgBox.button(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
- QCOMPARE(msgBox.defaultButton(), (QPushButton *)okButton);
+ QCOMPARE(msgBox.defaultButton(), static_cast<QPushButton *>(okButton));
closeHelper.start(Qt::Key_Enter, &msgBox);
msgBox.exec();
QCOMPARE(msgBox.clickedButton(), okButton);
@@ -260,7 +220,7 @@ void tst_QMessageBox::defaultButton()
QCOMPARE(msgBox.defaultButton(), okButton);
msgBox.removeButton(okButton);
delete okButton;
- okButton = 0;
+ okButton = nullptr;
QVERIFY(!msgBox.defaultButton());
msgBox.setDefaultButton(QMessageBox::Ok);
QVERIFY(!msgBox.defaultButton());
@@ -287,7 +247,7 @@ void tst_QMessageBox::escapeButton()
QVERIFY(msgBox.clickedButton() == msgBox.button(QMessageBox::Cancel)); // auto detected (cancel)
msgBox.setEscapeButton(retryButton);
- QCOMPARE(msgBox.escapeButton(), (QAbstractButton *)retryButton);
+ QCOMPARE(msgBox.escapeButton(), static_cast<QAbstractButton *>(retryButton));
// with escape
closeHelper.start(Qt::Key_Escape, &msgBox);
@@ -297,7 +257,7 @@ void tst_QMessageBox::escapeButton()
// with close
closeHelper.start(ExecCloseHelper::CloseWindow, &msgBox);
msgBox.exec();
- QCOMPARE(msgBox.clickedButton(), (QAbstractButton *)retryButton);
+ QCOMPARE(msgBox.clickedButton(), static_cast<QAbstractButton *>(retryButton));
QAbstractButton *okButton = msgBox.button(QMessageBox::Ok);
msgBox.setEscapeButton(QMessageBox::Ok);
@@ -309,7 +269,7 @@ void tst_QMessageBox::escapeButton()
QCOMPARE(msgBox.escapeButton(), okButton);
msgBox.removeButton(okButton);
delete okButton;
- okButton = 0;
+ okButton = nullptr;
QVERIFY(!msgBox.escapeButton());
msgBox.setEscapeButton(QMessageBox::Ok);
QVERIFY(!msgBox.escapeButton());
@@ -353,28 +313,28 @@ void tst_QMessageBox::statics()
ExecCloseHelper closeHelper;
for (int i = 0; i < 4; i++) {
closeHelper.start(Qt::Key_Escape);
- QMessageBox::StandardButton sb = (*statics[i])(0, "caption",
+ QMessageBox::StandardButton sb = (*statics[i])(nullptr, "caption",
"text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help | QMessageBox::Cancel,
QMessageBox::NoButton);
QCOMPARE(sb, QMessageBox::Cancel);
QVERIFY(closeHelper.done());
closeHelper.start(ExecCloseHelper::CloseWindow);
- sb = (*statics[i])(0, "caption",
+ sb = (*statics[i])(nullptr, "caption",
"text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help | QMessageBox::Cancel,
QMessageBox::NoButton);
QCOMPARE(sb, QMessageBox::Cancel);
QVERIFY(closeHelper.done());
closeHelper.start(Qt::Key_Enter);
- sb = (*statics[i])(0, "caption",
+ sb = (*statics[i])(nullptr, "caption",
"text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help,
QMessageBox::Yes);
QCOMPARE(sb, QMessageBox::Yes);
QVERIFY(closeHelper.done());
closeHelper.start(Qt::Key_Enter);
- sb = (*statics[i])(0, "caption",
+ sb = (*statics[i])(nullptr, "caption",
"text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help,
QMessageBox::No);
QCOMPARE(sb, QMessageBox::No);
@@ -400,7 +360,7 @@ void tst_QMessageBox::about()
{
ExecCloseHelper closeHelper;
closeHelper.start(Qt::Key_Escape);
- QMessageBox::about(0, "Caption", "This is an auto test");
+ QMessageBox::about(nullptr, "Caption", "This is an auto test");
// On Mac, about and aboutQt are not modal, so we need to
// explicitly run the event loop
#ifdef Q_OS_MAC
@@ -412,7 +372,7 @@ void tst_QMessageBox::about()
const int keyToSend = Qt::Key_Enter;
closeHelper.start(keyToSend);
- QMessageBox::aboutQt(0, "Caption");
+ QMessageBox::aboutQt(nullptr, "Caption");
#ifdef Q_OS_MAC
QTRY_VERIFY(closeHelper.done());
#else
@@ -427,7 +387,7 @@ void tst_QMessageBox::staticSourceCompat()
// source compat tests for < 4.2
ExecCloseHelper closeHelper;
closeHelper.start(Qt::Key_Enter);
- ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes, QMessageBox::No);
+ ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes, QMessageBox::No);
int expectedButton = int(QMessageBox::Yes);
if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
const int dialogButtonBoxLayout = theme->themeHint(QPlatformTheme::DialogButtonBoxLayout).toInt();
@@ -439,39 +399,39 @@ void tst_QMessageBox::staticSourceCompat()
QVERIFY(closeHelper.done());
closeHelper.start(Qt::Key_Enter);
- ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No);
+ ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No);
QCOMPARE(ret, int(QMessageBox::Yes));
QVERIFY(closeHelper.done());
closeHelper.start(Qt::Key_Enter);
- ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes, QMessageBox::No | QMessageBox::Default);
+ ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes, QMessageBox::No | QMessageBox::Default);
QCOMPARE(ret, int(QMessageBox::No));
QVERIFY(closeHelper.done());
closeHelper.start(Qt::Key_Enter);
- ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape);
+ ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape);
QCOMPARE(ret, int(QMessageBox::Yes));
QVERIFY(closeHelper.done());
closeHelper.start(Qt::Key_Enter);
- ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes | QMessageBox::Escape, QMessageBox::No | QMessageBox::Default);
+ ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes | QMessageBox::Escape, QMessageBox::No | QMessageBox::Default);
QCOMPARE(ret, int(QMessageBox::No));
QVERIFY(closeHelper.done());
// the button text versions
closeHelper.start(Qt::Key_Enter);
- ret = QMessageBox::information(0, "title", "text", "Yes", "No", QString(), 1);
+ ret = QMessageBox::information(nullptr, "title", "text", "Yes", "No", QString(), 1);
QCOMPARE(ret, 1);
QVERIFY(closeHelper.done());
if (0) { // don't run these tests since the dialog won't close!
closeHelper.start(Qt::Key_Escape);
- ret = QMessageBox::information(0, "title", "text", "Yes", "No", QString(), 1);
+ ret = QMessageBox::information(nullptr, "title", "text", "Yes", "No", QString(), 1);
QCOMPARE(ret, -1);
QVERIFY(closeHelper.done());
closeHelper.start(Qt::Key_Escape);
- ret = QMessageBox::information(0, "title", "text", "Yes", "No", QString(), 0, 1);
+ ret = QMessageBox::information(nullptr, "title", "text", "Yes", "No", QString(), 0, 1);
QCOMPARE(ret, 1);
QVERIFY(closeHelper.done());
}
@@ -505,96 +465,6 @@ void tst_QMessageBox::instanceSourceCompat()
#endif
}
-void tst_QMessageBox::testSymbols()
-{
- return;
-
- QMessageBox::Icon icon;
- icon = QMessageBox::NoIcon;
- icon = QMessageBox::Information;
- icon = QMessageBox::Warning;
- icon = QMessageBox::Critical;
- icon = QMessageBox::Question;
-
- QMessageBox mb1;
- QMessageBox mb2(0);
- QMessageBox mb3(&mb1);
- QMessageBox mb3b("title", "text", QMessageBox::Critical, int(QMessageBox::Yes),
- int(QMessageBox::No), int(QMessageBox::Cancel), &mb1, Qt::Dialog);
-
- QMessageBox::Button button = QMessageBox::NoButton;
- button = QMessageBox::Ok;
- button = QMessageBox::Cancel;
- button = QMessageBox::Yes;
- button = QMessageBox::No;
- button = QMessageBox::Abort;
- button = QMessageBox::Retry;
- button = QMessageBox::Ignore;
- button = QMessageBox::YesAll;
- button = QMessageBox::NoAll;
- button = QMessageBox::ButtonMask;
- button = QMessageBox::Default;
- button = QMessageBox::Escape;
- button = QMessageBox::FlagMask;
- QVERIFY(button);
-
- const QString text = QStringLiteral("Foo");
- mb1.setText(text);
- QCOMPARE(mb1.text(), text);
-
- icon = mb1.icon();
- QCOMPARE(icon, QMessageBox::NoIcon);
- mb1.setIcon(QMessageBox::Question);
- QCOMPARE(mb1.icon(), QMessageBox::Question);
-
- QPixmap iconPixmap = mb1.iconPixmap();
- mb1.setIconPixmap(iconPixmap);
- QCOMPARE(mb1.icon(), QMessageBox::NoIcon);
-
- QCOMPARE(mb1.buttonText(QMessageBox::Ok), QLatin1String("OK"));
- QCOMPARE(mb1.buttonText(QMessageBox::Cancel), QString());
- QCOMPARE(mb1.buttonText(QMessageBox::Ok | QMessageBox::Default), QString());
-
- const QString button1 = QStringLiteral("Bar");
- mb2.setButtonText(QMessageBox::Cancel, QStringLiteral("Foo"));
- mb2.setButtonText(QMessageBox::Ok, button1);
- mb2.setButtonText(QMessageBox::Ok | QMessageBox::Default, QStringLiteral("Baz"));
-
- QCOMPARE(mb2.buttonText(QMessageBox::Cancel), QString());
- QCOMPARE(mb2.buttonText(QMessageBox::Ok), button1);
-
- QVERIFY(mb3b.buttonText(QMessageBox::Yes).endsWith("Yes"));
- QCOMPARE(mb3b.buttonText(QMessageBox::YesAll), QString());
- QCOMPARE(mb3b.buttonText(QMessageBox::Ok), QString());
-
- const QString button2 = QStringLiteral("Blah");
- mb3b.setButtonText(QMessageBox::Yes, button2);
- mb3b.setButtonText(QMessageBox::YesAll, QStringLiteral("Zoo"));
- mb3b.setButtonText(QMessageBox::Ok, QStringLiteral("Zoo"));
-
- QCOMPARE(mb3b.buttonText(QMessageBox::Yes), button2);
- QCOMPARE(mb3b.buttonText(QMessageBox::YesAll), QString());
- QCOMPARE(mb3b.buttonText(QMessageBox::Ok), QString());
-
- QCOMPARE(mb1.textFormat(), Qt::AutoText);
- mb1.setTextFormat(Qt::PlainText);
- QCOMPARE(mb1.textFormat(), Qt::PlainText);
-
- CONVENIENCE_FUNC_SYMS(information);
- CONVENIENCE_FUNC_SYMS_EXTRA(information);
- CONVENIENCE_FUNC_SYMS(question);
- CONVENIENCE_FUNC_SYMS_EXTRA(question);
- CONVENIENCE_FUNC_SYMS(warning);
- CONVENIENCE_FUNC_SYMS(critical);
-
- QSize sizeHint = mb1.sizeHint();
- QVERIFY(sizeHint.width() > 20 && sizeHint.height() > 20);
-
- QMessageBox::about(&mb1, "title", "text");
- QMessageBox::aboutQt(&mb1);
- QMessageBox::aboutQt(&mb1, "title");
-}
-
void tst_QMessageBox::detailsText()
{
QMessageBox box;
@@ -618,9 +488,8 @@ void tst_QMessageBox::detailsButtonText()
QDialogButtonBox* bb = box.findChild<QDialogButtonBox*>("qt_msgbox_buttonbox");
QVERIFY(bb); //get the detail button
- QList<QAbstractButton *> list = bb->buttons();
- QAbstractButton* btn = NULL;
- foreach(btn, list) {
+ auto list = bb->buttons();
+ for (auto btn : list) {
if (btn && (btn->inherits("QPushButton"))) {
if (btn->text().remove(QLatin1Char('&')) != QMessageBox::tr("OK")
&& btn->text() != QMessageBox::tr("Show Details...")) {
@@ -640,12 +509,12 @@ void tst_QMessageBox::expandDetails_QTBUG_32473()
QDialogButtonBox* bb = box.findChild<QDialogButtonBox*>("qt_msgbox_buttonbox");
QVERIFY(bb);
- QList<QAbstractButton *> list = bb->buttons();
- QAbstractButton* moreButton = NULL;
- foreach (QAbstractButton* btn, list)
- if (btn && bb->buttonRole(btn) == QDialogButtonBox::ActionRole)
- moreButton = btn;
- QVERIFY(moreButton);
+ 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;
+
QVERIFY(QTest::qWaitForWindowExposed(&box));
QRect geom = box.geometry();
box.resized = false;
@@ -667,19 +536,19 @@ void tst_QMessageBox::incorrectDefaultButton()
closeHelper.start(Qt::Key_Escape);
//Do not crash here
QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added");
- QMessageBox::question( 0, "", "I've been hit!",QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Save );
+ QMessageBox::question(nullptr, "", "I've been hit!",QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Save);
QVERIFY(closeHelper.done());
closeHelper.start(Qt::Key_Escape);
QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added");
- QMessageBox::question( 0, "", "I've been hit!",QFlag(QMessageBox::Ok | QMessageBox::Cancel),QMessageBox::Save );
+ QMessageBox::question(nullptr, "", "I've been hit!",QFlag(QMessageBox::Ok | QMessageBox::Cancel),QMessageBox::Save);
QVERIFY(closeHelper.done());
closeHelper.start(Qt::Key_Escape);
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
- QMessageBox::question( 0, "", "I've been hit!",QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Save | QMessageBox::Cancel,QMessageBox::Ok);
+ QMessageBox::question(nullptr, "", "I've been hit!",QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Save | QMessageBox::Cancel,QMessageBox::Ok);
QVERIFY(closeHelper.done());
}
@@ -718,5 +587,96 @@ void tst_QMessageBox::iconPixmap()
QCOMPARE(messageBox.iconPixmap(), QPixmap());
}
+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();
+}
+
QTEST_MAIN(tst_QMessageBox)
#include "tst_qmessagebox.moc"
diff --git a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp
index 2ada4fedb6..6f527e7b6b 100644
--- a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp
+++ b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp
@@ -252,7 +252,7 @@ class QTestTranslator : public QTranslator
{
const QString m_str;
public:
- explicit QTestTranslator(QString str) : m_str(qMove(str)) {}
+ explicit QTestTranslator(QString str) : m_str(std::move(str)) {}
QString translate(const char *, const char *sourceText, const char *, int) const override
{ return m_str + sourceText + m_str; }
@@ -265,7 +265,7 @@ class QTranslatorGuard {
Translator t;
public:
template <typename Arg>
- explicit QTranslatorGuard(Arg a) : t(qMove(a))
+ explicit QTranslatorGuard(Arg a) : t(std::move(a))
{ qApp->installTranslator(&t); }
~QTranslatorGuard()
{ qApp->removeTranslator(&t); }