358 lines
10 KiB
C++
Executable File
358 lines
10 KiB
C++
Executable File
/**
|
|
* AES Function Topic Client test executable
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#include "aes_test_explosion_single.h"
|
|
#include <QCoreApplication>
|
|
#include <QTest>
|
|
#include <QTimer>
|
|
|
|
namespace AreaEffectSimulation
|
|
{
|
|
|
|
// must be in pdm.pdm_charge_type
|
|
// single fire charge types = area fire
|
|
static const int s_ChargeTypeId1 = 371;
|
|
static const int s_ChargeTypeId2 = 372;
|
|
|
|
TestExplosionSingle::TestExplosionSingle(QObject *parent)
|
|
: TestBase("Test.ExplosionSingle", parent)
|
|
{}
|
|
|
|
bool TestExplosionSingle::init(int domainId, int exerciseId, int testId)
|
|
{
|
|
if (!TestBase::init(domainId, exerciseId, testId))
|
|
return false;
|
|
|
|
m_dtc->waitForHistoricalDataExplosionSingle();
|
|
m_esData.id(-1);
|
|
|
|
connect(m_dtc.get(), &AreaEffectSimulation::Interface::Dtc::explosionSingleChanged,
|
|
this, &TestExplosionSingle::explosionSingleChanged);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool TestExplosionSingle::checkBaseData(const AreaEffectSimulation::ExplosionSingle &a,
|
|
const AreaEffectSimulation::ExplosionSingle &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;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
//
|
|
// ExplosionSingle
|
|
//
|
|
void TestExplosionSingle::tryCreateExplosionSingle()
|
|
{
|
|
m_esData = AreaEffectSimulation::ExplosionSingle();
|
|
AreaEffectSimulation::ExplosionSingle esData;
|
|
esData.id(0);
|
|
esData.name("chris");
|
|
esData.effectStart((time(nullptr) + 4) * 1000); // msec
|
|
esData.chargeStruct().chargeTypeId(345863487);
|
|
esData.impactPosition(Core::GeoPosition2D(0.16, 0.92));
|
|
esData.partyId(7);
|
|
esData.participantId(1234);
|
|
esData.externalId(1);
|
|
esData.effectMarkingInTa(false);
|
|
|
|
INFO_LOG(m_logger) << "trying to send explosionSingleCreateRequest()";
|
|
m_replyError = false;
|
|
m_bExpectedFailure = true;
|
|
m_bIsCreatedRequest = true;
|
|
if (!m_ftc->explosionSingleModifyRequest(
|
|
ExplosionSingleModifyRequest(
|
|
0,
|
|
esData.name(),
|
|
esData.effectStart(),
|
|
esData.effectSourceId(),
|
|
esData.chargeStruct().chargeTypeId(),
|
|
esData.impactPosition(),
|
|
esData.partyId(),
|
|
esData.participantId(),
|
|
esData.fireRequestTime(),
|
|
esData.altitude(),
|
|
esData.purpose(),
|
|
esData.effectMarkingInTa(),
|
|
esData.externalId()),
|
|
this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error during explosionSingleCreateRequest()";
|
|
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 single explosion object (try with error)";
|
|
}
|
|
|
|
// now with correct charge type
|
|
m_bExpectedFailure = false;
|
|
m_expectedAesId = -1;
|
|
|
|
esData.chargeStruct().chargeTypeId(s_ChargeTypeId1);
|
|
esData.partyId(2);
|
|
m_bIsCreatedRequest = true;
|
|
if (!m_ftc->explosionSingleModifyRequest(
|
|
ExplosionSingleModifyRequest(
|
|
0,
|
|
esData.name(),
|
|
esData.effectStart(),
|
|
esData.effectSourceId(),
|
|
esData.chargeStruct().chargeTypeId(),
|
|
esData.impactPosition(),
|
|
esData.partyId(),
|
|
esData.participantId(),
|
|
esData.fireRequestTime(),
|
|
esData.altitude(),
|
|
esData.purpose(),
|
|
esData.effectMarkingInTa(),
|
|
esData.externalId()),
|
|
this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error during explosionSingleCreateRequest()";
|
|
failExit();
|
|
return;
|
|
}
|
|
|
|
if (!waitForData([this]() { return m_esData.id() == m_expectedAesId; }))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error creating single explosion object";
|
|
failExit();
|
|
return;
|
|
}
|
|
if (!checkBaseData(m_esData, esData))
|
|
{
|
|
ERROR_LOG(m_logger) << "Creation data does not match published data";
|
|
failExit();
|
|
return;
|
|
}
|
|
QTimer::singleShot(0, this, &TestExplosionSingle::tryModifyExplosionSingle);
|
|
INFO_LOG(m_logger) << "tryCreateExplosionSingle successful";
|
|
}
|
|
|
|
void TestExplosionSingle::tryModifyExplosionSingle()
|
|
{
|
|
INFO_LOG(m_logger) << "trying to send modify request";
|
|
m_esData.name("chris2");
|
|
m_esData.effectStart(m_esData.effectStart().get() + 2000);
|
|
m_esData.chargeStruct().chargeTypeId(s_ChargeTypeId2);
|
|
m_esData.impactPosition(Core::GeoPosition2D(0.17, 0.93));
|
|
m_esData.partyId(3);
|
|
m_esData.participantId(1235);
|
|
const AreaEffectSimulation::ExplosionSingle esData(m_esData);
|
|
m_esData = AreaEffectSimulation::ExplosionSingle();
|
|
m_esData.id(esData.id());
|
|
|
|
m_bIsCreatedRequest = false;
|
|
if (!m_ftc->explosionSingleModifyRequest(
|
|
ExplosionSingleModifyRequest(
|
|
esData.id(),
|
|
esData.name(),
|
|
esData.effectStart(),
|
|
esData.effectSourceId(),
|
|
esData.chargeStruct().chargeTypeId(),
|
|
esData.impactPosition(),
|
|
esData.partyId(),
|
|
esData.participantId(),
|
|
esData.fireRequestTime(),
|
|
esData.altitude(),
|
|
esData.purpose(),
|
|
esData.effectMarkingInTa(),
|
|
esData.externalId()),
|
|
this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error requesting modify data";
|
|
failExit();
|
|
return;
|
|
}
|
|
if (!waitForData([this]() { return m_esData.chargeStruct().chargeTypeId() == s_ChargeTypeId2;}))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error updating single explosion object";
|
|
failExit();
|
|
return;
|
|
}
|
|
if (!checkBaseData(m_esData, esData))
|
|
{
|
|
ERROR_LOG(m_logger) << "Modify data does not match published data";
|
|
failExit();
|
|
return;
|
|
}
|
|
QTimer::singleShot(0, this, &TestExplosionSingle::waitExpireExplosionSingle);
|
|
INFO_LOG(m_logger) << "tryModifyExplosionSingle successful";
|
|
}
|
|
|
|
void TestExplosionSingle::waitExpireExplosionSingle()
|
|
{
|
|
INFO_LOG(m_logger) << "waiting until explosion single expires";
|
|
|
|
if (!waitForData([this]() { return m_esData.effectStateId() == AreaEffectSimulation::AesEffectState::EsExpired;}))
|
|
{
|
|
ERROR_LOG(m_logger) << "Timeout waiting for expiry of explosion single with id " << m_esData.id();
|
|
failExit();
|
|
return;
|
|
}
|
|
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
INFO_LOG(m_logger) << "waitExpireExplosionSingle successful";
|
|
}
|
|
|
|
void TestExplosionSingle::explosionSingleChanged(const AreaEffectSimulation::ExplosionSingle &data, DataModification modType)
|
|
{
|
|
if (m_esData.id() == -1)
|
|
return;
|
|
onAesChanged(data, modType, m_esData);
|
|
}
|
|
|
|
void TestExplosionSingle::onExplosionSingleModifyReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
if (m_bIsCreatedRequest)
|
|
onAesCreateReply(replyObject);
|
|
else
|
|
onAesModifyReply(replyObject);
|
|
}
|
|
|
|
void TestExplosionSingle::onExplosionSingleRemoveReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
onAesRemoveReply(replyObject);
|
|
}
|
|
|
|
//
|
|
// TestExplosionSingleTestVWM
|
|
//
|
|
TestExplosionSingleTestVWM::TestExplosionSingleTestVWM(QObject *parent)
|
|
: TestExplosionSingle(parent)
|
|
{
|
|
}
|
|
|
|
void TestExplosionSingleTestVWM::tryCreateExplosionSingleVWM(const std::string &esName,
|
|
int ammoId,
|
|
const Core::GeoPosition2D & position)
|
|
{
|
|
INFO_LOG(m_logger) << "tryCreateExplosionSingleVWM"
|
|
<< " name ='" << esName << "'"
|
|
<< " ammoId = " << ammoId
|
|
<< " position = " << position;
|
|
m_esData = AreaEffectSimulation::ExplosionSingle();
|
|
AreaEffectSimulation::ExplosionSingle esData;
|
|
esData.id(0);
|
|
esData.name(esName);
|
|
esData.effectStart((time(nullptr) + 4) * 1000); // msec
|
|
esData.chargeStruct().chargeTypeId(ammoId);
|
|
esData.impactPosition(position);
|
|
esData.partyId(3); // 3 -> blau
|
|
esData.participantId(1234);
|
|
esData.externalId(1);
|
|
esData.effectMarkingInTa(false);
|
|
|
|
INFO_LOG(m_logger) << "trying to send explosionSingleCreateRequest()";
|
|
m_replyError = false;
|
|
|
|
m_bIsCreatedRequest = true;
|
|
m_bExpectedFailure = false;
|
|
m_expectedAesId = -1;
|
|
|
|
if (!m_ftc->explosionSingleModifyRequest(
|
|
ExplosionSingleModifyRequest(
|
|
0,
|
|
esData.name(),
|
|
esData.effectStart(),
|
|
esData.effectSourceId(),
|
|
esData.chargeStruct().chargeTypeId(),
|
|
esData.impactPosition(),
|
|
esData.partyId(),
|
|
esData.participantId(),
|
|
esData.fireRequestTime(),
|
|
esData.altitude(),
|
|
esData.purpose(),
|
|
esData.effectMarkingInTa(),
|
|
esData.externalId()),
|
|
this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error during explosionSingleCreateRequest()";
|
|
failExit();
|
|
return;
|
|
}
|
|
|
|
// TestBase::onAesCreateReply should update m_expectedAesId:
|
|
if (!waitForData([this]() { return m_esData.id() == m_expectedAesId; }))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error creating single explosion object (try with error)";
|
|
}
|
|
|
|
INFO_LOG(m_logger) << "got answer, m_replyError=" << m_replyError
|
|
<< " m_expectedAesId=" << m_expectedAesId;
|
|
|
|
std::cerr << "got answer, m_replyError=" << m_replyError
|
|
<< " m_expectedAesId=" << m_expectedAesId << std::endl;
|
|
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
|
|
}
|
|
|
|
void TestExplosionSingleTestVWM::onExplosionSingleCreateReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
if (m_bIsCreatedRequest)
|
|
onAesCreateReply(replyObject);
|
|
else
|
|
onAesModifyReply(replyObject);
|
|
}
|
|
|
|
} // namespace AreaEffectSimulation
|
|
|
|
// ------------------------------------------------------------------
|
|
int main(int argc, char **argv)
|
|
{
|
|
// LOGGING: log4cxx_aes.props -> ctc_aes.log
|
|
|
|
// find name, ammoId, position
|
|
std::string name;
|
|
int ammoId = -1;
|
|
Core::GeoPosition2D position;
|
|
|
|
{
|
|
for (int i=1; i<argc; ++i)
|
|
{
|
|
if (strcmp(argv[i], "name") == 0)
|
|
name = argv[i+1];
|
|
if (strcmp(argv[i], "ammoId") == 0)
|
|
ammoId = atoi(argv[i+1]);
|
|
if (strcmp(argv[i], "x") == 0)
|
|
position.lon(atof(argv[i+1]));
|
|
if (strcmp(argv[i], "y") == 0)
|
|
position.lat(atof(argv[i+1]));
|
|
}
|
|
}
|
|
|
|
if (!name.empty())
|
|
{
|
|
std::cerr << " name = '" << name << "'"
|
|
<< " ammoId = '" << ammoId
|
|
<< " position = '" << position << std::endl;
|
|
|
|
std::function<AreaEffectSimulation::TestBase*()> createFunc = [name, ammoId, position]() {
|
|
auto ptr = new AreaEffectSimulation::TestExplosionSingleTestVWM;
|
|
ptr->setName(name);
|
|
ptr->setAmmoId(ammoId);
|
|
ptr->setPosition(position);
|
|
return ptr;
|
|
};
|
|
return AreaEffectSimulation::mainBase(argc, argv, createFunc);
|
|
} else {
|
|
return AreaEffectSimulation::mainBase(argc, argv, []() { return new AreaEffectSimulation::TestExplosionSingle; });
|
|
}
|
|
}
|
|
|