Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+308
@@ -0,0 +1,308 @@
|
||||
/**
|
||||
* Msg Function Topic Module Test
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "ces_tests_simulated_movement.h"
|
||||
|
||||
#include "CentralEffectSimulation/ces_dtc.h"
|
||||
#include "CentralEffectSimulation/ces_ftc.h"
|
||||
#include <TrainingAreaBase/tab_fts.h>
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
||||
#include <QTimer>
|
||||
#include <QDateTime>
|
||||
#include <QPolygonF>
|
||||
#include <QTest>
|
||||
|
||||
/* ----------------------------------------------------------------------------------
|
||||
* HOW TO RUN THE TESTS (example)
|
||||
* ----------------------------------------------------------------------------------
|
||||
* 0. Preconditions:
|
||||
* make db
|
||||
* Start services: (SV)
|
||||
* ./svcCentralEffectSimulation -e 42 &
|
||||
* ./cesTestsSimulatedMovement -t 1 -e 42 // Simulated Movement no Repeat
|
||||
* ./cesTestsSimulatedMovement -t 2 -e 42 // Simulated Movement Repeat
|
||||
*/
|
||||
|
||||
namespace CentralEffectSimulation
|
||||
{
|
||||
|
||||
cesTestsSimulatedMovement::cesTestsSimulatedMovement(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_bTestsSuccessful(true)
|
||||
, m_participantId(20)
|
||||
, m_repeat(false)
|
||||
, m_housePos(LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32UMD8000090000")))
|
||||
, m_logger(getLogger("cesTestsSimulatedMovement"))
|
||||
, m_testId(0)
|
||||
{}
|
||||
|
||||
cesTestsSimulatedMovement::~cesTestsSimulatedMovement()
|
||||
{}
|
||||
|
||||
bool cesTestsSimulatedMovement::init(int domainId, int exerciseId, int testId)
|
||||
{
|
||||
bool bRet = true;
|
||||
INFO_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->enableParticipant();
|
||||
|
||||
m_cesFtc = CentralEffectSimulation::Interface::Ftc::create(m_ddsConnector42);
|
||||
bRet &= m_cesFtc->enableAll();
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
void cesTestsSimulatedMovement::startTest()
|
||||
{
|
||||
INFO_LOG(m_logger) << "startTest m_testId=" << m_testId;
|
||||
if (m_testId <= 1) // 1 SMART
|
||||
{
|
||||
QTimer::singleShot(0, this, &cesTestsSimulatedMovement::tryCreateParticipant);
|
||||
QTimer::singleShot(250, this, &cesTestsSimulatedMovement::trySimulatedMovementModifyRequest);
|
||||
//QTimer::singleShot(500, this, &cesTestsSimulatedMovement::trySimulatedMovementModifyRequest);
|
||||
//QTimer::singleShot(750, this, &cesTestsSimulatedMovement::trySimulatedMovementRemoveRequest);
|
||||
|
||||
//QTimer::singleShot(6000, this, &cesTestsSimulatedMovement::checkParticipantEvent);
|
||||
}
|
||||
else if (m_testId <= 2) // 1 SMART
|
||||
{
|
||||
m_repeat = true;
|
||||
QTimer::singleShot(0, this, &cesTestsSimulatedMovement::tryCreateParticipant);
|
||||
QTimer::singleShot(250, this, &cesTestsSimulatedMovement::trySimulatedMovementModifyRequest);
|
||||
//QTimer::singleShot(500, this, &cesTestsSimulatedMovement::trySimulatedMovementModifyRequest);
|
||||
//QTimer::singleShot(750, this, &cesTestsSimulatedMovement::trySimulatedMovementRemoveRequest);
|
||||
|
||||
//QTimer::singleShot(6000, this, &cesTestsSimulatedMovement::checkParticipantEvent);
|
||||
}
|
||||
else
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Unknown test id = " << m_testId;
|
||||
failExit();
|
||||
}
|
||||
QTimer::singleShot(8000, this, &cesTestsSimulatedMovement::failExit);
|
||||
}
|
||||
|
||||
|
||||
void cesTestsSimulatedMovement::checkParticipantEvent()
|
||||
{
|
||||
INFO_LOG(m_logger) << "checkParticipantEvent";
|
||||
m_cesDtc->waitForHistoricalDataParticipantEvent();
|
||||
CentralEffectSimulation::ParticipantEvent participantEvent0 = m_cesDtc->participantEvent(0);
|
||||
CentralEffectSimulation::ParticipantEvent participantEvent1 = m_cesDtc->participantEvent(1);
|
||||
INFO_LOG(m_logger) << "Recived ParicipantEvent equipmentNumber:" << participantEvent0.equipmentNumber()
|
||||
<< " eventType=" << participantEvent0.eventTypeId();
|
||||
INFO_LOG(m_logger) << "Recived ParicipantEvent equipmentNumber:" << participantEvent1.equipmentNumber()
|
||||
<< " eventType=" << participantEvent1.eventTypeId();
|
||||
|
||||
switch (m_testId)
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
if (participantEvent0.eventTypeId() == ProjectDataManagement::EventType::HitEffectSimulation
|
||||
&& participantEvent1.eventTypeId() == ProjectDataManagement::EventType::HitEffectSimulation)
|
||||
ExitSuccess();
|
||||
break;
|
||||
default:
|
||||
// nothing
|
||||
failExit();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject cesTestsSimulatedMovement::fillFro(int participantId, bool bSuccess) const
|
||||
{
|
||||
if (bSuccess)
|
||||
return Core::FunctionReplyObject(participantId);
|
||||
return Core::FunctionReplyObject(participantId, tr_lts("dds", "Error sending telegram to tetra"));
|
||||
}
|
||||
|
||||
void cesTestsSimulatedMovement::trySimulatedMovementModifyRequest()
|
||||
{
|
||||
int32_t id = 0; // create
|
||||
std::string name = "Name";
|
||||
bool jumpToStart = false;
|
||||
bool repeat = m_repeat;
|
||||
int nextPoint = -1;
|
||||
rti::core::int64 startTime = QDateTime::currentMSecsSinceEpoch()+2000;
|
||||
int32_t participantId = m_participantId++;
|
||||
CentralEffectSimulation::SimulatedMovementSegment seg0;
|
||||
QPointF posF0 = m_housePos.geographic(5, 5);
|
||||
const Core::GeoPosition2D pos0(Core::GeoPosition2D(posF0.x(), posF0.y()));
|
||||
|
||||
QPointF posF1 = m_housePos.geographic(10, 10);
|
||||
const Core::GeoPosition2D pos1(Core::GeoPosition2D(posF1.x(), posF1.y()));
|
||||
|
||||
QPointF posF2 = m_housePos.geographic(5, 5);
|
||||
const Core::GeoPosition2D pos2(Core::GeoPosition2D(posF2.x(), posF2.y()));
|
||||
|
||||
seg0.delay(5);
|
||||
seg0.name("seg0");
|
||||
seg0.speed(1.1);
|
||||
//m_speed += 1.0;
|
||||
seg0.position(pos0);
|
||||
CentralEffectSimulation::SimulatedMovementSegment seg1;
|
||||
seg1.delay(5);
|
||||
seg1.name("seg1");
|
||||
seg1.speed(1.2);
|
||||
//m_speed += 1.0;
|
||||
seg1.position(pos1);
|
||||
CentralEffectSimulation::SimulatedMovementSegment seg2;
|
||||
seg2.delay(6);
|
||||
seg2.name("seg2");
|
||||
seg2.speed(1.3);
|
||||
//m_speed += 1.0;
|
||||
seg2.position(pos2);
|
||||
|
||||
std::vector<CentralEffectSimulation::SimulatedMovementSegment> segments;
|
||||
segments.push_back(seg0);
|
||||
segments.push_back(seg1);
|
||||
//segments[2] = seg2;
|
||||
|
||||
SimulatedMovementModifyRequest req;
|
||||
req.id(id);
|
||||
req.name(name);
|
||||
req.startTime(startTime);
|
||||
req.participantId(participantId);
|
||||
req.segments(segments);
|
||||
req.repeat(repeat);
|
||||
req.jumpToStart(jumpToStart);
|
||||
req.nextPoint(nextPoint);
|
||||
|
||||
if (!m_cesFtc->simulatedMovementModifyRequest(req, this))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error requesting create data";
|
||||
failExit();
|
||||
}
|
||||
|
||||
QTest::qWait(2000);
|
||||
}
|
||||
|
||||
void cesTestsSimulatedMovement::trySimulatedMovementRemoveRequest()
|
||||
{
|
||||
int32_t id = 1; // remove
|
||||
|
||||
if (!m_cesFtc->simulatedMovementRemoveRequest(SimulatedMovementRemoveRequest(id), this))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error requesting remove data";
|
||||
failExit();
|
||||
}
|
||||
QTest::qWait(2000);
|
||||
}
|
||||
|
||||
// /////////////////////////////////////////////////////
|
||||
/// \brief cesTestsSimulatedMovement::tryCreateParticipant
|
||||
///
|
||||
void cesTestsSimulatedMovement::tryCreateParticipant()
|
||||
{
|
||||
ParticipantManagement::Participant pt;
|
||||
pt.id(m_participantId);
|
||||
pt.partyId(5);
|
||||
|
||||
DEBUG_LOG(m_logger) << "Publishing Participant";
|
||||
if (!m_ppmDts->publish(pt))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error requesting create Participant";
|
||||
failExit();
|
||||
}
|
||||
QTest::qWait(2000);
|
||||
}
|
||||
|
||||
void cesTestsSimulatedMovement::onSimulatedMovementModifyReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
Q_UNUSED(replyObject);
|
||||
INFO_LOG(m_logger) << "onSimulatedMovementModifyReply()";
|
||||
}
|
||||
|
||||
void cesTestsSimulatedMovement::onSimulatedMovementRemoveReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
Q_UNUSED(replyObject);
|
||||
INFO_LOG(m_logger) << "onSimulatedMovementRemoveReply()";
|
||||
}
|
||||
|
||||
void cesTestsSimulatedMovement::failExit()
|
||||
{
|
||||
ERROR_LOG(m_logger) << "FailExit";
|
||||
m_bTestsSuccessful = false;
|
||||
QTimer::singleShot(50, qApp, QCoreApplication::quit);
|
||||
}
|
||||
|
||||
void cesTestsSimulatedMovement::ExitSuccess()
|
||||
{
|
||||
INFO_LOG(m_logger) << "ExitSuccess";
|
||||
m_bTestsSuccessful = true;
|
||||
QTimer::singleShot(200, 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<CentralEffectSimulation::cesTestsSimulatedMovement> cesTests(new CentralEffectSimulation::cesTestsSimulatedMovement);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user