Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,62 @@
|
||||
#
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
#
|
||||
|
||||
IF(BUILD_TESTING AND TARGET svcExmClient)
|
||||
SET(SRCS_TEST
|
||||
exm_tests.cpp
|
||||
exm_tests.h
|
||||
)
|
||||
# Testing DataTopic and FunctionTopic Functionality (DTC+FTC)
|
||||
ADD_EXECUTABLE(exmTests ${SRCS_TEST})
|
||||
TARGET_LINK_LIBRARIES(exmTests
|
||||
Qt5::Core
|
||||
Qt5::Test
|
||||
RTI::nddscpp2
|
||||
svcExmClient
|
||||
svcAsmClient
|
||||
LtsCommandLineParser
|
||||
ddsconnector
|
||||
nglcoreapplication
|
||||
)
|
||||
IF(NOT BUILD_RPM)
|
||||
NGL_INSTALL(AAR SV TARGETS exmTests DESTINATION bin/test)
|
||||
NGL_INSTALL(AAR SV FILES ../log4cxx_exm.props DESTINATION bin/test)
|
||||
ENDIF()
|
||||
SET(STMT_TEST
|
||||
exm_statemachine_test.cpp
|
||||
exm_statemachine_test.h
|
||||
../dds_handler.cpp
|
||||
../dds_handler.h
|
||||
../exercise_state_base.cpp
|
||||
../exercise_state_base.h
|
||||
../exercise_state_manager.cpp
|
||||
../exercise_state_manager.h
|
||||
../exercise_state_machine.cpp
|
||||
../exercise_state_machine.h
|
||||
../object_exercise.cpp
|
||||
../object_exercise.h
|
||||
../settings.cpp
|
||||
../settings.h
|
||||
)
|
||||
ADD_EXECUTABLE(exmStateMachineTest ${STMT_TEST})
|
||||
TARGET_COMPILE_DEFINITIONS(exmStateMachineTest PUBLIC EXM_OBJECT_EXERCISE_NO_HANDLER)
|
||||
TARGET_LINK_LIBRARIES(exmStateMachineTest
|
||||
dbAdminCopyExercise
|
||||
ddsconnector
|
||||
nglcoreapplication
|
||||
NGLLogger
|
||||
ngltools
|
||||
Qt5::Core
|
||||
Qt5::Test
|
||||
svcCoreClient
|
||||
svcExmCommon
|
||||
svcExmServer
|
||||
svcScmClient
|
||||
svcPpmClient
|
||||
svcAvmClient
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
/**
|
||||
* Unittest for testing the statemachine for aes objects
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "exm_statemachine_test.h"
|
||||
|
||||
|
||||
// Generated
|
||||
#include <ExerciseManagement/exm_enums.hpp>
|
||||
#include <ExerciseManagement/exm_db.h>
|
||||
|
||||
#include <DBAdministration/exercise_table_generator.h>
|
||||
#include <ExerciseManagement/exercise_state_machine.h>
|
||||
#include <ExerciseManagement/dds_handler.h>
|
||||
#include <ExerciseManagement/object_exercise.h>
|
||||
#include <ExerciseManagement/settings.h>
|
||||
#include <ExerciseManagement/logger.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <ngltools/ngltools_filesystem.h>
|
||||
|
||||
using namespace ExerciseManagement;
|
||||
|
||||
namespace QTest
|
||||
{
|
||||
template<>
|
||||
char *toString(const ExerciseState &s) { std::ostringstream str; str << s; return strdup(str.str().c_str()); }
|
||||
}
|
||||
|
||||
StateMachineTest::StateMachineTest()
|
||||
: m_exmObject(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
StateMachineTest::~StateMachineTest()
|
||||
{
|
||||
delete m_exmObject;
|
||||
}
|
||||
|
||||
void StateMachineTest::initTestCase()
|
||||
{
|
||||
NGL::INGLLogger &logger = getLogger("StateMachineTest");
|
||||
m_dbHandler = std::make_shared<DbHandler>();
|
||||
QVERIFY2(m_dbHandler.get(), "Reset of dbHandler failed");
|
||||
|
||||
bool bOk = m_dbHandler->init(0, Settings::settings());
|
||||
// Initialize database
|
||||
QVERIFY2(bOk, "Init dbHandler/DbInitialisation failed");
|
||||
|
||||
// initialize DDS
|
||||
int domainId = 0;
|
||||
m_ddsHandler = std::make_shared<DdsHandler>(domainId);
|
||||
QVERIFY2(m_ddsHandler.get(), "Reset of ddsInterface failed");
|
||||
QVERIFY2(m_ddsHandler->init(), "Ininitialisation of ddsInterface failed");
|
||||
|
||||
// Initialise ExerciseTableGenerator
|
||||
const QString xmlPath = NGL::directory(NGL::FileType::ConfigFile, QLatin1String("xml"));
|
||||
m_exTblGen = std::make_shared<DBAdministration::ExerciseTableGenerator>(logger, xmlPath);
|
||||
QVERIFY2(m_exTblGen, "new object creation of ExerciseTableGenerator failed");
|
||||
QVERIFY2(m_exTblGen->init(m_dbHandler->db()->database(), m_dbHandler->db()->schemaName(), false), "Initialisation of ExerciseTableGenerator failed");
|
||||
|
||||
HandlerExercise *exHandler = nullptr;
|
||||
m_exmObject = new ObjectExercise(m_ddsHandler, m_dbHandler->db(), m_exTblGen, exHandler);
|
||||
QVERIFY2(m_exmObject, "Initialisation of exerciseObject failed");
|
||||
|
||||
#if 1
|
||||
Database::ExmExercise data;
|
||||
|
||||
data.name = QLatin1String("Test Statemachine");
|
||||
data.trainingAreaId = 6; // Bremen
|
||||
data.beginTime = QDateTime::currentDateTimeUtc();
|
||||
data.endTime = data.beginTime.addDays(2);
|
||||
|
||||
#else
|
||||
QVector<Database::ExmExercise> dataVec;
|
||||
// read all exercises from database
|
||||
QVERIFY2(m_dbHandler->db()->select(dataVec), "Error retrieving exercises from db");
|
||||
|
||||
DatabaseInterface::ExmExercise data;
|
||||
if (dataVec.isEmpty() )
|
||||
{
|
||||
data.name = QLatin1String("Test Statemachine");
|
||||
data.beginTime = QDateTime::currentDateTimeUtc().toMSecsSinceEpoch();
|
||||
data.endTime = QDateTime::currentDateTimeUtc().toMSecsSinceEpoch() + 2000;
|
||||
data.created = QDateTime::currentDateTimeUtc();
|
||||
}
|
||||
else
|
||||
{
|
||||
data = dataVec.first();
|
||||
qDebug() << "First existing exerciseId: " << data.id << ", name = " << data.name;
|
||||
}
|
||||
#endif
|
||||
|
||||
Core::FunctionReplyObject ret = m_exmObject->createObject(data);
|
||||
QVERIFY2(!ret.error(), "Creation of new exerciseObject failed");
|
||||
QTest::qWait(100);
|
||||
}
|
||||
|
||||
void StateMachineTest::staticTests()
|
||||
{
|
||||
// newly created, nothing set -> Status should be ExerciseState::Created
|
||||
QCOMPARE(m_exmObject->exerciseState().underlying(), ExerciseState::Created);
|
||||
}
|
||||
|
||||
void StateMachineTest::dynamicTests()
|
||||
{
|
||||
QSignalSpy spy(m_exmObject->getStateMachine(), &ExerciseStateMachine::exerciseStateChanged);
|
||||
|
||||
// Switch to STARTED
|
||||
m_exmObject->switchToState(ExerciseState::Started, 0, 0);
|
||||
|
||||
QTRY_COMPARE(m_exmObject->exerciseState().underlying(), ExerciseState::Started);
|
||||
QCOMPARE(spy.count(), 1); // Started
|
||||
spy.clear();
|
||||
|
||||
// => PAUSED
|
||||
m_exmObject->switchToState(ExerciseState::Paused, 99, 10);
|
||||
|
||||
QTRY_COMPARE(m_exmObject->exerciseState().underlying(), ExerciseState::Paused);
|
||||
QCOMPARE(spy.count(), 1); // PAUSED
|
||||
spy.clear();
|
||||
|
||||
// Try to (re)start
|
||||
m_exmObject->switchToState(ExerciseState::Started, 99, 10);
|
||||
|
||||
QTRY_COMPARE(m_exmObject->exerciseState().underlying(), ExerciseState::Started);
|
||||
QCOMPARE(spy.count(), 1); // Started (Resumed)
|
||||
spy.clear();
|
||||
|
||||
// => Stopped
|
||||
m_exmObject->switchToState(ExerciseState::Stopped, 99, 10);
|
||||
|
||||
QTRY_COMPARE(m_exmObject->exerciseState().underlying(), ExerciseState::Stopped);
|
||||
QCOMPARE(spy.count(), 1); // Stopped
|
||||
spy.clear();
|
||||
|
||||
// => Terminated
|
||||
m_exmObject->switchToState(ExerciseState::Terminated, 99, 10);
|
||||
|
||||
QTRY_COMPARE(m_exmObject->exerciseState().underlying(), ExerciseState::Terminated);
|
||||
QCOMPARE(spy.count(), 1); // Terminated
|
||||
spy.clear();
|
||||
}
|
||||
|
||||
|
||||
void StateMachineTest::cleanupTestCase()
|
||||
{
|
||||
delete m_exmObject;
|
||||
m_exmObject = nullptr;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
|
||||
app.createLogger("EXM", 0);
|
||||
|
||||
STARTUP_LOG(app.baseLogger());
|
||||
|
||||
ExerciseManagement::StateMachineTest *test = new ExerciseManagement::StateMachineTest;
|
||||
int retCode = QTest::qExec(test, 0, argv);
|
||||
delete test;
|
||||
SHUTDOWN_LOG(app.baseLogger());
|
||||
|
||||
return retCode;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Unittest for testing the statemachine for aes objects
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <memory>
|
||||
#include <ExerciseManagement/exm_db.h>
|
||||
#include <ngldb/db_service_handler.h>
|
||||
#include <DBAdministration/exercise_table_generator.h>
|
||||
|
||||
namespace ExerciseManagement
|
||||
{
|
||||
using DbHandler = NGLDB::DbServiceHandler<DatabaseInterface>;
|
||||
class ObjectExercise;
|
||||
class DdsHandler;
|
||||
|
||||
class StateMachineTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
StateMachineTest();
|
||||
~StateMachineTest();
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
void staticTests();
|
||||
void dynamicTests();
|
||||
void cleanupTestCase();
|
||||
|
||||
private:
|
||||
std::shared_ptr<DdsHandler> m_ddsHandler;
|
||||
std::shared_ptr<DbHandler> m_dbHandler;
|
||||
std::shared_ptr<DBAdministration::ExerciseTableGenerator> m_exTblGen;
|
||||
|
||||
ObjectExercise *m_exmObject;
|
||||
|
||||
};
|
||||
} // namespace ExerciseManagement
|
||||
+550
@@ -0,0 +1,550 @@
|
||||
/**
|
||||
* 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 <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;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
Parameters, Comment
|
||||
-t 4,1. Create training area id 1
|
||||
-t 1 -a 1,2. Create exercise with training area 1
|
||||
-t 2 -e 1 -p 1,3. Modify Exercise id 1 with phase 1
|
||||
-t 3 -e 1,4. Remove exercise id 1
|
||||
-t 1 -1 1,5. Create new exercise
|
||||
-t 10,6. Get all exercises
|
||||
-t 11 -e 42,7. Get exercise 42
|
||||
-t 20 -e 42,8. Start exercise 42
|
||||
-t 30 -e 42,9. Create exercise phase 3 for ex 42
|
||||
-t 31 -e 42 -p 3,10. Modify exercise phase 3
|
||||
-t 32 -e 42 -p 3,11. Remove exercise phase 3
|
||||
|
+93
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
*
|
||||
* EXM Function Topic test executable
|
||||
*
|
||||
* ModuleTests for create/modify/remove exercise
|
||||
* ---------------------------------------------------
|
||||
* Client FTC is implemented
|
||||
*
|
||||
* => (!) Preconditon:
|
||||
* - Service sExeMgmt running
|
||||
*
|
||||
* -------------------------------------------------
|
||||
*
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*
|
||||
* Created by Hanna E. Rathje, SLSE, 2015-09-10
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ExerciseManagement/exm_ftc.h>
|
||||
#include <ExerciseManagement/exm_ftc_types.h>
|
||||
#include <AssetManagement/asm_ftc.h>
|
||||
#include <AssetManagement/asm_ftc_types.h>
|
||||
#include <ExerciseManagement/exm_dtc.h>
|
||||
#include <ExerciseManagement/exm_dtc_types.h>
|
||||
#include <ExerciseManagement/logger.h>
|
||||
#include <DDS/DDSConnector/dds_connector.h>
|
||||
|
||||
//--------------------------------------------------------------------------------------------
|
||||
namespace ExerciseManagement
|
||||
{
|
||||
class ExmTests : public QObject
|
||||
, protected ExerciseManagement::Interface::Ftc::ExerciseCreateReplyHandler
|
||||
, protected ExerciseManagement::Interface::Ftc::ExerciseModifyReplyHandler
|
||||
// , protected ExerciseManagement::Interface::Ftc::ExerciseChangeStateReplyHandler
|
||||
, protected ExerciseManagement::Interface::Ftc::ExerciseRemoveReplyHandler
|
||||
, protected ExerciseManagement::Interface::Ftc::ExercisePhaseCreateReplyHandler
|
||||
, protected ExerciseManagement::Interface::Ftc::ExercisePhaseModifyReplyHandler
|
||||
, protected ExerciseManagement::Interface::Ftc::ExercisePhaseRemoveReplyHandler
|
||||
, protected AssetManagement::Interface::Ftc::TrainingAreaModifyReplyHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ExmTests(QObject *parent = nullptr);
|
||||
~ExmTests();
|
||||
|
||||
bool init(int domainId, int exerciseId, int testId, int trainingAreaId, int phaseId);
|
||||
bool testsSuccessful() const { return m_bTestsSuccessful; }
|
||||
|
||||
public Q_SLOTS:
|
||||
void startTest();
|
||||
protected Q_SLOTS:
|
||||
void tryCreate();
|
||||
void tryCreateTrainingArea();
|
||||
void tryCreateExercisePhase();
|
||||
void tryModify();
|
||||
void tryModifyExercisePhase();
|
||||
void tryDelete();
|
||||
void tryDeleteExercisePhase();
|
||||
void tryStartExercise();
|
||||
void tryGetAllExercises();
|
||||
void tryGetExercise();
|
||||
void onExerciseChanged(const ExerciseManagement::Exercise &data, DataModification modType);
|
||||
protected:
|
||||
void onExerciseCreateReply(const Core::FunctionReplyObject &replyObject) override final;
|
||||
void onExerciseModifyReply(const Core::FunctionReplyObject &replyObject) override final;
|
||||
// void onExerciseChangeStateReply(const Core::FunctionReplyObject &replyObject) override final;
|
||||
void onExerciseRemoveReply(const Core::FunctionReplyObject &replyObject) override final;
|
||||
void onExercisePhaseCreateReply(const Core::FunctionReplyObject &replyObject) override final;
|
||||
void onExercisePhaseModifyReply(const Core::FunctionReplyObject &replyObject) override final;
|
||||
void onExercisePhaseRemoveReply(const Core::FunctionReplyObject &replyObject) override final;
|
||||
void onTrainingAreaModifyReply(const Core::FunctionReplyObject &replyObject) override final;
|
||||
void failExit();
|
||||
|
||||
private:
|
||||
std::shared_ptr<DDSConnector::DdsConnector> m_ddsConnector;
|
||||
std::shared_ptr<ExerciseManagement::Interface::Ftc> m_ftc;
|
||||
std::shared_ptr<AssetManagement::Interface::Ftc> m_ftc_asm;
|
||||
std::shared_ptr<ExerciseManagement::Interface::Dtc> m_dtc;
|
||||
|
||||
qint32 m_exerciseId;
|
||||
qint32 m_trainingAreaId;
|
||||
qint32 m_phaseId;
|
||||
int m_testId;
|
||||
bool m_bTestsSuccessful;
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
|
||||
} // namespace ExerciseManagement
|
||||
Reference in new issue
Block a user