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