Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,949 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Unittest
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "unit_test.h"
|
||||
|
||||
#include <TargetManagement/shootback_controller.h>
|
||||
|
||||
#include <QtTest/QTest>
|
||||
#include <QtTest/QSignalSpy>
|
||||
#include <QWeakPointer>
|
||||
|
||||
#include <nglapplication/nglapplication.h>
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
||||
|
||||
#include <QTimer>
|
||||
#include <QFlags>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
const int g_targetParticipantId_1 = 5;
|
||||
const int g_targetParticipantId_2 = 6;
|
||||
|
||||
const int g_movingParticipantId_1 = 30;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
class CmdLineParser : public LtsCommandLineParser::LtsCommandLineParser
|
||||
{
|
||||
public:
|
||||
CmdLineParser()
|
||||
: LtsCommandLineParser()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
NGLApplication app(argc, argv);
|
||||
app.createLogger("TgtUnitTestShootback", "log4cxxTgtUnitTestShootback.props");
|
||||
|
||||
CmdLineParser options;
|
||||
|
||||
// C O M M E N T :
|
||||
// To use the domainId and exerciseId via CmdLineParser AND
|
||||
// support also parameter for QTest::qExec do not return
|
||||
// if options.init() fails...
|
||||
if(!options.init())
|
||||
{
|
||||
fprintf(stdout, "\n \e[33m usage: try -v2 testTargetAreaAssignment -d 111 -e 222 \e[0m");
|
||||
fprintf(stdout, "\n \e[33m -functions \e[0m \n\n");
|
||||
}
|
||||
|
||||
int domainId = options.value(QStringLiteral("d")).toInt();
|
||||
int exerciseId = options.value(QStringLiteral("e")).toInt();
|
||||
if (exerciseId<0)
|
||||
exerciseId = 42;
|
||||
|
||||
QSharedPointer<TargetManagement::tgtTestShootbackTarget> tc =
|
||||
QSharedPointer<TargetManagement::tgtTestShootbackTarget>(new TargetManagement::tgtTestShootbackTarget());
|
||||
|
||||
tc->setPara(domainId, exerciseId);
|
||||
|
||||
if (options.domainIdProvided())
|
||||
argc -= 2;
|
||||
if (options.exerciseIdProvided())
|
||||
argc -= 2;
|
||||
// : C O M M E N T
|
||||
|
||||
int retCode = QTest::qExec(tc.data(), argc, argv);
|
||||
|
||||
return retCode;
|
||||
}
|
||||
|
||||
namespace TargetManagement
|
||||
{
|
||||
|
||||
tgtTestShootbackTarget::tgtTestShootbackTarget()
|
||||
: m_logger(getLogger("UnitTestShootback"))
|
||||
{
|
||||
// register some datatypes QSignalSpy
|
||||
qRegisterMetaType<DataModification>("DataModification");
|
||||
qRegisterMetaType<TargetManagement::ShootbackArea>("TargetManagement::ShootbackArea");
|
||||
qRegisterMetaType<TargetManagement::ShootbackTarget>("TargetManagement::ShootbackTarget");
|
||||
qRegisterMetaType<TargetManagement::TargetAreaAssignment>("TargetManagement::TargetAreaAssignment");
|
||||
}
|
||||
|
||||
tgtTestShootbackTarget::~tgtTestShootbackTarget()
|
||||
{
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::initTestCase()
|
||||
{
|
||||
NOTICE_LOG(m_logger) << LOGFUNCTION << " do testing with"
|
||||
<< " domainId=" << m_domainId
|
||||
<< " exerciseId=" << m_exerciseId;
|
||||
|
||||
m_ddsConnector.reset(new DDSConnector::DdsConnector(m_domainId, IDL::PartitionType::Exercise, m_exerciseId));
|
||||
if (!m_ddsConnector->init())
|
||||
return;
|
||||
|
||||
m_ddsConnector->initPublisherSubscriber();
|
||||
|
||||
m_ftcTgt = TargetManagement::Interface::Ftc::create(m_ddsConnector);
|
||||
bool bRet = m_ftcTgt->enableAll();
|
||||
|
||||
m_dtcTgt = TargetManagement::Interface::Dtc::create(m_ddsConnector);
|
||||
bRet &= m_dtcTgt->enableAll();
|
||||
|
||||
m_dtsPpm = ParticipantManagement::Interface::Dts::create(m_ddsConnector);
|
||||
bRet &= m_dtsPpm->enableAll();
|
||||
|
||||
m_dtsTab = TrainingAreaBase::Interface::Dts::create(m_ddsConnector);
|
||||
bRet &= m_dtsTab->enableAll();
|
||||
|
||||
// time to process changed-signals:
|
||||
QTest::qWait(2000);
|
||||
|
||||
removeTestObjects();
|
||||
|
||||
if (!bRet)
|
||||
FATAL_LOG(m_logger) << LOGFUNCTION << " init failed!!!";
|
||||
}
|
||||
|
||||
|
||||
|
||||
void tgtTestShootbackTarget::testShootbackArea()
|
||||
{
|
||||
ShootbackAreaModifyRequest request;
|
||||
|
||||
request.id(0); // force create
|
||||
request.name("UnitTest ShootbackArea");
|
||||
double lon = 0.15530364;
|
||||
double lat = 0.92601523;
|
||||
request.position().lon(lon);
|
||||
request.position().lat(lat);
|
||||
request.width(100);
|
||||
request.height(100);
|
||||
|
||||
// create
|
||||
{
|
||||
int32_t ret = m_ftcTgt->shootbackAreaModifyRequest(request, this);
|
||||
QVERIFY2((ret != 0), " shootbackAreaModifyRequest failed");
|
||||
checkShootbackAreaChangedWasEmitted(1, __LINE__);
|
||||
}
|
||||
|
||||
// time to process reply
|
||||
QTest::qWait(100);
|
||||
NOTICE_LOG(m_logger) << LOGFUNCTION << " got m_replyShootbackAreaId: " << m_replyShootbackAreaId;
|
||||
|
||||
|
||||
// modify
|
||||
request.id(m_replyShootbackAreaId);
|
||||
request.name("UnitTest ShootbackAreaModified");
|
||||
{
|
||||
int32_t ret = m_ftcTgt->shootbackAreaModifyRequest(request, this);
|
||||
QVERIFY2((ret != 0), " request failed");
|
||||
checkShootbackAreaChangedWasEmitted(1, __LINE__);
|
||||
|
||||
// verify mod
|
||||
{
|
||||
TargetManagement::ShootbackArea modData = m_dtcTgt->shootbackArea(m_replyShootbackAreaId);
|
||||
INFO_LOG(m_logger) << LOGFUNCTION << "modData=" << modData;
|
||||
QVERIFY2((modData.id() == m_replyShootbackAreaId), " shootbackArea failed");
|
||||
QVERIFY2((modData.name().compare(request.name()) == 0), " verify name failed");
|
||||
}
|
||||
}
|
||||
|
||||
// remove
|
||||
{
|
||||
ShootbackAreaRemoveRequest request;
|
||||
request.id(m_replyShootbackAreaId); // remove specific id
|
||||
|
||||
int32_t ret = m_ftcTgt->shootbackAreaRemoveRequest(request, this);
|
||||
QVERIFY2((ret != 0), " request failed");
|
||||
checkShootbackAreaChangedWasEmitted(1, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::testShootbackTarget()
|
||||
{
|
||||
ShootbackTargetModifyRequest request;
|
||||
|
||||
request.id(0); // force create
|
||||
// request.targetParticipantId(); // here would be the reference to the orbat
|
||||
request.name("UnitTest ShootbackTarget");
|
||||
|
||||
// create
|
||||
{
|
||||
int32_t ret = m_ftcTgt->shootbackTargetModifyRequest(request, this);
|
||||
QVERIFY2((ret != 0), " shootbackTargetModifyRequest failed");
|
||||
|
||||
QSignalSpy spy(m_dtcTgt.get(), &TargetManagement::Interface::Dtc::shootbackTargetChanged);
|
||||
if (spy.count() == 0)
|
||||
spy.wait(2000);
|
||||
QVERIFY2((spy.count() == 1), " spy failed");
|
||||
}
|
||||
|
||||
// time to process reply
|
||||
QTest::qWait(100);
|
||||
NOTICE_LOG(m_logger) << LOGFUNCTION << " got m_replyShootbackTargetId: " << m_replyShootbackTargetId;
|
||||
|
||||
|
||||
// modify
|
||||
request.id(m_replyShootbackTargetId);
|
||||
request.name("UnitTest ShootbackTargetModified");
|
||||
{
|
||||
int32_t ret = m_ftcTgt->shootbackTargetModifyRequest(request, this);
|
||||
QVERIFY2((ret != 0), " request failed");
|
||||
|
||||
QSignalSpy spy(m_dtcTgt.get(), &TargetManagement::Interface::Dtc::shootbackTargetChanged);
|
||||
if (spy.count() == 0)
|
||||
spy.wait(2000);
|
||||
INFO_LOG(m_logger) << LOGFUNCTION << "spy.count()=" << spy.count();
|
||||
QVERIFY2((spy.count() == 1), " spy failed");
|
||||
|
||||
// verify mod
|
||||
{
|
||||
TargetManagement::ShootbackTarget modData = m_dtcTgt->shootbackTarget(m_replyShootbackTargetId);
|
||||
INFO_LOG(m_logger) << LOGFUNCTION << "modData=" << modData;
|
||||
QVERIFY2((modData.id() == m_replyShootbackTargetId), " shootbackTarget failed");
|
||||
QVERIFY2((modData.name().compare(request.name()) == 0), " verify name failed");
|
||||
}
|
||||
}
|
||||
|
||||
// remove
|
||||
{
|
||||
ShootbackTargetRemoveRequest request;
|
||||
request.id(m_replyShootbackTargetId); // remove specific id
|
||||
|
||||
int32_t ret = m_ftcTgt->shootbackTargetRemoveRequest(request, this);
|
||||
QVERIFY2((ret != 0), " request failed");
|
||||
|
||||
QSignalSpy spy(m_dtcTgt.get(), &TargetManagement::Interface::Dtc::shootbackTargetChanged);
|
||||
if (spy.count() == 0)
|
||||
spy.wait(2000);
|
||||
QVERIFY2((spy.count() == 1), " spy failed");
|
||||
}
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::testTargetAreaAssignment()
|
||||
{
|
||||
TargetAreaAssignmentModifyRequest request;
|
||||
|
||||
// try to create
|
||||
request.id(0); // force create
|
||||
request.name("UnitTest TargetAreaAssignment");
|
||||
|
||||
// create
|
||||
{
|
||||
request.id(0); // force create
|
||||
request.name(QString(QStringLiteral("UnitTest-Assignment1")).toStdString());
|
||||
request.areaId(4711);
|
||||
request.targetParticipantId(4712);
|
||||
|
||||
int32_t ret = m_ftcTgt->targetAreaAssignmentModifyRequest(request, this);
|
||||
QVERIFY2((ret != 0), " request failed");
|
||||
|
||||
QSignalSpy spy(m_dtcTgt.get(), &TargetManagement::Interface::Dtc::targetAreaAssignmentChanged);
|
||||
if (spy.count() == 0)
|
||||
spy.wait(2000);
|
||||
INFO_LOG(m_logger) << LOGFUNCTION << "spy.count()=" << spy.count();
|
||||
QVERIFY2((spy.count() == 1), " spy failed");
|
||||
|
||||
// time to process reply
|
||||
QTest::qWait(100);
|
||||
|
||||
m_assignmentId1 = m_replyTargetAreaAssignmentId;
|
||||
}
|
||||
|
||||
|
||||
// modify
|
||||
request.id(m_assignmentId1);
|
||||
request.name("UnitTest-Assignment1_Modified");
|
||||
{
|
||||
int32_t ret = m_ftcTgt->targetAreaAssignmentModifyRequest(request, this);
|
||||
QVERIFY2((ret != 0), " request failed");
|
||||
|
||||
QSignalSpy spy(m_dtcTgt.get(), &TargetManagement::Interface::Dtc::targetAreaAssignmentChanged);
|
||||
if (spy.count() == 0)
|
||||
spy.wait(2000);
|
||||
INFO_LOG(m_logger) << LOGFUNCTION << "spy.count()=" << spy.count();
|
||||
QVERIFY2((spy.count() == 1), " spy failed");
|
||||
|
||||
// verify mod
|
||||
{
|
||||
TargetManagement::TargetAreaAssignment modData = m_dtcTgt->targetAreaAssignment(m_replyTargetAreaAssignmentId);
|
||||
INFO_LOG(m_logger) << LOGFUNCTION << "modData=" << modData;
|
||||
QVERIFY2((modData.id() == m_replyTargetAreaAssignmentId), " targetAreaAssignment failed");
|
||||
QVERIFY2((modData.name().compare(request.name()) == 0), " verify name failed");
|
||||
}
|
||||
}
|
||||
|
||||
// remove
|
||||
{
|
||||
TargetAreaAssignmentRemoveRequest request;
|
||||
request.id(m_replyTargetAreaAssignmentId); // remove specific id
|
||||
|
||||
int32_t ret = m_ftcTgt->targetAreaAssignmentRemoveRequest(request, this);
|
||||
QVERIFY2((ret != 0), " request failed");
|
||||
|
||||
QSignalSpy spy(m_dtcTgt.get(), &TargetManagement::Interface::Dtc::targetAreaAssignmentChanged);
|
||||
if (spy.count() == 0)
|
||||
spy.wait(2000);
|
||||
QVERIFY2((spy.count() == 1), " spy failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void tgtTestShootbackTarget::removeTestObjects()
|
||||
{
|
||||
// first, remove all TargetAreaAssignments:
|
||||
{
|
||||
QMap<qint32, TargetManagement::TargetAreaAssignment> allObj = m_dtcTgt->targetAreaAssignments();
|
||||
NOTICE_LOG(m_logger) << LOGFUNCTION << " remove... (" << allObj.size() << " TargetAreaAssignments)";
|
||||
for (auto item: qAsConst(allObj))
|
||||
if (item.name().substr(0, 8).compare("UnitTest") == 0)
|
||||
removeAssignment(item.id());
|
||||
QTest::qWait(250); // time to process reply
|
||||
allObj = m_dtcTgt->targetAreaAssignments();
|
||||
NOTICE_LOG(m_logger) << LOGFUNCTION << " remove targetAreaAssignments finished -> " << allObj.size() << " TargetAreaAssignments";
|
||||
}
|
||||
|
||||
// remove all Areas:
|
||||
{
|
||||
QMap<qint32, TargetManagement::ShootbackArea> allObj = m_dtcTgt->shootbackAreas();
|
||||
NOTICE_LOG(m_logger) << LOGFUNCTION << " remove... (" << allObj.size() << " Areas)";
|
||||
for (auto item: qAsConst(allObj))
|
||||
if (item.name().substr(0, 8).compare("UnitTest") == 0)
|
||||
removeArea(item.id());
|
||||
QTest::qWait(250); // time to process reply
|
||||
allObj = m_dtcTgt->shootbackAreas();
|
||||
NOTICE_LOG(m_logger) << LOGFUNCTION << " remove shootbackAreas finished -> " << allObj.size() << " Areas";
|
||||
}
|
||||
|
||||
// remove all Targets:
|
||||
{
|
||||
QMap<qint32, TargetManagement::ShootbackTarget> allObj = m_dtcTgt->shootbackTargets();
|
||||
NOTICE_LOG(m_logger) << LOGFUNCTION << " remove... (" << allObj.size() << " Targets)";
|
||||
for (auto item: qAsConst(allObj))
|
||||
if (item.name().substr(0, 8).compare("UnitTest") == 0)
|
||||
removeTarget(item.id());
|
||||
QTest::qWait(250); // time to process reply
|
||||
|
||||
allObj = m_dtcTgt->shootbackTargets();
|
||||
NOTICE_LOG(m_logger) << LOGFUNCTION << " remove shootbackTargets finished -> " << allObj.size() << " Targets";
|
||||
}
|
||||
QTest::qWait(1000); // time to process
|
||||
}
|
||||
|
||||
|
||||
void tgtTestShootbackTarget::createArea(int &areaIdInOut, const QString &name, double lon, double lat)
|
||||
{
|
||||
m_replyShootbackAreaId = -1;
|
||||
|
||||
ShootbackAreaModifyRequest request;
|
||||
|
||||
request.id(areaIdInOut);
|
||||
request.name(name.toStdString());
|
||||
request.position().lon(lon);
|
||||
request.position().lat(lat);
|
||||
request.width(100);
|
||||
request.height(100);
|
||||
|
||||
// create
|
||||
{
|
||||
int32_t ret = m_ftcTgt->shootbackAreaModifyRequest(request, this);
|
||||
|
||||
qCritical() << "shootbackAreaModifyRequest ret= " << ret;
|
||||
|
||||
QVERIFY2((ret != 0), " shootbackAreaModifyRequest failed");
|
||||
|
||||
QSignalSpy spy(m_dtcTgt.get(), &TargetManagement::Interface::Dtc::shootbackAreaChanged);
|
||||
if (spy.count() == 0)
|
||||
spy.wait(2000);
|
||||
QVERIFY2((spy.count() == 1), " spy failed");
|
||||
}
|
||||
|
||||
// time to process reply
|
||||
QTest::qWait(100);
|
||||
INFO_LOG(m_logger) << LOGFUNCTION << " got m_replyShootbackAreaId: " << m_replyShootbackAreaId;
|
||||
|
||||
areaIdInOut = m_replyShootbackAreaId;
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::modifyArea(int &areaId, const QString &name, double lon, double lat)
|
||||
{
|
||||
ShootbackAreaModifyRequest request;
|
||||
|
||||
request.id(areaId);
|
||||
request.name(name.toStdString());
|
||||
request.position().lon(lon);
|
||||
request.position().lat(lat);
|
||||
|
||||
// create/modify
|
||||
{
|
||||
int32_t ret = m_ftcTgt->shootbackAreaModifyRequest(request, this);
|
||||
QVERIFY2((ret != 0), " shootbackAreaModifyRequest failed");
|
||||
}
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::removeArea(int areaId, bool checkUsingSpy)
|
||||
{
|
||||
ShootbackAreaRemoveRequest request;
|
||||
request.id(areaId);
|
||||
|
||||
int32_t ret = m_ftcTgt->shootbackAreaRemoveRequest(request, this);
|
||||
QVERIFY2((ret != 0), " request failed");
|
||||
|
||||
if (checkUsingSpy)
|
||||
{
|
||||
QSignalSpy spy(m_dtcTgt.get(), &TargetManagement::Interface::Dtc::shootbackAreaChanged);
|
||||
if (spy.count() == 0)
|
||||
spy.wait(2000);
|
||||
QVERIFY2((spy.count() == 1), " spy failed");
|
||||
}
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::createTarget(int &targetIdOut, int targetParticipantId, const QString &name)
|
||||
{
|
||||
ShootbackTargetModifyRequest request;
|
||||
|
||||
request.id(targetIdOut); // force create !?
|
||||
request.targetParticipantId(targetParticipantId);
|
||||
request.name(name.toStdString());
|
||||
request.position(Core::GeoPosition(0.149276, 0.92622, 50.0)); // 0.149276, 0.92622 -> 32u MD 70000 80000 -> 31m
|
||||
|
||||
// create
|
||||
{
|
||||
int32_t ret = m_ftcTgt->shootbackTargetModifyRequest(request, this);
|
||||
QVERIFY2((ret != 0), " shootbackTargetModifyRequest failed");
|
||||
|
||||
QSignalSpy spy(m_dtcTgt.get(), &TargetManagement::Interface::Dtc::shootbackTargetChanged);
|
||||
if (spy.count() == 0)
|
||||
spy.wait(2000);
|
||||
QVERIFY2((spy.count() == 1), " spy failed");
|
||||
}
|
||||
|
||||
// time to process reply
|
||||
QTest::qWait(100);
|
||||
INFO_LOG(m_logger) << LOGFUNCTION << " got m_replyShootbackTargetId: " << m_replyShootbackTargetId;
|
||||
|
||||
targetIdOut = m_replyShootbackTargetId;
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::modifyTarget(int targetId, int targetParticipantId, const QString &name, double lon, double lat, double z)
|
||||
{
|
||||
ShootbackTargetModifyRequest request;
|
||||
|
||||
request.id(targetId);
|
||||
request.targetParticipantId(targetParticipantId);
|
||||
request.name(name.toStdString());
|
||||
request.position(Core::GeoPosition(lon, lat, z)); // 0.149276, 0.92622 -> 32u MD 70000 80000 -> 31m
|
||||
|
||||
// modify
|
||||
{
|
||||
int32_t ret = m_ftcTgt->shootbackTargetModifyRequest(request, this);
|
||||
QVERIFY2((ret != 0), " shootbackTargetModifyRequest failed");
|
||||
|
||||
QSignalSpy spy(m_dtcTgt.get(), &TargetManagement::Interface::Dtc::shootbackTargetChanged);
|
||||
if (spy.count() == 0)
|
||||
spy.wait(2000);
|
||||
QVERIFY2((spy.count() == 1), " spy failed");
|
||||
}
|
||||
|
||||
// time to process reply
|
||||
QTest::qWait(100);
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::removeTarget(int targetId, bool checkUsingSpy)
|
||||
{
|
||||
ShootbackTargetRemoveRequest request;
|
||||
request.id(targetId); // remove specific id
|
||||
|
||||
int32_t ret = m_ftcTgt->shootbackTargetRemoveRequest(request, this);
|
||||
QVERIFY2((ret != 0), " request failed");
|
||||
|
||||
if (checkUsingSpy)
|
||||
{
|
||||
QSignalSpy spy(m_dtcTgt.get(), &TargetManagement::Interface::Dtc::shootbackTargetChanged);
|
||||
if (spy.count() == 0)
|
||||
spy.wait(2000);
|
||||
QVERIFY2((spy.count() == 1), " spy failed");
|
||||
}
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::createAssignment(int areaId, int targetParticipantId, int &assignmentIdOut, const QString &name)
|
||||
{
|
||||
TargetAreaAssignmentModifyRequest request;
|
||||
|
||||
request.id(assignmentIdOut); // force create !?
|
||||
request.name(name.toStdString());
|
||||
request.areaId(areaId);
|
||||
request.targetParticipantId(targetParticipantId);
|
||||
|
||||
// create
|
||||
{
|
||||
int32_t ret = m_ftcTgt->targetAreaAssignmentModifyRequest(request, this);
|
||||
QVERIFY2((ret != 0), " targetAreaAssignmentModifyRequest failed");
|
||||
|
||||
QSignalSpy spy(m_dtcTgt.get(), &TargetManagement::Interface::Dtc::targetAreaAssignmentChanged);
|
||||
if (spy.count() == 0)
|
||||
spy.wait(2000);
|
||||
QVERIFY2((spy.count() == 1), " spy failed");
|
||||
}
|
||||
|
||||
// time to process reply
|
||||
QTest::qWait(100);
|
||||
INFO_LOG(m_logger) << LOGFUNCTION << " got m_replyTargetAreaAssignmentId: " << m_replyTargetAreaAssignmentId;
|
||||
|
||||
assignmentIdOut = m_replyTargetAreaAssignmentId;
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::modifyAssignment(int areaId, int targetParticipantId, int &assignmentId, const QString &name)
|
||||
{
|
||||
TargetAreaAssignmentModifyRequest request;
|
||||
|
||||
request.id(assignmentId);
|
||||
request.name(name.toStdString());
|
||||
request.areaId(areaId);
|
||||
request.targetParticipantId(targetParticipantId);
|
||||
|
||||
// modify
|
||||
{
|
||||
int32_t ret = m_ftcTgt->targetAreaAssignmentModifyRequest(request, this);
|
||||
QVERIFY2((ret != 0), " targetAreaAssignmentModifyRequest failed");
|
||||
}
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::removeAssignment(int id, bool checkUsingSpy)
|
||||
{
|
||||
TargetAreaAssignmentRemoveRequest request;
|
||||
request.id(id); // remove specific id
|
||||
|
||||
int32_t ret = m_ftcTgt->targetAreaAssignmentRemoveRequest(request, this);
|
||||
QVERIFY2((ret != 0), " request failed");
|
||||
|
||||
if (checkUsingSpy)
|
||||
{
|
||||
QSignalSpy spy(m_dtcTgt.get(), &TargetManagement::Interface::Dtc::targetAreaAssignmentChanged);
|
||||
if (spy.count() == 0)
|
||||
spy.wait(2000);
|
||||
QVERIFY2((spy.count() == 1), " spy failed");
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<int32_t> tgtTestShootbackTarget::visiParticpantsOfTarget(int targetId)
|
||||
{
|
||||
TargetManagement::ShootbackTarget sbTarget = m_dtcTgt->shootbackTarget(targetId);
|
||||
return sbTarget.visibleParticipants();
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::moveParticipant(int participantId, double lon, double lat)
|
||||
{
|
||||
if (!m_dtsPpm)
|
||||
return;
|
||||
|
||||
NOTICE_LOG(m_logger) << LOGFUNCTION << " move Participant: id = " << participantId;
|
||||
ParticipantManagement::ParticipantPosition posReq;
|
||||
posReq.participantId(participantId);
|
||||
posReq.sampleTime(currentSampleTime());
|
||||
posReq.pos(Core::GeoPosition(lon, lat, 50.12345));
|
||||
posReq.partyId(2); // 0 and 1 will be skipped
|
||||
if (!m_dtsPpm->publish(posReq))
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " Error publish posReq";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::checkShootbackAreaChangedWasEmitted(int number, int line)
|
||||
{
|
||||
QSignalSpy spy(m_dtcTgt.get(), &TargetManagement::Interface::Dtc::shootbackAreaChanged);
|
||||
if (spy.count() == 0)
|
||||
spy.wait(1000);
|
||||
QString msg = QString(QStringLiteral("Area-Spy failed: %1 of %2 (line=%3)")).arg(spy.count()).arg(number).arg(line);
|
||||
QVERIFY2((spy.count() == number), msg.toStdString().c_str());
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::checkShootbackTargetChangedWasEmitted(int number, int line)
|
||||
{
|
||||
QSignalSpy spy(m_dtcTgt.get(), &TargetManagement::Interface::Dtc::shootbackTargetChanged);
|
||||
if (spy.count() == 0)
|
||||
spy.wait(1000);
|
||||
QString msg = QString(QStringLiteral("Target-Spy failed: %1 of %2 (line=%3)")).arg(spy.count()).arg(number).arg(line);
|
||||
QVERIFY2((spy.count() == number), msg.toStdString().c_str());
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::checkAssignmentChangedWasEmitted(int number, int line)
|
||||
{
|
||||
QSignalSpy spy(m_dtcTgt.get(), &TargetManagement::Interface::Dtc::targetAreaAssignmentChanged);
|
||||
if (spy.count() == 0)
|
||||
spy.wait(1000);
|
||||
QString msg = QString(QStringLiteral("Assignment-Spy failed: %1 of %2 (line=%3)")).arg(spy.count()).arg(number).arg(line);
|
||||
QVERIFY2((spy.count() == number), msg.toStdString().c_str());
|
||||
}
|
||||
|
||||
|
||||
void tgtTestShootbackTarget::prepareDefaultSituation()
|
||||
{
|
||||
const int timeToProcess = 100;
|
||||
removeTestObjects();
|
||||
|
||||
// move outside:
|
||||
moveParticipant(g_movingParticipantId_1, 0.155, 0.922); // g_movingParticipantId_1 -> 30
|
||||
|
||||
// some areas
|
||||
m_areaId1 = 0;
|
||||
createArea(m_areaId1, QStringLiteral("UnitTest-Area1"), 0.155, 0.926);
|
||||
QVERIFY2((m_areaId1 > 0), " createArea failed");
|
||||
|
||||
m_areaId2 = 0;
|
||||
createArea(m_areaId2, QStringLiteral("UnitTest-Area2"), 0.155, 0.930);
|
||||
QVERIFY2((m_areaId2 > 0), " createArea failed");
|
||||
|
||||
QTest::qWait(timeToProcess); // time to process
|
||||
|
||||
// some targets
|
||||
m_targetDataId1 = 0;
|
||||
createTarget(m_targetDataId1, g_targetParticipantId_1, QStringLiteral("UnitTest-TargetDataId1_Part=5"));
|
||||
QVERIFY2((m_targetDataId1 > 0), " createTarget failed");
|
||||
|
||||
m_targetDataId2 = 0;
|
||||
createTarget(m_targetDataId2, g_targetParticipantId_2, QStringLiteral("UnitTest-TargetDataId2_Part=6"));
|
||||
QVERIFY2((m_targetDataId2 > 0), " createTarget failed");
|
||||
|
||||
QTest::qWait(timeToProcess); // time to process
|
||||
|
||||
// some assignments
|
||||
m_assignmentId1 = 0;
|
||||
createAssignment(m_areaId1, g_targetParticipantId_1, m_assignmentId1, QStringLiteral("UnitTest-Assignment1"));
|
||||
QVERIFY2((m_assignmentId1 > 0), " createAssignment failed");
|
||||
|
||||
// move Player, still outside
|
||||
QTest::qWait(timeToProcess); // time to process
|
||||
|
||||
moveParticipant(g_movingParticipantId_1, 0.155, 0.925);
|
||||
checkShootbackTargetChangedWasEmitted(0, __LINE__);
|
||||
|
||||
QTest::qWait(timeToProcess); // time to process
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId1).size() == 0), " visiParticpantsOfTarget failed");
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId2).size() == 0), " visiParticpantsOfTarget failed");
|
||||
|
||||
NOTICE_LOG(m_logger) << " -------------- DefaultSituation established --------------";
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::testPlayerMoves()
|
||||
{
|
||||
prepareDefaultSituation();
|
||||
|
||||
// no enter
|
||||
{
|
||||
moveParticipant(g_movingParticipantId_1, 0.155, 0.925);
|
||||
checkShootbackTargetChangedWasEmitted(0, __LINE__);
|
||||
|
||||
QTest::qWait(1000); // time to process
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId1).size() == 0), " visiParticpantsOfTarget failed");
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId2).size() == 0), " visiParticpantsOfTarget failed");
|
||||
}
|
||||
|
||||
// enter 1
|
||||
{
|
||||
moveParticipant(g_movingParticipantId_1, 0.155, 0.926001);
|
||||
checkShootbackTargetChangedWasEmitted(1, __LINE__);
|
||||
|
||||
QTest::qWait(1000); // time to process
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId1).size() == 1), " visiParticpantsOfTarget failed");
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId2).size() == 0), " visiParticpantsOfTarget failed");
|
||||
}
|
||||
|
||||
// leave 1
|
||||
{
|
||||
moveParticipant(g_movingParticipantId_1, 0.155, 0.927);
|
||||
checkShootbackTargetChangedWasEmitted(1, __LINE__);
|
||||
|
||||
QTest::qWait(1000); // time to process
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId1).size() == 0), " visiParticpantsOfTarget failed");
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId2).size() == 0), " visiParticpantsOfTarget failed");
|
||||
}
|
||||
|
||||
// enter 2
|
||||
{
|
||||
moveParticipant(g_movingParticipantId_1, 0.155, 0.93);
|
||||
checkShootbackTargetChangedWasEmitted(0, __LINE__);
|
||||
|
||||
QTest::qWait(1000); // time to process
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId1).size() == 0), " visiParticpantsOfTarget failed");
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId2).size() == 0), " visiParticpantsOfTarget failed"); // targetId2 has no assignment -> 0
|
||||
}
|
||||
|
||||
// leave 2
|
||||
{
|
||||
moveParticipant(g_movingParticipantId_1, 0.155, 0.94);
|
||||
checkShootbackTargetChangedWasEmitted(0, __LINE__);
|
||||
|
||||
QTest::qWait(1000); // time to process
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId1).size() == 0), " visiParticpantsOfTarget failed");
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId2).size() == 0), " visiParticpantsOfTarget failed");
|
||||
}
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::testPlayerMovesLos()
|
||||
{
|
||||
prepareDefaultSituation();
|
||||
|
||||
// enter 1
|
||||
{
|
||||
moveParticipant(g_movingParticipantId_1, 0.155, 0.926001);
|
||||
checkShootbackTargetChangedWasEmitted(1, __LINE__);
|
||||
|
||||
QTest::qWait(1000); // time to process
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId1).size() == 1), " visiParticpantsOfTarget failed");
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId2).size() == 0), " visiParticpantsOfTarget failed");
|
||||
}
|
||||
|
||||
QTest::qWait(1000); // time to process
|
||||
|
||||
|
||||
// move assigned target 1 slightly:
|
||||
{
|
||||
NOTICE_LOG(m_logger) << LOGFUNCTION << " move target1 ...";
|
||||
modifyTarget(m_targetDataId1, g_targetParticipantId_1, QStringLiteral("UnitTest-TargetDataId1_Moved"), 0.149, 0.926, 55.0);
|
||||
|
||||
QTest::qWait(250); // time to process
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId1).size() == 1), " visiParticpantsOfTarget failed");
|
||||
}
|
||||
|
||||
// move (z) assigned target 1 to interrupt line of sight:
|
||||
{
|
||||
NOTICE_LOG(m_logger) << LOGFUNCTION << " move target1 ...";
|
||||
modifyTarget(m_targetDataId1, g_targetParticipantId_1, QStringLiteral("UnitTest-TargetDataId1_Moved"), 0.152, 0.926, 2.0);
|
||||
|
||||
QTest::qWait(250); // time to process
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId1).size() == 0), " visiParticpantsOfTarget failed");
|
||||
}
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::testPlayerRemove()
|
||||
{
|
||||
prepareDefaultSituation();
|
||||
|
||||
// enter 1
|
||||
{
|
||||
moveParticipant(g_movingParticipantId_1, 0.155, 0.926001);
|
||||
checkShootbackTargetChangedWasEmitted(1, __LINE__);
|
||||
|
||||
QTest::qWait(1000); // time to process
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId1).size() == 1), " visiParticpantsOfTarget failed");
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId2).size() == 0), " visiParticpantsOfTarget failed");
|
||||
}
|
||||
|
||||
// remove ParticipantPOSTION
|
||||
m_dtsPpm->removeParticipantPositionByKey(g_movingParticipantId_1);
|
||||
{
|
||||
checkShootbackTargetChangedWasEmitted(1, __LINE__);
|
||||
|
||||
QTest::qWait(1000); // time to process
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId1).size() == 0), " visiParticpantsOfTarget failed");
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId2).size() == 0), " visiParticpantsOfTarget failed");
|
||||
}
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::testAreaChanges()
|
||||
{
|
||||
prepareDefaultSituation();
|
||||
|
||||
// move participant in the near of the target to ensure lineOfSight
|
||||
// target1: Pos 0.149276, 0.9262
|
||||
|
||||
moveParticipant(g_movingParticipantId_1, 0.149, 0.926);
|
||||
QTest::qWait(1000); // time to process
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId1).size() == 0), " visiParticpantsOfTarget failed");
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId2).size() == 0), " visiParticpantsOfTarget failed");
|
||||
|
||||
// move to area 1 (assigned to target1) over p1
|
||||
modifyArea(m_areaId1, QStringLiteral("UnitTest-Area1_Mod-AreaChanges"), 0.149, 0.926);
|
||||
checkShootbackTargetChangedWasEmitted(1, __LINE__);
|
||||
|
||||
QTest::qWait(1000); // time to process
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId1).size() == 1), " visiParticpantsOfTarget failed");
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId2).size() == 0), " visiParticpantsOfTarget failed");
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::testAreaRemove()
|
||||
{
|
||||
prepareDefaultSituation();
|
||||
|
||||
// enter 1
|
||||
{
|
||||
moveParticipant(g_movingParticipantId_1, 0.155, 0.926001);
|
||||
checkShootbackTargetChangedWasEmitted(1, __LINE__);
|
||||
|
||||
QTest::qWait(1000); // time to process
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId1).size() == 1), " visiParticpantsOfTarget failed");
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId2).size() == 0), " visiParticpantsOfTarget failed");
|
||||
}
|
||||
|
||||
removeArea(m_areaId1, false);
|
||||
checkShootbackTargetChangedWasEmitted(1, __LINE__);
|
||||
|
||||
QTest::qWait(1000); // time to process
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId1).size() == 0), " visiParticpantsOfTarget failed");
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId2).size() == 0), " visiParticpantsOfTarget failed");
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::testAssignmentRemove()
|
||||
{
|
||||
prepareDefaultSituation();
|
||||
|
||||
// enter 1
|
||||
{
|
||||
moveParticipant(g_movingParticipantId_1, 0.155, 0.926001);
|
||||
checkShootbackTargetChangedWasEmitted(1, __LINE__);
|
||||
|
||||
QTest::qWait(1000); // time to process
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId1).size() == 1), " visiParticpantsOfTarget failed");
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId2).size() == 0), " visiParticpantsOfTarget failed");
|
||||
}
|
||||
|
||||
removeAssignment(m_assignmentId1, false);
|
||||
checkShootbackTargetChangedWasEmitted(1, __LINE__);
|
||||
|
||||
QTest::qWait(1000); // time to process
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId1).size() == 0), " visiParticpantsOfTarget failed");
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId2).size() == 0), " visiParticpantsOfTarget failed");
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::testAssignmentChanges()
|
||||
{
|
||||
prepareDefaultSituation();
|
||||
|
||||
// enter 1
|
||||
{
|
||||
moveParticipant(g_movingParticipantId_1, 0.155, 0.926001);
|
||||
checkShootbackTargetChangedWasEmitted(1, __LINE__);
|
||||
|
||||
QTest::qWait(1000); // time to process
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId1).size() == 1), " visiParticpantsOfTarget failed");
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId2).size() == 0), " visiParticpantsOfTarget failed");
|
||||
}
|
||||
|
||||
// switch assignment: area1 -> area2
|
||||
modifyAssignment(m_areaId2, m_targetDataId1, m_assignmentId1, QStringLiteral("UnitTest-Assignment1_Mod"));
|
||||
|
||||
checkShootbackTargetChangedWasEmitted(1, __LINE__);
|
||||
|
||||
QTest::qWait(1000); // time to process
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId1).size() == 0), " visiParticpantsOfTarget failed");
|
||||
QVERIFY2((visiParticpantsOfTarget(m_targetDataId2).size() == 0), " visiParticpantsOfTarget failed");
|
||||
}
|
||||
|
||||
|
||||
void tgtTestShootbackTarget::cleanupTestCase()
|
||||
{
|
||||
// called one time at the end
|
||||
QTest::qWait(1000); // time to process
|
||||
removeTestObjects();
|
||||
QTest::qWait(1000); // time to process
|
||||
}
|
||||
|
||||
//
|
||||
// DdsSlots:
|
||||
//
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Area
|
||||
void tgtTestShootbackTarget::onShootbackAreaModifyReply(const Core::FunctionReplyObject &reply)
|
||||
{
|
||||
m_replyShootbackAreaId = reply.id();
|
||||
if (reply.error())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error onShootbackAreaRemoveReply - aborting: '" << reply.str() << "'";
|
||||
m_replyShootbackAreaId = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::onShootbackAreaRemoveReply(const Core::FunctionReplyObject &reply)
|
||||
{
|
||||
m_replyShootbackAreaId = reply.id();
|
||||
if (reply.error())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error onShootbackAreaRemoveReply - aborting: '" << reply.str() << "'"
|
||||
<< ", id="<< reply.id();
|
||||
m_replyShootbackAreaId = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Target
|
||||
void tgtTestShootbackTarget::onShootbackTargetModifyReply(const Core::FunctionReplyObject &reply)
|
||||
{
|
||||
m_replyShootbackTargetId = reply.id();
|
||||
if (reply.error())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error onShootbackAreaRemoveReply - aborting: '" << reply.str() << "'";
|
||||
m_replyShootbackTargetId = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::onShootbackTargetRemoveReply(const Core::FunctionReplyObject &reply)
|
||||
{
|
||||
m_replyShootbackTargetId = reply.id();
|
||||
if (reply.error())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error onShootbackAreaRemoveReply - aborting: '" << reply.str() << "'"
|
||||
<< ", id="<< reply.id();
|
||||
m_replyShootbackTargetId = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// TargetAreaAssignment
|
||||
void tgtTestShootbackTarget::onTargetAreaAssignmentModifyReply(const Core::FunctionReplyObject &reply)
|
||||
{
|
||||
m_replyTargetAreaAssignmentId = reply.id();
|
||||
if (reply.error())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error onShootbackAreaRemoveReply - aborting: '" << reply.str() << "'";
|
||||
m_replyTargetAreaAssignmentId = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void tgtTestShootbackTarget::onTargetAreaAssignmentRemoveReply(const Core::FunctionReplyObject &reply)
|
||||
{
|
||||
m_replyTargetAreaAssignmentId = reply.id();
|
||||
if (reply.error())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error onShootbackAreaRemoveReply - aborting: '" << reply.str() << "'"
|
||||
<< ", id="<< reply.id();
|
||||
m_replyTargetAreaAssignmentId = -1;
|
||||
}
|
||||
}
|
||||
|
||||
qint64 tgtTestShootbackTarget::currentSampleTime()
|
||||
{
|
||||
return QDateTime::currentDateTimeUtc().toMSecsSinceEpoch();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------
|
||||
Reference in new issue
Block a user