fix: fixed testing

This commit is contained in:
QxQ 2020-10-14 23:53:22 +08:00
parent e39c91bb21
commit eddd16bc38
5 changed files with 32 additions and 28 deletions

View File

@ -1 +1 @@
6003
6004

19
test/Common.hpp Normal file
View File

@ -0,0 +1,19 @@
#include "base/Qv2rayBaseApplication.hpp"
using namespace Qv2ray;
int fakeArgc = 0;
char *fakeArgv[]{};
class QvTestApplication
: public QCoreApplication
, public Qv2rayApplicationInterface
{
public:
explicit QvTestApplication() : QCoreApplication(fakeArgc, fakeArgv), Qv2rayApplicationInterface(){};
virtual void MessageBoxWarn(QWidget *, const QString &, const QString &, MessageOpt) override{};
virtual void MessageBoxInfo(QWidget *, const QString &, const QString &, MessageOpt) override{};
virtual MessageOpt MessageBoxAsk(QWidget *, const QString &, const QString &, const QList<MessageOpt> &) override
{
return {};
};
virtual void OpenURL(const QString &) override{};
};

View File

@ -1,26 +1,9 @@
#include "Common.hpp"
#include "src/components/latency/RealPing.hpp"
#include "uvw.hpp"
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
int fakeArgc = 0;
char *fakeArgv[]{};
class QvTestApplication
: public QCoreApplication
, public Qv2rayApplicationInterface
{
public:
explicit QvTestApplication() : QCoreApplication(fakeArgc, fakeArgv), Qv2rayApplicationInterface(){};
virtual void MessageBoxWarn(QWidget *, const QString &, const QString &, MessageOpt) override{};
virtual void MessageBoxInfo(QWidget *, const QString &, const QString &, MessageOpt) override{};
virtual MessageOpt MessageBoxAsk(QWidget *, const QString &, const QString &, const QList<MessageOpt> &) override
{
return {};
};
virtual void OpenURL(const QString &) override{};
};
SCENARIO("Test RealPing get proxy address", "[RealPing]")
{
QvTestApplication app;

View File

@ -1,4 +1,5 @@
#include "3rdparty/QJsonStruct/QJsonIO.hpp"
#include "Common.hpp"
#include "src/core/connection/Serialization.hpp"
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
@ -6,7 +7,7 @@ using namespace Qv2ray::core::connection::serialization;
SCENARIO("Test Parse Shadowsocks url", "[ParseSSUrl]")
{
QvTestApplication app;
GIVEN("A shadowsocks server object")
{
ShadowSocksServerObject s;
@ -50,8 +51,8 @@ SCENARIO("Test Parse Shadowsocks url", "[ParseSSUrl]")
}
WHEN("the url with sip003 plugin")
{
auto c = ss::Deserialize("ss://YmYtY2ZiOnRlc3Q@192.168.100.1:8888/?plugin=obfs-local%3bobfs%3dhttp%3bobfs-host%3dgoogle.com", &alias,
&err);
auto c =
ss::Deserialize("ss://YmYtY2ZiOnRlc3Q@192.168.100.1:8888/?plugin=obfs-local%3bobfs%3dhttp%3bobfs-host%3dgoogle.com", &alias, &err);
s = ShadowSocksServerObject::fromJson(QJsonIO::GetValue(c, "outbounds", 0, "settings", "servers", 0));
REQUIRE(s.address.toStdString() == "192.168.100.1");
REQUIRE(s.port == 8888);
@ -60,8 +61,7 @@ SCENARIO("Test Parse Shadowsocks url", "[ParseSSUrl]")
}
WHEN("another url with sip003 plugin")
{
auto c =
ss::Deserialize("ss://YmYtY2ZiOnRlc3Q@192.168.1.1:8388/?plugin=obfs-local%3bobfs%3dhttp%3bobfs-host%3dgoogle.com", &alias, &err);
auto c = ss::Deserialize("ss://YmYtY2ZiOnRlc3Q@192.168.1.1:8388/?plugin=obfs-local%3bobfs%3dhttp%3bobfs-host%3dgoogle.com", &alias, &err);
s = ShadowSocksServerObject::fromJson(QJsonIO::GetValue(c, "outbounds", 0, "settings", "servers", 0));
REQUIRE(s.address.toStdString() == "192.168.1.1");
REQUIRE(s.port == 8388);
@ -71,8 +71,7 @@ SCENARIO("Test Parse Shadowsocks url", "[ParseSSUrl]")
WHEN("the url with sip003 plugin and remarks")
{
auto c = ss::Deserialize(
"ss://YmYtY2ZiOnRlc3Q@192.168.100.1:8888/?plugin=obfs-local%3bobfs%3dhttp%3bobfs-host%3dgoogle.com#example-server", &alias,
&err);
"ss://YmYtY2ZiOnRlc3Q@192.168.100.1:8888/?plugin=obfs-local%3bobfs%3dhttp%3bobfs-host%3dgoogle.com#example-server", &alias, &err);
s = ShadowSocksServerObject::fromJson(QJsonIO::GetValue(c, "outbounds", 0, "settings", "servers", 0));
REQUIRE(s.address.toStdString() == "192.168.100.1");
REQUIRE(s.port == 8888);
@ -81,8 +80,8 @@ SCENARIO("Test Parse Shadowsocks url", "[ParseSSUrl]")
}
WHEN("another url with sip003 plugin and remarks")
{
auto c = ss::Deserialize(
"ss://YmYtY2ZiOnRlc3Q@192.168.1.1:8388/?plugin=obfs-local%3bobfs%3dhttp%3bobfs-host%3dgoogle.com#example-server", &alias, &err);
auto c = ss::Deserialize("ss://YmYtY2ZiOnRlc3Q@192.168.1.1:8388/?plugin=obfs-local%3bobfs%3dhttp%3bobfs-host%3dgoogle.com#example-server",
&alias, &err);
s = ShadowSocksServerObject::fromJson(QJsonIO::GetValue(c, "outbounds", 0, "settings", "servers", 0));
REQUIRE(s.address.toStdString() == "192.168.1.1");
REQUIRE(s.port == 8388);

View File

@ -1,10 +1,12 @@
#include "3rdparty/QJsonStruct/QJsonIO.hpp"
#include "Common.hpp"
#include "src/core/connection/Serialization.hpp"
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
SCENARIO("Test Parse VMess V2 url", "[ParseVMessV2]")
{
QvTestApplication app;
GIVEN("vmess+tcp")
{
QString _;
@ -48,6 +50,7 @@ SCENARIO("Test Parse VMess V2 url", "[ParseVMessV2]")
SCENARIO("Test Parse VMess V1 url", "[ParseVMessV1]")
{
QvTestApplication app;
GIVEN("vmess+ws")
{
QString _;