diff options
Diffstat (limited to 'tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp')
-rw-r--r-- | tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp | 92 |
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" |