summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-11-16 12:48:43 (GMT)
committerMontel Laurent <montel@kde.org>2016-11-16 12:48:43 (GMT)
commit5f14004230b4e75edb9833c9931a762a2f6b836e (patch)
tree0aa761a0cce1fcf4c0ecd77c79caa3e98fa0a2e1
parent549224ca465d59d94e40e6af547c2e171579ecce (diff)
improve autotest
-rw-r--r--webengineviewer/src/checkphishingurl/autotests/createphishingurldatabasejobtest.cpp16
-rw-r--r--webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp14
-rw-r--r--webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h5
-rw-r--r--webengineviewer/src/checkphishingurl/tests/createphishingurldatabasegui.cpp1
4 files changed, 29 insertions, 7 deletions
diff --git a/webengineviewer/src/checkphishingurl/autotests/createphishingurldatabasejobtest.cpp b/webengineviewer/src/checkphishingurl/autotests/createphishingurldatabasejobtest.cpp
index 890e924..b4a59cf 100644
--- a/webengineviewer/src/checkphishingurl/autotests/createphishingurldatabasejobtest.cpp
+++ b/webengineviewer/src/checkphishingurl/autotests/createphishingurldatabasejobtest.cpp
@@ -18,6 +18,7 @@
*/
#include "createphishingurldatabasejobtest.h"
+#include "../createphishingurldatabasejob.h"
#include <QTest>
@@ -45,10 +46,25 @@ CreatePhishingUrlDataBaseJobTest::~CreatePhishingUrlDataBaseJobTest()
void CreatePhishingUrlDataBaseJobTest::shouldCreateRequest_data()
{
+ QTest::addColumn<QString>("databasestate");
+ QTest::addColumn<WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownload>("downloadtype");
+ QTest::addColumn<QByteArray>("request");
+ QTest::newRow("fulldownload") << QString() << WebEngineViewer::CreatePhishingUrlDataBaseJob::FullDataBase << QByteArray("{\"client\":{\"clientId\":\"KDE\",\"clientVersion\":\"5.4.0\"},\"listUpdateRequests\":[{\"platformType\":\"WINDOWS\",\"state\":\"\",\"threatEntryType\":\"URL\",\"threatType\":\"MALWARE\"}]}");
+ QTest::newRow("fulldownloadwithdatabasestate") << QStringLiteral("foo") << WebEngineViewer::CreatePhishingUrlDataBaseJob::FullDataBase << QByteArray("{\"client\":{\"clientId\":\"KDE\",\"clientVersion\":\"5.4.0\"},\"listUpdateRequests\":[{\"platformType\":\"WINDOWS\",\"state\":\"\",\"threatEntryType\":\"URL\",\"threatType\":\"MALWARE\"}]}");
+ QTest::newRow("partialdownloadwithdatabasestate") << QStringLiteral("foo") << WebEngineViewer::CreatePhishingUrlDataBaseJob::UpdateDataBase << QByteArray("{\"client\":{\"clientId\":\"KDE\",\"clientVersion\":\"5.4.0\"},\"listUpdateRequests\":[{\"platformType\":\"WINDOWS\",\"state\":\"foo\",\"threatEntryType\":\"URL\",\"threatType\":\"MALWARE\"}]}");
}
void CreatePhishingUrlDataBaseJobTest::shouldCreateRequest()
{
+ QFETCH (QString, databasestate);
+ QFETCH (WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownload, downloadtype);
+ QFETCH (QByteArray, request);
+
+ WebEngineViewer::CreatePhishingUrlDataBaseJob job;
+ job.setDataBaseState(databasestate);
+ job.setDataBaseDownloadNeeded(downloadtype);
+ job.setUseCompactJson(true);
+ QCOMPARE(job.jsonRequest(), request);
}
diff --git a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp
index ce28ae8..8710e49 100644
--- a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp
+++ b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp
@@ -29,7 +29,8 @@ using namespace WebEngineViewer;
CreatePhishingUrlDataBaseJob::CreatePhishingUrlDataBaseJob(QObject *parent)
: QObject(parent),
- mDataBaseDownloadNeeded(FullDataBase)
+ mDataBaseDownloadNeeded(FullDataBase),
+ mUseCompactJson(true)
{
mNetworkAccessManager = new QNetworkAccessManager(this);
connect(mNetworkAccessManager, &QNetworkAccessManager::finished, this, &CreatePhishingUrlDataBaseJob::slotDownloadDataBaseFinished);
@@ -140,11 +141,7 @@ QByteArray CreatePhishingUrlDataBaseJob::jsonRequest() const
map.insert(QStringLiteral("listUpdateRequests"), listUpdateRequests);
const QJsonDocument postData = QJsonDocument::fromVariant(map);
-#ifdef DEBUG_JSON_REQUEST
- const QByteArray baPostData = postData.toJson();
-#else
- const QByteArray baPostData = postData.toJson(QJsonDocument::Compact);
-#endif
+ const QByteArray baPostData = postData.toJson(mUseCompactJson ? QJsonDocument::Compact : QJsonDocument::Indented);
//qDebug()<<" baPostData "<<baPostData;
return baPostData;
}
@@ -204,6 +201,11 @@ QVector<Addition> CreatePhishingUrlDataBaseJob::parseAdditions(const QVariantLis
return additionList;
}
+void CreatePhishingUrlDataBaseJob::setUseCompactJson(bool useCompactJson)
+{
+ mUseCompactJson = useCompactJson;
+}
+
QVector<Removal> CreatePhishingUrlDataBaseJob::parseRemovals(const QVariantList &lst)
{
QVector<Removal> removalList;
diff --git a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h
index 42efdb8..6dd4d59 100644
--- a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h
+++ b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h
@@ -94,6 +94,8 @@ public:
QByteArray jsonRequest() const;
+ void setUseCompactJson(bool useCompactJson);
+
Q_SIGNALS:
void finished(const WebEngineViewer::UpdateDataBaseInfo &infoDataBase, WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownloadResult status);
void debugJsonResult(const QByteArray &ba);
@@ -110,10 +112,11 @@ private:
QString mDataBaseState;
DataBaseDownload mDataBaseDownloadNeeded;
+ bool mUseCompactJson;
QNetworkAccessManager *mNetworkAccessManager;
};
}
-
+Q_DECLARE_METATYPE(WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownload)
Q_DECLARE_TYPEINFO(WebEngineViewer::Addition, Q_MOVABLE_TYPE);
Q_DECLARE_TYPEINFO(WebEngineViewer::Removal, Q_MOVABLE_TYPE);
#endif // CREATEPHISHINGURLDATABASEJOB_H
diff --git a/webengineviewer/src/checkphishingurl/tests/createphishingurldatabasegui.cpp b/webengineviewer/src/checkphishingurl/tests/createphishingurldatabasegui.cpp
index a530652..d93e304 100644
--- a/webengineviewer/src/checkphishingurl/tests/createphishingurldatabasegui.cpp
+++ b/webengineviewer/src/checkphishingurl/tests/createphishingurldatabasegui.cpp
@@ -57,6 +57,7 @@ CreatePhisingUrlDataBaseGui::~CreatePhisingUrlDataBaseGui()
void CreatePhisingUrlDataBaseGui::slotDownloadFullDatabase()
{
WebEngineViewer::CreatePhishingUrlDataBaseJob *job = new WebEngineViewer::CreatePhishingUrlDataBaseJob(this);
+ job->setUseCompactJson(false);
connect(job, &WebEngineViewer::CreatePhishingUrlDataBaseJob::debugJsonResult, this, &CreatePhisingUrlDataBaseGui::slotResult);
connect(job, &WebEngineViewer::CreatePhishingUrlDataBaseJob::debugJson, this, &CreatePhisingUrlDataBaseGui::slotDebugJSon);
job->start();