Use QAbstractItemModelTester or QFileSystemModel
This patch enables usage of QAbstractItemModelTester on QFileSystemModel. QAbstractItemModelTester called fetchMore() on all items. QFileSystemModel represents the whole file system. This led to very long test runs. To avoid this, this patch introduces a new feature in QAbstractItemModelTester, namely to disable calling of fetchMore(). Change-Id: Ie5d2e22fa4c143be7c080d9f79632cd2cbe07aac Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
parent
ec7989aa66
commit
2f35653a30
@ -91,6 +91,7 @@ private:
|
|||||||
QStack<Changing> insert;
|
QStack<Changing> insert;
|
||||||
QStack<Changing> remove;
|
QStack<Changing> remove;
|
||||||
|
|
||||||
|
bool useFetchMore = true;
|
||||||
bool fetchingMore;
|
bool fetchingMore;
|
||||||
|
|
||||||
enum class ChangeInFlight {
|
enum class ChangeInFlight {
|
||||||
@ -315,6 +316,19 @@ QAbstractItemModelTester::FailureReportingMode QAbstractItemModelTester::failure
|
|||||||
return d->failureReportingMode;
|
return d->failureReportingMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
If \a value is true, enables dynamic population of the
|
||||||
|
tested model, which is the default.
|
||||||
|
If \a value is false, it disables it.
|
||||||
|
|
||||||
|
\since 6.4
|
||||||
|
*/
|
||||||
|
void QAbstractItemModelTester::setUseFetchMore(bool value)
|
||||||
|
{
|
||||||
|
Q_D(QAbstractItemModelTester);
|
||||||
|
d->useFetchMore = value;
|
||||||
|
}
|
||||||
|
|
||||||
bool QAbstractItemModelTester::verify(bool statement, const char *statementStr, const char *description, const char *file, int line)
|
bool QAbstractItemModelTester::verify(bool statement, const char *statementStr, const char *description, const char *file, int line)
|
||||||
{
|
{
|
||||||
Q_D(QAbstractItemModelTester);
|
Q_D(QAbstractItemModelTester);
|
||||||
@ -349,9 +363,11 @@ void QAbstractItemModelTesterPrivate::nonDestructiveBasicTest()
|
|||||||
MODELTESTER_VERIFY(!model->buddy(QModelIndex()).isValid());
|
MODELTESTER_VERIFY(!model->buddy(QModelIndex()).isValid());
|
||||||
model->canFetchMore(QModelIndex());
|
model->canFetchMore(QModelIndex());
|
||||||
MODELTESTER_VERIFY(model->columnCount(QModelIndex()) >= 0);
|
MODELTESTER_VERIFY(model->columnCount(QModelIndex()) >= 0);
|
||||||
|
if (useFetchMore) {
|
||||||
fetchingMore = true;
|
fetchingMore = true;
|
||||||
model->fetchMore(QModelIndex());
|
model->fetchMore(QModelIndex());
|
||||||
fetchingMore = false;
|
fetchingMore = false;
|
||||||
|
}
|
||||||
Qt::ItemFlags flags = model->flags(QModelIndex());
|
Qt::ItemFlags flags = model->flags(QModelIndex());
|
||||||
MODELTESTER_VERIFY(flags == Qt::ItemIsDropEnabled || flags == 0);
|
MODELTESTER_VERIFY(flags == Qt::ItemIsDropEnabled || flags == 0);
|
||||||
model->hasChildren(QModelIndex());
|
model->hasChildren(QModelIndex());
|
||||||
@ -529,7 +545,7 @@ void QAbstractItemModelTesterPrivate::checkChildren(const QModelIndex &parent, i
|
|||||||
p = p.parent();
|
p = p.parent();
|
||||||
|
|
||||||
// For models that are dynamically populated
|
// For models that are dynamically populated
|
||||||
if (model->canFetchMore(parent)) {
|
if (model->canFetchMore(parent) && useFetchMore) {
|
||||||
fetchingMore = true;
|
fetchingMore = true;
|
||||||
model->fetchMore(parent);
|
model->fetchMore(parent);
|
||||||
fetchingMore = false;
|
fetchingMore = false;
|
||||||
|
@ -47,6 +47,7 @@ public:
|
|||||||
|
|
||||||
QAbstractItemModel *model() const;
|
QAbstractItemModel *model() const;
|
||||||
FailureReportingMode failureReportingMode() const;
|
FailureReportingMode failureReportingMode() const;
|
||||||
|
void setUseFetchMore(bool value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend inline bool QTestPrivate::testDataGuiRoles(QAbstractItemModelTester *tester);
|
friend inline bool QTestPrivate::testDataGuiRoles(QAbstractItemModelTester *tester);
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <QTemporaryDir>
|
#include <QTemporaryDir>
|
||||||
|
#include <QAbstractItemModelTester>
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
# include <qt_windows.h> // for SetFileAttributes
|
# include <qt_windows.h> // for SetFileAttributes
|
||||||
#endif
|
#endif
|
||||||
@ -149,6 +150,8 @@ void tst_QFileSystemModel::indexPath()
|
|||||||
{
|
{
|
||||||
#if !defined(Q_OS_WIN)
|
#if !defined(Q_OS_WIN)
|
||||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||||
|
QAbstractItemModelTester tester(model.get());
|
||||||
|
tester.setUseFetchMore(false);
|
||||||
int depth = QDir::currentPath().count('/');
|
int depth = QDir::currentPath().count('/');
|
||||||
model->setRootPath(QDir::currentPath());
|
model->setRootPath(QDir::currentPath());
|
||||||
QString backPath;
|
QString backPath;
|
||||||
@ -163,6 +166,8 @@ void tst_QFileSystemModel::indexPath()
|
|||||||
void tst_QFileSystemModel::rootPath()
|
void tst_QFileSystemModel::rootPath()
|
||||||
{
|
{
|
||||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||||
|
QAbstractItemModelTester tester(model.get());
|
||||||
|
tester.setUseFetchMore(false);
|
||||||
QCOMPARE(model->rootPath(), QString(QDir().path()));
|
QCOMPARE(model->rootPath(), QString(QDir().path()));
|
||||||
|
|
||||||
QSignalSpy rootChanged(model.data(), &QFileSystemModel::rootPathChanged);
|
QSignalSpy rootChanged(model.data(), &QFileSystemModel::rootPathChanged);
|
||||||
@ -227,6 +232,8 @@ void tst_QFileSystemModel::rootPath()
|
|||||||
void tst_QFileSystemModel::readOnly()
|
void tst_QFileSystemModel::readOnly()
|
||||||
{
|
{
|
||||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||||
|
QAbstractItemModelTester tester(model.get());
|
||||||
|
tester.setUseFetchMore(false);
|
||||||
QCOMPARE(model->isReadOnly(), true);
|
QCOMPARE(model->isReadOnly(), true);
|
||||||
QTemporaryFile file(flatDirTestPath + QStringLiteral("/XXXXXX.dat"));
|
QTemporaryFile file(flatDirTestPath + QStringLiteral("/XXXXXX.dat"));
|
||||||
QVERIFY2(file.open(), qPrintable(file.errorString()));
|
QVERIFY2(file.open(), qPrintable(file.errorString()));
|
||||||
@ -280,6 +287,8 @@ private:
|
|||||||
void tst_QFileSystemModel::iconProvider()
|
void tst_QFileSystemModel::iconProvider()
|
||||||
{
|
{
|
||||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||||
|
QAbstractItemModelTester tester(model.get());
|
||||||
|
tester.setUseFetchMore(false);
|
||||||
QVERIFY(model->iconProvider());
|
QVERIFY(model->iconProvider());
|
||||||
QScopedPointer<QFileIconProvider> provider(new QFileIconProvider);
|
QScopedPointer<QFileIconProvider> provider(new QFileIconProvider);
|
||||||
model->setIconProvider(provider.data());
|
model->setIconProvider(provider.data());
|
||||||
@ -389,6 +398,8 @@ void tst_QFileSystemModel::rowCount()
|
|||||||
QSignalSpy *spy2 = nullptr;
|
QSignalSpy *spy2 = nullptr;
|
||||||
QSignalSpy *spy3 = nullptr;
|
QSignalSpy *spy3 = nullptr;
|
||||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||||
|
QAbstractItemModelTester tester(model.get());
|
||||||
|
tester.setUseFetchMore(false);
|
||||||
QModelIndex root = prepareTestModelRoot(model.data(), flatDirTestPath, &spy2, &spy3);
|
QModelIndex root = prepareTestModelRoot(model.data(), flatDirTestPath, &spy2, &spy3);
|
||||||
QVERIFY(root.isValid());
|
QVERIFY(root.isValid());
|
||||||
|
|
||||||
@ -417,6 +428,8 @@ void tst_QFileSystemModel::rowsInserted()
|
|||||||
{
|
{
|
||||||
const QString tmp = flatDirTestPath;
|
const QString tmp = flatDirTestPath;
|
||||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||||
|
QAbstractItemModelTester tester(model.get());
|
||||||
|
tester.setUseFetchMore(false);
|
||||||
QModelIndex root = prepareTestModelRoot(model.data(), tmp);
|
QModelIndex root = prepareTestModelRoot(model.data(), tmp);
|
||||||
QVERIFY(root.isValid());
|
QVERIFY(root.isValid());
|
||||||
|
|
||||||
@ -471,6 +484,8 @@ void tst_QFileSystemModel::rowsRemoved()
|
|||||||
{
|
{
|
||||||
const QString tmp = flatDirTestPath;
|
const QString tmp = flatDirTestPath;
|
||||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||||
|
QAbstractItemModelTester tester(model.get());
|
||||||
|
tester.setUseFetchMore(false);
|
||||||
QModelIndex root = prepareTestModelRoot(model.data(), tmp);
|
QModelIndex root = prepareTestModelRoot(model.data(), tmp);
|
||||||
QVERIFY(root.isValid());
|
QVERIFY(root.isValid());
|
||||||
|
|
||||||
@ -533,6 +548,8 @@ void tst_QFileSystemModel::dataChanged()
|
|||||||
|
|
||||||
const QString tmp = flatDirTestPath;
|
const QString tmp = flatDirTestPath;
|
||||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||||
|
QAbstractItemModelTester tester(model.get());
|
||||||
|
tester.setUseFetchMore(false);
|
||||||
QModelIndex root = prepareTestModelRoot(model.data(), tmp);
|
QModelIndex root = prepareTestModelRoot(model.data(), tmp);
|
||||||
QVERIFY(root.isValid());
|
QVERIFY(root.isValid());
|
||||||
|
|
||||||
@ -593,6 +610,8 @@ void tst_QFileSystemModel::filters()
|
|||||||
{
|
{
|
||||||
QString tmp = flatDirTestPath;
|
QString tmp = flatDirTestPath;
|
||||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||||
|
QAbstractItemModelTester tester(model.get());
|
||||||
|
tester.setUseFetchMore(false);
|
||||||
QVERIFY(createFiles(model.data(), tmp, QStringList()));
|
QVERIFY(createFiles(model.data(), tmp, QStringList()));
|
||||||
QModelIndex root = model->setRootPath(tmp);
|
QModelIndex root = model->setRootPath(tmp);
|
||||||
QFETCH(QStringList, files);
|
QFETCH(QStringList, files);
|
||||||
@ -661,6 +680,8 @@ void tst_QFileSystemModel::nameFilters()
|
|||||||
QStringList list;
|
QStringList list;
|
||||||
list << "a" << "b" << "c";
|
list << "a" << "b" << "c";
|
||||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||||
|
QAbstractItemModelTester tester(model.get());
|
||||||
|
tester.setUseFetchMore(false);
|
||||||
model->setNameFilters(list);
|
model->setNameFilters(list);
|
||||||
model->setNameFilterDisables(false);
|
model->setNameFilterDisables(false);
|
||||||
QCOMPARE(model->nameFilters(), list);
|
QCOMPARE(model->nameFilters(), list);
|
||||||
@ -706,6 +727,8 @@ void tst_QFileSystemModel::setData_data()
|
|||||||
void tst_QFileSystemModel::setData()
|
void tst_QFileSystemModel::setData()
|
||||||
{
|
{
|
||||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||||
|
QAbstractItemModelTester tester(model.get());
|
||||||
|
tester.setUseFetchMore(false);
|
||||||
QSignalSpy spy(model.data(), &QFileSystemModel::fileRenamed);
|
QSignalSpy spy(model.data(), &QFileSystemModel::fileRenamed);
|
||||||
QFETCH(QString, subdirName);
|
QFETCH(QString, subdirName);
|
||||||
QFETCH(QStringList, files);
|
QFETCH(QStringList, files);
|
||||||
@ -758,6 +781,8 @@ void tst_QFileSystemModel::sortPersistentIndex()
|
|||||||
file.close();
|
file.close();
|
||||||
QTRY_VERIFY(QDir(flatDirTestPath).entryInfoList().contains(fileInfo));
|
QTRY_VERIFY(QDir(flatDirTestPath).entryInfoList().contains(fileInfo));
|
||||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||||
|
QAbstractItemModelTester tester(model.get());
|
||||||
|
tester.setUseFetchMore(false);
|
||||||
QModelIndex root = model->setRootPath(flatDirTestPath);
|
QModelIndex root = model->setRootPath(flatDirTestPath);
|
||||||
QTRY_VERIFY(model->rowCount(root) > 0);
|
QTRY_VERIFY(model->rowCount(root) > 0);
|
||||||
|
|
||||||
@ -864,6 +889,8 @@ void tst_QFileSystemModel::mkdir()
|
|||||||
QString tmp = flatDirTestPath;
|
QString tmp = flatDirTestPath;
|
||||||
QString newFolderPath = QDir::toNativeSeparators(tmp + '/' + "NewFoldermkdirtest4");
|
QString newFolderPath = QDir::toNativeSeparators(tmp + '/' + "NewFoldermkdirtest4");
|
||||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||||
|
QAbstractItemModelTester tester(model.get());
|
||||||
|
tester.setUseFetchMore(false);
|
||||||
QModelIndex tmpDir = model->index(tmp);
|
QModelIndex tmpDir = model->index(tmp);
|
||||||
QVERIFY(tmpDir.isValid());
|
QVERIFY(tmpDir.isValid());
|
||||||
QDir bestatic(newFolderPath);
|
QDir bestatic(newFolderPath);
|
||||||
@ -899,6 +926,8 @@ void tst_QFileSystemModel::deleteFile()
|
|||||||
}
|
}
|
||||||
newFile.close();
|
newFile.close();
|
||||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||||
|
QAbstractItemModelTester tester(model.get());
|
||||||
|
tester.setUseFetchMore(false);
|
||||||
QModelIndex idx = model->index(newFilePath);
|
QModelIndex idx = model->index(newFilePath);
|
||||||
QVERIFY(idx.isValid());
|
QVERIFY(idx.isValid());
|
||||||
QVERIFY(model->remove(idx));
|
QVERIFY(model->remove(idx));
|
||||||
@ -961,6 +990,8 @@ void tst_QFileSystemModel::caseSensitivity()
|
|||||||
QStringList files;
|
QStringList files;
|
||||||
files << "a" << "c" << "C";
|
files << "a" << "c" << "C";
|
||||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||||
|
QAbstractItemModelTester tester(model.get());
|
||||||
|
tester.setUseFetchMore(false);
|
||||||
QVERIFY(createFiles(model.data(), tmp, files));
|
QVERIFY(createFiles(model.data(), tmp, files));
|
||||||
QModelIndex root = model->index(tmp);
|
QModelIndex root = model->index(tmp);
|
||||||
QStringList paths;
|
QStringList paths;
|
||||||
@ -1026,6 +1057,8 @@ void tst_QFileSystemModel::dirsBeforeFiles()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||||
|
QAbstractItemModelTester tester(model.get());
|
||||||
|
tester.setUseFetchMore(false);
|
||||||
QModelIndex root = model->setRootPath(dir.absolutePath());
|
QModelIndex root = model->setRootPath(dir.absolutePath());
|
||||||
// Wait for model to be notified by the file system watcher
|
// Wait for model to be notified by the file system watcher
|
||||||
QTRY_COMPARE(model->rowCount(root), 2 * itemCount);
|
QTRY_COMPARE(model->rowCount(root), 2 * itemCount);
|
||||||
@ -1100,6 +1133,8 @@ void tst_QFileSystemModel::permissions() // checks QTBUG-20503
|
|||||||
const QString tmp = flatDirTestPath;
|
const QString tmp = flatDirTestPath;
|
||||||
const QString file = tmp + QLatin1String("/f");
|
const QString file = tmp + QLatin1String("/f");
|
||||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||||
|
QAbstractItemModelTester tester(model.get());
|
||||||
|
tester.setUseFetchMore(false);
|
||||||
QVERIFY(createFiles(model.data(), tmp, QStringList{QLatin1String("f")}));
|
QVERIFY(createFiles(model.data(), tmp, QStringList{QLatin1String("f")}));
|
||||||
|
|
||||||
QVERIFY(QFile::setPermissions(file, permissions));
|
QVERIFY(QFile::setPermissions(file, permissions));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user