/** * Msg Function Topic Module Test * $Id$ * $HeadURL$ * $Author$ */ #include "ces_tests_blocked_areas.h" #include "CentralEffectSimulation/ces_dtc.h" #include "CentralEffectSimulation/ces_ftc.h" #include #include #include #include #include /* ---------------------------------------------------------------------------------- * HOW TO RUN THE TESTS (example) * ---------------------------------------------------------------------------------- * 0. Preconditions: * load BT56 (BUILD) * make db * Start services: (SV) * ./bin/svcCentralEffectSimulation -e 42 & * ./CesTestsBlockedAreas -t 1 -e 42 // 1 Participant in Bldg 56 * ./CesTestsBlockedAreas -t 2 -e 42 // Participants * ./CesTestsBlockedAreas -t 3 -e 42 // Participants with vulnarability kill are not count * ./CesTestsBlockedAreas -t 4 -e 42 // Participants in Bldg 56 * ./CesTestsBlockedAreas -t 5 -e 42 // reset Ownership */ namespace CentralEffectSimulation { CesTestsBlockedAreas::CesTestsBlockedAreas(QObject *parent) : QObject(parent) , m_bTestsSuccessful(true) , m_housePos(LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32UMD8000090000"))) , m_logger(getLogger("CesTestsBlockedAreas")) , m_testId(0) , m_participantIndex(0) , m_DynamicParticipantIndex(0) {} CesTestsBlockedAreas::~CesTestsBlockedAreas() {} bool CesTestsBlockedAreas::init(int domainId, int exerciseId, int testId) { bool bRet = true; INFO_LOG(m_logger) << "init begin"; m_testId = testId; m_buildingId = 7; // ism_main_structure_element:id m_ddsConnector42 = std::make_shared(domainId, IDL::PartitionType::Exercise, exerciseId); m_ddsConnector42->init(); m_ddsConnector42->initPublisherSubscriber(); m_ppmDts = ParticipantManagement::Interface::Dts::create(m_ddsConnector42); bRet &= m_ppmDts->enableParticipantPosition(); bRet &= m_ppmDts->enableParticipant(); bRet &= m_ppmDts->enableDynamicParticipantData(); m_cesDtc = CentralEffectSimulation::Interface::Dtc::create(m_ddsConnector42); bRet &= m_cesDtc->enableAll(); m_bldDts = Buildings::Interface::Dts::create(m_ddsConnector42); bRet &= m_bldDts->enableBuildingState(); m_participants.resize(1); m_participants[0].participantId = 5; m_participants[0].equipmentNumber = 1001; m_participants[0].relX = -1; m_participants[0].relY = -1; m_participants[0].partyId = 2; m_participants[0].buildingId = 301; m_participants[0].roomId = 41; return bRet; } void CesTestsBlockedAreas::startTest() { INFO_LOG(m_logger) << "startTest m_testId=" << m_testId; if (m_testId <= 1) // 1 Participant in BT56 { QTimer::singleShot(0, this, &CesTestsBlockedAreas::tryCreateParticipantPositionOutside); QTimer::singleShot(200, this, &CesTestsBlockedAreas::tryCreateBuildingState); QTimer::singleShot(400, this, &CesTestsBlockedAreas::tryCreateParticipantPosition); QTimer::singleShot(600, this, &CesTestsBlockedAreas::tryCreateParticipantPosition); QTimer::singleShot(800, this, &CesTestsBlockedAreas::tryCreateParticipantPositionOutside); QTimer::singleShot(1000, this, &CesTestsBlockedAreas::tryCreateParticipantPositionOutside); } else if (m_testId <= 2) // Participants with vulnarability kill are not count { QTimer::singleShot(0, this, &CesTestsBlockedAreas::tryCreateParticipantPosition); QTimer::singleShot(500, this, &CesTestsBlockedAreas::tryCreateParticipantPosition); QTimer::singleShot(1000, this, &CesTestsBlockedAreas::tryCreateParticipantPosition); QTimer::singleShot(1500, this, &CesTestsBlockedAreas::checkBuildingOwnership); } else if (m_testId <= 3) // Participants with vulnarability kill are not count { // 1 participant with party=1 combatReady for use and // 2 participants with party=2 killed in the same room m_participants[0].roomId = 32; m_participants[1].roomId = 32; m_participants[2].roomId = 32; QTimer::singleShot(0, this, &CesTestsBlockedAreas::tryCreateParticipantPosition); QTimer::singleShot(500, this, &CesTestsBlockedAreas::tryCreateParticipantPosition); QTimer::singleShot(1000, this, &CesTestsBlockedAreas::tryCreateParticipantPosition); QTimer::singleShot(1500, this, &CesTestsBlockedAreas::tryCreateDynamicParticipantData); // Kill for Participant 0 (participantId = 20) QTimer::singleShot(1700, this, &CesTestsBlockedAreas::tryCreateDynamicParticipantData); // Kill for Participant 1 (participantId = 21) QTimer::singleShot(2500, this, &CesTestsBlockedAreas::checkBuildingOwnership); } else if (m_testId <= 4) // Participants in BT56 { QTimer::singleShot(0, this, &CesTestsBlockedAreas::tryCreateParticipantPosition); QTimer::singleShot(500, this, &CesTestsBlockedAreas::tryCreateParticipantPosition); QTimer::singleShot(1000, this, &CesTestsBlockedAreas::tryCreateParticipantPosition); QTimer::singleShot(1500, this, &CesTestsBlockedAreas::tryCreateParticipantPosition); QTimer::singleShot(2000, this, &CesTestsBlockedAreas::tryCreateParticipantPosition); QTimer::singleShot(2500, this, &CesTestsBlockedAreas::checkBuildingOwnership); } else if (m_testId <= 5) // reset ownership { QTimer::singleShot(0, this, &CesTestsBlockedAreas::tryCreateParticipantPosition); QTimer::singleShot(500, this, &CesTestsBlockedAreas::tryCreateParticipantPosition); QTimer::singleShot(1000, this, &CesTestsBlockedAreas::tryCreateParticipantPosition); QTimer::singleShot(1500, this, &CesTestsBlockedAreas::tryCreateParticipantPosition); QTimer::singleShot(2000, this, &CesTestsBlockedAreas::tryCreateParticipantPosition); QTimer::singleShot(3000, this, &CesTestsBlockedAreas::checkBuildingOwnership); } else { ERROR_LOG(m_logger) << "Unknown test id = " << m_testId; failExit(); } QTimer::singleShot(6000, this, &CesTestsBlockedAreas::failExit); } // ///////////////////////////////////////////////////// /// \brief CesTestsBlockedAreas::tryCreateDynamicParticipantData /// void CesTestsBlockedAreas::tryCreateDynamicParticipantData() { ParticipantManagement::DynamicParticipantData dp; const qint64 time = QDateTime::currentMSecsSinceEpoch(); const rti::core::int64 esTime = static_cast(time); ParticipantManagement::StateInformation si; si.stateTime(esTime); si.vulnerabilityState(ProjectDataManagement::VulnerabilityState_def::CatastrophicKill); dp.participantId(m_participants[m_DynamicParticipantIndex].participantId); dp.stateHistory().push_back(si); dp.sampleTime(esTime); m_DynamicParticipantIndex++; DEBUG_LOG(m_logger) << "Publishing DynamicParticipantData"; if (!m_ppmDts->publish(dp)) { ERROR_LOG(m_logger) << "Error requesting create ParticipantPosition"; failExit(); } } // ///////////////////////////////////////////////////// /// \brief CesTestsBlockedAreas::tryCreateParticipantPositionOutside /// void CesTestsBlockedAreas::tryCreateParticipantPositionOutside() { ParticipantManagement::ParticipantPosition pp; const qint64 time = QDateTime::currentMSecsSinceEpoch(); const rti::core::int64 posTime = static_cast(time); const Core::GeoPosition pos(0.15527934, 0.92597385, 1.0); pp.buildingId(0); pp.participantId(5); pp.partyId(2); pp.roomId(0); m_participantIndex++; pp.sampleTime(posTime); pp.pos(pos); DEBUG_LOG(m_logger) << "Publishing ParticipantPosition"; if (!m_ppmDts->publish(pp)) { ERROR_LOG(m_logger) << "Error requesting create ParticipantPosition"; failExit(); } } // ///////////////////////////////////////////////////// /// \brief CesTestsBlockedAreas::tryCreateParticipantPosition /// void CesTestsBlockedAreas::tryCreateParticipantPosition() { ParticipantManagement::ParticipantPosition pp; const qint64 time = QDateTime::currentMSecsSinceEpoch(); const rti::core::int64 posTime = static_cast(time); const Core::GeoPosition pos(0.15527550, 0.92597466, 1.0); pp.buildingId(301); pp.participantId(5); pp.partyId(2); pp.roomId(41); m_participantIndex++; pp.sampleTime(posTime); pp.pos(pos); DEBUG_LOG(m_logger) << "Publishing ParticipantPosition"; if (!m_ppmDts->publish(pp)) { ERROR_LOG(m_logger) << "Error requesting create ParticipantPosition"; failExit(); } } // ///////////////////////////////////////////////////// /// \brief CesTestsBlockedAreas::tryCreateParticipant /// void CesTestsBlockedAreas::tryCreateParticipant() { ParticipantManagement::Participant pt; pt.id(m_participants[m_participantIndex].participantId); pt.equipmentNumber(m_participants[m_participantIndex].equipmentNumber); DEBUG_LOG(m_logger) << "Publishing Participant"; if (!m_ppmDts->publish(pt)) { ERROR_LOG(m_logger) << "Error requesting create Participant"; failExit(); } } // ///////////////////////////////////////////////////// /// \brief CesTests::tryCreateBuildingState /// void CesTestsBlockedAreas::tryCreateBuildingStateInit() { Buildings::BuildingState bs; bs.id(301); // BuildingId bs.structureElementId(26); bs.aesId(100); bs.aesId(0); bs.originatorParticipantId(2000); bs.chargeTypeId(4); bs.damagePercent(0); bs.damagePercentOld(0); bs.vulnerabilityState(ProjectDataManagement::VulnerabilityState::CombatReady); bs.sampleTime(QDateTime::currentMSecsSinceEpoch()); DEBUG_LOG(m_logger) << "Publishing BuildingState"; if (!m_bldDts->publish(bs)) { ERROR_LOG(m_logger) << "Error requesting create BuildingState"; failExit(); } } void CesTestsBlockedAreas::tryCreateBuildingState() { Buildings::BuildingState bs; Buildings::RoomState rs; bs.id(301); // BuildingId bs.structureElementId(26); bs.aesId(100); bs.aesId(0); bs.originatorParticipantId(2000); bs.chargeTypeId(4); bs.damagePercent(60); bs.damagePercentOld(0); bs.vulnerabilityState(ProjectDataManagement::VulnerabilityState::CombatReady); bs.roomStates().resize(1); rs.id(41); // RoomId rs.damagePercent(90); rs.remainingEffectPercent(90); bs.roomStates()[0] = rs; bs.sampleTime(QDateTime::currentMSecsSinceEpoch()); DEBUG_LOG(m_logger) << "Publishing BuildingState"; if (!m_bldDts->publish(bs)) { ERROR_LOG(m_logger) << "Error requesting create BuildingState"; failExit(); } } void CesTestsBlockedAreas::checkBuildingOwnership() { INFO_LOG(m_logger) << "checkBuildingOwnership"; ExitSuccess(); } void CesTestsBlockedAreas::failExit() { DEBUG_LOG(m_logger) << "FailExit"; m_bTestsSuccessful = false; QTimer::singleShot(50, qApp, QCoreApplication::quit); } void CesTestsBlockedAreas::ExitSuccess() { DEBUG_LOG(m_logger) << "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: 0 (all tests)") , QLatin1String("0") }); addOption({ QStringList() << QLatin1String("a") << QLatin1String("trainingAreaId") , QLatin1String("TrainingAreaId.") , QLatin1String("Default: 0 (Unknown)") , QLatin1String("0") }); } int testId() const { return isSet(QLatin1String("t")) ? value(QLatin1String("t")).toInt() : -1; } int trainingAreaId() const { return isSet(QLatin1String("a")) ? value(QLatin1String("a")).toInt() : -1; } }; // ------------------------------------------------------------------ int main(int argc, char **argv) { NGLCoreApplication app(argc, argv); app.createLogger("CES", "log4cxx_ces.props"); CmdLineParser options; if (!options.init()) return -1; int iRet = -1; { std::unique_ptr cesTests(new CentralEffectSimulation::CesTestsBlockedAreas); if (!cesTests->init(options.domainId(), options.exerciseId(), options.testId())) 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 result = " << iRet; SHUTDOWN_LOG(app.baseLogger()); } return iRet; }