/** * Msg Function Topic Module Test * $Id$ * $HeadURL$ * $Author$ */ #include "ces_tests.h" #include #include #include #include #include #include /* ---------------------------------------------------------------------------------- * HOW TO RUN THE TESTS (example) * ---------------------------------------------------------------------------------- * 0. Preconditions: * * Setting [CES] calculateCentralAes=1 (/etc/lts-cc.conf) * * Start with an empty database (BUILD) * make test-db * Start services: (SV) * ./bin/svcCentralEffectSimulation -e 42 & * cesTests -t 1 -e 42 // AES-Hit On Buildings AtExplosionAreaSingleExplosions (handler_aes) * cesTests -t 2 -e 42 // AES-Hit On Buildings AesType::AtExplosionSingle (handler_aes) * cesTests -t 3 -e 42 // STTW (handler_participant_building) * cesTests -t 4 -e 42 // AesType::AtExplosionAreaSingleExplosions on participant (handler_participant_area) * cesTests -t 5 -e 42 // AesType::AtExplosionSingle on participant (handler_participant_area) * cesTests -t 6 -e 42 // AesType::BCContamination Participant run in B-Field * cesTests -t 7 -e 42 // AesType::BCContamination B-Field moves and overlapps the participant * cesTests -t 8 -e 42 // AesType::AtMineAreaSingleMines (handler_partitipant_area) Participant run on Mine * cesTests -t 9 -e 42 // AesType::AtNContamination Participant run in N-Field * cesTests -t 10 -e 42 // AesType::AtFunctionalArea Participant run in FunctionalArea * cesTests -t 11 -e 42 // AesType::AtFunctionalArea Participant delete FunctionalArea * cesTests -t 12 -e 42 // AesType::AtFunctionalArea Participant Position leave FunctionalArea * cesTests -t 13 -e 42 // AesType::AtBorderline Participant cross Local Borderline * cesTests -t 14 -e 42 // AesType::AtBorderline Participant enter DangerArea */ namespace CentralEffectSimulation { static void setPos(std::vector &cont, const QPointF &pos) { cont.emplace_back(Core::GeoPosition2D(pos.x(), pos.y())); } static void setPos(std::vector &cont, const QPointF &pos) { cont.emplace_back(Core::GeoPosition(pos.x(), pos.y(), 0.0)); } CesTests::CesTests(QObject *parent) : QObject(parent) , Buildings::Interface::Fts::SendCesHitOnBuildingRequestHandler(nullptr) , TrainingAreaBase::Interface::Fts::SendCesHitRequestHandler(nullptr) , m_bTestsSuccessful(true) , m_housePos(LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32UMD8000090000"))) , m_logger(getLogger("CesTests")) , m_testId(0) , m_buildingId(0) , m_roomId(0) , m_moutObjectId(301) , m_chargeTypeId(371) , m_participantIndex(0) , m_originatorParticipantId(30) , m_countHitOnBuildingReply(0) , m_aesItemId(5) , m_replyEnterFunctionalArea(0) { m_logger.setNoSpace(false); } bool CesTests::init(int domainId, int exerciseId, int testId, int roomId) { bool bRet = true; INFO_LOG(m_logger) << "init begin"; m_testId = testId; m_roomId = roomId; m_ddsConnector42 = std::make_shared(domainId, IDL::PartitionType::Exercise, exerciseId); m_ddsConnector42->init(); m_ddsConnector42->initPublisherSubscriber(); m_aesDts = AreaEffectSimulation::Interface::Dts::create(m_ddsConnector42); // bRet &= m_aesDts->enableAll(); bRet &= m_aesDts->enableTriggeredImpacts(); bRet &= m_aesDts->enableAesItemView(); bRet &= m_aesDts->enableExplosionArea(); bRet &= m_aesDts->enableExplosionSingle(); bRet &= m_aesDts->enableBCContamination(); bRet &= m_aesDts->enableFunctionalArea(); bRet &= m_aesDts->enableBorderline(); bRet &= m_aesDts->enableDusMineState(); bRet &= m_aesDts->enableMineArea(); DEBUG_LOG(m_logger) << "AES Dts create interface bRet:" << bRet ; m_ismDts = InfrastructureManagement::Interface::Dts::create(m_ddsConnector42); bRet &= m_ismDts->enableMainStructureElement(); bRet &= m_ismDts->enableMainFootprint(); m_pdmDts = ProjectDataManagement::Interface::Dts::create(m_ddsConnector42); bRet &= m_pdmDts->enableChargeType(); m_bldDts = Buildings::Interface::Dts::create(m_ddsConnector42); bRet &= m_bldDts->enableBuildingState(); m_bldFts = Buildings::Interface::Fts::create(m_ddsConnector42); m_bldFts->enableSendCesHitOnBuilding(); m_bldFts->setSendCesHitOnBuildingRequestHandler(this); m_ppmDts = ParticipantManagement::Interface::Dts::create(m_ddsConnector42); bRet &= m_ppmDts->enableParticipantPosition(); bRet &= m_ppmDts->enableParticipant(); bRet &= m_ppmDts->enableDynamicParticipantData(); bRet &= m_ppmDts->enableType(); m_tabFts = TrainingAreaBase::Interface::Fts::create(m_ddsConnector42); m_tabFts->enableSendCesHit(); m_tabFts->setSendCesHitRequestHandler(this); m_cesDtc = CentralEffectSimulation::Interface::Dtc::create(m_ddsConnector42); bRet &= m_cesDtc->enableParticipantEvent(); // this is not enabled in enableAll() bRet &= m_cesDtc->enableAll(); m_participants.resize(2); m_participants[0].participantId = 20; m_participants[0].equipmentNumber = 60; m_participants[0].relX = -1; m_participants[0].relY = -1; m_participants[1].participantId = 21; m_participants[1].equipmentNumber = 61; m_participants[1].relX = -10; m_participants[1].relY = -1; return bRet; } void CesTests::startTest() { INFO_LOG(m_logger) << "startTest m_testId:" << m_testId; if (m_testId <= 1) // AES-Hit On Buildings area explosions { m_countHitOnBuildingReply = 0; m_aesType = AreaEffectSimulation::AesType::AtExplosionArea; QTimer::singleShot(0, this, &CesTests::tryCreateMainStructureElement); QTimer::singleShot(0, this, &CesTests::tryCreateMainFootprint); QTimer::singleShot(0, this, &CesTests::tryCreateChargeType); QTimer::singleShot(300, this, &CesTests::tryCreateAesItemView); QTimer::singleShot(400, this, &CesTests::tryCreateAesItemViewSingleExplosions); QTimer::singleShot(500, this, &CesTests::tryCreateTriggeredExplosion); } else if (m_testId == 2) // AesType::AtExplosionSingle on building { m_countHitOnBuildingReply = 0; m_explosionSingle = m_housePos.geographic(5, 5); m_aesType = AreaEffectSimulation::AesType::AtExplosionSingle; QTimer::singleShot(0, this, &CesTests::tryCreateMainStructureElement); QTimer::singleShot(0, this, &CesTests::tryCreateMainFootprint); QTimer::singleShot(0, this, &CesTests::tryCreateChargeType); QTimer::singleShot(750, this, &CesTests::tryCreateExplosionSinglePrepared); QTimer::singleShot(800, this, &CesTests::tryCreateExplosionSingle); } else if (m_testId == 3) // STTW { m_participantIndex = 0; QTimer::singleShot(0, this, &CesTests::tryCreateParticipant); m_buildingId = m_moutObjectId; // Criterium inside Buildings: buildingId >0 QTimer::singleShot(0, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(500, this, &CesTests::tryCreateBuildingState); } else if (m_testId == 4) // AesType::AtExplosionAreaSingleExplosions on participant { m_participantIndex = 0; m_buildingId = 0; // Criterium outside Buildings: buildingId = 0 QTimer::singleShot(0, this, &CesTests::tryCreateParticipant); QTimer::singleShot(0, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(50, this, &CesTests::tryCreateParticipant); QTimer::singleShot(50, this, &CesTests::tryCreateParticipantPosition); // 1) AreaEffectSimulation::ChargeAdministation QTimer::singleShot(0, this, &CesTests::tryCreateChargeType); // 2) AreaEffectSimulation::ExplosionArea QTimer::singleShot(300, this, &CesTests::tryCreateExplosionArea); // 3) AreaEffectSimulation::AesItemView AtExplosionArea m_aesType = AreaEffectSimulation::AesType::AtExplosionArea; // is not used for AtExplosionAreaSingleExplosions on participant // 4) AreaEffectSimulation::AesItemView AtExplosionAreaSingleExplosions m_aesItemId = 5; QTimer::singleShot(350, this, &CesTests::tryCreateAesItemViewMA); // MineArea QTimer::singleShot(400, this, &CesTests::tryCreateAesItemViewSingleExplosions); // 5) AreaEffectSimulation::TriggeredImpacts QTimer::singleShot(600, this, &CesTests::tryCreateTriggeredExplosion); } else if (m_testId == 5) // AesType::AtExplosionSingle on participant { m_participantIndex = 0; m_buildingId = 0; // Criterium outside Buildings: buildingId = 0 m_explosionSingle = m_housePos.geographic(-2, -2); m_aesType = AreaEffectSimulation::AesType::AtExplosionAreaSingleExplosions; QTimer::singleShot(0, this, &CesTests::tryCreateParticipant); QTimer::singleShot(50, this, &CesTests::tryCreateDynamicParticipantData); QTimer::singleShot(100, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(150, this, &CesTests::tryCreateParticipant); QTimer::singleShot(200, this, &CesTests::tryCreateDynamicParticipantData); QTimer::singleShot(250, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(0, this, &CesTests::tryCreateChargeType); QTimer::singleShot(750, this, &CesTests::tryCreateExplosionSinglePrepared); QTimer::singleShot(800, this, &CesTests::tryCreateExplosionSingle); } else if (m_testId == 6) // AesType::BCContamination Participant run in B-Field { m_participants.resize(3); m_participants[0].participantId = 20; m_participants[0].equipmentNumber = 60; m_participants[0].relX = -1; m_participants[0].relY = -1; m_participants[1].participantId = 20; m_participants[1].equipmentNumber = 60; m_participants[1].relX = -7; m_participants[1].relY = -1; m_participants[2].participantId = 20; m_participants[2].equipmentNumber = 60; m_participants[2].relX = 5; m_participants[2].relY = 20; m_participantIndex = 0; m_buildingId = 0; // Criterium outside Buildings: buildingId = 0 m_roomId = 0; m_aesType = AreaEffectSimulation::AesType::AtBCContamination; m_chargeTypeId = 341; QTimer::singleShot(0, this, [this]() { tryCreateAesItemViewBC(); }); QTimer::singleShot(50, this, &CesTests::tryCreateDynamicParticipantData); QTimer::singleShot(100, this, &CesTests::tryCreateParticipant); QTimer::singleShot(200, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(300, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(400, this, &CesTests::tryCreateParticipantPosition); } else if (m_testId == 7) // AesType::BCContamination B-Field moves and overlapps the participant { m_participants.resize(1); m_participants[0].participantId = 20; m_participants[0].equipmentNumber = 60; m_participants[0].relX = -7; m_participants[0].relY = -1; m_participantIndex = 0; m_buildingId = 0; // Criterium outside Buildings: buildingId = 0 m_aesType = AreaEffectSimulation::AesType::AtBCContamination; m_chargeTypeId = 341; QTimer::singleShot(00, this, &CesTests::tryCreateDynamicParticipantData); QTimer::singleShot(100, this, &CesTests::tryCreateParticipant); QTimer::singleShot(200, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(300, this, [this]() { tryCreateAesItemViewBC(); }); QTimer::singleShot(400, this, &CesTests::tryCreateAesItemView); } else if (m_testId == 8) // AesType::AtMineAreaSingleMines (handler_partitipant_area) Participant run on Mine { m_participants.resize(3); m_participants[0].participantId = 20; m_participants[0].equipmentNumber = 60; m_participants[0].relX = -1; m_participants[0].relY = -1; m_participants[1].participantId = 20; m_participants[1].equipmentNumber = 60; m_participants[1].relX = -10; m_participants[1].relY = -10; m_participants[2].participantId = 20; m_participants[2].equipmentNumber = 60; m_participants[2].relX = 5; m_participants[2].relY = 20; m_participantIndex = 0; m_buildingId = 0; // Criterium outside Buildings: buildingId = 0 m_roomId = 0; m_aesType = AreaEffectSimulation::AesType::AtMineAreaSingleMines; m_chargeTypeId = 40; QTimer::singleShot(0, this, &CesTests::tryCreateChargeType); QTimer::singleShot(0, this, &CesTests::tryCreateAesItemViewSM); // SingleMines QTimer::singleShot(50, this, &CesTests::tryCreateAesItemViewMA); // MineArea QTimer::singleShot(100, this, &CesTests::tryCreateDynamicParticipantData); QTimer::singleShot(150, this, &CesTests::tryCreateParticipant); QTimer::singleShot(200, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(300, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(400, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(1000, this, &CesTests::checkParticipantEvent); } else if (m_testId == 9) // AesType::AtNContamination Participant run in N-Field { m_participants.resize(3); m_participants[0].participantId = 20; m_participants[0].equipmentNumber = 60; m_participants[0].relX = -1; m_participants[0].relY = -1; m_participants[1].participantId = 20; m_participants[1].equipmentNumber = 60; m_participants[1].relX = -7; m_participants[1].relY = -1; m_participants[2].participantId = 20; m_participants[2].equipmentNumber = 60; m_participants[2].relX = 5; m_participants[2].relY = 20; m_participantIndex = 0; m_buildingId = 0; // Criterium outside Buildings: buildingId = 0 m_roomId = 0; m_aesType = AreaEffectSimulation::AesType::AtNContamination; m_chargeTypeId = 341; QTimer::singleShot(0, this, [this]() { tryCreateAesItemViewBC(); }); QTimer::singleShot(50, this, &CesTests::tryCreateDynamicParticipantData); QTimer::singleShot(100, this, &CesTests::tryCreateParticipant); QTimer::singleShot(200, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(300, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(400, this, &CesTests::tryCreateParticipantPosition); } else if (m_testId == 10) // AesType::AtFunctionalArea Participant run in FunctionalArea { // expected result: LTS_ParticipantEvent enterFunctionalArea m_participants.resize(1); m_participants[0].participantId = 20; m_participants[0].equipmentNumber = 60; m_participants[0].relX = 5; m_participants[0].relY = 20; m_participantIndex = 0; m_buildingId = 0; // Criterium outside Buildings: buildingId = 0 m_roomId = 0; m_aesType = AreaEffectSimulation::AesType::AtFunctionalArea; m_chargeTypeId = 411; QTimer::singleShot(0, this, [this]() { tryCreateAesItemViewBC(); }); QTimer::singleShot(100, this, &CesTests::tryCreateDynamicParticipantData); QTimer::singleShot(200, this, &CesTests::tryCreateParticipant); QTimer::singleShot(300, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(400, this, &CesTests::checkParticipantEvent); } else if (m_testId == 11) // AesType::AtFunctionalArea delete FunctionalArea while Participant is inside { m_participants.resize(3); m_participants[0].participantId = 20; m_participants[0].equipmentNumber = 60; m_participants[0].relX = -1; m_participants[0].relY = -1; m_participants[1].participantId = 20; m_participants[1].equipmentNumber = 60; m_participants[1].relX = -7; m_participants[1].relY = -1; m_participants[2].participantId = 20; m_participants[2].equipmentNumber = 60; m_participants[2].relX = 5; m_participants[2].relY = 20; m_participantIndex = 0; m_buildingId = 0; // Criterium outside Buildings: buildingId = 0 m_roomId = 0; m_aesType = AreaEffectSimulation::AesType::AtFunctionalArea; m_chargeTypeId = 411; QTimer::singleShot(0, this, [this]() { tryCreateAesItemViewBC(); }); QTimer::singleShot(100, this, &CesTests::tryCreateDynamicParticipantData); QTimer::singleShot(200, this, &CesTests::tryCreateParticipant); QTimer::singleShot(300, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(400, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(500, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(600, this, [this]() { tryCreateAesItemViewBC(AreaEffectSimulation::AesEffectState::EsExpired); }); QTimer::singleShot(700, this, &CesTests::checkParticipantEvent); } else if (m_testId == 12) // AesType::AtFunctionalArea Participant leave FunctionalArea { m_participants.resize(2); // inside Functional Area m_participants[0].participantId = 20; m_participants[0].equipmentNumber = 60; m_participants[0].relX = 5; m_participants[0].relY = 20; // Outside Functional Area m_participants[1].participantId = 20; m_participants[1].equipmentNumber = 60; m_participants[1].relX = -100; m_participants[1].relY = -100; m_participantIndex = 0; // Only last 2 Positions m_buildingId = 0; // Criterium outside Buildings: buildingId = 0 m_roomId = 0; m_aesType = AreaEffectSimulation::AesType::AtFunctionalArea; m_chargeTypeId = 411; QTimer::singleShot(0, this, [this]() { tryCreateAesItemViewBC(); }); QTimer::singleShot(100, this, &CesTests::tryCreateDynamicParticipantData); QTimer::singleShot(200, this, &CesTests::tryCreateParticipant); // First create in Functional Area QTimer::singleShot(300, this, &CesTests::tryCreateParticipantPosition); // Step out of Functional Area QTimer::singleShot(400, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(500, this, &CesTests::checkParticipantEvent); } else if (m_testId == 13) // AesType::AtFunctionalArea Participant cross Borderline { m_participants.resize(2); m_participants[0].participantId = 20; m_participants[0].equipmentNumber = 60; m_participants[0].relX = 4; m_participants[0].relY = 3; m_participants[1].participantId = 20; m_participants[1].equipmentNumber = 60; m_participants[1].relX = 4; m_participants[1].relY = 5; QTimer::singleShot(0, this, &CesTests::tryCreateParticipant); QTimer::singleShot(100, this, &CesTests::tryCreateBorderline); QTimer::singleShot(200, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(600, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(1000, this, &CesTests::checkParticipantEvent); } else if (m_testId == 14) // AesType::AtDangerArea Participant run in DangerArea { // expected result: LTS_ParticipantEvent enterDangerArea m_participants.resize(3); m_participants[0].participantId = 20; m_participants[0].equipmentNumber = 60; m_participants[0].relX = -1; m_participants[0].relY = -1; m_participants[1].participantId = 20; m_participants[1].equipmentNumber = 60; m_participants[1].relX = -7; m_participants[1].relY = -1; m_participants[2].participantId = 20; m_participants[2].equipmentNumber = 60; m_participants[2].relX = 5; m_participants[2].relY = 20; m_participantIndex = 0; m_buildingId = 0; // Criterium outside Buildings: buildingId = 0 m_roomId = 0; m_aesType = AreaEffectSimulation::AesType::AtDangerArea; m_chargeTypeId = 411; QTimer::singleShot(0, this, &CesTests::tryCreateAesItemView); //QTimer::singleShot(100, this, &CesTests::tryCreateDynamicParticipantData); QTimer::singleShot(200, this, &CesTests::tryCreateParticipant); QTimer::singleShot(300, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(400, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(500, this, &CesTests::tryCreateParticipantPosition); QTimer::singleShot(500, this, &CesTests::checkParticipantEvent); } else { failExit(QStringLiteral("Unknown test id %1").arg(m_testId)); } QTimer::singleShot(10000, this, &CesTests::testTimeout); } void CesTests::tryCreateTriggeredExplosion() { AreaEffectSimulation::TriggeredImpacts ti; // publish new triggered explosions data here ti.id = m_aesItemId; ti.aesItemId = m_aesItemId; ti.aesTypeId = AreaEffectSimulation::AesType::AtExplosionAreaSingleExplosions; ti.sampleTime = QDateTime::currentMSecsSinceEpoch(); ti.impactCount = 3; ti.bitfield.resize(1); ti.bitfield[0] = 0; // 0 = Mine active DEBUG_LOG(m_logger) << "Publishing TriggeredExplosions: " << ti; if (!m_aesDts->publish(ti)) failExit("Error publishing TriggeredExplosions"); } void CesTests::tryCreateExplosionArea() { AreaEffectSimulation::ExplosionArea ea; ea.id = m_aesItemId; ea.participantId = m_originatorParticipantId; // In ddsview ea.effectStateId = AreaEffectSimulation::AesEffectState::EsPrepared; DEBUG_LOG(m_logger) << "Publishing ExplosionArea: " << ea; if (!m_aesDts->publish(ea)) failExit("Error publishing ExplosionArea"); } void CesTests::tryCreateExplosionSinglePrepared() { m_aiv = AreaEffectSimulation::AesItemView(); m_aiv.aesItemId = m_aesItemId; m_aiv.id = m_aesItemId; m_aiv.effectStateId = AreaEffectSimulation::AesEffectState::EsPrepared; m_aiv.aesTypeId = m_aesType; m_aiv.partyId = 5; m_aiv.boundingBoxBottomLeft = Core::GeoPosition2D(m_explosionSingle.x(), m_explosionSingle.y()); m_aiv.boundingBoxTopRight = Core::GeoPosition2D(m_explosionSingle.x(), m_explosionSingle.y()); m_aiv.sampleTime = QDateTime::currentMSecsSinceEpoch(); m_aiv.chargeStruct.chargeTypeId = m_chargeTypeId; setPos(m_aiv.form, m_explosionSingle); if (!m_aesDts->publish(m_aiv)) failExit("Error publishing AesItemView"); m_es = AreaEffectSimulation::ExplosionSingle(); m_es.id = m_aesItemId; m_es.participantId = m_originatorParticipantId; // In ddsview m_es.effectStateId = AreaEffectSimulation::AesEffectState::EsPrepared; m_es.impactPosition = Core::GeoPosition2D(m_explosionSingle.x(), m_explosionSingle.y()); m_es.sampleTime = QDateTime::currentMSecsSinceEpoch(); m_es.chargeStruct.chargeTypeId = m_chargeTypeId; DEBUG_LOG(m_logger) << "Publishing ExplosionSingle: " << m_es; if (!m_aesDts->publish(m_es)) failExit("Error publishing ExplosionSingle"); } void CesTests::tryCreateExplosionSingle() { // tryCreateExplosionSinglePrepared() must be called before! m_aiv.effectStateId = AreaEffectSimulation::AesEffectState::EsActivated; m_aiv.sampleTime = QDateTime::currentMSecsSinceEpoch(); if (!m_aesDts->publish(m_aiv)) failExit("Error publishing AesItemView"); m_es.effectStateId = AreaEffectSimulation::AesEffectState::EsActivated; m_es.sampleTime = QDateTime::currentMSecsSinceEpoch(); DEBUG_LOG(m_logger) << "Publishing ExplosionSingle: " << m_es; if (!m_aesDts->publish(m_es)) failExit("Error publishing ExplosionSingle"); } void CesTests::tryCreateAesItemView() { INFO_LOG(m_logger) << "trying to send AesItemView AtExplosionArea"; m_aiv = AreaEffectSimulation::AesItemView(); m_aiv.aesItemId = m_aesItemId; m_aiv.id = m_aesItemId; m_aiv.effectStateId = AreaEffectSimulation::AesEffectState::EsActivated; m_aiv.aesTypeId = m_aesType; m_aiv.partyId = 5; QPointF bl = m_housePos.geographic(-10, -10); QPointF tr = m_housePos.geographic(30, 30); m_aiv.boundingBoxBottomLeft = Core::GeoPosition2D(bl.x(), bl.y()); m_aiv.boundingBoxTopRight = Core::GeoPosition2D(tr.x(), tr.y()); m_aiv.sampleTime = QDateTime::currentMSecsSinceEpoch(); m_aiv.chargeStruct.chargeTypeId = m_chargeTypeId; setPos(m_aiv.form, m_housePos.geographic(-10, -10)); setPos(m_aiv.form, m_housePos.geographic(-10, 30)); setPos(m_aiv.form, m_housePos.geographic(30, 30)); setPos(m_aiv.form, m_housePos.geographic(30, -10)); DEBUG_LOG(m_logger) << "Publishing AesItemView: " << m_aiv; if (!m_aesDts->publish(m_aiv)) failExit("Error publishing AesItemView"); } void CesTests::tryCreateChargeType() { ProjectDataManagement::ChargeType ct; ct.id = m_chargeTypeId; ct.properties = "{\"impactRadius\":5}"; DEBUG_LOG(m_logger) << "Publishing ChargeType: " << ct; if (!m_pdmDts->publish(ct)) failExit("Error publishing ChargeType"); ct.id = 40; // old charge type 10040 -> 40, hard-codded?! ct.properties = "{\"impactRadius\":6}"; DEBUG_LOG(m_logger) << "Publishing ChargeType: " << ct; if (!m_pdmDts->publish(ct)) failExit("Error publishing ChargeType"); } void CesTests::tryCreateAesItemViewSingleExplosions() { m_aiv = AreaEffectSimulation::AesItemView(); m_aiv.effectStateId = AreaEffectSimulation::AesEffectState::EsActivated; m_aiv.aesItemId = m_aesItemId; m_aiv.id = m_aesItemId; m_aiv.aesTypeId = AreaEffectSimulation::AesType::AtExplosionAreaSingleExplosions; m_aiv.partyId = 5; QPointF bl = m_housePos.geographic(-10, -10); QPointF tr = m_housePos.geographic(30, 30); m_aiv.boundingBoxBottomLeft = Core::GeoPosition2D(bl.x(), bl.y()); m_aiv.boundingBoxTopRight = Core::GeoPosition2D(tr.x(), tr.y()); m_aiv.chargeStruct.chargeTypeId = m_chargeTypeId; m_aiv.sampleTime = QDateTime::currentMSecsSinceEpoch(); setPos(m_aiv.form, m_housePos.geographic(-10, -10)); setPos(m_aiv.form, m_housePos.geographic(0, 0)); setPos(m_aiv.form, m_housePos.geographic(5, 5)); setPos(m_aiv.form, m_housePos.geographic(-10, 10)); setPos(m_aiv.form, m_housePos.geographic(-10, 20)); setPos(m_aiv.form, m_housePos.geographic(-10, 30)); DEBUG_LOG(m_logger) << "Publishing AesItemView: " << m_aiv; if (!m_aesDts->publish(m_aiv)) failExit("Error publishing AesItemView"); } void CesTests::tryCreateAesItemViewBC(AreaEffectSimulation::AesEffectState desiredState) { m_aiv = AreaEffectSimulation::AesItemView(); m_aiv.aesItemId = m_aesItemId; m_aiv.id = m_aesItemId; m_aiv.aesTypeId = m_aesType; m_aiv.effectStateId = desiredState; QPointF bl = m_housePos.geographic(-10, -10); QPointF tr = m_housePos.geographic(30, 30); m_aiv.boundingBoxBottomLeft = Core::GeoPosition2D(bl.x(), bl.y()); m_aiv.boundingBoxTopRight = Core::GeoPosition2D(tr.x(), tr.y()); m_aiv.chargeStruct.chargeTypeId = m_chargeTypeId; m_aiv.sampleTime = QDateTime::currentMSecsSinceEpoch(); setPos(m_aiv.form, m_housePos.geographic(3, 3)); setPos(m_aiv.form, m_housePos.geographic(3, 35)); setPos(m_aiv.form, m_housePos.geographic(35, 35)); setPos(m_aiv.form, m_housePos.geographic(35, 3)); DEBUG_LOG(m_logger) << "Publishing AesItemView: " << m_aiv; if (!m_aesDts->publish(m_aiv)) failExit("Error publishing AesItemView"); } void CesTests::tryCreateAesItemViewSM() { m_aiv = AreaEffectSimulation::AesItemView(); m_aiv.aesItemId = m_aesItemId; m_aiv.id = m_aesItemId; m_aiv.aesTypeId = AreaEffectSimulation::AesType::AtMineArea; m_aiv.effectStateId = AreaEffectSimulation::AesEffectState::EsActivated; QPointF bl = m_housePos.geographic(-10, -10); QPointF tr = m_housePos.geographic(30, 30); m_aiv.boundingBoxBottomLeft = Core::GeoPosition2D(bl.x(), bl.y()); m_aiv.boundingBoxTopRight = Core::GeoPosition2D(tr.x(), tr.y()); m_aiv.chargeStruct.chargeTypeId = m_chargeTypeId; m_aiv.sampleTime = QDateTime::currentMSecsSinceEpoch(); // Position of each mine setPos(m_aiv.form, m_housePos.geographic(3, 3)); setPos(m_aiv.form, m_housePos.geographic(3, 35)); setPos(m_aiv.form, m_housePos.geographic(35, 35)); setPos(m_aiv.form, m_housePos.geographic(35, 3)); DEBUG_LOG(m_logger) << "Publishing AesItemView: " << m_aiv; if (!m_aesDts->publish(m_aiv)) failExit("Error publishing AesItemView"); } void CesTests::tryCreateAesItemViewMA() { INFO_LOG(m_logger) << "trying to send AesItemView AtMineArea"; m_aiv = AreaEffectSimulation::AesItemView(); m_aiv.aesItemId = m_aesItemId; m_aiv.id = m_aesItemId; m_aiv.aesTypeId = m_aesType; m_aiv.effectStateId = AreaEffectSimulation::AesEffectState::EsActivated; QPointF bl = m_housePos.geographic(-10, -10); QPointF tr = m_housePos.geographic(30, 30); m_aiv.boundingBoxBottomLeft = Core::GeoPosition2D(bl.x(), bl.y()); m_aiv.boundingBoxTopRight = Core::GeoPosition2D(tr.x(), tr.y()); m_aiv.chargeStruct.chargeTypeId = m_chargeTypeId; m_aiv.sampleTime = QDateTime::currentMSecsSinceEpoch(); // Form of mine Area setPos(m_aiv.form, m_housePos.geographic(1, 1)); setPos(m_aiv.form, m_housePos.geographic(1, 37)); setPos(m_aiv.form, m_housePos.geographic(37, 37)); setPos(m_aiv.form, m_housePos.geographic(37, 1)); DEBUG_LOG(m_logger) << "Publishing AesItemView: " << m_aiv; if (!m_aesDts->publish(m_aiv)) failExit("Error publishing AesItemView"); } // ///////////////////////////////////////////////////// /// \brief CesTests::tryCreateBorderline /// void CesTests::tryCreateBorderline() { AreaEffectSimulation::Borderline bl; bl.id = m_aesItemId; bl.name = "Borderline"; bl.operatorId = 20; bl.partyId = 1; bl.effectStateId = AreaEffectSimulation::AesEffectState::EsCreated; setPos(bl.segments, m_housePos.geographic(3, 3)); setPos(bl.segments, m_housePos.geographic(4, 4)); setPos(bl.segments, m_housePos.geographic(5, 3)); bl.isDeleted = false; DEBUG_LOG(m_logger) << "Publishing BorderLine: " << bl; if (!m_aesDts->publish(bl)) failExit("Error publishing Borderline"); } void CesTests::tryCreateMainStructureElement() { m_mse.id = 555; m_mse.name = "Building 56"; m_mse.isDeleted = false; m_mse.isUsed = false; m_mse.description = "\"street\":\"Brueggeweg\":\"56\""; m_mse.structureElementId = 1; m_mse.geoPosition.lat = m_housePos.geographic().y(); m_mse.geoPosition.lon = m_housePos.geographic().x(); m_mse.geoPosition.z = 0; m_mse.angle = 318.83; m_mse.modelId = 1337; m_mse.externalWlsId = 0; DEBUG_LOG(m_logger) << "Publishing MainStructureElement: " << m_mse; if (!m_ismDts->publish(m_mse)) failExit("Error publishing MainStructureElement"); } void CesTests::tryCreateMainFootprint() { InfrastructureManagement::MainFootprint mf; mf.id = 555; mf.isDeleted = false; mf.isUsed = false; mf.structureElementId = 1; mf.elements.resize(4); InfrastructureManagement::FootprintElement elem; elem.id = 1; elem.relPosition = Core::RelativePosition(0.0, 0.0, 0.0); mf.elements.push_back(elem); elem.id = 2; elem.relPosition = Core::RelativePosition(10.0, 0.0, 0.0); mf.elements.push_back(elem); elem.id = 3; elem.relPosition = Core::RelativePosition(10.0, 10.0, 0.0); mf.elements.push_back(elem); elem.id = 4; elem.relPosition = Core::RelativePosition(0.0, 10.0, 0.0); mf.elements.push_back(elem); DEBUG_LOG(m_logger) << "Publishing MainFootprint: " << mf; if (!m_ismDts->publish(mf)) failExit("Error publishing MainFootprint"); } // ///////////////////////////////////////////////////// /// \brief CesTests::tryCreateDynamicParticipantData /// void CesTests::tryCreateDynamicParticipantData() { ParticipantManagement::DynamicParticipantData dp; ParticipantManagement::StateInformation si; si.stateTime = QDateTime::currentMSecsSinceEpoch(); si.vulnerabilityState = ProjectDataManagement::VulnerabilityState::VulnerabilityState_CombatReady; dp.participantId = m_participants[m_participantIndex].participantId; dp.stateHistory.push_back(si); dp.sampleTime = si.stateTime; DEBUG_LOG(m_logger) << "Publishing DynamicParticipantData: " << dp; if (!m_ppmDts->publish(dp)) failExit("Error publishing DynamicParticipantData"); } // ///////////////////////////////////////////////////// /// \brief CesTests::tryCreateParticipantPosition /// void CesTests::tryCreateParticipantPosition() { ParticipantManagement::ParticipantPosition pp; QPointF posF = m_housePos.geographic(m_participants[m_participantIndex].relX, m_participants[m_participantIndex].relY); const Core::GeoPosition pos(Core::GeoPosition(posF.x(), posF.y(), 0)); pp.buildingId = m_buildingId; pp.participantId = m_participants[m_participantIndex].participantId; pp.participantTypeId = 78; pp.partyId = 5; m_participantIndex++; pp.roomId = m_roomId; pp.sampleTime = QDateTime::currentMSecsSinceEpoch(); pp.pos = pos; m_expectedPosition[pp.participantId] = Core::GeoPosition2D(posF.x(), posF.y()); DEBUG_LOG(m_logger) << "Publishing ParticipantPosition: " << pp; if (!m_ppmDts->publish(pp)) failExit("Error publishing ParticipantPosition"); } // ///////////////////////////////////////////////////// /// \brief CesTests::tryCreateBuildingState /// void CesTests::tryCreateBuildingState() { Buildings::BuildingState bs; Buildings::RoomState rs; bs.id = m_moutObjectId; bs.aesId = m_moutObjectId; bs.originatorParticipantId = 2000; bs.chargeTypeId = m_chargeTypeId; bs.damagePercent = 100; bs.damagePercentOld = 0; bs.vulnerabilityState = ProjectDataManagement::VulnerabilityState::VulnerabilityState_CatastrophicKill; rs.id = m_roomId; rs.damagePercent = 80; rs.remainingEffectPercent = 90; bs.roomStates.push_back(rs); rs.id = m_roomId+1; rs.damagePercent = 80; rs.remainingEffectPercent = 60; bs.roomStates.push_back(rs); DEBUG_LOG(m_logger) << "Publishing BuildingState: " << bs; if (!m_bldDts->publish(bs)) failExit("Error publishing BuildingState"); } static inline bool isSamePosition(const Core::GeoPosition2D &p1, const Core::GeoPosition2D &p2) { return (qFuzzyCompare(p1.lat, p2.lat) && qFuzzyCompare(p1.lon, p2.lon)); } // ///////////////////////////////////////////////////// // cesTests -t 3 -e 42 // STTW (handler_participant_building) void CesTests::onSendCesHitOnBuildingRequest(const rti::core::SampleIdentity &cookie, const Buildings::SendCesHitOnBuildingRequest &request) { const QDateTime dateTime(QDateTime::fromMSecsSinceEpoch(request.effectTime)); // debug und co m_countHitOnBuildingReply++; DEBUG_LOG(m_logger) << "onSendCesHitOnBuildingRequest cnt = " << m_countHitOnBuildingReply << "\n" << " request: " << request << ", " << dateTime.toString(QStringLiteral("dd.MM.yy - hh:mm:ss.zzz")) << "\n"; if (request.buildingId != m_mse.id) { failExit(QStringLiteral("Invalid building id %1 - %2").arg(request.buildingId).arg(m_mse.id)); return; } if (request.chargeTypeId != m_chargeTypeId) { failExit(QStringLiteral("Invalid chargeType id %1 - %2").arg(request.chargeTypeId).arg(m_chargeTypeId)); return; } if (request.aesId != m_aesItemId) { failExit(QStringLiteral("Invalid aes id %1 - %2").arg(request.aesId).arg(m_aesItemId)); return; } m_bldFts->sendCesHitOnBuildingReply(cookie, Core::FunctionReplyObject()); switch (m_testId) { case 1: { for (const auto &impact : m_aiv.form) { if (isSamePosition(impact, request.impactPosition)) { if (m_countHitOnBuildingReply == 2) ExitSuccess(); return; } } failExit("Got building hit on unknown position"); break; } case 2: if (isSamePosition(m_es.impactPosition, request.impactPosition)) ExitSuccess(); else failExit("Got building hit on unknown position"); break; default: failExit("Unexpected hit request"); break; } } void CesTests::onSendCesHitRequest(const rti::core::SampleIdentity &cookie, const TrainingAreaBase::SendCesHitRequest &request) { m_tabFts->sendCesHitReply(cookie, Core::FunctionReplyObject()); /* comes out with timeout on STTW if (request.effectTime() + 1000 < QDateTime::currentMSecsSinceEpoch()) { DEBUG_LOG(m_logger) << "onSendCesHitRequest from previous test - ignoring" << request.effectTime() << QDateTime::currentMSecsSinceEpoch(); return; } */ // debug und co const QDateTime dateTime(QDateTime::fromMSecsSinceEpoch(request.effectTime)); DEBUG_LOG(m_logger) << "onSendCesHitRequest" << "\n" << " request: " << request << ", " << dateTime.toString(QStringLiteral("dd.MM.yy - hh:mm:ss.zzz")) << "\n"; if (request.remainEffectPercent) switch (m_testId) { case 5: case 6: case 7: case 9: { if (request.chargeTypeId != m_chargeTypeId) failExit(QStringLiteral("Invalid chargeType id %1 - %2").arg(request.chargeTypeId).arg(m_chargeTypeId)); else if (request.aesId != m_aesItemId) failExit(QStringLiteral("Invalid aes id %1 - %2").arg(request.chargeTypeId).arg(m_chargeTypeId)); else if (isSamePosition(m_expectedPosition.value(request.participantId), request.position.position)) ExitSuccess(); else failExit("Got wrong impact position"); return; } case 10: { // 3 x Enter if (request.remainEffectPercent == 1) m_replyEnterFunctionalArea ++; DEBUG_LOG(m_logger)<< "m_replyEnterFunctionalArea=" << m_replyEnterFunctionalArea; if (m_replyEnterFunctionalArea == 3) ExitSuccess(); break; } case 11: // delete functional Area case 12: // leave functional Area break; default: { // nothing ExitSuccess(); break; } } } void CesTests::checkParticipantEvent() { ProjectDataManagement::PdmEventType expectedType = ProjectDataManagement::PdmEventType::Unknown; switch (m_testId) { case 8: expectedType = ProjectDataManagement::PdmEventType::EventType_MineArea; break; case 10: expectedType = ProjectDataManagement::PdmEventType::EventType_FunctionalArea; break; case 11: case 12: expectedType = ProjectDataManagement::PdmEventType::EventType_FunctionalArea; break; case 13: expectedType = ProjectDataManagement::PdmEventType::EventType_CrossLocalBorderline; break; case 14: expectedType = ProjectDataManagement::PdmEventType::EventType_DangerArea; break; default: // nothing failExit("Unexpected participant event"); return; } DEBUG_LOG(m_logger) << "Waiting for a participant event: " << expectedType; bool bRet = false; for (int i = 0; i < 50; ++i) { std::function cb = [&bRet, expectedType](const CentralEffectSimulation::ParticipantEvent &pe) -> bool { if (pe.eventTypeId == expectedType) { bRet = true; return true; } return false; }; m_cesDtc->participantEvents(cb); if (bRet) { ExitSuccess(); return; } QTest::qWait(100); } } // ///////////////////////////////////////////////////// /// \brief CesTests::tryCreateParticipant /// void CesTests::tryCreateParticipant() { ParticipantManagement::Type ty; ty.id = 78; ty.typeClass = ParticipantManagement::TypeClass::WeaponSystem; m_ppmDts->publish(ty); ParticipantManagement::Participant pt; pt.id = m_participants[m_participantIndex].participantId; pt.equipmentNumber = m_participants[m_participantIndex].equipmentNumber; pt.partyId = 4; pt.typeId = ty.id; // Leo pt.isDeleted = false; pt.isSimulated = false; pt.equipmentNumber = 4711; DEBUG_LOG(m_logger) << "Publishing Participant:" << pt; if (!m_ppmDts->publish(pt)) failExit("Error requesting create Participant"); } void CesTests::failExit(const char *reason) { ERROR_LOG(m_logger) << "FailExit: " << reason << " for test case = " << m_testId; m_bTestsSuccessful = false; QTimer::singleShot(50, qApp, QCoreApplication::quit); } void CesTests::ExitSuccess() { if (!m_bTestsSuccessful) return; INFO_LOG(m_logger) << "ExitSuccess for test case = " << m_testId; 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: 0 (all tests)") , QLatin1String("0") }); addOption({ QStringList() << QLatin1String("r") << QLatin1String("roomId") , QLatin1String("RoomId.") , QLatin1String("Default: 0") , QLatin1String("0") }); } int testId() const { return isSet(QLatin1String("t")) ? value(QLatin1String("t")).toInt() : -1; } int roomId() const { return isSet(QLatin1String("r")) ? value(QLatin1String("r")).toInt() : 0; } }; // ------------------------------------------------------------------ int main(int argc, char **argv) { NGLCoreApplication app(argc, argv); app.createLogger("CES", 0); CmdLineParser options; if (!options.init()) return -1; int iRet = -1; { std::unique_ptr cesTests(new CentralEffectSimulation::CesTests); if (!cesTests->init(options.domainId(), options.exerciseId(), options.testId(), options.roomId())) return iRet; cesTests->startTest(); STARTUP_LOG(app.baseLogger()); app.exec(); iRet = cesTests->testsSuccessful() ? 0 : 1; fprintf(stderr, "%d\n", iRet); DEBUG_LOG(app.baseLogger()) << "** TEST (" << QString::number(options.testId()) <<") result = " << iRet; SHUTDOWN_LOG(app.baseLogger()); } return iRet; }