mirror of
https://github.com/savoirfairelinux/jami-client-qt.git
synced 2025-12-18 08:35:26 +08: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:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user