/** * EXM Function Topic test executable * $Id$ * $HeadURL$ * $Author$ * * Created by Hanna E. Rathje, SLSE, 2015-09-10 */ #include "pre_tests.h" #include #include #include #include #include namespace PresentationManagement { //---------------------------------------------------------------------------------- PreTests::PreTests(QObject *parent) : QObject(parent) , m_exerciseId(0) , m_testId(0) , m_presentationId(0) , m_bTestsSuccessful(true) , m_logger(getLogger("Test")) { qRegisterMetaType("Core::FunctionReply"); } //---------------------------------------------------------------------------------- bool PreTests::init(int domainId, int exerciseId, int testId, int presentationId) { INFO_LOG(m_logger) << "init begin"; m_testId = testId; m_exerciseId = exerciseId; m_presentationId = presentationId; // initialize DDS m_ddsConnector.reset(new DDSConnector::DdsConnector(domainId, IDL::PartitionType::Exercise, m_exerciseId)); if (!m_ddsConnector->init()) return false; DEBUG_LOG(m_logger) << "DdsHandler(" << domainId << ") for partition: " << m_ddsConnector->getDefaultPartition(); m_ddsConnector->initPublisherSubscriber(); DEBUG_LOG(m_logger) << "create ftc PRE"; m_ftc = PresentationManagement::Interface::Ftc::create(m_ddsConnector); DEBUG_LOG(m_logger) << "init ftc PRE"; bool bRet = m_ftc->enableAll(); DEBUG_LOG(m_logger) << "init end PRE - bRet = " << bRet; DEBUG_LOG(m_logger) << "Domain Id = " << domainId; DEBUG_LOG(m_logger) << "Exercise Id = " << exerciseId; DEBUG_LOG(m_logger) << "Test Id = " << testId; //TODO: add connects return bRet; } //---------------------------------------------------------------------------------- void PreTests::startTest() { INFO_LOG(m_logger) << "startTest"; switch (m_testId) { case 1: tryCreate(); break; case 2: tryModify(); break; case 3: tryGetContent(); break; case 4: tryDelete(); break; case 5: tryChangeStatus(); break; default: ERROR_LOG(m_logger) << "Unknown test case !"; failExit(); break; } INFO_LOG(m_logger) << "********* endTest **************"; QTimer::singleShot(0, qApp, &QCoreApplication::quit); } //---------------------------------------------------------------------------------- void PreTests::tryCreate() { INFO_LOG(m_logger) << "trying to send createRequest Presentation"; m_presentationId = -1; PresentationModifyRequest request; request.name("Test Presentation"); request.description("Description Presentation"); request.operatorId(100); request.lastModified(QDateTime(QDate(2017,2,14), QTime(9,34)).toMSecsSinceEpoch()); std::vector vectorPc; vectorPc.resize(2); vectorPc[0].presentationTopicType("pdf"); vectorPc[0].channel("1V"); vectorPc[0].duration(30); vectorPc[0].startTime(QDateTime(QDate(2017,2,13), QTime(12,34)).toMSecsSinceEpoch()); vectorPc[1].presentationTopicType("text"); vectorPc[1].channel("2V"); vectorPc[1].duration(30); vectorPc[1].startTime(QDateTime(QDate(2017,2,14), QTime(9,45)).toMSecsSinceEpoch()); request.content(vectorPc); if (!m_ftc->presentationModifyRequest(request, this)) { ERROR_LOG(m_logger) << "Error requesting create data"; failExit(); } QTest::qWait(1000); } //---------------------------------------------------------------------------------- void PreTests::tryModify() { PresentationModifyRequest request; request.id(m_presentationId); request.name("Presentation Modify"); request.description("Description Presentation Modify"); request.operatorId(102); request.lastModified(QDateTime(QDate(2017,2,16), QTime(10,34)).toMSecsSinceEpoch()); std::vector &vectorPc = request.content(); vectorPc.resize(2); vectorPc[0].presentationTopicType("pdf"); vectorPc[0].channel("1V2"); vectorPc[0].duration(60); vectorPc[0].startTime(QDateTime(QDate(2017,2,13), QTime(12,34)).toMSecsSinceEpoch()); vectorPc[1].presentationTopicType("text"); vectorPc[1].channel("2V"); vectorPc[1].duration(60); vectorPc[1].startTime(QDateTime(QDate(2017,2,14), QTime(9,45)).toMSecsSinceEpoch()); INFO_LOG(m_logger) << "trying to send modify request for presentation Id = " << m_presentationId; if (!m_ftc->presentationModifyRequest(request, this)) { ERROR_LOG(m_logger) << "Error requesting modify data"; failExit(); } QTest::qWait(1000); } //---------------------------------------------------------------------------------- void PreTests::tryDelete() { PresentationRemoveRequest request; request.id(m_presentationId); INFO_LOG(m_logger) << "trying to send delete request for presentation Id = " << m_presentationId; if (!m_ftc->presentationRemoveRequest(request, this)) { ERROR_LOG(m_logger) << "Error requesting delete data"; failExit(); } } //---------------------------------------------------------------------------------- void PreTests::tryGetContent() { GetPresentationContentRequest request; request.presentationId(m_presentationId); INFO_LOG(m_logger) << "trying to send content request for presentation Id = " << m_presentationId; if (!m_ftc->getPresentationContentRequest(request, this)) { ERROR_LOG(m_logger) << "Error requesting content for presentationId: " << m_presentationId; failExit(); } QTest::qWait(1000); } //---------------------------------------------------------------------------------- void PreTests::tryChangeStatus() { PresentationChangeStatusRequest request; request.id(m_presentationId); request.operatorId(101); request.lastModified(QDateTime::currentMSecsSinceEpoch()); request.fileStatus(FileStatus::Deleted); INFO_LOG(m_logger) << "trying to send change status request for presentation Id = " << m_presentationId; if (!m_ftc->presentationChangeStatusRequest(request, this)) { ERROR_LOG(m_logger) << "Error requesting change status"; failExit(); } QTest::qWait(1000); } //---------------------------------------------------------------------------------- void PreTests::failExit() { ERROR_LOG(m_logger) << "FAIL EXIT !"; m_bTestsSuccessful = false; QTimer::singleShot(0, qApp, &QCoreApplication::quit); } //---------------------------------------------------------------------------------- void PreTests::onPresentationCreateReply(const Core::FunctionReplyObject &replyObject) { DEBUG_LOG(m_logger) << "END (onPresentationCreateReply)"; if (replyObject.error()) { ERROR_LOG(m_logger) << "Got onPresentationCreateReply error: " << replyObject(); QTimer::singleShot(0, qApp, &QCoreApplication::quit); return; } INFO_LOG(m_logger) << "Got createReply with id " << replyObject.id() << " and errorString " << replyObject.translated(); m_presentationId = replyObject.id(); if(m_testId == 0) QTimer::singleShot(0, this, &PreTests::tryModify); else QTimer::singleShot(0, qApp, &QCoreApplication::quit); } //---------------------------------------------------------------------------------- void PreTests::onPresentationModifyReply(const Core::FunctionReplyObject &replyObject) { if (m_presentationId == -1) return onPresentationCreateReply(replyObject); DEBUG_LOG(m_logger) << "END (onPresentationModifyReply)"; if (replyObject.error()) { ERROR_LOG(m_logger) << "Got onPresentationModifyReply error: " << replyObject(); QTimer::singleShot(0, qApp, &QCoreApplication::quit); return; } INFO_LOG(m_logger) << "Got createReply with id " << replyObject.id() << " and errorString " << replyObject.translated(); m_presentationId = replyObject.id(); if(m_testId == 0) QTimer::singleShot(0, this, &PreTests::tryChangeStatus); else QTimer::singleShot(0, qApp, &QCoreApplication::quit); } //---------------------------------------------------------------------------------- void PreTests::onPresentationChangeStatusReply(const Core::FunctionReplyObject &replyObject) { DEBUG_LOG(m_logger) << "END (onPresentationChangeStatusReply)"; if (replyObject.error()) { ERROR_LOG(m_logger) << "Got onPresentationChangeStatusReply error: " << replyObject(); QTimer::singleShot(0, qApp, &QCoreApplication::quit); return; } INFO_LOG(m_logger) << "Got changeStatusReply with id " << replyObject.id() << " and errorString " << replyObject.translated(); m_presentationId = replyObject.id(); if(m_testId == 0) QTimer::singleShot(0, this, &PreTests::tryGetContent); else QTimer::singleShot(0, qApp, &QCoreApplication::quit); } //---------------------------------------------------------------------------------- void PreTests::onPresentationRemoveReply(const Core::FunctionReplyObject &replyObject) { DEBUG_LOG(m_logger) << "END (onPresentationRemoveReply)"; if (replyObject.error()) { ERROR_LOG(m_logger) << "Got onPresentationRemoveReply error: " << replyObject(); QTimer::singleShot(0, qApp, &QCoreApplication::quit); return; } INFO_LOG(m_logger) << "Got reply with id " << replyObject.id() << " and errorString " << replyObject.translated(); QTimer::singleShot(0, qApp, &QCoreApplication::quit); } //---------------------------------------------------------------------------------- void PreTests::onGetPresentationContentReply(const GetPresentationContentReply &replyObject) { DEBUG_LOG(m_logger) << "END (onGetPresentationContentReply)"; if (replyObject.errorString().size() > 0) { ERROR_LOG(m_logger) << "Got onGetPresentationContentReply error: " << replyObject.errorString(); QTimer::singleShot(0, qApp, &QCoreApplication::quit); return; } INFO_LOG(m_logger) << "Got reply with id " << replyObject.id() << " and errorString " << replyObject.errorString() << " and content size " << replyObject.content().size(); if(m_testId == 0) QTimer::singleShot(0, this, &PreTests::tryDelete); else QTimer::singleShot(0, qApp, &QCoreApplication::quit); } } // ------------------------------------------------------------------ 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("p") << QLatin1String("presentationId") , QLatin1String("PresentationId") , QLatin1String("Default: 0 ") , QLatin1String("0") } ); } int testId() const { return isSet(QLatin1String("t")) ? value(QLatin1String("t")).toInt() : -1; } int presentationId() const { return isSet(QLatin1String("p")) ? value(QLatin1String("p")).toInt() : -1; } }; // ------------------------------------------------------------------ int main(int argc, char **argv) { int iRet = -1; NGLCoreApplication app(argc, argv); app.createLogger("PRE", 0); CmdLineParser options; if (!options.init()) return iRet; std::unique_ptr PreTests(new PresentationManagement::PreTests); if (!PreTests->init(options.domainId(), options.exerciseId(), options.testId(), options.presentationId())) return iRet; QTimer::singleShot(0, PreTests.get(), &PresentationManagement::PreTests::startTest); STARTUP_LOG(app.baseLogger()); app.exec(); iRet = PreTests->testsSuccessful() ? 0 : 1; fprintf(stderr, "\n%d\n\n", iRet); INFO_LOG(app.baseLogger()) << "** TEST result = " << iRet; SHUTDOWN_LOG(app.baseLogger()); return iRet; }