annotate ui/tests/downloadertest.cpp @ 45:c6125d73faf4

Move SSLConnection into it's own class
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 14 Mar 2014 16:40:53 +0000
parents 5910bf9016cd
children d28e2624c1d5
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>
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
6 #include "unistd.h"
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
7
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
8 void DownloaderTest::startServer(QString additionalOptions)
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
9 {
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
10 QFile serverConfig(serverConfigDir.path() + "/" + "hiawatha.conf");
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
11 QFile mimeConfig(serverConfigDir.path() + "/" + "mimetype.conf");
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
12 if (serverProc.state() == QProcess::Running) {
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
13 serverProc.close();
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
14 }
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
15 serverConfig.open(QIODevice::WriteOnly);
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
16 mimeConfig.open(QIODevice::WriteOnly);
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
17 mimeConfig.close(); /* just an empty file */
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
18
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
19 QTextStream configStream(&serverConfig);
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
20 qDebug() << "Config file name: " << serverConfig.fileName();
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
21 configStream <<
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
22 "Binding { " << endl <<
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
23 "Port = 44443 " << endl <<
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
24 "SSLcertFile = " << SOURCE_DIR <<
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
25 "/data/valid_ssl_bp_priv.pem" << endl <<
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
26 "Interface = 127.0.0.1" << endl <<
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
27 "}" << endl <<
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
28 "Hostname = 127.0.0.1" << endl <<
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
29 "WebsiteRoot = " << SOURCE_DIR << endl;
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
30 configStream.flush();
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
31
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
32 serverConfig.close();
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
33 serverProc.start();
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
34 serverProc.waitForStarted();
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
35 }
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
36
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37 void DownloaderTest::initTestCase() {
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38 QStringList arguments;
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39 serverProc.setProgram(HIAWATHA_EXECUTABLE);
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
40 arguments << "-d" << "-c" << serverConfigDir.path();
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
41 serverProc.setArguments(arguments);
45
c6125d73faf4 Move SSLConnection into it's own class
Andre Heinecke <aheinecke@intevation.de>
parents: 43
diff changeset
42 qRegisterMetaType<SSLConnection::ErrorCode>("SSLConnection::ErrorCode");
43
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
43 startServer();
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
44 QTest::qWait(1000); /* Wait for the server to settle */
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
45 }
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46
45
c6125d73faf4 Move SSLConnection into it's own class
Andre Heinecke <aheinecke@intevation.de>
parents: 43
diff changeset
47 void DownloaderTest::downloaderError(const QString &message, SSLConnection::ErrorCode error)
43
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
48 {
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
49 qDebug() << "Downloader Error: " << error << " Msg: " << message;
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
50 }
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
51
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
52 void DownloaderTest::testNewList()
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
53 {
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
54 QFile validCert(QString::fromLatin1(SOURCE_DIR) +
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
55 "/data/valid_ssl_bp.pem");
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
56 validCert.open(QIODevice::ReadOnly);
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
57
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
58 Downloader* downloader = new Downloader(this,
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
59 QString::fromLatin1("https://localhost:44443"),
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
60 validCert.readAll(),
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
61 QDateTime::currentDateTime(), // Last installed SW
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
62 QDateTime::fromString("2010", "YYYY"),
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
63 "/list-valid.txt",
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
64 "/random_2MB");
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
65 validCert.close();
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
66
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
67 QSignalSpy newListAvailable(downloader,
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
68 SIGNAL(newListAvailable(const QString&, const QDateTime&)));
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
69 QSignalSpy newSoftwareAvailable(downloader,
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
70 SIGNAL(newSoftwareAvailable(const QString&, const QDateTime&)));
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
71 QSignalSpy errors(downloader, SIGNAL(error(const QString &,
45
c6125d73faf4 Move SSLConnection into it's own class
Andre Heinecke <aheinecke@intevation.de>
parents: 43
diff changeset
72 SSLConnection::ErrorCode)));
c6125d73faf4 Move SSLConnection into it's own class
Andre Heinecke <aheinecke@intevation.de>
parents: 43
diff changeset
73 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
74 this, SLOT(downloaderError(const QString &, SSLConnection::ErrorCode)));
43
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
75
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
76 downloader->start();
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
77
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
78 int waited = 0;
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
79 while (newListAvailable.count() == 0 &&
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
80 errors.count() == 0 && waited < 20) {
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
81 QTest::qWait(200);
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
82 waited++;
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
83 }
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
84 QVERIFY(waited != 20);
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
85 QVERIFY(newListAvailable.count() == 1);
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
86 QVERIFY(newSoftwareAvailable.count() == 0);
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
87 QVERIFY(errors.count() == 0);
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
88 delete downloader;
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
89 }
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
90
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
91 void DownloaderTest::cleanupTestCase() {
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
92 if (serverProc.state() == QProcess::Running) {
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
93 serverProc.close();
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
94 }
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
95 }
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
96
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
97 QTEST_GUILESS_MAIN (DownloaderTest);
5910bf9016cd Add Downloadertest
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
98

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