comparison ui/tests/downloadertest.cpp @ 243:4b67cc2d4dad

Merged
author Sascha Wilde <wilde@intevation.de>
date Fri, 28 Mar 2014 18:38:34 +0100
parents c05e126b0b9e
children 17e1c8f37d72
comparison
equal deleted inserted replaced
242:809eaca3898c 243:4b67cc2d4dad
1 #include "downloadertest.h" 1 #include "downloadertest.h"
2 #include "downloader.h" 2 #include "downloader.h"
3 #include "common.h"
3 4
4 #include <QTextStream> 5 #include <QTextStream>
5 #include <QFile> 6 #include <QFile>
6 #include <QVariant> 7 #include <QVariant>
7 #include "unistd.h" 8 #include <unistd.h>
8 9
9 #define MAX_WAIT 20 10 #define MAX_WAIT 20
10 11
11 #define SETUP_SPY \ 12 #define SETUP_SPY \
12 QSignalSpy newListAvailable(downloader, \ 13 QSignalSpy newListAvailable(downloader, \
26 serverConfig.open(QIODevice::WriteOnly); 27 serverConfig.open(QIODevice::WriteOnly);
27 mimeConfig.open(QIODevice::WriteOnly); 28 mimeConfig.open(QIODevice::WriteOnly);
28 mimeConfig.close(); /* just an empty file */ 29 mimeConfig.close(); /* just an empty file */
29 30
30 QTextStream configStream(&serverConfig); 31 QTextStream configStream(&serverConfig);
31 qDebug() << "Config file name: " << serverConfig.fileName();
32 configStream << 32 configStream <<
33 "Binding { " << endl << 33 "Binding { " << endl <<
34 "Port = 44443 " << endl << 34 "Port = 44443 " << endl <<
35 "SSLcertFile = " << SOURCE_DIR << 35 "SSLcertFile = " << SOURCE_DIR <<
36 "/data/valid_ssl_bp_priv.pem" << endl << 36 "/data/valid_ssl_bp_priv.pem" << endl <<
37 "Interface = 127.0.0.1" << endl << 37 "Interface = 127.0.0.1" << endl <<
38 "}" << endl << 38 "}" << endl <<
39 "Hostname = 127.0.0.1" << endl << 39 "Hostname = 127.0.0.1" << endl <<
40 "WebsiteRoot = " << SOURCE_DIR << "/data" << endl; 40 "WebsiteRoot = " << serverConfigDir.path() << endl;
41 configStream.flush(); 41 configStream.flush();
42 42
43 serverConfig.close(); 43 serverConfig.close();
44 serverProc.start(); 44 serverProc.start();
45 serverProc.waitForStarted(); 45 serverProc.waitForStarted();
50 serverProc.setProgram(HIAWATHA_EXECUTABLE); 50 serverProc.setProgram(HIAWATHA_EXECUTABLE);
51 arguments << "-d" << "-c" << serverConfigDir.path(); 51 arguments << "-d" << "-c" << serverConfigDir.path();
52 serverProc.setArguments(arguments); 52 serverProc.setArguments(arguments);
53 qRegisterMetaType<SSLConnection::ErrorCode>("SSLConnection::ErrorCode"); 53 qRegisterMetaType<SSLConnection::ErrorCode>("SSLConnection::ErrorCode");
54 startServer(); 54 startServer();
55 garbageInfo = QFileInfo(getRandomDataFile(2 * 1024, serverConfigDir.path()));
56 QVERIFY(QFile::copy(QString::fromLocal8Bit(SOURCE_DIR"/data/list-valid.txt"),
57 serverConfigDir.path() + "/" + "list-valid.txt"));
58
55 QTest::qWait(1000); /* Wait for the server to settle */ 59 QTest::qWait(1000); /* Wait for the server to settle */
56 } 60 }
57 61
58 void DownloaderTest::downloaderError(const QString &message, SSLConnection::ErrorCode error) 62 void DownloaderTest::downloaderError(const QString &message, SSLConnection::ErrorCode error)
59 { 63 {
78 { 82 {
79 QFile otherCert(QString::fromLatin1(SOURCE_DIR) + 83 QFile otherCert(QString::fromLatin1(SOURCE_DIR) +
80 "/data/valid_ssl_rsa.pem"); 84 "/data/valid_ssl_rsa.pem");
81 otherCert.open(QIODevice::ReadOnly); 85 otherCert.open(QIODevice::ReadOnly);
82 86
87 QFileInfo fi(getRandomDataFile(200));
88
83 Downloader* downloader = new Downloader(this, 89 Downloader* downloader = new Downloader(this,
84 QString::fromLatin1("https://localhost:44443"), 90 QString::fromLatin1("https://localhost:44443"),
85 otherCert.readAll(), 91 otherCert.readAll(),
86 QDateTime::currentDateTime(), // Last installed SW 92 QDateTime::currentDateTime(), // Last installed SW
87 QDateTime::fromString("2010", "YYYY"), 93 QDateTime::fromString("2010", "YYYY"),
88 "/garbage_2MB", 94 "/" + garbageInfo.fileName(),
89 "/list-valid.txt"); 95 "/list-valid.txt");
90 otherCert.close(); 96 otherCert.close();
91 97
92 SETUP_SPY 98 SETUP_SPY
93 99
144 Downloader* downloader = new Downloader(this, 150 Downloader* downloader = new Downloader(this,
145 QString::fromLatin1("https://localhost:44443"), 151 QString::fromLatin1("https://localhost:44443"),
146 validCert.readAll(), 152 validCert.readAll(),
147 QDateTime::fromString("2010", "YYYY"), 153 QDateTime::fromString("2010", "YYYY"),
148 QDateTime::currentDateTime(), 154 QDateTime::currentDateTime(),
149 "/garbage_2MB", 155 "/" + garbageInfo.fileName(),
150 "/list-valid.txt"); 156 "/list-valid.txt");
151 validCert.close(); 157 validCert.close();
152 158
153 SETUP_SPY 159 SETUP_SPY
154 160
168 QVERIFY(newSoftwareAvailable.count() == 1); 174 QVERIFY(newSoftwareAvailable.count() == 1);
169 QVERIFY(errors.count() == 0); 175 QVERIFY(errors.count() == 0);
170 176
171 QList<QVariant> arguments = newSoftwareAvailable.takeFirst(); 177 QList<QVariant> arguments = newSoftwareAvailable.takeFirst();
172 178
173 QVERIFY(filesEqual(QString::fromLatin1(SOURCE_DIR) + "/data/garbage_2MB", 179 QVERIFY(filesEqual(serverConfigDir.path() + "/" + garbageInfo.fileName(),
174 arguments.at(0).toString())); 180 arguments.at(0).toString()));
175 181
176 delete downloader; 182 delete downloader;
177 } 183 }
178 184
185 Downloader* downloader = new Downloader(this, 191 Downloader* downloader = new Downloader(this,
186 QString::fromLatin1("https://localhost:44443"), 192 QString::fromLatin1("https://localhost:44443"),
187 validCert.readAll(), 193 validCert.readAll(),
188 QDateTime::currentDateTime(), // Last installed SW 194 QDateTime::currentDateTime(), // Last installed SW
189 QDateTime::fromString("2010", "YYYY"), 195 QDateTime::fromString("2010", "YYYY"),
190 "/garbage_2MB", 196 "/" + garbageInfo.fileName(),
191 "/list-valid.txt"); 197 "/list-valid.txt");
192 validCert.close(); 198 validCert.close();
193 199
194 SETUP_SPY 200 SETUP_SPY
195 201

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