File indexing completed on 2024-04-21 03:54:51

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2006 David Faure <faure@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 #ifndef KDIRMODELTEST_H
0008 #define KDIRMODELTEST_H
0009 
0010 #include <kdirmodel.h>
0011 
0012 #include <QEventLoop>
0013 #include <QObject>
0014 #include <QTemporaryDir>
0015 #include <QTest>
0016 #include <QTestEventLoop>
0017 
0018 #include <memory>
0019 
0020 class KDirModelTest : public QObject
0021 {
0022     Q_OBJECT
0023 private Q_SLOTS:
0024     void initTestCase();
0025     void cleanupTestCase();
0026     void cleanup();
0027     void testRowCount();
0028     void testIndex();
0029     void testNames();
0030     void testItemForIndex();
0031     void testIndexForItem();
0032     void testData();
0033 
0034     /**
0035      * Test if the icon is valid if "Icon" is specified in the desktop file, and can fall back to "unknown"
0036      * if KDirModel fails to load the icon.
0037      */
0038     void testIcon();
0039 
0040     void testReload();
0041     void testModifyFile();
0042     void testRenameFile();
0043     void testMoveDirectory();
0044     void testRenameDirectory();
0045     void testRenameDirectoryInCache();
0046     void testChmodDirectory();
0047     void testExpandToUrl_data();
0048     void testExpandToUrl();
0049     void testFilter();
0050     void testFilterPatterns();
0051     void testMimeFilter();
0052     void testMimeExcludeFilter();
0053     void testShowHiddenFiles();
0054     void testMultipleSlashes();
0055     void testUrlWithRef();
0056     void testRemoteUrlWithHost();
0057     void testZipFile();
0058     void testBug196695();
0059     void testMimeData();
0060     void testDotHiddenFile_data();
0061     void testDotHiddenFile();
0062     void testShowRoot();
0063     void testShowRootWithTrailingSlash();
0064     void testShowRootAndExpandToUrl();
0065     void testHasChildren_data();
0066     void testHasChildren();
0067     void testInvalidUrl();
0068 
0069     // These tests must be done last
0070     void testDeleteFile();
0071     void testDeleteFileWhileListing();
0072     void testOverwriteFileWithDir();
0073     void testDeleteFiles();
0074     void testRenameFileToHidden();
0075     void testDeleteDirectory();
0076     void testDeleteCurrentDirectory();
0077 
0078     // Somewhat unrelated
0079     void testQUrlHash();
0080 
0081 protected Q_SLOTS: // 'more private than private slots' - i.e. not seen by qtestlib
0082     void slotExpand(const QModelIndex &index);
0083     void slotRowsInserted(const QModelIndex &index, int, int);
0084 
0085 private:
0086     void recreateTestData();
0087     void fillModel(bool reload, bool expectAllIndexes = true);
0088     void collectKnownIndexes();
0089     void testMoveDirectory(const QString &srcdir);
0090     void testUpdateParentAfterExpand();
0091 
0092 private:
0093     std::unique_ptr<QTemporaryDir> m_tempDir;
0094     KDirModel *m_dirModel;
0095     QModelIndex m_fileIndex;
0096     QModelIndex m_specialFileIndex;
0097     QModelIndex m_secondFileIndex;
0098     QModelIndex m_dirIndex;
0099     QModelIndex m_fileInDirIndex;
0100     QModelIndex m_fileInSubdirIndex;
0101     QStringList m_topLevelFileNames; // files only
0102 
0103     // for slotExpand
0104     QStringList m_expectedExpandSignals;
0105     int m_nextExpectedExpandSignals; // index into m_expectedExpandSignals
0106     KDirModel *m_dirModelForExpand;
0107     QUrl m_urlToExpandTo;
0108     bool m_rowsInsertedEmitted;
0109     bool m_expectRowsInserted;
0110 };
0111 
0112 #endif