auto-answer - add unit test

Add a media negotiation unit test for auto-answer mode

Gitlab: #645

Change-Id: I37f768ce48e078fbd95a2c9b28997877a4dc468d
This commit is contained in:
Mohamed Chibani
2021-11-18 09:31:49 -05:00
parent c74375b3f8
commit 38981578d5
6 changed files with 1103 additions and 30 deletions

View File

@ -200,7 +200,7 @@ createConfFromParticipantList(const std::string& accountId,
void
setConferenceLayout(const std::string& accountId, const std::string& confId, uint32_t layout)
{
if (const auto account = jami::Manager::instance().getAccount(accountId))
if (const auto account = jami::Manager::instance().getAccount(accountId)) {
if (auto conf = account->getConference(confId)) {
conf->setLayout(layout);
} else if (auto call = account->getCall(confId)) {
@ -208,6 +208,7 @@ setConferenceLayout(const std::string& accountId, const std::string& confId, uin
root["layout"] = layout;
call->sendConfOrder(root);
}
}
}
void
@ -215,7 +216,7 @@ setActiveParticipant(const std::string& accountId,
const std::string& confId,
const std::string& participant)
{
if (const auto account = jami::Manager::instance().getAccount(accountId))
if (const auto account = jami::Manager::instance().getAccount(accountId)) {
if (auto conf = account->getConference(confId)) {
conf->setActiveParticipant(participant);
} else if (auto call = account->getCall(confId)) {
@ -223,6 +224,7 @@ setActiveParticipant(const std::string& accountId,
root["activeParticipant"] = participant;
call->sendConfOrder(root);
}
}
}
bool

View File

@ -2524,19 +2524,29 @@ SIPCall::handleMediaChangeRequest(const std::vector<DRing::MediaMap>& remoteMedi
return;
}
// If the offered media differ from the current local media, the
// request is reported to the client to be processed. Otherwise,
// it will be processed using the current local media.
if (checkMediaChangeRequest(remoteMediaList)) {
// Report the media change request.
emitSignal<DRing::CallSignal::MediaChangeRequested>(getAccountId(),
getCallId(),
remoteMediaList);
} else {
auto localMediaList = MediaAttribute::mediaAttributesToMediaMaps(getMediaAttributeList());
answerMediaChangeRequest(localMediaList);
// If the offered media does not differ from the current local media, the
// request is answered using the current local media.
if (not checkMediaChangeRequest(remoteMediaList)) {
answerMediaChangeRequest(
MediaAttribute::mediaAttributesToMediaMaps(getMediaAttributeList()));
return;
}
if (account->isAutoAnswerEnabled()) {
// NOTE:
// Since the auto-answer is enabled in the account, media change requests
// are automatically accepted too. This also means that if the original
// call was an audio-only call, and the remote added the video, the local
// camera will be enabled, unless the video is disabled in the account
// settings.
answerMediaChangeRequest(remoteMediaList);
return;
}
// Report the media change request.
emitSignal<DRing::CallSignal::MediaChangeRequested>(getAccountId(),
getCallId(),
remoteMediaList);
}
pj_status_t

View File

@ -5,15 +5,42 @@
#include <cppunit/CompilerOutputter.h>
#define RING_TEST_RUNNER(suite_name) \
int main() \
{ \
CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry(suite_name); \
CppUnit::Test *suite = registry.makeTest(); \
if(suite->countTestCases() == 0) { \
std::cout << "No test cases specified for suite \"" << suite_name << "\"\n"; \
return 1; \
} \
CppUnit::TextUi::TestRunner runner; \
runner.addTest(suite); \
return runner.run() ? 0 : 1; \
}
int main() \
{ \
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry( \
suite_name); \
CppUnit::Test* suite = registry.makeTest(); \
if (suite->countTestCases() == 0) { \
std::cout << "No test cases specified for suite \"" << suite_name << "\"\n"; \
return 1; \
} \
CppUnit::TextUi::TestRunner runner; \
runner.addTest(suite); \
return runner.run() ? 0 : 1; \
}
// This version of the test runner is similar to RING_TEST_RUNNER but
// can take multiple unit tests.
// It's practical to run a test for diffrent configs, for instance when
// running the same test for both Jami and SIP accounts.
// The test will abort if a test fails.
#define JAMI_TEST_RUNNER(...) \
int main() \
{ \
std::vector<std::string> suite_names {__VA_ARGS__}; \
for (const std::string& name : suite_names) { \
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry( \
name); \
CppUnit::Test* suite = registry.makeTest(); \
if (suite->countTestCases() == 0) { \
std::cout << "No test cases specified for suite \"" << name << "\"\n"; \
continue; \
} \
CppUnit::TextUi::TestRunner runner; \
runner.addTest(suite); \
if (not runner.run()) \
return 1; \
} \
return 0; \
}

View File

@ -157,6 +157,8 @@ check_PROGRAMS += ut_media_negotiation
ut_media_negotiation_SOURCES = media_negotiation/media_negotiation.cpp common.cpp
check_PROGRAMS += ut_hold_resume
ut_hold_resume_SOURCES = media_negotiation/hold_resume.cpp common.cpp
check_PROGRAMS += ut_auto_answer
ut_auto_answer_SOURCES = media_negotiation/auto_answer.cpp common.cpp
#
# compability

File diff suppressed because it is too large Load Diff

View File

@ -147,7 +147,9 @@ private:
// Helpers
static void configureScenario(CallData& bob, CallData& alice);
void testWithScenario(CallData& aliceData, CallData& bobData, const TestScenario& scenario);
static void testWithScenario(CallData& aliceData,
CallData& bobData,
const TestScenario& scenario);
static std::string getUserAlias(const std::string& callId);
// Infer media direction of an offer.
static uint8_t directionToBitset(MediaDirection direction, bool isLocal);
@ -666,7 +668,7 @@ MediaNegotiationTest::testWithScenario(CallData& aliceData,
// Answer the call.
{
auto const& mediaList = MediaAttribute::mediaAttributesToMediaMaps(scenario.answer_);
Manager::instance().answerCall(bobData.accountId_, bobData.callId_, mediaList);
DRing::acceptWithMedia(bobData.accountId_, bobData.callId_, mediaList);
}
// Wait for media negotiation complete signal.
@ -798,7 +800,7 @@ MediaNegotiationTest::testWithScenario(CallData& aliceData,
// Bob hang-up.
JAMI_INFO("Hang up BOB's call and wait for ALICE to hang up");
Manager::instance().hangupCall(bobData.accountId_, bobData.callId_);
DRing::hangUp(bobData.accountId_, bobData.callId_);
CPPUNIT_ASSERT_EQUAL(true,
waitForSignal(aliceData,
@ -1026,4 +1028,4 @@ MediaNegotiationTest::audio_and_video_then_change_video_source()
} // namespace test
} // namespace jami
RING_TEST_RUNNER(jami::test::MediaNegotiationTest::name())
JAMI_TEST_RUNNER(jami::test::MediaNegotiationTest::name())