summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/itemviews
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-06-03 11:26:24 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-06-04 19:11:19 +0200
commit94dcb5454f0f8f144568dff7a9dd1316046ee197 (patch)
tree7da0e7c6708999abc9b4cd88ee7e83aa996b18e2 /tests/auto/widgets/itemviews
parent5781ef2013160ba3810ad7df399aa79be085cd6c (diff)
Remove the deprecated QDirModel
QFileSystemModel is the documented replacement. It uses threads to populate the model, which QDirModel doesn't. Change-Id: I7818ecd8f849eb566ac176612f382e17a0471c47 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'tests/auto/widgets/itemviews')
-rw-r--r--tests/auto/widgets/itemviews/CMakeLists.txt1
-rw-r--r--tests/auto/widgets/itemviews/itemviews.pro1
-rw-r--r--tests/auto/widgets/itemviews/qdirmodel/.gitignore1
-rw-r--r--tests/auto/widgets/itemviews/qdirmodel/CMakeLists.txt49
-rw-r--r--tests/auto/widgets/itemviews/qdirmodel/dirtest/test1/dummy1
-rw-r--r--tests/auto/widgets/itemviews/qdirmodel/dirtest/test1/test0
-rw-r--r--tests/auto/widgets/itemviews/qdirmodel/qdirmodel.pro18
-rw-r--r--tests/auto/widgets/itemviews/qdirmodel/test/file01.tst0
-rw-r--r--tests/auto/widgets/itemviews/qdirmodel/test/file02.tst0
-rw-r--r--tests/auto/widgets/itemviews/qdirmodel/test/file03.tst0
-rw-r--r--tests/auto/widgets/itemviews/qdirmodel/test/file04.tst0
-rw-r--r--tests/auto/widgets/itemviews/qdirmodel/testdata.qrc11
-rw-r--r--tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp722
13 files changed, 0 insertions, 804 deletions
diff --git a/tests/auto/widgets/itemviews/CMakeLists.txt b/tests/auto/widgets/itemviews/CMakeLists.txt
index e7dc78b18c..a3737b2abc 100644
--- a/tests/auto/widgets/itemviews/CMakeLists.txt
+++ b/tests/auto/widgets/itemviews/CMakeLists.txt
@@ -2,7 +2,6 @@
add_subdirectory(qabstractitemview)
add_subdirectory(qdatawidgetmapper)
-add_subdirectory(qdirmodel)
add_subdirectory(qfileiconprovider)
add_subdirectory(qheaderview)
add_subdirectory(qitemdelegate)
diff --git a/tests/auto/widgets/itemviews/itemviews.pro b/tests/auto/widgets/itemviews/itemviews.pro
index f2ee0e9124..b9477b7a7e 100644
--- a/tests/auto/widgets/itemviews/itemviews.pro
+++ b/tests/auto/widgets/itemviews/itemviews.pro
@@ -3,7 +3,6 @@ SUBDIRS=\
qabstractitemview \
qcolumnview \
qdatawidgetmapper \
- qdirmodel \
qfileiconprovider \
qheaderview \
qitemdelegate \
diff --git a/tests/auto/widgets/itemviews/qdirmodel/.gitignore b/tests/auto/widgets/itemviews/qdirmodel/.gitignore
deleted file mode 100644
index 641c99880f..0000000000
--- a/tests/auto/widgets/itemviews/qdirmodel/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-tst_qdirmodel
diff --git a/tests/auto/widgets/itemviews/qdirmodel/CMakeLists.txt b/tests/auto/widgets/itemviews/qdirmodel/CMakeLists.txt
deleted file mode 100644
index d47cc3457d..0000000000
--- a/tests/auto/widgets/itemviews/qdirmodel/CMakeLists.txt
+++ /dev/null
@@ -1,49 +0,0 @@
-# Generated from qdirmodel.pro.
-
-#####################################################################
-## tst_qdirmodel Test:
-#####################################################################
-
-add_qt_test(tst_qdirmodel
- SOURCES
- ../../../../shared/emulationdetector.h
- tst_qdirmodel.cpp
- INCLUDE_DIRECTORIES
- ../../../../shared
- PUBLIC_LIBRARIES
- Qt::Gui
- Qt::Widgets
-)
-
-## Scopes:
-#####################################################################
-
-extend_target(tst_qdirmodel CONDITION ANDROID
- DEFINES
- SRCDIR=\\\"./\\\"
-)
-
-extend_target(tst_qdirmodel CONDITION NOT ANDROID
- DEFINES
- SRCDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/\\\"
-)
-
-if(ANDROID AND NOT ANDROID_EMBEDDED)
- # Resources:
- set(testdata_resource_files
- "dirtest/test1/dummy"
- "dirtest/test1/test"
- "test/file01.tst"
- "test/file02.tst"
- "test/file03.tst"
- "test/file04.tst"
- "tst_qdirmodel.cpp"
- )
-
- add_qt_resource(tst_qdirmodel "testdata"
- PREFIX
- "/android_testdata"
- FILES
- ${testdata_resource_files}
- )
-endif()
diff --git a/tests/auto/widgets/itemviews/qdirmodel/dirtest/test1/dummy b/tests/auto/widgets/itemviews/qdirmodel/dirtest/test1/dummy
deleted file mode 100644
index 4d6a3b44f4..0000000000
--- a/tests/auto/widgets/itemviews/qdirmodel/dirtest/test1/dummy
+++ /dev/null
@@ -1 +0,0 @@
-ECHO is on.
diff --git a/tests/auto/widgets/itemviews/qdirmodel/dirtest/test1/test b/tests/auto/widgets/itemviews/qdirmodel/dirtest/test1/test
deleted file mode 100644
index e69de29bb2..0000000000
--- a/tests/auto/widgets/itemviews/qdirmodel/dirtest/test1/test
+++ /dev/null
diff --git a/tests/auto/widgets/itemviews/qdirmodel/qdirmodel.pro b/tests/auto/widgets/itemviews/qdirmodel/qdirmodel.pro
deleted file mode 100644
index 0429315d95..0000000000
--- a/tests/auto/widgets/itemviews/qdirmodel/qdirmodel.pro
+++ /dev/null
@@ -1,18 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qdirmodel
-QT += widgets testlib
-SOURCES += tst_qdirmodel.cpp
-
-INCLUDEPATH += ../../../../shared/
-HEADERS += ../../../../shared/emulationdetector.h
-
-android {
- DEFINES += SRCDIR=\\\"./\\\"
-} else {
- DEFINES += SRCDIR=\\\"$$PWD/\\\"
-}
-
-android:!android-embedded {
- RESOURCES += \
- testdata.qrc
-}
diff --git a/tests/auto/widgets/itemviews/qdirmodel/test/file01.tst b/tests/auto/widgets/itemviews/qdirmodel/test/file01.tst
deleted file mode 100644
index e69de29bb2..0000000000
--- a/tests/auto/widgets/itemviews/qdirmodel/test/file01.tst
+++ /dev/null
diff --git a/tests/auto/widgets/itemviews/qdirmodel/test/file02.tst b/tests/auto/widgets/itemviews/qdirmodel/test/file02.tst
deleted file mode 100644
index e69de29bb2..0000000000
--- a/tests/auto/widgets/itemviews/qdirmodel/test/file02.tst
+++ /dev/null
diff --git a/tests/auto/widgets/itemviews/qdirmodel/test/file03.tst b/tests/auto/widgets/itemviews/qdirmodel/test/file03.tst
deleted file mode 100644
index e69de29bb2..0000000000
--- a/tests/auto/widgets/itemviews/qdirmodel/test/file03.tst
+++ /dev/null
diff --git a/tests/auto/widgets/itemviews/qdirmodel/test/file04.tst b/tests/auto/widgets/itemviews/qdirmodel/test/file04.tst
deleted file mode 100644
index e69de29bb2..0000000000
--- a/tests/auto/widgets/itemviews/qdirmodel/test/file04.tst
+++ /dev/null
diff --git a/tests/auto/widgets/itemviews/qdirmodel/testdata.qrc b/tests/auto/widgets/itemviews/qdirmodel/testdata.qrc
deleted file mode 100644
index e0ef4203fe..0000000000
--- a/tests/auto/widgets/itemviews/qdirmodel/testdata.qrc
+++ /dev/null
@@ -1,11 +0,0 @@
-<RCC>
- <qresource prefix="/android_testdata">
- <file>dirtest/test1/dummy</file>
- <file>dirtest/test1/test</file>
- <file>test/file01.tst</file>
- <file>test/file02.tst</file>
- <file>test/file03.tst</file>
- <file>test/file04.tst</file>
- <file>tst_qdirmodel.cpp</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp b/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp
deleted file mode 100644
index 925c578300..0000000000
--- a/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp
+++ /dev/null
@@ -1,722 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
-#include <qdirmodel.h>
-#include <qapplication.h>
-#include <qtreeview.h>
-#include <qdir.h>
-#include <qdebug.h>
-#include "emulationdetector.h"
-
-QT_WARNING_DISABLE_DEPRECATED
-
-class tst_QDirModel : public QObject
-{
- Q_OBJECT
-public slots:
- void initTestCase();
- void cleanupTestCase();
- void init();
-private slots:
- void getSetCheck();
- void unreadable();
- /*
- void construct();
- void rowCount();
- void columnCount();
- void t_data();
- void setData();
- void hasChildren();
- void isEditable();
- void isDragEnabled();
- void isDropEnabled();
- void sort();
- */
- bool rowsAboutToBeRemoved_init(const QString &test_path, const QStringList &initial_files);
- bool rowsAboutToBeRemoved_cleanup(const QString &test_path);
- void rowsAboutToBeRemoved_data();
- void rowsAboutToBeRemoved();
-
- void mkdir_data();
- void mkdir();
-
- void rmdir_data();
- void rmdir();
-
- void filePath();
-
- void hidden();
-
- void fileName();
- void fileName_data();
- void task196768_sorting();
- void filter();
-
- void task244669_remove();
-
- void roleNames_data();
- void roleNames();
-};
-
-// Testing get/set functions
-void tst_QDirModel::getSetCheck()
-{
- QDirModel obj1;
- // QFileIconProvider * QDirModel::iconProvider()
- // void QDirModel::setIconProvider(QFileIconProvider *)
- QFileIconProvider *var1 = new QFileIconProvider;
- obj1.setIconProvider(var1);
- QCOMPARE(var1, obj1.iconProvider());
- obj1.setIconProvider((QFileIconProvider *)0);
- QCOMPARE((QFileIconProvider *)0, obj1.iconProvider());
- delete var1;
-
- // bool QDirModel::resolveSymlinks()
- // void QDirModel::setResolveSymlinks(bool)
- obj1.setResolveSymlinks(false);
- QCOMPARE(false, obj1.resolveSymlinks());
- obj1.setResolveSymlinks(true);
- QCOMPARE(true, obj1.resolveSymlinks());
-
- // bool QDirModel::lazyChildCount()
- // void QDirModel::setLazyChildCount(bool)
- obj1.setLazyChildCount(false);
- QCOMPARE(false, obj1.lazyChildCount());
- obj1.setLazyChildCount(true);
- QCOMPARE(true, obj1.lazyChildCount());
-}
-
-void tst_QDirModel::initTestCase()
-{
-#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
- QString dataPath = SRCDIR;
- QString resourceSourcePath = QStringLiteral(":/android_testdata");
- QDirIterator it(resourceSourcePath, QDirIterator::Subdirectories);
- while (it.hasNext()) {
- it.next();
-
- QFileInfo fileInfo = it.fileInfo();
- if (!fileInfo.isDir()) {
- QString destination = dataPath + QLatin1Char('/') + fileInfo.filePath().mid(resourceSourcePath.length());
- QFileInfo destinationFileInfo(destination);
- if (!destinationFileInfo.exists()) {
- QDir().mkpath(destinationFileInfo.path());
- if (!QFile::copy(fileInfo.filePath(), destination))
- qWarning("Failed to copy %s", qPrintable(fileInfo.filePath()));
- }
- }
- }
-#endif
-}
-
-void tst_QDirModel::cleanupTestCase()
-{
- QDir current;
- current.rmdir(".qtest_hidden");
-}
-
-void tst_QDirModel::init()
-{
-#ifdef Q_OS_UNIX
- if (QTest::currentTestFunction() == QLatin1String( "unreadable" )) {
- // Make sure that the unreadable file created by the unreadable()
- // test function doesn't already exist.
- QFile unreadableFile(QDir::currentPath() + "qtest_unreadable");
- if (unreadableFile.exists()) {
- unreadableFile.remove();
- QVERIFY(!unreadableFile.exists());
- }
- }
-#endif
-}
-
-/*
- tests
-*/
-/*
-void tst_QDirModel::construct()
-{
- QDirModel model;
- QModelIndex index = model.index(QDir::currentPath() + "/test");
- index = model.index(2, 0, index);
- QVERIFY(index.isValid());
- QFileInfo info(QDir::currentPath() + "/test/file03.tst");
- QCOMPARE(model.filePath(index), info.absoluteFilePath());
-}
-
-void tst_QDirModel::rowCount()
-{
- QDirModel model;
- QModelIndex index = model.index(QDir::currentPath() + "/test");
- QVERIFY(index.isValid());
- QCOMPARE(model.rowCount(index), 4);
-}
-
-void tst_QDirModel::columnCount()
-{
- QDirModel model;
- QModelIndex index = model.index(QDir::currentPath() + "/test");
- QVERIFY(index.isValid());
- QCOMPARE(model.columnCount(index), 4);
-}
-
-void tst_QDirModel::t_data()
-{
- QDirModel model;
- QModelIndex index = model.index(QDir::currentPath() + "/test");
- QVERIFY(index.isValid());
- QCOMPARE(model.rowCount(index), 4);
-
- index = model.index(2, 0, index);
- QVERIFY(index.isValid());
- QCOMPARE(model.data(index).toString(), QString::fromLatin1("file03.tst"));
- QCOMPARE(model.rowCount(index), 0);
-}
-
-void tst_QDirModel::setData()
-{
- QDirModel model;
- QModelIndex index = model.index(QDir::currentPath() + "/test");
- QVERIFY(index.isValid());
-
- index = model.index(2, 0, index);
- QVERIFY(index.isValid());
- QVERIFY(!model.setData(index, "file0X.tst", Qt::EditRole));
-}
-
-void tst_QDirModel::hasChildren()
-{
- QDirModel model;
- QModelIndex index = model.index(QDir::currentPath() + "/test");
- QVERIFY(index.isValid());
-
- index = model.index(2, 0, index);
- QVERIFY(index.isValid());
- QVERIFY(!model.hasChildren(index));
-}
-
-void tst_QDirModel::isEditable()
-{
- QDirModel model;
- QModelIndex index = model.index(QDir::currentPath() + "/test");
- QVERIFY(index.isValid());
-
- index = model.index(2, 0, index);
- QVERIFY(index.isValid());
- QVERIFY(!(model.flags(index) & Qt::ItemIsEditable));
-}
-
-void tst_QDirModel::isDragEnabled()
-{
- QDirModel model;
- QModelIndex index = model.index(QDir::currentPath() + "/test");
- QVERIFY(index.isValid());
-
- index = model.index(2, 0, index);
- QVERIFY(index.isValid());
- QVERIFY(model.flags(index) & Qt::ItemIsDragEnabled);
-}
-
-void tst_QDirModel::isDropEnabled()
-{
- QDirModel model;
- QModelIndex index = model.index(QDir::currentPath() + "/test");
- QVERIFY(index.isValid());
-
- index = model.index(2, 0, index);
- QVERIFY(!(model.flags(index) & Qt::ItemIsDropEnabled));
-}
-
-void tst_QDirModel::sort()
-{
- QDirModel model;
- QModelIndex parent = model.index(QDir::currentPath() + "/test");
- QVERIFY(parent.isValid());
-
- QModelIndex index = model.index(0, 0, parent);
- QCOMPARE(model.data(index).toString(), QString::fromLatin1("file01.tst"));
-
- index = model.index(3, 0, parent);
- QCOMPARE(model.data(index).toString(), QString::fromLatin1("file04.tst"));
-
- model.sort(0, Qt::DescendingOrder);
- parent = model.index(QDir::currentPath() + "/test");
-
- index = model.index(0, 0, parent);
- QCOMPARE(model.data(index).toString(), QString::fromLatin1("file04.tst"));
-
- index = model.index(3, 0, parent);
- QCOMPARE(model.data(index).toString(), QString::fromLatin1("file01.tst"));
-}
-*/
-
-void tst_QDirModel::mkdir_data()
-{
- QTest::addColumn<QString>("dirName"); // the directory to be made under <currentpath>/dirtest
- QTest::addColumn<bool>("mkdirSuccess");
- QTest::addColumn<int>("rowCount");
-
- QTest::newRow("okDirName") << QString("test2") << true << 2;
- QTest::newRow("existingDirName") << QString("test1") << false << 1;
- QTest::newRow("nameWithSpace") << QString("ab cd") << true << 2;
- QTest::newRow("emptyDirName") << QString("") << false << 1;
- QTest::newRow("nullDirName") << QString() << false << 1;
-
-/*
- QTest::newRow("recursiveDirName") << QString("test2/test3") << false << false;
- QTest::newRow("singleDotDirName") << QString("./test3") << true << true;
- QTest::newRow("outOfTreeDirName") << QString("../test4") << false << false;
- QTest::newRow("insideTreeDirName") << QString("../dirtest/test4") << true << true;
- QTest::newRow("insideTreeDirName2") << QString("./././././../dirtest/./../dirtest/test4") << true << true;
- QTest::newRow("absoluteDirName") << QString(QDir::currentPath() + "/dirtest/test5") << true << true;
- QTest::newRow("outOfTreeDirName") << QString(QDir::currentPath() + "/test5") << false << false;
-
- // Directory names only illegal on Windows
-#ifdef Q_OS_WIN
- QTest::newRow("illegalDirName") << QString("*") << false << false;
- QTest::newRow("illegalDirName2") << QString("|") << false << false;
- QTest::newRow("onlySpace") << QString(" ") << false << false;
-#endif
- */
-}
-
-void tst_QDirModel::mkdir()
-{
- QFETCH(QString, dirName);
- QFETCH(bool, mkdirSuccess);
- QFETCH(int, rowCount);
-
- QDirModel model;
- model.setReadOnly(false);
-
- QModelIndex parent = model.index(SRCDIR "dirtest");
-#ifdef Q_OS_WINRT
- QEXPECT_FAIL("", "Sandboxed applications cannot access SRCDIR - QTBUG-68297", Abort);
-#endif
- QVERIFY(parent.isValid());
- QCOMPARE(model.rowCount(parent), 1); // start out with only 'test1' - in's in the depot
-
- QModelIndex index = model.mkdir(parent, dirName);
- bool success = index.isValid();
- int rows = model.rowCount(parent);
-
- if (success && !model.rmdir(index))
- QVERIFY(QDir(SRCDIR "dirtests").rmdir(dirName));
-
- QCOMPARE(rows, rowCount);
- QCOMPARE(success, mkdirSuccess);
-}
-
-void tst_QDirModel::rmdir_data()
-{
- QTest::addColumn<QString>("dirName"); // <currentpath>/dirtest/dirname
- QTest::addColumn<bool>("rmdirSuccess");
- QTest::addColumn<int>("rowCount");
-
- QTest::newRow("okDirName") << QString("test2") << true << 2;
- QTest::newRow("existingDirName") << QString("test1") << false << 1;
- QTest::newRow("nameWithSpace") << QString("ab cd") << true << 2;
- QTest::newRow("emptyDirName") << QString("") << false << 1;
- QTest::newRow("nullDirName") << QString() << false << 1;
-}
-
-void tst_QDirModel::rmdir()
-{
- QFETCH(QString, dirName);
- QFETCH(bool, rmdirSuccess);
- QFETCH(int, rowCount);
-
- QDirModel model;
- model.setReadOnly(false);
-
- QModelIndex parent = model.index(SRCDIR "/dirtest");
-#ifdef Q_OS_WINRT
- QEXPECT_FAIL("", "Sandboxed applications cannot access SRCDIR - QTBUG-68297", Abort);
-#endif
- QVERIFY(parent.isValid());
- QCOMPARE(model.rowCount(parent), 1); // start out with only 'test1' - in's in the depot
-
- QModelIndex index;
- if (rmdirSuccess) {
- index = model.mkdir(parent, dirName);
- QVERIFY(index.isValid());
- }
-
- int rows = model.rowCount(parent);
- bool success = model.rmdir(index);
-
- if (!success) { // cleanup
- QDir dirtests(SRCDIR "/dirtests/");
- dirtests.rmdir(dirName);
- }
-
- QCOMPARE(rows, rowCount);
- QCOMPARE(success, rmdirSuccess);
-}
-
-void tst_QDirModel::rowsAboutToBeRemoved_data()
-{
- QTest::addColumn<QString>("test_path");
- QTest::addColumn<QStringList>("initial_files");
- QTest::addColumn<int>("remove_row");
- QTest::addColumn<QStringList>("remove_files");
- QTest::addColumn<QStringList>("expected_files");
-
- QString test_path = "test2";
- QStringList initial_files = (QStringList()
- << "file1.tst"
- << "file2.tst"
- << "file3.tst"
- << "file4.tst");
-
- QTest::newRow("removeFirstRow")
- << test_path
- << initial_files
- << 0
- << (QStringList() << "file1.tst")
- << (QStringList() << "file2.tst" << "file3.tst" << "file4.tst");
-
- QTest::newRow("removeMiddle")
- << test_path
- << initial_files
- << 1
- << (QStringList() << "file2.tst")
- << (QStringList() << "file1.tst" << "file3.tst" << "file4.tst");
-
- QTest::newRow("removeLastRow")
- << test_path
- << initial_files
- << 3
- << (QStringList() << "file4.tst")
- << (QStringList() << "file1.tst" << "file2.tst" << "file3.tst");
-
-}
-
-bool tst_QDirModel::rowsAboutToBeRemoved_init(const QString &test_path, const QStringList &initial_files)
-{
- QString path = QDir::currentPath() + QLatin1Char('/') + test_path;
- if (!QDir::current().mkdir(test_path) && false) { // FIXME
- qDebug() << "failed to create dir" << path;
- return false;
- }
-
- for (int i = 0; i < initial_files.count(); ++i) {
- QFile file(path + QLatin1Char('/') + initial_files.at(i));
- if (!file.open(QIODevice::WriteOnly)) {
- qDebug() << "failed to open file" << initial_files.at(i);
- return false;
- }
- if (!file.resize(1024)) {
- qDebug() << "failed to resize file" << initial_files.at(i);
- return false;
- }
- if (!file.flush()) {
- qDebug() << "failed to flush file" << initial_files.at(i);
- return false;
- }
- }
-
- return true;
-}
-
-bool tst_QDirModel::rowsAboutToBeRemoved_cleanup(const QString &test_path)
-{
- QString path = QDir::currentPath() + QLatin1Char('/') + test_path;
- QDir dir(path, "*", QDir::SortFlags(QDir::Name|QDir::IgnoreCase), QDir::Files);
- QStringList files = dir.entryList();
-
- for (int i = 0; i < files.count(); ++i) {
- if (!dir.remove(files.at(i))) {
- qDebug() << "failed to remove file" << files.at(i);
- return false;
- }
- }
-
- if (!QDir::current().rmdir(test_path) && false) { // FIXME
- qDebug() << "failed to remove dir" << test_path;
- return false;
- }
-
- return true;
-}
-
-void tst_QDirModel::rowsAboutToBeRemoved()
-{
-#ifdef Q_OS_WINRT
- QSKIP("Test fails on WinRT - QTBUG-68297");
-#endif
- QFETCH(QString, test_path);
- QFETCH(QStringList, initial_files);
- QFETCH(int, remove_row);
- QFETCH(QStringList, remove_files);
- QFETCH(QStringList, expected_files);
-
- rowsAboutToBeRemoved_cleanup(test_path); // clean up first
- QVERIFY(rowsAboutToBeRemoved_init(test_path, initial_files));
-
- QDirModel model;
- model.setReadOnly(false);
-
-
- // NOTE: QDirModel will call refresh() when a file is removed. refresh() will reread the entire directory,
- // and emit layoutAboutToBeChanged and layoutChange. So, instead of checking for
- // rowsAboutToBeRemoved/rowsRemoved we check for layoutAboutToBeChanged/layoutChanged
- QSignalSpy spy(&model, SIGNAL(layoutAboutToBeChanged()));
-
- QModelIndex parent = model.index(test_path);
- QVERIFY(parent.isValid());
-
- // remove the file
- {
- QModelIndex index = model.index(remove_row, 0, parent);
- QVERIFY(index.isValid());
- QVERIFY(model.remove(index));
- }
-
- QCOMPARE(spy.count(), 1);
-
- // Compare the result
- for (int row = 0; row < expected_files.count(); ++row) {
- QModelIndex index = model.index(row, 0, parent);
- QString str = index.data().toString();
- QCOMPARE(str, expected_files.at(row));
- }
-
- QVERIFY(rowsAboutToBeRemoved_cleanup(test_path));
-}
-
-void tst_QDirModel::hidden()
-{
-#ifndef Q_OS_UNIX
- QSKIP("Test not implemented on non-Unixes");
-#else
- QDir current;
- current.mkdir(".qtest_hidden");
-
- QDirModel model;
- QModelIndex index = model.index(QDir::currentPath() + "/.qtest_hidden");
- //QVERIFY(!index.isValid()); // hidden items are not listed, but if you specify a valid path, it will give a valid index
-
- current.mkdir(".qtest_hidden/qtest_visible");
- QModelIndex index2 = model.index(QDir::currentPath() + "/.qtest_hidden/qtest_visible");
- QVERIFY(index2.isValid());
-
- QDirModel model2;
- model2.setFilter(model2.filter() | QDir::Hidden);
- index = model2.index(QDir::currentPath() + "/.qtest_hidden");
- QVERIFY(index.isValid());
-#endif
-}
-
-void tst_QDirModel::fileName_data()
-{
- QTest::addColumn<QString>("path");
- QTest::addColumn<QString>("result");
-
- QTest::newRow("invalid") << "" << "";
- //QTest::newRow("root") << "/" << "/";
- //QTest::newRow("home") << "/home" << "home";
- // TODO add symlink test too
-}
-
-void tst_QDirModel::fileName()
-{
- QDirModel model;
-
- QFETCH(QString, path);
- QFETCH(QString, result);
- QCOMPARE(model.fileName(model.index(path)), result);
-}
-
-void tst_QDirModel::unreadable()
-{
-#ifndef Q_OS_UNIX
- QSKIP("Test not implemented on non-Unixes");
-#else
- // Create an empty file which has no read permissions (file will be removed by cleanup()).
- QFile unreadableFile(QDir::currentPath() + "qtest_unreadable");
- QVERIFY2(unreadableFile.open(QIODevice::WriteOnly | QIODevice::Text), qPrintable(unreadableFile.errorString()));
- unreadableFile.close();
- QVERIFY(unreadableFile.exists());
- QVERIFY2(unreadableFile.setPermissions(QFile::WriteOwner), qPrintable(unreadableFile.errorString()));
-
- // Check that we can't make a valid model index from an unreadable file.
- QDirModel model;
- QModelIndex index = model.index(QDir::currentPath() + "/qtest_unreadable");
- QVERIFY(!index.isValid());
-
- // Check that unreadable files are not treated like hidden files.
- QDirModel model2;
- model2.setFilter(model2.filter() | QDir::Hidden);
- index = model2.index(QDir::currentPath() + "/qtest_unreadable");
- QVERIFY(!index.isValid());
-#endif
-}
-
-void tst_QDirModel::filePath()
-{
- QFile::remove(SRCDIR "test.lnk");
-#ifdef Q_OS_WINRT
- QEXPECT_FAIL("", "Sandboxed applications cannot access SRCDIR - QTBUG-68297", Abort);
-#endif
- QVERIFY(QFile(SRCDIR "tst_qdirmodel.cpp").link(SRCDIR "test.lnk"));
- QDirModel model;
- model.setResolveSymlinks(false);
- QModelIndex index = model.index(SRCDIR "test.lnk");
- QVERIFY(index.isValid());
-#if !defined(Q_OS_ANDROID)
- QString path = SRCDIR;
-#else
- QString path = QFileInfo(SRCDIR).absoluteFilePath();
- if (!path.endsWith(QLatin1Char('/')))
- path += QLatin1Char('/');
-#endif
- QCOMPARE(model.filePath(index), path + QString( "test.lnk"));
- model.setResolveSymlinks(true);
- QCOMPARE(model.filePath(index), path + QString( "tst_qdirmodel.cpp"));
- QFile::remove(SRCDIR "test.lnk");
-}
-
-void tst_QDirModel::task196768_sorting()
-{
- //this task showed that the persistent model indexes got corrupted when sorting
- QString path = SRCDIR;
-
- QDirModel model;
-
- /* QDirModel has a bug if we show the content of the subdirectory inside a hidden directory
- and we don't add QDir::Hidden. But as QDirModel is deprecated, we decided not to fix it. */
- model.setFilter(QDir::AllEntries | QDir::Hidden | QDir::AllDirs);
-
- QTreeView view;
- QPersistentModelIndex index = model.index(path);
- view.setModel(&model);
- QModelIndex index2 = model.index(path);
- QCOMPARE(index.data(), index2.data());
- view.setRootIndex(index);
- index2 = model.index(path);
- QCOMPARE(index.data(), index2.data());
- view.setCurrentIndex(index);
- index2 = model.index(path);
- QCOMPARE(index.data(), index2.data());
- view.setSortingEnabled(true);
- index2 = model.index(path);
-
-#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
- QEXPECT_FAIL("", "QTBUG-43818", Continue);
-#else
- if (EmulationDetector::isRunningArmOnX86())
- QEXPECT_FAIL("", "QTBUG-43818", Continue);
-#endif
-
- QCOMPARE(index.data(), index2.data());
-}
-
-void tst_QDirModel::filter()
-{
- QDirModel model;
- model.setNameFilters(QStringList() << "*.nada");
- QModelIndex index = model.index(SRCDIR "test");
-#ifdef Q_OS_WINRT
- QEXPECT_FAIL("", "Sandboxed applications cannot access SRCDIR - QTBUG-68297", Abort);
-#endif
- QCOMPARE(model.rowCount(index), 0);
- QModelIndex index2 = model.index(SRCDIR "test/file01.tst");
- QVERIFY(!index2.isValid());
- QCOMPARE(model.rowCount(index), 0);
-}
-
-void tst_QDirModel::task244669_remove()
-{
- QFile f1(SRCDIR "dirtest/f1.txt");
-#ifdef Q_OS_WINRT
- QEXPECT_FAIL("", "Sandboxed applications cannot access SRCDIR - QTBUG-68297", Abort);
-#endif
- QVERIFY(f1.open(QIODevice::WriteOnly));
- f1.close();
- QFile f2(SRCDIR "dirtest/f2.txt");
- QVERIFY(f2.open(QIODevice::WriteOnly));
- f2.close();
-
- QDirModel model;
- model.setReadOnly(false);
- QPersistentModelIndex parent = model.index(SRCDIR "dirtest");
- QPersistentModelIndex index2 = model.index(SRCDIR "dirtest/f2.txt");
- QPersistentModelIndex index1 = model.index(SRCDIR "dirtest/f1.txt");
-
- QVERIFY(parent.isValid());
- QVERIFY(index1.isValid());
- QVERIFY(index2.isValid());
- QCOMPARE(parent.data() , model.index(SRCDIR "dirtest").data());
- QCOMPARE(index1.data() , model.index(SRCDIR "dirtest/f1.txt").data());
- QCOMPARE(index2.data() , model.index(SRCDIR "dirtest/f2.txt").data());
-
- QVERIFY(model.remove(index1));
-
- QVERIFY(parent.isValid());
- QVERIFY(!index1.isValid());
- QVERIFY(index2.isValid());
- QCOMPARE(parent.data() , model.index(SRCDIR "dirtest").data());
- QCOMPARE(index2.data() , model.index(SRCDIR "dirtest/f2.txt").data());
-
- QVERIFY(model.remove(index2));
-
- QVERIFY(parent.isValid());
- QVERIFY(!index2.isValid());
- QVERIFY(!index1.isValid());
- QCOMPARE(parent.data() , model.index(SRCDIR "dirtest").data());
-}
-
-void tst_QDirModel::roleNames_data()
-{
- QTest::addColumn<int>("role");
- QTest::addColumn<QByteArray>("roleName");
- QTest::newRow("decoration") << int(Qt::DecorationRole) << QByteArray("fileIcon");
- QTest::newRow("display") << int(Qt::DisplayRole) << QByteArray("display");
- QTest::newRow("fileIcon") << int(QDirModel::FileIconRole) << QByteArray("fileIcon");
- QTest::newRow("filePath") << int(QDirModel::FilePathRole) << QByteArray("filePath");
- QTest::newRow("fileName") << int(QDirModel::FileNameRole) << QByteArray("fileName");
-}
-
-void tst_QDirModel::roleNames()
-{
- QDirModel model;
- QHash<int, QByteArray> roles = model.roleNames();
-
- QFETCH(int, role);
- QVERIFY(roles.contains(role));
-
- QFETCH(QByteArray, roleName);
- QCOMPARE(roles.contains(role), true);
- QCOMPARE(roles.value(role), roleName);
-}
-
-
-QTEST_MAIN(tst_QDirModel)
-#include "tst_qdirmodel.moc"