summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/dialogs/qfilesystemmodel
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2015-12-18 08:37:31 +0100
committerLiang Qi <liang.qi@theqtcompany.com>2015-12-18 08:37:31 +0100
commitbeb65dcd79f8c354dab7bb4a8d08157bd9d69329 (patch)
tree4632a0ff0df8462f8913f347042cf8378de03268 /tests/auto/widgets/dialogs/qfilesystemmodel
parent3fc1002489d5861d4f7cc2e1e8800881d6593c9d (diff)
parente3288f246b44ba2b6d90b90eb99ab61f496d8d57 (diff)
Merge remote-tracking branch 'origin/5.6' into dev
Conflicts: src/gui/painting/painting.pri src/plugins/platforms/xcb/qxcbconnection.cpp tests/auto/corelib/thread/qthreadstorage/qthreadstorage.pro tests/auto/corelib/tools/qlocale/test/test.pro tests/auto/gui/kernel/qwindow/tst_qwindow.cpp tools/configure/environment.cpp Change-Id: I9c40f458b89b2c206de2d2c24e90b5f679c93495
Diffstat (limited to 'tests/auto/widgets/dialogs/qfilesystemmodel')
-rw-r--r--tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp92
1 files changed, 85 insertions, 7 deletions
diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
index 260aa25512..b0bf395f6b 100644
--- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
+++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
@@ -123,6 +123,9 @@ private slots:
void permissions_data();
void permissions();
+ void doNotUnwatchOnFailedRmdir();
+ void specialFiles();
+
protected:
bool createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount = 0, const QStringList &intial_dirs = QStringList());
@@ -821,18 +824,21 @@ void tst_QFileSystemModel::sort()
QModelIndex parent = myModel->index(dirPath, 0);
QList<QString> expectedOrder;
expectedOrder << tempFile2.fileName() << tempFile.fileName() << dirPath + QChar('/') + ".." << dirPath + QChar('/') + ".";
- //File dialog Mode means sub trees are not sorted, only the current root
+
if (fileDialogMode) {
- // FIXME: we were only able to disableRecursiveSort in developer builds, so we can only
- // stably perform this test for developer builds
-#ifdef QT_BUILD_INTERNAL
- QList<QString> actualRows;
+ // File dialog Mode means sub trees are not sorted, only the current root.
+ // There's no way we can check that the sub tree is "not sorted"; just check if it
+ // has the same contents of the expected list
+ QList<QString> actualRows;
for(int i = 0; i < myModel->rowCount(parent); ++i)
{
actualRows << dirPath + QChar('/') + myModel->index(i, 1, parent).data(QFileSystemModel::FileNameRole).toString();
}
- QVERIFY(actualRows != expectedOrder);
-#endif
+
+ std::sort(expectedOrder.begin(), expectedOrder.end());
+ std::sort(actualRows.begin(), actualRows.end());
+
+ QCOMPARE(actualRows, expectedOrder);
} else {
for(int i = 0; i < myModel->rowCount(parent); ++i)
{
@@ -1044,6 +1050,78 @@ void tst_QFileSystemModel::permissions() // checks QTBUG-20503
QCOMPARE(fileInfoPermissions, modelPermissions);
}
+void tst_QFileSystemModel::doNotUnwatchOnFailedRmdir()
+{
+ const QString tmp = flatDirTestPath;
+
+ QFileSystemModel model;
+
+ const QTemporaryDir tempDir(tmp + '/' + QStringLiteral("doNotUnwatchOnFailedRmdir-XXXXXX"));
+ QVERIFY(tempDir.isValid());
+
+ const QModelIndex rootIndex = model.setRootPath(tempDir.path());
+
+ // create a file in the directory so to prevent it from deletion
+ {
+ QFile file(tempDir.path() + '/' + QStringLiteral("file1"));
+ QVERIFY(file.open(QIODevice::WriteOnly));
+ }
+
+ QCOMPARE(model.rmdir(rootIndex), false);
+
+ // create another file
+ {
+ QFile file(tempDir.path() + '/' + QStringLiteral("file2"));
+ QVERIFY(file.open(QIODevice::WriteOnly));
+ }
+
+ // the model must now detect this second file
+ QTRY_COMPARE(model.rowCount(rootIndex), 2);
+}
+
+static QSet<QString> fileListUnderIndex(const QFileSystemModel *model, const QModelIndex &parent)
+{
+ QSet<QString> fileNames;
+ const int rowCount = model->rowCount(parent);
+ for (int i = 0; i < rowCount; ++i)
+ fileNames.insert(model->index(i, 0, parent).data(QFileSystemModel::FileNameRole).toString());
+ return fileNames;
+}
+
+void tst_QFileSystemModel::specialFiles()
+{
+ QFileSystemModel model;
+
+ model.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
+
+ // Can't simply verify if the model returns a valid model index for a special file
+ // as it will always return a valid index for existing files,
+ // even if the file is not visible with the given filter.
+
+#if defined(Q_OS_UNIX)
+ const QModelIndex rootIndex = model.setRootPath(QStringLiteral("/dev/"));
+ const QString testFileName = QStringLiteral("null");
+#elif defined(Q_OS_WIN)
+ const QModelIndex rootIndex = model.setRootPath(flatDirTestPath);
+
+ const QString testFileName = QStringLiteral("linkSource.lnk");
+
+ QFile file(flatDirTestPath + QLatin1String("/linkTarget.txt"));
+ QVERIFY(file.open(QIODevice::WriteOnly));
+ file.close();
+ QVERIFY(file.link(flatDirTestPath + '/' + testFileName));
+#else
+ QSKIP("Not implemented");
+ QModelIndex rootIndex;
+ QString testFileName;
+#endif
+
+ QTRY_VERIFY(fileListUnderIndex(&model, rootIndex).contains(testFileName));
+
+ model.setFilter(QDir::AllEntries | QDir::Hidden);
+
+ QTRY_VERIFY(!fileListUnderIndex(&model, rootIndex).contains(testFileName));
+}
QTEST_MAIN(tst_QFileSystemModel)
#include "tst_qfilesystemmodel.moc"