]> cloud.milkyroute.net Git - dolphin.git/commitdiff
It's easier to put functionality that is used by many unit tests into
authorFrank Reininghaus <frank78ac@googlemail.com>
Fri, 29 Oct 2010 14:13:11 +0000 (14:13 +0000)
committerFrank Reininghaus <frank78ac@googlemail.com>
Fri, 29 Oct 2010 14:13:11 +0000 (14:13 +0000)
a common base class. I took that idea from Nepomuk's unit tests in
kdelibs.

svn path=/trunk/KDE/kdebase/apps/; revision=1191051

src/tests/CMakeLists.txt
src/tests/dolphindetailsviewtest.cpp
src/tests/testbase.cpp [moved from src/tests/testhelper.cpp with 88% similarity]
src/tests/testbase.h [moved from src/tests/testhelper.h with 88% similarity]
src/views/dolphinview.h

index 411994f05b3d41ea7c78c386fe3f6a4da5295bb4..0bf57665b91a741426b38a74ebdbf245a0416630 100644 (file)
@@ -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})
index ab3006d9d7b7250dd93c907b533a58ba44a51071..bf77830f767182c9f58704d088b56b40c3e869dd 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <qtest_kde.h>
 
-#include "testhelper.h"
+#include "testbase.h"
 
 #include "views/dolphindetailsview.h"
 #include "views/dolphinview.h"
 
 #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.";
 }
 
similarity index 88%
rename from src/tests/testhelper.cpp
rename to src/tests/testbase.cpp
index 3e663f76298159795bf783e35d3d4128f5354072..5945cd258882df02ea520e8d31f2a1f0caa072f8 100644 (file)
@@ -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;
similarity index 88%
rename from src/tests/testhelper.h
rename to src/tests/testbase.h
index a06b5dea12ad5e142121b21c768633aa83e3913b..121c230ca0e3ebe39197e68edd56300931ab57ad 100644 (file)
@@ -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
index 0c88d27ff522c21a6a8d8295722e0c85d82ee07c..9d2032e9f0b23918aaeb9233a44b3de45756d61e 100644 (file)
@@ -799,7 +799,7 @@ private:
     QSet<QString> m_newFileNames;
 
     // For unit tests
-    friend class TestHelper;
+    friend class TestBase;
 };
 
 /// Allow using DolphinView::Mode in QVariant