Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+323
@@ -0,0 +1,323 @@
|
||||
/**
|
||||
* Asm Function Topic Module Test
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "asm_tests.h"
|
||||
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
||||
#include <QTimer>
|
||||
#include <QTest>
|
||||
|
||||
#include <AssetManagement/asm_ftc.h>
|
||||
|
||||
/* ----------------------------------------------------------------------------------
|
||||
* HOW TO RUN THE TESTS (example)
|
||||
* ----------------------------------------------------------------------------------
|
||||
* 0. Preconditions:
|
||||
*
|
||||
* ./asmTests -t 1 // Create
|
||||
* ./asmTests -t 2 -a 7 // Modify TraingAreaId = 7
|
||||
* ./asmTests -t 3 -a 7 // Delete TraingAreaId = 7
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
namespace AssetManagement
|
||||
{
|
||||
AsmTests::AsmTests(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_trainingAreaId(0)
|
||||
, m_testId(0)
|
||||
, m_bTestsSuccessful(true)
|
||||
, m_logger(getLogger("Test"))
|
||||
{
|
||||
qRegisterMetaType<Core::FunctionReply>("Core::FunctionReply");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
AsmTests::~AsmTests()
|
||||
{}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
bool AsmTests::init(int domainId, int trainingAreaId, int testId)
|
||||
{
|
||||
INFO_LOG(m_logger) << "init begin";
|
||||
|
||||
m_testId = testId;
|
||||
m_trainingAreaId = trainingAreaId; // overwritten when new exercise created
|
||||
|
||||
m_ddsConnector.reset(new DDSConnector::DdsConnector(domainId, IDL::PartitionType::Any));
|
||||
if (!m_ddsConnector->init())
|
||||
{
|
||||
failExit();
|
||||
return false;
|
||||
}
|
||||
m_ddsConnector->initPublisherSubscriber();
|
||||
|
||||
DEBUG_LOG(m_logger) << "create ftc";
|
||||
m_ftc = AssetManagement::Interface::Ftc::create(m_ddsConnector);
|
||||
DEBUG_LOG(m_logger) << "init ftc";
|
||||
bool bRet = m_ftc->enableAll();
|
||||
DEBUG_LOG(m_logger) << "init end - bRet = " << bRet;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Domain Id = " << domainId;
|
||||
DEBUG_LOG(m_logger) << "Training Area Id = " << trainingAreaId;
|
||||
DEBUG_LOG(m_logger) << "Test Id = " << testId;
|
||||
|
||||
if (!bRet)
|
||||
failExit();
|
||||
return bRet;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
void AsmTests::startTest()
|
||||
{
|
||||
INFO_LOG(m_logger) << "startTest";
|
||||
if (m_testId == 1)
|
||||
QTimer::singleShot(0, this, &AsmTests::tryCreate);
|
||||
else if (m_testId == 2)
|
||||
QTimer::singleShot(0, this, &AsmTests::tryModify);
|
||||
else if (m_testId == 3)
|
||||
QTimer::singleShot(0, this, &AsmTests::tryDelete);
|
||||
else
|
||||
failExit();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
void AsmTests::setRequestData(AssetManagement::TrainingAreaModifyRequest &request , int modId)
|
||||
{
|
||||
AssetManagement::MapDescription mapDescription;
|
||||
std::vector<uint8_t> imageVector(0);
|
||||
std::vector<AssetManagement::MapDescription> map2D_param;
|
||||
std::vector<AssetManagement::MapDescription> scene3D_param;
|
||||
std::vector<AssetManagement::MapDescription> elevation_param;
|
||||
std::vector<AssetManagement::MapDescription> sceneObjects_param;
|
||||
|
||||
mapDescription.name("Topographic 01");
|
||||
mapDescription.description("Description_01");
|
||||
mapDescription.isDeleted(false);
|
||||
mapDescription.mapTypeId(AssetManagement::MapType_def::Topographic);
|
||||
mapDescription.mapDescriptionTypeId(AssetManagement::MapDescriptionType::Map2D);
|
||||
mapDescription.maxScale(20.0);
|
||||
mapDescription.minScale(0.5);
|
||||
if (modId > 0)
|
||||
{
|
||||
mapDescription.trainingAreaId(modId);
|
||||
mapDescription.url("URL1 modified");
|
||||
}
|
||||
else
|
||||
mapDescription.url("URL1 initial");
|
||||
|
||||
map2D_param.resize(2);
|
||||
map2D_param[0] = mapDescription;
|
||||
|
||||
mapDescription.name("Topographic 02");
|
||||
mapDescription.description("Description_02");
|
||||
if (modId > 0)
|
||||
{
|
||||
mapDescription.trainingAreaId(modId);
|
||||
mapDescription.url("URL2 modified");
|
||||
}
|
||||
else
|
||||
mapDescription.url("URL2 initial");
|
||||
|
||||
map2D_param[1] = mapDescription;
|
||||
request.map2D(map2D_param);
|
||||
|
||||
scene3D_param.resize(1);
|
||||
mapDescription.mapTypeId(AssetManagement::MapType_def::Topographic);
|
||||
mapDescription.mapDescriptionTypeId(AssetManagement::MapDescriptionType::Scene3D);
|
||||
mapDescription.description("Description_03");
|
||||
mapDescription.name("Scene3D");
|
||||
if (modId > 0)
|
||||
{
|
||||
mapDescription.trainingAreaId(modId);
|
||||
mapDescription.url("URL3 modified");
|
||||
}
|
||||
else
|
||||
mapDescription.url("URL3 initial");
|
||||
scene3D_param[0] = mapDescription;
|
||||
request.scene3D(scene3D_param);
|
||||
|
||||
if (modId == 0)
|
||||
{
|
||||
elevation_param.resize(1);
|
||||
mapDescription.mapTypeId(AssetManagement::MapType_def::Elevation);
|
||||
mapDescription.mapDescriptionTypeId(AssetManagement::MapDescriptionType::Elevation);
|
||||
mapDescription.url("URL4 initial");
|
||||
mapDescription.description("Description_04");
|
||||
mapDescription.name("Elevation");
|
||||
elevation_param[0] = mapDescription;
|
||||
request.elevation(elevation_param);
|
||||
|
||||
sceneObjects_param.resize(1);
|
||||
mapDescription.mapTypeId(AssetManagement::MapType_def::SceneObjects);
|
||||
mapDescription.mapDescriptionTypeId(AssetManagement::MapDescriptionType::SceneObj);
|
||||
mapDescription.url("URL5 initial");
|
||||
mapDescription.description("Description_05");
|
||||
mapDescription.name("SceneObjects");
|
||||
sceneObjects_param[0] = mapDescription;
|
||||
request.sceneObjects(sceneObjects_param);
|
||||
|
||||
request.id(0);
|
||||
request.name("TestTrainingAreaCreate");
|
||||
request.bottomLeft(Core::GeoPosition2D(11.61/180*M_PI, 53.07/180*M_PI));
|
||||
request.height(100000);
|
||||
request.width(100000);
|
||||
request.image(imageVector);
|
||||
}
|
||||
else
|
||||
{
|
||||
request.id(m_trainingAreaId);
|
||||
request.name("TestTrainingAreaModified");
|
||||
request.bottomLeft(Core::GeoPosition2D(11.61/180*M_PI, 53.07/180*M_PI));
|
||||
request.height(140000);
|
||||
request.width(120000);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
void AsmTests::tryCreate()
|
||||
{
|
||||
INFO_LOG(m_logger) << "trying to send ModifyRequest TrainingArea (create)";
|
||||
|
||||
AssetManagement::TrainingAreaModifyRequest request;
|
||||
|
||||
setRequestData(request, 0);
|
||||
|
||||
if (!m_ftc->trainingAreaModifyRequest(request, this))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error requesting create data";
|
||||
failExit();
|
||||
}
|
||||
|
||||
QTest::qWait(1000);
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
void AsmTests::tryModify()
|
||||
{
|
||||
AssetManagement::TrainingAreaModifyRequest request;
|
||||
INFO_LOG(m_logger) << "trying to send modify request for training Area Id = " << m_trainingAreaId;
|
||||
|
||||
setRequestData(request, m_trainingAreaId);
|
||||
|
||||
if (!m_ftc->trainingAreaModifyRequest(request, this))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error requesting modify data";
|
||||
failExit();
|
||||
}
|
||||
|
||||
QTest::qWait(1000);
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
void AsmTests::tryDelete()
|
||||
{
|
||||
INFO_LOG(m_logger) << "trying to send delete request for exercise Id = " << m_trainingAreaId;
|
||||
if (!m_ftc->trainingAreaRemoveRequest(TrainingAreaRemoveRequest(m_trainingAreaId), this))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error requesting delete data";
|
||||
failExit();
|
||||
}
|
||||
|
||||
QTest::qWait(1000);
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
void AsmTests::onTrainingAreaModifyReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Got modifyReply with id " << replyObject.id()
|
||||
<< " and errorString " << replyObject.translated();
|
||||
|
||||
if (replyObject.error())
|
||||
failExit();
|
||||
|
||||
m_trainingAreaId = replyObject.id();
|
||||
|
||||
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
void AsmTests::onTrainingAreaRemoveReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Got removeReply with id " << replyObject.id()
|
||||
<< " and errorString " << replyObject.translated();
|
||||
|
||||
if (replyObject.error())
|
||||
failExit();
|
||||
|
||||
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
void AsmTests::failExit()
|
||||
{
|
||||
m_bTestsSuccessful = false;
|
||||
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
||||
}
|
||||
|
||||
} //end namespace
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
class CmdLineParser : public LtsCommandLineParser::LtsCommandLineParser
|
||||
{
|
||||
public:
|
||||
CmdLineParser()
|
||||
: LtsCommandLineParser()
|
||||
{
|
||||
addOption( { QStringList() << QLatin1String("t") << QLatin1String("testId")
|
||||
, QLatin1String("TestId.")
|
||||
, QLatin1String("Default: 0 (all tests)")
|
||||
, QLatin1String("0")
|
||||
} );
|
||||
|
||||
addOption( { QStringList() << QLatin1String("a") << QLatin1String("trainingAreaId")
|
||||
, QLatin1String("TrainingAreaId.")
|
||||
, QLatin1String("Default: 0 (Unknown)")
|
||||
, QLatin1String("0")
|
||||
} );
|
||||
}
|
||||
|
||||
int testId() const { return isSet(QLatin1String("t")) ? value(QLatin1String("t")).toInt() : 0; }
|
||||
int trainingAreaId() const { return isSet(QLatin1String("a")) ? value(QLatin1String("a")).toInt() : 0; }
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
app.createLogger("ASM", 0 );
|
||||
|
||||
int iRet = -1;
|
||||
CmdLineParser options;
|
||||
if (!options.init())
|
||||
return iRet;
|
||||
|
||||
std::unique_ptr<AssetManagement::AsmTests> AsmTests(new AssetManagement::AsmTests);
|
||||
|
||||
if(!AsmTests->init(options.domainId(), options.trainingAreaId(), options.testId()))
|
||||
return iRet;
|
||||
|
||||
QTimer::singleShot(0, AsmTests.get(), &AssetManagement::AsmTests::startTest);
|
||||
|
||||
STARTUP_LOG(app.baseLogger());
|
||||
|
||||
app.exec();
|
||||
|
||||
iRet = AsmTests->testsSuccessful() ? 0 : 1;
|
||||
fprintf(stderr, "%d\n", iRet);
|
||||
|
||||
DEBUG_LOG(app.baseLogger()) << "** TEST result = " << iRet;
|
||||
|
||||
SHUTDOWN_LOG(app.baseLogger());
|
||||
|
||||
return iRet;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user