QFileSystemModel: Brush up the test
- Use nullptr - Instantiate test helpers on the stack or use QScopedPointer - Remove C-style casts of enumerations/flags, use meta types - Port to Qt 5 connection syntax - Fix static method invocation - Use initializer lists for QStringList - Introduce a logging category for all debug output - Streamline code - Refactor cleanup() to operate on QFileInfoList which is faster and streamline - Remove unused variables Task-number: QTBUG-76493 Change-Id: I3a033af7c9ec4dac3149d2016104daad07797a4f Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
This commit is contained in:
parent
a2fa624c79
commit
84a58e514b
@ -65,6 +65,11 @@
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
Q_DECLARE_METATYPE(QDir::Filters)
|
||||
Q_DECLARE_METATYPE(QFileDevice::Permissions)
|
||||
|
||||
Q_LOGGING_CATEGORY(lcFileSystemModel, "qt.widgets.tests.qfilesystemmodel")
|
||||
|
||||
class tst_QFileSystemModel : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
@ -128,7 +133,7 @@ private slots:
|
||||
void fileInfo();
|
||||
|
||||
protected:
|
||||
bool createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount = 0, const QStringList &intial_dirs = QStringList());
|
||||
bool createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount = 0, const QStringList &initial_dirs = QStringList());
|
||||
QModelIndex prepareTestModelRoot(const QString &test_path, QSignalSpy **spy2 = nullptr,
|
||||
QSignalSpy **spy3 = nullptr);
|
||||
|
||||
@ -153,23 +158,20 @@ void tst_QFileSystemModel::cleanup()
|
||||
{
|
||||
delete model;
|
||||
model = 0;
|
||||
QString tmp = flatDirTestPath;
|
||||
QDir dir(tmp);
|
||||
if (dir.exists(tmp)) {
|
||||
QStringList list = dir.entryList(QDir::AllEntries | QDir::System | QDir::Hidden | QDir::NoDotAndDotDot);
|
||||
for (int i = 0; i < list.count(); ++i) {
|
||||
QFileInfo fi(dir.path() + '/' + list.at(i));
|
||||
if (fi.exists() && fi.isFile()) {
|
||||
QFile p(fi.absoluteFilePath());
|
||||
p.setPermissions(QFile::ReadUser | QFile::ReadOwner | QFile::ExeOwner | QFile::ExeUser | QFile::WriteUser | QFile::WriteOwner | QFile::WriteOther);
|
||||
QFile dead(dir.path() + '/' + list.at(i));
|
||||
dead.remove();
|
||||
QDir dir(flatDirTestPath);
|
||||
if (dir.exists()) {
|
||||
const QDir::Filters filters = QDir::AllEntries | QDir::System | QDir::Hidden | QDir::NoDotAndDotDot;
|
||||
const QFileInfoList list = dir.entryInfoList(filters);
|
||||
for (const QFileInfo &fi : list) {
|
||||
if (fi.isDir()) {
|
||||
QVERIFY(dir.rmdir(fi.fileName()));
|
||||
} else {
|
||||
QFile dead(fi.absoluteFilePath());
|
||||
dead.setPermissions(QFile::ReadUser | QFile::ReadOwner | QFile::ExeOwner | QFile::ExeUser | QFile::WriteUser | QFile::WriteOwner | QFile::WriteOther);
|
||||
QVERIFY(dead.remove());
|
||||
}
|
||||
if (fi.exists() && fi.isDir())
|
||||
QVERIFY(dir.rmdir(list.at(i)));
|
||||
}
|
||||
list = dir.entryList(QDir::AllEntries | QDir::System | QDir::Hidden | QDir::NoDotAndDotDot);
|
||||
QCOMPARE(list.count(), 0);
|
||||
QVERIFY(dir.entryInfoList(filters).isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,7 +199,7 @@ void tst_QFileSystemModel::rootPath()
|
||||
{
|
||||
QCOMPARE(model->rootPath(), QString(QDir().path()));
|
||||
|
||||
QSignalSpy rootChanged(model, SIGNAL(rootPathChanged(QString)));
|
||||
QSignalSpy rootChanged(model, &QFileSystemModel::rootPathChanged);
|
||||
QModelIndex root = model->setRootPath(model->rootPath());
|
||||
root = model->setRootPath("this directory shouldn't exist");
|
||||
QCOMPARE(rootChanged.count(), 0);
|
||||
@ -263,19 +265,21 @@ void tst_QFileSystemModel::readOnly()
|
||||
class CustomFileIconProvider : public QFileIconProvider
|
||||
{
|
||||
public:
|
||||
CustomFileIconProvider() : QFileIconProvider() {
|
||||
mb = qApp->style()->standardIcon(QStyle::SP_MessageBoxCritical);
|
||||
dvd = qApp->style()->standardIcon(QStyle::SP_DriveDVDIcon);
|
||||
CustomFileIconProvider() : QFileIconProvider()
|
||||
{
|
||||
auto style = QApplication::style();
|
||||
mb = style->standardIcon(QStyle::SP_MessageBoxCritical);
|
||||
dvd = style->standardIcon(QStyle::SP_DriveDVDIcon);
|
||||
}
|
||||
|
||||
virtual QIcon icon(const QFileInfo &info) const
|
||||
QIcon icon(const QFileInfo &info) const override
|
||||
{
|
||||
if (info.isDir())
|
||||
return mb;
|
||||
|
||||
return QFileIconProvider::icon(info);
|
||||
}
|
||||
virtual QIcon icon(IconType type) const
|
||||
QIcon icon(IconType type) const override
|
||||
{
|
||||
if (type == QFileIconProvider::Folder)
|
||||
return dvd;
|
||||
@ -290,68 +294,63 @@ private:
|
||||
void tst_QFileSystemModel::iconProvider()
|
||||
{
|
||||
QVERIFY(model->iconProvider());
|
||||
QFileIconProvider *p = new QFileIconProvider();
|
||||
model->setIconProvider(p);
|
||||
QCOMPARE(model->iconProvider(), p);
|
||||
model->setIconProvider(0);
|
||||
delete p;
|
||||
QScopedPointer<QFileIconProvider> provider(new QFileIconProvider);
|
||||
model->setIconProvider(provider.data());
|
||||
QCOMPARE(model->iconProvider(), provider.data());
|
||||
model->setIconProvider(nullptr);
|
||||
provider.reset();
|
||||
|
||||
QFileSystemModel *myModel = new QFileSystemModel();
|
||||
QScopedPointer<QFileSystemModel> myModel(new QFileSystemModel);
|
||||
const QStringList documentPaths = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
|
||||
QVERIFY(!documentPaths.isEmpty());
|
||||
const QString documentPath = documentPaths.front();
|
||||
myModel->setRootPath(documentPath);
|
||||
myModel->setRootPath(documentPaths.constFirst());
|
||||
//We change the provider, icons must be updated
|
||||
CustomFileIconProvider *custom = new CustomFileIconProvider();
|
||||
myModel->setIconProvider(custom);
|
||||
provider.reset(new CustomFileIconProvider);
|
||||
myModel->setIconProvider(provider.data());
|
||||
|
||||
QPixmap mb = qApp->style()->standardIcon(QStyle::SP_MessageBoxCritical).pixmap(50, 50);
|
||||
QPixmap mb = QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical).pixmap(50, 50);
|
||||
QCOMPARE(myModel->fileIcon(myModel->index(QDir::homePath())).pixmap(50, 50), mb);
|
||||
delete myModel;
|
||||
delete custom;
|
||||
}
|
||||
|
||||
bool tst_QFileSystemModel::createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount, const QStringList &initial_dirs)
|
||||
{
|
||||
//qDebug() << (model->rowCount(model->index(test_path))) << existingFileCount << initial_files;
|
||||
qCDebug(lcFileSystemModel) << (model->rowCount(model->index(test_path))) << existingFileCount << initial_files;
|
||||
bool timedOut = false;
|
||||
TRY_WAIT((model->rowCount(model->index(test_path)) == existingFileCount), &timedOut);
|
||||
if (timedOut)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < initial_dirs.count(); ++i) {
|
||||
QDir dir(test_path);
|
||||
if (!dir.exists()) {
|
||||
qWarning() << "error" << test_path << "doesn't exists";
|
||||
return false;
|
||||
}
|
||||
if(!dir.mkdir(initial_dirs.at(i))) {
|
||||
qWarning() << "error" << "failed to make" << initial_dirs.at(i);
|
||||
return false;
|
||||
}
|
||||
//qDebug() << test_path + '/' + initial_dirs.at(i) << (QFile::exists(test_path + '/' + initial_dirs.at(i)));
|
||||
QDir dir(test_path);
|
||||
if (!dir.exists()) {
|
||||
qWarning() << "error" << test_path << "doesn't exist";
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < initial_files.count(); ++i) {
|
||||
QFile file(test_path + '/' + initial_files.at(i));
|
||||
for (const auto &initial_dir : initial_dirs) {
|
||||
if (!dir.mkdir(initial_dir)) {
|
||||
qWarning() << "error" << "failed to make" << initial_dir;
|
||||
return false;
|
||||
}
|
||||
qCDebug(lcFileSystemModel) << test_path + '/' + initial_dir << (QFile::exists(test_path + '/' + initial_dir));
|
||||
}
|
||||
for (const auto &initial_file : initial_files) {
|
||||
QFile file(test_path + '/' + initial_file);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Append)) {
|
||||
qDebug() << "failed to open file" << initial_files.at(i);
|
||||
qDebug() << "failed to open file" << initial_file;
|
||||
return false;
|
||||
}
|
||||
if (!file.resize(1024 + file.size())) {
|
||||
qDebug() << "failed to resize file" << initial_files.at(i);
|
||||
qDebug() << "failed to resize file" << initial_file;
|
||||
return false;
|
||||
}
|
||||
if (!file.flush()) {
|
||||
qDebug() << "failed to flush file" << initial_files.at(i);
|
||||
qDebug() << "failed to flush file" << initial_file;
|
||||
return false;
|
||||
}
|
||||
file.close();
|
||||
#if defined(Q_OS_WIN)
|
||||
if (initial_files.at(i)[0] == '.') {
|
||||
QString hiddenFile = QDir::toNativeSeparators(file.fileName());
|
||||
wchar_t nativeHiddenFile[MAX_PATH];
|
||||
memset(nativeHiddenFile, 0, sizeof(nativeHiddenFile));
|
||||
hiddenFile.toWCharArray(nativeHiddenFile);
|
||||
if (initial_file[0] == '.') {
|
||||
const QString hiddenFile = QDir::toNativeSeparators(file.fileName());
|
||||
const auto nativeHiddenFile = reinterpret_cast<const wchar_t *>(hiddenFile.utf16());
|
||||
#ifndef Q_OS_WINRT
|
||||
DWORD currentAttributes = ::GetFileAttributes(nativeHiddenFile);
|
||||
#else // !Q_OS_WINRT
|
||||
@ -370,7 +369,7 @@ bool tst_QFileSystemModel::createFiles(const QString &test_path, const QStringLi
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//qDebug() << test_path + '/' + initial_files.at(i) << (QFile::exists(test_path + '/' + initial_files.at(i)));
|
||||
qCDebug(lcFileSystemModel) << test_path + '/' + initial_file << (QFile::exists(test_path + '/' + initial_file));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -387,7 +386,6 @@ QModelIndex tst_QFileSystemModel::prepareTestModelRoot(const QString &test_path,
|
||||
*spy3 = new QSignalSpy(model, &QFileSystemModel::rowsAboutToBeInserted);
|
||||
|
||||
QStringList files = { "b", "d", "f", "h", "j", ".a", ".c", ".e", ".g" };
|
||||
QString l = "b,d,f,h,j,.a,.c,.e,.g";
|
||||
|
||||
if (!createFiles(test_path, files))
|
||||
return QModelIndex();
|
||||
@ -406,7 +404,6 @@ QModelIndex tst_QFileSystemModel::prepareTestModelRoot(const QString &test_path,
|
||||
|
||||
void tst_QFileSystemModel::rowCount()
|
||||
{
|
||||
const QString tmp = flatDirTestPath;
|
||||
QSignalSpy *spy2 = nullptr;
|
||||
QSignalSpy *spy3 = nullptr;
|
||||
QModelIndex root = prepareTestModelRoot(flatDirTestPath, &spy2, &spy3);
|
||||
@ -419,11 +416,11 @@ void tst_QFileSystemModel::rowCount()
|
||||
void tst_QFileSystemModel::rowsInserted_data()
|
||||
{
|
||||
QTest::addColumn<int>("count");
|
||||
QTest::addColumn<int>("ascending");
|
||||
QTest::addColumn<Qt::SortOrder>("ascending");
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
const QByteArray iB = QByteArray::number(i);
|
||||
QTest::newRow(("Qt::AscendingOrder " + iB).constData()) << i << (int)Qt::AscendingOrder;
|
||||
QTest::newRow(("Qt::DescendingOrder " + iB).constData()) << i << (int)Qt::DescendingOrder;
|
||||
QTest::newRow(("Qt::AscendingOrder " + iB).constData()) << i << Qt::AscendingOrder;
|
||||
QTest::newRow(("Qt::DescendingOrder " + iB).constData()) << i << Qt::DescendingOrder;
|
||||
}
|
||||
}
|
||||
|
||||
@ -439,12 +436,12 @@ void tst_QFileSystemModel::rowsInserted()
|
||||
QModelIndex root = prepareTestModelRoot(tmp);
|
||||
QVERIFY(root.isValid());
|
||||
|
||||
QFETCH(int, ascending);
|
||||
QFETCH(Qt::SortOrder, ascending);
|
||||
QFETCH(int, count);
|
||||
model->sort(0, (Qt::SortOrder)ascending);
|
||||
model->sort(0, ascending);
|
||||
|
||||
QSignalSpy spy0(model, SIGNAL(rowsInserted(QModelIndex,int,int)));
|
||||
QSignalSpy spy1(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)));
|
||||
QSignalSpy spy0(model, &QAbstractItemModel::rowsInserted);
|
||||
QSignalSpy spy1(model, &QAbstractItemModel::rowsAboutToBeInserted);
|
||||
int oldCount = model->rowCount(root);
|
||||
QStringList files;
|
||||
for (int i = 0; i < count; ++i)
|
||||
@ -493,15 +490,16 @@ void tst_QFileSystemModel::rowsRemoved()
|
||||
QVERIFY(root.isValid());
|
||||
|
||||
QFETCH(int, count);
|
||||
QFETCH(int, ascending);
|
||||
model->sort(0, (Qt::SortOrder)ascending);
|
||||
QFETCH(Qt::SortOrder, ascending);
|
||||
model->sort(0, ascending);
|
||||
|
||||
QSignalSpy spy0(model, SIGNAL(rowsRemoved(QModelIndex,int,int)));
|
||||
QSignalSpy spy1(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)));
|
||||
QSignalSpy spy0(model, &QAbstractItemModel::rowsRemoved);
|
||||
QSignalSpy spy1(model, &QAbstractItemModel::rowsAboutToBeRemoved);
|
||||
int oldCount = model->rowCount(root);
|
||||
for (int i = count - 1; i >= 0; --i) {
|
||||
//qDebug() << "removing" << model->index(i, 0, root).data().toString();
|
||||
QVERIFY(QFile::remove(tmp + '/' + model->index(i, 0, root).data().toString()));
|
||||
const QString fileName = model->index(i, 0, root).data().toString();
|
||||
qCDebug(lcFileSystemModel) << "removing" << fileName;
|
||||
QVERIFY(QFile::remove(tmp + QLatin1Char('/') + fileName));
|
||||
}
|
||||
for (int i = 0 ; i < 10; ++i) {
|
||||
if (count != 0) {
|
||||
@ -520,18 +518,23 @@ void tst_QFileSystemModel::rowsRemoved()
|
||||
lst.append(model->index(i, 0, root).data().toString());
|
||||
if (model->rowCount(root) == oldCount - count)
|
||||
break;
|
||||
qDebug() << "still have:" << lst << QFile::exists(tmp + '/' + QString(".a"));
|
||||
qCDebug(lcFileSystemModel) << "still have:" << lst << QFile::exists(tmp + QLatin1String("/.a"));
|
||||
QDir tmpLister(tmp);
|
||||
qDebug() << tmpLister.entryList();
|
||||
qCDebug(lcFileSystemModel) << tmpLister.entryList();
|
||||
}
|
||||
QTRY_COMPARE(model->rowCount(root), oldCount - count);
|
||||
|
||||
QVERIFY(QFile::exists(tmp + '/' + QString(".a")));
|
||||
QVERIFY(QFile::remove(tmp + '/' + QString(".a")));
|
||||
QVERIFY(QFile::remove(tmp + '/' + QString(".c")));
|
||||
QVERIFY(QFile::exists(tmp + QLatin1String("/.a")));
|
||||
QVERIFY(QFile::remove(tmp + QLatin1String("/.a")));
|
||||
QVERIFY(QFile::remove(tmp + QLatin1String("/.c")));
|
||||
|
||||
if (count != 0) QVERIFY(spy0.count() >= 1); else QCOMPARE(spy0.count(), 0);
|
||||
if (count != 0) QVERIFY(spy1.count() >= 1); else QCOMPARE(spy1.count(), 0);
|
||||
if (count != 0) {
|
||||
QVERIFY(spy0.count() >= 1);
|
||||
QVERIFY(spy1.count() >= 1);
|
||||
} else {
|
||||
QCOMPARE(spy0.count(), 0);
|
||||
QCOMPARE(spy1.count(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QFileSystemModel::dataChanged_data()
|
||||
@ -548,10 +551,10 @@ void tst_QFileSystemModel::dataChanged()
|
||||
QVERIFY(root.isValid());
|
||||
|
||||
QFETCH(int, count);
|
||||
QFETCH(int, assending);
|
||||
model->sort(0, (Qt::SortOrder)assending);
|
||||
QFETCH(Qt::SortOrder, ascending);
|
||||
model->sort(0, ascending);
|
||||
|
||||
QSignalSpy spy(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)));
|
||||
QSignalSpy spy(model, &QAbstractItemModel::dataChanged);
|
||||
QStringList files;
|
||||
for (int i = 0; i < count; ++i)
|
||||
files.append(model->index(i, 0, root).data().toString());
|
||||
@ -566,34 +569,38 @@ void tst_QFileSystemModel::filters_data()
|
||||
{
|
||||
QTest::addColumn<QStringList>("files");
|
||||
QTest::addColumn<QStringList>("dirs");
|
||||
QTest::addColumn<int>("dirFilters");
|
||||
QTest::addColumn<QDir::Filters>("dirFilters");
|
||||
QTest::addColumn<QStringList>("nameFilters");
|
||||
QTest::addColumn<int>("rowCount");
|
||||
QTest::newRow("no dirs") << (QStringList() << "a" << "b" << "c") << QStringList() << (int)(QDir::Dirs) << QStringList() << 2;
|
||||
QTest::newRow("no dirs - dot") << (QStringList() << "a" << "b" << "c") << QStringList() << (int)(QDir::Dirs | QDir::NoDot) << QStringList() << 1;
|
||||
QTest::newRow("no dirs - dotdot") << (QStringList() << "a" << "b" << "c") << QStringList() << (int)(QDir::Dirs | QDir::NoDotDot) << QStringList() << 1;
|
||||
QTest::newRow("no dirs - dotanddotdot") << (QStringList() << "a" << "b" << "c") << QStringList() << (int)(QDir::Dirs | QDir::NoDotAndDotDot) << QStringList() << 0;
|
||||
QTest::newRow("one dir - dot") << (QStringList() << "a" << "b" << "c") << (QStringList() << "Z") << (int)(QDir::Dirs | QDir::NoDot) << QStringList() << 2;
|
||||
QTest::newRow("one dir - dotdot") << (QStringList() << "a" << "b" << "c") << (QStringList() << "Z") << (int)(QDir::Dirs | QDir::NoDotDot) << QStringList() << 2;
|
||||
QTest::newRow("one dir - dotanddotdot") << (QStringList() << "a" << "b" << "c") << (QStringList() << "Z") << (int)(QDir::Dirs | QDir::NoDotAndDotDot) << QStringList() << 1;
|
||||
QTest::newRow("one dir") << (QStringList() << "a" << "b" << "c") << (QStringList() << "Z") << (int)(QDir::Dirs) << QStringList() << 3;
|
||||
QTest::newRow("no dir + hidden") << (QStringList() << "a" << "b" << "c") << QStringList() << (int)(QDir::Dirs | QDir::Hidden) << QStringList() << 2;
|
||||
QTest::newRow("dir+hid+files") << (QStringList() << "a" << "b" << "c") << QStringList() <<
|
||||
(int)(QDir::Dirs | QDir::Files | QDir::Hidden) << QStringList() << 5;
|
||||
QTest::newRow("dir+file+hid-dot .A") << (QStringList() << "a" << "b" << "c") << (QStringList() << ".A") <<
|
||||
(int)(QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot) << QStringList() << 4;
|
||||
QTest::newRow("dir+files+hid+dot A") << (QStringList() << "a" << "b" << "c") << (QStringList() << "AFolder") <<
|
||||
(int)(QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot) << (QStringList() << "A*") << 2;
|
||||
QTest::newRow("dir+files+hid+dot+cas1") << (QStringList() << "a" << "b" << "c") << (QStringList() << "Z") <<
|
||||
(int)(QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot | QDir::CaseSensitive) << (QStringList() << "Z") << 1;
|
||||
QTest::newRow("dir+files+hid+dot+cas2") << (QStringList() << "a" << "b" << "c") << (QStringList() << "Z") <<
|
||||
(int)(QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot | QDir::CaseSensitive) << (QStringList() << "a") << 1;
|
||||
QTest::newRow("dir+files+hid+dot+cas+alldir") << (QStringList() << "a" << "b" << "c") << (QStringList() << "Z") <<
|
||||
(int)(QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot | QDir::CaseSensitive | QDir::AllDirs) << (QStringList() << "Z") << 1;
|
||||
|
||||
QTest::newRow("case sensitive") << (QStringList() << "Antiguagdb" << "Antiguamtd"
|
||||
<< "Antiguamtp" << "afghanistangdb" << "afghanistanmtd")
|
||||
<< QStringList() << (int)(QDir::Files) << QStringList() << 5;
|
||||
const QStringList abcList{QLatin1String("a"), QLatin1String("b"), QLatin1String("c")};
|
||||
const QStringList zList{QLatin1String("Z")};
|
||||
|
||||
QTest::newRow("no dirs") << abcList << QStringList() << QDir::Filters(QDir::Dirs) << QStringList() << 2;
|
||||
QTest::newRow("no dirs - dot") << abcList << QStringList() << (QDir::Dirs | QDir::NoDot) << QStringList() << 1;
|
||||
QTest::newRow("no dirs - dotdot") << abcList << QStringList() << (QDir::Dirs | QDir::NoDotDot) << QStringList() << 1;
|
||||
QTest::newRow("no dirs - dotanddotdot") << abcList << QStringList() << (QDir::Dirs | QDir::NoDotAndDotDot) << QStringList() << 0;
|
||||
QTest::newRow("one dir - dot") << abcList << zList << (QDir::Dirs | QDir::NoDot) << QStringList() << 2;
|
||||
QTest::newRow("one dir - dotdot") << abcList << zList << (QDir::Dirs | QDir::NoDotDot) << QStringList() << 2;
|
||||
QTest::newRow("one dir - dotanddotdot") << abcList << zList << (QDir::Dirs | QDir::NoDotAndDotDot) << QStringList() << 1;
|
||||
QTest::newRow("one dir") << abcList << zList << QDir::Filters(QDir::Dirs) << QStringList() << 3;
|
||||
QTest::newRow("no dir + hidden") << abcList << QStringList() << (QDir::Dirs | QDir::Hidden) << QStringList() << 2;
|
||||
QTest::newRow("dir+hid+files") << abcList << QStringList() <<
|
||||
(QDir::Dirs | QDir::Files | QDir::Hidden) << QStringList() << 5;
|
||||
QTest::newRow("dir+file+hid-dot .A") << abcList << QStringList{QLatin1String(".A")} <<
|
||||
(QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot) << QStringList() << 4;
|
||||
QTest::newRow("dir+files+hid+dot A") << abcList << QStringList{QLatin1String("AFolder")} <<
|
||||
(QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot) << QStringList{QLatin1String("A*")} << 2;
|
||||
QTest::newRow("dir+files+hid+dot+cas1") << abcList << zList <<
|
||||
(QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot | QDir::CaseSensitive) << zList << 1;
|
||||
QTest::newRow("dir+files+hid+dot+cas2") << abcList << zList <<
|
||||
(QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot | QDir::CaseSensitive) << QStringList{QLatin1String("a")} << 1;
|
||||
QTest::newRow("dir+files+hid+dot+cas+alldir") << abcList << zList <<
|
||||
(QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot | QDir::CaseSensitive | QDir::AllDirs) << zList << 1;
|
||||
|
||||
QTest::newRow("case sensitive") << QStringList{QLatin1String("Antiguagdb"), QLatin1String("Antiguamtd"),
|
||||
QLatin1String("Antiguamtp"), QLatin1String("afghanistangdb"), QLatin1String("afghanistanmtd")}
|
||||
<< QStringList() << QDir::Filters(QDir::Files) << QStringList() << 5;
|
||||
}
|
||||
|
||||
void tst_QFileSystemModel::filters()
|
||||
@ -603,27 +610,26 @@ void tst_QFileSystemModel::filters()
|
||||
QModelIndex root = model->setRootPath(tmp);
|
||||
QFETCH(QStringList, files);
|
||||
QFETCH(QStringList, dirs);
|
||||
QFETCH(int, dirFilters);
|
||||
QFETCH(QDir::Filters, dirFilters);
|
||||
QFETCH(QStringList, nameFilters);
|
||||
QFETCH(int, rowCount);
|
||||
|
||||
if (nameFilters.count() > 0)
|
||||
model->setNameFilters(nameFilters);
|
||||
model->setNameFilterDisables(false);
|
||||
model->setFilter((QDir::Filters)dirFilters);
|
||||
model->setFilter(dirFilters);
|
||||
|
||||
QVERIFY(createFiles(tmp, files, 0, dirs));
|
||||
QTRY_COMPARE(model->rowCount(root), rowCount);
|
||||
|
||||
// Make sure that we do what QDir does
|
||||
QDir xFactor(tmp);
|
||||
QDir::Filters filters = (QDir::Filters)dirFilters;
|
||||
QStringList dirEntries;
|
||||
|
||||
if (nameFilters.count() > 0)
|
||||
dirEntries = xFactor.entryList(nameFilters, filters);
|
||||
dirEntries = xFactor.entryList(nameFilters, dirFilters);
|
||||
else
|
||||
dirEntries = xFactor.entryList(filters);
|
||||
dirEntries = xFactor.entryList(dirFilters);
|
||||
|
||||
QCOMPARE(dirEntries.count(), rowCount);
|
||||
|
||||
@ -693,15 +699,17 @@ void tst_QFileSystemModel::setData_data()
|
||||
<< QDir::temp().absolutePath() + '/' + "a"
|
||||
<< false;
|
||||
*/
|
||||
|
||||
const QStringList abcList{QLatin1String("a"), QLatin1String("b"), QLatin1String("c")};
|
||||
QTest::newRow("in current dir")
|
||||
<< QString()
|
||||
<< (QStringList() << "a" << "b" << "c")
|
||||
<< abcList
|
||||
<< "a"
|
||||
<< "d"
|
||||
<< true;
|
||||
QTest::newRow("in subdir")
|
||||
<< "s"
|
||||
<< (QStringList() << "a" << "b" << "c")
|
||||
<< abcList
|
||||
<< "a"
|
||||
<< "d"
|
||||
<< true;
|
||||
@ -709,7 +717,7 @@ void tst_QFileSystemModel::setData_data()
|
||||
|
||||
void tst_QFileSystemModel::setData()
|
||||
{
|
||||
QSignalSpy spy(model, SIGNAL(fileRenamed(QString,QString,QString)));
|
||||
QSignalSpy spy(model, &QFileSystemModel::fileRenamed);
|
||||
QFETCH(QString, subdirName);
|
||||
QFETCH(QStringList, files);
|
||||
QFETCH(QString, oldFileName);
|
||||
@ -786,8 +794,9 @@ void tst_QFileSystemModel::sort()
|
||||
{
|
||||
QFETCH(bool, fileDialogMode);
|
||||
|
||||
MyFriendFileSystemModel *myModel = new MyFriendFileSystemModel();
|
||||
QTreeView *tree = new QTreeView();
|
||||
QScopedPointer<MyFriendFileSystemModel> myModel(new MyFriendFileSystemModel);
|
||||
QTreeView tree;
|
||||
tree.setWindowTitle(QTest::currentTestFunction());
|
||||
|
||||
if (fileDialogMode && EmulationDetector::isRunningArmOnX86())
|
||||
QSKIP("Crashes in QEMU. QTBUG-70572");
|
||||
@ -816,24 +825,23 @@ void tst_QFileSystemModel::sort()
|
||||
|
||||
myModel->setRootPath("");
|
||||
myModel->setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
|
||||
tree->setSortingEnabled(true);
|
||||
tree->setModel(myModel);
|
||||
tree->show();
|
||||
tree->resize(800, 800);
|
||||
QVERIFY(QTest::qWaitForWindowActive(tree));
|
||||
tree->header()->setSortIndicator(1,Qt::DescendingOrder);
|
||||
tree->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
||||
tree.setSortingEnabled(true);
|
||||
tree.setModel(myModel.data());
|
||||
tree.show();
|
||||
tree.resize(800, 800);
|
||||
QVERIFY(QTest::qWaitForWindowActive(&tree));
|
||||
tree.header()->setSortIndicator(1, Qt::DescendingOrder);
|
||||
tree.header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
||||
QStringList dirsToOpen;
|
||||
do
|
||||
{
|
||||
dirsToOpen<<dir.absolutePath();
|
||||
do {
|
||||
dirsToOpen << dir.absolutePath();
|
||||
} while (dir.cdUp());
|
||||
|
||||
for (int i = dirsToOpen.size() -1 ; i > 0 ; --i) {
|
||||
QString path = dirsToOpen[i];
|
||||
tree->expand(myModel->index(path, 0));
|
||||
tree.expand(myModel->index(path, 0));
|
||||
}
|
||||
tree->expand(myModel->index(dirPath, 0));
|
||||
tree.expand(myModel->index(dirPath, 0));
|
||||
QModelIndex parent = myModel->index(dirPath, 0);
|
||||
QList<QString> expectedOrder;
|
||||
expectedOrder << tempFile2.fileName() << tempFile.fileName() << dirPath + QChar('/') + ".." << dirPath + QChar('/') + ".";
|
||||
@ -859,9 +867,6 @@ void tst_QFileSystemModel::sort()
|
||||
QTRY_COMPARE(dirPath + QChar('/') + myModel->index(i, 1, parent).data(QFileSystemModel::FileNameRole).toString(), expectedOrder.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
delete tree;
|
||||
delete myModel;
|
||||
}
|
||||
|
||||
void tst_QFileSystemModel::mkdir()
|
||||
@ -1013,10 +1018,10 @@ void tst_QFileSystemModel::dirsBeforeFiles()
|
||||
|
||||
const int itemCount = 3;
|
||||
for (int i = 0; i < itemCount; ++i) {
|
||||
QLatin1Char c('a' + i);
|
||||
dir.mkdir(c + QLatin1String("-dir"));
|
||||
QLatin1Char c('a' + char(i));
|
||||
QVERIFY(dir.mkdir(c + QLatin1String("-dir")));
|
||||
QFile file(flatDirTestPath + QLatin1Char('/') + c + QLatin1String("-file"));
|
||||
file.open(QIODevice::ReadWrite);
|
||||
QVERIFY(file.open(QIODevice::ReadWrite));
|
||||
file.close();
|
||||
}
|
||||
|
||||
@ -1073,7 +1078,7 @@ static inline QByteArray permissionRowName(bool readOnly, int permission)
|
||||
|
||||
void tst_QFileSystemModel::permissions_data()
|
||||
{
|
||||
QTest::addColumn<int>("permissions");
|
||||
QTest::addColumn<QFileDevice::Permissions>("permissions");
|
||||
QTest::addColumn<bool>("readOnly");
|
||||
|
||||
static const int permissions[] = {
|
||||
@ -1081,22 +1086,22 @@ void tst_QFileSystemModel::permissions_data()
|
||||
QFile::ReadOwner,
|
||||
QFile::WriteOwner|QFile::ReadOwner,
|
||||
};
|
||||
for (size_t i = 0; i < sizeof permissions / sizeof *permissions; ++i) {
|
||||
QTest::newRow(permissionRowName(false, permissions[i]).constData()) << permissions[i] << false;
|
||||
QTest::newRow(permissionRowName(true, permissions[i]).constData()) << permissions[i] << true;
|
||||
for (int permission : permissions) {
|
||||
QTest::newRow(permissionRowName(false, permission).constData()) << QFileDevice::Permissions(permission) << false;
|
||||
QTest::newRow(permissionRowName(true, permission).constData()) << QFileDevice::Permissions(permission) << true;
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QFileSystemModel::permissions() // checks QTBUG-20503
|
||||
{
|
||||
QFETCH(int, permissions);
|
||||
QFETCH(QFileDevice::Permissions, permissions);
|
||||
QFETCH(bool, readOnly);
|
||||
|
||||
const QString tmp = flatDirTestPath;
|
||||
const QString file = tmp + QLatin1String("/f");
|
||||
QVERIFY(createFiles(tmp, QStringList() << "f"));
|
||||
QVERIFY(createFiles(tmp, QStringList{QLatin1String("f")}));
|
||||
|
||||
QVERIFY(QFile::setPermissions(file, QFile::Permissions(permissions)));
|
||||
QVERIFY(QFile::setPermissions(file, permissions));
|
||||
|
||||
const QModelIndex root = model->setRootPath(tmp);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user