summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp')
-rw-r--r--tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp36
1 files changed, 22 insertions, 14 deletions
diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
index 590b3502f1..2c0b3f2bcb 100644
--- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
+++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
@@ -826,7 +826,7 @@ void tst_QFileSystemModel::sort()
tree.setModel(myModel.data());
tree.show();
tree.resize(800, 800);
- QVERIFY(QTest::qWaitForWindowActive(&tree));
+ QVERIFY(QTest::qWaitForWindowExposed(&tree));
tree.header()->setSortIndicator(1, Qt::DescendingOrder);
tree.header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
QStringList dirsToOpen;
@@ -1014,30 +1014,38 @@ void tst_QFileSystemModel::drives()
void tst_QFileSystemModel::dirsBeforeFiles()
{
- QDir dir(flatDirTestPath);
+ auto diagnosticMsg = [](int row, const QFileInfo &left, const QFileInfo &right) -> QByteArray {
+ QString message;
+ QDebug(&message).noquote() << "Unexpected sort order at #" << row << ':' << left << right;
+ return message.toLocal8Bit();
+ };
+ QTemporaryDir testDir(flatDirTestPath);
+ QVERIFY2(testDir.isValid(), qPrintable(testDir.errorString()));
+ QDir dir(testDir.path());
const int itemCount = 3;
for (int i = 0; i < itemCount; ++i) {
QLatin1Char c('a' + char(i));
QVERIFY(dir.mkdir(c + QLatin1String("-dir")));
- QFile file(flatDirTestPath + QLatin1Char('/') + c + QLatin1String("-file"));
+ QFile file(dir.filePath(c + QLatin1String("-file")));
QVERIFY(file.open(QIODevice::ReadWrite));
file.close();
}
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
- QModelIndex root = model->setRootPath(flatDirTestPath);
+ QModelIndex root = model->setRootPath(dir.absolutePath());
// Wait for model to be notified by the file system watcher
QTRY_COMPARE(model->rowCount(root), 2 * itemCount);
-
- // Ensure that no file occurs before any directory:
- for (int i = 1; i < model->rowCount(root); ++i) {
+ // sort explicitly - dirs before files (except on macOS), and then by name
+ model->sort(0);
+ // Ensure that no file occurs before any directory (see QFileSystemModelSorter):
+ for (int i = 1, count = model->rowCount(root); i < count; ++i) {
+ const QFileInfo previous = model->fileInfo(model->index(i - 1, 0, root));
+ const QFileInfo current = model->fileInfo(model->index(i, 0, root));
#ifndef Q_OS_MAC
- QVERIFY(!(model->fileInfo(model->index(i - 1, 0, root)).isFile()
- && model->fileInfo(model->index(i, 0, root)).isDir()));
+ QVERIFY2(!(previous.isFile() && current.isDir()), diagnosticMsg(i, previous, current).constData());
#else
- QVERIFY(model->fileInfo(model->index(i - 1, 0, root)).fileName() <
- model->fileInfo(model->index(i, 0, root)).fileName());
+ QVERIFY2(previous.fileName() < current.fileName(), diagnosticMsg(i, previous, current).constData());
#endif
}
}
@@ -1046,7 +1054,7 @@ void tst_QFileSystemModel::roleNames_data()
{
QTest::addColumn<int>("role");
QTest::addColumn<QByteArray>("roleName");
- QTest::newRow("decoration") << int(Qt::DecorationRole) << QByteArray("decoration");
+ QTest::newRow("decoration") << int(Qt::DecorationRole) << QByteArray("fileIcon");
QTest::newRow("display") << int(Qt::DisplayRole) << QByteArray("display");
QTest::newRow("fileIcon") << int(QFileSystemModel::FileIconRole) << QByteArray("fileIcon");
QTest::newRow("filePath") << int(QFileSystemModel::FilePathRole) << QByteArray("filePath");
@@ -1063,8 +1071,8 @@ void tst_QFileSystemModel::roleNames()
QVERIFY(roles.contains(role));
QFETCH(QByteArray, roleName);
- QList<QByteArray> values = roles.values(role);
- QVERIFY(values.contains(roleName));
+ QCOMPARE(roles.values(role).count(), 1);
+ QCOMPARE(roles.value(role), roleName);
}
static inline QByteArray permissionRowName(bool readOnly, int permission)