]> cloud.milkyroute.net Git - dolphin.git/blob - src/tests/testbase.h
It's easier to put functionality that is used by many unit tests into
[dolphin.git] / src / tests / testbase.h
1 /***************************************************************************
2 * Copyright (C) 2010 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 class KTempDir;
26 class QAbstractItemView;
27 class QDir;
28 class DolphinDirLister;
29 class DolphinModel;
30 class DolphinSortFilterProxyModel;
31 class DolphinView;
32
33 /*
34 * The class TestBase aims to make writing Dolphin unit tests easier.
35 * It provides functionality that almost every unit test needs: setup of the DolphinView and
36 * easy creation of test files and subfolders in a temporary directory which is removed in
37 * the TestBase destructor.
38 *
39 * TODO: TestBase should also backup the DolphinSettings and restore them later!
40 */
41
42 class TestBase : public QObject
43 {
44 Q_OBJECT
45
46 public:
47
48 TestBase();
49 ~TestBase();
50
51 // Returns the item view (icons, details, or columns)
52 QAbstractItemView* itemView () const;
53
54 KUrl testDirUrl() const;
55
56 /*
57 * The following functions create either a file, a list of files, or a directory.
58 * The paths may be absolute or relative to the test directory. Any missing parent
59 * directories will be created automatically.
60 */
61
62 void createFile(const QString& path, const QByteArray& data = QByteArray("test"));
63 void createFiles(const QStringList& files);
64 void createDir(const QString& path);
65
66 /*
67 * Remove the test directory and create an empty one.
68 */
69
70 void cleanupTestDir();
71
72 // Make members that are accessed frequently by the derived test classes public
73
74 DolphinDirLister* m_dirLister;
75 DolphinModel* m_dolphinModel;
76 DolphinSortFilterProxyModel* m_proxyModel;
77 DolphinView* m_view;
78
79 private:
80
81 KTempDir* m_tempDir;
82 QString m_path;
83 QDir* m_dir;
84
85 void makePathAbsoluteAndCreateParents(QString& path);
86
87 };
88
89 #endif