diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_ui.cpp | 34 | ||||
-rw-r--r-- | tests/tst_smoke.qml | 4 |
2 files changed, 35 insertions, 3 deletions
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?") } } |