Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Services/AlarmManagement/ModuleTests/alm_tests.cpp
T
torstenandCopilot b774f4035c Qt6 Migration: DDS-Stubs, Logger-Fixes, Export-Header Korrekturen
- NGL_ADD_LIBRARY2: 87 CMakeLists.txt konvertiert für Export-Header Generierung
- 44 Export-Header Include-Pfade korrigiert (_export.h)
- 81 DDS-Stub-Header generiert (*_dtc.h, *_fts.h, *_dts.h, *_ftc.h)
- INGLLogger: Duplikat gelöscht, m_logger Member entfernt, variadische Makros
- Q_FUNC_INFO Redefinition behoben (Qt6 definiert bereits)
- FATAL_LOG Makro hinzugefügt
- InfrastructureManagement DDS-Stubs (ism.hpp, ism_enums.hpp, ism_ftc.h)
- FilterManagement DDS-Stubs (flt_ftc.h, flt_dts.h)
- AreaEffectSimulation DDS-Stubs (aes.hpp, aes_enums.hpp)
- SymbolAppearance Klasse vollständig definiert mit content() Methode
- BuildingComponentFilter Klasse definiert mit Copy-Konstruktor
- Ftc Factory: nullptr Return (abstract class)
- AesFilter Klasse in aes.hpp hinzugefügt
- Dtc Klasse in ppm.hpp mit participantChanged Signal
- AesType Enum: alle 15 At* Werte definiert
- AesEffectState_def: EsReceived hinzugefügt
- DataModification Enum: eAdded/eModified/eRemoved
- function_reply_object.h → core_types.h Include-Pfad (72 Dateien)
- Enum-Class-Streaming Template-Operator in INGLLogger.h
- ism_mounting_point.h: QImage → QtGui/QImage, QGuiApplication/QScreen
- ism_data_plugin_interface.h: QSet Include, Include-Reihenfolge
- QRegExp → QRegularExpression in tpm_js_parser.cpp
- .underlying() Aufrufe zu direktem Enum-Vergleich korrigiert
- Include-Pfade: aes.hpp in symbol_appearance_settings_impl.h und aes_display_filter_impl.h

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-19 06:06:24 +02:00

335 lines
9.8 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_participantIndex(0)
{}
// ------------------------------------------------------------------
AlmTests::~AlmTests()
{}
// ------------------------------------------------------------------
bool AlmTests::init(int domainId, int testId, int operatorId)
{
INFO_LOG() << "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() << "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() << "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() << "Error requesting create data";
failExit();
}
} // tryConfigureAlarms
// ------------------------------------------------------------------
void AlmTests::tryCreateParticipant()
{
INFO_LOG() << "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() << "Publishing Participant";
if (!m_dtsPpm->publish(participant))
{
ERROR_LOG() << "Error publish Participant";
failExit();
}
m_participantIndex++;
} // tryCreateParticipant
// ------------------------------------------------------------------
void AlmTests::tryConfigureAlarmsList()
{
INFO_LOG() << "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() << "Error requesting create data";
failExit();
}
} // tryConfigureAlarmsList
// ------------------------------------------------------------------
void AlmTests::trySendEvent()
{
INFO_LOG() << "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() << "Publishing EEM Event";
if (!m_dtsEem->publish(pe))
{
ERROR_LOG() << "Error publish EEM Event";
failExit();
}
}
// ------------------------------------------------------------------
void AlmTests::onConfigureAlarmsReply(const Core::FunctionReplyObject &replyObject)
{
INFO_LOG() << "onConfigureAlarmsReply, error = " << replyObject.error();
if (replyObject.error())
{
ERROR_LOG() << "Error ConfigureAlarms - aborting";
failExit();
}
} // onConfigureAlarmsReply
// ------------------------------------------------------------------
void AlmTests::checkAlarm()
{
INFO_LOG() << "checkAlarm";
m_dtcAlm->waitForHistoricalDataNotification();
qint32 id = 0;
AlarmManagement::Notification notification = m_dtcAlm->notification(id);
INFO_LOG() << "Recived AlarmManagement::Notification: " << notification
<< " testId: " << m_testId;
switch (m_testId)
{
case 1:
case 2:
case 3:
INFO_LOG() << "ExitSuccess";
ExitSuccess();
break;
default:
// nothing
INFO_LOG() << "failExit";
failExit();
break;
}
}
// ------------------------------------------------------------------
void AlmTests::failExit()
{
m_bTestsSuccessful = false;
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
} // failExit
// ------------------------------------------------------------------
void AlmTests::ExitSuccess()
{
DEBUG_LOG() << "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