Initial commit

This commit is contained in:
torsten committed 2026-08-13 18:33:10 +02:00
commit b7d90b9afe
16245 files changed
+3396666

No files matched your search

@@ -0,0 +1,323 @@
/**
* AES Function Topic Client test executable
* $Id$
* $HeadURL$
* $Author$
*/
#include "aes_test_booby_trap.h"
#include <QCoreApplication>
#include <QTest>
#include <QTimer>
namespace AreaEffectSimulation
{
// must be in pdm.pdm_charge_type
static const int s_ChargeTypeId1 = 251;
static const int s_ChargeTypeId2 = 252;
TestBoobyTrap::TestBoobyTrap(QObject *parent)
: TestBase("Test.BoobyTrap", parent)
{}
bool TestBoobyTrap::init(int domainId, int exerciseId, int testId)
{
if (!TestBase::init(domainId, exerciseId, testId))
return false;
m_dtc->waitForHistoricalDataBoobyTrap();
m_btData.id(-1);
connect(m_dtc.get(), &AreaEffectSimulation::Interface::Dtc::boobyTrapChanged,
this, &TestBoobyTrap::boobyTrapChanged);
return true;
}
bool TestBoobyTrap::checkBaseData(const AreaEffectSimulation::BoobyTrap &a,
const AreaEffectSimulation::BoobyTrap &b) const
{
if (!checkAesItem(a, b))
return false;
if (a.impactPosition() != b.impactPosition())
{
WARNING_LOG(m_logger) << "impactPosition does not match: " << a.impactPosition() << " - " << b.impactPosition();
return false;
}
if (a.impactRadius() != b.impactRadius())
{
WARNING_LOG(m_logger) << "impactRadius does not match: " << a.impactRadius() << " - " << b.impactRadius();
return false;
}
return true;
}
//
// BoobyTrap
//
void TestBoobyTrap::tryCreateBoobyTrap()
{
m_btData = AreaEffectSimulation::BoobyTrap();
AreaEffectSimulation::BoobyTrap btData;
btData.id(0);
btData.name("BoobyTrap1");
btData.effectStart((time(nullptr) + 4) * 1000); // msec
btData.effectDuration(10234); // msec
btData.chargeStruct().chargeTypeId(3456789);
btData.impactPosition(Core::GeoPosition2D(0.1547, 0.926));
btData.impactRadius(800); // 100m
btData.triggerRadius(200);
btData.rotationAngle(45);
btData.centralAngle(90);
btData.partyId(2);
//btData.participantId(1234);
INFO_LOG(m_logger) << "trying to send BoobyTrapCreateRequest()";
m_replyError = false;
m_bExpectedFailure = true;
m_bIsCreatedRequest = true;
m_expectedAesId = -1;
if (!m_ftc->boobyTrapModifyRequest(
BoobyTrapModifyRequest(
0,
btData.name(),
btData.effectDuration(),
btData.chargeStruct().chargeTypeId(),
btData.impactPosition(),
btData.impactRadius(),
btData.triggerRadius(),
btData.rotationAngle().get(),
btData.centralAngle().get(),
btData.effectStart().get(),
btData.partyId().get()),
this))
{
ERROR_LOG(m_logger) << "Error during BoobyTrapCreateRequest()";
failExit();
return;
}
// since the chargeTypeId is not valid, we should get an error
if (!waitForData([this]() { return m_replyError == true; }))
{
ERROR_LOG(m_logger) << "Error creating booby trap object (try with error)";
failExit();
return;
}
// now with correct charge type
m_bExpectedFailure = false;
m_bIsCreatedRequest = true;
m_expectedAesId = -1;
btData.chargeStruct().chargeTypeId(s_ChargeTypeId1);
if (!m_ftc->boobyTrapModifyRequest(
BoobyTrapModifyRequest(
0,
btData.name(),
btData.effectDuration(),
btData.chargeStruct().chargeTypeId(),
btData.impactPosition(),
btData.impactRadius(),
btData.triggerRadius(),
btData.rotationAngle().get(),
btData.centralAngle().get(),
btData.effectStart().get(),
btData.partyId().get()),
this))
{
ERROR_LOG(m_logger) << "Error during BoobyTrapCreateRequest()";
failExit();
return;
}
if (!waitForData([this]() { return m_btData.id() == m_expectedAesId; }))
{
ERROR_LOG(m_logger) << "Error creating booby trap object";
failExit();
return;
}
if (!checkBaseData(m_btData, btData))
{
ERROR_LOG(m_logger) << "Creation data does not match published data";
failExit();
return;
}
QTimer::singleShot(0, this, &TestBoobyTrap::tryModifyBoobyTrap);
INFO_LOG(m_logger) << "tryCreateBoobyTrap successful";
}
void TestBoobyTrap::tryModifyBoobyTrap()
{
INFO_LOG(m_logger) << "trying to send modify request";
m_btData.name("Booby Trap 2");
m_btData.effectStart(m_btData.effectStart().get() + 2000);
m_btData.effectDuration(3200); // msec
m_btData.chargeStruct().chargeTypeId(s_ChargeTypeId2);
m_btData.impactPosition(Core::GeoPosition2D(0.1547, 0.926));
m_btData.partyId(3);
//m_btData.participantId(1235);
const AreaEffectSimulation::BoobyTrap btData(m_btData);
m_btData = AreaEffectSimulation::BoobyTrap();
m_btData.id(btData.id());
m_bIsCreatedRequest = false;
if (!m_ftc->boobyTrapModifyRequest(
BoobyTrapModifyRequest(
btData.id(),
btData.name(),
btData.effectDuration(),
btData.chargeStruct().chargeTypeId(),
btData.impactPosition(),
btData.impactRadius(),
btData.triggerRadius(),
btData.rotationAngle().get(),
btData.centralAngle().get(),
btData.effectStart().get(),
btData.partyId().get()),
this))
{
ERROR_LOG(m_logger) << "Error requesting modify data";
failExit();
return;
}
if (!waitForData([this]() { return m_btData.chargeStruct().chargeTypeId() == s_ChargeTypeId2;}))
{
ERROR_LOG(m_logger) << "Error updating booby trap object";
failExit();
return;
}
if (!checkBaseData(m_btData, btData))
{
ERROR_LOG(m_logger) << "Modify data does not match published data";
failExit();
return;
}
QTimer::singleShot(0, this, &TestBoobyTrap::tryTriggerBoobyTrap);
INFO_LOG(m_logger) << "tryModifyBoobyTrap successful";
}
void TestBoobyTrap::tryTriggerBoobyTrap()
{
INFO_LOG(m_logger) << "trigger booby trap -> expires";
BoobyTrapTriggerRequest req;
req.id(m_btData.id());
req.triggered(true);
if (!m_ftc->boobyTrapTriggerRequest(req, this))
{
ERROR_LOG(m_logger) << "Error requesting trigger data";
failExit();
return;
}
QTimer::singleShot(0, this, &TestBoobyTrap::waitExpireBoobyTrap);
INFO_LOG(m_logger) << "waitExpireBoobyTrap successful";
}
void TestBoobyTrap::waitExpireBoobyTrap()
{
INFO_LOG(m_logger) << "waiting until booby trap expires";
if (!waitForData([this]() { return m_btData.effectStateId() == AreaEffectSimulation::AesEffectState::EsExpired;}))
{
ERROR_LOG(m_logger) << "Timeout waiting for expiry of booby trap with id " << m_btData.id();
failExit();
return;
}
//QTimer::singleShot(0, this, &TestBoobyTrap::tryRemoveBoobyTrap);
INFO_LOG(m_logger) << "waitExpireBoobyTrap successful";
}
void TestBoobyTrap::tryRemoveBoobyTrap()
{
INFO_LOG(m_logger) << "tryRemoveBoobyTrap start";
AreaEffectSimulation::BoobyTrap btData(m_btData);
btData.name("RemoveTest");
btData.effectStart(0); // not set
m_btData = AreaEffectSimulation::BoobyTrap();
m_expectedAesId = -1;
m_bIsCreatedRequest = true;
if (!m_ftc->boobyTrapModifyRequest(
BoobyTrapModifyRequest(
0,
btData.name(),
btData.effectDuration(),
btData.chargeStruct().chargeTypeId(),
btData.impactPosition(),
btData.impactRadius(),
btData.triggerRadius(),
btData.rotationAngle().get(),
btData.centralAngle().get(),
btData.effectStart().get(),
btData.partyId().get()),
this))
{
ERROR_LOG(m_logger) << "Error during BoobyTrapModifyRequest()";
failExit();
return;
}
if (!waitForData([this]() { return m_btData.id() == m_expectedAesId; }))
{
ERROR_LOG(m_logger) << "Error creating booby trap object";
failExit();
return;
}
m_expectedAesId = -1;
if (!m_ftc->boobyTrapRemoveRequest(Core::RemoveElementRequest(m_btData.id()), this))
{
ERROR_LOG(m_logger) << "Error during BoobyTrapRemoveRequest()";
failExit();
return;
}
if (!waitForData([this]() { return m_btData.id() == m_expectedAesId; }))
{
ERROR_LOG(m_logger) << "Error removing booby trap object";
failExit();
return;
}
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
INFO_LOG(m_logger) << "tryRemoveBoobyTrap successful";
}
void TestBoobyTrap::boobyTrapChanged(const AreaEffectSimulation::BoobyTrap &data, DataModification modType)
{
if (m_btData.id() == -1)
return;
onAesChanged(data, modType, m_btData);
}
void TestBoobyTrap::onBoobyTrapModifyReply(const Core::FunctionReplyObject &replyObject)
{
if (m_bIsCreatedRequest)
onAesCreateReply(replyObject);
else
onAesModifyReply(replyObject);
}
void TestBoobyTrap::onBoobyTrapRemoveReply(const Core::FunctionReplyObject &replyObject)
{
onAesRemoveReply(replyObject);
}
void TestBoobyTrap::onBoobyTrapTriggerReply(const Core::FunctionReplyObject &replyObject)
{
onAesTriggerReply(replyObject);
}
} // namespace AreaEffectSimulation
// ------------------------------------------------------------------
int main(int argc, char **argv)
{
return AreaEffectSimulation::mainBase(argc, argv, []() { return new AreaEffectSimulation::TestBoobyTrap; });
}