summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/dialogs/qfilesystemmodel
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-01-15 15:32:45 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2018-01-26 11:36:30 +0000
commit0901d4290f6e7f0d1650b14fc085ecde7fb595ff (patch)
treec5b2f4a8c692682a03bbd63fc69fc68a2f5b2ade /tests/auto/widgets/dialogs/qfilesystemmodel
parentf55c73ede28d4455f555a28e401407326ac9b954 (diff)
QFileSystemModel/Win: Fix file system operations failing due to watchers
File system operations like renaming/removing may fail on Windows when file system watchers are present. Add functions to QFileSystemModelPrivate to temporarily remove the watchers prior to such operations and to restore them in case of failure. Use them for rename/remove (within a feature check for QFileSystemWatcher and Q_OS_WIN). Task-number: QTBUG-65683 Change-Id: I90142901892fbf9b1e1206a3397a95ffd3c8f010 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/widgets/dialogs/qfilesystemmodel')
-rw-r--r--tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
index 71efe1d59a..40a7d56432 100644
--- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
+++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
@@ -102,6 +102,7 @@ private slots:
void mkdir();
void deleteFile();
+ void deleteDirectory();
void caseSensitivity();
@@ -884,6 +885,44 @@ void tst_QFileSystemModel::deleteFile()
QVERIFY(!newFile.exists());
}
+void tst_QFileSystemModel::deleteDirectory()
+{
+ // QTBUG-65683: Verify that directories can be removed recursively despite
+ // file system watchers being active on them or their sub-directories (Windows).
+ // Create a temporary directory, a nested directory and expand a treeview
+ // to show them to ensure watcher creation. Then delete the directory.
+ QTemporaryDir dirToBeDeleted(flatDirTestPath + QStringLiteral("/deleteDirectory-XXXXXX"));
+ QVERIFY(dirToBeDeleted.isValid());
+ const QString dirToBeDeletedPath = dirToBeDeleted.path();
+ const QString nestedTestDir = QStringLiteral("test");
+ QVERIFY(QDir(dirToBeDeletedPath).mkpath(nestedTestDir));
+ const QString nestedTestDirPath = dirToBeDeletedPath + QLatin1Char('/') + nestedTestDir;
+ QFile testFile(nestedTestDirPath + QStringLiteral("/test.txt"));
+ QVERIFY(testFile.open(QIODevice::WriteOnly | QIODevice::Text));
+ testFile.write("Hello\n");
+ testFile.close();
+
+ QFileSystemModel model;
+ const QModelIndex rootIndex = model.setRootPath(flatDirTestPath);
+ QTreeView treeView;
+ treeView.setWindowTitle(QTest::currentTestFunction());
+ treeView.setModel(&model);
+ treeView.setRootIndex(rootIndex);
+
+ const QModelIndex dirToBeDeletedPathIndex = model.index(dirToBeDeletedPath);
+ QVERIFY(dirToBeDeletedPathIndex.isValid());
+ treeView.setExpanded(dirToBeDeletedPathIndex, true);
+ const QModelIndex nestedTestDirIndex = model.index(nestedTestDirPath);
+ QVERIFY(nestedTestDirIndex.isValid());
+ treeView.setExpanded(nestedTestDirIndex, true);
+
+ treeView.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&treeView));
+
+ QVERIFY(model.remove(dirToBeDeletedPathIndex));
+ dirToBeDeleted.setAutoRemove(false);
+}
+
static QString flipCase(QString s)
{
for (int i = 0, size = s.size(); i < size; ++i) {