unitTest: Add load_actors function

Load actors from YAML description for unit tests.

Change-Id: Id1840e2bd7244abf902c9be95589b82503c72840
This commit is contained in:
Olivier Dion
2021-06-01 11:51:18 -04:00
parent e4eb13038f
commit cabbc523a8
14 changed files with 152 additions and 233 deletions

View File

@ -0,0 +1,20 @@
default-account:
type: RING
upnpEnabled: "true"
archivePassword: ""
archivePIN: ""
archivePath: ""
accounts:
alice:
displayName: ALICE
alias: ALICE
bob:
displayName: BOB
alias: BOB
carla:
displayName: CARLA
alias: CARLA

View File

@ -0,0 +1,16 @@
default-account:
type: RING
upnpEnabled: "false"
archivePassword: ""
archivePIN: ""
archivePath: ""
accounts:
alice:
displayName: ALICE
alias: ALICE
bob:
displayName: BOB
alias: BOB

View File

@ -0,0 +1,16 @@
default-account:
type: RING
upnpEnabled: "true"
archivePassword: ""
archivePIN: ""
archivePath: ""
accounts:
alice:
displayName: ALICE
alias: ALICE
bob:
displayName: BOB
alias: BOB

View File

@ -76,31 +76,9 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(CallTest, CallTest::name());
void
CallTest::setUp()
{
std::map<std::string, std::string> details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "ALICE";
details[ConfProperties::ALIAS] = "ALICE";
details[ConfProperties::UPNP_ENABLED] = "true";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
aliceId = Manager::instance().addAccount(details);
details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "BOB";
details[ConfProperties::ALIAS] = "BOB";
details[ConfProperties::UPNP_ENABLED] = "true";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
bobId = Manager::instance().addAccount(details);
JAMI_INFO("Initialize account...");
auto aliceAccount = Manager::instance().getAccount<JamiAccount>(aliceId);
auto bobAccount = Manager::instance().getAccount<JamiAccount>(bobId);
wait_for_announcement_of({aliceId, bobId});
auto actors = load_actors_and_wait_for_announcement("actors/alice-bob.yml");
aliceId = actors["alice"];
bobId = actors["bob"];
}
void
@ -284,6 +262,7 @@ CallTest::testDeclineMultiDevice()
auto bobArchive = std::filesystem::current_path().string() + "/bob.gz";
std::remove(bobArchive.c_str());
bobAccount->exportArchive(bobArchive);
std::map<std::string, std::string> details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "BOB2";
@ -292,6 +271,7 @@ CallTest::testDeclineMultiDevice()
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = bobArchive;
bob2Id = Manager::instance().addAccount(details);
wait_for_announcement_of(bob2Id);

View File

@ -96,41 +96,10 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ConferenceTest, ConferenceTest::name());
void
ConferenceTest::setUp()
{
std::map<std::string, std::string> details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "ALICE";
details[ConfProperties::ALIAS] = "ALICE";
details[ConfProperties::UPNP_ENABLED] = "true";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
aliceId = Manager::instance().addAccount(details);
details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "BOB";
details[ConfProperties::ALIAS] = "BOB";
details[ConfProperties::UPNP_ENABLED] = "true";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
bobId = Manager::instance().addAccount(details);
details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "CARLA";
details[ConfProperties::ALIAS] = "CARLA";
details[ConfProperties::UPNP_ENABLED] = "true";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
carlaId = Manager::instance().addAccount(details);
JAMI_INFO("Initialize account...");
auto aliceAccount = Manager::instance().getAccount<JamiAccount>(aliceId);
auto bobAccount = Manager::instance().getAccount<JamiAccount>(bobId);
auto carlaAccount = Manager::instance().getAccount<JamiAccount>(carlaId);
wait_for_announcement_of({aliceId, bobId, carlaId}, std::chrono::seconds(60));
auto actors = load_actors_and_wait_for_announcement("actors/alice-bob-carla.yml");
aliceId = actors["alice"];
bobId = actors["bob"];
carlaId = actors["carla"];
bobCall.reset();
carlaCall.reset();

View File

@ -20,6 +20,12 @@
#pragma once
#include <yaml-cpp/yaml.h>
/* Jami */
#include "fileutils.h"
#include "manager.h"
static void
wait_for_announcement_of(const std::vector<std::string> accountIDs,
std::chrono::seconds timeout = std::chrono::seconds(30))
@ -77,3 +83,62 @@ wait_for_announcement_of(const std::string& accountId,
{
wait_for_announcement_of(std::vector<std::string> {accountId}, timeout);
}
static std::map<std::string, std::string>
load_actors(const std::string& from_yaml)
{
std::map<std::string, std::string> actors {};
std::map<std::string, std::string> default_details = DRing::getAccountTemplate("RING");
std::ifstream file = jami::fileutils::ifstream(from_yaml);
CPPUNIT_ASSERT(file.is_open());
YAML::Node node = YAML::Load(file);
CPPUNIT_ASSERT(node.IsMap());
auto default_account = node["default-account"];
if (default_account.IsMap()) {
for (const auto& kv : default_account) {
default_details["Account." + kv.first.as<std::string>()] = kv.second.as<std::string>();
}
}
auto accounts = node["accounts"];
CPPUNIT_ASSERT(accounts.IsMap());
for (const auto& kv : accounts) {
auto account_name = kv.first.as<std::string>();
auto account = kv.second.as<YAML::Node>();
auto details = std::map<std::string, std::string>(default_details);
for (const auto& detail : account) {
details["Account." + detail.first.as<std::string>()] = detail.second.as<std::string>();
}
actors[account_name] = jami::Manager::instance().addAccount(details);
}
return actors;
}
static std::map<std::string, std::string>
load_actors_and_wait_for_announcement(const std::string& from_yaml)
{
auto actors = load_actors(from_yaml);
std::vector<std::string> wait_for;
wait_for.reserve(actors.size());
for (auto it = actors.cbegin(); it != actors.cend(); ++it) {
wait_for.emplace_back(it->second);
}
wait_for_announcement_of(wait_for);
return actors;
}

View File

@ -103,28 +103,9 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ConnectionManagerTest, ConnectionManagerTe
void
ConnectionManagerTest::setUp()
{
std::map<std::string, std::string> details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "ALICE";
details[ConfProperties::ALIAS] = "ALICE";
details[ConfProperties::UPNP_ENABLED] = "true";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
aliceId = Manager::instance().addAccount(details);
details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "BOB";
details[ConfProperties::ALIAS] = "BOB";
details[ConfProperties::UPNP_ENABLED] = "true";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
bobId = Manager::instance().addAccount(details);
JAMI_INFO("Initialize account...");
wait_for_announcement_of({aliceId, bobId});
auto actors = load_actors_and_wait_for_announcement("actors/alice-bob.yml");
aliceId = actors["alice"];
bobId = actors["bob"];
}
void

View File

@ -215,39 +215,13 @@ ConversationTest::setUp()
if (not Manager::instance().initialized)
CPPUNIT_ASSERT(DRing::start("dring-sample.yml"));
std::map<std::string, std::string> details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "ALICE";
details[ConfProperties::ALIAS] = "ALICE";
details[ConfProperties::UPNP_ENABLED] = "true";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
aliceId = Manager::instance().addAccount(details);
auto actors = load_actors("actors/alice-bob-carla.yml");
aliceId = actors["alice"];
bobId = actors["bob"];
carlaId = actors["carla"];
details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "BOB";
details[ConfProperties::ALIAS] = "BOB";
details[ConfProperties::UPNP_ENABLED] = "true";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
bobId = Manager::instance().addAccount(details);
details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "CARLA";
details[ConfProperties::ALIAS] = "CARLA";
details[ConfProperties::UPNP_ENABLED] = "true";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
carlaId = Manager::instance().addAccount(details);
JAMI_INFO("Initialize account...");
Manager::instance().sendRegister(carlaId, false);
wait_for_announcement_of({aliceId, bobId});
wait_for_announcement_of({aliceId, bobId, carlaId});
}
void

View File

@ -109,28 +109,9 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ConversationRepositoryTest,
void
ConversationRepositoryTest::setUp()
{
std::map<std::string, std::string> details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "ALICE";
details[ConfProperties::ALIAS] = "ALICE";
details[ConfProperties::UPNP_ENABLED] = "true";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
aliceId = Manager::instance().addAccount(details);
details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "BOB";
details[ConfProperties::ALIAS] = "BOB";
details[ConfProperties::UPNP_ENABLED] = "true";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
bobId = Manager::instance().addAccount(details);
JAMI_INFO("Initialize account...");
wait_for_announcement_of({aliceId, bobId});
auto actors = load_actors_and_wait_for_announcement("actors/alice-bob.yml");
aliceId = actors["alice"];
bobId = actors["bob"];
}
void

View File

@ -89,28 +89,9 @@ FileTransferTest::compare(const std::string& fileA, const std::string& fileB) co
void
FileTransferTest::setUp()
{
std::map<std::string, std::string> details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "ALICE";
details[ConfProperties::ALIAS] = "ALICE";
details[ConfProperties::UPNP_ENABLED] = "true";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
aliceId = Manager::instance().addAccount(details);
details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "BOB";
details[ConfProperties::ALIAS] = "BOB";
details[ConfProperties::UPNP_ENABLED] = "true";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
bobId = Manager::instance().addAccount(details);
JAMI_INFO("Initialize account...");
wait_for_announcement_of({aliceId, bobId});
auto actors = load_actors_and_wait_for_announcement("actors/alice-bob.yml");
aliceId = actors["alice"];
bobId = actors["bob"];
}
void

View File

@ -178,19 +178,9 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(IceSdpParsingTest, IceSdpParsingTest::name
void
IceSdpParsingTest::setUp()
{
std::map<std::string, std::string> details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "ALICE";
details[ConfProperties::ALIAS] = "ALICE";
details[ConfProperties::UPNP_ENABLED] = "false";
aliceData_.accountId_ = Manager::instance().addAccount(details);
details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "BOB";
details[ConfProperties::ALIAS] = "BOB";
details[ConfProperties::UPNP_ENABLED] = "false";
bobData_.accountId_ = Manager::instance().addAccount(details);
auto actors = load_actors("actors/alice-bob-no-upnp.yml");
aliceData_.accountId_ = actors["alice"];
bobData_.accountId_ = actors["bob"];
JAMI_INFO("Initializing accounts ...");
auto aliceAccount = Manager::instance().getAccount<JamiAccount>(aliceData_.accountId_);

View File

@ -123,29 +123,9 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(MediaControlTest, MediaControlTest::name()
void
MediaControlTest::setUp()
{
std::map<std::string, std::string> details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "ALICE";
details[ConfProperties::ALIAS] = "ALICE";
details[ConfProperties::UPNP_ENABLED] = "false";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
aliceAccountId_ = Manager::instance().addAccount(details);
details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "BOB";
details[ConfProperties::ALIAS] = "BOB";
details[ConfProperties::UPNP_ENABLED] = "false";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
bobAccountId_ = Manager::instance().addAccount(details);
JAMI_INFO("Initialize account...");
wait_for_announcement_of({aliceAccountId_, bobAccountId_});
auto actors = load_actors_and_wait_for_announcement("actors/alice-bob-no-upnpp.yml");
aliceAccountId_ = actors["alice"];
bobAccountId_ = actors["bob"];
}
void

View File

@ -160,25 +160,10 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(MediaNegotiationTest, MediaNegotiationTest
void
MediaNegotiationTest::setUp()
{
std::map<std::string, std::string> details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "ALICE";
details[ConfProperties::ALIAS] = "ALICE";
details[ConfProperties::UPNP_ENABLED] = "false";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
aliceData_.accountId_ = Manager::instance().addAccount(details);
auto actors = load_actors("actors/alice-bob-no-upnp.yml");
details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "BOB";
details[ConfProperties::ALIAS] = "BOB";
details[ConfProperties::UPNP_ENABLED] = "false";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
bobData_.accountId_ = Manager::instance().addAccount(details);
aliceData_.accountId_ = actors["alice"];
bobData_.accountId_ = actors["bob"];
JAMI_INFO("Initialize account...");
auto aliceAccount = Manager::instance().getAccount<JamiAccount>(aliceData_.accountId_);

View File

@ -86,28 +86,9 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SyncHistoryTest, SyncHistoryTest::name());
void
SyncHistoryTest::setUp()
{
std::map<std::string, std::string> details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "ALICE";
details[ConfProperties::ALIAS] = "ALICE";
details[ConfProperties::UPNP_ENABLED] = "true";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
aliceId = Manager::instance().addAccount(details);
details = DRing::getAccountTemplate("RING");
details[ConfProperties::TYPE] = "RING";
details[ConfProperties::DISPLAYNAME] = "BOB";
details[ConfProperties::ALIAS] = "BOB";
details[ConfProperties::UPNP_ENABLED] = "true";
details[ConfProperties::ARCHIVE_PASSWORD] = "";
details[ConfProperties::ARCHIVE_PIN] = "";
details[ConfProperties::ARCHIVE_PATH] = "";
bobId = Manager::instance().addAccount(details);
JAMI_INFO("Initialize account...");
wait_for_announcement_of({aliceId, bobId});
auto actors = load_actors_and_wait_for_announcement("actors/alice-bob.yml");
aliceId = actors["alice"];
bobId = actors["bob"];
alice2Id = "";
}