summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2014-04-28 16:16:34 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-29 03:27:26 +0200
commit9f6a0300a5ab5996a97b27bc8ada55f41e3ca517 (patch)
tree17f14408a71d82b3f0baf012f44a4a6533aa8ac3 /tests/auto
parent386292837bf5f6bcb502bd3fa68cb2a4e9498b1b (diff)
Observe case insensitive file systems in QFileDialog::selectFile().
When stripping the root path from a file name that cannot be found in the model, use case sensitive comparison depending on file system. Task-number: QTBUG-38162 Change-Id: I28e28973fca2da35a5768fdd00cc258b9669a15a Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
index e856c2efc5..047df0d3f2 100644
--- a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
+++ b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
@@ -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();
@@ -882,6 +898,27 @@ void tst_QFiledialog::selectFile()
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()
{
QTemporaryDir tempDir;