mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-07-23 00:45:29 +02:00
test: enhance the google unit tests of the client
1. Move JAMI_DATA_HOME, JAMI_CONFIG_HOME, JAMI_CACHE_HOME setup into individual test main entry 2. Use google test assertion macros instead of Qt 3. Add QT_QPA_FONTDIR to avoid QFont warnings 4. Tests will now fail if the env variables cannot be set Change-Id: I63f6498d26b646d8ebc60799d8797fd5f13b54f9
This commit is contained in:
parent
0aa3275b93
commit
e2dbc33ac0
5 changed files with 56 additions and 37 deletions
|
@ -32,10 +32,7 @@ qml_test_project = build_dir + '\\tests\\qml_tests.vcxproj'
|
|||
qml_test_exe = this_dir + '\\x64\\test\\qml_tests.exe -input ' + this_dir + '\\tests\\qml'
|
||||
unit_test_exe = this_dir + '\\x64\\test\\unittests.exe'
|
||||
|
||||
# test env path
|
||||
test_data_dir = temp_path + '\\jami_test\\jami'
|
||||
test_config_dir = temp_path + '\\jami_test\\.config'
|
||||
test_cache_dir = temp_path + '\\jami_test\\.cache'
|
||||
windows_font_dir = 'C:\\Windows\\Fonts'
|
||||
|
||||
class TestBuilding(Enum):
|
||||
NoTests = 0
|
||||
|
@ -320,10 +317,8 @@ def run_tests(mute_jamid, output_to_files):
|
|||
os.environ["QT_QPA_PLATFORM"] = 'offscreen'
|
||||
os.environ["QT_QUICK_BACKEND"] = 'software'
|
||||
|
||||
# set test env variables
|
||||
os.environ["JAMI_DATA_HOME"] = test_data_dir
|
||||
os.environ["JAMI_CONFIG_HOME"] = test_config_dir
|
||||
os.environ["JAMI_CACHE_HOME"] = test_cache_dir
|
||||
# provide font dir
|
||||
os.environ["QT_QPA_FONTDIR"] = windows_font_dir
|
||||
|
||||
for test_exe_command in test_exe_command_list:
|
||||
if (execute_cmd(test_exe_command, True)):
|
||||
|
|
|
@ -124,6 +124,18 @@ private:
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
QDir tempDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
|
||||
|
||||
auto jamiDataDir = tempDir.absolutePath() + "\\jami_test\\jami";
|
||||
auto jamiConfigDir = tempDir.absolutePath() + "\\jami_test\\.config";
|
||||
auto jamiCacheDir = tempDir.absolutePath() + "\\jami_test\\.cache";
|
||||
|
||||
bool envSet = qputenv("JAMI_DATA_HOME", jamiDataDir.toLocal8Bit());
|
||||
envSet &= qputenv("JAMI_CONFIG_HOME", jamiConfigDir.toLocal8Bit());
|
||||
envSet &= qputenv("JAMI_CACHE_HOME", jamiCacheDir.toLocal8Bit());
|
||||
if (!envSet)
|
||||
return 1;
|
||||
|
||||
bool muteDring {false};
|
||||
|
||||
// Remove "-mutejamid" from argv, as quick_test_main_with_setup() will
|
||||
|
@ -139,7 +151,6 @@ main(int argc, char** argv)
|
|||
argc = std::distance(argv, end);
|
||||
}
|
||||
|
||||
QStandardPaths::setTestModeEnabled(true);
|
||||
QtWebEngine::initialize();
|
||||
|
||||
QTEST_SET_MAIN_SOURCE_PATH
|
||||
|
|
|
@ -60,11 +60,11 @@ TEST_F(AccountFixture, CreateSIPAccountTest)
|
|||
// Create SIP Acc
|
||||
globalEnv.accountAdapter->createSIPAccount(QVariantMap());
|
||||
|
||||
QVERIFY(accountAddedSpy.wait());
|
||||
QCOMPARE(accountAddedSpy.count(), 1);
|
||||
accountAddedSpy.wait();
|
||||
EXPECT_EQ(accountAddedSpy.count(), 1);
|
||||
|
||||
QList<QVariant> accountAddedArguments = accountAddedSpy.takeFirst();
|
||||
QVERIFY(accountAddedArguments.at(0).type() == QVariant::String);
|
||||
EXPECT_TRUE(accountAddedArguments.at(0).type() == QVariant::String);
|
||||
|
||||
// Select the created account
|
||||
globalEnv.lrcInstance->set_currentAccountId(accountAddedArguments.at(0).toString());
|
||||
|
@ -76,18 +76,18 @@ TEST_F(AccountFixture, CreateSIPAccountTest)
|
|||
QSignalSpy accountStatusChangedSpy(&globalEnv.lrcInstance->accountModel(),
|
||||
&NewAccountModel::accountStatusChanged);
|
||||
|
||||
QVERIFY(accountStatusChangedSpy.wait());
|
||||
QCOMPARE(accountStatusChangedSpy.count(), 1);
|
||||
accountStatusChangedSpy.wait();
|
||||
EXPECT_GE(accountStatusChangedSpy.count(), 1);
|
||||
|
||||
// Remove the account
|
||||
globalEnv.lrcInstance->accountModel().removeAccount(
|
||||
globalEnv.lrcInstance->get_currentAccountId());
|
||||
|
||||
QSignalSpy accountRemovedSpy(&globalEnv.lrcInstance->accountModel(),
|
||||
&NewAccountModel::accountRemoved);
|
||||
|
||||
QVERIFY(accountRemovedSpy.wait());
|
||||
QCOMPARE(accountRemovedSpy.count(), 1);
|
||||
globalEnv.lrcInstance->accountModel().removeAccount(
|
||||
globalEnv.lrcInstance->get_currentAccountId());
|
||||
|
||||
accountRemovedSpy.wait();
|
||||
EXPECT_EQ(accountRemovedSpy.count(), 1);
|
||||
|
||||
accountListSize = globalEnv.lrcInstance->accountModel().getAccountList().size();
|
||||
ASSERT_EQ(accountListSize, 0);
|
||||
|
|
|
@ -48,11 +48,11 @@ TEST_F(ContactFixture, AddSIPContactTest)
|
|||
// Create SIP Acc
|
||||
globalEnv.accountAdapter->createSIPAccount(QVariantMap());
|
||||
|
||||
QVERIFY(accountAddedSpy.wait());
|
||||
QCOMPARE(accountAddedSpy.count(), 1);
|
||||
accountAddedSpy.wait();
|
||||
EXPECT_EQ(accountAddedSpy.count(), 1);
|
||||
|
||||
QList<QVariant> accountAddedArguments = accountAddedSpy.takeFirst();
|
||||
QVERIFY(accountAddedArguments.at(0).type() == QVariant::String);
|
||||
EXPECT_TRUE(accountAddedArguments.at(0).type() == QVariant::String);
|
||||
|
||||
// Select the created account
|
||||
globalEnv.lrcInstance->set_currentAccountId(accountAddedArguments.at(0).toString());
|
||||
|
@ -61,8 +61,8 @@ TEST_F(ContactFixture, AddSIPContactTest)
|
|||
QSignalSpy accountStatusChangedSpy(&globalEnv.lrcInstance->accountModel(),
|
||||
&lrc::api::NewAccountModel::accountStatusChanged);
|
||||
|
||||
QVERIFY(accountStatusChangedSpy.wait());
|
||||
QCOMPARE(accountStatusChangedSpy.count(), 1);
|
||||
accountStatusChangedSpy.wait();
|
||||
EXPECT_GE(accountStatusChangedSpy.count(), 1);
|
||||
|
||||
// ModelUpdated signal spy
|
||||
QSignalSpy modelUpdatedSpy(globalEnv.lrcInstance->getCurrentContactModel(),
|
||||
|
@ -71,11 +71,11 @@ TEST_F(ContactFixture, AddSIPContactTest)
|
|||
// Add temp contact test
|
||||
globalEnv.lrcInstance->getCurrentConversationModel()->setFilter("test");
|
||||
|
||||
QVERIFY(modelUpdatedSpy.wait());
|
||||
QCOMPARE(modelUpdatedSpy.count(), 1);
|
||||
modelUpdatedSpy.wait();
|
||||
EXPECT_EQ(modelUpdatedSpy.count(), 1);
|
||||
|
||||
QList<QVariant> modelUpdatedArguments = modelUpdatedSpy.takeFirst();
|
||||
QVERIFY(modelUpdatedArguments.at(0).type() == QVariant::String);
|
||||
EXPECT_TRUE(modelUpdatedArguments.at(0).type() == QVariant::String);
|
||||
|
||||
// Get conversation id
|
||||
auto convId = globalEnv.lrcInstance
|
||||
|
@ -89,16 +89,19 @@ TEST_F(ContactFixture, AddSIPContactTest)
|
|||
|
||||
globalEnv.lrcInstance->getCurrentConversationModel()->makePermanent(convId);
|
||||
|
||||
QVERIFY(contactAddedSpy.wait());
|
||||
QCOMPARE(contactAddedSpy.count(), 1);
|
||||
contactAddedSpy.wait();
|
||||
EXPECT_EQ(contactAddedSpy.count(), 1);
|
||||
|
||||
// Remove the account
|
||||
globalEnv.lrcInstance->accountModel().removeAccount(
|
||||
globalEnv.lrcInstance->get_currentAccountId());
|
||||
|
||||
QSignalSpy accountRemovedSpy(&globalEnv.lrcInstance->accountModel(),
|
||||
&lrc::api::NewAccountModel::accountRemoved);
|
||||
|
||||
QVERIFY(accountRemovedSpy.wait());
|
||||
QCOMPARE(accountRemovedSpy.count(), 1);
|
||||
}
|
||||
globalEnv.lrcInstance->accountModel().removeAccount(
|
||||
globalEnv.lrcInstance->get_currentAccountId());
|
||||
|
||||
accountRemovedSpy.wait();
|
||||
EXPECT_EQ(accountRemovedSpy.count(), 1);
|
||||
|
||||
auto accountListSize = globalEnv.lrcInstance->accountModel().getAccountList().size();
|
||||
ASSERT_EQ(accountListSize, 0);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,18 @@ TestEnvironment globalEnv;
|
|||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
QDir tempDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
|
||||
|
||||
auto jamiDataDir = tempDir.absolutePath() + "\\jami_test\\jami";
|
||||
auto jamiConfigDir = tempDir.absolutePath() + "\\jami_test\\.config";
|
||||
auto jamiCacheDir = tempDir.absolutePath() + "\\jami_test\\.cache";
|
||||
|
||||
bool envSet = qputenv("JAMI_DATA_HOME", jamiDataDir.toLocal8Bit());
|
||||
envSet &= qputenv("JAMI_CONFIG_HOME", jamiConfigDir.toLocal8Bit());
|
||||
envSet &= qputenv("JAMI_CACHE_HOME", jamiCacheDir.toLocal8Bit());
|
||||
if (!envSet)
|
||||
return 1;
|
||||
|
||||
// Remove "-mutejamid" from argv, as quick_test_main_with_setup() will
|
||||
// fail if given an invalid command-line argument.
|
||||
auto end = std::remove_if(argv + 1, argv + argc, [](char* argv) {
|
||||
|
@ -40,8 +52,6 @@ main(int argc, char* argv[])
|
|||
argc = std::distance(argv, end);
|
||||
}
|
||||
|
||||
QStandardPaths::setTestModeEnabled(true);
|
||||
|
||||
QApplication a(argc, argv);
|
||||
a.processEvents();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue