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> remove;
|
||||
|
||||
bool useFetchMore = true;
|
||||
bool fetchingMore;
|
||||
|
||||
enum class ChangeInFlight {
|
||||
@ -315,6 +316,19 @@ QAbstractItemModelTester::FailureReportingMode QAbstractItemModelTester::failure
|
||||
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)
|
||||
{
|
||||
Q_D(QAbstractItemModelTester);
|
||||
@ -349,9 +363,11 @@ void QAbstractItemModelTesterPrivate::nonDestructiveBasicTest()
|
||||
MODELTESTER_VERIFY(!model->buddy(QModelIndex()).isValid());
|
||||
model->canFetchMore(QModelIndex());
|
||||
MODELTESTER_VERIFY(model->columnCount(QModelIndex()) >= 0);
|
||||
fetchingMore = true;
|
||||
model->fetchMore(QModelIndex());
|
||||
fetchingMore = false;
|
||||
if (useFetchMore) {
|
||||
fetchingMore = true;
|
||||
model->fetchMore(QModelIndex());
|
||||
fetchingMore = false;
|
||||
}
|
||||
Qt::ItemFlags flags = model->flags(QModelIndex());
|
||||
MODELTESTER_VERIFY(flags == Qt::ItemIsDropEnabled || flags == 0);
|
||||
model->hasChildren(QModelIndex());
|
||||
@ -529,7 +545,7 @@ void QAbstractItemModelTesterPrivate::checkChildren(const QModelIndex &parent, i
|
||||
p = p.parent();
|
||||
|
||||
// For models that are dynamically populated
|
||||
if (model->canFetchMore(parent)) {
|
||||
if (model->canFetchMore(parent) && useFetchMore) {
|
||||
fetchingMore = true;
|
||||
model->fetchMore(parent);
|
||||
fetchingMore = false;
|
||||
|
@ -47,6 +47,7 @@ public:
|
||||
|
||||
QAbstractItemModel *model() const;
|
||||
FailureReportingMode failureReportingMode() const;
|
||||
void setUseFetchMore(bool value);
|
||||
|
||||
private:
|
||||
friend inline bool QTestPrivate::testDataGuiRoles(QAbstractItemModelTester *tester);
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <QStyle>
|
||||
#include <QtGlobal>
|
||||
#include <QTemporaryDir>
|
||||
#include <QAbstractItemModelTester>
|
||||
#if defined(Q_OS_WIN)
|
||||
# include <qt_windows.h> // for SetFileAttributes
|
||||
#endif
|
||||
@ -149,6 +150,8 @@ void tst_QFileSystemModel::indexPath()
|
||||
{
|
||||
#if !defined(Q_OS_WIN)
|
||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||
QAbstractItemModelTester tester(model.get());
|
||||
tester.setUseFetchMore(false);
|
||||
int depth = QDir::currentPath().count('/');
|
||||
model->setRootPath(QDir::currentPath());
|
||||
QString backPath;
|
||||
@ -163,6 +166,8 @@ void tst_QFileSystemModel::indexPath()
|
||||
void tst_QFileSystemModel::rootPath()
|
||||
{
|
||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||
QAbstractItemModelTester tester(model.get());
|
||||
tester.setUseFetchMore(false);
|
||||
QCOMPARE(model->rootPath(), QString(QDir().path()));
|
||||
|
||||
QSignalSpy rootChanged(model.data(), &QFileSystemModel::rootPathChanged);
|
||||
@ -227,6 +232,8 @@ void tst_QFileSystemModel::rootPath()
|
||||
void tst_QFileSystemModel::readOnly()
|
||||
{
|
||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||
QAbstractItemModelTester tester(model.get());
|
||||
tester.setUseFetchMore(false);
|
||||
QCOMPARE(model->isReadOnly(), true);
|
||||
QTemporaryFile file(flatDirTestPath + QStringLiteral("/XXXXXX.dat"));
|
||||
QVERIFY2(file.open(), qPrintable(file.errorString()));
|
||||
@ -280,6 +287,8 @@ private:
|
||||
void tst_QFileSystemModel::iconProvider()
|
||||
{
|
||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||
QAbstractItemModelTester tester(model.get());
|
||||
tester.setUseFetchMore(false);
|
||||
QVERIFY(model->iconProvider());
|
||||
QScopedPointer<QFileIconProvider> provider(new QFileIconProvider);
|
||||
model->setIconProvider(provider.data());
|
||||
@ -389,6 +398,8 @@ void tst_QFileSystemModel::rowCount()
|
||||
QSignalSpy *spy2 = nullptr;
|
||||
QSignalSpy *spy3 = nullptr;
|
||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||
QAbstractItemModelTester tester(model.get());
|
||||
tester.setUseFetchMore(false);
|
||||
QModelIndex root = prepareTestModelRoot(model.data(), flatDirTestPath, &spy2, &spy3);
|
||||
QVERIFY(root.isValid());
|
||||
|
||||
@ -417,6 +428,8 @@ void tst_QFileSystemModel::rowsInserted()
|
||||
{
|
||||
const QString tmp = flatDirTestPath;
|
||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||
QAbstractItemModelTester tester(model.get());
|
||||
tester.setUseFetchMore(false);
|
||||
QModelIndex root = prepareTestModelRoot(model.data(), tmp);
|
||||
QVERIFY(root.isValid());
|
||||
|
||||
@ -471,6 +484,8 @@ void tst_QFileSystemModel::rowsRemoved()
|
||||
{
|
||||
const QString tmp = flatDirTestPath;
|
||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||
QAbstractItemModelTester tester(model.get());
|
||||
tester.setUseFetchMore(false);
|
||||
QModelIndex root = prepareTestModelRoot(model.data(), tmp);
|
||||
QVERIFY(root.isValid());
|
||||
|
||||
@ -533,6 +548,8 @@ void tst_QFileSystemModel::dataChanged()
|
||||
|
||||
const QString tmp = flatDirTestPath;
|
||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||
QAbstractItemModelTester tester(model.get());
|
||||
tester.setUseFetchMore(false);
|
||||
QModelIndex root = prepareTestModelRoot(model.data(), tmp);
|
||||
QVERIFY(root.isValid());
|
||||
|
||||
@ -593,6 +610,8 @@ void tst_QFileSystemModel::filters()
|
||||
{
|
||||
QString tmp = flatDirTestPath;
|
||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||
QAbstractItemModelTester tester(model.get());
|
||||
tester.setUseFetchMore(false);
|
||||
QVERIFY(createFiles(model.data(), tmp, QStringList()));
|
||||
QModelIndex root = model->setRootPath(tmp);
|
||||
QFETCH(QStringList, files);
|
||||
@ -661,6 +680,8 @@ void tst_QFileSystemModel::nameFilters()
|
||||
QStringList list;
|
||||
list << "a" << "b" << "c";
|
||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||
QAbstractItemModelTester tester(model.get());
|
||||
tester.setUseFetchMore(false);
|
||||
model->setNameFilters(list);
|
||||
model->setNameFilterDisables(false);
|
||||
QCOMPARE(model->nameFilters(), list);
|
||||
@ -706,6 +727,8 @@ void tst_QFileSystemModel::setData_data()
|
||||
void tst_QFileSystemModel::setData()
|
||||
{
|
||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||
QAbstractItemModelTester tester(model.get());
|
||||
tester.setUseFetchMore(false);
|
||||
QSignalSpy spy(model.data(), &QFileSystemModel::fileRenamed);
|
||||
QFETCH(QString, subdirName);
|
||||
QFETCH(QStringList, files);
|
||||
@ -758,6 +781,8 @@ void tst_QFileSystemModel::sortPersistentIndex()
|
||||
file.close();
|
||||
QTRY_VERIFY(QDir(flatDirTestPath).entryInfoList().contains(fileInfo));
|
||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||
QAbstractItemModelTester tester(model.get());
|
||||
tester.setUseFetchMore(false);
|
||||
QModelIndex root = model->setRootPath(flatDirTestPath);
|
||||
QTRY_VERIFY(model->rowCount(root) > 0);
|
||||
|
||||
@ -864,6 +889,8 @@ void tst_QFileSystemModel::mkdir()
|
||||
QString tmp = flatDirTestPath;
|
||||
QString newFolderPath = QDir::toNativeSeparators(tmp + '/' + "NewFoldermkdirtest4");
|
||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||
QAbstractItemModelTester tester(model.get());
|
||||
tester.setUseFetchMore(false);
|
||||
QModelIndex tmpDir = model->index(tmp);
|
||||
QVERIFY(tmpDir.isValid());
|
||||
QDir bestatic(newFolderPath);
|
||||
@ -899,6 +926,8 @@ void tst_QFileSystemModel::deleteFile()
|
||||
}
|
||||
newFile.close();
|
||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||
QAbstractItemModelTester tester(model.get());
|
||||
tester.setUseFetchMore(false);
|
||||
QModelIndex idx = model->index(newFilePath);
|
||||
QVERIFY(idx.isValid());
|
||||
QVERIFY(model->remove(idx));
|
||||
@ -961,6 +990,8 @@ void tst_QFileSystemModel::caseSensitivity()
|
||||
QStringList files;
|
||||
files << "a" << "c" << "C";
|
||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||
QAbstractItemModelTester tester(model.get());
|
||||
tester.setUseFetchMore(false);
|
||||
QVERIFY(createFiles(model.data(), tmp, files));
|
||||
QModelIndex root = model->index(tmp);
|
||||
QStringList paths;
|
||||
@ -1026,6 +1057,8 @@ void tst_QFileSystemModel::dirsBeforeFiles()
|
||||
}
|
||||
|
||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||
QAbstractItemModelTester tester(model.get());
|
||||
tester.setUseFetchMore(false);
|
||||
QModelIndex root = model->setRootPath(dir.absolutePath());
|
||||
// Wait for model to be notified by the file system watcher
|
||||
QTRY_COMPARE(model->rowCount(root), 2 * itemCount);
|
||||
@ -1100,6 +1133,8 @@ void tst_QFileSystemModel::permissions() // checks QTBUG-20503
|
||||
const QString tmp = flatDirTestPath;
|
||||
const QString file = tmp + QLatin1String("/f");
|
||||
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
|
||||
QAbstractItemModelTester tester(model.get());
|
||||
tester.setUseFetchMore(false);
|
||||
QVERIFY(createFiles(model.data(), tmp, QStringList{QLatin1String("f")}));
|
||||
|
||||
QVERIFY(QFile::setPermissions(file, permissions));
|
||||
|
Loading…
x
Reference in New Issue
Block a user