┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/tests/testhelper.h
diff options
context:
space:
mode:
authorFrank Reininghaus <[email protected]>2010-10-22 15:41:47 +0000
committerFrank Reininghaus <[email protected]>2010-10-22 15:41:47 +0000
commit28bc452f0d4489e0f3076996dde128a5b2940209 (patch)
tree34589545276e84167e868db9ed0186c6420cc7ec /src/tests/testhelper.h
parentef87498e5226ce44d9c3fd01893d668038122c55 (diff)
Add a second Dolphin unit test (for a regression in DolphinDetailsView
which has been fixed recently). This commit also adds a new class TestHelper which provides some funtionality that most Dolphin unit tests will need. I hope that this makes implementing additional tests as easy as possible :-) svn path=/trunk/KDE/kdebase/apps/; revision=1188536
Diffstat (limited to 'src/tests/testhelper.h')
-rw-r--r--src/tests/testhelper.h88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/tests/testhelper.h b/src/tests/testhelper.h
new file mode 100644
index 000000000..a06b5dea1
--- /dev/null
+++ b/src/tests/testhelper.h
@@ -0,0 +1,88 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Frank Reininghaus ([email protected]) *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#ifndef TESTHELPER_H
+#define TESTHELPER_H
+
+#include <KUrl>
+
+class KTempDir;
+class QAbstractItemView;
+class QDir;
+class DolphinDirLister;
+class DolphinModel;
+class DolphinSortFilterProxyModel;
+class DolphinView;
+
+/*
+ * The class TestHelper aims to make writing Dolphin unit tests easier.
+ * It provides functionality that almost every unit test needs: setup of the DolphinView and
+ * easy creation of test files and subfolders in a temporary directory which is removed in
+ * the TestHelper destructor.
+ *
+ * TODO: TestHelper should also backup the DolphinSettings and restore them later!
+ */
+
+class TestHelper
+{
+
+public:
+
+ TestHelper();
+ ~TestHelper();
+
+ DolphinView* view() const { return m_view; }
+ DolphinSortFilterProxyModel* proxyModel() const { return m_proxyModel; }
+
+ // Returns the item view (icons, details, or columns)
+ QAbstractItemView* itemView () const;
+
+ KUrl testDirUrl() const;
+
+ /*
+ * The following functions create either a file, a list of files, or a directory.
+ * The paths may be absolute or relative to the test directory. Any missing parent
+ * directories will be created automatically.
+ */
+
+ void createFile(const QString& path, const QByteArray& data = QByteArray("test"));
+ void createFiles(const QStringList& files);
+ void createDir(const QString& path);
+
+ /*
+ * Remove the test directory and create an empty one.
+ */
+
+ void cleanupTestDir();
+
+private:
+
+ void makePathAbsoluteAndCreateParents(QString& path);
+
+ KTempDir* m_tempDir;
+ QString m_path;
+ QDir* m_dir;
+ DolphinDirLister* m_dirLister;
+ DolphinModel* m_dolphinModel;
+ DolphinSortFilterProxyModel* m_proxyModel;
+ DolphinView* m_view;
+
+};
+
+#endif \ No newline at end of file