307 lines
8.5 KiB
C++
Executable File
307 lines
8.5 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*
|
|
* Created by Gerlinde Rudolphus, SLSE, 2017-10-20
|
|
*/
|
|
|
|
/**
|
|
* @file
|
|
* Requirements for this test:
|
|
* - an exercise
|
|
* - an operator
|
|
* - svcAudioVideoManagement -e 0
|
|
*
|
|
* How to start?
|
|
* - avmVcaTests [-d <domainId>] [-e <exerciseId>] [--operatorid=<operatorId>] [-- <QTest options>]
|
|
* - default exercise is 42
|
|
* - default operator is 22
|
|
*/
|
|
|
|
#include "avm_vca_tests.h"
|
|
#include <AudioVideoManagement/avm_dtc.h>
|
|
#include <nglapplication/nglcoreapplication.h>
|
|
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
|
#include <QTest>
|
|
#include <QtGlobal>
|
|
#include <QStringList>
|
|
#include <QMap>
|
|
#include <string>
|
|
#include <algorithm>
|
|
#include <iterator>
|
|
|
|
namespace AudioVideoManagement
|
|
{
|
|
|
|
AvmVcaTests::AvmVcaTests(int domainId, int exerciseId, int operatorId)
|
|
: m_ddsConnector(std::make_shared<DDSConnector::DdsConnector>(domainId, IDL::PartitionType::Exercise))
|
|
, m_exerciseId(exerciseId)
|
|
, m_operatorId(operatorId)
|
|
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("VcaTest"))
|
|
{
|
|
Q_ASSERT(exerciseId > 0);
|
|
Q_ASSERT(operatorId > 0);
|
|
|
|
bool status = m_ddsConnector->init();
|
|
Q_ASSERT(status);
|
|
m_ddsConnector->initPublisherSubscriber();
|
|
|
|
m_ftc = Interface::Ftc::create(m_ddsConnector);
|
|
status = m_ftc->enableAll();
|
|
Q_ASSERT(status);
|
|
|
|
m_dtc = Interface::Dtc::create(m_ddsConnector);
|
|
status = m_dtc->enableAll();
|
|
Q_ASSERT(status);
|
|
}
|
|
|
|
void AvmVcaTests::initTestCase()
|
|
{
|
|
createTvcConfig();
|
|
createCnrConfig();
|
|
}
|
|
|
|
void AvmVcaTests::cleanupTestCase()
|
|
{
|
|
removeTvcConfig();
|
|
removeCnrConfig();
|
|
}
|
|
|
|
void AvmVcaTests::test()
|
|
{
|
|
create();
|
|
QVERIFY(!QTest::currentTestFailed());
|
|
modify();
|
|
QVERIFY(!QTest::currentTestFailed());
|
|
remove();
|
|
QVERIFY(!QTest::currentTestFailed());
|
|
}
|
|
|
|
void AvmVcaTests::create()
|
|
{
|
|
CnrTvcProfile createRequest;
|
|
|
|
createRequest.id(0); // create
|
|
createRequest.exerciseId(m_exerciseId);
|
|
createRequest.operatorId(m_operatorId);
|
|
|
|
createRequest.data().resize(3);
|
|
createRequest.data()[0] = CnrTvcProfileData(m_cnrConfigIds.at(0), RadioSystem::Cnr);
|
|
createRequest.data()[1] = CnrTvcProfileData(m_tvcConfigIds.at(0), RadioSystem::Tvc);
|
|
createRequest.data()[2] = CnrTvcProfileData(m_cnrConfigIds.at(1), RadioSystem::Cnr);
|
|
|
|
m_modifyReplyReceived = false;
|
|
bool status = m_ftc->modifyCnrTvcProfileRequest(createRequest, this);
|
|
QVERIFY(status);
|
|
QTRY_VERIFY(m_modifyReplyReceived);
|
|
QVERIFY(m_circuitId > 0);
|
|
|
|
CnrTvcProfile expected = createRequest;
|
|
expected.id(m_circuitId);
|
|
QTRY_COMPARE(m_dtc->cnrTvcProfile(m_circuitId), expected);
|
|
}
|
|
|
|
void AvmVcaTests::modify()
|
|
{
|
|
CnrTvcProfile request;
|
|
|
|
request.id(m_circuitId); // modify
|
|
request.exerciseId(m_exerciseId);
|
|
request.operatorId(m_operatorId);
|
|
|
|
request.data().resize(4);
|
|
request.data()[0] = CnrTvcProfileData(m_tvcConfigIds.at(0), RadioSystem::Tvc);
|
|
request.data()[1] = CnrTvcProfileData(m_tvcConfigIds.at(1), RadioSystem::Tvc);
|
|
request.data()[2] = CnrTvcProfileData(m_cnrConfigIds.at(2), RadioSystem::Cnr);
|
|
request.data()[3] = CnrTvcProfileData(m_cnrConfigIds.at(1), RadioSystem::Cnr);
|
|
|
|
m_modifyReplyReceived = false;
|
|
bool status = m_ftc->modifyCnrTvcProfileRequest(request, this);
|
|
QVERIFY(status);
|
|
QTRY_VERIFY(m_modifyReplyReceived);
|
|
QCOMPARE(m_circuitId, request.id());
|
|
|
|
CnrTvcProfile expected = request;
|
|
QTRY_COMPARE(m_dtc->cnrTvcProfile(m_circuitId), expected);
|
|
}
|
|
|
|
void AvmVcaTests::remove()
|
|
{
|
|
Core::RemoveElementRequest request;
|
|
request.id(m_circuitId);
|
|
|
|
m_removeReplyReceived = false;
|
|
bool status = m_ftc->removeCnrTvcProfileRequest(request, this);
|
|
QVERIFY(status);
|
|
QTRY_VERIFY(m_removeReplyReceived);
|
|
QCOMPARE(m_circuitId, request.id());
|
|
|
|
CnrTvcProfile expected;
|
|
QTRY_COMPARE(m_dtc->cnrTvcProfile(m_circuitId), expected);
|
|
}
|
|
|
|
void AvmVcaTests::onModifyCnrTvcProfileReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
m_modifyReplyReceived = true;
|
|
QVERIFY2(!replyObject.error(), replyObject.str().c_str());
|
|
m_circuitId = replyObject.id();
|
|
}
|
|
|
|
void AvmVcaTests::onRemoveCnrTvcProfileReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
m_removeReplyReceived = true;
|
|
QVERIFY2(!replyObject.error(), replyObject.str().c_str());
|
|
m_circuitId = replyObject.id();
|
|
}
|
|
|
|
void AvmVcaTests::createTvcConfig()
|
|
{
|
|
ModifyTvcConfigRequest createRequest{0, 1, "tvc01", false, 42, "test"};
|
|
bool status = m_ftc->modifyTvcConfigRequest(createRequest, this);
|
|
Q_ASSERT(status);
|
|
|
|
createRequest = {0, 2, "tvc02", false, 42, "test2"};
|
|
status = m_ftc->modifyTvcConfigRequest(createRequest, this);
|
|
Q_ASSERT(status);
|
|
|
|
createRequest = {0, 3, "tvc03", false, 42, ""};
|
|
status = m_ftc->modifyTvcConfigRequest(createRequest, this);
|
|
Q_ASSERT(status);
|
|
|
|
QTRY_VERIFY(m_tvcConfigIds.size() == 3);
|
|
}
|
|
|
|
void AvmVcaTests::createCnrConfig()
|
|
{
|
|
ModifyCnrConfigRequest createRequest{0, 3, m_exerciseId, "vhf01", false, {}, 0, "call sign"};
|
|
bool status = m_ftc->modifyCnrConfigRequest(createRequest, this);
|
|
Q_ASSERT(status);
|
|
|
|
createRequest = {0, 4, m_exerciseId, "vhf02", false, {}, 0, "call sign"};
|
|
status = m_ftc->modifyCnrConfigRequest(createRequest, this);
|
|
Q_ASSERT(status);
|
|
|
|
createRequest = {0, 5, m_exerciseId, "vhf03", false, {}, 0, "call sign"};
|
|
status = m_ftc->modifyCnrConfigRequest(createRequest, this);
|
|
Q_ASSERT(status);
|
|
|
|
QTRY_VERIFY(m_cnrConfigIds.size() == 3);
|
|
}
|
|
|
|
void AvmVcaTests::removeTvcConfig()
|
|
{
|
|
for (auto id: qAsConst(m_tvcConfigIds))
|
|
m_ftc->removeTvcConfigRequest(RemoveTvcConfigRequest{id}, this);
|
|
QTRY_VERIFY(m_tvcConfigIds.isEmpty());
|
|
}
|
|
|
|
void AvmVcaTests::removeCnrConfig()
|
|
{
|
|
for (auto id: qAsConst(m_cnrConfigIds))
|
|
m_ftc->removeCnrConfigRequest(RemoveCnrConfigRequest{id}, this);
|
|
QTRY_VERIFY(m_cnrConfigIds.isEmpty());
|
|
}
|
|
|
|
void AvmVcaTests::onModifyTvcConfigReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
QVERIFY(!replyObject.error());
|
|
m_tvcConfigIds.push_back(replyObject.id());
|
|
}
|
|
|
|
void AvmVcaTests::onModifyCnrConfigReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
QVERIFY(!replyObject.error());
|
|
m_cnrConfigIds.push_back(replyObject.id());
|
|
}
|
|
|
|
void AvmVcaTests::onRemoveTvcConfigReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
QVERIFY(!replyObject.error());
|
|
m_tvcConfigIds.removeAll(replyObject.id());
|
|
}
|
|
|
|
void AvmVcaTests::onRemoveCnrConfigReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
QVERIFY(!replyObject.error());
|
|
QVERIFY(!replyObject.error());
|
|
m_cnrConfigIds.removeAll(replyObject.id());
|
|
}
|
|
|
|
} // end namespace
|
|
|
|
|
|
using namespace AudioVideoManagement;
|
|
|
|
|
|
namespace
|
|
{
|
|
const int EXERCISE_42 = 42;
|
|
const int OPERATOR = 22;
|
|
|
|
//-----------------------------------------------------------------------------
|
|
class CmdLineParser : public LtsCommandLineParser::LtsCommandLineParser
|
|
{
|
|
public:
|
|
CmdLineParser()
|
|
: LtsCommandLineParser()
|
|
{
|
|
addOption( { QStringList() << QLatin1String("o") << QLatin1String("operatorId")
|
|
, QLatin1String("OperatorId.")
|
|
, QLatin1String("Operator")
|
|
, QString::number(OPERATOR)
|
|
} );
|
|
|
|
}
|
|
|
|
int operatorId() const { return isSet(QLatin1String("o")) ? value(QLatin1String("o")).toInt() : OPERATOR; }
|
|
};
|
|
|
|
|
|
/**
|
|
* The command line options are possibly separated by "--".
|
|
* All options left from "--" are consumed by ourselves.
|
|
* Options right from "--" are cosumed by QTest::qExec().
|
|
*/
|
|
int findDoubleDash(int argc, char **argv)
|
|
{
|
|
const std::string doubleDash{"--"};
|
|
auto found = std::find_if(&argv[0], &argv[argc], [&doubleDash] (const char *s) { return s == doubleDash; });
|
|
return found - argv;
|
|
}
|
|
|
|
/**
|
|
* Retrun all the command line options right of "--". These are supposed to be given to QTest::qExec().
|
|
*/
|
|
QStringList qTestOptions(int argc, char **argv, int dashIndex)
|
|
{
|
|
Q_ASSERT(argc > 0);
|
|
Q_ASSERT(dashIndex > 0 && dashIndex <= argc);
|
|
QStringList options{QString::fromUtf8(argv[0])}; // program name
|
|
if (dashIndex == argc)
|
|
return options;
|
|
|
|
std::transform(&argv[dashIndex + 1], &argv[argc], std::back_inserter(options), [] (const char *s) { return QString::fromUtf8(s); });
|
|
return options;
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
int dashIndex = findDoubleDash(argc, argv);
|
|
NGLCoreApplication app(dashIndex, argv);
|
|
app.createLogger("avm", "log4cxx_avm.props");
|
|
|
|
CmdLineParser cmdlineOptions;
|
|
Q_ASSERT(cmdlineOptions.init());
|
|
|
|
const int exerciseId = cmdlineOptions.exerciseId() > 0 ? cmdlineOptions.exerciseId() : EXERCISE_42;
|
|
AvmVcaTests tests{cmdlineOptions.domainId(), exerciseId, cmdlineOptions.operatorId()};
|
|
|
|
return QTest::qExec(&tests, qTestOptions(argc, argv, dashIndex));
|
|
}
|