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)
|
} 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 {
|
class tst_QFileSystemModel : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -128,7 +133,7 @@ private slots:
|
|||||||
void fileInfo();
|
void fileInfo();
|
||||||
|
|
||||||
protected:
|
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,
|
QModelIndex prepareTestModelRoot(const QString &test_path, QSignalSpy **spy2 = nullptr,
|
||||||
QSignalSpy **spy3 = nullptr);
|
QSignalSpy **spy3 = nullptr);
|
||||||
|
|
||||||
@ -153,23 +158,20 @@ void tst_QFileSystemModel::cleanup()
|
|||||||
{
|
{
|
||||||
delete model;
|
delete model;
|
||||||
model = 0;
|
model = 0;
|
||||||
QString tmp = flatDirTestPath;
|
QDir dir(flatDirTestPath);
|
||||||
QDir dir(tmp);
|
if (dir.exists()) {
|
||||||
if (dir.exists(tmp)) {
|
const QDir::Filters filters = QDir::AllEntries | QDir::System | QDir::Hidden | QDir::NoDotAndDotDot;
|
||||||
QStringList list = dir.entryList(QDir::AllEntries | QDir::System | QDir::Hidden | QDir::NoDotAndDotDot);
|
const QFileInfoList list = dir.entryInfoList(filters);
|
||||||
for (int i = 0; i < list.count(); ++i) {
|
for (const QFileInfo &fi : list) {
|
||||||
QFileInfo fi(dir.path() + '/' + list.at(i));
|
if (fi.isDir()) {
|
||||||
if (fi.exists() && fi.isFile()) {
|
QVERIFY(dir.rmdir(fi.fileName()));
|
||||||
QFile p(fi.absoluteFilePath());
|
} else {
|
||||||
p.setPermissions(QFile::ReadUser | QFile::ReadOwner | QFile::ExeOwner | QFile::ExeUser | QFile::WriteUser | QFile::WriteOwner | QFile::WriteOther);
|
QFile dead(fi.absoluteFilePath());
|
||||||
QFile dead(dir.path() + '/' + list.at(i));
|
dead.setPermissions(QFile::ReadUser | QFile::ReadOwner | QFile::ExeOwner | QFile::ExeUser | QFile::WriteUser | QFile::WriteOwner | QFile::WriteOther);
|
||||||
dead.remove();
|
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);
|
QVERIFY(dir.entryInfoList(filters).isEmpty());
|
||||||
QCOMPARE(list.count(), 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +199,7 @@ void tst_QFileSystemModel::rootPath()
|
|||||||
{
|
{
|
||||||
QCOMPARE(model->rootPath(), QString(QDir().path()));
|
QCOMPARE(model->rootPath(), QString(QDir().path()));
|
||||||
|
|
||||||
QSignalSpy rootChanged(model, SIGNAL(rootPathChanged(QString)));
|
QSignalSpy rootChanged(model, &QFileSystemModel::rootPathChanged);
|
||||||
QModelIndex root = model->setRootPath(model->rootPath());
|
QModelIndex root = model->setRootPath(model->rootPath());
|
||||||
root = model->setRootPath("this directory shouldn't exist");
|
root = model->setRootPath("this directory shouldn't exist");
|
||||||
QCOMPARE(rootChanged.count(), 0);
|
QCOMPARE(rootChanged.count(), 0);
|
||||||
@ -263,19 +265,21 @@ void tst_QFileSystemModel::readOnly()
|
|||||||
class CustomFileIconProvider : public QFileIconProvider
|
class CustomFileIconProvider : public QFileIconProvider
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CustomFileIconProvider() : QFileIconProvider() {
|
CustomFileIconProvider() : QFileIconProvider()
|
||||||
mb = qApp->style()->standardIcon(QStyle::SP_MessageBoxCritical);
|
{
|
||||||
dvd = qApp->style()->standardIcon(QStyle::SP_DriveDVDIcon);
|
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())
|
if (info.isDir())
|
||||||
return mb;
|
return mb;
|
||||||
|
|
||||||
return QFileIconProvider::icon(info);
|
return QFileIconProvider::icon(info);
|
||||||
}
|
}
|
||||||
virtual QIcon icon(IconType type) const
|
QIcon icon(IconType type) const override
|
||||||
{
|
{
|
||||||
if (type == QFileIconProvider::Folder)
|
if (type == QFileIconProvider::Folder)
|
||||||
return dvd;
|
return dvd;
|
||||||
@ -290,68 +294,63 @@ private:
|
|||||||
void tst_QFileSystemModel::iconProvider()
|
void tst_QFileSystemModel::iconProvider()
|
||||||
{
|
{
|
||||||
QVERIFY(model->iconProvider());
|
QVERIFY(model->iconProvider());
|
||||||
QFileIconProvider *p = new QFileIconProvider();
|
QScopedPointer<QFileIconProvider> provider(new QFileIconProvider);
|
||||||
model->setIconProvider(p);
|
model->setIconProvider(provider.data());
|
||||||
QCOMPARE(model->iconProvider(), p);
|
QCOMPARE(model->iconProvider(), provider.data());
|
||||||
model->setIconProvider(0);
|
model->setIconProvider(nullptr);
|
||||||
delete p;
|
provider.reset();
|
||||||
|
|
||||||
QFileSystemModel *myModel = new QFileSystemModel();
|
QScopedPointer<QFileSystemModel> myModel(new QFileSystemModel);
|
||||||
const QStringList documentPaths = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
|
const QStringList documentPaths = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
|
||||||
QVERIFY(!documentPaths.isEmpty());
|
QVERIFY(!documentPaths.isEmpty());
|
||||||
const QString documentPath = documentPaths.front();
|
myModel->setRootPath(documentPaths.constFirst());
|
||||||
myModel->setRootPath(documentPath);
|
|
||||||
//We change the provider, icons must be updated
|
//We change the provider, icons must be updated
|
||||||
CustomFileIconProvider *custom = new CustomFileIconProvider();
|
provider.reset(new CustomFileIconProvider);
|
||||||
myModel->setIconProvider(custom);
|
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);
|
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)
|
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;
|
bool timedOut = false;
|
||||||
TRY_WAIT((model->rowCount(model->index(test_path)) == existingFileCount), &timedOut);
|
TRY_WAIT((model->rowCount(model->index(test_path)) == existingFileCount), &timedOut);
|
||||||
if (timedOut)
|
if (timedOut)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (int i = 0; i < initial_dirs.count(); ++i) {
|
QDir dir(test_path);
|
||||||
QDir dir(test_path);
|
if (!dir.exists()) {
|
||||||
if (!dir.exists()) {
|
qWarning() << "error" << test_path << "doesn't exist";
|
||||||
qWarning() << "error" << test_path << "doesn't exists";
|
return false;
|
||||||
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)));
|
|
||||||
}
|
}
|
||||||
for (int i = 0; i < initial_files.count(); ++i) {
|
for (const auto &initial_dir : initial_dirs) {
|
||||||
QFile file(test_path + '/' + initial_files.at(i));
|
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)) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
if (!file.resize(1024 + file.size())) {
|
if (!file.resize(1024 + file.size())) {
|
||||||
qDebug() << "failed to resize file" << initial_files.at(i);
|
qDebug() << "failed to resize file" << initial_file;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!file.flush()) {
|
if (!file.flush()) {
|
||||||
qDebug() << "failed to flush file" << initial_files.at(i);
|
qDebug() << "failed to flush file" << initial_file;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
if (initial_files.at(i)[0] == '.') {
|
if (initial_file[0] == '.') {
|
||||||
QString hiddenFile = QDir::toNativeSeparators(file.fileName());
|
const QString hiddenFile = QDir::toNativeSeparators(file.fileName());
|
||||||
wchar_t nativeHiddenFile[MAX_PATH];
|
const auto nativeHiddenFile = reinterpret_cast<const wchar_t *>(hiddenFile.utf16());
|
||||||
memset(nativeHiddenFile, 0, sizeof(nativeHiddenFile));
|
|
||||||
hiddenFile.toWCharArray(nativeHiddenFile);
|
|
||||||
#ifndef Q_OS_WINRT
|
#ifndef Q_OS_WINRT
|
||||||
DWORD currentAttributes = ::GetFileAttributes(nativeHiddenFile);
|
DWORD currentAttributes = ::GetFileAttributes(nativeHiddenFile);
|
||||||
#else // !Q_OS_WINRT
|
#else // !Q_OS_WINRT
|
||||||
@ -370,7 +369,7 @@ bool tst_QFileSystemModel::createFiles(const QString &test_path, const QStringLi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#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;
|
return true;
|
||||||
}
|
}
|
||||||
@ -387,7 +386,6 @@ QModelIndex tst_QFileSystemModel::prepareTestModelRoot(const QString &test_path,
|
|||||||
*spy3 = new QSignalSpy(model, &QFileSystemModel::rowsAboutToBeInserted);
|
*spy3 = new QSignalSpy(model, &QFileSystemModel::rowsAboutToBeInserted);
|
||||||
|
|
||||||
QStringList files = { "b", "d", "f", "h", "j", ".a", ".c", ".e", ".g" };
|
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))
|
if (!createFiles(test_path, files))
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
@ -406,7 +404,6 @@ QModelIndex tst_QFileSystemModel::prepareTestModelRoot(const QString &test_path,
|
|||||||
|
|
||||||
void tst_QFileSystemModel::rowCount()
|
void tst_QFileSystemModel::rowCount()
|
||||||
{
|
{
|
||||||
const QString tmp = flatDirTestPath;
|
|
||||||
QSignalSpy *spy2 = nullptr;
|
QSignalSpy *spy2 = nullptr;
|
||||||
QSignalSpy *spy3 = nullptr;
|
QSignalSpy *spy3 = nullptr;
|
||||||
QModelIndex root = prepareTestModelRoot(flatDirTestPath, &spy2, &spy3);
|
QModelIndex root = prepareTestModelRoot(flatDirTestPath, &spy2, &spy3);
|
||||||
@ -419,11 +416,11 @@ void tst_QFileSystemModel::rowCount()
|
|||||||
void tst_QFileSystemModel::rowsInserted_data()
|
void tst_QFileSystemModel::rowsInserted_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<int>("count");
|
QTest::addColumn<int>("count");
|
||||||
QTest::addColumn<int>("ascending");
|
QTest::addColumn<Qt::SortOrder>("ascending");
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
const QByteArray iB = QByteArray::number(i);
|
const QByteArray iB = QByteArray::number(i);
|
||||||
QTest::newRow(("Qt::AscendingOrder " + iB).constData()) << i << (int)Qt::AscendingOrder;
|
QTest::newRow(("Qt::AscendingOrder " + iB).constData()) << i << Qt::AscendingOrder;
|
||||||
QTest::newRow(("Qt::DescendingOrder " + iB).constData()) << i << (int)Qt::DescendingOrder;
|
QTest::newRow(("Qt::DescendingOrder " + iB).constData()) << i << Qt::DescendingOrder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,12 +436,12 @@ void tst_QFileSystemModel::rowsInserted()
|
|||||||
QModelIndex root = prepareTestModelRoot(tmp);
|
QModelIndex root = prepareTestModelRoot(tmp);
|
||||||
QVERIFY(root.isValid());
|
QVERIFY(root.isValid());
|
||||||
|
|
||||||
QFETCH(int, ascending);
|
QFETCH(Qt::SortOrder, ascending);
|
||||||
QFETCH(int, count);
|
QFETCH(int, count);
|
||||||
model->sort(0, (Qt::SortOrder)ascending);
|
model->sort(0, ascending);
|
||||||
|
|
||||||
QSignalSpy spy0(model, SIGNAL(rowsInserted(QModelIndex,int,int)));
|
QSignalSpy spy0(model, &QAbstractItemModel::rowsInserted);
|
||||||
QSignalSpy spy1(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)));
|
QSignalSpy spy1(model, &QAbstractItemModel::rowsAboutToBeInserted);
|
||||||
int oldCount = model->rowCount(root);
|
int oldCount = model->rowCount(root);
|
||||||
QStringList files;
|
QStringList files;
|
||||||
for (int i = 0; i < count; ++i)
|
for (int i = 0; i < count; ++i)
|
||||||
@ -493,15 +490,16 @@ void tst_QFileSystemModel::rowsRemoved()
|
|||||||
QVERIFY(root.isValid());
|
QVERIFY(root.isValid());
|
||||||
|
|
||||||
QFETCH(int, count);
|
QFETCH(int, count);
|
||||||
QFETCH(int, ascending);
|
QFETCH(Qt::SortOrder, ascending);
|
||||||
model->sort(0, (Qt::SortOrder)ascending);
|
model->sort(0, ascending);
|
||||||
|
|
||||||
QSignalSpy spy0(model, SIGNAL(rowsRemoved(QModelIndex,int,int)));
|
QSignalSpy spy0(model, &QAbstractItemModel::rowsRemoved);
|
||||||
QSignalSpy spy1(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)));
|
QSignalSpy spy1(model, &QAbstractItemModel::rowsAboutToBeRemoved);
|
||||||
int oldCount = model->rowCount(root);
|
int oldCount = model->rowCount(root);
|
||||||
for (int i = count - 1; i >= 0; --i) {
|
for (int i = count - 1; i >= 0; --i) {
|
||||||
//qDebug() << "removing" << model->index(i, 0, root).data().toString();
|
const QString fileName = model->index(i, 0, root).data().toString();
|
||||||
QVERIFY(QFile::remove(tmp + '/' + model->index(i, 0, root).data().toString()));
|
qCDebug(lcFileSystemModel) << "removing" << fileName;
|
||||||
|
QVERIFY(QFile::remove(tmp + QLatin1Char('/') + fileName));
|
||||||
}
|
}
|
||||||
for (int i = 0 ; i < 10; ++i) {
|
for (int i = 0 ; i < 10; ++i) {
|
||||||
if (count != 0) {
|
if (count != 0) {
|
||||||
@ -520,18 +518,23 @@ void tst_QFileSystemModel::rowsRemoved()
|
|||||||
lst.append(model->index(i, 0, root).data().toString());
|
lst.append(model->index(i, 0, root).data().toString());
|
||||||
if (model->rowCount(root) == oldCount - count)
|
if (model->rowCount(root) == oldCount - count)
|
||||||
break;
|
break;
|
||||||
qDebug() << "still have:" << lst << QFile::exists(tmp + '/' + QString(".a"));
|
qCDebug(lcFileSystemModel) << "still have:" << lst << QFile::exists(tmp + QLatin1String("/.a"));
|
||||||
QDir tmpLister(tmp);
|
QDir tmpLister(tmp);
|
||||||
qDebug() << tmpLister.entryList();
|
qCDebug(lcFileSystemModel) << tmpLister.entryList();
|
||||||
}
|
}
|
||||||
QTRY_COMPARE(model->rowCount(root), oldCount - count);
|
QTRY_COMPARE(model->rowCount(root), oldCount - count);
|
||||||
|
|
||||||
QVERIFY(QFile::exists(tmp + '/' + QString(".a")));
|
QVERIFY(QFile::exists(tmp + QLatin1String("/.a")));
|
||||||
QVERIFY(QFile::remove(tmp + '/' + QString(".a")));
|
QVERIFY(QFile::remove(tmp + QLatin1String("/.a")));
|
||||||
QVERIFY(QFile::remove(tmp + '/' + QString(".c")));
|
QVERIFY(QFile::remove(tmp + QLatin1String("/.c")));
|
||||||
|
|
||||||
if (count != 0) QVERIFY(spy0.count() >= 1); else QCOMPARE(spy0.count(), 0);
|
if (count != 0) {
|
||||||
if (count != 0) QVERIFY(spy1.count() >= 1); else QCOMPARE(spy1.count(), 0);
|
QVERIFY(spy0.count() >= 1);
|
||||||
|
QVERIFY(spy1.count() >= 1);
|
||||||
|
} else {
|
||||||
|
QCOMPARE(spy0.count(), 0);
|
||||||
|
QCOMPARE(spy1.count(), 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QFileSystemModel::dataChanged_data()
|
void tst_QFileSystemModel::dataChanged_data()
|
||||||
@ -548,10 +551,10 @@ void tst_QFileSystemModel::dataChanged()
|
|||||||
QVERIFY(root.isValid());
|
QVERIFY(root.isValid());
|
||||||
|
|
||||||
QFETCH(int, count);
|
QFETCH(int, count);
|
||||||
QFETCH(int, assending);
|
QFETCH(Qt::SortOrder, ascending);
|
||||||
model->sort(0, (Qt::SortOrder)assending);
|
model->sort(0, ascending);
|
||||||
|
|
||||||
QSignalSpy spy(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)));
|
QSignalSpy spy(model, &QAbstractItemModel::dataChanged);
|
||||||
QStringList files;
|
QStringList files;
|
||||||
for (int i = 0; i < count; ++i)
|
for (int i = 0; i < count; ++i)
|
||||||
files.append(model->index(i, 0, root).data().toString());
|
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>("files");
|
||||||
QTest::addColumn<QStringList>("dirs");
|
QTest::addColumn<QStringList>("dirs");
|
||||||
QTest::addColumn<int>("dirFilters");
|
QTest::addColumn<QDir::Filters>("dirFilters");
|
||||||
QTest::addColumn<QStringList>("nameFilters");
|
QTest::addColumn<QStringList>("nameFilters");
|
||||||
QTest::addColumn<int>("rowCount");
|
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"
|
const QStringList abcList{QLatin1String("a"), QLatin1String("b"), QLatin1String("c")};
|
||||||
<< "Antiguamtp" << "afghanistangdb" << "afghanistanmtd")
|
const QStringList zList{QLatin1String("Z")};
|
||||||
<< QStringList() << (int)(QDir::Files) << QStringList() << 5;
|
|
||||||
|
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()
|
void tst_QFileSystemModel::filters()
|
||||||
@ -603,27 +610,26 @@ void tst_QFileSystemModel::filters()
|
|||||||
QModelIndex root = model->setRootPath(tmp);
|
QModelIndex root = model->setRootPath(tmp);
|
||||||
QFETCH(QStringList, files);
|
QFETCH(QStringList, files);
|
||||||
QFETCH(QStringList, dirs);
|
QFETCH(QStringList, dirs);
|
||||||
QFETCH(int, dirFilters);
|
QFETCH(QDir::Filters, dirFilters);
|
||||||
QFETCH(QStringList, nameFilters);
|
QFETCH(QStringList, nameFilters);
|
||||||
QFETCH(int, rowCount);
|
QFETCH(int, rowCount);
|
||||||
|
|
||||||
if (nameFilters.count() > 0)
|
if (nameFilters.count() > 0)
|
||||||
model->setNameFilters(nameFilters);
|
model->setNameFilters(nameFilters);
|
||||||
model->setNameFilterDisables(false);
|
model->setNameFilterDisables(false);
|
||||||
model->setFilter((QDir::Filters)dirFilters);
|
model->setFilter(dirFilters);
|
||||||
|
|
||||||
QVERIFY(createFiles(tmp, files, 0, dirs));
|
QVERIFY(createFiles(tmp, files, 0, dirs));
|
||||||
QTRY_COMPARE(model->rowCount(root), rowCount);
|
QTRY_COMPARE(model->rowCount(root), rowCount);
|
||||||
|
|
||||||
// Make sure that we do what QDir does
|
// Make sure that we do what QDir does
|
||||||
QDir xFactor(tmp);
|
QDir xFactor(tmp);
|
||||||
QDir::Filters filters = (QDir::Filters)dirFilters;
|
|
||||||
QStringList dirEntries;
|
QStringList dirEntries;
|
||||||
|
|
||||||
if (nameFilters.count() > 0)
|
if (nameFilters.count() > 0)
|
||||||
dirEntries = xFactor.entryList(nameFilters, filters);
|
dirEntries = xFactor.entryList(nameFilters, dirFilters);
|
||||||
else
|
else
|
||||||
dirEntries = xFactor.entryList(filters);
|
dirEntries = xFactor.entryList(dirFilters);
|
||||||
|
|
||||||
QCOMPARE(dirEntries.count(), rowCount);
|
QCOMPARE(dirEntries.count(), rowCount);
|
||||||
|
|
||||||
@ -693,15 +699,17 @@ void tst_QFileSystemModel::setData_data()
|
|||||||
<< QDir::temp().absolutePath() + '/' + "a"
|
<< QDir::temp().absolutePath() + '/' + "a"
|
||||||
<< false;
|
<< false;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const QStringList abcList{QLatin1String("a"), QLatin1String("b"), QLatin1String("c")};
|
||||||
QTest::newRow("in current dir")
|
QTest::newRow("in current dir")
|
||||||
<< QString()
|
<< QString()
|
||||||
<< (QStringList() << "a" << "b" << "c")
|
<< abcList
|
||||||
<< "a"
|
<< "a"
|
||||||
<< "d"
|
<< "d"
|
||||||
<< true;
|
<< true;
|
||||||
QTest::newRow("in subdir")
|
QTest::newRow("in subdir")
|
||||||
<< "s"
|
<< "s"
|
||||||
<< (QStringList() << "a" << "b" << "c")
|
<< abcList
|
||||||
<< "a"
|
<< "a"
|
||||||
<< "d"
|
<< "d"
|
||||||
<< true;
|
<< true;
|
||||||
@ -709,7 +717,7 @@ void tst_QFileSystemModel::setData_data()
|
|||||||
|
|
||||||
void tst_QFileSystemModel::setData()
|
void tst_QFileSystemModel::setData()
|
||||||
{
|
{
|
||||||
QSignalSpy spy(model, SIGNAL(fileRenamed(QString,QString,QString)));
|
QSignalSpy spy(model, &QFileSystemModel::fileRenamed);
|
||||||
QFETCH(QString, subdirName);
|
QFETCH(QString, subdirName);
|
||||||
QFETCH(QStringList, files);
|
QFETCH(QStringList, files);
|
||||||
QFETCH(QString, oldFileName);
|
QFETCH(QString, oldFileName);
|
||||||
@ -786,8 +794,9 @@ void tst_QFileSystemModel::sort()
|
|||||||
{
|
{
|
||||||
QFETCH(bool, fileDialogMode);
|
QFETCH(bool, fileDialogMode);
|
||||||
|
|
||||||
MyFriendFileSystemModel *myModel = new MyFriendFileSystemModel();
|
QScopedPointer<MyFriendFileSystemModel> myModel(new MyFriendFileSystemModel);
|
||||||
QTreeView *tree = new QTreeView();
|
QTreeView tree;
|
||||||
|
tree.setWindowTitle(QTest::currentTestFunction());
|
||||||
|
|
||||||
if (fileDialogMode && EmulationDetector::isRunningArmOnX86())
|
if (fileDialogMode && EmulationDetector::isRunningArmOnX86())
|
||||||
QSKIP("Crashes in QEMU. QTBUG-70572");
|
QSKIP("Crashes in QEMU. QTBUG-70572");
|
||||||
@ -816,24 +825,23 @@ void tst_QFileSystemModel::sort()
|
|||||||
|
|
||||||
myModel->setRootPath("");
|
myModel->setRootPath("");
|
||||||
myModel->setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
|
myModel->setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
|
||||||
tree->setSortingEnabled(true);
|
tree.setSortingEnabled(true);
|
||||||
tree->setModel(myModel);
|
tree.setModel(myModel.data());
|
||||||
tree->show();
|
tree.show();
|
||||||
tree->resize(800, 800);
|
tree.resize(800, 800);
|
||||||
QVERIFY(QTest::qWaitForWindowActive(tree));
|
QVERIFY(QTest::qWaitForWindowActive(&tree));
|
||||||
tree->header()->setSortIndicator(1,Qt::DescendingOrder);
|
tree.header()->setSortIndicator(1, Qt::DescendingOrder);
|
||||||
tree->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
tree.header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
||||||
QStringList dirsToOpen;
|
QStringList dirsToOpen;
|
||||||
do
|
do {
|
||||||
{
|
dirsToOpen << dir.absolutePath();
|
||||||
dirsToOpen<<dir.absolutePath();
|
|
||||||
} while (dir.cdUp());
|
} while (dir.cdUp());
|
||||||
|
|
||||||
for (int i = dirsToOpen.size() -1 ; i > 0 ; --i) {
|
for (int i = dirsToOpen.size() -1 ; i > 0 ; --i) {
|
||||||
QString path = dirsToOpen[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);
|
QModelIndex parent = myModel->index(dirPath, 0);
|
||||||
QList<QString> expectedOrder;
|
QList<QString> expectedOrder;
|
||||||
expectedOrder << tempFile2.fileName() << tempFile.fileName() << dirPath + QChar('/') + ".." << dirPath + QChar('/') + ".";
|
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));
|
QTRY_COMPARE(dirPath + QChar('/') + myModel->index(i, 1, parent).data(QFileSystemModel::FileNameRole).toString(), expectedOrder.at(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete tree;
|
|
||||||
delete myModel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QFileSystemModel::mkdir()
|
void tst_QFileSystemModel::mkdir()
|
||||||
@ -1013,10 +1018,10 @@ void tst_QFileSystemModel::dirsBeforeFiles()
|
|||||||
|
|
||||||
const int itemCount = 3;
|
const int itemCount = 3;
|
||||||
for (int i = 0; i < itemCount; ++i) {
|
for (int i = 0; i < itemCount; ++i) {
|
||||||
QLatin1Char c('a' + i);
|
QLatin1Char c('a' + char(i));
|
||||||
dir.mkdir(c + QLatin1String("-dir"));
|
QVERIFY(dir.mkdir(c + QLatin1String("-dir")));
|
||||||
QFile file(flatDirTestPath + QLatin1Char('/') + c + QLatin1String("-file"));
|
QFile file(flatDirTestPath + QLatin1Char('/') + c + QLatin1String("-file"));
|
||||||
file.open(QIODevice::ReadWrite);
|
QVERIFY(file.open(QIODevice::ReadWrite));
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1073,7 +1078,7 @@ static inline QByteArray permissionRowName(bool readOnly, int permission)
|
|||||||
|
|
||||||
void tst_QFileSystemModel::permissions_data()
|
void tst_QFileSystemModel::permissions_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<int>("permissions");
|
QTest::addColumn<QFileDevice::Permissions>("permissions");
|
||||||
QTest::addColumn<bool>("readOnly");
|
QTest::addColumn<bool>("readOnly");
|
||||||
|
|
||||||
static const int permissions[] = {
|
static const int permissions[] = {
|
||||||
@ -1081,22 +1086,22 @@ void tst_QFileSystemModel::permissions_data()
|
|||||||
QFile::ReadOwner,
|
QFile::ReadOwner,
|
||||||
QFile::WriteOwner|QFile::ReadOwner,
|
QFile::WriteOwner|QFile::ReadOwner,
|
||||||
};
|
};
|
||||||
for (size_t i = 0; i < sizeof permissions / sizeof *permissions; ++i) {
|
for (int permission : permissions) {
|
||||||
QTest::newRow(permissionRowName(false, permissions[i]).constData()) << permissions[i] << false;
|
QTest::newRow(permissionRowName(false, permission).constData()) << QFileDevice::Permissions(permission) << false;
|
||||||
QTest::newRow(permissionRowName(true, permissions[i]).constData()) << permissions[i] << true;
|
QTest::newRow(permissionRowName(true, permission).constData()) << QFileDevice::Permissions(permission) << true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QFileSystemModel::permissions() // checks QTBUG-20503
|
void tst_QFileSystemModel::permissions() // checks QTBUG-20503
|
||||||
{
|
{
|
||||||
QFETCH(int, permissions);
|
QFETCH(QFileDevice::Permissions, permissions);
|
||||||
QFETCH(bool, readOnly);
|
QFETCH(bool, readOnly);
|
||||||
|
|
||||||
const QString tmp = flatDirTestPath;
|
const QString tmp = flatDirTestPath;
|
||||||
const QString file = tmp + QLatin1String("/f");
|
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);
|
const QModelIndex root = model->setRootPath(tmp);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user