Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+331
@@ -0,0 +1,331 @@
|
||||
/**
|
||||
* AES Function Topic Client test executable
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "aes_test_bccontamination.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QTest>
|
||||
#include <QTimer>
|
||||
|
||||
namespace AreaEffectSimulation
|
||||
{
|
||||
|
||||
// must be in pdm.pdm_charge_type
|
||||
static const int s_ChargeTypeId1 = 341;
|
||||
static const int s_ChargeTypeId2 = 342;
|
||||
|
||||
TestBCContamination::TestBCContamination(QObject *parent)
|
||||
: TestBase("Test.BCContamination", parent)
|
||||
{}
|
||||
|
||||
bool TestBCContamination::init(int domainId, int exerciseId, int testId)
|
||||
{
|
||||
if (!TestBase::init(domainId, exerciseId, testId))
|
||||
return false;
|
||||
|
||||
m_dtc->waitForHistoricalDataBCContamination();
|
||||
m_bcData.id(-1);
|
||||
connect(m_dtc.get(), &AreaEffectSimulation::Interface::Dtc::bCContaminationChanged,
|
||||
this, &TestBCContamination::bCContaminationChanged);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestBCContamination::checkBaseData(const AreaEffectSimulation::BCContamination &a,
|
||||
const AreaEffectSimulation::BCContamination &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;
|
||||
}
|
||||
|
||||
//
|
||||
// BCContamination
|
||||
//
|
||||
void TestBCContamination::tryCreateBCContamination()
|
||||
{
|
||||
m_bcData = AreaEffectSimulation::BCContamination();
|
||||
AreaEffectSimulation::BCContamination bcData;
|
||||
|
||||
bcData.id(0);
|
||||
bcData.name("chris");
|
||||
bcData.effectStart((time(nullptr) + 4) * 1000); // msec
|
||||
bcData.effectDuration(10234); // msec
|
||||
bcData.chargeStruct().chargeTypeId(345863487);
|
||||
bcData.impactPosition(Core::GeoPosition2D(0.16, 0.92));
|
||||
bcData.impactRadius(100); // 100m
|
||||
bcData.partyId(2);
|
||||
bcData.participantId(1234);
|
||||
bcData.upperOffset(6.0);
|
||||
bcData.lowerOffset(-1000.0);
|
||||
|
||||
INFO_LOG(m_logger) << "trying to send BCContaminationCreateRequest()";
|
||||
m_replyError = false;
|
||||
m_bExpectedFailure = true;
|
||||
m_bIsCreatedRequest = true;
|
||||
m_expectedAesId = -1;
|
||||
|
||||
if(!m_ftc->bCContaminationModifyRequest(
|
||||
BCContaminationModifyRequest(
|
||||
0,
|
||||
bcData.name(),
|
||||
bcData.effectStart(),
|
||||
bcData.effectDuration(),
|
||||
bcData.chargeStruct().chargeTypeId(),
|
||||
bcData.impactPosition(),
|
||||
bcData.impactRadius(),
|
||||
AesWeatherSource::AwsStatic,
|
||||
bcData.partyId(),
|
||||
bcData.participantId(),
|
||||
dds::core::optional<double>(), // propagationDirection
|
||||
dds::core::optional<double>(), // windSpeed
|
||||
dds::core::optional<Core::GeoPosition2D>(), // weatherPosition
|
||||
dds::core::optional<rti::core::int64>(), // weatherTimestamp
|
||||
dds::core::optional<long long>(), // externalId
|
||||
bcData.upperOffset(),
|
||||
bcData.lowerOffset(),
|
||||
dds::core::optional<bool>()),
|
||||
this))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error during BCContaminationCreateRequest()";
|
||||
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 bc contamination object (try with error)";
|
||||
failExit();
|
||||
return;
|
||||
}
|
||||
|
||||
// now with correct charge type
|
||||
m_bExpectedFailure = false;
|
||||
m_bIsCreatedRequest = true;
|
||||
m_expectedAesId = -1;
|
||||
|
||||
bcData.chargeStruct().chargeTypeId(s_ChargeTypeId1);
|
||||
if (!m_ftc->bCContaminationModifyRequest(
|
||||
BCContaminationModifyRequest(
|
||||
0,
|
||||
bcData.name(),
|
||||
bcData.effectStart(),
|
||||
bcData.effectDuration(),
|
||||
bcData.chargeStruct().chargeTypeId(),
|
||||
bcData.impactPosition(),
|
||||
bcData.impactRadius(),
|
||||
AesWeatherSource::AwsStatic,
|
||||
bcData.partyId(),
|
||||
bcData.participantId(),
|
||||
dds::core::optional<double>(),
|
||||
dds::core::optional<double>(),
|
||||
dds::core::optional<Core::GeoPosition2D>(),
|
||||
dds::core::optional<rti::core::int64>(),
|
||||
dds::core::optional<long long>(),
|
||||
bcData.upperOffset(),
|
||||
bcData.lowerOffset(),
|
||||
dds::core::optional<bool>()),
|
||||
this))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error during BCContaminationCreateRequest()";
|
||||
failExit();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!waitForData([this]() { return m_bcData.id() == m_expectedAesId; }))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error creating bc contamination object";
|
||||
failExit();
|
||||
return;
|
||||
}
|
||||
if (!checkBaseData(m_bcData, bcData))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Creation data does not match published data";
|
||||
failExit();
|
||||
return;
|
||||
}
|
||||
QTimer::singleShot(0, this, &TestBCContamination::tryModifyBCContamination);
|
||||
INFO_LOG(m_logger) << "tryCreateBCContamination successful";
|
||||
}
|
||||
|
||||
void TestBCContamination::tryModifyBCContamination()
|
||||
{
|
||||
INFO_LOG(m_logger) << "trying to send modify request";
|
||||
m_bcData.name("chris2");
|
||||
m_bcData.effectStart(m_bcData.effectStart().get() + 2000);
|
||||
m_bcData.effectDuration(3200); // msec
|
||||
m_bcData.chargeStruct().chargeTypeId(s_ChargeTypeId2);
|
||||
m_bcData.impactPosition(Core::GeoPosition2D(0.17, 0.93));
|
||||
m_bcData.partyId(3);
|
||||
m_bcData.participantId(1235);
|
||||
m_bcData.upperOffset(6.0);
|
||||
m_bcData.lowerOffset(false);
|
||||
const AreaEffectSimulation::BCContamination bcData(m_bcData);
|
||||
m_bcData = AreaEffectSimulation::BCContamination();
|
||||
m_bcData.id(bcData.id());
|
||||
|
||||
m_bIsCreatedRequest = false;
|
||||
if (!m_ftc->bCContaminationModifyRequest(
|
||||
BCContaminationModifyRequest(
|
||||
bcData.id(),
|
||||
bcData.name(),
|
||||
bcData.effectStart(),
|
||||
bcData.effectDuration(),
|
||||
bcData.chargeStruct().chargeTypeId(),
|
||||
bcData.impactPosition(),
|
||||
bcData.impactRadius(),
|
||||
AesWeatherSource::AwsStatic,
|
||||
bcData.partyId(),
|
||||
bcData.participantId(),
|
||||
dds::core::optional<double>(),
|
||||
dds::core::optional<double>(),
|
||||
dds::core::optional<Core::GeoPosition2D>(),
|
||||
dds::core::optional<rti::core::int64>(),
|
||||
dds::core::optional<rti::core::int64>(),
|
||||
bcData.upperOffset(),
|
||||
bcData.lowerOffset(),
|
||||
dds::core::optional<bool>()),
|
||||
this))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error requesting modify data";
|
||||
failExit();
|
||||
return;
|
||||
}
|
||||
if (!waitForData([this]() { return m_bcData.chargeStruct().chargeTypeId() == s_ChargeTypeId2;}))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error updating bc contamination object";
|
||||
failExit();
|
||||
return;
|
||||
}
|
||||
if (!checkBaseData(m_bcData, bcData))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Modify data does not match published data";
|
||||
failExit();
|
||||
return;
|
||||
}
|
||||
QTimer::singleShot(0, this, &TestBCContamination::waitExpireBCContamination);
|
||||
INFO_LOG(m_logger) << "tryModifyBCContamination successful";
|
||||
}
|
||||
|
||||
void TestBCContamination::waitExpireBCContamination()
|
||||
{
|
||||
INFO_LOG(m_logger) << "waiting until bc contamination expires";
|
||||
|
||||
if (!waitForData([this]() { return m_bcData.effectStateId() == AreaEffectSimulation::AesEffectState::EsExpired;}))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Timeout waiting for expiry of bc contamination with id " << m_bcData.id();
|
||||
failExit();
|
||||
return;
|
||||
}
|
||||
|
||||
QTimer::singleShot(0, this, &TestBCContamination::tryRemoveBCContamination);
|
||||
INFO_LOG(m_logger) << "waitExpireBCContamination successful";
|
||||
}
|
||||
|
||||
void TestBCContamination::tryRemoveBCContamination()
|
||||
{
|
||||
INFO_LOG(m_logger) << "tryRemoveBCContamination start";
|
||||
|
||||
AreaEffectSimulation::BCContamination bcData(m_bcData);
|
||||
bcData.name("RemoveTest");
|
||||
bcData.effectStart(0); // not set
|
||||
m_bcData = AreaEffectSimulation::BCContamination();
|
||||
m_expectedAesId = -1;
|
||||
m_bIsCreatedRequest = true;
|
||||
bcData.upperOffset(6.0);
|
||||
bcData.lowerOffset(false);
|
||||
|
||||
if (!m_ftc->bCContaminationModifyRequest(
|
||||
BCContaminationModifyRequest(
|
||||
0,
|
||||
bcData.name(),
|
||||
bcData.effectStart(),
|
||||
bcData.effectDuration(),
|
||||
bcData.chargeStruct().chargeTypeId(),
|
||||
bcData.impactPosition(),
|
||||
bcData.impactRadius(),
|
||||
AesWeatherSource::AwsStatic,
|
||||
bcData.partyId(),
|
||||
bcData.participantId(),
|
||||
dds::core::optional<double>(),
|
||||
dds::core::optional<double>(),
|
||||
dds::core::optional<Core::GeoPosition2D>(),
|
||||
dds::core::optional<rti::core::int64>(),
|
||||
dds::core::optional<rti::core::int64>(),
|
||||
bcData.upperOffset(),
|
||||
bcData.lowerOffset(),
|
||||
dds::core::optional<bool>()),
|
||||
this))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error during bCContaminationModifyRequest()";
|
||||
failExit();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!waitForData([this]() { return m_bcData.id() == m_expectedAesId; }))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error creating bc contamination object";
|
||||
failExit();
|
||||
return;
|
||||
}
|
||||
|
||||
m_expectedAesId = -1;
|
||||
if (!m_ftc->bCContaminationRemoveRequest(Core::RemoveElementRequest(m_bcData.id()), this))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error during BCContaminationRemoveRequest()";
|
||||
failExit();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!waitForData([this]() { return m_bcData.id() == m_expectedAesId; }))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error removing bc contamination object";
|
||||
failExit();
|
||||
return;
|
||||
}
|
||||
|
||||
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
||||
INFO_LOG(m_logger) << "tryRemoveBCContamination successful";
|
||||
}
|
||||
|
||||
void TestBCContamination::bCContaminationChanged(const AreaEffectSimulation::BCContamination &data, DataModification modType)
|
||||
{
|
||||
if (m_bcData.id() == -1)
|
||||
return;
|
||||
onAesChanged(data, modType, m_bcData);
|
||||
}
|
||||
|
||||
void TestBCContamination::onBCContaminationModifyReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
if (m_bIsCreatedRequest)
|
||||
onAesCreateReply(replyObject);
|
||||
else
|
||||
onAesModifyReply(replyObject);
|
||||
}
|
||||
|
||||
void TestBCContamination::onBCContaminationRemoveReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
onAesRemoveReply(replyObject);
|
||||
}
|
||||
|
||||
} // namespace AreaEffectSimulation
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
return AreaEffectSimulation::mainBase(argc, argv, []() { return new AreaEffectSimulation::TestBCContamination; });
|
||||
}
|
||||
Reference in new issue
Block a user