Mercurial > trustbridge
comparison 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 |
comparison
equal
deleted
inserted
replaced
50:a7b8cb29f1f6 | 51:78633b2b580c |
---|---|
3 | 3 |
4 #include <QTextStream> | 4 #include <QTextStream> |
5 #include <QFile> | 5 #include <QFile> |
6 #include <QVariant> | 6 #include <QVariant> |
7 #include "unistd.h" | 7 #include "unistd.h" |
8 | |
9 #define MAX_WAIT 20 | |
10 | |
11 #define SETUP_SPY \ | |
12 QSignalSpy newListAvailable(downloader, \ | |
13 SIGNAL(newListAvailable(const QString&, const QDateTime&))); \ | |
14 QSignalSpy newSoftwareAvailable(downloader, \ | |
15 SIGNAL(newSoftwareAvailable(const QString&, const QDateTime&))); \ | |
16 QSignalSpy errors(downloader, SIGNAL(error(const QString &, \ | |
17 SSLConnection::ErrorCode))); \ | |
8 | 18 |
9 void DownloaderTest::startServer(QString additionalOptions) | 19 void DownloaderTest::startServer(QString additionalOptions) |
10 { | 20 { |
11 QFile serverConfig(serverConfigDir.path() + "/" + "hiawatha.conf"); | 21 QFile serverConfig(serverConfigDir.path() + "/" + "hiawatha.conf"); |
12 QFile mimeConfig(serverConfigDir.path() + "/" + "mimetype.conf"); | 22 QFile mimeConfig(serverConfigDir.path() + "/" + "mimetype.conf"); |
66 | 76 |
67 void DownloaderTest::testNoConnection() | 77 void DownloaderTest::testNoConnection() |
68 { | 78 { |
69 Downloader* downloader = new Downloader(this, | 79 Downloader* downloader = new Downloader(this, |
70 QString::fromLatin1("https://foobar.intevation.de")); | 80 QString::fromLatin1("https://foobar.intevation.de")); |
71 QSignalSpy newListAvailable(downloader, | 81 |
72 SIGNAL(newListAvailable(const QString&, const QDateTime&))); | 82 SETUP_SPY |
73 QSignalSpy newSoftwareAvailable(downloader, | 83 |
74 SIGNAL(newSoftwareAvailable(const QString&, const QDateTime&))); | |
75 QSignalSpy errors(downloader, SIGNAL(error(const QString &, | |
76 SSLConnection::ErrorCode))); | |
77 downloader->start(); | 84 downloader->start(); |
78 | 85 |
79 int waited = 0; | 86 int waited = 0; |
80 while (newListAvailable.count() == 0 && | 87 while (newListAvailable.count() == 0 && |
81 errors.count() == 0 && waited < 20) { | 88 errors.count() == 0 && waited < MAX_WAIT) { |
82 QTest::qWait(200); | 89 QTest::qWait(200); |
83 waited++; | 90 waited++; |
84 } | 91 } |
85 QVERIFY(waited != 20); | 92 QVERIFY(waited != MAX_WAIT); |
93 QVERIFY(newListAvailable.count() == 0); | |
94 QVERIFY(newSoftwareAvailable.count() == 0); | |
86 | 95 |
87 QList<QVariant> arguments = errors.takeFirst(); | 96 QList<QVariant> arguments = errors.takeFirst(); |
88 | 97 |
89 int error = arguments.at(1).toInt(); | 98 int error = arguments.at(1).toInt(); |
90 | 99 |
104 QDateTime::fromString("2010", "YYYY"), | 113 QDateTime::fromString("2010", "YYYY"), |
105 "/garbage_2MB", | 114 "/garbage_2MB", |
106 "/list-valid.txt"); | 115 "/list-valid.txt"); |
107 validCert.close(); | 116 validCert.close(); |
108 | 117 |
109 QSignalSpy newListAvailable(downloader, | 118 SETUP_SPY |
110 SIGNAL(newListAvailable(const QString&, const QDateTime&))); | 119 |
111 QSignalSpy newSoftwareAvailable(downloader, | |
112 SIGNAL(newSoftwareAvailable(const QString&, const QDateTime&))); | |
113 QSignalSpy errors(downloader, SIGNAL(error(const QString &, | |
114 SSLConnection::ErrorCode))); | |
115 connect(downloader, SIGNAL(error(const QString &, SSLConnection::ErrorCode)), | 120 connect(downloader, SIGNAL(error(const QString &, SSLConnection::ErrorCode)), |
116 this, SLOT(downloaderError(const QString &, SSLConnection::ErrorCode))); | 121 this, SLOT(downloaderError(const QString &, SSLConnection::ErrorCode))); |
117 | 122 |
118 downloader->start(); | 123 downloader->start(); |
119 | 124 |