]> cloud.milkyroute.net Git - dolphin.git/blob - src/tests/testbase.h
Use capitalized KDE includes
[dolphin.git] / src / tests / testbase.h
1 /*****************************************************************************
2 * Copyright (C) 2010-2011 by Frank Reininghaus (frank78ac@googlemail.com) *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 *****************************************************************************/
19
20 #ifndef TESTHELPER_H
21 #define TESTHELPER_H
22
23 #include <KUrl>
24
25 #include <QDateTime>
26
27 class KTempDir;
28 class QAbstractItemView;
29 class QDir;
30 class DolphinDirLister;
31 class DolphinModel;
32 class DolphinSortFilterProxyModel;
33 class DolphinView;
34
35 /**
36 * The class TestBase aims to make writing Dolphin unit tests easier.
37 * It provides functionality that almost every unit test needs: setup of the DolphinView and
38 * easy creation of test files and subfolders in a temporary directory which is removed in
39 * the TestBase destructor.
40 *
41 * TODO: TestBase should also backup the DolphinSettings and restore them later!
42 */
43
44 class TestBase : public QObject
45 {
46 Q_OBJECT
47
48 public:
49
50 TestBase();
51 ~TestBase();
52
53 // Returns the item view (icons, details, or columns)
54 QAbstractItemView* itemView() const;
55
56 // Reloads the view and waits for the finishedPathLoading(const KUrl&) signal.
57 void reloadViewAndWait();
58
59 KUrl testDirUrl() const;
60
61 /**
62 * The following functions create either a file, a list of files, or a directory.
63 * The paths may be absolute or relative to the test directory. Any missing parent
64 * directories will be created automatically.
65 */
66
67 void createFile(const QString& path, const QByteArray& data = QByteArray("test"), const QDateTime& time = QDateTime());
68 void createFiles(const QStringList& files);
69 void createDir(const QString& path, const QDateTime& time = QDateTime());
70
71 /**
72 * Returns the items shown in the view. The order corresponds to the sort order of the view.
73 */
74
75 QStringList viewItems() const;
76
77 /**
78 * Remove the test directory and create an empty one.
79 */
80
81 void cleanupTestDir();
82
83 // Make members that are accessed frequently by the derived test classes public
84
85 DolphinView* m_view;
86
87 QString m_path;
88
89 private:
90
91 KTempDir* m_tempDir;
92 QDir* m_dir;
93
94 void makePathAbsoluteAndCreateParents(QString& path);
95
96 };
97
98 #endif