From ac30c6954a55347677d04ad2d8485b8ce85c9a55 Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Fri, 2 Oct 2020 13:22:07 +0200 Subject: [test] update ui smoke test, add it to ci --- .gitlab-ci.yml | 1 + bitmask.pro | 3 ++- gui/backend.go | 8 ++++++-- test.pro | 3 ++- tests/test_ui.cpp | 34 +++++++++++++++++++++++++++++++++- tests/tst_smoke.qml | 4 ++-- 6 files changed, 46 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 46bcf31..a8d0398 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,6 +11,7 @@ build_test: script: - make generate - make test + - make test_ui - make build tags: - linux diff --git a/bitmask.pro b/bitmask.pro index 7d4543a..3ab8507 100644 --- a/bitmask.pro +++ b/bitmask.pro @@ -18,7 +18,6 @@ SOURCES += \ gui/qjsonmodel.cpp \ gui/handlers.cpp -RESOURCES += gui/gui.qrc HEADERS += \ gui/handlers.h \ @@ -27,6 +26,8 @@ HEADERS += \ LIBS += -L../lib -lgoshim -lpthread +RESOURCES += gui/gui.qrc + DESTDIR = release OBJECTS_DIR = release/.obj MOC_DIR = release/.moc diff --git a/gui/backend.go b/gui/backend.go index abacd85..9453d88 100644 --- a/gui/backend.go +++ b/gui/backend.go @@ -59,9 +59,13 @@ func InitializeBitmaskContext(provider string, } //export InitializeTestBitmaskContext -func InitializeTestBitmaskContext() { - opts := &backend.InitOpts{} +func InitializeTestBitmaskContext(provider string, + jsonPtr unsafe.Pointer, jsonLen C.int) { + json := C.GoBytes(jsonPtr, jsonLen) + opts := backend.InitOptsFromJSON(provider, string(json)) + opts.DisableAutostart = true opts.SkipLaunch = true + opts.StartVPN = "no" backend.InitializeBitmaskContext(opts) backend.EnableMockBackend() } diff --git a/test.pro b/test.pro index 099e18f..e731e2b 100644 --- a/test.pro +++ b/test.pro @@ -12,9 +12,10 @@ HEADERS += \ gui/qjsonmodel.h \ gui/handlers.h - LIBS += -L../lib -lgoshim -lpthread +RESOURCES += tests/tests.qrc + DESTDIR = build OBJECTS_DIR = build/.obj RCC_DIR = build/.rcc diff --git a/tests/test_ui.cpp b/tests/test_ui.cpp index f9f960a..7642157 100644 --- a/tests/test_ui.cpp +++ b/tests/test_ui.cpp @@ -6,6 +6,23 @@ #include "../gui/qjsonmodel.h" #include "../lib/libgoshim.h" + +GoString _toGoStr(QString s) +{ + const char *c = s.toUtf8().constData(); + return (GoString){c, (long int)strlen(c)}; +} + +QString getAppName(QJsonValue info, QString provider) { + for (auto p: info.toArray()) { + QJsonObject item = p.toObject(); + if (item["name"] == provider) { + return item["applicationName"].toString(); + } + } + return "BitmaskVPN"; +} + class Helper : public QObject { Q_OBJECT @@ -40,9 +57,24 @@ public slots: QJsonModel *model = new QJsonModel; Helper *helper = new Helper(this); - InitializeTestBitmaskContext(); + /* load providers json */ + QFile providerJson (":/providers.json"); + providerJson.open(QIODevice::ReadOnly | QIODevice::Text); + QJsonModel *providers = new QJsonModel; + QByteArray providerJsonBytes = providerJson.readAll(); + providers->loadJson(providerJsonBytes); + QJsonValue defaultProvider = providers->json().object().value("default"); + QJsonValue providersInfo = providers->json().object().value("providers"); + QString appName = getAppName(providersInfo, defaultProvider.toString()); + + InitializeTestBitmaskContext( + _toGoStr(defaultProvider.toString()), + (char*)providerJsonBytes.data(), providerJsonBytes.length()); ctx->setContextProperty("jsonModel", model); + ctx->setContextProperty("providers", providers); + + /* helper for tests */ ctx->setContextProperty("helper", helper); } }; diff --git a/tests/tst_smoke.qml b/tests/tst_smoke.qml index 19904a6..7cb2cd4 100644 --- a/tests/tst_smoke.qml +++ b/tests/tst_smoke.qml @@ -21,8 +21,8 @@ TestCase { function test_loadCtx() { refresh() - compare(ctx.appName, "RiseupVPN", "can read appName?") - compare(ctx.tosURL, "https://riseup.net/tos", "can read tosURL?") + compare(ctx.appName, "DemoLibVPN", "can read appName?") + compare(ctx.tosURL, "https://libraryvpn.org/", "can read tosURL?") compare(ctx.status, "off", "is initial status off?") } } -- cgit v1.2.3