Converts accessor calls to plain member access across the residual service set.
469 lines
15 KiB
C++
Executable File
469 lines
15 KiB
C++
Executable File
/**
|
|
* Tlm Function Topic Module Test
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#include "eem_tests.h"
|
|
|
|
#include <nglapplication/nglcoreapplication.h>
|
|
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
|
#include <QtCore/QTimer>
|
|
#include <QtCore/QDateTime>
|
|
#include <QTest>
|
|
#include <QJsonObject>
|
|
#include <QJsonDocument>
|
|
#include <LtsUtilsCore/json_object.h>
|
|
|
|
/* Module tests for ExerciseEventManagement
|
|
* 1. Dynamic data
|
|
* 2. IED Events
|
|
* 3. Fire events
|
|
* 4. Bite messages
|
|
* 5. Hit Building
|
|
* 6. Sanitation events
|
|
*/
|
|
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------------
|
|
namespace ExerciseEventManagement
|
|
{
|
|
EemTests::EemTests(QObject *parent)
|
|
: QObject(parent)
|
|
, m_logger(getLogger("Test"))
|
|
{}
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------------
|
|
bool EemTests::init(int domainId, int exerciseId, int testId)
|
|
{
|
|
bool bRet = true;
|
|
DEBUG_LOG(m_logger) << "init begin";
|
|
|
|
m_testId = testId;
|
|
|
|
m_ddsConnector42 = std::make_shared<DDSConnector::DdsConnector>(domainId, IDL::PartitionType::Exercise, exerciseId);
|
|
m_ddsConnector42->init();
|
|
m_ddsConnector42->initPublisherSubscriber();
|
|
|
|
m_ppmDts = ParticipantManagement::Interface::Dts::create(m_ddsConnector42);
|
|
bRet &= m_ppmDts->enableDynamicParticipantData();
|
|
|
|
m_tabDts = TrainingAreaBase::Interface::Dts::create(m_ddsConnector42);
|
|
bRet &= m_tabDts->enableEquipmentGearEvent();
|
|
bRet &= m_tabDts->enableEquipmentGearChargeState();
|
|
bRet &= m_tabDts->enableEquipmentGearAssignment();
|
|
bRet &= m_tabDts->enableEquipmentBite();
|
|
|
|
m_gimDts = GuezIedManagement::Interface::Dts::create(m_ddsConnector42);
|
|
bRet &= m_gimDts->enableIed();
|
|
|
|
m_dtc = ExerciseEventManagement::Interface::Dtc::create(m_ddsConnector42);
|
|
bRet &= m_dtc->enableEvent();
|
|
|
|
m_bldDts = Buildings::Interface::Dts::create(m_ddsConnector42);
|
|
bRet &= m_bldDts->enableBuildingState();
|
|
|
|
DEBUG_LOG(m_logger) << "bRet: " << bRet;
|
|
|
|
return bRet;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------------
|
|
void EemTests::startTest()
|
|
{
|
|
INFO_LOG(m_logger) << "startTest m_testId = " << m_testId;
|
|
|
|
if (m_testId == 1) // publish dynamicParticipantData
|
|
{
|
|
const qint64 time = QDateTime::currentMSecsSinceEpoch();
|
|
tryCreateDynamicParticipantData(1, ProjectDataManagement::VulnerabilityState::VulnerabilityState_MediumDamage, time - 15000 * 60, 38);
|
|
QTest::qWait(500);
|
|
tryCreateDynamicParticipantData(2, ProjectDataManagement::VulnerabilityState::VulnerabilityState_MediumDamage, time - 13000 * 30, 38);
|
|
QTest::qWait(500);
|
|
tryCreateDynamicParticipantData(1, ProjectDataManagement::VulnerabilityState::VulnerabilityState_HeavyDamage, time - 10000 * 60, 38);
|
|
QTest::qWait(500);
|
|
tryCreateDynamicParticipantData(1, ProjectDataManagement::VulnerabilityState::VulnerabilityState_MobilityKill, time - 8000 * 30, 38);
|
|
QTest::qWait(500);
|
|
tryCreateDynamicParticipantData(2, ProjectDataManagement::VulnerabilityState::VulnerabilityState_MobilityKill, time - 6000 * 60, 38);
|
|
QTest::qWait(500);
|
|
tryCreateDynamicParticipantData(1, ProjectDataManagement::VulnerabilityState::VulnerabilityState_CatastrophicKill, time - 4000 * 30, 38);
|
|
QTest::qWait(500);
|
|
tryCreateDynamicParticipantData(2, ProjectDataManagement::VulnerabilityState::VulnerabilityState_CatastrophicKill, time - 2000, 38);
|
|
QTest::qWait(500);
|
|
}
|
|
|
|
if (m_testId == 2)
|
|
{
|
|
//ied
|
|
const qint64 time = QDateTime::currentMSecsSinceEpoch();
|
|
tryCreateIed(time - 1000 * 60);
|
|
QTest::qWait(500);
|
|
|
|
// dynamic participant data for ied
|
|
tryCreateDynamicParticipantData(1, ProjectDataManagement::VulnerabilityState::VulnerabilityState_HeavyDamage, time + 1000 * 60, 49, ProjectDataManagement::StateChangeOriginator::StateChangeOriginator_ImprovisedExplosiveDevice);
|
|
QTest::qWait(500);
|
|
tryCreateDynamicParticipantData(1, ProjectDataManagement::VulnerabilityState::VulnerabilityState_MobilityKill, time + 2000 * 60, 49, ProjectDataManagement::StateChangeOriginator::StateChangeOriginator_ImprovisedExplosiveDevice);
|
|
QTest::qWait(500);
|
|
tryCreateDynamicParticipantData(1, ProjectDataManagement::VulnerabilityState::VulnerabilityState_CatastrophicKill, time + 3000 * 60, 70, ProjectDataManagement::StateChangeOriginator::StateChangeOriginator_ImprovisedExplosiveDevice);
|
|
QTest::qWait(5000);
|
|
|
|
checkEvents(ProjectDataManagement::PdmEventType::EventType_HitEffectSimulation, 3);
|
|
}
|
|
|
|
if (m_testId == 3)
|
|
trySendFireEvent();
|
|
|
|
if (m_testId == 4)
|
|
trySendBiteMessage();
|
|
|
|
if (m_testId == 5)
|
|
trySendBuildingState();
|
|
|
|
if (m_testId == 6)
|
|
{
|
|
const qint64 time = QDateTime::currentMSecsSinceEpoch();
|
|
tryCreateDynamicParticipantData(2, ProjectDataManagement::VulnerabilityState::VulnerabilityState_HeavyDamage, time - 10000 * 60, 0, ProjectDataManagement::StateChangeOriginator::StateChangeOriginator_Sanitation);
|
|
QTest::qWait(500);
|
|
tryCreateDynamicParticipantData(2, ProjectDataManagement::VulnerabilityState::VulnerabilityState_MediumDamage, time - 8000 * 30, 0, ProjectDataManagement::StateChangeOriginator::StateChangeOriginator_Sanitation);
|
|
QTest::qWait(500);
|
|
tryCreateDynamicParticipantData(2, ProjectDataManagement::VulnerabilityState::VulnerabilityState_LightDamage, time - 5000 * 30, 0, ProjectDataManagement::StateChangeOriginator::StateChangeOriginator_Sanitation);
|
|
QTest::qWait(500);
|
|
|
|
checkEvents(ProjectDataManagement::PdmEventType::Sanitation, 3);
|
|
}
|
|
|
|
if (m_testId <= 0 || m_testId > 6)
|
|
{
|
|
ERROR_LOG(m_logger) << "Unknown test case: " << m_testId;
|
|
failExit();
|
|
}
|
|
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------------
|
|
void EemTests::tryCreateDynamicParticipantData(int participantId, ProjectDataManagement::VulnerabilityState vulnState, qint64 time, int chargeTypeId,
|
|
ProjectDataManagement::StateChangeOriginator originator)
|
|
{
|
|
ParticipantManagement::DynamicParticipantData dp;
|
|
const rti::core::int64 esTime = static_cast<rti::core::int64>(time);
|
|
ParticipantManagement::StateInformation si;
|
|
si.stateTime = esTime;
|
|
si.vulnerabilityState = vulnState;
|
|
if (chargeTypeId > 0)
|
|
si.originatorChargeTypeId = chargeTypeId;
|
|
si.originatorId = participantId + 1;
|
|
si.originatorType = originator;
|
|
si.vitality = 100;
|
|
if (originator == ProjectDataManagement::StateChangeOriginator::StateChangeOriginator_Sanitation)
|
|
{
|
|
si.sanitationResult = ParticipantManagement::SanitationResult::Sufficient;
|
|
si.sanitationProceduresTaken = 1;
|
|
}
|
|
|
|
dp.participantId = participantId;
|
|
//dp.isManipulated(true);
|
|
dp.stateHistory.push_back(si);
|
|
dp.sampleTime = esTime;
|
|
|
|
DEBUG_LOG(m_logger) << "Publishing DynamicParticipantData for participant " << participantId ;
|
|
if (!m_ppmDts->publish(dp))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error requesting create DynamicParticipantData";
|
|
failExit();
|
|
}
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------------
|
|
void EemTests::trySendFireEvent()
|
|
{
|
|
TrainingAreaBase::EquipmentGearAssignment gearAssigment;
|
|
|
|
gearAssigment.equipmentNumber = 1002;
|
|
gearAssigment.sampleTime = QDateTime::currentMSecsSinceEpoch();
|
|
std::vector<TrainingAreaBase::Gear> gears;
|
|
|
|
gears.resize(2);
|
|
gears[0].gearId = 132456;
|
|
gears[0].gearTypeId = 1003; // Sniper
|
|
gears[1].gearId = 45778;
|
|
gears[1].gearTypeId = 1006; // HMG
|
|
|
|
gearAssigment.gears = gears;
|
|
|
|
DEBUG_LOG(m_logger) << "Publish EquipmentGearAssigment";
|
|
if (!m_tabDts->publish(gearAssigment))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error while publishing EquipmentGearAssigment";
|
|
failExit();
|
|
}
|
|
|
|
TrainingAreaBase::EquipmentGearChargeState gearChargeState;
|
|
|
|
gearChargeState.equipmentNumber = 1002;
|
|
gearChargeState.sampleTime = QDateTime::currentMSecsSinceEpoch();
|
|
|
|
std::vector<TrainingAreaBase::GearCharge> vGearCharge;
|
|
vGearCharge.resize(1);
|
|
vGearCharge[0].gearId = 132456;
|
|
vGearCharge[0].gearTypeId = 1003;
|
|
vGearCharge[0].chargeTypeId = 44;
|
|
vGearCharge[0].remain = 250;
|
|
|
|
gearChargeState.charge = vGearCharge;
|
|
|
|
DEBUG_LOG(m_logger) << "Publish EquipmentGearChargeState";
|
|
if (!m_tabDts->publish(gearChargeState))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error while publishing EquipmentGearChargeState";
|
|
failExit();
|
|
}
|
|
|
|
TrainingAreaBase::EquipmentGearEvent gearEvent;
|
|
gearEvent.equipmentNumber = 1002;
|
|
gearEvent.sampleTime = QDateTime::currentMSecsSinceEpoch()+1000;
|
|
|
|
TrainingAreaBase::GearCharge gc;
|
|
gc.gearId = 132456;
|
|
gc.gearTypeId = 1003;
|
|
gc.chargeTypeId = 44;
|
|
gc.remain = 200;
|
|
gearEvent.chargeAmount = 200;
|
|
gearEvent.charge = gc;
|
|
|
|
DEBUG_LOG(m_logger) << "Publish EquipmentGearEvent";
|
|
if (!m_tabDts->publish(gearEvent))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error while publishing EquipmentGearEvent";
|
|
failExit();
|
|
}
|
|
|
|
gearEvent.equipmentNumber = 1003;
|
|
gc.gearId = 45678;
|
|
gc.gearTypeId = 1009;
|
|
gc.chargeTypeId = 9;
|
|
gc.remain = 350;
|
|
gearEvent.chargeAmount = 100;
|
|
gearEvent.charge = gc;
|
|
|
|
DEBUG_LOG(m_logger) << "Publish EquipmentGearEvent";
|
|
if (!m_tabDts->publish(gearEvent))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error while publishing EquipmentGearEvent";
|
|
failExit();
|
|
}
|
|
|
|
QTest::qWait(2000);
|
|
|
|
const QMap<qint64, ExerciseEventManagement::Event> events = m_dtc->events();
|
|
|
|
DEBUG_LOG(m_logger) << "events: " << events.size();
|
|
|
|
int noEvents = 0;
|
|
for(const ExerciseEventManagement::Event &e : events)
|
|
{
|
|
INFO_LOG(m_logger) << "eventId: " << e.id << ", eventType: " << e.eventTypeId;
|
|
if (e.eventTypeId == ProjectDataManagement::PdmEventType::WeaponAssignment ||
|
|
e.eventTypeId == ProjectDataManagement::PdmEventType::FireEvent)
|
|
noEvents ++;
|
|
}
|
|
|
|
if (noEvents != 5)
|
|
{
|
|
ERROR_LOG(m_logger) << "Error number of events (" << QString::number(noEvents) << ") not as expected (5)";
|
|
failExit();
|
|
}
|
|
|
|
QTimer::singleShot(500, qApp, &QCoreApplication::quit);
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------------
|
|
void EemTests::trySendBiteMessage()
|
|
{
|
|
TrainingAreaBase::EquipmentBite bite;
|
|
|
|
bite.batteryState = 2;
|
|
bite.equipmentNumber = 1002;
|
|
bite.biteState = 16;
|
|
bite.configError = true;
|
|
bite.configState = 8;
|
|
bite.sampleTime = QDateTime::currentMSecsSinceEpoch();
|
|
|
|
std::vector<TrainingAreaBase::EquipmentBiteError> beVec;
|
|
beVec.resize(2);
|
|
|
|
beVec[0].canDeviceNumber = 1000;
|
|
beVec[0].errorNumber = 23;
|
|
beVec[0].subdeviceNumber = 110;
|
|
beVec[0].uniqueId = 198765;
|
|
|
|
beVec[1].canDeviceNumber = 1001;
|
|
beVec[1].errorNumber = 24;
|
|
beVec[1].subdeviceNumber = 111;
|
|
beVec[1].uniqueId = 9876;
|
|
|
|
bite.biteErrors = beVec;
|
|
|
|
if (!m_tabDts->publish(bite))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error while publishing EquipmentBite";
|
|
failExit();
|
|
}
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------------
|
|
void EemTests::trySendBuildingState()
|
|
{
|
|
Buildings::BuildingState bState;
|
|
|
|
bState.id = 301;
|
|
bState.damagePercent = 80;
|
|
bState.damagePercentOld = 0;
|
|
bState.sampleTime = QDateTime::currentMSecsSinceEpoch();
|
|
bState.vulnerabilityState = ProjectDataManagement::VulnerabilityState::VulnerabilityState_CatastrophicKill;
|
|
bState.structureElementId = 26;
|
|
// bState.aesId(1);
|
|
// bState.assetId(10);
|
|
// bState.chargeTypeId(44);
|
|
// bState.originatorType(ProjectDataManagement::StateChangeOriginator::AreaEffectSimulation);
|
|
// bState.originatorParticipantId(6);
|
|
|
|
if (!m_bldDts->publish(bState))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error while publishing building state";
|
|
failExit();
|
|
}
|
|
|
|
QTest::qWait(2000); // wait until it is really published
|
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------------
|
|
void EemTests::tryCreateIed(qint64 time)
|
|
{
|
|
GuezIedManagement::Ied ied;
|
|
|
|
ied.id = 100;
|
|
ied.name = "Test IED";
|
|
ied.partyId = 4;
|
|
ied.equipmentNumber = 1003;
|
|
ied.type = GuezIedManagement::IedType::IedBigPyro;
|
|
ied.explosiveForce = 100;
|
|
ied.pairingState = GuezIedManagement::IedPairingState::NotPaired;
|
|
ied.tacticalState = GuezIedManagement::IedTacticalState::TriggeredByControlDevice;
|
|
ied.pyrotechnics = true;
|
|
ied.symbol = "AP6D|CMPL|10014000001103000000";
|
|
const rti::core::int64 esTime = static_cast<rti::core::int64>(time);
|
|
ied.sampleTime = esTime;
|
|
|
|
DEBUG_LOG(m_logger) << "Publishing Ied " ;
|
|
if (!m_gimDts->publish(ied))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error requesting publish Ied";
|
|
failExit();
|
|
}
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------------
|
|
void EemTests::checkEvents(const ProjectDataManagement::PdmEventType &et, int expected)
|
|
{
|
|
const QMap<qint64, ExerciseEventManagement::Event> events = m_dtc->events();
|
|
|
|
DEBUG_LOG(m_logger) << "All published events: " << events.size();
|
|
int noEvents = 0;
|
|
|
|
for (const ExerciseEventManagement::Event &e : events)
|
|
{
|
|
INFO_LOG(m_logger) << "eventId: " << e.id << ", eventType: " << e.eventTypeId;
|
|
if (e.eventTypeId == et)
|
|
{
|
|
QJsonObject prop = LtsUtils::JsonObject::fromJson(e.properties);
|
|
|
|
int ot = prop[QStringLiteral("OriginatorType")].toInt();
|
|
if (et == ProjectDataManagement::PdmEventType::EventType_HitEffectSimulation && ot == 20) //ImprovisedExplosiveDevice
|
|
noEvents ++;
|
|
if (et == ProjectDataManagement::PdmEventType::Sanitation && ot == 10) // Sanitation
|
|
noEvents ++;
|
|
}
|
|
}
|
|
|
|
DEBUG_LOG(m_logger) << "No events: " << noEvents;
|
|
|
|
if (noEvents != expected)
|
|
{
|
|
ERROR_LOG(m_logger) << "Error number of events (" << QString::number(noEvents) << ") not as expected (" << QString::number(expected) << ")";
|
|
failExit();
|
|
}
|
|
|
|
QTimer::singleShot(500, qApp, &QCoreApplication::quit);
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------------
|
|
void EemTests::failExit()
|
|
{
|
|
m_bTestsSuccessful = false;
|
|
QTimer::singleShot(50, qApp, QCoreApplication::quit);
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------------
|
|
void EemTests::ExitSuccess()
|
|
{
|
|
m_bTestsSuccessful = true;
|
|
QTimer::singleShot(50, qApp, QCoreApplication::quit);
|
|
}
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------
|
|
class CmdLineParser : public LtsCommandLineParser::LtsCommandLineParser
|
|
{
|
|
public:
|
|
CmdLineParser()
|
|
: LtsCommandLineParser()
|
|
{
|
|
addOption({ QStringList() << QLatin1String("t") << QLatin1String("testId")
|
|
, QLatin1String("TestId.")
|
|
, QLatin1String("Default: -1 (Unknown)")
|
|
, QLatin1String("0")
|
|
});
|
|
}
|
|
int testId() const { return isSet(QLatin1String("t")) ? value(QLatin1String("t")).toInt() : -1; }
|
|
};
|
|
|
|
// ------------------------------------------------------------------
|
|
int main(int argc, char **argv)
|
|
{
|
|
NGLCoreApplication app(argc, argv);
|
|
|
|
int iRet = -1;
|
|
CmdLineParser options;
|
|
if (!options.init())
|
|
return iRet;
|
|
|
|
app.createLogger("EEM", options.exerciseId());
|
|
|
|
std::unique_ptr<ExerciseEventManagement::EemTests> EemTests(new ExerciseEventManagement::EemTests);
|
|
|
|
if (!EemTests->init(options.domainId(), options.exerciseId(), options.testId()))
|
|
return iRet;
|
|
|
|
EemTests->startTest();
|
|
|
|
STARTUP_LOG(app.baseLogger());
|
|
|
|
app.exec();
|
|
|
|
iRet = EemTests->testsSuccessful() ? 0 : 1;
|
|
fprintf(stderr, "%d\n", iRet);
|
|
|
|
DEBUG_LOG(app.baseLogger()) << "** TEST result = " << iRet;
|
|
|
|
SHUTDOWN_LOG(app.baseLogger());
|
|
|
|
return iRet;
|
|
}
|
|
|