]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Add function TestBase::waitForFinishedPathLoading()
authorFrank Reininghaus <frank78ac@googlemail.com>
Tue, 5 Apr 2011 20:12:51 +0000 (22:12 +0200)
committerFrank Reininghaus <frank78ac@googlemail.com>
Tue, 5 Apr 2011 20:12:51 +0000 (22:12 +0200)
Many tests have to wait until this signal is received from the
DolphinView, so it is convenient to have a function that wraps
the QTest::kWaitForSignal() call.

src/tests/dolphindetailsviewtest.cpp
src/tests/dolphinviewtest_allviewmodes.cpp
src/tests/testbase.cpp
src/tests/testbase.h

index 87a9d253db1693a1a67d779bb8670eb5599db74e..d17341f6ffe386465d2e8ebd60e426b9534a9e7f 100644 (file)
@@ -98,11 +98,6 @@ void DolphinDetailsViewTest::testExpandedUrls()
     QSet<KUrl> expectedExpandedUrls;
     QCOMPARE(detailsView->expandedUrls(), expectedExpandedUrls);
 
-    // Every time we expand a folder, we have to wait until the view has finished loading
-    // its contents before we can expand further subfolders. We keep track of the reloading
-    // using a signal spy.
-    QSignalSpy spyFinishedPathLoading(&view, SIGNAL(finishedPathLoading(const KUrl&)));
-
     // Expand URLs one by one and verify the result of DolphinDetailsView::expandedUrls()
     QStringList itemsToExpand;
     itemsToExpand << "b" << "b/a" << "b/a/c" << "b/c" << "c";
@@ -115,10 +110,7 @@ void DolphinDetailsViewTest::testExpandedUrls()
 
         // Before we proceed, we have to make sure that the view has finished
         // loading the contents of the expanded folder.
-        while (spyFinishedPathLoading.isEmpty()) {
-            QTest::qWait(10);
-        }
-        spyFinishedPathLoading.takeFirst();
+        QVERIFY(waitForFinishedPathLoading(&view));
     }
 
     // Collapse URLs one by one and verify the result of DolphinDetailsView::expandedUrls()
index 77684984d1479374a4e32d02ae9561f225dcb008..f357ce60c0c353f6ee95882377de9f130c7dc2b5 100644 (file)
@@ -198,7 +198,7 @@ void DolphinViewTest_AllViewModes::testViewPropertySettings()
     // Show hidden files. This triggers the dir lister
     // -> we have to wait until loading the hidden files is finished
     view.setShowHiddenFiles(true);
-    QVERIFY(QTest::kWaitForSignal(&view, SIGNAL(finishedPathLoading(const KUrl&)), 2000));
+    QVERIFY(waitForFinishedPathLoading(&view));
     QVERIFY(view.showHiddenFiles());
     QCOMPARE(viewItems(&view), QStringList() << ".f" << "a" << "b" << "c" << "d" << "e");
 
@@ -324,12 +324,12 @@ void DolphinViewTest_AllViewModes::testSaveAndRestoreState()
 
     // Change the URL
     view.setUrl(dir.name() + "51");
-    QVERIFY(QTest::kWaitForSignal(&view, SIGNAL(finishedPathLoading(const KUrl&)), 2000));
+    QVERIFY(waitForFinishedPathLoading(&view));
     qApp->sendPostedEvents();
 
     // Go back, but do not call DolphinView::restoreState()
     view.setUrl(dir.url());
-    QVERIFY(QTest::kWaitForSignal(&view, SIGNAL(finishedPathLoading(const KUrl&)), 2000));
+    QVERIFY(waitForFinishedPathLoading(&view));
     qApp->sendPostedEvents();
 
     // Verify that the view is scrolled to top-left corner and that item 45 is not the current item.
@@ -343,7 +343,7 @@ void DolphinViewTest_AllViewModes::testSaveAndRestoreState()
 
     // Change the URL again
     view.setUrl(dir.name() + "51");
-    QVERIFY(QTest::kWaitForSignal(&view, SIGNAL(finishedPathLoading(const KUrl&)), 2000));
+    QVERIFY(waitForFinishedPathLoading(&view));
     qApp->sendPostedEvents();
 
     // Check that the current item and scroll position are correct if DolphinView::restoreState()
@@ -351,7 +351,7 @@ void DolphinViewTest_AllViewModes::testSaveAndRestoreState()
     view.setUrl(dir.url());
     QDataStream restoreStream(viewState);
     view.restoreState(restoreStream);
-    QVERIFY(QTest::kWaitForSignal(&view, SIGNAL(finishedPathLoading(const KUrl&)), 2000));
+    QVERIFY(waitForFinishedPathLoading(&view));
     qApp->sendPostedEvents();
 
     QCOMPARE(itemView(&view)->currentIndex(), index45);
index 59c40fb947a0510475d267f1e75cf079ae289370..38909e671809e763a9ac83d738d7b3539fb39fcb 100644 (file)
@@ -33,10 +33,15 @@ QAbstractItemView* TestBase::itemView(const DolphinView* view)
     return view->m_viewAccessor.itemView();
 }
 
+bool TestBase::waitForFinishedPathLoading(DolphinView* view, int milliseconds)
+{
+    return QTest::kWaitForSignal(view, SIGNAL(finishedPathLoading(const KUrl&)), milliseconds);
+}
+
 void TestBase::reloadViewAndWait(DolphinView* view)
 {
     view->reload();
-    QVERIFY(QTest::kWaitForSignal(view, SIGNAL(finishedPathLoading(const KUrl&)), 2000));
+    QVERIFY(waitForFinishedPathLoading(view));
 }
 
 QStringList TestBase::viewItems(const DolphinView* view)
index 7034cbe4149fecdac7c587cc546dfdbba7f47e7a..5b5d7164e9e12dd8f154687b326eb98506794c24 100644 (file)
@@ -47,6 +47,12 @@ public:
     /** Returns the item view (icons, details, or columns) */
     static QAbstractItemView* itemView(const DolphinView* view);
 
+    /**
+     * Waits until the view emits its finishedPathLoading(const KUrl&) signal.
+     * Returns false if it is not received within the given number of milliseconds.
+     */
+    static bool waitForFinishedPathLoading(DolphinView* view, int milliseconds=2000);
+
     /** Reloads the view and waits for the finishedPathLoading(const KUrl&) signal. */
     static void reloadViewAndWait(DolphinView* view);