]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Do not reload the DolphinView in the tests' initView() members
authorFrank Reininghaus <frank78ac@googlemail.com>
Tue, 5 Apr 2011 21:55:37 +0000 (23:55 +0200)
committerFrank Reininghaus <frank78ac@googlemail.com>
Wed, 6 Apr 2011 09:44:01 +0000 (11:44 +0200)
Rather than reloading the view after it is initilised, we just wait
until the view emits its finishedPathLoading() signal. This saves some
time when running the tests (at least on my system).

src/tests/dolphindetailsviewtest.cpp
src/tests/dolphinviewtest_allviewmodes.cpp

index d17341f6ffe386465d2e8ebd60e426b9534a9e7f..2aaf95e01a6fe481b9ef17bd6ca9089904883ae7 100644 (file)
@@ -53,13 +53,24 @@ private:
      * Therefore, a pointer to the details view is returned by initView(DolphinView*).
      */
     DolphinDetailsView* initView(DolphinView* view) const {
+        QSignalSpy spyFinishedPathLoading(view, SIGNAL(finishedPathLoading(const KUrl&)));
         view->setMode(DolphinView::DetailsView);
         DolphinDetailsView* detailsView = qobject_cast<DolphinDetailsView*>(itemView(view));
+        Q_ASSERT(detailsView);
         detailsView->setFoldersExpandable(true);
         view->resize(400, 400);
         view->show();
         QTest::qWaitForWindowShown(view);
-        reloadViewAndWait(view);
+
+        // If the DolphinView's finishedPathLoading(const KUrl&) signal has not been received yet,
+        // we have to wait a bit more.
+        // The reason why the if-statement is needed here is that the signal might have been emitted
+        // while we were waiting in QTest::qWaitForWindowShown(view)
+        // -> waitForFinishedPathLoading(view) would fail in that case.
+        if (spyFinishedPathLoading.isEmpty()) {
+            Q_ASSERT(waitForFinishedPathLoading(view));
+        }
+
         return detailsView;
     }
 
index 7673f9df9f809e5b45784a98192073b5398e9b43..d9db5b141e82ca6ca69198f2803a318596df012f 100644 (file)
@@ -389,14 +389,34 @@ void DolphinViewTest_AllViewModes::testKeyboardFocus()
     }
 }
 
+// Private member functions which are used by the tests
+
+/**
+ * initView(DolphinView*) sets the correct view mode, shows the view on the screen, and waits until loading the
+ * folder in the view is finished.
+ *
+ * Many unit tests need access to DolphinVie's internal item view (icons, details, or columns).
+ * Therefore, a pointer to the item view is returned by initView(DolphinView*).
+ */
+
 QAbstractItemView* DolphinViewTest_AllViewModes::initView(DolphinView* view) const
 {
+    QSignalSpy spyFinishedPathLoading(view, SIGNAL(finishedPathLoading(const KUrl&)));
     view->setMode(mode());
+    Q_ASSERT(verifyCorrectViewMode(view));
     view->resize(200, 300);
     view->show();
     QTest::qWaitForWindowShown(view);
-    Q_ASSERT(verifyCorrectViewMode(view));
-    reloadViewAndWait(view);
+
+    // If the DolphinView's finishedPathLoading(const KUrl&) signal has not been received yet,
+    // we have to wait a bit more.
+    // The reason why the if-statement is needed here is that the signal might have been emitted
+    // while we were waiting in QTest::qWaitForWindowShown(view)
+    // -> waitForFinishedPathLoading(view) would fail in that case.
+    if (spyFinishedPathLoading.isEmpty()) {
+        Q_ASSERT(waitForFinishedPathLoading(view));
+    }
+
     return itemView(view);
 }