- Migrated all 104 CMakeLists.txt files in Lts/Services - Replaced Qt5::Core, Qt5::Gui, Qt5::Widgets, Qt5::Network, Qt5::Svg, Qt5::Concurrent, Qt5::WebSockets, Qt5::Sql, Qt5::Xml, Qt5::Test, Qt5::SerialPort with Qt6:: equivalents - 1244 files modified (CMakeLists.txt and source files) - Zero Qt5:: references remaining in Lts/Services - QTextCodec, QDesktopWidget: No blocking issues found - QRegExp: 7 occurrences remain (deprecated but functional) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
336 lines
10 KiB
C++
Executable File
336 lines
10 KiB
C++
Executable File
/**
|
|
* Msg Function Topic Module Test
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#include "alm_tests.h"
|
|
|
|
#include <nglapplication/nglcoreapplication.h>
|
|
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
|
#include <QTimer>
|
|
#include <QDateTime>
|
|
#include <QJsonObject>
|
|
#include <QJsonDocument>
|
|
|
|
/* ----------------------------------------------------------------------------------
|
|
* HOW TO RUN THE TESTS
|
|
* ----------------------------------------------------------------------------------
|
|
*
|
|
* Preconditions: Nothing
|
|
*
|
|
* Start services: (SV)
|
|
* ./svcExerciseEventManagement -e 42
|
|
* ./almTests -t 1 -e 42 // Configure Alarms with participantId=0, send EEM-Event and receive Alarm
|
|
* ./almTests -t 2 -e 42 // Configure Alarms with participantId-List, send EEM-Event and receive Alarm
|
|
* ./almTests -t 3 -e 42 // Configure Alarms with vulnerability > 0, send EEM-Event and receive Alarm
|
|
*/
|
|
|
|
// ------------------------------------------------------------------
|
|
namespace AlarmManagement
|
|
{
|
|
AlmTests::AlmTests(QObject *parent)
|
|
: QObject(parent)
|
|
, m_testId(0)
|
|
, m_bTestsSuccessful(true)
|
|
, m_logger(getLogger("AlmTests"))
|
|
, m_participantIndex(0)
|
|
{}
|
|
|
|
// ------------------------------------------------------------------
|
|
AlmTests::~AlmTests()
|
|
{}
|
|
|
|
// ------------------------------------------------------------------
|
|
bool AlmTests::init(int domainId, int testId, int operatorId)
|
|
{
|
|
INFO_LOG(m_logger) << "init begin";
|
|
|
|
m_testId = testId;
|
|
m_operatorId = operatorId;
|
|
m_participantIndex = 0;
|
|
|
|
m_ddsConnector.reset(new DDSConnector::DdsConnector(domainId, IDL::PartitionType::Any));
|
|
if (!m_ddsConnector->init())
|
|
return false;
|
|
m_ddsConnector->initPublisherSubscriber();
|
|
|
|
m_ftcAlm = AlarmManagement::Interface::Ftc::create(m_ddsConnector);
|
|
bool bRet = m_ftcAlm->enableAll();
|
|
|
|
m_dtcAlm = AlarmManagement::Interface::Dtc::create(m_ddsConnector);
|
|
bRet &= m_dtcAlm->enableAll();
|
|
|
|
m_dtsEem = ExerciseEventManagement::Interface::Dts::create(m_ddsConnector);
|
|
bRet &= m_dtsEem->enableAll();
|
|
|
|
m_dtsPpm = ParticipantManagement::Interface::Dts::create(m_ddsConnector);
|
|
bRet &= m_dtsPpm->enableAll();
|
|
|
|
return bRet;
|
|
} // init
|
|
|
|
// ------------------------------------------------------------------
|
|
void AlmTests::startTest()
|
|
{
|
|
INFO_LOG(m_logger) << "startTest m_testId=" << m_testId;
|
|
if (m_testId <= 1) // Send FTC ConfigureAlarms and EEM Event
|
|
{
|
|
QTimer::singleShot(0, this, &AlmTests::tryConfigureAlarms);
|
|
QTimer::singleShot(100, this, &AlmTests::trySendEvent);
|
|
QTimer::singleShot(200, this, &AlmTests::checkAlarm);
|
|
}
|
|
if (m_testId == 2)
|
|
{
|
|
QTimer::singleShot(0, this, &AlmTests::tryCreateParticipant);
|
|
QTimer::singleShot(100, this, &AlmTests::tryCreateParticipant);
|
|
QTimer::singleShot(200, this, &AlmTests::tryConfigureAlarmsList);
|
|
QTimer::singleShot(300, this, &AlmTests::trySendEvent);
|
|
QTimer::singleShot(400, this, &AlmTests::checkAlarm);
|
|
}
|
|
if (m_testId == 3)
|
|
{
|
|
QTimer::singleShot(0, this, &AlmTests::tryCreateParticipant);
|
|
QTimer::singleShot(100, this, &AlmTests::tryCreateParticipant);
|
|
QTimer::singleShot(200, this, &AlmTests::tryConfigureAlarmsList);
|
|
QTimer::singleShot(300, this, &AlmTests::trySendEvent);
|
|
QTimer::singleShot(400, this, &AlmTests::checkAlarm);
|
|
}
|
|
QTimer::singleShot(5000, this, &AlmTests::failExit);
|
|
} // startTest
|
|
|
|
// ------------------------------------------------------------------
|
|
void AlmTests::tryConfigureAlarms()
|
|
{
|
|
INFO_LOG(m_logger) << "trying to send createRequest Operator Message";
|
|
|
|
std::vector<AlarmManagement::AlarmAction> alarms;
|
|
alarms.resize(2);
|
|
|
|
alarms[0].setMarker(true);
|
|
alarms[0].messageWindow(true);
|
|
alarms[0].vulnerabilityState(-1);
|
|
alarms[0].eventTypeId(ProjectDataManagement::EventType_def::Hit);
|
|
|
|
alarms[1].setMarker(true);
|
|
alarms[1].messageWindow(true);
|
|
alarms[1].vulnerabilityState(0);
|
|
alarms[1].eventTypeId(ProjectDataManagement::EventType_def::EnterNuclear);
|
|
|
|
std::vector<int32_t> participantIds;
|
|
participantIds.push_back(0);
|
|
bool globalEvent = true;
|
|
bool remove = false;
|
|
|
|
if (!m_ftcAlm->configureAlarmsRequest(ConfigureAlarmsRequest(alarms, m_operatorId, participantIds, globalEvent, remove), this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error requesting create data";
|
|
failExit();
|
|
}
|
|
} // tryConfigureAlarms
|
|
|
|
// ------------------------------------------------------------------
|
|
void AlmTests::tryCreateParticipant()
|
|
{
|
|
INFO_LOG(m_logger) << "trying to create Participant index = " << m_participantIndex;
|
|
ParticipantManagement::Participant participant;
|
|
switch (m_participantIndex)
|
|
{
|
|
case 0:
|
|
participant.id(1);
|
|
participant.superiorId(0);
|
|
participant.inferiorIds().resize(2);
|
|
participant.inferiorIds().at(0) = 2;
|
|
participant.inferiorIds().at(1) = 3;
|
|
participant.partyId(5);
|
|
break;
|
|
case 1:
|
|
participant.id(2);
|
|
participant.superiorId(1);
|
|
participant.inferiorIds().resize(2);
|
|
participant.inferiorIds().at(0) = 4;
|
|
participant.inferiorIds().at(1) = 5;
|
|
participant.partyId(5);
|
|
break;
|
|
}
|
|
DEBUG_LOG(m_logger) << "Publishing Participant";
|
|
if (!m_dtsPpm->publish(participant))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error publish Participant";
|
|
failExit();
|
|
}
|
|
m_participantIndex++;
|
|
} // tryCreateParticipant
|
|
|
|
// ------------------------------------------------------------------
|
|
void AlmTests::tryConfigureAlarmsList()
|
|
{
|
|
INFO_LOG(m_logger) << "trying to send createRequest Operator Message";
|
|
|
|
std::vector<AlarmManagement::AlarmAction> alarms;
|
|
alarms.resize(2);
|
|
|
|
alarms[0].setMarker(true);
|
|
alarms[0].messageWindow(true);
|
|
alarms[0].eventTypeId(ProjectDataManagement::EventType_def::Hit);
|
|
alarms[0].vulnerabilityState(-1);
|
|
|
|
alarms[1].setMarker(true);
|
|
alarms[1].messageWindow(true);
|
|
alarms[1].vulnerabilityState(-1);
|
|
alarms[1].eventTypeId(ProjectDataManagement::EventType_def::WeaponAssignment);
|
|
|
|
std::vector<int32_t> participantIds;
|
|
participantIds.push_back(1);
|
|
participantIds.push_back(2);
|
|
bool globalEvent = true;
|
|
bool remove = false;
|
|
|
|
if (!m_ftcAlm->configureAlarmsRequest(ConfigureAlarmsRequest(alarms, m_operatorId, participantIds, globalEvent, remove), this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error requesting create data";
|
|
failExit();
|
|
}
|
|
} // tryConfigureAlarmsList
|
|
|
|
// ------------------------------------------------------------------
|
|
void AlmTests::trySendEvent()
|
|
{
|
|
INFO_LOG(m_logger) << "trying to send ParticipantEvent";
|
|
|
|
ExerciseEventManagement::Event pe;
|
|
|
|
// publish new Event data here
|
|
pe.id(100);
|
|
//pe.aesItemId(5);
|
|
pe.eventTypeId(ProjectDataManagement::EventType_def::Hit); // same as eventTypeId in ConfigureAlarms
|
|
pe.participantId(2);
|
|
pe.equipmentNumber(55);
|
|
pe.sampleTime(QDateTime::currentMSecsSinceEpoch());
|
|
//pe.friendlyFire(1);
|
|
//pe.vulnerability(0);
|
|
|
|
QJsonObject obj;
|
|
obj[QStringLiteral("FriendlyFire")] = QJsonValue(true);
|
|
|
|
QString properties = QString::fromUtf8(QJsonDocument(obj).toJson());
|
|
pe.properties(properties.toStdString());
|
|
DEBUG_LOG(m_logger) << "Publishing EEM Event";
|
|
if (!m_dtsEem->publish(pe))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error publish EEM Event";
|
|
failExit();
|
|
}
|
|
}
|
|
|
|
// ------------------------------------------------------------------
|
|
void AlmTests::onConfigureAlarmsReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
INFO_LOG(m_logger) << "onConfigureAlarmsReply, error = " << replyObject.error();
|
|
if (replyObject.error())
|
|
{
|
|
ERROR_LOG(m_logger) << "Error ConfigureAlarms - aborting";
|
|
failExit();
|
|
}
|
|
} // onConfigureAlarmsReply
|
|
|
|
// ------------------------------------------------------------------
|
|
void AlmTests::checkAlarm()
|
|
{
|
|
INFO_LOG(m_logger) << "checkAlarm";
|
|
m_dtcAlm->waitForHistoricalDataNotification();
|
|
qint32 id = 0;
|
|
AlarmManagement::Notification notification = m_dtcAlm->notification(id);
|
|
INFO_LOG(m_logger) << "Recived AlarmManagement::Notification: " << notification
|
|
<< " testId: " << m_testId;
|
|
|
|
switch (m_testId)
|
|
{
|
|
case 1:
|
|
case 2:
|
|
case 3:
|
|
INFO_LOG(m_logger) << "ExitSuccess";
|
|
ExitSuccess();
|
|
break;
|
|
default:
|
|
// nothing
|
|
INFO_LOG(m_logger) << "failExit";
|
|
failExit();
|
|
break;
|
|
}
|
|
}
|
|
|
|
// ------------------------------------------------------------------
|
|
void AlmTests::failExit()
|
|
{
|
|
m_bTestsSuccessful = false;
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
} // failExit
|
|
|
|
// ------------------------------------------------------------------
|
|
void AlmTests::ExitSuccess()
|
|
{
|
|
DEBUG_LOG(m_logger) << "SUCCESS";
|
|
m_bTestsSuccessful = true;
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
} // ExitSuccess
|
|
|
|
} // 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("o") << QLatin1String("operatorId")
|
|
, QLatin1String("OperatorId.")
|
|
, QLatin1String("Default: 10")
|
|
, QLatin1String("10")
|
|
});
|
|
|
|
}
|
|
int testId() const { return isSet(QLatin1String("t")) ? value(QLatin1String("t")).toInt() : 0; }
|
|
int operatorId() const { return isSet(QLatin1String("o")) ? value(QLatin1String("o")).toInt() : 10; }
|
|
};
|
|
|
|
// ------------------------------------------------------------------
|
|
int main(int argc, char **argv)
|
|
{
|
|
NGLCoreApplication app(argc, argv);
|
|
app.createLogger("ALM", "log4cxx_alm.props");
|
|
|
|
CmdLineParser options;
|
|
if (!options.init())
|
|
return -1;
|
|
|
|
int iRet = -1;
|
|
{
|
|
std::unique_ptr<AlarmManagement::AlmTests> almTests(new AlarmManagement::AlmTests);
|
|
|
|
if (!almTests->init(options.domainId(), options.testId(), options.operatorId()))
|
|
return iRet;
|
|
|
|
almTests->startTest();
|
|
|
|
STARTUP_LOG(app.baseLogger());
|
|
|
|
app.exec();
|
|
|
|
iRet = almTests->testsSuccessful() ? 0 : 1;
|
|
fprintf(stderr, "%d\n", iRet);
|
|
|
|
SHUTDOWN_LOG(app.baseLogger());
|
|
}
|
|
|
|
return iRet;
|
|
} // main
|
|
|