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.cpp107
1 files changed, 79 insertions, 28 deletions
diff --git a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
index d360a646f1..047df0d3f2 100644
--- a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
+++ b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
@@ -43,6 +43,7 @@
#include <QtTest/QtTest>
#include <qcoreapplication.h>
+#include <qfile.h>
#include <qdebug.h>
#include <qsharedpointer.h>
#include <qfiledialog.h>
@@ -72,6 +73,7 @@
#include <QFileSystemModel>
#if defined(Q_OS_UNIX)
+#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);
@@ -79,6 +81,19 @@ QT_END_NAMESPACE
#endif
#endif
+static inline bool isCaseSensitiveFileSystem(const QString &path)
+{
+ Q_UNUSED(path)
+#if defined(Q_OS_MAC)
+ return pathconf(QFile::encodeName(path).constData(), _PC_CASE_SENSITIVE);
+#elif defined(Q_OS_WIN)
+ return false;
+#else
+ return true;
+#endif
+}
+
+
class QNonNativeFileDialog : public QFileDialog
{
Q_OBJECT
@@ -130,6 +145,7 @@ private slots:
void selectFile_data();
void selectFile();
void selectFiles();
+ void selectFileWrongCaseSaveAs();
void selectFilter();
void viewMode();
void proxymodel();
@@ -147,6 +163,7 @@ private slots:
void clearLineEdit();
void enableChooseButton();
void widgetlessNativeDialog();
+ void selectedFilesWithoutWidgets();
void trailingDotsAndSpaces();
#ifdef Q_OS_UNIX
#ifdef QT_BUILD_INTERNAL
@@ -857,36 +874,59 @@ void tst_QFiledialog::selectFile()
{
QFETCH(QString, file);
QFETCH(int, count);
- QNonNativeFileDialog fd;
- QFileSystemModel *model = fd.findChild<QFileSystemModel*>("qt_filesystem_model");
+ QScopedPointer<QNonNativeFileDialog> fd(new QNonNativeFileDialog);
+ QFileSystemModel *model = fd->findChild<QFileSystemModel*>("qt_filesystem_model");
QVERIFY(model);
- fd.setDirectory(QDir::currentPath());
+ fd->setDirectory(QDir::currentPath());
// default value
- QCOMPARE(fd.selectedFiles().count(), 1);
+ QCOMPARE(fd->selectedFiles().count(), 1);
- QTemporaryFile tempFile(QDir::tempPath() + "/aXXXXXX");
- bool inTemp = (file == "temp");
- if (inTemp) {
- tempFile.open();
- file = tempFile.fileName();
+ QScopedPointer<QTemporaryFile> tempFile;
+ if (file == QLatin1String("temp")) {
+ tempFile.reset(new QTemporaryFile(QDir::tempPath() + QStringLiteral("/aXXXXXX")));
+ QVERIFY(tempFile->open());
+ file = tempFile->fileName();
}
- fd.selectFile(file);
- QCOMPARE(fd.selectedFiles().count(), count);
- if (inTemp) {
- QCOMPARE(model->index(fd.directory().path()), model->index(QDir::tempPath()));
+ fd->selectFile(file);
+ QCOMPARE(fd->selectedFiles().count(), count);
+ if (tempFile.isNull()) {
+ QCOMPARE(model->index(fd->directory().path()), model->index(QDir::currentPath()));
} else {
- QCOMPARE(model->index(fd.directory().path()), model->index(QDir::currentPath()));
+ QCOMPARE(model->index(fd->directory().path()), model->index(QDir::tempPath()));
}
+ fd.reset(); // Ensure the file dialog let's go of the temporary file for "temp".
+}
+
+void tst_QFiledialog::selectFileWrongCaseSaveAs()
+{
+ const QString home = QDir::homePath();
+ if (isCaseSensitiveFileSystem(home))
+ QSKIP("This test is intended for case-insensitive file systems only.");
+ // QTBUG-38162: when passing a wrongly capitalized path to selectFile()
+ // on a case-insensitive file system, the line edit should only
+ // contain the file name ("c:\PRogram files\foo.txt" -> "foo.txt").
+ const QString fileName = QStringLiteral("foo.txt");
+ const QString path = home + QLatin1Char('/') + fileName;
+ 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);
+ fd.setAcceptMode(QFileDialog::AcceptSave);
+ fd.selectFile(wrongCasePath);
+ const QLineEdit *lineEdit = fd.findChild<QLineEdit*>("fileNameEdit");
+ QVERIFY(lineEdit);
+ QCOMPARE(lineEdit->text().compare(fileName, Qt::CaseInsensitive), 0);
}
void tst_QFiledialog::selectFiles()
{
- QNonNativeFileDialog fd;
- fd.setViewMode(QFileDialog::List);
QTemporaryDir tempDir;
QVERIFY(tempDir.isValid());
const QString tempPath = tempDir.path();
+ {
+ QNonNativeFileDialog fd;
+ fd.setViewMode(QFileDialog::List);
fd.setDirectory(tempPath);
QSignalSpy spyCurrentChanged(&fd, SIGNAL(currentChanged(QString)));
QSignalSpy spyDirectoryEntered(&fd, SIGNAL(directoryEntered(QString)));
@@ -931,17 +971,20 @@ void tst_QFiledialog::selectFiles()
QCOMPARE(spyFilesSelected.count(), 0);
QCOMPARE(spyFilterSelected.count(), 0);
- //If the selection is invalid then we fill the line edit but without the /
- QNonNativeFileDialog * dialog = new QNonNativeFileDialog( 0, "Save" );
- dialog->setFileMode( QFileDialog::AnyFile );
- dialog->setAcceptMode( QFileDialog::AcceptSave );
- dialog->selectFile(tempPath + QStringLiteral("/blah"));
- dialog->show();
- QVERIFY(QTest::qWaitForWindowExposed(dialog));
- QLineEdit *lineEdit = dialog->findChild<QLineEdit*>("fileNameEdit");
- QVERIFY(lineEdit);
- QCOMPARE(lineEdit->text(),QLatin1String("blah"));
- delete dialog;
+ }
+
+ {
+ //If the selection is invalid then we fill the line edit but without the /
+ QNonNativeFileDialog dialog( 0, "Save" );
+ dialog.setFileMode( QFileDialog::AnyFile );
+ dialog.setAcceptMode( QFileDialog::AcceptSave );
+ dialog.selectFile(tempPath + QStringLiteral("/blah"));
+ dialog.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&dialog));
+ QLineEdit *lineEdit = dialog.findChild<QLineEdit*>("fileNameEdit");
+ QVERIFY(lineEdit);
+ QCOMPARE(lineEdit->text(),QLatin1String("blah"));
+ }
}
void tst_QFiledialog::viewMode()
@@ -1321,6 +1364,14 @@ void tst_QFiledialog::widgetlessNativeDialog()
QVERIFY(!button);
}
+void tst_QFiledialog::selectedFilesWithoutWidgets()
+{
+ // Test for a crash when widgets are not instantiated yet.
+ QFileDialog fd;
+ fd.setAcceptMode(QFileDialog::AcceptOpen);
+ QVERIFY(fd.selectedFiles().size() >= 0);
+}
+
void tst_QFiledialog::trailingDotsAndSpaces()
{
#ifndef Q_OS_WIN