┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Reininghaus <[email protected]>2010-10-29 14:13:11 +0000
committerFrank Reininghaus <[email protected]>2010-10-29 14:13:11 +0000
commitb1e69cae00a708aa50dbd03eca944e83a639d861 (patch)
tree83db23b6f8c49f6fd786b3b3c0656fde58abadaa
parent454a0a6539384aff0578379f8b18703a0cadd86b (diff)
It's easier to put functionality that is used by many unit tests into
a common base class. I took that idea from Nepomuk's unit tests in kdelibs. svn path=/trunk/KDE/kdebase/apps/; revision=1191051
-rw-r--r--src/tests/CMakeLists.txt2
-rw-r--r--src/tests/dolphindetailsviewtest.cpp23
-rw-r--r--src/tests/testbase.cpp (renamed from src/tests/testhelper.cpp)20
-rw-r--r--src/tests/testbase.h (renamed from src/tests/testhelper.h)31
-rw-r--r--src/views/dolphinview.h2
5 files changed, 33 insertions, 45 deletions
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 411994f05..0bf57665b 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -4,5 +4,5 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. ${KDE4_INCLUDES} )
kde4_add_unit_test(dolphintreeviewtest TEST dolphintreeviewtest.cpp)
target_link_libraries(dolphintreeviewtest dolphinprivate ${KDE4_KDEUI_LIBS} ${QT_QTTEST_LIBRARY})
-kde4_add_unit_test(dolphindetailsviewtest TEST dolphindetailsviewtest.cpp testhelper.cpp ../views/zoomlevelinfo.cpp)
+kde4_add_unit_test(dolphindetailsviewtest TEST dolphindetailsviewtest.cpp testbase.cpp ../views/zoomlevelinfo.cpp)
target_link_libraries(dolphindetailsviewtest dolphinprivate ${KDE4_KIO_LIBS} ${QT_QTTEST_LIBRARY})
diff --git a/src/tests/dolphindetailsviewtest.cpp b/src/tests/dolphindetailsviewtest.cpp
index ab3006d9d..bf77830f7 100644
--- a/src/tests/dolphindetailsviewtest.cpp
+++ b/src/tests/dolphindetailsviewtest.cpp
@@ -19,7 +19,7 @@
#include <qtest_kde.h>
-#include "testhelper.h"
+#include "testbase.h"
#include "views/dolphindetailsview.h"
#include "views/dolphinview.h"
@@ -34,21 +34,16 @@
#include "kdebug.h"
-class DolphinDetailsViewTest : public QObject
+class DolphinDetailsViewTest : public TestBase
{
Q_OBJECT
private slots:
void initTestCase();
- void cleanupTestCase();
void bug234600_overlappingIconsWhenZooming();
-private:
-
- TestHelper* m_helper;
- DolphinView* m_view;
};
void DolphinDetailsViewTest::initTestCase()
@@ -56,14 +51,6 @@ void DolphinDetailsViewTest::initTestCase()
// add time stamps to find origin of test failures due to timeout at
// http://my.cdash.org/index.php?project=kdebase&date=
qputenv("KDE_DEBUG_TIMESTAMP", QByteArray("1"));
-
- m_helper = new TestHelper;
- m_view = m_helper->view();
-}
-
-void DolphinDetailsViewTest::cleanupTestCase()
-{
- delete m_helper;
}
/**
@@ -79,10 +66,10 @@ void DolphinDetailsViewTest::bug234600_overlappingIconsWhenZooming()
{
QStringList files;
files << "a" << "b" << "c" << "d";
- m_helper->createFiles(files);
+ createFiles(files);
m_view->setMode(DolphinView::DetailsView);
- DolphinDetailsView* detailsView = qobject_cast<DolphinDetailsView*>(m_helper->itemView());
+ DolphinDetailsView* detailsView = qobject_cast<DolphinDetailsView*>(itemView());
QVERIFY(detailsView);
m_view->resize(400, 400);
m_view->show();
@@ -126,7 +113,7 @@ void DolphinDetailsViewTest::bug234600_overlappingIconsWhenZooming()
m_view->hide();
kDebug() << "Cleaning up test directory...";
- m_helper->cleanupTestDir();
+ cleanupTestDir();
kDebug() << "Done.";
}
diff --git a/src/tests/testhelper.cpp b/src/tests/testbase.cpp
index 3e663f762..5945cd258 100644
--- a/src/tests/testhelper.cpp
+++ b/src/tests/testbase.cpp
@@ -17,7 +17,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
-#include "testhelper.h"
+#include "testbase.h"
#include "views/dolphinview.h"
#include "views/dolphinmodel.h"
@@ -29,7 +29,7 @@
#include <QtCore/QDir>
#include <QtGui/QAbstractItemView>
-TestHelper::TestHelper()
+TestBase::TestBase()
{
m_tempDir = new KTempDir;
Q_ASSERT(m_tempDir->exists());
@@ -45,7 +45,7 @@ TestHelper::TestHelper()
m_view = new DolphinView(0, KUrl(m_path), m_proxyModel);
}
-TestHelper::~TestHelper()
+TestBase::~TestBase()
{
delete m_view;
delete m_proxyModel;
@@ -55,18 +55,18 @@ TestHelper::~TestHelper()
delete m_tempDir;
}
-QAbstractItemView* TestHelper::itemView () const
+QAbstractItemView* TestBase::itemView () const
{
return m_view->m_viewAccessor.itemView();
}
-KUrl TestHelper::testDirUrl() const
+KUrl TestBase::testDirUrl() const
{
return KUrl(m_path);
}
-void TestHelper::createFile(const QString& path, const QByteArray& data)
+void TestBase::createFile(const QString& path, const QByteArray& data)
{
QString absolutePath = path;
makePathAbsoluteAndCreateParents(absolutePath);
@@ -79,14 +79,14 @@ void TestHelper::createFile(const QString& path, const QByteArray& data)
Q_ASSERT(QFile::exists(absolutePath));
}
-void TestHelper::createFiles(const QStringList& files)
+void TestBase::createFiles(const QStringList& files)
{
foreach(const QString& path, files) {
createFile(path);
}
}
-void TestHelper::createDir(const QString& path)
+void TestBase::createDir(const QString& path)
{
QString absolutePath = path;
makePathAbsoluteAndCreateParents(absolutePath);
@@ -95,7 +95,7 @@ void TestHelper::createDir(const QString& path)
Q_ASSERT(QFile::exists(absolutePath));
}
-void TestHelper::makePathAbsoluteAndCreateParents(QString& path)
+void TestBase::makePathAbsoluteAndCreateParents(QString& path)
{
QFileInfo fileInfo(path);
if (!fileInfo.isAbsolute()) {
@@ -111,7 +111,7 @@ void TestHelper::makePathAbsoluteAndCreateParents(QString& path)
Q_ASSERT(dir.exists());
}
-void TestHelper::cleanupTestDir()
+void TestBase::cleanupTestDir()
{
delete m_tempDir;
m_tempDir = new KTempDir;
diff --git a/src/tests/testhelper.h b/src/tests/testbase.h
index a06b5dea1..121c230ca 100644
--- a/src/tests/testhelper.h
+++ b/src/tests/testbase.h
@@ -31,24 +31,22 @@ class DolphinSortFilterProxyModel;
class DolphinView;
/*
- * The class TestHelper aims to make writing Dolphin unit tests easier.
+ * The class TestBase 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.
+ * the TestBase destructor.
*
- * TODO: TestHelper should also backup the DolphinSettings and restore them later!
+ * TODO: TestBase should also backup the DolphinSettings and restore them later!
*/
-class TestHelper
+class TestBase : public QObject
{
+ Q_OBJECT
public:
- TestHelper();
- ~TestHelper();
-
- DolphinView* view() const { return m_view; }
- DolphinSortFilterProxyModel* proxyModel() const { return m_proxyModel; }
+ TestBase();
+ ~TestBase();
// Returns the item view (icons, details, or columns)
QAbstractItemView* itemView () const;
@@ -71,18 +69,21 @@ public:
void cleanupTestDir();
-private:
-
- void makePathAbsoluteAndCreateParents(QString& path);
+ // Make members that are accessed frequently by the derived test classes public
- KTempDir* m_tempDir;
- QString m_path;
- QDir* m_dir;
DolphinDirLister* m_dirLister;
DolphinModel* m_dolphinModel;
DolphinSortFilterProxyModel* m_proxyModel;
DolphinView* m_view;
+private:
+
+ KTempDir* m_tempDir;
+ QString m_path;
+ QDir* m_dir;
+
+ void makePathAbsoluteAndCreateParents(QString& path);
+
};
#endif \ No newline at end of file
diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h
index 0c88d27ff..9d2032e9f 100644
--- a/src/views/dolphinview.h
+++ b/src/views/dolphinview.h
@@ -799,7 +799,7 @@ private:
QSet<QString> m_newFileNames;
// For unit tests
- friend class TestHelper;
+ friend class TestBase;
};
/// Allow using DolphinView::Mode in QVariant