1 /*
2     This file is part of the KDE project
3     SPDX-FileCopyrightText: 2006 David Faure <faure@kde.org>
4 
5     SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 #ifndef KDIRMODELTEST_H
8 #define KDIRMODELTEST_H
9 
10 #include <kdirmodel.h>
11 
12 #include <QEventLoop>
13 #include <QObject>
14 #include <QTemporaryDir>
15 #include <QTest>
16 #include <QTestEventLoop>
17 
18 #include <memory>
19 
20 // If you disable this, you need to change all exitLoop into quit in connect() statements...
21 #define USE_QTESTEVENTLOOP
22 
23 class KDirModelTest : public QObject
24 {
25     Q_OBJECT
26 private Q_SLOTS:
27     void initTestCase();
28     void cleanupTestCase();
29     void cleanup();
30     void testRowCount();
31     void testIndex();
32     void testNames();
33     void testItemForIndex();
34     void testIndexForItem();
35     void testData();
36     void testReload();
37     void testModifyFile();
38     void testRenameFile();
39     void testMoveDirectory();
40     void testRenameDirectory();
41     void testRenameDirectoryInCache();
42     void testChmodDirectory();
43     void testExpandToUrl_data();
44     void testExpandToUrl();
45     void testFilter();
46     void testFilterPatterns();
47     void testMimeFilter();
48     void testShowHiddenFiles();
49     void testMultipleSlashes();
50     void testUrlWithRef();
51     void testRemoteUrlWithHost();
52     void testZipFile();
53     void testBug196695();
54     void testMimeData();
55     void testDotHiddenFile_data();
56     void testDotHiddenFile();
57     void testShowRoot();
58     void testShowRootWithTrailingSlash();
59     void testShowRootAndExpandToUrl();
60     void testHasChildren_data();
61     void testHasChildren();
62     void testInvalidUrl();
63 
64     // These tests must be done last
65     void testDeleteFile();
66     void testDeleteFileWhileListing();
67     void testOverwriteFileWithDir();
68     void testDeleteFiles();
69     void testRenameFileToHidden();
70     void testDeleteDirectory();
71     void testDeleteCurrentDirectory();
72 
73     // Somewhat unrelated
74     void testQUrlHash();
75 
76 protected Q_SLOTS: // 'more private than private slots' - i.e. not seen by qtestlib
77     void slotListingCompleted();
78     void slotExpand(const QModelIndex &index);
79     void slotRowsInserted(const QModelIndex &index, int, int);
80 
81 private:
82     void recreateTestData();
83     void enterLoop();
84     void fillModel(bool reload, bool expectAllIndexes = true);
85     void collectKnownIndexes();
86     void testMoveDirectory(const QString &srcdir);
87     void testUpdateParentAfterExpand();
88 
89 private:
90 #ifdef USE_QTESTEVENTLOOP
91     QTestEventLoop m_eventLoop;
92 #else
93     QEventLoop m_eventLoop;
94 #endif
95     std::unique_ptr<QTemporaryDir> m_tempDir;
96     KDirModel *m_dirModel;
97     QModelIndex m_fileIndex;
98     QModelIndex m_specialFileIndex;
99     QModelIndex m_secondFileIndex;
100     QModelIndex m_dirIndex;
101     QModelIndex m_fileInDirIndex;
102     QModelIndex m_fileInSubdirIndex;
103     QStringList m_topLevelFileNames; // files only
104 
105     // for slotExpand
106     QStringList m_expectedExpandSignals;
107     int m_nextExpectedExpandSignals; // index into m_expectedExpandSignals
108     KDirModel *m_dirModelForExpand;
109     QUrl m_urlToExpandTo;
110     bool m_rowsInsertedEmitted;
111     bool m_expectRowsInserted;
112 };
113 
114 #endif
115