┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/tests/testdir.h
diff options
context:
space:
mode:
authorFrank Reininghaus <[email protected]>2011-04-03 15:31:27 +0200
committerFrank Reininghaus <[email protected]>2011-04-03 15:32:12 +0200
commit95cb8ffe01e0252d3a26f244e8607254200d067f (patch)
treed76499d9b454b8730e48a2f24a55c914f7f0230c /src/tests/testdir.h
parent5ff682d852a07b5121e49d8ed2a239b0a1762b6b (diff)
Dolphin unit test refactoring
This commit changes mainly two things: 1. The functionality related to the handling of temporary files and folders is moved to a new class TestDir. 2. The setup of a temporary folder and of DolphinView instances is now done in each unit test function. A benefit of this change is that there are no unwanted interactions between different unit test functions any more. Moreover, different test functions could now share a test folder more easily. Additionally, the reference arguments of all functions are changed to pointers for consistency.
Diffstat (limited to 'src/tests/testdir.h')
-rw-r--r--src/tests/testdir.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/tests/testdir.h b/src/tests/testdir.h
new file mode 100644
index 000000000..bff462690
--- /dev/null
+++ b/src/tests/testdir.h
@@ -0,0 +1,59 @@
+/*****************************************************************************
+ * Copyright (C) 2010-2011 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 TESTDIR_H
+#define TESTDIR_H
+
+#include <KTempDir>
+#include <KUrl>
+
+#include <QDateTime>
+
+/**
+ * TestDir provides a temporary directory. In addition to KTempDir, it has
+ * methods that create files and subdirectories inside the directory.
+ */
+
+class TestDir : public KTempDir
+{
+
+public:
+
+ TestDir() {}
+ ~TestDir() {}
+
+ KUrl url() const { return KUrl(name()); }
+
+ /**
+ * 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"), const QDateTime& time = QDateTime());
+ void createFiles(const QStringList& files);
+ void createDir(const QString& path, const QDateTime& time = QDateTime());
+
+private:
+
+ void makePathAbsoluteAndCreateParents(QString& path);
+
+};
+
+#endif