diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2015-12-10 20:29:24 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2015-12-13 11:46:17 +0000 |
commit | 3b093034b638a69b4dc91212d1743638864a1337 (patch) | |
tree | f87af13ae08ef7788549ca1a2dc7c49ab8d238d4 /tests/auto | |
parent | be9df4bc82b3f62854906761b7661bc2778b513e (diff) |
QFileSystemModel: report special files which are not symlinks
Since special files have file size == -1, they were always filtered
out by QFileSystemModel, even when passing QDir::System as filtering
option. Keep them instead.
The testcase is more convoluted than it should be because QFSM
is so broken that it returns valid indexes for invisible elements
in the model (such as filtered out elements).
Change-Id: I023a9813dbfeed7be99dded42c66b1191afdc17e
Task-number: QTBUG-20968
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp index 8c8872e807..d370a647b4 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -124,6 +124,7 @@ private slots: 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()); @@ -1077,6 +1078,49 @@ void tst_QFileSystemModel::doNotUnwatchOnFailedRmdir() 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" |