summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp')
-rw-r--r--tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp211
1 files changed, 93 insertions, 118 deletions
diff --git a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
index 05f42cf685..d182d2edec 100644
--- a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
+++ b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
@@ -1,31 +1,26 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -68,7 +63,7 @@
#include <unistd.h> // for pathconf() on OS X
#ifdef QT_BUILD_INTERNAL
QT_BEGIN_NAMESPACE
-extern Q_GUI_EXPORT QString qt_tildeExpansion(const QString &path, bool *expanded = 0);
+extern Q_GUI_EXPORT QString qt_tildeExpansion(const QString &path);
QT_END_NAMESPACE
#endif
#endif
@@ -85,32 +80,14 @@ static inline bool isCaseSensitiveFileSystem(const QString &path)
#endif
}
-
-class QNonNativeFileDialog : public QFileDialog
-{
- Q_OBJECT
-public:
- QNonNativeFileDialog(QWidget *parent = 0, const QString &caption = QString(), const QString &directory = QString(), const QString &filter = QString())
- : QFileDialog(parent, caption, directory, filter)
- {
- setOption(QFileDialog::DontUseNativeDialog, true);
- }
-};
-
class tst_QFiledialog : public QObject
{
Q_OBJECT
-public:
- tst_QFiledialog();
- virtual ~tst_QFiledialog();
-
-public slots:
+private slots:
void initTestCase();
void init();
void cleanup();
-
-private slots:
void currentChangedSignal();
#ifdef QT_BUILD_INTERNAL
void directoryEnteredSignal();
@@ -155,7 +132,6 @@ private slots:
void saveButtonText();
void clearLineEdit();
void enableChooseButton();
- void widgetlessNativeDialog();
void selectedFilesWithoutWidgets();
void trailingDotsAndSpaces();
#ifdef Q_OS_UNIX
@@ -167,18 +143,24 @@ private slots:
void rejectModalDialogs();
void QTBUG49600_nativeIconProviderCrash();
+ // NOTE: Please keep widgetlessNativeDialog() as the LAST test!
+ //
+ // widgetlessNativeDialog() is the only test function that creates
+ // a native file dialog instance. GTK+ versions prior 3.15.5 have
+ // a nasty bug (https://bugzilla.gnome.org/show_bug.cgi?id=725164)
+ // in GtkFileChooserWidget, which makes it leak its folder change
+ // callback, causing a crash "at some point later". Running the
+ // native test last is enough to avoid spinning the event loop after
+ // the test, and that way circumvent the crash.
+ //
+ // The crash has been fixed in GTK+ 3.15.5, but the RHEL 7.2 CI has
+ // GTK+ 3.14.13 installed (QTBUG-55276).
+ void widgetlessNativeDialog();
+
private:
void cleanupSettingsFile();
};
-tst_QFiledialog::tst_QFiledialog()
-{
-}
-
-tst_QFiledialog::~tst_QFiledialog()
-{
-}
-
void tst_QFiledialog::cleanupSettingsFile()
{
// clean up the sidebar between each test
@@ -199,9 +181,11 @@ void tst_QFiledialog::initTestCase()
void tst_QFiledialog::init()
{
+ // all tests, except widgetlessNativeDialog, use non-native dialogs
+ QCoreApplication::setAttribute(Qt::AA_DontUseNativeDialogs);
QFileDialogPrivate::setLastVisitedDirectory(QUrl());
// populate the sidebar with some default settings
- QNonNativeFileDialog fd;
+ QFileDialog fd;
#if defined(Q_OS_WINCE)
QTest::qWait(1000);
#endif
@@ -223,7 +207,7 @@ public:
// emitted any time the selection model emits current changed
void tst_QFiledialog::currentChangedSignal()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
fd.setViewMode(QFileDialog::List);
QSignalSpy spyCurrentChanged(&fd, SIGNAL(currentChanged(QString)));
@@ -249,8 +233,7 @@ void tst_QFiledialog::currentChangedSignal()
#if defined QT_BUILD_INTERNAL
void tst_QFiledialog::directoryEnteredSignal()
{
- QNonNativeFileDialog fd(0, "", QDir::root().path());
- fd.setOptions(QFileDialog::DontUseNativeDialog);
+ QFileDialog fd(0, "", QDir::root().path());
QSidebar *sidebar = fd.findChild<QSidebar*>("sidebar");
QVERIFY(sidebar);
if (sidebar->model()->rowCount() < 2)
@@ -315,9 +298,8 @@ void tst_QFiledialog::filesSelectedSignal_data()
// emitted when the dialog closes with the selected files
void tst_QFiledialog::filesSelectedSignal()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
fd.setViewMode(QFileDialog::List);
- fd.setOptions(QFileDialog::DontUseNativeDialog);
QDir testDir(SRCDIR);
fd.setDirectory(testDir);
QFETCH(QFileDialog::FileMode, fileMode);
@@ -359,7 +341,7 @@ void tst_QFiledialog::filesSelectedSignal()
// only emitted when the combo box is activated
void tst_QFiledialog::filterSelectedSignal()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
fd.setAcceptMode(QFileDialog::AcceptSave);
fd.show();
QSignalSpy spyFilterSelected(&fd, SIGNAL(filterSelected(QString)));
@@ -387,7 +369,7 @@ void tst_QFiledialog::args()
QString caption = "caption";
QString directory = QDir::tempPath();
QString filter = "*.mp3";
- QNonNativeFileDialog fd(parent, caption, directory, filter);
+ QFileDialog fd(parent, caption, directory, filter);
QCOMPARE(fd.parent(), (QObject *)parent);
QCOMPARE(fd.windowTitle(), caption);
#ifndef Q_OS_WIN
@@ -398,7 +380,7 @@ void tst_QFiledialog::args()
void tst_QFiledialog::directory()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
fd.setViewMode(QFileDialog::List);
QFileSystemModel *model = fd.findChild<QFileSystemModel*>("qt_filesystem_model");
QVERIFY(model);
@@ -432,12 +414,12 @@ void tst_QFiledialog::directory()
#else
QCOMPARE(list.at(0)->rootIndex().data().toString(), temp.dirName());
#endif
- QNonNativeFileDialog *dlg = new QNonNativeFileDialog(0, "", tempPath);
+ QFileDialog *dlg = new QFileDialog(0, "", tempPath);
QCOMPARE(model->index(tempPath), model->index(dlg->directory().absolutePath()));
QCOMPARE(model->index(tempPath).data(QFileSystemModel::FileNameRole).toString(),
model->index(dlg->directory().absolutePath()).data(QFileSystemModel::FileNameRole).toString());
delete dlg;
- dlg = new QNonNativeFileDialog();
+ dlg = new QFileDialog();
QCOMPARE(model->index(tempPath), model->index(dlg->directory().absolutePath()));
delete dlg;
}
@@ -494,10 +476,9 @@ void tst_QFiledialog::completer()
}
// ### flesh this out more
- QNonNativeFileDialog fd(0, QLatin1String(QTest::currentTestFunction())
+ QFileDialog fd(0, QLatin1String(QTest::currentTestFunction())
+ QStringLiteral(" \"") + QLatin1String(QTest::currentDataTag())
+ QLatin1Char('"'), startPath);
- fd.setOptions(QFileDialog::DontUseNativeDialog);
fd.show();
QVERIFY(QTest::qWaitForWindowExposed(&fd));
QVERIFY(fd.isVisible());
@@ -592,8 +573,7 @@ void tst_QFiledialog::completer()
void tst_QFiledialog::completer_up()
{
- QNonNativeFileDialog fd;
- fd.setOptions(QFileDialog::DontUseNativeDialog);
+ QFileDialog fd;
QSignalSpy spyCurrentChanged(&fd, SIGNAL(currentChanged(QString)));
QSignalSpy spyDirectoryEntered(&fd, SIGNAL(directoryEntered(QString)));
QSignalSpy spyFilesSelected(&fd, SIGNAL(filesSelected(QStringList)));
@@ -616,7 +596,7 @@ void tst_QFiledialog::completer_up()
void tst_QFiledialog::acceptMode()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
fd.show();
QToolButton* newButton = fd.findChild<QToolButton*>("newFolderButton");
@@ -638,7 +618,7 @@ void tst_QFiledialog::acceptMode()
void tst_QFiledialog::confirmOverwrite()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
QCOMPARE(fd.confirmOverwrite(), true);
fd.setConfirmOverwrite(true);
QCOMPARE(fd.confirmOverwrite(), true);
@@ -650,7 +630,7 @@ void tst_QFiledialog::confirmOverwrite()
void tst_QFiledialog::defaultSuffix()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
QCOMPARE(fd.defaultSuffix(), QString());
fd.setDefaultSuffix("txt");
QCOMPARE(fd.defaultSuffix(), QString("txt"));
@@ -662,7 +642,7 @@ void tst_QFiledialog::defaultSuffix()
void tst_QFiledialog::fileMode()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
QCOMPARE(fd.fileMode(), QFileDialog::AnyFile);
fd.setFileMode(QFileDialog::ExistingFile);
QCOMPARE(fd.fileMode(), QFileDialog::ExistingFile);
@@ -676,7 +656,7 @@ void tst_QFiledialog::fileMode()
void tst_QFiledialog::caption()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
fd.setWindowTitle("testing");
fd.setFileMode(QFileDialog::Directory);
QCOMPARE(fd.windowTitle(), QString("testing"));
@@ -684,8 +664,7 @@ void tst_QFiledialog::caption()
void tst_QFiledialog::filters()
{
- QNonNativeFileDialog fd;
- fd.setOptions(QFileDialog::DontUseNativeDialog);
+ QFileDialog fd;
QSignalSpy spyCurrentChanged(&fd, SIGNAL(currentChanged(QString)));
QSignalSpy spyDirectoryEntered(&fd, SIGNAL(directoryEntered(QString)));
QSignalSpy spyFilesSelected(&fd, SIGNAL(filesSelected(QStringList)));
@@ -720,7 +699,7 @@ void tst_QFiledialog::filters()
QCOMPARE(spyFilterSelected.count(), 0);
//Let check if filters with whitespaces
- QNonNativeFileDialog fd2;
+ QFileDialog fd2;
QStringList expected;
expected << "C++ Source Files(*.cpp)";
expected << "Any(*.*)";
@@ -738,7 +717,7 @@ void tst_QFiledialog::filters()
void tst_QFiledialog::selectFilter()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
QSignalSpy spyFilterSelected(&fd, SIGNAL(filterSelected(QString)));
QCOMPARE(fd.selectedNameFilter(), QString("All Files (*)"));
QStringList filters;
@@ -761,7 +740,7 @@ void tst_QFiledialog::selectFilter()
void tst_QFiledialog::history()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
fd.setViewMode(QFileDialog::List);
QFileSystemModel *model = fd.findChild<QFileSystemModel*>("qt_filesystem_model");
QVERIFY(model);
@@ -803,7 +782,7 @@ void tst_QFiledialog::history()
void tst_QFiledialog::iconProvider()
{
- QNonNativeFileDialog *fd = new QNonNativeFileDialog();
+ QFileDialog *fd = new QFileDialog();
QVERIFY(fd->iconProvider() != 0);
QFileIconProvider *ip = new QFileIconProvider();
fd->setIconProvider(ip);
@@ -814,7 +793,7 @@ void tst_QFiledialog::iconProvider()
void tst_QFiledialog::isReadOnly()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
QPushButton* newButton = fd.findChild<QPushButton*>("newFolderButton");
QAction* renameAction = fd.findChild<QAction*>("qt_rename_action");
@@ -838,7 +817,7 @@ void tst_QFiledialog::isReadOnly()
void tst_QFiledialog::itemDelegate()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
QVERIFY(fd.itemDelegate() != 0);
QItemDelegate *id = new QItemDelegate(&fd);
fd.setItemDelegate(id);
@@ -847,7 +826,7 @@ void tst_QFiledialog::itemDelegate()
void tst_QFiledialog::labelText()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
QDialogButtonBox buttonBox;
QPushButton *cancelButton = buttonBox.addButton(QDialogButtonBox::Cancel);
QCOMPARE(fd.labelText(QFileDialog::LookIn), QString("Look in:"));
@@ -870,7 +849,7 @@ void tst_QFiledialog::labelText()
void tst_QFiledialog::resolveSymlinks()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
// default
QCOMPARE(fd.resolveSymlinks(), true);
@@ -896,7 +875,7 @@ void tst_QFiledialog::selectFile()
{
QFETCH(QString, file);
QFETCH(int, count);
- QScopedPointer<QNonNativeFileDialog> fd(new QNonNativeFileDialog);
+ QScopedPointer<QFileDialog> fd(new QFileDialog);
QFileSystemModel *model = fd->findChild<QFileSystemModel*>("qt_filesystem_model");
QVERIFY(model);
fd->setDirectory(QDir::currentPath());
@@ -933,7 +912,7 @@ void tst_QFiledialog::selectFileWrongCaseSaveAs()
QString wrongCasePath = path;
for (int c = 0; c < wrongCasePath.size(); c += 2)
wrongCasePath[c] = wrongCasePath.at(c).isLower() ? wrongCasePath.at(c).toUpper() : wrongCasePath.at(c).toLower();
- QNonNativeFileDialog fd(0, "QTBUG-38162", wrongCasePath);
+ QFileDialog fd(0, "QTBUG-38162", wrongCasePath);
fd.setAcceptMode(QFileDialog::AcceptSave);
fd.selectFile(wrongCasePath);
const QLineEdit *lineEdit = fd.findChild<QLineEdit*>("fileNameEdit");
@@ -947,7 +926,7 @@ void tst_QFiledialog::selectFiles()
QVERIFY2(tempDir.isValid(), qPrintable(tempDir.errorString()));
const QString tempPath = tempDir.path();
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
fd.setViewMode(QFileDialog::List);
fd.setDirectory(tempPath);
QSignalSpy spyCurrentChanged(&fd, SIGNAL(currentChanged(QString)));
@@ -959,7 +938,7 @@ void tst_QFiledialog::selectFiles()
QString filesPath = fd.directory().absolutePath();
for (int i=0; i < 5; ++i) {
- QFile file(filesPath + QString::fromLatin1("/qfiledialog_auto_test_not_pres_%1").arg(i));
+ QFile file(filesPath + QLatin1String("/qfiledialog_auto_test_not_pres_") + QString::number(i));
file.open(QIODevice::WriteOnly);
file.resize(1024);
file.flush();
@@ -973,7 +952,7 @@ void tst_QFiledialog::selectFiles()
QListView* listView = fd.findChild<QListView*>("listView");
QVERIFY(listView);
for (int i = 0; i < list.count(); ++i) {
- fd.selectFile(fd.directory().path() + "/" + list.at(i));
+ fd.selectFile(fd.directory().path() + QLatin1Char('/') + list.at(i));
QTRY_VERIFY(!listView->selectionModel()->selectedRows().isEmpty());
toSelect.append(listView->selectionModel()->selectedRows().last());
}
@@ -997,7 +976,7 @@ void tst_QFiledialog::selectFiles()
{
//If the selection is invalid then we fill the line edit but without the /
- QNonNativeFileDialog dialog( 0, "Save" );
+ QFileDialog dialog( 0, "Save" );
dialog.setFileMode( QFileDialog::AnyFile );
dialog.setAcceptMode( QFileDialog::AcceptSave );
dialog.selectFile(tempPath + QStringLiteral("/blah"));
@@ -1011,7 +990,7 @@ void tst_QFiledialog::selectFiles()
void tst_QFiledialog::viewMode()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
fd.setViewMode(QFileDialog::List);
fd.show();
@@ -1049,7 +1028,7 @@ void tst_QFiledialog::viewMode()
void tst_QFiledialog::proxymodel()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
QCOMPARE(fd.proxyModel(), (QAbstractProxyModel*)0);
fd.setProxyModel(0);
@@ -1065,7 +1044,7 @@ void tst_QFiledialog::proxymodel()
void tst_QFiledialog::setEmptyNameFilter()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
fd.setNameFilter(QString());
fd.setNameFilters(QStringList());
}
@@ -1106,7 +1085,7 @@ void tst_QFiledialog::setNameFilter()
QFETCH(QString, selectFilter);
QFETCH(QString, expectedSelectedFilter);
- QNonNativeFileDialog fd;
+ QFileDialog fd;
fd.setNameFilters(filters);
fd.setNameFilterDetailsVisible(nameFilterDetailsVisible);
fd.selectNameFilter(selectFilter);
@@ -1115,7 +1094,7 @@ void tst_QFiledialog::setNameFilter()
void tst_QFiledialog::focus()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
fd.setDirectory(QDir::currentPath());
fd.show();
QApplication::setActiveWindow(&fd);
@@ -1137,7 +1116,7 @@ void tst_QFiledialog::focus()
void tst_QFiledialog::historyBack()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
QFileSystemModel *model = fd.findChild<QFileSystemModel*>("qt_filesystem_model");
QVERIFY(model);
QToolButton *backButton = fd.findChild<QToolButton*>("backButton");
@@ -1184,7 +1163,7 @@ void tst_QFiledialog::historyBack()
void tst_QFiledialog::historyForward()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
fd.setDirectory(QDir::currentPath());
QToolButton *backButton = fd.findChild<QToolButton*>("backButton");
QVERIFY(backButton);
@@ -1260,7 +1239,7 @@ void tst_QFiledialog::disableSaveButton()
QFETCH(QString, path);
QFETCH(bool, isEnabled);
- QNonNativeFileDialog fd(0, "caption", path);
+ QFileDialog fd(0, "caption", path);
fd.setAcceptMode(QFileDialog::AcceptSave);
QDialogButtonBox *buttonBox = fd.findChild<QDialogButtonBox*>("buttonBox");
QPushButton *button = buttonBox->button(QDialogButtonBox::Save);
@@ -1287,7 +1266,7 @@ void tst_QFiledialog::saveButtonText()
QFETCH(QString, label);
QFETCH(QString, caption);
- QNonNativeFileDialog fd(0, "auto test", QDir::temp().absolutePath());
+ QFileDialog fd(0, "auto test", QDir::temp().absolutePath());
fd.setAcceptMode(QFileDialog::AcceptSave);
if (!label.isNull())
fd.setLabelText(QFileDialog::Accept, label);
@@ -1302,10 +1281,9 @@ void tst_QFiledialog::saveButtonText()
void tst_QFiledialog::clearLineEdit()
{
- QNonNativeFileDialog fd(0, "caption", "foo");
+ QFileDialog fd(0, "caption", "foo");
fd.setViewMode(QFileDialog::List);
fd.setFileMode(QFileDialog::AnyFile);
- fd.setOptions(QFileDialog::DontUseNativeDialog);
fd.show();
//play it really safe by creating a directory
@@ -1339,7 +1317,7 @@ void tst_QFiledialog::clearLineEdit()
// selecting a dir the text should be cleared so one can just hit ok
// and it selects that directory
- fd.setFileMode(QNonNativeFileDialog::Directory);
+ fd.setFileMode(QFileDialog::Directory);
fd.setDirectory(QDir::home());
QTest::qWait(1000);
@@ -1360,7 +1338,7 @@ void tst_QFiledialog::clearLineEdit()
void tst_QFiledialog::enableChooseButton()
{
- QNonNativeFileDialog fd;
+ QFileDialog fd;
fd.setFileMode(QFileDialog::Directory);
fd.show();
QDialogButtonBox *buttonBox = fd.findChild<QDialogButtonBox*>("buttonBox");
@@ -1373,6 +1351,7 @@ void tst_QFiledialog::widgetlessNativeDialog()
{
if (!QGuiApplicationPrivate::platformTheme()->usePlatformNativeDialog(QPlatformTheme::FileDialog))
QSKIP("This platform always uses widgets to realize its QFileDialog, instead of the native file dialog.");
+ QApplication::setAttribute(Qt::AA_DontUseNativeDialogs, false);
QFileDialog fd;
fd.setWindowModality(Qt::ApplicationModal);
fd.show();
@@ -1381,6 +1360,7 @@ void tst_QFiledialog::widgetlessNativeDialog()
QVERIFY(!model);
QPushButton *button = fd.findChild<QPushButton*>();
QVERIFY(!button);
+ QApplication::setAttribute(Qt::AA_DontUseNativeDialogs, true);
}
void tst_QFiledialog::selectedFilesWithoutWidgets()
@@ -1396,10 +1376,9 @@ void tst_QFiledialog::trailingDotsAndSpaces()
#ifndef Q_OS_WIN
QSKIP("This is only tested on Windows");
#endif
- QNonNativeFileDialog fd;
+ QFileDialog fd;
fd.setViewMode(QFileDialog::List);
fd.setFileMode(QFileDialog::ExistingFile);
- fd.setOptions(QFileDialog::DontUseNativeDialog);
fd.show();
QLineEdit *lineEdit = fd.findChild<QLineEdit *>("fileNameEdit");
QVERIFY(lineEdit);
@@ -1425,15 +1404,18 @@ void tst_QFiledialog::tildeExpansion_data()
QTest::addColumn<QString>("tildePath");
QTest::addColumn<QString>("expandedPath");
+ const QString tilde = QStringLiteral("~");
+ const QString tildeUser = tilde + QString(qgetenv("USER"));
+ const QLatin1String someSubDir("/some/sub/dir");
+ const QString homePath = QDir::homePath();
+ const QString invalid = QStringLiteral("~thisIsNotAValidUserName");
+
QTest::newRow("empty path") << QString() << QString();
- QTest::newRow("~") << QString::fromLatin1("~") << QDir::homePath();
- QTest::newRow("~/some/sub/dir/") << QString::fromLatin1("~/some/sub/dir") << QDir::homePath()
- + QString::fromLatin1("/some/sub/dir");
- QString userHome = QString(qgetenv("USER"));
- userHome.prepend('~');
- QTest::newRow("current user (~<user> syntax)") << userHome << QDir::homePath();
- QString invalid = QString::fromLatin1("~thisIsNotAValidUserName");
- QTest::newRow("invalid user name") << invalid << invalid;
+ QTest::newRow("~") << tilde << homePath;
+ QTest::newRow("~/some/sub/dir/") << tilde + someSubDir << homePath + someSubDir;
+ QTest::newRow("~<user>") << tildeUser << homePath;
+ QTest::newRow("~<user>/some/sub/dir") << tildeUser + someSubDir << homePath + someSubDir;
+ QTest::newRow("invalid user name") << invalid << invalid;
}
#endif // QT_BUILD_INTERNAL
@@ -1472,35 +1454,28 @@ public slots:
void tst_QFiledialog::rejectModalDialogs()
{
// QTBUG-38672 , static functions should return empty Urls
- const QFileDialog::Options options = QFileDialog::DontUseNativeDialog;
DialogRejecter dr;
- QUrl url = QFileDialog::getOpenFileUrl(0, QStringLiteral("getOpenFileUrl"),
- QUrl(), QString(), Q_NULLPTR, options);
+ QUrl url = QFileDialog::getOpenFileUrl(0, QStringLiteral("getOpenFileUrl"));
QVERIFY(url.isEmpty());
QVERIFY(!url.isValid());
- url = QFileDialog::getExistingDirectoryUrl(0, QStringLiteral("getExistingDirectoryUrl"),
- QUrl(), options | QFileDialog::ShowDirsOnly);
+ url = QFileDialog::getExistingDirectoryUrl(0, QStringLiteral("getExistingDirectoryUrl"));
QVERIFY(url.isEmpty());
QVERIFY(!url.isValid());
- url = QFileDialog::getSaveFileUrl(0, QStringLiteral("getSaveFileUrl"),
- QUrl(), QString(), Q_NULLPTR, options);
+ url = QFileDialog::getSaveFileUrl(0, QStringLiteral("getSaveFileUrl"));
QVERIFY(url.isEmpty());
QVERIFY(!url.isValid());
// Same test with local files
- QString file = QFileDialog::getOpenFileName(0, QStringLiteral("getOpenFileName"),
- QString(), QString(), Q_NULLPTR, options);
+ QString file = QFileDialog::getOpenFileName(0, QStringLiteral("getOpenFileName"));
QVERIFY(file.isEmpty());
- file = QFileDialog::getExistingDirectory(0, QStringLiteral("getExistingDirectory"),
- QString(), options | QFileDialog::ShowDirsOnly);
+ file = QFileDialog::getExistingDirectory(0, QStringLiteral("getExistingDirectory"));
QVERIFY(file.isEmpty());
- file = QFileDialog::getSaveFileName(0, QStringLiteral("getSaveFileName"),
- QString(), QString(), Q_NULLPTR, options);
+ file = QFileDialog::getSaveFileName(0, QStringLiteral("getSaveFileName"));
QVERIFY(file.isEmpty());
}