diff ui/tests/downloadertest.cpp @ 51:78633b2b580c

Add macro for common signal setup tasks
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 17 Mar 2014 11:38:13 +0000
parents a7b8cb29f1f6
children d73a2f0170d4
line wrap: on
line diff
--- a/ui/tests/downloadertest.cpp	Mon Mar 17 11:36:42 2014 +0000
+++ b/ui/tests/downloadertest.cpp	Mon Mar 17 11:38:13 2014 +0000
@@ -6,6 +6,16 @@
 #include <QVariant>
 #include "unistd.h"
 
+#define MAX_WAIT 20
+
+#define SETUP_SPY \
+    QSignalSpy newListAvailable(downloader,                                 \
+            SIGNAL(newListAvailable(const QString&, const QDateTime&)));    \
+    QSignalSpy newSoftwareAvailable(downloader,                             \
+           SIGNAL(newSoftwareAvailable(const QString&, const QDateTime&))); \
+    QSignalSpy errors(downloader, SIGNAL(error(const QString &,             \
+                    SSLConnection::ErrorCode)));                            \
+
 void DownloaderTest::startServer(QString additionalOptions)
 {
     QFile serverConfig(serverConfigDir.path() + "/" + "hiawatha.conf");
@@ -68,21 +78,20 @@
 {
     Downloader* downloader = new Downloader(this,
             QString::fromLatin1("https://foobar.intevation.de"));
-    QSignalSpy newListAvailable(downloader,
-            SIGNAL(newListAvailable(const QString&, const QDateTime&)));
-    QSignalSpy newSoftwareAvailable(downloader,
-           SIGNAL(newSoftwareAvailable(const QString&, const QDateTime&)));
-    QSignalSpy errors(downloader, SIGNAL(error(const QString &,
-                    SSLConnection::ErrorCode)));
+
+    SETUP_SPY
+
     downloader->start();
 
     int waited = 0;
     while (newListAvailable.count() == 0 &&
-            errors.count() == 0  && waited < 20) {
+            errors.count() == 0  && waited < MAX_WAIT) {
         QTest::qWait(200);
         waited++;
     }
-    QVERIFY(waited != 20);
+    QVERIFY(waited != MAX_WAIT);
+    QVERIFY(newListAvailable.count() == 0);
+    QVERIFY(newSoftwareAvailable.count() == 0);
 
     QList<QVariant> arguments = errors.takeFirst();
 
@@ -106,12 +115,8 @@
             "/list-valid.txt");
     validCert.close();
 
-    QSignalSpy newListAvailable(downloader,
-            SIGNAL(newListAvailable(const QString&, const QDateTime&)));
-    QSignalSpy newSoftwareAvailable(downloader,
-           SIGNAL(newSoftwareAvailable(const QString&, const QDateTime&)));
-    QSignalSpy errors(downloader, SIGNAL(error(const QString &,
-                    SSLConnection::ErrorCode)));
+    SETUP_SPY
+
     connect(downloader, SIGNAL(error(const QString &, SSLConnection::ErrorCode)),
             this, SLOT(downloaderError(const QString &, SSLConnection::ErrorCode)));
 

http://wald.intevation.org/projects/trustbridge/