Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+186
@@ -0,0 +1,186 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* SRP Data Topic test executable
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*
|
||||
* Created by Hanna E. Rathje, SLSE, 2015-09-11
|
||||
*/
|
||||
|
||||
#include "srp_dt_tests.h"
|
||||
|
||||
#include <nglapplication/nglcoreapplication.h>
|
||||
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
||||
#include <QTimer>
|
||||
|
||||
#include <SituationReplay/srp_dtc.h>
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
namespace SituationReplay
|
||||
{
|
||||
SrpDtTests::SrpDtTests(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_replayPartitionId(0)
|
||||
, m_situationReplayId(0)
|
||||
, m_bTestsSuccessful(true)
|
||||
, m_logger(getLogger("DtTest"))
|
||||
{
|
||||
qRegisterMetaType<Core::FunctionReply>("Core::FunctionReply");
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
SrpDtTests::~SrpDtTests()
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
bool SrpDtTests::init(int domainId, int replayPartitionId)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "init begin";
|
||||
m_replayPartitionId = replayPartitionId;
|
||||
|
||||
// initialize DDS
|
||||
m_ddsConnector.reset(new DDSConnector::DdsConnector(domainId, IDL::PartitionType::Replay, replayPartitionId));
|
||||
if (!m_ddsConnector->init())
|
||||
return false;
|
||||
|
||||
// Subscribe on replayPartition - default = true in this DdsSubscriber
|
||||
|
||||
// DdsInterface Subscriber
|
||||
m_ddsConnector->initSubscriber();
|
||||
|
||||
// DdsInterface Publisher
|
||||
//m_ddsConnector->setPublisher(new Publisher(domainId, m_ddsConnector->getPartition(), m_ddsConnector->getDomainParticipant()));
|
||||
|
||||
DEBUG_LOG(m_logger) << "Create dtc";
|
||||
m_dtc = SituationReplay::Interface::Dtc::create(m_ddsConnector);
|
||||
DEBUG_LOG(m_logger) << "Init dtc";
|
||||
bool bRet = m_dtc->enableAll();
|
||||
DEBUG_LOG(m_logger) << "init end - bRet = " << bRet;
|
||||
|
||||
connect(m_dtc.get(), &SituationReplay::Interface::Dtc::sitReplayChanged,
|
||||
this, &SrpDtTests::onReceiveSituationReplayData);
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
void SrpDtTests::startTest()
|
||||
{
|
||||
INFO_LOG(m_logger) << "startTest";
|
||||
QTimer::singleShot(1000, this, &SrpDtTests::tryGetAllSituationReplays);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
void SrpDtTests::tryGetAllSituationReplays()
|
||||
{
|
||||
INFO_LOG(m_logger) << "trying to get all situationReplays";
|
||||
const QMap<qint32, SituationReplay::SitReplay> map = m_dtc->sitReplays();
|
||||
if (map.isEmpty())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error requesting all situation replay data";
|
||||
failExit();
|
||||
}
|
||||
else
|
||||
{
|
||||
INFO_LOG(m_logger) << "Amout of existing situation replays = " << map.size();
|
||||
m_situationReplayId = map.firstKey();
|
||||
for(auto it = map.begin(); it != map.end(); ++it)
|
||||
INFO_LOG(m_logger) << "situationReplay(" << it.key() << ") : " << it.value().replayPartitionId() ;
|
||||
}
|
||||
|
||||
QTimer::singleShot(10, this, &SrpDtTests::tryGetSituationReplay);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
void SrpDtTests::tryGetSituationReplay()
|
||||
{
|
||||
INFO_LOG(m_logger) << "trying get itemData for situationReplay " << m_situationReplayId;
|
||||
SituationReplay::SitReplay data = m_dtc->sitReplay(m_situationReplayId);
|
||||
|
||||
if (data.id() <= 0)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error receiving data for situation replay " << m_situationReplayId;
|
||||
failExit();
|
||||
}
|
||||
else
|
||||
{
|
||||
INFO_LOG(m_logger) << "## SitReplay(" << data.id() << "), replayPartition: " << data.replayPartitionId()
|
||||
<< ", on exercise " << data.exerciseId();
|
||||
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
void SrpDtTests::onReceiveSituationReplayData(const SituationReplay::SitReplay &data)
|
||||
{
|
||||
if (m_situationReplayId == data.id())
|
||||
INFO_LOG(m_logger) << "##################### Data for id = " << data.id() << " received";
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
void SrpDtTests::failExit()
|
||||
{
|
||||
m_bTestsSuccessful = false;
|
||||
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
class CmdLineParser : public LtsCommandLineParser::LtsCommandLineParser
|
||||
{
|
||||
public:
|
||||
CmdLineParser()
|
||||
: LtsCommandLineParser()
|
||||
{
|
||||
addOption( { QStringList() << QLatin1String("p") << QLatin1String("replay-partition-id")
|
||||
, QLatin1String("ReplayPartitionId (required).")
|
||||
, QLatin1String("> 0")
|
||||
, QLatin1String("1")
|
||||
} );
|
||||
|
||||
addHelpOption();
|
||||
}
|
||||
|
||||
int replayPartitionId() const { return isSet(QLatin1String("p")) ? value(QLatin1String("p")).toInt() : -1; }
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
NGLCoreApplication app(argc, argv);
|
||||
app.createLogger("SRP", "log4cxx_srp.props");
|
||||
|
||||
int iRet = -1;
|
||||
CmdLineParser options;
|
||||
if (!options.init())
|
||||
return -1;
|
||||
|
||||
if (options.replayPartitionId() <= 0)
|
||||
{
|
||||
ERROR_LOG(app.baseLogger()) << "Required parameter p: (replay) partitionId ";
|
||||
options.showHelp();
|
||||
return -2;
|
||||
}
|
||||
|
||||
std::unique_ptr<SituationReplay::SrpDtTests> srpDtTests(new SituationReplay::SrpDtTests);
|
||||
|
||||
if(!srpDtTests->init(options.domainId(), options.replayPartitionId()))
|
||||
return iRet;
|
||||
|
||||
QTimer::singleShot(0, srpDtTests.get(), &SituationReplay::SrpDtTests::startTest);
|
||||
|
||||
STARTUP_LOG(app.baseLogger());
|
||||
|
||||
app.exec();
|
||||
iRet = srpDtTests->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