diff ui/tests/downloadertest.cpp @ 48:3f8c2d46ded6

Add test for no connection handling
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 17 Mar 2014 11:20:37 +0000
parents 7e37c6033c81
children a7b8cb29f1f6
line wrap: on
line diff
--- a/ui/tests/downloadertest.cpp	Mon Mar 17 11:03:17 2014 +0000
+++ b/ui/tests/downloadertest.cpp	Mon Mar 17 11:20:37 2014 +0000
@@ -3,6 +3,7 @@
 
 #include <QTextStream>
 #include <QFile>
+#include <QVariant>
 #include "unistd.h"
 
 void DownloaderTest::startServer(QString additionalOptions)
@@ -63,6 +64,33 @@
     return retval;
 }
 
+void DownloaderTest::testNoConnection()
+{
+    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)));
+    downloader->start();
+
+    int waited = 0;
+    while (newListAvailable.count() == 0 &&
+            errors.count() == 0  && waited < 20) {
+        QTest::qWait(200);
+        waited++;
+    }
+    QVERIFY(waited != 20);
+
+    QList<QVariant> arguments = errors.takeFirst();
+
+    int error = arguments.at(1).toInt();
+
+    QVERIFY(error == SSLConnection::NoConnection);
+}
+
 void DownloaderTest::testNewList()
 {
     QFile validCert(QString::fromLatin1(SOURCE_DIR) +
@@ -92,7 +120,7 @@
     int waited = 0;
     while (newListAvailable.count() == 0 &&
             errors.count() == 0  && waited < 20) {
-        QTest::qWait(2000);
+        QTest::qWait(200);
         waited++;
     }
     QVERIFY(waited != 20);

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