mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-12-04 06:01:26 +09:00
* basic tests adaptation * fix: ui servers model and controller test awg config * fix: platforms test builds * build dirs inspection * fix: changed paths for tests and tests artifacts * fix: 'deploy' parent dir * windows ctest configuration and macos dependencies inspection * windows check executable and macos copy openssl libs * windows test executables check and macos copy openssl * changed some path on windows * android apk list * fix: updated android apk path * Verify Android test files * fix: build tests only with AMNEZIA_BUILD_TESTS * fix: copy openssl runtime next to test_openssl_library * fix: awg2 test config and inverted description checks * chore: move run_android_tests.sh to client/tests and drop personal paths * chore: gate tests by option, scope secrets and drop global concurrency in ci * chore: serialized vps test job, scoped secrets, backup secret guard, test data lookup --------- Co-authored-by: MrMirDan <8mirdan8@gmail.com>
101 lines
4.5 KiB
C++
101 lines
4.5 KiB
C++
#include <QCoreApplication>
|
|
#include <QDebug>
|
|
#include <QFile>
|
|
#include <QJsonDocument>
|
|
#include <QJsonObject>
|
|
#include <QProcessEnvironment>
|
|
#include <QSignalSpy>
|
|
#include <QTemporaryDir>
|
|
#include <QUuid>
|
|
#include <QTest>
|
|
|
|
#include "utils/testCoreController.h"
|
|
#include "core/models/serverDescription.h"
|
|
#include "secureQSettings.h"
|
|
#include "vpnConnection.h"
|
|
|
|
using namespace amnezia;
|
|
|
|
class TestUiAppSTModelAndController : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
private:
|
|
TestCoreController *m_coreController;
|
|
SecureQSettings *m_settings;
|
|
|
|
private slots:
|
|
void initTestCase()
|
|
{
|
|
QString testOrg = "AmneziaVPN-Test-" + QUuid::createUuid().toString();
|
|
m_settings = new SecureQSettings(testOrg, "amnezia-client", nullptr, false);
|
|
|
|
auto vpnConnection = QSharedPointer<VpnConnection>::create(nullptr, nullptr);
|
|
|
|
m_coreController = new TestCoreController(vpnConnection, m_settings, nullptr, this);
|
|
}
|
|
|
|
void cleanupTestCase()
|
|
{
|
|
m_settings->clearSettings();
|
|
delete m_coreController;
|
|
delete m_settings;
|
|
}
|
|
|
|
void init()
|
|
{
|
|
m_settings->clearSettings();
|
|
if (m_coreController->m_serversModel) {
|
|
m_coreController->m_serversModel->updateModel(QVector<ServerDescription>(), QString{});
|
|
}
|
|
}
|
|
|
|
void testRolesAndSignals()
|
|
{
|
|
QSignalSpy finishedSpy(m_coreController->m_appSplitTunnelingUiController, &AppSplitTunnelingUiController::finished);
|
|
QSignalSpy errorOccurredSpy(m_coreController->m_appSplitTunnelingUiController, &AppSplitTunnelingUiController::errorOccurred);
|
|
QSignalSpy isSplitTunnelingChangedSpy(m_coreController->m_appSplitTunnelingUiController, &AppSplitTunnelingUiController::isSplitTunnelingEnabledChanged);
|
|
|
|
m_coreController->m_appSplitTunnelingUiController->toggleSplitTunneling(true);
|
|
QVERIFY2(isSplitTunnelingChangedSpy.count() == 1, "isSplitTunnelingChangedSpy signal should be emitted");
|
|
QVERIFY2(m_coreController->m_appSplitTunnelingUiController->isSplitTunnelingEnabled() == true, "AppSplitTunneling should be enabled");
|
|
|
|
m_coreController->m_appSplitTunnelingUiController->toggleSplitTunneling(false);
|
|
QVERIFY2(isSplitTunnelingChangedSpy.count() == 2, "isSplitTunnelingChangedSpy signal should be emitted 2nd time");
|
|
QVERIFY2(m_coreController->m_appSplitTunnelingUiController->isSplitTunnelingEnabled() == false, "AppSplitTunneling should be disabled");
|
|
|
|
const QString app = QCoreApplication::applicationFilePath();
|
|
|
|
m_coreController->m_appSplitTunnelingUiController->addApp(app);
|
|
m_coreController->m_appSplitTunnelingUiController->updateModel();
|
|
QVERIFY2(finishedSpy.count() == 1, "finished signal should be emitted");
|
|
QVERIFY2(m_coreController->m_appSplitTunnelingModel->rowCount() == 1, "AppSplitTunnelingModel should have 1 row");
|
|
|
|
QModelIndex appSTModelIndex = m_coreController->m_appSplitTunnelingModel->index(0, 0);
|
|
QVERIFY2(appSTModelIndex.isValid(), "Site model index should be valid");
|
|
|
|
auto appPath = m_coreController->m_appSplitTunnelingModel->data(appSTModelIndex, AppSplitTunnelingModel::AppPathRole);
|
|
QString msg = QString("app path should be %1, got %2").arg(app, appPath.toString());
|
|
QVERIFY2(app.contains(appPath.toString()) == true, msg.toLocal8Bit().constData());
|
|
|
|
auto pkgAppName = m_coreController->m_appSplitTunnelingModel->data(appSTModelIndex, AppSplitTunnelingModel::PackageAppNameRole);
|
|
QVERIFY2(pkgAppName == true, "app name should be set");
|
|
|
|
auto pkgAppIcon = m_coreController->m_appSplitTunnelingModel->data(appSTModelIndex, AppSplitTunnelingModel::PackageAppIconRole);
|
|
QVERIFY2(pkgAppIcon == true, "app image should be set");
|
|
|
|
m_coreController->m_appSplitTunnelingUiController->addApp(app);
|
|
m_coreController->m_appSplitTunnelingUiController->updateModel();
|
|
QVERIFY2(errorOccurredSpy.count() == 1, "errorOccurred signal should be emitted");
|
|
QVERIFY2(m_coreController->m_appSplitTunnelingModel->rowCount() == 1, "AppSplitTunnelingModel should have 3 rows (same app should not be added)");
|
|
|
|
m_coreController->m_appSplitTunnelingUiController->removeApp(0);
|
|
m_coreController->m_appSplitTunnelingUiController->updateModel();
|
|
QVERIFY2(finishedSpy.count() == 2, "finished signal should be emitted");
|
|
QVERIFY2(m_coreController->m_appSplitTunnelingModel->rowCount() == 0, "AppSplitTunnelingModel should have 0 rows");
|
|
}
|
|
};
|
|
|
|
QTEST_MAIN(TestUiAppSTModelAndController)
|
|
#include "testUiAppSTModelAndController.moc"
|