1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

test(core): Added test for startup with invalid proxy

This commit is contained in:
Patrick 2019-03-17 00:05:41 +01:00
parent cf32ccfa0e
commit e3a02b6ccb

View File

@ -23,6 +23,8 @@
#include "src/net/bootstrapnodeupdater.h" #include "src/net/bootstrapnodeupdater.h"
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <QtGlobal>
#include <limits>
#include <QSignalSpy> #include <QSignalSpy>
#include <src/persistence/settings.h> #include <src/persistence/settings.h>
#include <iostream> #include <iostream>
@ -46,14 +48,14 @@ public:
bool getEnableLanDiscovery() const override { return false; } bool getEnableLanDiscovery() const override { return false; }
void setEnableLanDiscovery(bool) override { } void setEnableLanDiscovery(bool) override { }
QString getProxyAddr() const override { return QString(""); } QString getProxyAddr() const override { return Addr; }
void setProxyAddr(const QString &) override { } void setProxyAddr(const QString &Addr) override { this->Addr = Addr; }
ProxyType getProxyType() const override { return ProxyType::ptNone; } ProxyType getProxyType() const override { return type; }
void setProxyType(ProxyType) override { } void setProxyType(ProxyType type) override { this->type = type; }
quint16 getProxyPort() const override { return 0; } quint16 getProxyPort() const override { return port; }
void setProxyPort(quint16) override { } void setProxyPort(quint16 port) override { this->port = port; }
QNetworkProxy getProxy() const override { return QNetworkProxy(QNetworkProxy::ProxyType::NoProxy); } QNetworkProxy getProxy() const override { return QNetworkProxy(QNetworkProxy::ProxyType::NoProxy); }
@ -66,7 +68,9 @@ public:
private: private:
QList<DhtServer> dhtServerList; QList<DhtServer> dhtServerList;
QString Addr;
ProxyType type;
quint16 port;
}; };
@ -75,6 +79,7 @@ class TestCore : public QObject
Q_OBJECT Q_OBJECT
private slots: private slots:
void startup_without_proxy(); void startup_without_proxy();
void startup_with_invalid_proxy();
private: private:
/* Test Variables */ /* Test Variables */
@ -91,8 +96,13 @@ namespace {
void TestCore::startup_without_proxy() void TestCore::startup_without_proxy()
{ {
settings = new MockSettings();
Q_INIT_RESOURCE(res); Q_INIT_RESOURCE(res);
settings = new MockSettings();
// No proxy
settings->setProxyAddr("1.2.3.4");
settings->setProxyPort(1234);
settings->setProxyType(MockSettings::ProxyType::ptNone);
test_core = Core::makeToxCore(savedata, settings, err); test_core = Core::makeToxCore(savedata, settings, err);
@ -108,6 +118,40 @@ void TestCore::startup_without_proxy()
QVERIFY(spyCore.wait(timeout)); //wait 90seconds QVERIFY(spyCore.wait(timeout)); //wait 90seconds
QCOMPARE(spyCore.count(), 1); // make sure the signal was emitted exactly one time QCOMPARE(spyCore.count(), 1); // make sure the signal was emitted exactly one time
test_core.reset();
}
void TestCore::startup_with_invalid_proxy()
{
Q_INIT_RESOURCE(res);
settings = new MockSettings();
// Test invalid proxy SOCKS5
settings->setProxyAddr("Test");
settings->setProxyPort(9985);
settings->setProxyType(MockSettings::ProxyType::ptSOCKS5);
test_core = Core::makeToxCore(savedata, settings, err);
if(test_core != ToxCorePtr{}) {
QFAIL("ToxCore initialisation passed with invalid SOCKS5 proxy address");
}
// Test invalid proxy HTTP
settings->setProxyAddr("Test");
settings->setProxyPort(9985);
settings->setProxyType(MockSettings::ProxyType::ptHTTP);
test_core = Core::makeToxCore(savedata, settings, err);
if(test_core != ToxCorePtr{}) {
QFAIL("ToxCore initialisation passed with invalid HTTP proxy address");
}
test_core.reset();
} }
QTEST_GUILESS_MAIN(TestCore) QTEST_GUILESS_MAIN(TestCore)