289 lines
8.8 KiB
C++
Executable File
289 lines
8.8 KiB
C++
Executable File
/**
|
|
* EXM Function Topic test executable
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*
|
|
* Created by Hanna E. Rathje, SLSE, 2015-09-10
|
|
*/
|
|
|
|
#include "avm_ft_tests.h"
|
|
|
|
#include <nglapplication/nglcoreapplication.h>
|
|
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
|
#include <QTimer>
|
|
#include <QTest>
|
|
|
|
#include <AudioVideoManagement/avm_ftc.h>
|
|
|
|
//------------------------------------
|
|
namespace AudioVideoManagement
|
|
{
|
|
AvmFtTests::AvmFtTests(QObject *parent)
|
|
: QObject(parent)
|
|
, m_menuStructId(0)
|
|
, m_testId(0)
|
|
, m_mountingPointId(100)
|
|
, m_bTestsSuccessful(true)
|
|
, m_logger(getLogger("FtTest"))
|
|
{
|
|
qRegisterMetaType<Core::FunctionReply>("Core::FunctionReply");
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------
|
|
AvmFtTests::~AvmFtTests()
|
|
{}
|
|
|
|
// ------------------------------------------------------------------------------
|
|
bool AvmFtTests::init(int domainId, int testId, int menuId, int mountingPointId)
|
|
{
|
|
INFO_LOG(m_logger) << "init begin";
|
|
|
|
m_testId = testId;
|
|
m_menuStructId = menuId;
|
|
m_mountingPointId = mountingPointId;
|
|
|
|
m_ddsConnector.reset(new DDSConnector::DdsConnector(domainId, IDL::PartitionType::Any));
|
|
if (!m_ddsConnector->init())
|
|
return false;
|
|
m_ddsConnector->initPublisherSubscriber();
|
|
|
|
DEBUG_LOG(m_logger) << "create ftc AVM";
|
|
m_ftc = AudioVideoManagement::Interface::Ftc::create(m_ddsConnector);
|
|
DEBUG_LOG(m_logger) << "init ftc AVM";
|
|
bool bRet = m_ftc->enableAll();
|
|
DEBUG_LOG(m_logger) << "init end AVM - bRet = " << bRet;
|
|
|
|
DEBUG_LOG(m_logger) << "Domain Id = " << domainId;
|
|
DEBUG_LOG(m_logger) << "Test Id = " << testId;
|
|
|
|
return bRet;
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------
|
|
void AvmFtTests::startTest()
|
|
{
|
|
INFO_LOG(m_logger) << "startTest";
|
|
if (m_testId <= 1)
|
|
QTimer::singleShot(0, this, &AvmFtTests::tryCreate);
|
|
else if (m_testId == 2)
|
|
QTimer::singleShot(0, this, &AvmFtTests::tryModify);
|
|
else if (m_testId == 3)
|
|
QTimer::singleShot(0, this, &AvmFtTests::tryDelete);
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------
|
|
void AvmFtTests::tryCreate()
|
|
{
|
|
INFO_LOG(m_logger) << "trying to send createMenuStructRequest";
|
|
|
|
m_menuStructId = -2;
|
|
ModifyMenuStructRequest request;
|
|
request.id(0);
|
|
request.name("TestGlobalMenu");
|
|
|
|
int newId = -10000000;
|
|
|
|
request.menuEntries().resize(3);
|
|
request.menuEntries()[0].name().set("Test-1");
|
|
request.menuEntries()[0].id(newId++);
|
|
request.menuEntries()[0].parentId(request.id());
|
|
request.menuEntries()[0].isGroup(true);
|
|
|
|
request.menuEntries()[1].mountingPointId(m_mountingPointId);
|
|
request.menuEntries()[1].id(newId++);
|
|
request.menuEntries()[1].parentId(request.menuEntries()[0].id());
|
|
request.menuEntries()[1].isGroup(false);
|
|
|
|
request.menuEntries()[2].mountingPointId(m_mountingPointId+1);
|
|
request.menuEntries()[2].id(newId++);
|
|
request.menuEntries()[2].parentId(request.menuEntries()[0].id());
|
|
request.menuEntries()[2].isGroup(false);
|
|
|
|
if (!m_ftc->modifyMenuStructRequest(request, this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error requesting create data";
|
|
failExit();
|
|
}
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------
|
|
void AvmFtTests::tryModify()
|
|
{
|
|
INFO_LOG(m_logger) << "trying to send modify request for menuStructId = " << m_menuStructId;
|
|
ModifyMenuStructRequest request;
|
|
request.id(m_menuStructId);
|
|
request.name("TestGlobalMenuModify");
|
|
|
|
int newId = -10000000;
|
|
|
|
request.menuEntries().resize(3);
|
|
request.menuEntries()[0].name().set("Test-1-mod");
|
|
request.menuEntries()[0].id(newId++);
|
|
request.menuEntries()[0].parentId(request.id());
|
|
request.menuEntries()[0].isGroup(true);
|
|
|
|
request.menuEntries()[1].mountingPointId(m_mountingPointId);
|
|
request.menuEntries()[1].id(newId++);
|
|
request.menuEntries()[1].parentId(request.menuEntries()[0].id());
|
|
request.menuEntries()[1].isGroup(false);
|
|
|
|
request.menuEntries()[2].mountingPointId(m_mountingPointId+1);
|
|
request.menuEntries()[2].id(newId++);
|
|
request.menuEntries()[2].parentId(request.menuEntries()[0].id());
|
|
request.menuEntries()[2].isGroup(false);
|
|
|
|
if (!m_ftc->modifyMenuStructRequest(request, this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error requesting modify data";
|
|
failExit();
|
|
}
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------
|
|
void AvmFtTests::tryDelete()
|
|
{
|
|
INFO_LOG(m_logger) << "trying to send delete request for menuStructId = " << m_menuStructId;
|
|
RemoveMenuStructRequest request;
|
|
request.id(m_menuStructId);
|
|
|
|
if (!m_ftc->removeMenuStructRequest(request, this))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error requesting delete data";
|
|
failExit();
|
|
}
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------
|
|
void AvmFtTests::onModifyMenuStructReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
if (m_menuStructId == -2)
|
|
createMenuStructReply(replyObject);
|
|
else
|
|
modifyMenuStructReply(replyObject);
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------
|
|
void AvmFtTests::createMenuStructReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
if (replyObject.error())
|
|
{
|
|
ERROR_LOG(m_logger) << "Got onCreateMenuStructReply error: " << replyObject();
|
|
failExit();
|
|
return;
|
|
}
|
|
INFO_LOG(m_logger) << "Got createReply with id " << replyObject.id()
|
|
<< " and errorString " << replyObject.translated();
|
|
m_menuStructId = replyObject.id();
|
|
|
|
DEBUG_LOG(m_logger) << "m_testId = " << m_testId;
|
|
|
|
if(m_testId == 0)
|
|
QTimer::singleShot(0, this, &AvmFtTests::tryModify);
|
|
else
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------
|
|
void AvmFtTests::modifyMenuStructReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
if (replyObject.error())
|
|
{
|
|
ERROR_LOG(m_logger) << "Got onModifyMenuStructReply error: " << replyObject();
|
|
failExit();
|
|
return;
|
|
}
|
|
INFO_LOG(m_logger) << "Got modifyRequest with id " << replyObject.id()
|
|
<< " and errorString " << replyObject.translated();
|
|
if(m_testId == 0)
|
|
QTimer::singleShot(0, this, &AvmFtTests::tryDelete);
|
|
else
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------
|
|
void AvmFtTests::onRemoveMenuStructReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
if (replyObject.error())
|
|
{
|
|
ERROR_LOG(m_logger) << "Got onRemoveMenuStructReply error: " << replyObject();
|
|
failExit();
|
|
return;
|
|
}
|
|
INFO_LOG(m_logger) << "Got removeReply with id " << replyObject.id()
|
|
<< " and errorString " << replyObject.translated();
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------
|
|
void AvmFtTests::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("m") << QLatin1String("menuId")
|
|
, QLatin1String("MenuId.")
|
|
, QLatin1String("will be set during tests")
|
|
, QLatin1String("0")
|
|
} );
|
|
addOption( { QStringList() << QLatin1String("p") << QLatin1String("mountingPointId")
|
|
, QLatin1String("MountingPointId.")
|
|
, QLatin1String("Default 100")
|
|
, QLatin1String("100")
|
|
} );
|
|
}
|
|
|
|
int testId() const { return value(QLatin1String("t")).toInt(); }
|
|
int menuId() const { return value(QLatin1String("m")).toInt(); }
|
|
int mountingPointId() const{ return value(QLatin1String("p")).toInt(); }
|
|
};
|
|
|
|
using namespace AudioVideoManagement;
|
|
|
|
// ------------------------------------------------------------------
|
|
int main(int argc, char **argv)
|
|
{
|
|
NGLCoreApplication app(argc, argv);
|
|
app.createLogger("AVM", "log4cxx_avm.props");
|
|
|
|
int iRet = -1;
|
|
CmdLineParser options;
|
|
if (!options.init())
|
|
return iRet;
|
|
|
|
std::unique_ptr<AvmFtTests> avmFtTests(new AvmFtTests);
|
|
|
|
if(!avmFtTests->init(options.domainId(), options.testId(), options.menuId(), options.mountingPointId()))
|
|
return iRet;
|
|
|
|
QTimer::singleShot(0, avmFtTests.get(), &AvmFtTests::startTest);
|
|
|
|
STARTUP_LOG(app.baseLogger());
|
|
|
|
app.exec();
|
|
iRet = avmFtTests->testsSuccessful() ? 0 : 1;
|
|
fprintf(stderr, "%d\n", iRet);
|
|
|
|
DEBUG_LOG(app.baseLogger()) << "** TEST result = " << iRet;
|
|
|
|
SHUTDOWN_LOG(app.baseLogger());
|
|
|
|
return iRet;
|
|
}
|
|
|