Skip to content
Snippets Groups Projects
Commit 68b21ee3 authored by Olivier Dion's avatar Olivier Dion Committed by Sébastien Blin
Browse files

unitTest: Share common.cpp between check programs

Change-Id: I88c44743227dc264a7bae899caccbb02b7a29a69
parent 5c2008a2
No related branches found
No related tags found
No related merge requests found
......@@ -11,159 +11,159 @@ check_PROGRAMS =
# account_factory
#
check_PROGRAMS += ut_account_factory
ut_account_factory_SOURCES = account_factory/testAccount_factory.cpp
ut_account_factory_SOURCES = account_factory/testAccount_factory.cpp common.cpp
#
# certstore
#
check_PROGRAMS += ut_certstore
ut_certstore_SOURCES = certstore.cpp
ut_certstore_SOURCES = certstore.cpp common.cpp
ut_certstore_LDADD = @OPENDHT_LIBS@
#
# scheduler
#
check_PROGRAMS += ut_scheduler
ut_scheduler_SOURCES = scheduler.cpp
ut_scheduler_SOURCES = scheduler.cpp common.cpp
ut_scheduler_LDADD = @OPENDHT_LIBS@
#
# base64
#
check_PROGRAMS += ut_base64
ut_base64_SOURCES = base64/base64.cpp
ut_base64_SOURCES = base64/base64.cpp common.cpp
#
# map_utils
#
check_PROGRAMS += ut_map_utils
ut_map_utils_SOURCES = map_utils/testMap_utils.cpp
ut_map_utils_SOURCES = map_utils/testMap_utils.cpp common.cpp
#
# fileutils
#
check_PROGRAMS += ut_fileutils
ut_fileutils_SOURCES = fileutils/testFileutils.cpp
ut_fileutils_SOURCES = fileutils/testFileutils.cpp common.cpp
#
# smartools
#
check_PROGRAMS += ut_smartools
ut_smartools_SOURCES = smartools/testSmartools.cpp
ut_smartools_SOURCES = smartools/testSmartools.cpp common.cpp
#
# utf8_utils
#
check_PROGRAMS += ut_utf8_utils
ut_utf8_utils_SOURCES = utf8_utils/testUtf8_utils.cpp
ut_utf8_utils_SOURCES = utf8_utils/testUtf8_utils.cpp common.cpp
#
# string_utils
#
check_PROGRAMS += ut_string_utils
ut_string_utils_SOURCES = string_utils/testString_utils.cpp
ut_string_utils_SOURCES = string_utils/testString_utils.cpp common.cpp
#
# video_input
#
check_PROGRAMS += ut_video_input
ut_video_input_SOURCES = media/video/testVideo_input.cpp
ut_video_input_SOURCES = media/video/testVideo_input.cpp common.cpp
#
# media_encoder
#
check_PROGRAMS += ut_media_encoder
ut_media_encoder_SOURCES = media/test_media_encoder.cpp
ut_media_encoder_SOURCES = media/test_media_encoder.cpp common.cpp
#
# media_decoder
#
check_PROGRAMS += ut_media_decoder
ut_media_decoder_SOURCES = media/test_media_decoder.cpp
ut_media_decoder_SOURCES = media/test_media_decoder.cpp common.cpp
#
# media_filter
#
check_PROGRAMS += ut_media_filter
ut_media_filter_SOURCES = media/test_media_filter.cpp
ut_media_filter_SOURCES = media/test_media_filter.cpp common.cpp
#
# resampler
#
check_PROGRAMS += ut_resampler
ut_resampler_SOURCES = media/audio/test_resampler.cpp
ut_resampler_SOURCES = media/audio/test_resampler.cpp common.cpp
#
# media_frame
#
check_PROGRAMS += ut_media_frame
ut_media_frame_SOURCES = media/test_media_frame.cpp
ut_media_frame_SOURCES = media/test_media_frame.cpp common.cpp
#
# video_scaler
#
check_PROGRAMS += ut_video_scaler
ut_video_scaler_SOURCES = media/video/test_video_scaler.cpp
ut_video_scaler_SOURCES = media/video/test_video_scaler.cpp common.cpp
#
# audio_frame_resizer
#
check_PROGRAMS += ut_audio_frame_resizer
ut_audio_frame_resizer_SOURCES = media/audio/test_audio_frame_resizer.cpp
ut_audio_frame_resizer_SOURCES = media/audio/test_audio_frame_resizer.cpp common.cpp
#
# call
#
check_PROGRAMS += ut_call
ut_call_SOURCES = call/call.cpp
ut_call_SOURCES = call/call.cpp common.cpp
#
# conference
#
check_PROGRAMS += ut_conference
ut_conference_SOURCES = call/conference.cpp
ut_conference_SOURCES = call/conference.cpp common.cpp
#
# connectionManager
#
check_PROGRAMS += ut_connectionManager
ut_connectionManager_SOURCES = connectionManager/connectionManager.cpp
ut_connectionManager_SOURCES = connectionManager/connectionManager.cpp common.cpp
#
# fileTransfer
#
check_PROGRAMS += ut_fileTransfer
ut_fileTransfer_SOURCES = fileTransfer/fileTransfer.cpp
ut_fileTransfer_SOURCES = fileTransfer/fileTransfer.cpp common.cpp
# conversationRepository
#
check_PROGRAMS += ut_conversationRepository
ut_conversationRepository_SOURCES = conversationRepository/conversationRepository.cpp
ut_conversationRepository_SOURCES = conversationRepository/conversationRepository.cpp common.cpp
#
# conversation
#
check_PROGRAMS += ut_conversation
ut_conversation_SOURCES = conversation/conversation.cpp
ut_conversation_SOURCES = conversation/conversation.cpp common.cpp
#
# media_negotiation
#
check_PROGRAMS += ut_media_negotiation
ut_media_negotiation_SOURCES = media_negotiation/media_negotiation.cpp
ut_media_negotiation_SOURCES = media_negotiation/media_negotiation.cpp common.cpp
#
# syncHistory
#
check_PROGRAMS += ut_syncHistory
ut_syncHistory_SOURCES = syncHistory/syncHistory.cpp
ut_syncHistory_SOURCES = syncHistory/syncHistory.cpp common.cpp
#
# ice
#
check_PROGRAMS += ut_ice
ut_ice_SOURCES = ice/ice.cpp
ut_ice_SOURCES = ice/ice.cpp common.cpp
check_PROGRAMS += ut_ice_sdp_parser
ut_ice_sdp_parser_SOURCES = ice/ice_sdp_parser.cpp
ut_ice_sdp_parser_SOURCES = ice/ice_sdp_parser.cpp common.cpp
TESTS = $(check_PROGRAMS)
/*
* Copyright (C) 2021 Savoir-faire Linux Inc.
*
* Author: Olivier Dion <olivier.dion>@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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <cppunit/TestAssert.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <yaml-cpp/yaml.h>
/* Jami */
#include "account_const.h"
#include "dring.h"
#include "fileutils.h"
#include "manager.h"
/* Make GCC quiet about unused functions */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
void
wait_for_announcement_of(const std::vector<std::string> accountIDs,
std::chrono::seconds timeout = std::chrono::seconds(30))
{
std::map<std::string, std::shared_ptr<DRing::CallbackWrapperBase>> confHandlers;
std::mutex mtx;
std::unique_lock<std::mutex> lk {mtx};
std::condition_variable cv;
std::vector<std::atomic_bool> accountsReady(accountIDs.size());
confHandlers.insert(
DRing::exportable_callback<DRing::ConfigurationSignal::VolatileDetailsChanged>(
[&](const std::string& accountID, const std::map<std::string, std::string>& details) {
for (size_t i = 0; i < accountIDs.size(); ++i) {
if (accountIDs[i] != accountID) {
continue;
}
try {
if ("true"
!= details.at(DRing::Account::VolatileProperties::DEVICE_ANNOUNCED)) {
continue;
}
} catch (const std::out_of_range&) {
continue;
}
accountsReady[i] = true;
cv.notify_one();
}
}));
JAMI_DBG("Waiting for %zu account to be announced...", accountIDs.size());
DRing::registerSignalHandlers(confHandlers);
CPPUNIT_ASSERT(cv.wait_for(lk, timeout, [&] {
for (const auto& rdy : accountsReady) {
if (not rdy) {
return false;
}
}
return true;
}));
DRing::unregisterSignalHandlers();
JAMI_DBG("%zu account announced!", accountIDs.size());
}
void
wait_for_announcement_of(const std::string& accountId,
std::chrono::seconds timeout = std::chrono::seconds(30))
{
wait_for_announcement_of(std::vector<std::string> {accountId}, timeout);
}
void
wait_for_removal_of(const std::vector<std::string> accounts,
std::chrono::seconds timeout = std::chrono::seconds(30))
{
JAMI_INFO("Removing %zu accounts...", accounts.size());
std::map<std::string, std::shared_ptr<DRing::CallbackWrapperBase>> confHandlers;
std::mutex mtx;
std::unique_lock<std::mutex> lk {mtx};
std::condition_variable cv;
std::atomic_bool accountsRemoved {false};
size_t current = jami::Manager::instance().getAccountList().size();
/* Prevent overflow */
CPPUNIT_ASSERT(current >= accounts.size());
size_t target = current - accounts.size();
confHandlers.insert(
DRing::exportable_callback<DRing::ConfigurationSignal::AccountsChanged>([&]() {
if (jami::Manager::instance().getAccountList().size() <= target) {
accountsRemoved = true;
cv.notify_one();
}
}));
DRing::unregisterSignalHandlers();
DRing::registerSignalHandlers(confHandlers);
for (const auto& account : accounts) {
jami::Manager::instance().removeAccount(account, true);
}
CPPUNIT_ASSERT(cv.wait_for(lk, timeout, [&] { return accountsRemoved.load(); }));
DRing::unregisterSignalHandlers();
}
void
wait_for_removal_of(const std::string& account,
std::chrono::seconds timeout = std::chrono::seconds(30))
{
wait_for_removal_of(std::vector<std::string>{account}, timeout);
}
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;
}
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;
}
#pragma GCC diagnostic pop
......@@ -20,177 +20,27 @@
#pragma once
#include <yaml-cpp/yaml.h>
constexpr size_t WAIT_FOR_ANNOUNCEMENT_TIMEOUT = 30;
constexpr size_t WAIT_FOR_REMOVAL_TIMEOUT = 30;
/* Jami */
#include "fileutils.h"
#include "manager.h"
/* Make GCC quiet about unused functions */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
static void
extern void
wait_for_announcement_of(const std::vector<std::string> accountIDs,
std::chrono::seconds timeout = std::chrono::seconds(30))
{
std::map<std::string, std::shared_ptr<DRing::CallbackWrapperBase>> confHandlers;
std::mutex mtx;
std::unique_lock<std::mutex> lk {mtx};
std::condition_variable cv;
std::vector<std::atomic_bool> accountsReady(accountIDs.size());
confHandlers.insert(
DRing::exportable_callback<DRing::ConfigurationSignal::VolatileDetailsChanged>(
[&](const std::string& accountID, const std::map<std::string, std::string>& details) {
for (size_t i = 0; i < accountIDs.size(); ++i) {
if (accountIDs[i] != accountID) {
continue;
}
try {
if ("true"
!= details.at(DRing::Account::VolatileProperties::DEVICE_ANNOUNCED)) {
continue;
}
} catch (const std::out_of_range&) {
continue;
}
accountsReady[i] = true;
cv.notify_one();
}
}));
JAMI_DBG("Waiting for %zu account to be announced...", accountIDs.size());
DRing::registerSignalHandlers(confHandlers);
CPPUNIT_ASSERT(cv.wait_for(lk, timeout, [&] {
for (const auto& rdy : accountsReady) {
if (not rdy) {
return false;
}
}
return true;
}));
DRing::unregisterSignalHandlers();
std::chrono::seconds timeout = std::chrono::seconds(WAIT_FOR_ANNOUNCEMENT_TIMEOUT));
JAMI_DBG("%zu account announced!", accountIDs.size());
}
static void
extern void
wait_for_announcement_of(const std::string& accountId,
std::chrono::seconds timeout = std::chrono::seconds(30))
{
wait_for_announcement_of(std::vector<std::string> {accountId}, timeout);
}
std::chrono::seconds timeout = std::chrono::seconds(WAIT_FOR_ANNOUNCEMENT_TIMEOUT));
static void
extern void
wait_for_removal_of(const std::vector<std::string> accounts,
std::chrono::seconds timeout = std::chrono::seconds(30))
{
JAMI_INFO("Removing %zu accounts...", accounts.size());
std::map<std::string, std::shared_ptr<DRing::CallbackWrapperBase>> confHandlers;
std::mutex mtx;
std::unique_lock<std::mutex> lk {mtx};
std::condition_variable cv;
std::atomic_bool accountsRemoved {false};
size_t current = jami::Manager::instance().getAccountList().size();
/* Prevent overflow */
CPPUNIT_ASSERT(current >= accounts.size());
size_t target = current - accounts.size();
confHandlers.insert(
DRing::exportable_callback<DRing::ConfigurationSignal::AccountsChanged>([&]() {
if (jami::Manager::instance().getAccountList().size() <= target) {
accountsRemoved = true;
cv.notify_one();
}
}));
DRing::unregisterSignalHandlers();
DRing::registerSignalHandlers(confHandlers);
for (const auto& account : accounts) {
jami::Manager::instance().removeAccount(account, true);
}
CPPUNIT_ASSERT(cv.wait_for(lk, timeout, [&] { return accountsRemoved.load(); }));
std::chrono::seconds timeout = std::chrono::seconds(WAIT_FOR_REMOVAL_TIMEOUT));
DRing::unregisterSignalHandlers();
}
static void
extern void
wait_for_removal_of(const std::string& account,
std::chrono::seconds timeout = std::chrono::seconds(30))
{
wait_for_removal_of(std::vector<std::string>{account}, 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);
std::chrono::seconds timeout = std::chrono::seconds(WAIT_FOR_REMOVAL_TIMEOUT));
return actors;
}
extern std::map<std::string, std::string>
load_actors(const std::string& from_yaml);
#pragma GCC diagnostic pop
extern std::map<std::string, std::string>
load_actors_and_wait_for_announcement(const std::string& from_yaml);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment