comparison 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
comparison
equal deleted inserted replaced
47:7e37c6033c81 48:3f8c2d46ded6
1 #include "downloadertest.h" 1 #include "downloadertest.h"
2 #include "downloader.h" 2 #include "downloader.h"
3 3
4 #include <QTextStream> 4 #include <QTextStream>
5 #include <QFile> 5 #include <QFile>
6 #include <QVariant>
6 #include "unistd.h" 7 #include "unistd.h"
7 8
8 void DownloaderTest::startServer(QString additionalOptions) 9 void DownloaderTest::startServer(QString additionalOptions)
9 { 10 {
10 QFile serverConfig(serverConfigDir.path() + "/" + "hiawatha.conf"); 11 QFile serverConfig(serverConfigDir.path() + "/" + "hiawatha.conf");
61 file1.close(); 62 file1.close();
62 file2.close(); 63 file2.close();
63 return retval; 64 return retval;
64 } 65 }
65 66
67 void DownloaderTest::testNoConnection()
68 {
69 Downloader* downloader = new Downloader(this,
70 QString::fromLatin1("https://foobar.intevation.de"));
71 QSignalSpy newListAvailable(downloader,
72 SIGNAL(newListAvailable(const QString&, const QDateTime&)));
73 QSignalSpy newSoftwareAvailable(downloader,
74 SIGNAL(newSoftwareAvailable(const QString&, const QDateTime&)));
75 QSignalSpy errors(downloader, SIGNAL(error(const QString &,
76 SSLConnection::ErrorCode)));
77 downloader->start();
78
79 int waited = 0;
80 while (newListAvailable.count() == 0 &&
81 errors.count() == 0 && waited < 20) {
82 QTest::qWait(200);
83 waited++;
84 }
85 QVERIFY(waited != 20);
86
87 QList<QVariant> arguments = errors.takeFirst();
88
89 int error = arguments.at(1).toInt();
90
91 QVERIFY(error == SSLConnection::NoConnection);
92 }
93
66 void DownloaderTest::testNewList() 94 void DownloaderTest::testNewList()
67 { 95 {
68 QFile validCert(QString::fromLatin1(SOURCE_DIR) + 96 QFile validCert(QString::fromLatin1(SOURCE_DIR) +
69 "/data/valid_ssl_bp.pem"); 97 "/data/valid_ssl_bp.pem");
70 validCert.open(QIODevice::ReadOnly); 98 validCert.open(QIODevice::ReadOnly);
90 downloader->start(); 118 downloader->start();
91 119
92 int waited = 0; 120 int waited = 0;
93 while (newListAvailable.count() == 0 && 121 while (newListAvailable.count() == 0 &&
94 errors.count() == 0 && waited < 20) { 122 errors.count() == 0 && waited < 20) {
95 QTest::qWait(2000); 123 QTest::qWait(200);
96 waited++; 124 waited++;
97 } 125 }
98 QVERIFY(waited != 20); 126 QVERIFY(waited != 20);
99 QVERIFY(newListAvailable.count() == 1); 127 QVERIFY(newListAvailable.count() == 1);
100 QVERIFY(newSoftwareAvailable.count() == 0); 128 QVERIFY(newSoftwareAvailable.count() == 0);

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