314 lines
9.0 KiB
C++
Executable File
314 lines
9.0 KiB
C++
Executable File
/**
|
|
* AES Function Topic Client test executable
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#include "aes_test_off_route_mine.h"
|
|
#include <QCoreApplication>
|
|
#include <QTest>
|
|
#include <QTimer>
|
|
|
|
namespace AreaEffectSimulation
|
|
{
|
|
|
|
// must be in pdm.pdm_charge_type
|
|
static const int s_ChargeTypeId1 = 253;
|
|
static const int s_ChargeTypeId2 = 254;
|
|
|
|
TestOffRouteMine::TestOffRouteMine(QObject *parent)
|
|
: TestBase("Test.OffRouteMine", parent)
|
|
{}
|
|
|
|
bool TestOffRouteMine::init(int domainId, int exerciseId, int testId)
|
|
{
|
|
if (!TestBase::init(domainId, exerciseId, testId))
|
|
return false;
|
|
|
|
m_dtc->waitForHistoricalDataOffRouteMine();
|
|
m_ormData.id(-1);
|
|
connect(m_dtc.get(), &AreaEffectSimulation::Interface::Dtc::offRouteMineChanged,
|
|
this, &TestOffRouteMine::offRouteMineChanged);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool TestOffRouteMine::checkBaseData(const AreaEffectSimulation::OffRouteMine &a,
|
|
const AreaEffectSimulation::OffRouteMine &b) const
|
|
{
|
|
if (!checkAesItem(a, b))
|
|
return false;
|
|
|
|
if (a.area().cornerBottomLeft() != b.area().cornerBottomLeft())
|
|
{
|
|
WARNING_LOG(m_logger) << "cornerBottomLeft does not match: " << a.area().cornerBottomLeft() << " - " << b.area().cornerBottomLeft();
|
|
return false;
|
|
}
|
|
if (a.impactRadius() != b.impactRadius())
|
|
{
|
|
WARNING_LOG(m_logger) << "impactRadius does not match: " << a.impactRadius() << " - " << b.impactRadius();
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
//
|
|
// OffRouteMine
|
|
//
|
|
void TestOffRouteMine::tryCreateOffRouteMine()
|
|
{
|
|
m_ormData = AreaEffectSimulation::OffRouteMine();
|
|
AreaEffectSimulation::OffRouteMine ormData;
|
|
|
|
ormData.id(0);
|
|
ormData.name("OffRouteMine1");
|
|
ormData.effectStart((time(nullptr) + 4) * 1000); // msec
|
|
ormData.effectDuration(10234); // msec
|
|
ormData.chargeStruct().chargeTypeId(3456789);
|
|
ormData.area().cornerBottomLeft(Core::GeoPosition2D(0.154, 0.926));
|
|
ormData.area().width(1000);//(20);
|
|
ormData.area().height(200);//(15);
|
|
ormData.area().rotation(0.0);//(20.5);
|
|
ormData.impactRadius(100); // 100m
|
|
ormData.partyId(2);
|
|
//ormData.participantId(1234);
|
|
|
|
INFO_LOG(m_logger) << "trying to send OffRouteMineCreateRequest()";
|
|
m_replyError = false;
|
|
m_bExpectedFailure = true;
|
|
m_bIsCreatedRequest = true;
|
|
m_expectedAesId = -1;
|
|
|
|
if (!m_ftc->offRouteMineModifyRequest(
|
|
OffRouteMineModifyRequest(
|
|
0,
|
|
ormData.name(),
|
|
ormData.effectDuration(),
|
|
ormData.chargeStruct().chargeTypeId(),
|
|
ormData.area(),
|
|
ormData.impactRadius().get(),
|
|
ormData.effectStart().get(),
|
|
ormData.partyId().get()),
|
|
this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error during OffRouteMineCreateRequest()";
|
|
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 off route mine object (try with error)";
|
|
failExit();
|
|
return;
|
|
}
|
|
|
|
// now with correct charge type
|
|
m_bExpectedFailure = false;
|
|
m_bIsCreatedRequest = true;
|
|
m_expectedAesId = -1;
|
|
|
|
ormData.chargeStruct().chargeTypeId(s_ChargeTypeId1);
|
|
if (!m_ftc->offRouteMineModifyRequest(
|
|
OffRouteMineModifyRequest(
|
|
0,
|
|
ormData.name(),
|
|
ormData.effectDuration(),
|
|
ormData.chargeStruct().chargeTypeId(),
|
|
ormData.area(),
|
|
ormData.impactRadius().get(),
|
|
ormData.effectStart().get(),
|
|
ormData.partyId().get()),
|
|
this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error during OffRouteMineCreateRequest()";
|
|
failExit();
|
|
return;
|
|
}
|
|
|
|
if (!waitForData([this]() { return m_ormData.id() == m_expectedAesId; }))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error creating off route mine object";
|
|
failExit();
|
|
return;
|
|
}
|
|
if (!checkBaseData(m_ormData, ormData))
|
|
{
|
|
ERROR_LOG(m_logger) << "Creation data does not match published data";
|
|
failExit();
|
|
return;
|
|
}
|
|
QTimer::singleShot(0, this, &TestOffRouteMine::tryModifyOffRouteMine);
|
|
INFO_LOG(m_logger) << "tryCreateOffRouteMine successful";
|
|
}
|
|
|
|
void TestOffRouteMine::tryModifyOffRouteMine()
|
|
{
|
|
INFO_LOG(m_logger) << "trying to send modify request";
|
|
m_ormData.name("OffRouteMine 2");
|
|
m_ormData.effectStart(m_ormData.effectStart().get() + 2000);
|
|
m_ormData.effectDuration(3200); // msec
|
|
m_ormData.chargeStruct().chargeTypeId(s_ChargeTypeId2);
|
|
m_ormData.area().cornerBottomLeft(Core::GeoPosition2D(0.154, 0.926));
|
|
m_ormData.area().width(1000);//(50);
|
|
m_ormData.area().height(200);//(25);
|
|
m_ormData.area().rotation(90);//(20.5);
|
|
m_ormData.partyId(3);
|
|
//m_ormData.participantId(1235);
|
|
const AreaEffectSimulation::OffRouteMine ormData(m_ormData);
|
|
m_ormData = AreaEffectSimulation::OffRouteMine();
|
|
m_ormData.id(ormData.id());
|
|
|
|
m_bIsCreatedRequest = false;
|
|
if (!m_ftc->offRouteMineModifyRequest(
|
|
OffRouteMineModifyRequest(
|
|
ormData.id(),
|
|
ormData.name(),
|
|
ormData.effectDuration(),
|
|
ormData.chargeStruct().chargeTypeId(),
|
|
ormData.area(),
|
|
ormData.impactRadius().get(),
|
|
ormData.effectStart().get(),
|
|
ormData.partyId().get()),
|
|
this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error requesting modify data";
|
|
failExit();
|
|
return;
|
|
}
|
|
if (!waitForData([this]() { return m_ormData.chargeStruct().chargeTypeId() == s_ChargeTypeId2;}))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error updating off route mine object";
|
|
failExit();
|
|
return;
|
|
}
|
|
if (!checkBaseData(m_ormData, ormData))
|
|
{
|
|
ERROR_LOG(m_logger) << "Modify data does not match published data";
|
|
failExit();
|
|
return;
|
|
}
|
|
QTimer::singleShot(0, this, &TestOffRouteMine::tryTriggerOffRouteMine);
|
|
INFO_LOG(m_logger) << "tryModifyOffRouteMine successful";
|
|
}
|
|
|
|
void TestOffRouteMine::tryTriggerOffRouteMine()
|
|
{
|
|
INFO_LOG(m_logger) << "trigger off route mine -> expires";
|
|
|
|
OffRouteMineTriggerRequest req;
|
|
req.id(m_ormData.id());
|
|
req.triggered(true);
|
|
if (!m_ftc->offRouteMineTriggerRequest(req, this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error requesting trigger data";
|
|
failExit();
|
|
return;
|
|
}
|
|
|
|
QTimer::singleShot(0, this, &TestOffRouteMine::waitExpireOffRouteMine);
|
|
INFO_LOG(m_logger) << "waitExpireBoobyTrap successful";
|
|
}
|
|
void TestOffRouteMine::waitExpireOffRouteMine()
|
|
{
|
|
INFO_LOG(m_logger) << "waiting until off route mine expires";
|
|
|
|
if (!waitForData([this]() { return m_ormData.effectStateId() == AreaEffectSimulation::AesEffectState::EsExpired;}))
|
|
{
|
|
ERROR_LOG(m_logger) << "Timeout waiting for expiry of off route mine with id " << m_ormData.id();
|
|
failExit();
|
|
return;
|
|
}
|
|
|
|
//QTimer::singleShot(0, this, &TestOffRouteMine::tryRemoveOffRouteMine);
|
|
INFO_LOG(m_logger) << "waitExpireOffRouteMine successful";
|
|
}
|
|
|
|
void TestOffRouteMine::tryRemoveOffRouteMine()
|
|
{
|
|
INFO_LOG(m_logger) << "tryRemoveOffRouteMine start";
|
|
|
|
AreaEffectSimulation::OffRouteMine ormData(m_ormData);
|
|
ormData.name("RemoveTest");
|
|
ormData.effectStart(0); // not set
|
|
m_ormData = AreaEffectSimulation::OffRouteMine();
|
|
m_expectedAesId = -1;
|
|
m_bIsCreatedRequest = true;
|
|
|
|
if (!m_ftc->offRouteMineModifyRequest(
|
|
OffRouteMineModifyRequest(
|
|
0,
|
|
ormData.name(),
|
|
ormData.effectDuration(),
|
|
ormData.chargeStruct().chargeTypeId(),
|
|
ormData.area(),
|
|
ormData.impactRadius().get(),
|
|
ormData.effectStart().get(),
|
|
ormData.partyId().get()),
|
|
this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error during OffRouteMineModifyRequest()";
|
|
failExit();
|
|
return;
|
|
}
|
|
|
|
if (!waitForData([this]() { return m_ormData.id() == m_expectedAesId; }))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error creating off route mine object";
|
|
failExit();
|
|
return;
|
|
}
|
|
|
|
m_expectedAesId = -1;
|
|
if (!m_ftc->offRouteMineRemoveRequest(Core::RemoveElementRequest(m_ormData.id()), this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error during OffRouteMineRemoveRequest()";
|
|
failExit();
|
|
return;
|
|
}
|
|
|
|
if (!waitForData([this]() { return m_ormData.id() == m_expectedAesId; }))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error removing off route mine object";
|
|
failExit();
|
|
return;
|
|
}
|
|
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
INFO_LOG(m_logger) << "tryRemoveOffRouteMine successful";
|
|
}
|
|
|
|
void TestOffRouteMine::offRouteMineChanged(const AreaEffectSimulation::OffRouteMine &data, DataModification modType)
|
|
{
|
|
if (m_ormData.id() == -1)
|
|
return;
|
|
onAesChanged(data, modType, m_ormData);
|
|
}
|
|
|
|
void TestOffRouteMine::onOffRouteMineModifyReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
if (m_bIsCreatedRequest)
|
|
onAesCreateReply(replyObject);
|
|
else
|
|
onAesModifyReply(replyObject);
|
|
}
|
|
|
|
void TestOffRouteMine::onOffRouteMineRemoveReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
onAesRemoveReply(replyObject);
|
|
}
|
|
|
|
void TestOffRouteMine::onOffRouteMineTriggerReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
onAesTriggerReply(replyObject);
|
|
}
|
|
|
|
} // namespace AreaEffectSimulation
|
|
|
|
// ------------------------------------------------------------------
|
|
int main(int argc, char **argv)
|
|
{
|
|
return AreaEffectSimulation::mainBase(argc, argv, []() { return new AreaEffectSimulation::TestOffRouteMine; });
|
|
}
|