/** * Msg Function Topic Module Test * $Id$ * $HeadURL$ * $Author$ */ #include "ces_tests_ownership.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 & * ./cesTestsOwnership -t 1 -e 42 // 1 Participant in Bldg 56 * ./cesTestsOwnership -t 2 -e 42 // Participants * ./cesTestsOwnership -t 3 -e 42 // Participants with vulnarability kill are not count * ./cesTestsOwnership -t 4 -e 42 // Participants in Bldg 56 * ./cesTestsOwnership -t 5 -e 42 // reset Ownership */ namespace CentralEffectSimulation { CesTestsOwnership::CesTestsOwnership(QObject *parent) : QObject(parent) , m_bTestsSuccessful(true) , m_housePos(LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32UMD8000090000"))) , m_testId(0) , m_participantIndex(0) , m_DynamicParticipantIndex(0) {} CesTestsOwnership::~CesTestsOwnership() {} bool CesTestsOwnership::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_cesFtc = CentralEffectSimulation::Interface::Ftc::create(m_ddsConnector42); bRet &= m_cesFtc->enableAll(); m_participants.resize(5); m_participants[0].participantId = 20; m_participants[0].equipmentNumber = 60; m_participants[0].relX = -1; m_participants[0].relY = -1; m_participants[0].partyId = 2; m_participants[0].buildingId = m_buildingId; m_participants[0].roomId = 58; m_participants[1].participantId = 21; m_participants[1].equipmentNumber = 61; m_participants[1].relX = -10; m_participants[1].relY = -1; m_participants[1].partyId = 2; m_participants[1].buildingId = m_buildingId; m_participants[1].roomId = 32; m_participants[2].participantId = 22; m_participants[2].equipmentNumber = 62; m_participants[2].relX = -10; m_participants[2].relY = -1; m_participants[2].partyId = 3; m_participants[2].buildingId = m_buildingId; m_participants[2].roomId = 32; m_participants[3].participantId = 23; m_participants[3].equipmentNumber = 63; m_participants[3].relX = -10; m_participants[3].relY = -1; m_participants[3].partyId = 3; m_participants[3].buildingId = m_buildingId; m_participants[3].roomId = 32; m_participants[4].participantId = 24; m_participants[4].equipmentNumber = 64; m_participants[4].relX = -10; m_participants[4].relY = -1; m_participants[4].partyId = 2; m_participants[4].buildingId = m_buildingId; m_participants[4].roomId = 58; return bRet; } void CesTestsOwnership::startTest() { INFO_LOG(m_logger) << "startTest m_testId=" << m_testId; if (m_testId <= 1) // 1 Participant in BT56 { QTimer::singleShot(0, this, &CesTestsOwnership::tryCreateParticipantPosition); QTimer::singleShot(500, this, &CesTestsOwnership::checkBuildingOwnership); } else if (m_testId <= 2) // Participants with vulnarability kill are not count { // 1 participant with party=1 combatReady for use and // 2 participants with party=2 m_participants[0].roomId = 32; m_participants[1].roomId = 32; m_participants[2].roomId = 32; QTimer::singleShot(0, this, &CesTestsOwnership::tryCreateParticipantPosition); QTimer::singleShot(500, this, &CesTestsOwnership::tryCreateParticipantPosition); QTimer::singleShot(1000, this, &CesTestsOwnership::tryCreateParticipantPosition); QTimer::singleShot(1500, this, &CesTestsOwnership::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, &CesTestsOwnership::tryCreateParticipantPosition); QTimer::singleShot(500, this, &CesTestsOwnership::tryCreateParticipantPosition); QTimer::singleShot(1000, this, &CesTestsOwnership::tryCreateParticipantPosition); QTimer::singleShot(1500, this, &CesTestsOwnership::tryCreateDynamicParticipantData); // Kill for Participant 0 (participantId = 20) QTimer::singleShot(1700, this, &CesTestsOwnership::tryCreateDynamicParticipantData); // Kill for Participant 1 (participantId = 21) QTimer::singleShot(2500, this, &CesTestsOwnership::checkBuildingOwnership); } else if (m_testId <= 4) // Participants in BT56 { QTimer::singleShot(0, this, &CesTestsOwnership::tryCreateParticipantPosition); QTimer::singleShot(500, this, &CesTestsOwnership::tryCreateParticipantPosition); QTimer::singleShot(1000, this, &CesTestsOwnership::tryCreateParticipantPosition); QTimer::singleShot(1500, this, &CesTestsOwnership::tryCreateParticipantPosition); QTimer::singleShot(2000, this, &CesTestsOwnership::tryCreateParticipantPosition); QTimer::singleShot(2500, this, &CesTestsOwnership::checkBuildingOwnership); } else if (m_testId <= 5) // reset ownership { QTimer::singleShot(0, this, &CesTestsOwnership::tryCreateParticipantPosition); QTimer::singleShot(500, this, &CesTestsOwnership::tryCreateParticipantPosition); QTimer::singleShot(1000, this, &CesTestsOwnership::tryCreateParticipantPosition); QTimer::singleShot(1500, this, &CesTestsOwnership::tryCreateParticipantPosition); QTimer::singleShot(2000, this, &CesTestsOwnership::tryCreateParticipantPosition); QTimer::singleShot(2500, this, &CesTestsOwnership::trySetOwnershipRequest); QTimer::singleShot(3000, this, &CesTestsOwnership::checkBuildingOwnership); } else { ERROR_LOG(m_logger) << "Unknown test id = " << m_testId; failExit(); } QTimer::singleShot(6000, this, &CesTestsOwnership::failExit); } // ///////////////////////////////////////////////////// /// \brief CesTestsOwnership::tryCreateDynamicParticipantData /// void CesTestsOwnership::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 CesTestsOwnership::tryCreateParticipantPosition /// void CesTestsOwnership::tryCreateParticipantPosition() { ParticipantManagement::ParticipantPosition pp; const qint64 time = QDateTime::currentMSecsSinceEpoch(); const rti::core::int64 posTime = static_cast(time); 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_participants[m_participantIndex].buildingId); pp.participantId(m_participants[m_participantIndex].participantId); pp.partyId(m_participants[m_participantIndex].partyId); pp.roomId(m_participants[m_participantIndex].roomId); 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 CesTestsOwnership::tryCreateParticipant /// void CesTestsOwnership::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(); } } void CesTestsOwnership::trySetOwnershipRequest() { int32_t partyId = 0; DEBUG_LOG(m_logger) << " request.buildingId() = " << m_buildingId << " request.partyId() = " << m_buildingId; if (!m_cesFtc->setOwnershipRequest(SetOwnershipRequest(m_buildingId, partyId), this)) { ERROR_LOG(m_logger) << "Error requesting create data"; failExit(); } } void CesTestsOwnership::onSetOwnershipReply(const Core::FunctionReplyObject &replyObject) { INFO_LOG(m_logger) << "onSetOwnershipReply() replyObject.id=" << replyObject.id(); } void CesTestsOwnership::checkBuildingOwnership() { INFO_LOG(m_logger) << "checkBuildingOwnership"; /* m_cesDtc->waitForHistoricalDataBuildingOwnership(); QMap < int ,CentralEffectSimulation::BuildingOwnership> buildingOwnership = m_cesDtc->buildingOwnerships(); INFO_LOG(m_logger) << "Recived ParicipantEvent BuildingOwnership:"< cesTests(new CentralEffectSimulation::CesTestsOwnership); 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; }