Converts accessor calls to plain member access across the residual service set.
551 lines
18 KiB
C++
Executable File
551 lines
18 KiB
C++
Executable File
/**
|
|
* EXM Function Topic test executable
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*
|
|
* Created by Hanna E. Rathje, SLSE, 2015-09-10
|
|
*/
|
|
|
|
#include "exm_tests.h"
|
|
|
|
#include <nglapplication/nglcoreapplication.h>
|
|
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
|
#include <QtCore/QTimer>
|
|
#include <QTest>
|
|
|
|
#include <ExerciseManagement/exm_ftc.h>
|
|
#include <AssetManagement/asm_ftc.h>
|
|
|
|
/* ----------------------------------------------------------------------------------
|
|
* HOW TO RUN THE TESTS (example)
|
|
* ----------------------------------------------------------------------------------
|
|
* 0. Preconditions:
|
|
* Start with an empty database (BUILD)
|
|
* make db
|
|
* Start services: (SV)
|
|
* ./bin/svcAssetManagement -d 74 &
|
|
* ./bin/svcExerciseManagement -d 74 &
|
|
* Test steps: see exm_tests.csv
|
|
*/
|
|
|
|
//--------------------------------------------------------------------------
|
|
namespace ExerciseManagement
|
|
{
|
|
ExmTests::ExmTests(QObject *parent)
|
|
: QObject(parent)
|
|
, m_exerciseId(0)
|
|
, m_trainingAreaId(0)
|
|
, m_phaseId(0)
|
|
, m_testId(0)
|
|
, m_bTestsSuccessful(true)
|
|
, m_logger(getLogger("Test"))
|
|
{
|
|
qRegisterMetaType<Core::FunctionReply>("Core::FunctionReply");
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
ExmTests::~ExmTests()
|
|
{}
|
|
|
|
//--------------------------------------------------------------------------
|
|
bool ExmTests::init(int domainId, int exerciseId, int testId, int trainingAreaId, int phaseId)
|
|
{
|
|
INFO_LOG(m_logger) << "init begin";
|
|
|
|
m_testId = testId;
|
|
m_exerciseId = exerciseId; // overwritten when new exercise created
|
|
m_trainingAreaId = trainingAreaId; //overwritten
|
|
m_phaseId = phaseId;
|
|
|
|
// initialize DDS, always on ex_0
|
|
// exm ist immer auf ex_0 --> -e wird für die zu modifizierende/loeschende exercise missbraucht
|
|
m_ddsConnector.reset(new DDSConnector::DdsConnector(domainId, IDL::PartitionType::Global));
|
|
if (!m_ddsConnector->init())
|
|
return false;
|
|
m_ddsConnector->initPublisherSubscriber();
|
|
|
|
DEBUG_LOG(m_logger) << "Create dtc EXM";
|
|
m_dtc = ExerciseManagement::Interface::Dtc::create(m_ddsConnector);
|
|
DEBUG_LOG(m_logger) << "Init dtc";
|
|
bool bRet = m_dtc->enableAll();
|
|
DEBUG_LOG(m_logger) << "init DTC EXM end - bRet = " << bRet;
|
|
|
|
connect(m_dtc.get(), &ExerciseManagement::Interface::Dtc::exerciseChanged,
|
|
this, &ExmTests::onExerciseChanged);
|
|
|
|
DEBUG_LOG(m_logger) << "create ftc EXM";
|
|
m_ftc = ExerciseManagement::Interface::Ftc::create(m_ddsConnector);
|
|
DEBUG_LOG(m_logger) << "init ftc EXM";
|
|
bRet &= m_ftc->enableAll();
|
|
DEBUG_LOG(m_logger) << "init FTC EXM end - bRet = " << bRet;
|
|
|
|
DEBUG_LOG(m_logger) << "create ftc ASM";
|
|
m_ftc_asm = AssetManagement::Interface::Ftc::create(m_ddsConnector);
|
|
DEBUG_LOG(m_logger) << "init ftc ASM";
|
|
bRet &= m_ftc_asm->enableAll();
|
|
DEBUG_LOG(m_logger) << "init end EXM - bRet = " << bRet;
|
|
|
|
DEBUG_LOG(m_logger) << "Domain Id = " << domainId;
|
|
DEBUG_LOG(m_logger) << "Exercise Id = " << exerciseId;
|
|
DEBUG_LOG(m_logger) << "Test Id = " << testId;
|
|
DEBUG_LOG(m_logger) << "Training Area Id = " << trainingAreaId;
|
|
DEBUG_LOG(m_logger) << "Phase Id = " << phaseId;
|
|
|
|
//TODO: add connects
|
|
|
|
return bRet;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void ExmTests::startTest()
|
|
{
|
|
INFO_LOG(m_logger) << "startTest";
|
|
if (m_testId <= 1)
|
|
QTimer::singleShot(0, this, &ExmTests::tryCreate);
|
|
else if (m_testId == 2)
|
|
QTimer::singleShot(0, this, &ExmTests::tryModify);
|
|
else if (m_testId == 3)
|
|
QTimer::singleShot(0, this, &ExmTests::tryDelete);
|
|
else if (m_testId == 4)
|
|
QTimer::singleShot(0, this, &ExmTests::tryCreateTrainingArea);
|
|
else if (m_testId == 10)
|
|
QTimer::singleShot(0, this, &ExmTests::tryGetAllExercises);
|
|
else if (m_testId == 11)
|
|
QTimer::singleShot(0, this, &ExmTests::tryGetExercise);
|
|
else if (m_testId == 20)
|
|
QTimer::singleShot(0, this, &ExmTests::tryStartExercise);
|
|
else if (m_testId == 30)
|
|
QTimer::singleShot(0, this, &ExmTests::tryCreateExercisePhase);
|
|
else if (m_testId == 31)
|
|
QTimer::singleShot(0, this, &ExmTests::tryModifyExercisePhase);
|
|
else if (m_testId == 32)
|
|
QTimer::singleShot(0, this, &ExmTests::tryDeleteExercisePhase);
|
|
else if (m_testId == 99)
|
|
// do nothing, return true, need this in squish to alter sequence to 42
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
else
|
|
{
|
|
ERROR_LOG(m_logger) << "Unknown test id: " << m_testId;
|
|
failExit();
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void ExmTests::tryCreateTrainingArea()
|
|
{
|
|
INFO_LOG(m_logger) << "trying to send modifyRequest TrainingArea (create)";
|
|
AssetManagement::TrainingAreaModifyRequest request;
|
|
request.id = 0;
|
|
request.name = "TestTrainingAreaCreate";
|
|
request.bottomLeft = Core::GeoPosition2D(11.61/180*M_PI, 53.07/180*M_PI);
|
|
request.height = 1000000;
|
|
request.width = 1000000;
|
|
|
|
if (!m_ftc_asm->trainingAreaModifyRequest(request, this))
|
|
|
|
{
|
|
ERROR_LOG(m_logger) << "Error requesting create data";
|
|
failExit();
|
|
}
|
|
INFO_LOG(m_logger) << "Training Area Id = " << m_trainingAreaId;
|
|
|
|
QTest::qWait(1000);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void ExmTests::tryCreateExercisePhase()
|
|
{
|
|
INFO_LOG(m_logger) << "trying to send createrequest Exercise Phase";
|
|
if(!m_ftc->exercisePhaseCreateRequest(ExercisePhaseCreateRequest(std::string("Test Phase"), std::string("Test Phase description"), 10, 20, m_exerciseId), this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error requesting create Exercise Phase";
|
|
failExit();
|
|
}
|
|
QTest::qWait(1000);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void ExmTests::tryCreate()
|
|
{
|
|
// TODO: add symbolFillType (PDM)
|
|
int symbolFillType = 1;
|
|
int radioGroupId = 1;
|
|
|
|
INFO_LOG(m_logger) << "Training Area Id = " << m_trainingAreaId;
|
|
|
|
INFO_LOG(m_logger) << "trying to send createRequest Exercise";
|
|
ExerciseCreateRequest req;
|
|
req.name = std::string("TestExerciseCreate");
|
|
req.beginTime = 10;
|
|
req.endTime = 20;
|
|
req.trainingAreaId = m_trainingAreaId;
|
|
req.radioGroupId = radioGroupId;
|
|
req.symbolFillTypeId = symbolFillType;
|
|
req.forces = std::string("Forces");
|
|
req.description = std::string("Description");
|
|
|
|
if (!m_ftc->exerciseCreateRequest(req, this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error requesting create data";
|
|
failExit();
|
|
}
|
|
QTest::qWait(10000);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void ExmTests::tryModify()
|
|
{
|
|
INFO_LOG(m_logger) << "trying to send modify request for exercise Id = " << m_exerciseId;
|
|
ExerciseModifyRequest req;
|
|
req.id = m_exerciseId;
|
|
req.name = std::string("ExerciseModifyTest");
|
|
req.beginTime = 1000;
|
|
req.endTime = 2000;
|
|
req.trainingAreaId = m_trainingAreaId;
|
|
req.radioGroupId = 1;
|
|
req.symbolFillTypeId = 1;
|
|
req.forces = std::string("ForcesUpdated");
|
|
req.description = std::string("DescriptionUpdated");
|
|
req.activePhaseId = m_phaseId;
|
|
req.newState = ExerciseState::Created;
|
|
if (!m_ftc->exerciseModifyRequest(req, this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error requesting modify data";
|
|
failExit();
|
|
}
|
|
QTest::qWait(1000);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void ExmTests::tryModifyExercisePhase()
|
|
{
|
|
INFO_LOG(m_logger) << "trying to send modify exercise phase request for exercise phase Id = " << m_phaseId;
|
|
if (!m_ftc->exercisePhaseModifyRequest(ExercisePhaseModifyRequest(std::string("Modified Exercise Phase"), std::string("Exercise Phase has been modified"), 20, 30, m_exerciseId, m_phaseId), this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error requesting modify exercise phase";
|
|
failExit();
|
|
}
|
|
QTest::qWait(1000);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void ExmTests::tryDelete()
|
|
{
|
|
INFO_LOG(m_logger) << "trying to send delete request for exercise Id = " << m_exerciseId;
|
|
if (!m_ftc->exerciseRemoveRequest(ExerciseRemoveRequest(m_exerciseId, false), this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error requesting delete data";
|
|
failExit();
|
|
}
|
|
QTest::qWait(5000);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void ExmTests::tryDeleteExercisePhase()
|
|
{
|
|
if (m_phaseId == 0)
|
|
{
|
|
ERROR_LOG(m_logger) << "No phase available for deleting";
|
|
failExit();
|
|
}
|
|
|
|
INFO_LOG(m_logger) << "trying to send delete request for exercise phase Id = " << m_phaseId;
|
|
m_ftc->enableExercisePhaseRemove();
|
|
if (!m_ftc->exercisePhaseRemoveRequest(ExercisePhaseRemoveRequest(m_phaseId), this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error requesting delete exercise phase";
|
|
failExit();
|
|
}
|
|
QTest::qWait(1000);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void ExmTests::tryStartExercise()
|
|
{
|
|
INFO_LOG(m_logger) << "trying to start exercise Id = " << m_exerciseId;
|
|
|
|
m_dtc->waitForHistoricalDataExercise();
|
|
ExerciseManagement::Exercise ex = m_dtc->exercise(m_exerciseId);
|
|
|
|
DEBUG_LOG(m_logger) << "Training area id = " << ex.trainingAreaId;
|
|
|
|
ExerciseModifyRequest req;
|
|
req.id = m_exerciseId;
|
|
req.name = std::string("ExerciseStarted");
|
|
req.beginTime = ex.beginTime;
|
|
req.endTime = ex.endTime;
|
|
req.trainingAreaId = ex.trainingAreaId;
|
|
req.radioGroupId = ex.radioGroupId;
|
|
req.symbolFillTypeId = ex.symbolFillTypeId;
|
|
req.activePhaseId = ex.activePhaseId;
|
|
req.forces = ex.forces;
|
|
req.description = ex.description;
|
|
req.newState = ExerciseState::Started;
|
|
if (!m_ftc->exerciseModifyRequest(req, this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error requesting modify data";
|
|
failExit();
|
|
}
|
|
|
|
// ExerciseChangeStateRequest req;
|
|
// req.id(m_exerciseId);
|
|
// req.newState(ExerciseState::Started);
|
|
// req.startTime(3000);
|
|
|
|
// if (!m_ftc->exerciseChangeStateRequest(req, this))
|
|
// {
|
|
// ERROR_LOG(m_logger) << "Error requesting change state";
|
|
// failExit();
|
|
// }
|
|
|
|
QTest::qWait(2000);
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
void ExmTests::tryGetAllExercises()
|
|
{
|
|
INFO_LOG(m_logger) << "trying to get all exercises";
|
|
m_dtc->waitForHistoricalDataExercise();
|
|
|
|
bool bAtLeastOneFound = false;
|
|
auto cb = [this, &bAtLeastOneFound](const ExerciseManagement::Exercise &ex)
|
|
{
|
|
INFO_LOG(m_logger) << "Exe(" << ex.id << ") : " << ex.name;
|
|
bAtLeastOneFound = true;
|
|
};
|
|
m_dtc->exercises(cb);
|
|
if (!bAtLeastOneFound)
|
|
{
|
|
ERROR_LOG(m_logger) << "Error receiving data for exercises";
|
|
failExit();
|
|
}
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
void ExmTests::tryGetExercise()
|
|
{
|
|
INFO_LOG(m_logger) << "trying get itemData for exercise " << m_exerciseId;
|
|
m_dtc->waitForHistoricalDataExercise();
|
|
ExerciseManagement::Exercise data = m_dtc->exercise(m_exerciseId);
|
|
|
|
if (data.id <= 0)
|
|
{
|
|
ERROR_LOG(m_logger) << "Error receiving data for exercise " << m_exerciseId;
|
|
DEBUG_LOG(m_logger) << "data.id() = " << data.id;
|
|
failExit();
|
|
}
|
|
else
|
|
{
|
|
INFO_LOG(m_logger) << "## Exe(" << data.id << ") : name = " << data.name
|
|
<< ", begin = " << data.beginTime << ", end = " << data.endTime
|
|
<< ", state = " << data.state;
|
|
}
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
void ExmTests::onExerciseChanged(const ExerciseManagement::Exercise &data,
|
|
DataModification modType)
|
|
{
|
|
const int id = data.id;
|
|
DEBUG_LOG(m_logger) << "onExerciseChanged for exercise " << id
|
|
<< " - modType: " << (int)modType;
|
|
if (m_exerciseId == id)
|
|
INFO_LOG(m_logger) << "##################### Data for id = " << id << " received";
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void ExmTests::onExerciseCreateReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
if (replyObject.error())
|
|
{
|
|
ERROR_LOG(m_logger) << "Got onExerciseCreateReply error: " << replyObject();
|
|
failExit();
|
|
return;
|
|
}
|
|
INFO_LOG(m_logger) << "Got createReply with id " << replyObject.id()
|
|
<< " and errorString " << replyObject.translated();
|
|
m_exerciseId = replyObject.id();
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void ExmTests::onExerciseModifyReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
if (replyObject.error())
|
|
{
|
|
ERROR_LOG(m_logger) << "Got onExerciseModifyReply error: " << replyObject();
|
|
failExit();
|
|
return;
|
|
}
|
|
INFO_LOG(m_logger) << "Got modifyRequest with id " << replyObject.id()
|
|
<< " and errorString " << replyObject.translated();
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
}
|
|
|
|
////--------------------------------------------------------------------------
|
|
//void ExmTests::onExerciseChangeStateReply(const Core::FunctionReplyObject &replyObject)
|
|
//{
|
|
// if (replyObject.error())
|
|
// {
|
|
// ERROR_LOG(m_logger) << "Got onExerciseChangeStateReply error: " << replyObject();
|
|
// failExit();
|
|
// return;
|
|
// }
|
|
// INFO_LOG(m_logger) << "Got changeStateRequest with id " << replyObject.id()
|
|
// << " and errorString " << replyObject.translated();
|
|
// QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
//}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void ExmTests::onExerciseRemoveReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
if (replyObject.error())
|
|
{
|
|
ERROR_LOG(m_logger) << "Got onExerciseRemoveReply error: " << replyObject();
|
|
failExit();
|
|
return;
|
|
}
|
|
INFO_LOG(m_logger) << "Got removeReply with id " << replyObject.id()
|
|
<< " and errorString " << replyObject.translated();
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void ExmTests::onExercisePhaseCreateReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
if (replyObject.error())
|
|
{
|
|
ERROR_LOG(m_logger) << "Got onExercisePhaseCreateReply error: " << replyObject();
|
|
failExit();
|
|
return;
|
|
}
|
|
INFO_LOG(m_logger) << "Got createExercisePhaseReply with id " << replyObject.id()
|
|
<< " and errorString " << replyObject.translated();
|
|
|
|
m_phaseId = replyObject.id();
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void ExmTests::onExercisePhaseModifyReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
if (replyObject.error())
|
|
{
|
|
ERROR_LOG(m_logger) << "Got onExercisePhaseModifyReply error: " << replyObject();
|
|
failExit();
|
|
return;
|
|
}
|
|
INFO_LOG(m_logger) << "Got modifyExercisePhaseReply with id " << replyObject.id()
|
|
<< " and errorString " << replyObject.translated();
|
|
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void ExmTests::onExercisePhaseRemoveReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
if (replyObject.error())
|
|
{
|
|
ERROR_LOG(m_logger) << "Got onExercisePhaseRemoveReply error: " << replyObject();
|
|
failExit();
|
|
return;
|
|
}
|
|
INFO_LOG(m_logger) << "Got removeExercisePhaseReply with id " << replyObject.id()
|
|
<< " and errorString " << replyObject.translated();
|
|
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void ExmTests::onTrainingAreaModifyReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
if (replyObject.error())
|
|
{
|
|
ERROR_LOG(m_logger) << "Got onTrainingAreaModifyReply error: " << replyObject();
|
|
failExit();
|
|
return;
|
|
}
|
|
INFO_LOG(m_logger) << "Got createReply with id " << replyObject.id()
|
|
<< " and errorString " << replyObject.translated();
|
|
m_trainingAreaId = replyObject.id();
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------
|
|
void ExmTests::failExit()
|
|
{
|
|
ERROR_LOG(m_logger) << "FAIL EXIT !";
|
|
m_bTestsSuccessful = false;
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
}
|
|
|
|
} // end namespace
|
|
|
|
// ------------------------------------------------------------------
|
|
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")
|
|
} );
|
|
|
|
addOption( { QStringList() << QLatin1String("p") << QLatin1String("phaseId")
|
|
, QLatin1String("PhaseId.")
|
|
, 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 phaseId() const { return isSet(QLatin1String("p")) ? value(QLatin1String("p")).toInt() : -1; }
|
|
};
|
|
|
|
// ------------------------------------------------------------------
|
|
int main(int argc, char **argv)
|
|
{
|
|
NGLCoreApplication app(argc, argv);
|
|
|
|
app.createLogger("EXM", 0 );
|
|
|
|
int iRet = -1;
|
|
CmdLineParser options;
|
|
if (!options.init())
|
|
return -1;
|
|
|
|
std::unique_ptr<ExerciseManagement::ExmTests> ExmTests(new ExerciseManagement::ExmTests);
|
|
|
|
if(!ExmTests->init(options.domainId(), options.exerciseId(), options.testId(), options.trainingAreaId(), options.phaseId()))
|
|
return iRet;
|
|
|
|
QTimer::singleShot(0, ExmTests.get(), &ExerciseManagement::ExmTests::startTest);
|
|
|
|
STARTUP_LOG(app.baseLogger());
|
|
fprintf(stdout, "%s\n", app.baseLogger().getLoggerName().data());
|
|
|
|
app.exec();
|
|
|
|
iRet = ExmTests->testsSuccessful() ? 0 : 1;
|
|
fprintf(stderr, "%d\n", iRet);
|
|
|
|
DEBUG_LOG(app.baseLogger()) << "** TEST result = " << iRet;
|
|
|
|
SHUTDOWN_LOG(app.baseLogger());
|
|
|
|
return iRet;
|
|
}
|