summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-11-20 07:17:45 (GMT)
committerMontel Laurent <montel@kde.org>2016-11-20 07:17:45 (GMT)
commit8094abcc664a3e0c324fabab268cab3fc0b47624 (patch)
tree1d2151fb4ab1ae345d3830b2e9fe79bd3a0d154f
parentcb62494470bc56b85b16592228891bb437d4bc22 (diff)
Add test apps
-rw-r--r--webengineviewer/src/checkphishingurl/tests/CMakeLists.txt10
-rw-r--r--webengineviewer/src/checkphishingurl/tests/searchfullhashgui.cpp118
-rw-r--r--webengineviewer/src/checkphishingurl/tests/searchfullhashgui.h43
3 files changed, 171 insertions, 0 deletions
diff --git a/webengineviewer/src/checkphishingurl/tests/CMakeLists.txt b/webengineviewer/src/checkphishingurl/tests/CMakeLists.txt
index 8c2d68f..c429316 100644
--- a/webengineviewer/src/checkphishingurl/tests/CMakeLists.txt
+++ b/webengineviewer/src/checkphishingurl/tests/CMakeLists.txt
@@ -13,6 +13,16 @@ target_link_libraries(checkphishingurlgui
KF5::I18n
)
+set(searchfullhashgui_SRCS searchfullhashgui.cpp)
+add_executable(searchfullhashgui ${searchfullhashgui_SRCS})
+target_link_libraries(searchfullhashgui
+ KF5::KIOCore
+ KF5::WebEngineViewer
+ Qt5::WebEngine
+ Qt5::WebEngineWidgets
+ KF5::I18n
+ )
+
set(createphishingurldatabasegui_SRCS createphishingurldatabasegui.cpp)
add_executable(createphishingurldatabasegui ${createphishingurldatabasegui_SRCS})
target_link_libraries(createphishingurldatabasegui
diff --git a/webengineviewer/src/checkphishingurl/tests/searchfullhashgui.cpp b/webengineviewer/src/checkphishingurl/tests/searchfullhashgui.cpp
new file mode 100644
index 0000000..1821805
--- /dev/null
+++ b/webengineviewer/src/checkphishingurl/tests/searchfullhashgui.cpp
@@ -0,0 +1,118 @@
+/*
+ Copyright (C) 2016 Laurent Montel <montel@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "searchfullhashgui.h"
+
+#include <QApplication>
+#include <QStandardPaths>
+#include <QLineEdit>
+#include <QPushButton>
+#include <QTextEdit>
+#include <QLabel>
+#include <QVBoxLayout>
+
+SearchFullHashGui::SearchFullHashGui(QWidget *parent)
+ : QWidget(parent)
+{
+ QVBoxLayout *layout = new QVBoxLayout(this);
+
+ QHBoxLayout *checkUrlLayout = new QHBoxLayout;
+ layout->addLayout(checkUrlLayout);
+ QLabel *lab = new QLabel(QStringLiteral("Url to Check:"), this);
+ checkUrlLayout->addWidget(lab);
+ mCheckUrlLineEdit = new QLineEdit(this);
+ checkUrlLayout->addWidget(mCheckUrlLineEdit);
+ QPushButton *button = new QPushButton(QStringLiteral("Check"), this);
+ checkUrlLayout->addWidget(button);
+ connect(button, &QPushButton::clicked, this, &SearchFullHashGui::slotCheckUrl);
+ connect(mCheckUrlLineEdit, &QLineEdit::returnPressed, this, &SearchFullHashGui::slotCheckUrl);
+
+ mResult = new QTextEdit(this);
+ mResult->setReadOnly(true);
+ mResult->setAcceptRichText(false);
+ layout->addWidget(mResult);
+
+ mJson = new QTextEdit(this);
+ mJson->setReadOnly(true);
+ mJson->setAcceptRichText(false);
+ layout->addWidget(mJson);
+
+}
+
+SearchFullHashGui::~SearchFullHashGui()
+{
+
+}
+
+void SearchFullHashGui::slotCheckUrl()
+{
+ const QString urlStr = mCheckUrlLineEdit->text().trimmed();
+ if (urlStr.isEmpty()) {
+ return;
+ }
+ mResult->clear();
+/*
+ WebEngineViewer::CheckPhishingUrlJob *job = new WebEngineViewer::CheckPhishingUrlJob(this);
+ job->setUseCompactJson(false);
+ connect(job, &WebEngineViewer::CheckPhishingUrlJob::result, this, &SearchFullHashGui::slotGetResult);
+ connect(job, &WebEngineViewer::CheckPhishingUrlJob::debugJson, this, &SearchFullHashGui::slotJSonDebug);
+ job->setUrl(QUrl::fromUserInput(urlStr));
+ job->start();
+ */
+}
+
+void SearchFullHashGui::slotJSonDebug(const QByteArray &debug)
+{
+ mJson->setText(QString::fromLatin1(debug));
+}
+
+void SearchFullHashGui::slotGetResult(WebEngineViewer::SearchFullHashJob::UrlStatus result)
+{
+ QString resultStr;
+ switch (result) {
+ case WebEngineViewer::SearchFullHashJob::Ok:
+ resultStr = QStringLiteral("Url ok");
+ break;
+ case WebEngineViewer::SearchFullHashJob::MalWare:
+ resultStr = QStringLiteral("Url MalWare");
+ break;
+ case WebEngineViewer::SearchFullHashJob::Unknown:
+ resultStr = QStringLiteral("Url Unknow state");
+ break;
+ case WebEngineViewer::SearchFullHashJob::BrokenNetwork:
+ resultStr = QStringLiteral("Broken Network");
+ break;
+ case WebEngineViewer::SearchFullHashJob::InvalidUrl:
+ resultStr = QStringLiteral("Invalid Url");
+ break;
+ }
+ mResult->setText(resultStr);
+}
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ QStandardPaths::setTestModeEnabled(true);
+ SearchFullHashGui *w = new SearchFullHashGui;
+
+ w->show();
+ app.exec();
+ delete w;
+ return 0;
+}
diff --git a/webengineviewer/src/checkphishingurl/tests/searchfullhashgui.h b/webengineviewer/src/checkphishingurl/tests/searchfullhashgui.h
new file mode 100644
index 0000000..45d420e
--- /dev/null
+++ b/webengineviewer/src/checkphishingurl/tests/searchfullhashgui.h
@@ -0,0 +1,43 @@
+/*
+ Copyright (C) 2016 Laurent Montel <montel@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef CHECKPHISHINGURLGUI_H
+#define CHECKPHISHINGURLGUI_H
+
+#include <QWidget>
+#include "../searchfullhashjob.h"
+class QLineEdit;
+class QTextEdit;
+class SearchFullHashGui : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit SearchFullHashGui(QWidget *parent = Q_NULLPTR);
+ ~SearchFullHashGui();
+private Q_SLOTS:
+ void slotCheckUrl();
+ void slotGetResult(WebEngineViewer::SearchFullHashJob::UrlStatus result);
+ void slotJSonDebug(const QByteArray &debug);
+private:
+ QLineEdit *mCheckUrlLineEdit;
+ QTextEdit *mJson;
+ QTextEdit *mResult;
+};
+
+#endif // CHECKPHISHINGURLGUI_H