File indexing completed on 2025-01-19 12:48:34
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 testShowHiddenFiles(); 0053 void testMultipleSlashes(); 0054 void testUrlWithRef(); 0055 void testRemoteUrlWithHost(); 0056 void testZipFile(); 0057 void testBug196695(); 0058 void testMimeData(); 0059 void testDotHiddenFile_data(); 0060 void testDotHiddenFile(); 0061 void testShowRoot(); 0062 void testShowRootWithTrailingSlash(); 0063 void testShowRootAndExpandToUrl(); 0064 void testHasChildren_data(); 0065 void testHasChildren(); 0066 void testInvalidUrl(); 0067 0068 // These tests must be done last 0069 void testDeleteFile(); 0070 void testDeleteFileWhileListing(); 0071 void testOverwriteFileWithDir(); 0072 void testDeleteFiles(); 0073 void testRenameFileToHidden(); 0074 void testDeleteDirectory(); 0075 void testDeleteCurrentDirectory(); 0076 0077 // Somewhat unrelated 0078 void testQUrlHash(); 0079 0080 protected Q_SLOTS: // 'more private than private slots' - i.e. not seen by qtestlib 0081 void slotExpand(const QModelIndex &index); 0082 void slotRowsInserted(const QModelIndex &index, int, int); 0083 0084 private: 0085 void recreateTestData(); 0086 void fillModel(bool reload, bool expectAllIndexes = true); 0087 void collectKnownIndexes(); 0088 void testMoveDirectory(const QString &srcdir); 0089 void testUpdateParentAfterExpand(); 0090 0091 private: 0092 std::unique_ptr<QTemporaryDir> m_tempDir; 0093 KDirModel *m_dirModel; 0094 QModelIndex m_fileIndex; 0095 QModelIndex m_specialFileIndex; 0096 QModelIndex m_secondFileIndex; 0097 QModelIndex m_dirIndex; 0098 QModelIndex m_fileInDirIndex; 0099 QModelIndex m_fileInSubdirIndex; 0100 QStringList m_topLevelFileNames; // files only 0101 0102 // for slotExpand 0103 QStringList m_expectedExpandSignals; 0104 int m_nextExpectedExpandSignals; // index into m_expectedExpandSignals 0105 KDirModel *m_dirModelForExpand; 0106 QUrl m_urlToExpandTo; 0107 bool m_rowsInsertedEmitted; 0108 bool m_expectRowsInserted; 0109 }; 0110 0111 #endif