]> cloud.milkyroute.net Git - dolphin.git/blob - src/tests/testbase.h
DolphinTreeViewTest: Add unit test for bug 220898 (rubberband
[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 // Reloads the view and waits for the finishedPathLoading(const KUrl&) signal.
55 void reloadViewAndWait();
56
57 KUrl testDirUrl() const;
58
59 /**
60 * The following functions create either a file, a list of files, or a directory.
61 * The paths may be absolute or relative to the test directory. Any missing parent
62 * directories will be created automatically.
63 */
64
65 void createFile(const QString& path, const QByteArray& data = QByteArray("test"));
66 void createFiles(const QStringList& files);
67 void createDir(const QString& path);
68
69 /**
70 * Remove the test directory and create an empty one.
71 */
72
73 void cleanupTestDir();
74
75 // Make members that are accessed frequently by the derived test classes public
76
77 DolphinView* m_view;
78
79 QString m_path;
80
81 private:
82
83 KTempDir* m_tempDir;
84 QDir* m_dir;
85
86 void makePathAbsoluteAndCreateParents(QString& path);
87
88 };
89
90 #endif