Mercurial > trustbridge
annotate ui/tests/downloadertest.cpp @ 810:ee75e236843c
Use sudo to install software in case of is_admin
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Tue, 15 Jul 2014 16:31:24 +0200 |
parents | 17e1c8f37d72 |
children | eaed02defe6a |
rev | line source |
---|---|
404 | 1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU GPL (v>=2) | |
5 * and comes with ABSOLUTELY NO WARRANTY! | |
6 * See LICENSE.txt for details. | |
7 */ | |
43 | 8 #include "downloadertest.h" |
9 #include "downloader.h" | |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
10 #include "common.h" |
43 | 11 |
12 #include <QTextStream> | |
13 #include <QFile> | |
48
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
14 #include <QVariant> |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
15 #include <unistd.h> |
43 | 16 |
51
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
17 #define MAX_WAIT 20 |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
18 |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
19 #define SETUP_SPY \ |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
20 QSignalSpy newListAvailable(downloader, \ |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
21 SIGNAL(newListAvailable(const QString&, const QDateTime&))); \ |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
22 QSignalSpy newSoftwareAvailable(downloader, \ |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
23 SIGNAL(newSoftwareAvailable(const QString&, const QDateTime&))); \ |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
24 QSignalSpy errors(downloader, SIGNAL(error(const QString &, \ |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
25 SSLConnection::ErrorCode))); \ |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
26 |
43 | 27 void DownloaderTest::startServer(QString additionalOptions) |
28 { | |
29 QFile serverConfig(serverConfigDir.path() + "/" + "hiawatha.conf"); | |
30 QFile mimeConfig(serverConfigDir.path() + "/" + "mimetype.conf"); | |
31 if (serverProc.state() == QProcess::Running) { | |
32 serverProc.close(); | |
33 } | |
34 serverConfig.open(QIODevice::WriteOnly); | |
35 mimeConfig.open(QIODevice::WriteOnly); | |
36 mimeConfig.close(); /* just an empty file */ | |
37 | |
38 QTextStream configStream(&serverConfig); | |
39 configStream << | |
40 "Binding { " << endl << | |
41 "Port = 44443 " << endl << | |
42 "SSLcertFile = " << SOURCE_DIR << | |
43 "/data/valid_ssl_bp_priv.pem" << endl << | |
44 "Interface = 127.0.0.1" << endl << | |
45 "}" << endl << | |
46 "Hostname = 127.0.0.1" << endl << | |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
47 "WebsiteRoot = " << serverConfigDir.path() << endl; |
43 | 48 configStream.flush(); |
49 | |
50 serverConfig.close(); | |
51 serverProc.start(); | |
52 serverProc.waitForStarted(); | |
53 } | |
54 | |
55 void DownloaderTest::initTestCase() { | |
56 QStringList arguments; | |
57 serverProc.setProgram(HIAWATHA_EXECUTABLE); | |
58 arguments << "-d" << "-c" << serverConfigDir.path(); | |
59 serverProc.setArguments(arguments); | |
45
c6125d73faf4
Move SSLConnection into it's own class
Andre Heinecke <aheinecke@intevation.de>
parents:
43
diff
changeset
|
60 qRegisterMetaType<SSLConnection::ErrorCode>("SSLConnection::ErrorCode"); |
43 | 61 startServer(); |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
62 garbageInfo = QFileInfo(getRandomDataFile(2 * 1024, serverConfigDir.path())); |
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
63 QVERIFY(QFile::copy(QString::fromLocal8Bit(SOURCE_DIR"/data/list-valid.txt"), |
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
64 serverConfigDir.path() + "/" + "list-valid.txt")); |
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
65 |
43 | 66 QTest::qWait(1000); /* Wait for the server to settle */ |
67 } | |
68 | |
45
c6125d73faf4
Move SSLConnection into it's own class
Andre Heinecke <aheinecke@intevation.de>
parents:
43
diff
changeset
|
69 void DownloaderTest::downloaderError(const QString &message, SSLConnection::ErrorCode error) |
43 | 70 { |
71 qDebug() << "Downloader Error: " << error << " Msg: " << message; | |
72 } | |
73 | |
47
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
74 bool filesEqual(QString filename1, QString filename2) |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
75 { |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
76 bool retval = false; |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
77 QFile file1(filename1); |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
78 QFile file2(filename2); |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
79 file1.open(QIODevice::ReadOnly); |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
80 file2.open(QIODevice::ReadOnly); |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
81 |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
82 retval = (file1.readAll() == file2.readAll()); |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
83 file1.close(); |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
84 file2.close(); |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
85 return retval; |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
86 } |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
87 |
52
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
88 void DownloaderTest::testOtherCertificate() |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
89 { |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
90 QFile otherCert(QString::fromLatin1(SOURCE_DIR) + |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
91 "/data/valid_ssl_rsa.pem"); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
92 otherCert.open(QIODevice::ReadOnly); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
93 |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
94 QFileInfo fi(getRandomDataFile(200)); |
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
95 |
52
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
96 Downloader* downloader = new Downloader(this, |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
97 QString::fromLatin1("https://localhost:44443"), |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
98 otherCert.readAll(), |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
99 QDateTime::currentDateTime(), // Last installed SW |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
100 QDateTime::fromString("2010", "YYYY"), |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
101 "/" + garbageInfo.fileName(), |
52
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
102 "/list-valid.txt"); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
103 otherCert.close(); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
104 |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
105 SETUP_SPY |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
106 |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
107 downloader->start(); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
108 |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
109 int waited = 0; |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
110 while (errors.count() == 0 && waited < MAX_WAIT) { |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
111 QTest::qWait(200); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
112 waited++; |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
113 } |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
114 QVERIFY(waited != MAX_WAIT); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
115 QVERIFY(newListAvailable.count() == 0); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
116 QVERIFY(newSoftwareAvailable.count() == 0); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
117 |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
118 QList<QVariant> arguments = errors.takeFirst(); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
119 |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
120 int error = arguments.at(1).toInt(); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
121 |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
122 QVERIFY(error == SSLConnection::InvalidCertificate); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
123 } |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
124 |
48
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
125 void DownloaderTest::testNoConnection() |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
126 { |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
127 Downloader* downloader = new Downloader(this, |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
128 QString::fromLatin1("https://foobar.intevation.de")); |
51
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
129 |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
130 SETUP_SPY |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
131 |
48
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
132 downloader->start(); |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
133 |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
134 int waited = 0; |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
135 while (newListAvailable.count() == 0 && |
51
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
136 errors.count() == 0 && waited < MAX_WAIT) { |
48
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
137 QTest::qWait(200); |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
138 waited++; |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
139 } |
51
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
140 QVERIFY(waited != MAX_WAIT); |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
141 QVERIFY(newListAvailable.count() == 0); |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
142 QVERIFY(newSoftwareAvailable.count() == 0); |
48
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
143 |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
144 QList<QVariant> arguments = errors.takeFirst(); |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
145 |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
146 int error = arguments.at(1).toInt(); |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
147 |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
148 QVERIFY(error == SSLConnection::NoConnection); |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
149 } |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
150 |
55
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
151 void DownloaderTest::testNewSoftware() |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
152 { |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
153 QFile validCert(QString::fromLatin1(SOURCE_DIR) + |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
154 "/data/valid_ssl_bp.pem"); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
155 validCert.open(QIODevice::ReadOnly); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
156 |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
157 Downloader* downloader = new Downloader(this, |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
158 QString::fromLatin1("https://localhost:44443"), |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
159 validCert.readAll(), |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
160 QDateTime::fromString("2010", "YYYY"), |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
161 QDateTime::currentDateTime(), |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
162 "/" + garbageInfo.fileName(), |
55
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
163 "/list-valid.txt"); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
164 validCert.close(); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
165 |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
166 SETUP_SPY |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
167 |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
168 connect(downloader, SIGNAL(error(const QString &, SSLConnection::ErrorCode)), |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
169 this, SLOT(downloaderError(const QString &, SSLConnection::ErrorCode))); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
170 |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
171 downloader->start(); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
172 |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
173 int waited = 0; |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
174 while (newSoftwareAvailable.count() == 0 && |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
175 errors.count() == 0 && waited < 20) { |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
176 QTest::qWait(200); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
177 waited++; |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
178 } |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
179 QVERIFY(waited != 20); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
180 QVERIFY(newListAvailable.count() == 0); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
181 QVERIFY(newSoftwareAvailable.count() == 1); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
182 QVERIFY(errors.count() == 0); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
183 |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
184 QList<QVariant> arguments = newSoftwareAvailable.takeFirst(); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
185 |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
186 QVERIFY(filesEqual(serverConfigDir.path() + "/" + garbageInfo.fileName(), |
55
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
187 arguments.at(0).toString())); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
188 |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
189 delete downloader; |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
190 } |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
191 |
43 | 192 void DownloaderTest::testNewList() |
193 { | |
194 QFile validCert(QString::fromLatin1(SOURCE_DIR) + | |
195 "/data/valid_ssl_bp.pem"); | |
196 validCert.open(QIODevice::ReadOnly); | |
197 | |
198 Downloader* downloader = new Downloader(this, | |
199 QString::fromLatin1("https://localhost:44443"), | |
200 validCert.readAll(), | |
201 QDateTime::currentDateTime(), // Last installed SW | |
202 QDateTime::fromString("2010", "YYYY"), | |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
203 "/" + garbageInfo.fileName(), |
46
d28e2624c1d5
Reset connection before the next request.
Andre Heinecke <aheinecke@intevation.de>
parents:
45
diff
changeset
|
204 "/list-valid.txt"); |
43 | 205 validCert.close(); |
206 | |
51
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
207 SETUP_SPY |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
208 |
45
c6125d73faf4
Move SSLConnection into it's own class
Andre Heinecke <aheinecke@intevation.de>
parents:
43
diff
changeset
|
209 connect(downloader, SIGNAL(error(const QString &, SSLConnection::ErrorCode)), |
c6125d73faf4
Move SSLConnection into it's own class
Andre Heinecke <aheinecke@intevation.de>
parents:
43
diff
changeset
|
210 this, SLOT(downloaderError(const QString &, SSLConnection::ErrorCode))); |
43 | 211 |
212 downloader->start(); | |
213 | |
214 int waited = 0; | |
215 while (newListAvailable.count() == 0 && | |
216 errors.count() == 0 && waited < 20) { | |
48
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
217 QTest::qWait(200); |
43 | 218 waited++; |
219 } | |
220 QVERIFY(waited != 20); | |
221 QVERIFY(newListAvailable.count() == 1); | |
222 QVERIFY(newSoftwareAvailable.count() == 0); | |
223 QVERIFY(errors.count() == 0); | |
47
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
224 |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
225 QList<QVariant> arguments = newListAvailable.takeFirst(); |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
226 |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
227 QVERIFY(filesEqual(QString::fromLatin1(SOURCE_DIR) + "/data/list-valid.txt", |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
228 arguments.at(0).toString())); |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
229 |
43 | 230 delete downloader; |
231 } | |
232 | |
233 void DownloaderTest::cleanupTestCase() { | |
234 if (serverProc.state() == QProcess::Running) { | |
235 serverProc.close(); | |
236 } | |
237 } | |
238 | |
239 QTEST_GUILESS_MAIN (DownloaderTest); | |
240 |