diff options
author | Alexander Volkov <a.volkov@rusbitech.ru> | 2016-04-14 18:57:14 +0300 |
---|---|---|
committer | Alexander Volkov <a.volkov@rusbitech.ru> | 2016-04-22 09:49:53 +0000 |
commit | e27fae353ca9a2d4d5054d32bb3a2622ccf9d889 (patch) | |
tree | 58874939b22062d2923b832f144ca6c82e3b412b /tests | |
parent | ea64dc9a113a850334fbf47ca2cdc3b447945c25 (diff) |
QFileSystemModel: fix updating QFileInfo for a node after a file rename
Use the correct parent path for the renamed file when creating
QFileInfo. It must be a path to the parent directory, not to the
root directory of the model.
Modify tst_QFileSystemModel::setData() to test renames in subdirs
of the root directory of the model.
Change-Id: I69d9e3a937616857a81617791ed118af3f6eea05
Task-number: QTBUG-52561
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp index d370a647b4..19b1d0e7c8 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -697,6 +697,7 @@ void tst_QFileSystemModel::nameFilters() } void tst_QFileSystemModel::setData_data() { + QTest::addColumn<QString>("subdirName"); QTest::addColumn<QStringList>("files"); QTest::addColumn<QString>("oldFileName"); QTest::addColumn<QString>("newFileName"); @@ -706,7 +707,15 @@ void tst_QFileSystemModel::setData_data() << QDir::temp().absolutePath() + '/' + "a" << false; */ - QTest::newRow("in current dir") << (QStringList() << "a" << "b" << "c") + QTest::newRow("in current dir") + << QString() + << (QStringList() << "a" << "b" << "c") + << "a" + << "d" + << true; + QTest::newRow("in subdir") + << "s" + << (QStringList() << "a" << "b" << "c") << "a" << "d" << true; @@ -715,15 +724,25 @@ void tst_QFileSystemModel::setData_data() void tst_QFileSystemModel::setData() { QSignalSpy spy(model, SIGNAL(fileRenamed(QString,QString,QString))); - QString tmp = flatDirTestPath; + QFETCH(QString, subdirName); QFETCH(QStringList, files); QFETCH(QString, oldFileName); QFETCH(QString, newFileName); QFETCH(bool, success); + QString tmp = flatDirTestPath; + if (!subdirName.isEmpty()) { + QDir dir(tmp); + QVERIFY(dir.mkdir(subdirName)); + tmp.append('/' + subdirName); + } QVERIFY(createFiles(tmp, files)); - QModelIndex root = model->setRootPath(tmp); - QTRY_COMPARE(model->rowCount(root), files.count()); + QModelIndex tmpIdx = model->setRootPath(flatDirTestPath); + if (!subdirName.isEmpty()) { + tmpIdx = model->index(tmp); + model->fetchMore(tmpIdx); + } + QTRY_COMPARE(model->rowCount(tmpIdx), files.count()); QModelIndex idx = model->index(tmp + '/' + oldFileName); QCOMPARE(idx.isValid(), true); @@ -731,16 +750,21 @@ void tst_QFileSystemModel::setData() model->setReadOnly(false); QCOMPARE(model->setData(idx, newFileName), success); + model->setReadOnly(true); if (success) { QCOMPARE(spy.count(), 1); QList<QVariant> arguments = spy.takeFirst(); QCOMPARE(model->data(idx, QFileSystemModel::FileNameRole).toString(), newFileName); + QCOMPARE(model->fileInfo(idx).filePath(), tmp + '/' + newFileName); QCOMPARE(model->index(arguments.at(0).toString()), model->index(tmp)); QCOMPARE(arguments.at(1).toString(), oldFileName); QCOMPARE(arguments.at(2).toString(), newFileName); QCOMPARE(QFile::rename(tmp + '/' + newFileName, tmp + '/' + oldFileName), true); } - QTRY_COMPARE(model->rowCount(root), files.count()); + QTRY_COMPARE(model->rowCount(tmpIdx), files.count()); + // cleanup + if (!subdirName.isEmpty()) + QVERIFY(QDir(tmp).removeRecursively()); } void tst_QFileSystemModel::sortPersistentIndex() |