mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-08-03 14:25:38 +02:00
unittest: add SIP account creation and contact adding tests
Add global test environment for google test Change-Id: Id035ebf31498e11574b6bf4671b4c6e12d29ddc7
This commit is contained in:
parent
ce22cbbabe
commit
872fbeb5d3
6 changed files with 275 additions and 96 deletions
|
@ -63,7 +63,8 @@ set(UNIT_TESTS_HEADER_FILES ${CMAKE_SOURCE_DIR}/tests/unittests/globaltestenviro
|
|||
|
||||
set(UNIT_TESTS_SOURCE_FILES
|
||||
${CMAKE_SOURCE_DIR}/tests/unittests/main_unittest.cpp
|
||||
${CMAKE_SOURCE_DIR}/tests/unittests/accountadapter_unittest.cpp)
|
||||
${CMAKE_SOURCE_DIR}/tests/unittests/account_unittest.cpp
|
||||
${CMAKE_SOURCE_DIR}/tests/unittests/contact_unittest.cpp)
|
||||
|
||||
add_executable(unittests
|
||||
${UNIT_TESTS_HEADER_FILES}
|
||||
|
|
94
tests/unittests/account_unittest.cpp
Normal file
94
tests/unittests/account_unittest.cpp
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (C) 2021 by Savoir-faire Linux
|
||||
* Author: Albert Babí Oller <albert.babi@savoirfairelinux.com>
|
||||
* Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "globaltestenvironment.h"
|
||||
|
||||
TestEnvironment globalEnv;
|
||||
|
||||
/*!
|
||||
* Test fixture for AccountAdapter testing
|
||||
*/
|
||||
class AccountFixture : public ::testing::Test
|
||||
{
|
||||
public:
|
||||
// Prepare unit test context. Called at
|
||||
// prior each unit test execution
|
||||
void SetUp() override {}
|
||||
|
||||
// Close unit test context. Called
|
||||
// after each unit test ending
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
/*!
|
||||
* WHEN There is no account initially.
|
||||
* THEN Account list should be empty.
|
||||
*/
|
||||
TEST_F(AccountFixture, InitialAccountListCheck)
|
||||
{
|
||||
auto accountListSize = globalEnv.lrcInstance->accountModel().getAccountList().size();
|
||||
|
||||
ASSERT_EQ(accountListSize, 0);
|
||||
}
|
||||
|
||||
/*!
|
||||
* WHEN An SIP account is created.
|
||||
* THEN The size of the account list should be one.
|
||||
*/
|
||||
TEST_F(AccountFixture, CreateSIPAccountTest)
|
||||
{
|
||||
// AccountAdded signal spy
|
||||
QSignalSpy accountAddedSpy(&globalEnv.lrcInstance->accountModel(),
|
||||
&lrc::api::NewAccountModel::accountAdded);
|
||||
|
||||
// Create SIP Acc
|
||||
globalEnv.accountAdapter->createSIPAccount(QVariantMap());
|
||||
|
||||
if (accountAddedSpy.count() < 1)
|
||||
QVERIFY(accountAddedSpy.wait());
|
||||
|
||||
QList<QVariant> accountAddedArguments = accountAddedSpy.takeFirst();
|
||||
QVERIFY(accountAddedArguments.at(0).type() == QVariant::String);
|
||||
|
||||
// Select the created account
|
||||
globalEnv.lrcInstance->setCurrentAccountId(accountAddedArguments.at(0).toString());
|
||||
|
||||
auto accountListSize = globalEnv.lrcInstance->accountModel().getAccountList().size();
|
||||
ASSERT_EQ(accountListSize, 1);
|
||||
|
||||
// Make sure the account setup is done
|
||||
QSignalSpy accountStatusChangedSpy(&globalEnv.lrcInstance->accountModel(),
|
||||
&lrc::api::NewAccountModel::accountStatusChanged);
|
||||
|
||||
if (accountStatusChangedSpy.count() < 1)
|
||||
QVERIFY(accountStatusChangedSpy.wait());
|
||||
|
||||
// Remove the account
|
||||
globalEnv.lrcInstance->accountModel().removeAccount(
|
||||
globalEnv.lrcInstance->getCurrentAccountId());
|
||||
|
||||
QSignalSpy accountRemovedSpy(&globalEnv.lrcInstance->accountModel(),
|
||||
&lrc::api::NewAccountModel::accountRemoved);
|
||||
|
||||
if (accountRemovedSpy.count() < 1)
|
||||
QVERIFY(accountRemovedSpy.wait());
|
||||
|
||||
accountListSize = globalEnv.lrcInstance->accountModel().getAccountList().size();
|
||||
ASSERT_EQ(accountListSize, 0);
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2021 by Savoir-faire Linux
|
||||
* Author: Albert Babí Oller <albert.babi@savoirfairelinux.com>
|
||||
* Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "globaltestenvironment.h"
|
||||
|
||||
#include "mainapplication.h"
|
||||
#include "qmlregister.h"
|
||||
#include "appsettingsmanager.h"
|
||||
#include "connectivitymonitor.h"
|
||||
#include "systemtray.h"
|
||||
|
||||
#include "accountadapter.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#if defined _MSC_VER && !COMPILE_ONLY
|
||||
#include <gnutls/gnutls.h>
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* Test fixture for AccountAdapter testing
|
||||
*/
|
||||
class AccountAdapterFixture : public ::testing::Test
|
||||
{
|
||||
public:
|
||||
// Prepare unit test context. Called at
|
||||
// prior each unit test execution
|
||||
void SetUp() override
|
||||
{
|
||||
connectivityMonitor_.reset(new ConnectivityMonitor(nullptr));
|
||||
settingsManager_.reset(new AppSettingsManager(nullptr));
|
||||
systemTray_.reset(new SystemTray(settingsManager_.get(), nullptr));
|
||||
|
||||
#if defined _MSC_VER && !COMPILE_ONLY
|
||||
gnutls_global_init();
|
||||
#endif
|
||||
|
||||
std::atomic_bool isMigrating(false);
|
||||
lrcInstance_.reset(
|
||||
new LRCInstance(nullptr, nullptr, "", connectivityMonitor_.get(), muteDring));
|
||||
lrcInstance_->subscribeToDebugReceived();
|
||||
|
||||
// setup the adapters (their lifetimes are that of MainApplication)
|
||||
accountAdapter_.reset(
|
||||
new AccountAdapter(settingsManager_.get(), lrcInstance_.data(), nullptr));
|
||||
}
|
||||
|
||||
// Close unit test context. Called
|
||||
// after each unit test ending
|
||||
void TearDown() override {}
|
||||
|
||||
QScopedPointer<AccountAdapter> accountAdapter_;
|
||||
|
||||
QScopedPointer<LRCInstance> lrcInstance_;
|
||||
QScopedPointer<ConnectivityMonitor> connectivityMonitor_;
|
||||
QScopedPointer<AppSettingsManager> settingsManager_;
|
||||
QScopedPointer<SystemTray> systemTray_;
|
||||
};
|
||||
|
||||
/*!
|
||||
* WHEN There is no account initially.
|
||||
* THEN Account list should be empty.
|
||||
*/
|
||||
TEST_F(AccountAdapterFixture, InitialAccountListCheck)
|
||||
{
|
||||
auto accountListSize = lrcInstance_->accountModel().getAccountList().size();
|
||||
|
||||
ASSERT_EQ(accountListSize, 0);
|
||||
}
|
104
tests/unittests/contact_unittest.cpp
Normal file
104
tests/unittests/contact_unittest.cpp
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Copyright (C) 2021 by Savoir-faire Linux
|
||||
* Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "globaltestenvironment.h"
|
||||
|
||||
TestEnvironment globalEnv;
|
||||
|
||||
/*!
|
||||
* Test fixture for AccountAdapter testing
|
||||
*/
|
||||
class ContactFixture : public ::testing::Test
|
||||
{
|
||||
public:
|
||||
// Prepare unit test context. Called at
|
||||
// prior each unit test execution
|
||||
void SetUp() override {}
|
||||
|
||||
// Close unit test context. Called
|
||||
// after each unit test ending
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
/*!
|
||||
* WHEN Add an SIP contact.
|
||||
* THEN ContactAdded signal should be emitted once.
|
||||
*/
|
||||
TEST_F(ContactFixture, AddSIPContactTest)
|
||||
{
|
||||
// AccountAdded signal spy
|
||||
QSignalSpy accountAddedSpy(&globalEnv.lrcInstance->accountModel(),
|
||||
&lrc::api::NewAccountModel::accountAdded);
|
||||
|
||||
// Create SIP Acc
|
||||
globalEnv.accountAdapter->createSIPAccount(QVariantMap());
|
||||
|
||||
if (accountAddedSpy.count() < 1)
|
||||
QVERIFY(accountAddedSpy.wait());
|
||||
|
||||
QList<QVariant> accountAddedArguments = accountAddedSpy.takeFirst();
|
||||
QVERIFY(accountAddedArguments.at(0).type() == QVariant::String);
|
||||
|
||||
// Select the created account
|
||||
globalEnv.lrcInstance->setCurrentAccountId(accountAddedArguments.at(0).toString());
|
||||
|
||||
// Make sure the account setup is done
|
||||
QSignalSpy accountStatusChangedSpy(&globalEnv.lrcInstance->accountModel(),
|
||||
&lrc::api::NewAccountModel::accountStatusChanged);
|
||||
|
||||
if (accountStatusChangedSpy.count() < 1)
|
||||
QVERIFY(accountStatusChangedSpy.wait());
|
||||
|
||||
// ModelUpdated signal spy
|
||||
QSignalSpy modelUpdatedSpy(globalEnv.lrcInstance->getCurrentContactModel(),
|
||||
&lrc::api::ContactModel::modelUpdated);
|
||||
|
||||
// Add temp contact test
|
||||
globalEnv.lrcInstance->getCurrentConversationModel()->setFilter("test");
|
||||
|
||||
if (modelUpdatedSpy.count() < 1)
|
||||
QVERIFY(modelUpdatedSpy.wait());
|
||||
|
||||
QList<QVariant> modelUpdatedArguments = modelUpdatedSpy.takeFirst();
|
||||
QVERIFY(modelUpdatedArguments.at(0).type() == QVariant::String);
|
||||
|
||||
// Get conversation id
|
||||
auto convId = globalEnv.lrcInstance
|
||||
->getConversationFromPeerUri(modelUpdatedArguments.at(0).toString())
|
||||
.uid;
|
||||
ASSERT_EQ(convId.isEmpty(), false);
|
||||
|
||||
// ContactAdded signal spy
|
||||
QSignalSpy contactAddedSpy(globalEnv.lrcInstance->getCurrentContactModel(),
|
||||
&lrc::api::ContactModel::contactAdded);
|
||||
|
||||
globalEnv.lrcInstance->getCurrentConversationModel()->makePermanent(convId);
|
||||
|
||||
if (contactAddedSpy.count() < 1)
|
||||
QVERIFY(contactAddedSpy.wait());
|
||||
|
||||
// Remove the account
|
||||
globalEnv.lrcInstance->accountModel().removeAccount(
|
||||
globalEnv.lrcInstance->getCurrentAccountId());
|
||||
|
||||
QSignalSpy accountRemovedSpy(&globalEnv.lrcInstance->accountModel(),
|
||||
&lrc::api::NewAccountModel::accountRemoved);
|
||||
|
||||
if (accountRemovedSpy.count() < 1)
|
||||
QVERIFY(accountRemovedSpy.wait());
|
||||
}
|
|
@ -16,4 +16,70 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
extern bool muteDring;
|
||||
#include "mainapplication.h"
|
||||
#include "qmlregister.h"
|
||||
#include "appsettingsmanager.h"
|
||||
#include "connectivitymonitor.h"
|
||||
#include "systemtray.h"
|
||||
|
||||
#include "accountadapter.h"
|
||||
|
||||
#include <QTest>
|
||||
#include <QSignalSpy>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#if defined _MSC_VER && !COMPILE_ONLY
|
||||
#include <gnutls/gnutls.h>
|
||||
#endif
|
||||
|
||||
class TestEnvironment
|
||||
{
|
||||
public:
|
||||
TestEnvironment() = default;
|
||||
~TestEnvironment() = default;
|
||||
|
||||
void SetUp()
|
||||
{
|
||||
connectivityMonitor.reset(new ConnectivityMonitor(nullptr));
|
||||
settingsManager.reset(new AppSettingsManager(nullptr));
|
||||
systemTray.reset(new SystemTray(settingsManager.get(), nullptr));
|
||||
|
||||
#if defined _MSC_VER && !COMPILE_ONLY
|
||||
gnutls_global_init();
|
||||
#endif
|
||||
|
||||
std::atomic_bool isMigrating(false);
|
||||
lrcInstance.reset(
|
||||
new LRCInstance(nullptr, nullptr, "", connectivityMonitor.get(), muteDring));
|
||||
lrcInstance->subscribeToDebugReceived();
|
||||
|
||||
// setup the adapters (their lifetimes are that of MainApplication)
|
||||
accountAdapter.reset(new AccountAdapter(settingsManager.get(), lrcInstance.data(), nullptr));
|
||||
}
|
||||
|
||||
void TearDown()
|
||||
{
|
||||
accountAdapter.reset();
|
||||
|
||||
systemTray.reset();
|
||||
settingsManager.reset();
|
||||
lrcInstance.reset();
|
||||
connectivityMonitor.reset();
|
||||
}
|
||||
|
||||
bool muteDring {false};
|
||||
|
||||
QScopedPointer<AccountAdapter> accountAdapter;
|
||||
|
||||
QScopedPointer<LRCInstance> lrcInstance;
|
||||
QScopedPointer<ConnectivityMonitor> connectivityMonitor;
|
||||
QScopedPointer<AppSettingsManager> settingsManager;
|
||||
QScopedPointer<SystemTray> systemTray;
|
||||
};
|
||||
|
||||
extern TestEnvironment globalEnv;
|
|
@ -22,9 +22,7 @@
|
|||
#include <QApplication>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
bool muteDring;
|
||||
TestEnvironment globalEnv;
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
|
@ -36,7 +34,7 @@ main(int argc, char* argv[])
|
|||
});
|
||||
|
||||
if (end != argv + argc) {
|
||||
muteDring = true;
|
||||
globalEnv.muteDring = true;
|
||||
|
||||
// Adjust the argument count.
|
||||
argc = std::distance(argv, end);
|
||||
|
@ -46,6 +44,11 @@ main(int argc, char* argv[])
|
|||
|
||||
QApplication a(argc, argv);
|
||||
a.processEvents();
|
||||
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
globalEnv.SetUp();
|
||||
auto result = RUN_ALL_TESTS();
|
||||
globalEnv.TearDown();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue