annotate ui/tests/downloadertest.cpp @ 132:4691d9e3b1d3

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

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