Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,48 @@
|
||||
#
|
||||
# @RDE_HEADER@
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
#
|
||||
|
||||
NGL_ADD_EXECUTABLE(AAR SV NO_TRANSLATION aes_statemachine_test
|
||||
aes_statemachine_test.cpp
|
||||
aes_statemachine_test.h
|
||||
../object_base.cpp
|
||||
../object_base.h
|
||||
../dds_handler.cpp
|
||||
../dds_handler.h
|
||||
../special_area_provider.cpp
|
||||
../special_area_provider.h
|
||||
)
|
||||
|
||||
NGL_TARGET_INCLUDE_DIRECTORIES( aes_statemachine_test
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_BINARY_DIR}/..
|
||||
)
|
||||
|
||||
|
||||
NGL_TARGET_LINK_LIBRARIES(aes_statemachine_test
|
||||
ddsconnector
|
||||
nglcoreapplication
|
||||
svcAesClient
|
||||
svcAesServer
|
||||
svcCesClient
|
||||
svcCoreClient
|
||||
svcPdmClient
|
||||
svcPpmClient
|
||||
svcTabClient
|
||||
svcIsmClient
|
||||
svcAsmClient
|
||||
svcExmClient
|
||||
Qt5::Core
|
||||
Qt5::Test
|
||||
)
|
||||
NGL_TARGET_COMPILE_DEFINITIONS(aes_statemachine_test PRIVATE AES_STATEMACHINE_TEST)
|
||||
IF(TARGET aes_statemachine_test)
|
||||
ADD_TEST(NAME aes_statemachine_test COMMAND $<TARGET_FILE:aes_statemachine_test>)
|
||||
ENDIF()
|
||||
|
||||
ADD_SUBDIRECTORY(UnitTest_Basics)
|
||||
ADD_SUBDIRECTORY(UnitTest_TneAlgo)
|
||||
ADD_SUBDIRECTORY(UnitTest_Polygons)
|
||||
@@ -0,0 +1,29 @@
|
||||
#
|
||||
# @RDE_HEADER@
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
#
|
||||
|
||||
SET(UnitTestSources
|
||||
basics_unit_test.cpp
|
||||
basics_unit_test.h
|
||||
)
|
||||
|
||||
SOURCE_GROUP( UnitTestSources FILES ${UnitTestSources} )
|
||||
|
||||
IF(BUILD_TESTING)
|
||||
ADD_EXECUTABLE(aesUnitTestBasics ${LinkedSources} ${UnitTestSources} )
|
||||
|
||||
TARGET_LINK_LIBRARIES(aesUnitTestBasics
|
||||
NGLLogger
|
||||
nglcoreapplication
|
||||
LtsCoordTrans
|
||||
Qt5::Core
|
||||
Qt5::Test
|
||||
svcAesCommon
|
||||
)
|
||||
|
||||
ADD_TEST(NAME aesUnitTestBasics COMMAND $<TARGET_FILE:aesUnitTestTneAlgorithmen>)
|
||||
|
||||
ENDIF()
|
||||
+427
@@ -0,0 +1,427 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Unittest
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "basics_unit_test.h"
|
||||
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <AreaEffectSimulation/aes.hpp>
|
||||
#include <QtTest/QTest>
|
||||
#include <QTimer>
|
||||
#include <QDebug>
|
||||
#include <QtTest/QSignalSpy>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
||||
using namespace AreaEffectSimulation;
|
||||
|
||||
|
||||
UnitTestBasics::UnitTestBasics()
|
||||
: m_logger(getLogger("UnitTest"))
|
||||
{}
|
||||
|
||||
void UnitTestBasics::test_isNull_isNaN()
|
||||
{
|
||||
QPointF point1(1.1, 1.2);
|
||||
QVERIFY2(point1.isNull() == false, "QPointF isNull failed");
|
||||
|
||||
QPointF point2;
|
||||
QVERIFY2(point2.isNull() == true, "QPointF isNull failed");
|
||||
|
||||
QPointF point3(0, 0);
|
||||
QVERIFY2(point3.isNull() == true, "QPointF isNull failed");
|
||||
|
||||
QPointF point4(1, 2);
|
||||
point4.ry() = 0;
|
||||
QVERIFY2(point4.isNull() == false, "QPointF isNull failed");
|
||||
|
||||
QPointF point5(1, 2);
|
||||
point5.rx() = std::nan("");
|
||||
point5.ry() = std::nan("");
|
||||
|
||||
// !!! nan is not detected be isNull !!!
|
||||
QVERIFY2(point5.isNull() == false, "QPointF isNull failed");
|
||||
|
||||
// Qt::5.14.1: mit isNull() wird NaN nicht erkannt.
|
||||
// Eine separate Prüfung ergibt Sinn!
|
||||
}
|
||||
|
||||
void UnitTestBasics::test_operator_equal_1()
|
||||
{
|
||||
|
||||
// Some cases the operator == recognizes a difference, but i don´t know why.
|
||||
// crate this testCase:
|
||||
|
||||
AesItemView aesItem1, aesItem2;
|
||||
QVERIFY2(aesItem1 == aesItem2, "AesItemView::operator== failed");
|
||||
|
||||
aesItem1.id(1);
|
||||
aesItem2.id(1);
|
||||
QVERIFY2(aesItem1 == aesItem2, "AesItemView::operator== failed");
|
||||
|
||||
|
||||
std::vector<Core::GeoPosition> formVec;
|
||||
formVec.reserve(100);
|
||||
for (int i=1; i< 100; ++i)
|
||||
formVec.emplace_back(Core::GeoPosition(i*0.001, 100/i, 100/i));
|
||||
|
||||
aesItem1.aesItemId(12);
|
||||
aesItem1.sampleTime(12345567);
|
||||
aesItem1.chargeStruct().chargeTypeId(123);
|
||||
aesItem1.effectStart(123456789);
|
||||
aesItem1.form(formVec);
|
||||
aesItem1.boundingBoxBottomLeft(Core::GeoPosition2D(0.1, 0.2));
|
||||
aesItem1.boundingBoxTopRight(Core::GeoPosition2D(1.1, 1.2));
|
||||
aesItem1.aesTypeId(AreaEffectSimulation::AesType_def::AtBoobyTrap);
|
||||
aesItem1.effectStateId(AreaEffectSimulation::AesEffectState_def::EsActivated);
|
||||
aesItem1.partyId(2);
|
||||
|
||||
aesItem1.setId(2334);
|
||||
|
||||
aesItem2 = aesItem1;
|
||||
QVERIFY2(aesItem1 == aesItem2, "AesItemView::operator== failed");
|
||||
}
|
||||
|
||||
void foo(const std::vector<QPoint> &vec)
|
||||
{
|
||||
qCritical() << " foo: number of elements = " << vec.size();
|
||||
|
||||
// copy data to tele
|
||||
|
||||
for (unsigned int i = 0; i < 4; ++i)
|
||||
{
|
||||
int offsetX = -1;
|
||||
int offsetY = -1;
|
||||
|
||||
// qCritical() << " foo: vec.size()-1 = " << vec.size()-1;
|
||||
|
||||
if (i <= vec.size()-1)
|
||||
{
|
||||
offsetX = vec[i].x();
|
||||
offsetY = vec[i].y();
|
||||
}
|
||||
|
||||
// instead of writing data to telegram, use qCritical() to print:
|
||||
qCritical() << " i=" << i
|
||||
<< " # offset [x-y]=" << offsetX << " # " << offsetY;
|
||||
}
|
||||
}
|
||||
|
||||
void UnitTestBasics::test_container()
|
||||
{
|
||||
// Define source data
|
||||
std::vector<QPoint> sourcePointVec;
|
||||
sourcePointVec.push_back(QPoint(1, 1));
|
||||
sourcePointVec.push_back(QPoint(2, 2));
|
||||
|
||||
// call foo
|
||||
foo(sourcePointVec);
|
||||
}
|
||||
|
||||
|
||||
// https://medium.com/@sidbhasin82/c-templates-what-is-std-enable-if-and-how-to-use-it-fd76d3abbabe
|
||||
|
||||
class ObjectBASE
|
||||
{
|
||||
public:
|
||||
int32_t memberBaseINT{0};
|
||||
int32_t getMemberInt() { return 11; }
|
||||
};
|
||||
|
||||
class ObjectINT : public ObjectBASE
|
||||
{
|
||||
public:
|
||||
int32_t memberINT{0};
|
||||
|
||||
int32_t getMemberInt() { return memberINT; }
|
||||
|
||||
};
|
||||
class ObjectDOUBLE : public ObjectBASE
|
||||
{
|
||||
public:
|
||||
double memberDOUBLE{0.0};
|
||||
};
|
||||
|
||||
|
||||
template <class C>
|
||||
class HasRequestId
|
||||
{
|
||||
template <class T>
|
||||
static std::true_type testSignature(const int32_t &(T::*)() const);
|
||||
template <class T>
|
||||
static std::true_type testSignature(int32_t (T::*)() const);
|
||||
|
||||
template <class T>
|
||||
static decltype(testSignature(&T::getMemberInt)) test(std::nullptr_t);
|
||||
|
||||
template <class T>
|
||||
static std::false_type test(...);
|
||||
|
||||
public:
|
||||
using type = decltype(test<C>(nullptr));
|
||||
static const bool value = type::value;
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
struct has_memberDouble {
|
||||
static const bool value = false; //Compile time Constant
|
||||
};
|
||||
template<>
|
||||
struct has_memberDouble<ObjectINT> {
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
|
||||
|
||||
template < typename T, typename std::enable_if < has_memberDouble<T>::value, int >::type = 0 >
|
||||
void getFilterType(const T &obj)
|
||||
{
|
||||
qCritical() << " HasRequestId";
|
||||
// sendErrorInternal(request.errorSlot, reason, request.uniqueId, request.sample.data().requestId());
|
||||
}
|
||||
// -------------------------------------------------------------------------------------------------------------
|
||||
|
||||
template < typename T, typename std::enable_if < !has_memberDouble<T>::value, int >::type = 0 >
|
||||
void getFilterType(const T &obj)
|
||||
{
|
||||
qCritical() << " ! HasRequestId";
|
||||
// sendErrorInternal(request.errorSlot, reason, request.uniqueId, -1);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class worker
|
||||
{
|
||||
public:
|
||||
virtual void do_stuff()
|
||||
{
|
||||
qCritical() << "**** do_stuff: this" << typeid(*this).name();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void UnitTestBasics::test_SFINAE()
|
||||
{
|
||||
worker<ObjectINT> inst1;
|
||||
inst1.do_stuff();
|
||||
|
||||
worker<ObjectDOUBLE> inst2;
|
||||
inst2.do_stuff();
|
||||
|
||||
|
||||
ObjectINT oInt;
|
||||
getFilterType(oInt);
|
||||
|
||||
ObjectDOUBLE oDouble;
|
||||
getFilterType(oDouble);
|
||||
|
||||
}
|
||||
|
||||
void UnitTestBasics::test_fireTimer10()
|
||||
{
|
||||
FiringTimer ft(QStringLiteral("TestEnv10"));
|
||||
|
||||
QStringList logSl = ft.getLogHistorie();
|
||||
QVERIFY2(logSl.size() == 0, "getCommandHistorie failed");
|
||||
|
||||
{
|
||||
bool success = ft.startFiring();
|
||||
QVERIFY2(!success, "startFiring not failed");
|
||||
}
|
||||
|
||||
{
|
||||
ft.init(10*1000, 5, 2.567*1000); // effectDuration, ammoCount, ammoFlightDuration
|
||||
|
||||
bool success = ft.startFiring();
|
||||
QVERIFY2(success, "startFiring failed");
|
||||
success = ft.startFiring();
|
||||
QVERIFY2(!success, "startFiring failed");
|
||||
QStringList logSl1 = ft.getLogHistorie();
|
||||
QVERIFY2(logSl1.size() == 1, "getCommandHistorie failed");
|
||||
|
||||
for (const auto &log : qAsConst(logSl1))
|
||||
NOTICE_LOG(m_logger) << "log ='" << log << "'";
|
||||
}
|
||||
|
||||
{
|
||||
ft.reset();
|
||||
QStringList logSl2 = ft.getLogHistorie();
|
||||
QVERIFY2(logSl2.size() == 0, "getCommandHistorie failed");
|
||||
}
|
||||
}
|
||||
|
||||
void UnitTestBasics::test_fireTimer15()
|
||||
{
|
||||
FiringTimer ft(QStringLiteral("TestEnv15"));
|
||||
|
||||
ft.init(10*1000, 5, 0.0); // effectDurationMsec, ammoFlightDurationMsec
|
||||
|
||||
// count firing
|
||||
QSignalSpy spyFiring(&ft, &FiringTimer::firing);
|
||||
|
||||
ft.startFiring(); // with this, the very first signal 'firing' will be emitted
|
||||
|
||||
// count firingFinished
|
||||
QSignalSpy spyFinished(&ft, &FiringTimer::firingFinished);
|
||||
QSignalSpy spyFinishedPlus(&ft, &FiringTimer::firingFinishedPlus);
|
||||
QSignalSpy spyStateChanged(&ft, &FiringTimer::stateChangeDelayedAsInt);
|
||||
spyFinishedPlus.wait(20000);
|
||||
// call wait twice (wait for CMD_EXPIRED, CMD_EXPIRED_PLUS)
|
||||
spyStateChanged.wait(5000);
|
||||
spyStateChanged.wait(5000);
|
||||
|
||||
// Verify at end:
|
||||
QVERIFY2(spyFiring.count() == 5, "FiringTimer: signalCount failed, spyFiring");
|
||||
QVERIFY2(spyFinished.count() == 1, "FiringTimer: signalCount failed, spyFinished");
|
||||
QVERIFY2(spyFinishedPlus.count() == 1, "FiringTimer: signalCount failed, spyFinishedPlus");
|
||||
QVERIFY2(spyStateChanged.count() == 3, "FiringTimer: signalCount failed, spyStateChanged");
|
||||
|
||||
NOTICE_LOG(m_logger) << " spyStateChanged.count() " << spyStateChanged.count();
|
||||
|
||||
// check order of signal paramter:
|
||||
QVERIFY2(static_cast<FiringTimer::CMD>(spyStateChanged[0][0].toInt()) == FiringTimer::CMD::CMD_START, "FiringTimer: StateChanged.argument failed, spyStateChanged");
|
||||
QVERIFY2(static_cast<FiringTimer::CMD>(spyStateChanged[1][0].toInt()) == FiringTimer::CMD::CMD_EXPIRED, "FiringTimer: StateChanged.argument failed, spyStateChanged");
|
||||
QVERIFY2(static_cast<FiringTimer::CMD>(spyStateChanged[2][0].toInt()) == FiringTimer::CMD::CMD_EXPIRED_PLUS, "FiringTimer: StateChanged.argument failed, spyStateChanged");
|
||||
}
|
||||
|
||||
void UnitTestBasics::test_fireTimer20()
|
||||
{
|
||||
FiringTimer ft(QStringLiteral("TestEnv20"));
|
||||
|
||||
ft.init(10*1000, 5, 2.567*1000); // effectDurationMsec, ammoFlightDurationMsec
|
||||
|
||||
// count firing
|
||||
QSignalSpy spyFiring(&ft, &FiringTimer::firing);
|
||||
|
||||
ft.startFiring(); // with this, the very first signal 'firing' will be emitted
|
||||
|
||||
// count firingFinished
|
||||
QSignalSpy spyFinished(&ft, &FiringTimer::firingFinished);
|
||||
QSignalSpy spyFinishedPlus(&ft, &FiringTimer::firingFinishedPlus);
|
||||
QSignalSpy spyStateChanged(&ft, &FiringTimer::stateChangeDelayedAsInt);
|
||||
spyFinishedPlus.wait(20000);
|
||||
// call wait twice (wait for CMD_EXPIRED, CMD_EXPIRED_PLUS)
|
||||
spyStateChanged.wait(5000);
|
||||
spyStateChanged.wait(5000);
|
||||
|
||||
// Verify at end:
|
||||
QVERIFY2(spyFiring.count() == 5, "FiringTimer: signalCount failed, spyFiring");
|
||||
QVERIFY2(spyFinished.count() == 1, "FiringTimer: signalCount failed, spyFinished");
|
||||
QVERIFY2(spyFinishedPlus.count() == 1, "FiringTimer: signalCount failed, spyFinishedPlus");
|
||||
QVERIFY2(spyStateChanged.count() == 3, "FiringTimer: signalCount failed, spyStateChanged");
|
||||
|
||||
// QList<QVariant> arguments = spyStateChanged.takeFirst(); // take the first signal
|
||||
// NOTICE_LOG(m_logger) << " spyStateChanged.count() " << spyStateChanged.count();
|
||||
// for (const QList<QVariant> &argument : qAsConst(spyStateChanged))
|
||||
// NOTICE_LOG(m_logger) << " spyStateChanged . argument " << argument.first().toInt();
|
||||
|
||||
// check order of signal paramter:
|
||||
QVERIFY2(static_cast<FiringTimer::CMD>(spyStateChanged[0][0].toInt()) == FiringTimer::CMD::CMD_START, "FiringTimer: StateChanged.argument failed, spyStateChanged");
|
||||
QVERIFY2(static_cast<FiringTimer::CMD>(spyStateChanged[1][0].toInt()) == FiringTimer::CMD::CMD_EXPIRED, "FiringTimer: StateChanged.argument failed, spyStateChanged");
|
||||
QVERIFY2(static_cast<FiringTimer::CMD>(spyStateChanged[2][0].toInt()) == FiringTimer::CMD::CMD_EXPIRED_PLUS, "FiringTimer: StateChanged.argument failed, spyStateChanged");
|
||||
}
|
||||
|
||||
void UnitTestBasics::test_fireTimer21()
|
||||
{
|
||||
FiringTimer ft(QStringLiteral("TestEnv21"));
|
||||
|
||||
ft.init(10*1000, 5, 2.567*1000); // effectDuration, ammoCount, ammoFlightDuration
|
||||
|
||||
ft.startFiring();
|
||||
|
||||
QTimer::singleShot(3000, this, [this, &ft]() {
|
||||
NOTICE_LOG(m_logger) << " trigger pauseFiring...";
|
||||
ft.pauseFiring();
|
||||
});
|
||||
|
||||
QSignalSpy spyFinished(&ft, &FiringTimer::firingFinished);
|
||||
QSignalSpy spyFinishedPlus(&ft, &FiringTimer::firingFinishedPlus);
|
||||
QSignalSpy spyStateChanged(&ft, &FiringTimer::stateChangeDelayedAsInt);
|
||||
spyFinishedPlus.wait(10000);
|
||||
// call wait twice (wait for CMD_EXPIRED, CMD_EXPIRED_PLUS)
|
||||
spyStateChanged.wait(5000);
|
||||
spyStateChanged.wait(5000);
|
||||
|
||||
|
||||
// Verify at end:
|
||||
QVERIFY2(spyFinished.count() == 0, "FiringTimer: signalCount failed, spyFinished");
|
||||
QVERIFY2(spyFinishedPlus.count() == 0, "FiringTimer: signalCount failed, spyFinishedPlus");
|
||||
QVERIFY2(spyStateChanged.count() == 2, "FiringTimer: signalCount failed, spyStateChanged");
|
||||
|
||||
// check order of signal paramter:
|
||||
QVERIFY2(static_cast<FiringTimer::CMD>(spyStateChanged[0][0].toInt()) == FiringTimer::CMD::CMD_START, "FiringTimer: StateChanged.argument failed, spyStateChanged");
|
||||
QVERIFY2(static_cast<FiringTimer::CMD>(spyStateChanged[1][0].toInt()) == FiringTimer::CMD::CMD_PAUSE, "FiringTimer: StateChanged.argument failed, spyStateChanged");
|
||||
// !! no finished !!
|
||||
}
|
||||
|
||||
void UnitTestBasics::test_fireTimer22()
|
||||
{
|
||||
FiringTimer ft(QStringLiteral("TestEnv22"));
|
||||
|
||||
ft.init(10*1000, 5, 3.000*1000); // effectDuration, ammoCount, ammoFlightDuration
|
||||
|
||||
// count firing
|
||||
QSignalSpy spyFiring(&ft, &FiringTimer::firing);
|
||||
|
||||
ft.startFiring();
|
||||
|
||||
// !! Attention: do pauseFiring() WITHIN the intervall will reduce amount of time the firing is active !!
|
||||
QTimer::singleShot(3000, this, [this, &ft]() {
|
||||
NOTICE_LOG(m_logger) << " trigger pauseFiring...";
|
||||
ft.pauseFiring();
|
||||
});
|
||||
|
||||
QTimer::singleShot(5123, this, [this, &ft]() {
|
||||
NOTICE_LOG(m_logger) << " trigger (re)StartFiring / Resume ...";
|
||||
ft.startFiring();
|
||||
});
|
||||
|
||||
|
||||
QSignalSpy spyFinished(&ft, &FiringTimer::firingFinished);
|
||||
QSignalSpy spyFinishedPlus(&ft, &FiringTimer::firingFinishedPlus);
|
||||
QSignalSpy spyStateChanged(&ft, &FiringTimer::stateChangeDelayedAsInt);
|
||||
spyFinishedPlus.wait(20000);
|
||||
// call wait twice (wait for CMD_EXPIRED, CMD_EXPIRED_PLUS)
|
||||
spyStateChanged.wait(5000);
|
||||
spyStateChanged.wait(5000);
|
||||
|
||||
// Verify at end:
|
||||
QVERIFY2(spyFiring.count() == 5, "FiringTimer: signalCount failed, spyFiring");
|
||||
QVERIFY2(spyFinished.count() == 1, "FiringTimer: signalCount failed, spyFinished");
|
||||
QVERIFY2(spyFinishedPlus.count() == 1, "FiringTimer: signalCount failed, spyFinishedPlus");
|
||||
QVERIFY2(spyStateChanged.count() == 5, "FiringTimer: signalCount failed, spyStateChanged");
|
||||
|
||||
// check order of signal paramter:
|
||||
QVERIFY2(static_cast<FiringTimer::CMD>(spyStateChanged[0][0].toInt()) == FiringTimer::CMD::CMD_START, "FiringTimer: StateChanged.argument failed, spyStateChanged");
|
||||
QVERIFY2(static_cast<FiringTimer::CMD>(spyStateChanged[1][0].toInt()) == FiringTimer::CMD::CMD_PAUSE, "FiringTimer: StateChanged.argument failed, spyStateChanged");
|
||||
QVERIFY2(static_cast<FiringTimer::CMD>(spyStateChanged[2][0].toInt()) == FiringTimer::CMD::CMD_RESUME, "FiringTimer: StateChanged.argument failed, spyStateChanged");
|
||||
QVERIFY2(static_cast<FiringTimer::CMD>(spyStateChanged[3][0].toInt()) == FiringTimer::CMD::CMD_EXPIRED, "FiringTimer: StateChanged.argument failed, spyStateChanged");
|
||||
QVERIFY2(static_cast<FiringTimer::CMD>(spyStateChanged[4][0].toInt()) == FiringTimer::CMD::CMD_EXPIRED_PLUS, "FiringTimer: StateChanged.argument failed, spyStateChanged");
|
||||
|
||||
|
||||
// !! Attention: do pauseFiring() WITHIN the intervall will reduce amount of time the firing is active !!
|
||||
// stop firing2 after [ms]: 5999, m_activeMsec in total = 8902, m_pausedMsec in total = 2000
|
||||
// ^^^^ maybe you expect 10000
|
||||
// !! Attention: do pauseFiring() WITHIN the intervall will reduce amount of time the firing is active !!
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
app.createLogger("UnitTest_TNE-ALOG", "log4cxxUnitTest.props");
|
||||
|
||||
UnitTestBasics tc;
|
||||
return QTest::qExec(&tc, argc, argv);
|
||||
}
|
||||
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Unittest
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <../../logger.h>
|
||||
#include <QCoreApplication>
|
||||
#include <QtTest/QTest>
|
||||
#include <AreaEffectSimulation/Utils/firing_timer.h>
|
||||
|
||||
|
||||
|
||||
class UnitTestBasics : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
UnitTestBasics();
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
// void init();
|
||||
|
||||
void test_isNull_isNaN();
|
||||
|
||||
void test_operator_equal_1();
|
||||
|
||||
void test_container();
|
||||
|
||||
void test_SFINAE();
|
||||
|
||||
|
||||
void test_fireTimer10();
|
||||
|
||||
void test_fireTimer15();
|
||||
|
||||
void test_fireTimer20();
|
||||
void test_fireTimer21();
|
||||
void test_fireTimer22();
|
||||
|
||||
|
||||
// void cleanup();
|
||||
|
||||
private:
|
||||
AreaEffectSimulation::LOGGER_T &m_logger;
|
||||
};
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#
|
||||
# @RDE_HEADER@
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
#
|
||||
|
||||
SET(UnitTestSources
|
||||
polygons_unit_test.cpp
|
||||
polygons_unit_test.h
|
||||
)
|
||||
|
||||
SOURCE_GROUP( UnitTestSources FILES ${UnitTestSources} )
|
||||
|
||||
IF(BUILD_TESTING)
|
||||
ADD_EXECUTABLE(aesUnitTestPolygons ${LinkedSources} ${UnitTestSources} )
|
||||
|
||||
TARGET_LINK_LIBRARIES(aesUnitTestPolygons
|
||||
NGLLogger
|
||||
nglcoreapplication
|
||||
LtsCoordTrans
|
||||
Qt5::Core
|
||||
Qt5::Test
|
||||
svcAesCommon
|
||||
)
|
||||
|
||||
ADD_TEST(NAME aesUnitTestPolygons COMMAND $<TARGET_FILE:aesUnitTestTneAlgorithmen>)
|
||||
|
||||
ENDIF()
|
||||
+308
@@ -0,0 +1,308 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Unittest
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "polygons_unit_test.h"
|
||||
#include <Services/AreaEffectSimulation/Utils/polygons.h>
|
||||
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
#include <QTransform>
|
||||
#include <QTextStream> //
|
||||
#include <QtTest/QTest>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace AreaEffectSimulation;
|
||||
|
||||
double distanceMeter(const LtsCoordTrans::UtmCoordinate utmCoord1, const LtsCoordTrans::UtmCoordinate &utmCoord2)
|
||||
{
|
||||
double dist = LtsCoordTrans::distance(utmCoord1, utmCoord2);
|
||||
qCritical() << " dist" << dist;
|
||||
return dist;
|
||||
}
|
||||
|
||||
double distanceMeter(const QPointF &geoCoord1, const LtsCoordTrans::UtmCoordinate &utmCoord2)
|
||||
{
|
||||
const LtsCoordTrans::UtmCoordinate &utmCoord1 = LtsCoordTrans::UtmCoordinate::fromGeographic(geoCoord1);
|
||||
double dist = LtsCoordTrans::distance(utmCoord1, utmCoord2);
|
||||
qCritical() << " dist" << dist;
|
||||
return dist;
|
||||
}
|
||||
|
||||
|
||||
void UnitTestPolygons::test_QTrans()
|
||||
{
|
||||
QPolygonF poly;
|
||||
poly.reserve(3);
|
||||
poly.append(QPointF(0, 0));
|
||||
poly.append(QPointF(1, 0));
|
||||
poly.append(QPointF(2, 0));
|
||||
|
||||
//rotate
|
||||
{
|
||||
QTransform trans;
|
||||
trans.rotate(90);
|
||||
|
||||
QPolygonF poly2a = trans.map(poly);
|
||||
qCritical() << "poly2a = " << poly2a;
|
||||
|
||||
QVERIFY2(poly2a.first() == QPointF(0, 0), "QTransform failed");
|
||||
QVERIFY2(poly2a.last() == QPointF(0, 2), "QTransform failed; vec.last()");
|
||||
}
|
||||
|
||||
{
|
||||
QPolygonF poly2b = QTransform().rotate(90).map(poly); // squence in a single line
|
||||
|
||||
qCritical() << "poly2b = " << poly2b;
|
||||
|
||||
QVERIFY2(poly2b.first() == QPointF(0, 0), "QTransform failed");
|
||||
QVERIFY2(poly2b.last() == QPointF(0, 2), "QTransform failed; vec.last()");
|
||||
}
|
||||
}
|
||||
|
||||
void printAbl(const Polygons::AreaBottomLeft &obj)
|
||||
{
|
||||
qCritical() << " AreaBottomLeft = "
|
||||
<< ", cornerBL=" << obj.m_cornerBottomLeft
|
||||
<< ", m_width=" << obj.m_width
|
||||
<< ", m_height=" << obj.m_height
|
||||
<< ", m_height=" << obj.m_height;
|
||||
}
|
||||
|
||||
|
||||
void UnitTestPolygons::test_explosionClusterAddTla()
|
||||
{
|
||||
double width = 1000; // x
|
||||
double height = 100; // y
|
||||
double rotation_deg = 0;
|
||||
const Polygons::AreaBottomLeft boundaryOrg(QPointF(123, 123), width, height, rotation_deg);
|
||||
printAbl(boundaryOrg);
|
||||
|
||||
|
||||
{
|
||||
int zog = 0;
|
||||
const Polygons::AreaBottomLeft areaBlWithZog = Polygons::explosionClusterAddTla(boundaryOrg, zog);
|
||||
printAbl(areaBlWithZog);
|
||||
QVERIFY2(areaBlWithZog.m_cornerBottomLeft == boundaryOrg.m_cornerBottomLeft, "m_cornerBottomLeft failed");
|
||||
QVERIFY2(areaBlWithZog.m_width == boundaryOrg.m_width, "m_width failed");
|
||||
QVERIFY2(areaBlWithZog.m_height == boundaryOrg.m_height, "m_height failed");
|
||||
QVERIFY2(areaBlWithZog.m_rotation_deg == boundaryOrg.m_rotation_deg, "m_rotation_deg failed");
|
||||
}
|
||||
|
||||
{
|
||||
int zog = 10;
|
||||
const Polygons::AreaBottomLeft areaBlWithZog = Polygons::explosionClusterAddTla(boundaryOrg, zog);
|
||||
printAbl(areaBlWithZog);
|
||||
QVERIFY2(areaBlWithZog.m_cornerBottomLeft == QPointF(113, 113), "m_cornerBottomLeft failed");
|
||||
QVERIFY2(areaBlWithZog.m_width == boundaryOrg.m_width+(2*zog), "m_width failed");
|
||||
QVERIFY2(areaBlWithZog.m_height == boundaryOrg.m_height+(2*zog), "m_height failed");
|
||||
QVERIFY2(areaBlWithZog.m_rotation_deg == boundaryOrg.m_rotation_deg, "m_rotation_deg failed");
|
||||
}
|
||||
|
||||
{
|
||||
double rotation_deg = 30;
|
||||
const Polygons::AreaBottomLeft boundaryOrgRot(QPointF(123, 123), width, height, rotation_deg);
|
||||
int zog = 10;
|
||||
const Polygons::AreaBottomLeft areaBlWithZog = Polygons::explosionClusterAddTla(boundaryOrgRot, zog);
|
||||
printAbl(areaBlWithZog);
|
||||
|
||||
QVERIFY2((areaBlWithZog.m_cornerBottomLeft - QPointF(109.34, 119.34)).manhattanLength() < 1, "m_cornerBottomLeft failed");
|
||||
QVERIFY2(areaBlWithZog.m_width == boundaryOrgRot.m_width+(2*zog), "m_width failed");
|
||||
QVERIFY2(areaBlWithZog.m_height == boundaryOrgRot.m_height+(2*zog), "m_height failed");
|
||||
QVERIFY2(areaBlWithZog.m_rotation_deg == boundaryOrgRot.m_rotation_deg, "m_rotation_deg failed");
|
||||
}
|
||||
}
|
||||
|
||||
void UnitTestPolygons::test_explosionClusterAreaToMtpsRelativeToBottomLeft_noRotation()
|
||||
{
|
||||
double width = 1000; // x
|
||||
double height = 100; // y
|
||||
double rotation_deg = 0;
|
||||
const Polygons::AreaBottomLeft boundary(QPointF(123, 123), width, height, rotation_deg);
|
||||
|
||||
const int numberOfMTPs = 4;
|
||||
double singleWidthOut = 0;
|
||||
double singleHeightOut = 0;
|
||||
|
||||
QVector<QPointF> vec = Polygons::explosionClusterAreaToMtpsRelativeToBottomLeft(boundary, numberOfMTPs, &singleWidthOut, &singleHeightOut);
|
||||
|
||||
qCritical() << "vec = " << vec;
|
||||
qCritical() << "singleWidthOut = " << singleWidthOut;
|
||||
qCritical() << "singleHeightOut = " << singleHeightOut;
|
||||
|
||||
// independent on rotation
|
||||
QVERIFY2(vec.size() == numberOfMTPs, "noRotation failed; numberOfMTPs");
|
||||
QVERIFY2(singleWidthOut == width/4, "noRotation failed; singleWidthOut");
|
||||
QVERIFY2(singleHeightOut == height, "noRotation failed; singleHeightOut");
|
||||
|
||||
// depending on rotation
|
||||
QVERIFY2(vec.first() == QPointF(125.0, 50), "noRotation failed");
|
||||
QVERIFY2(vec[1] == QPointF(375.0, 50), "noRotation failed");
|
||||
QVERIFY2(vec[2] == QPointF(625.0, 50), "noRotation failed");
|
||||
QVERIFY2(vec.last() == QPointF(875.0, 50), "noRotation failed");
|
||||
}
|
||||
|
||||
void UnitTestPolygons::test_explosionClusterAreaToMtpsRelativeToBottomLeft_withRotation()
|
||||
{
|
||||
double width = 1000; // x
|
||||
double height = 100; // y
|
||||
double rotation_deg = -90;
|
||||
const Polygons::AreaBottomLeft boundary(QPointF(123, 123), width, height, rotation_deg);
|
||||
|
||||
const int numberOfMTPs = 4;
|
||||
double singleWidthOut = 0;
|
||||
double singleHeightOut = 0;
|
||||
|
||||
QVector<QPointF> vec = Polygons::explosionClusterAreaToMtpsRelativeToBottomLeft(boundary, numberOfMTPs, &singleWidthOut, &singleHeightOut);
|
||||
|
||||
qCritical() << "vec = " << vec;
|
||||
qCritical() << "singleWidthOut = " << singleWidthOut;
|
||||
qCritical() << "singleHeightOut = " << singleHeightOut;
|
||||
|
||||
// independent on rotation
|
||||
QVERIFY2(vec.size() == numberOfMTPs, "withRotation failed; numberOfMTPs");
|
||||
QVERIFY2(singleWidthOut == width/4, "withRotation failed; singleWidthOut");
|
||||
QVERIFY2(singleHeightOut == height, "withRotation failed; singleHeightOut");
|
||||
|
||||
// depending on rotation
|
||||
QVERIFY2(vec.first() == QPointF(-50, 125), "withRotation failed");
|
||||
QVERIFY2(vec[1] == QPointF(-50, 375), "withRotation failed");
|
||||
QVERIFY2(vec[2] == QPointF(-50, 625), "withRotation failed");
|
||||
QVERIFY2(vec.last() == QPointF(-50, 875), "withRotation failed");
|
||||
}
|
||||
|
||||
void UnitTestPolygons::test_explosionClusterSingleExplosionsGAUSS_Mtp()
|
||||
{
|
||||
Database::AesExplosionCluster explosionClusterDb;
|
||||
|
||||
double width = 1000; // x
|
||||
double height = 100; // y
|
||||
double rotation_deg = 0;
|
||||
|
||||
LtsCoordTrans::UtmCoordinate UTM = LtsCoordTrans::UtmCoordinate::fromMgrs(QLatin1String("32UMD100000100000")); // 32U MD 100000 100000
|
||||
|
||||
const Polygons::AreaBottomLeft boundary(UTM.geographic(), width, height, rotation_deg);
|
||||
|
||||
explosionClusterDb.id = 1;
|
||||
|
||||
explosionClusterDb.impactPosition = boundary.m_cornerBottomLeft;
|
||||
explosionClusterDb.impactLength = boundary.m_height;
|
||||
explosionClusterDb.impactWidth = boundary.m_width;
|
||||
explosionClusterDb.rotationAngle = boundary.m_rotation_deg;
|
||||
|
||||
explosionClusterDb.zog = 0;
|
||||
|
||||
explosionClusterDb.impactCount = 8;
|
||||
explosionClusterDb.mhpCountRequest = 4;
|
||||
|
||||
// rotation = 0
|
||||
{
|
||||
double mtpRotationNorthDegree = explosionClusterDb.rotationAngle;
|
||||
const QVector<QPointF> &singleExplosions = Polygons::explosionClusterSingleExplosionsGAUSS_Mtp(explosionClusterDb, mtpRotationNorthDegree);
|
||||
|
||||
qCritical() << "rotation_deg = " << rotation_deg
|
||||
<< ", mtpRotationNorthDegree = " << mtpRotationNorthDegree
|
||||
<< ", explosionClusterDb = " << singleExplosions;
|
||||
for (const auto &singleExplosion : qAsConst(singleExplosions))
|
||||
qDebug() << "singleExUtm: " << LtsCoordTrans::UtmCoordinate::fromGeographic(singleExplosion).mgrs();
|
||||
|
||||
size_t i = 0;
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 10029 10048"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 10298 10042"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 10682 10046"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 10908 10055"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 10101 10076"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 10386 10022"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 10581 10032"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 10828 10065"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
}
|
||||
|
||||
// rotation = -90
|
||||
rotation_deg = -90;
|
||||
const Polygons::AreaBottomLeft boundary2(UTM.geographic(), width, height, rotation_deg);
|
||||
|
||||
explosionClusterDb.id = 1;
|
||||
|
||||
explosionClusterDb.impactPosition = boundary2.m_cornerBottomLeft;
|
||||
explosionClusterDb.impactLength = boundary2.m_height;
|
||||
explosionClusterDb.impactWidth = boundary2.m_width;
|
||||
explosionClusterDb.rotationAngle = boundary2.m_rotation_deg;
|
||||
{
|
||||
double mtpRotationNorthDegree = explosionClusterDb.rotationAngle;
|
||||
const QVector<QPointF> &singleExplosions = Polygons::explosionClusterSingleExplosionsGAUSS_Mtp(explosionClusterDb, mtpRotationNorthDegree);
|
||||
|
||||
qCritical() << "rotation_deg = " << rotation_deg
|
||||
<< ", mtpRotationNorthDegree = " << mtpRotationNorthDegree
|
||||
<< " explosionClusterDb = " << singleExplosions;
|
||||
for (const auto &singleExplosion : qAsConst(singleExplosions))
|
||||
qCritical() << "singleExUtm: " << LtsCoordTrans::UtmCoordinate::fromGeographic(singleExplosion).mgrs();
|
||||
|
||||
size_t i = 0;
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 09952 10029"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 09958 10298"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 09954 10682"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 09945 10908"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 09924 10101"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 09978 10386"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 09968 10581"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 09935 10828"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
}
|
||||
|
||||
// rotation = -45
|
||||
rotation_deg = -45;
|
||||
int zog = 100;
|
||||
|
||||
const Polygons::AreaBottomLeft boundary3(UTM.geographic(), width, height, rotation_deg);
|
||||
|
||||
explosionClusterDb.id = 1;
|
||||
|
||||
explosionClusterDb.impactPosition = boundary3.m_cornerBottomLeft;
|
||||
explosionClusterDb.impactLength = boundary3.m_height;
|
||||
explosionClusterDb.impactWidth = boundary3.m_width;
|
||||
explosionClusterDb.rotationAngle = boundary3.m_rotation_deg;
|
||||
|
||||
explosionClusterDb.zog = zog;
|
||||
{
|
||||
double mtpRotationNorthDegree = explosionClusterDb.rotationAngle;
|
||||
const QVector<QPointF> &singleExplosions = Polygons::explosionClusterSingleExplosionsGAUSS_Mtp(explosionClusterDb, mtpRotationNorthDegree);
|
||||
|
||||
qCritical() << "rotation_deg = " << rotation_deg
|
||||
<< ", zog = " << zog
|
||||
<< ", mtpRotationNorthDegree = " << mtpRotationNorthDegree
|
||||
<< " explosionClusterDb = " << singleExplosions;
|
||||
for (const auto &singleExplosion : qAsConst(singleExplosions))
|
||||
qCritical() << "singleExUtm: " << LtsCoordTrans::UtmCoordinate::fromGeographic(singleExplosion).mgrs();
|
||||
|
||||
size_t i = 0;
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 09923 09984"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 10164 10200"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 10480 10536"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 10654 10746"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 09925 10104"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 10281 10233"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 10426 10419"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
QVERIFY2(distanceMeter(singleExplosions[i++], LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 10565 10699"))) < 1, "ERROR, distanceMeter failed!!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
app.createLogger("UnitTest_TNE-ALOG", "log4cxxUnitTest.props");
|
||||
|
||||
UnitTestPolygons tc;
|
||||
return QTest::qExec(&tc, argc, argv);
|
||||
}
|
||||
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Unittest
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QtTest/QTest>
|
||||
|
||||
|
||||
|
||||
class UnitTestPolygons : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
// void init();
|
||||
|
||||
void test_QTrans();
|
||||
void test_explosionClusterAddTla();
|
||||
void test_explosionClusterAreaToMtpsRelativeToBottomLeft_noRotation();
|
||||
void test_explosionClusterAreaToMtpsRelativeToBottomLeft_withRotation();
|
||||
|
||||
void test_explosionClusterSingleExplosionsGAUSS_Mtp();
|
||||
|
||||
// void cleanup();
|
||||
|
||||
private:
|
||||
};
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#
|
||||
# @RDE_HEADER@
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
#
|
||||
|
||||
SET(UnitTestSources
|
||||
tne_algo_unit_test.cpp
|
||||
tne_algo_unit_test.h
|
||||
)
|
||||
|
||||
SOURCE_GROUP( UnitTestSources FILES ${UnitTestSources} )
|
||||
|
||||
IF(BUILD_TESTING)
|
||||
ADD_EXECUTABLE(aesUnitTestTneAlgorithmen ${LinkedSources} ${UnitTestSources} )
|
||||
|
||||
TARGET_LINK_LIBRARIES(aesUnitTestTneAlgorithmen
|
||||
NGLLogger
|
||||
nglcoreapplication
|
||||
Qt5::Core
|
||||
Qt5::Test
|
||||
svcAesCommon
|
||||
)
|
||||
|
||||
ADD_TEST(NAME aesUnitTestTneAlgorithmen COMMAND $<TARGET_FILE:aesUnitTestTneAlgorithmen>)
|
||||
|
||||
ENDIF()
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Unittest
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "tne_algo_unit_test.h"
|
||||
#include <Services/AreaEffectSimulation/Utils/tne_algorithmen.h>
|
||||
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <QtTest/QTest>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace AreaEffectSimulation;
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// This class is an UnitTest with values taken from the TNE.
|
||||
// That was created while Michael Moetje was implementing that code at the TNE (PlayerUnit)
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
void UnitTestVerteilung::test_long()
|
||||
{
|
||||
int size = sizeof(int);
|
||||
std::cout << " sizeof 'int' " << size << std::endl;
|
||||
|
||||
size = sizeof(long);
|
||||
std::cout << " sizeof 'long' " << size << std::endl;
|
||||
|
||||
size = sizeof(long long);
|
||||
std::cout << " sizeof 'long long' " << size << std::endl;
|
||||
|
||||
size = sizeof(qint32);
|
||||
std::cout << " sizeof 'qint32g' " << size << std::endl;
|
||||
}
|
||||
|
||||
void UnitTestVerteilung::test_xorshift32()
|
||||
{
|
||||
// 1
|
||||
ULONG pxInOut = 123;
|
||||
|
||||
ushort ret = TNE_ALGORITHMEN::xorshift32(&pxInOut);
|
||||
std::cout << " test_xorshift32 ret: " << ret << std::endl;
|
||||
QVERIFY2(ret == 28668, "xorshift32 failed");
|
||||
}
|
||||
|
||||
void UnitTestVerteilung::test_xorshift32_nv()
|
||||
{
|
||||
ULONG _generator = 123;
|
||||
short _bereich = 500;
|
||||
|
||||
// _generator = 123, _bereich = 500 => laut Moetje: -73, 93, -79, -321, -25
|
||||
|
||||
int ret = TNE_ALGORITHMEN::xorshift32_nv(&_generator, _bereich, 3);
|
||||
std::cout << " xorshift32_nv ret: " << ret << std::endl;
|
||||
QVERIFY2(ret == -73, "xorshift32_nv failed");
|
||||
|
||||
ret = TNE_ALGORITHMEN::xorshift32_nv(&_generator, _bereich, 3);
|
||||
std::cout << " xorshift32_nv ret: " << ret << std::endl;
|
||||
QVERIFY2(ret == 93, "xorshift32_nv failed");
|
||||
|
||||
ret = TNE_ALGORITHMEN::xorshift32_nv(&_generator, _bereich, 3);
|
||||
std::cout << " xorshift32_nv ret: " << ret << std::endl;
|
||||
QVERIFY2(ret == -79, "xorshift32_nv failed");
|
||||
|
||||
ret = TNE_ALGORITHMEN::xorshift32_nv(&_generator, _bereich, 3);
|
||||
std::cout << " xorshift32_nv ret: " << ret << std::endl;
|
||||
QVERIFY2(ret == -321, "xorshift32_nv failed");
|
||||
|
||||
ret = TNE_ALGORITHMEN::xorshift32_nv(&_generator, _bereich, 3);
|
||||
std::cout << " xorshift32_nv ret: " << ret << std::endl;
|
||||
QVERIFY2(ret == -25, "xorshift32_nv failed");
|
||||
}
|
||||
|
||||
void UnitTestVerteilung::test_xorshift32_nv_saveToFile()
|
||||
{
|
||||
ULONG _generator = 123;
|
||||
SHORT _bereich = 500;
|
||||
|
||||
QString tempDir = QDir::tempPath();
|
||||
QFile file(tempDir + QDir::separator() + QStringLiteral("tne_algorithmen_xorshift32_nv_data.txt"));
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
return;
|
||||
|
||||
QTextStream out(&file);
|
||||
|
||||
out << "Test vom Algorithmus 'xorshift32_nv'" << "\n";
|
||||
out << "_generator = " << _generator << "\n";
|
||||
out << "_bereich = " << _bereich << "\n";
|
||||
out << " Start " << "\n";
|
||||
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
out << "_generator = " << _generator;
|
||||
|
||||
int ret = TNE_ALGORITHMEN::xorshift32_nv(&_generator, _bereich, 3);
|
||||
std::cout << " test_xorshift32_nv ret: " << ret << std::endl;
|
||||
|
||||
out << " -> erzeugter Wert = " << ret << "\n";
|
||||
}
|
||||
out << "Ende :-)" << "\n";
|
||||
}
|
||||
|
||||
void UnitTestVerteilung::test_areaExlosionGAUSS()
|
||||
{
|
||||
const int wirkfeldKennung = 4711;
|
||||
const int breite_m = 500; // Vielfaches von 5m
|
||||
const int tiefe_m = 50; // Vielfaches von 5m
|
||||
const int anzahl_einschlaege = 10;
|
||||
|
||||
QVector<QPointF> impacts = TNE_ALGORITHMEN::areaExlosionsGAUSS(wirkfeldKennung,
|
||||
breite_m, tiefe_m,
|
||||
anzahl_einschlaege);
|
||||
|
||||
QVERIFY2(impacts.size() == anzahl_einschlaege, "test_areaExlosionGAUSS failed");
|
||||
|
||||
QVERIFY2(impacts[0] == QPointF(206, 29), "test_areaExlosionGAUSS failed");
|
||||
QVERIFY2(impacts[1] == QPointF(252, 42), "test_areaExlosionGAUSS failed");
|
||||
QVERIFY2(impacts[2] == QPointF(110, 21), "test_areaExlosionGAUSS failed");
|
||||
QVERIFY2(impacts[3] == QPointF(209, 32), "test_areaExlosionGAUSS failed");
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
app.createLogger("UnitTest_TNE-ALOG", "log4cxxUnitTest.props");
|
||||
|
||||
UnitTestVerteilung tc;
|
||||
return QTest::qExec(&tc, argc, argv);
|
||||
}
|
||||
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Unittest
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QtTest/QTest>
|
||||
|
||||
|
||||
|
||||
using ULONG = quint32;
|
||||
using LONG = qint32;
|
||||
using SHORT = qint32;
|
||||
|
||||
|
||||
/**
|
||||
* @brief This class is an UnitTest with values taken from the TNE.
|
||||
* That was created while Michael Moetje was implementing that code at the TNE (PlayerUnit)
|
||||
*/
|
||||
class UnitTestVerteilung : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
// void init();
|
||||
|
||||
void test_long();
|
||||
|
||||
void test_xorshift32();
|
||||
void test_xorshift32_nv();
|
||||
void test_xorshift32_nv_saveToFile();
|
||||
|
||||
void test_areaExlosionGAUSS();
|
||||
|
||||
|
||||
// void cleanup();
|
||||
|
||||
private:
|
||||
};
|
||||
@@ -0,0 +1,150 @@
|
||||
/**
|
||||
* Unittest for testing the statemachine for aes objects
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "aes_statemachine_test.h"
|
||||
#include <QDebug>
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
|
||||
using namespace AreaEffectSimulation;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
app.createLogger("StateMachineTest", "log4cxx_AreaEffectSimulation.props");
|
||||
|
||||
StateMachineTest *test = new StateMachineTest;
|
||||
int retCode = QTest::qExec(test, argc, argv);
|
||||
delete test;
|
||||
|
||||
return retCode;
|
||||
}
|
||||
|
||||
namespace QTest
|
||||
{
|
||||
template<>
|
||||
char *toString(const AesEffectState &s) { std::ostringstream str; str << s; return strdup(str.str().c_str()); }
|
||||
}
|
||||
|
||||
DummyAesObject::DummyAesObject(QObject *parent)
|
||||
: ObjectBaseTmpl(nullptr, QStringLiteral("DummyAesObject"), parent)
|
||||
{}
|
||||
|
||||
QPolygonF DummyAesObject::generateForm()
|
||||
{
|
||||
return QPolygonF();
|
||||
}
|
||||
|
||||
StateMachineTest::StateMachineTest()
|
||||
: m_dummyAesObject(new DummyAesObject(this))
|
||||
{}
|
||||
|
||||
StateMachineTest::~StateMachineTest()
|
||||
{
|
||||
delete m_dummyAesObject;
|
||||
}
|
||||
|
||||
void StateMachineTest::staticTests()
|
||||
{
|
||||
const time_t tNow = time(nullptr);
|
||||
|
||||
// newly created, nothing set -> checkEnterNewState() should switch to created
|
||||
QCOMPARE(m_dummyAesObject->checkEnterNewState().underlying(), AesEffectState::EsCreated);
|
||||
|
||||
// now we set a activation time -> Prepared
|
||||
m_dummyAesObject->setActivationTime(tNow + 5);
|
||||
QCOMPARE(m_dummyAesObject->checkEnterNewState().underlying(), AesEffectState::EsPrepared);
|
||||
|
||||
// now back to created
|
||||
m_dummyAesObject->setActivationTime(0);
|
||||
QCOMPARE(m_dummyAesObject->checkEnterNewState().underlying(), AesEffectState::EsCreated);
|
||||
|
||||
// directly to activated
|
||||
m_dummyAesObject->setActivationTime(tNow);
|
||||
QCOMPARE(m_dummyAesObject->checkEnterNewState().underlying(), AesEffectState::EsActivated);
|
||||
|
||||
// pause not possible
|
||||
m_dummyAesObject->setSupportsPausing(false);
|
||||
QCOMPARE(m_dummyAesObject->trySwitchToPaused(), false);
|
||||
|
||||
// now possible
|
||||
m_dummyAesObject->setSupportsPausing(true);
|
||||
QCOMPARE(m_dummyAesObject->trySwitchToPaused(), true);
|
||||
|
||||
// and back to activated
|
||||
QCOMPARE(m_dummyAesObject->isActivationTimeReached(), true); // sanity
|
||||
QCOMPARE(m_dummyAesObject->trySwitchToActivated(), true);
|
||||
|
||||
// set end time
|
||||
m_dummyAesObject->setActivationTime(tNow);
|
||||
m_dummyAesObject->setDurationSec(1);
|
||||
|
||||
// wait 1.5sec (100 * QTest::qWait(15))
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
QTest::qWait(15);
|
||||
}
|
||||
QCOMPARE(m_dummyAesObject->checkEnterNewState().underlying(), AesEffectState::EsExpired);
|
||||
|
||||
// try to delete it
|
||||
QCOMPARE(m_dummyAesObject->trySwitchToRemoved(), false);
|
||||
m_dummyAesObject->setActivationTime(0);
|
||||
m_dummyAesObject->setDurationSec(0);
|
||||
m_dummyAesObject->setAesEffectState(AesEffectState::EsUnknown);
|
||||
QCOMPARE(m_dummyAesObject->trySwitchToRemoved(), false);
|
||||
m_dummyAesObject->setAesEffectState(AesEffectState::EsCreated);
|
||||
QCOMPARE(m_dummyAesObject->trySwitchToRemoved(), true);
|
||||
m_dummyAesObject->setAesEffectState(AesEffectState::EsPaused);
|
||||
QCOMPARE(m_dummyAesObject->trySwitchToRemoved(), true);
|
||||
// an active/paused object must not set to deleted but to expired
|
||||
QCOMPARE(m_dummyAesObject->effectState().underlying(), AesEffectState::EsExpired);
|
||||
QCOMPARE(m_dummyAesObject->trySwitchToCreated(), false);
|
||||
}
|
||||
|
||||
void StateMachineTest::dynamicTests()
|
||||
{
|
||||
const time_t tNow = time(nullptr);
|
||||
|
||||
QSignalSpy spy(m_dummyAesObject, &DummyAesObject::effectStateChanged);
|
||||
|
||||
m_dummyAesObject->setAesEffectState(AesEffectState::EsUnknown);
|
||||
// set activation time
|
||||
m_dummyAesObject->setActivationTime(tNow + 1);
|
||||
QCOMPARE(m_dummyAesObject->isActivationTimeSet(), true);
|
||||
|
||||
// set end time
|
||||
m_dummyAesObject->setDurationSec(2);
|
||||
QCOMPARE(m_dummyAesObject->isEndTimeSet(), true);
|
||||
|
||||
QCOMPARE(m_dummyAesObject->checkEnterNewState().underlying(), AesEffectState::EsPrepared);
|
||||
QCOMPARE(spy.count(), 2); // Created, Prepared
|
||||
spy.clear();
|
||||
|
||||
qDebug() << "Waiting for activation time";
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
QTest::qWait(15); // wait until the object is Activated
|
||||
if (m_dummyAesObject->effectState() == AesEffectState::EsActivated)
|
||||
break;
|
||||
}
|
||||
QCOMPARE(m_dummyAesObject->effectState().underlying(), AesEffectState::EsActivated);
|
||||
|
||||
qDebug() << "Waiting for end time";
|
||||
for (int i = 0; i < 200; ++i)
|
||||
{
|
||||
QTest::qWait(15); // wait until the object is Expired
|
||||
if (m_dummyAesObject->effectState() == AesEffectState::EsExpired)
|
||||
break;
|
||||
}
|
||||
AreaEffectSimulation::AesEffectState state = m_dummyAesObject->effectState();
|
||||
QCOMPARE(state.underlying(), AesEffectState::EsExpired);
|
||||
|
||||
QCOMPARE(spy.count(), 2); // Activated, Done
|
||||
spy.clear();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Unittest for testing the statemachine for aes objects
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AreaEffectSimulation/object_base.h>
|
||||
|
||||
namespace AreaEffectSimulation
|
||||
{
|
||||
class DummyAesObject final: public ObjectBaseTmpl<Database::AesNContamination>
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DummyAesObject(QObject *parent = nullptr);
|
||||
|
||||
void setAesEffectState(AesEffectState newState) { m_data.effectStateId = newState; }
|
||||
void setSupportsPausing(bool bSupportsPausing) { m_bSupportsPausing = bSupportsPausing; }
|
||||
void setActivationTime(time_t actTime)
|
||||
{
|
||||
if (actTime)
|
||||
m_data.effectStart = QDateTime::fromMSecsSinceEpoch(actTime * 1000LL);
|
||||
else
|
||||
m_data.effectStart = QDateTime();
|
||||
}
|
||||
void setDurationSec(int durationSec)
|
||||
{
|
||||
m_data.effectDuration = durationSec * 1000;
|
||||
}
|
||||
qint64 partitionTimeMSec() const override
|
||||
{
|
||||
return partitionTime().toMSecsSinceEpoch();
|
||||
}
|
||||
QDateTime partitionTime() const override
|
||||
{
|
||||
return QDateTime::currentDateTimeUtc();
|
||||
}
|
||||
std::vector<Core::GeoPosition> form() const override { return {}; }
|
||||
QPolygonF generateForm() override;
|
||||
AesType aesType() const override { return AesType::AtUnknown; }
|
||||
bool isCentral() const override { return m_data.isCentral; }
|
||||
};
|
||||
|
||||
class StateMachineTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
StateMachineTest();
|
||||
~StateMachineTest();
|
||||
private Q_SLOTS:
|
||||
void staticTests();
|
||||
void dynamicTests();
|
||||
|
||||
private:
|
||||
DummyAesObject *m_dummyAesObject;
|
||||
};
|
||||
} // namespace AreaEffectSimulation
|
||||
Reference in new issue
Block a user