/** * @RDE_HEADER@ * SRP Data Topic test executable * $Id$ * $HeadURL$ * $Author$ */ #include "pdm_tests.h" #include #include #include #include //--------------------------------------------------------------------------------- namespace ProjectDataManagement { PdmTests::PdmTests(QObject *parent) : QObject(parent) , m_id(0) , m_testId(0) , m_bTestsSuccessful(true) , m_logger(getLogger("Test")) { qRegisterMetaType("Core::FunctionReply"); } //--------------------------------------------------------------------------------- PdmTests::~PdmTests() {} //--------------------------------------------------------------------------------- bool PdmTests::init(int domainId, int testId) { DEBUG_LOG(m_logger) << "init begin"; m_testId = testId; // initialize DDS m_ddsConnector.reset(new DDSConnector::DdsConnector(domainId, IDL::PartitionType::Global, 0)); 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 dtc"; m_dtc = ProjectDataManagement::Interface::Dtc::create(m_ddsConnector); DEBUG_LOG(m_logger) << "create ftc"; m_ftc = ProjectDataManagement::Interface::Ftc::create(m_ddsConnector); bool bRet = m_dtc->enableAll() && m_ftc->enableAll(); DEBUG_LOG(m_logger) << "init end - bRet = " << bRet; return bRet; } //--------------------------------------------------------------------------------- void PdmTests::startTest() { INFO_LOG(m_logger) << "startTest"; if (m_testId == 0) { QTimer::singleShot(1000, this, &PdmTests::tryGetAllVulnerabilityKinds); QTimer::singleShot(2000, this, &PdmTests::tryGetAllBiteComponentTexts); } else if (m_testId == 1) { QTimer::singleShot(1000, this, &PdmTests::tryGetAllVulnerabilityKinds); } else if (m_testId == 2) { QTimer::singleShot(1000, this, &PdmTests::tryGetAllBiteComponentTexts); } else { ERROR_LOG(m_logger) << "Unknown test case!"; failExit(); } QTimer::singleShot(5000, qApp, &QCoreApplication::quit); } //--------------------------------------------------------------------------------- void PdmTests::tryGetAllVulnerabilityKinds() { INFO_LOG(m_logger) << "trying to get all ProjectDataManagements"; const QMap map = m_dtc->vulnerabilityKinds(); if (map.isEmpty()) { ERROR_LOG(m_logger) << "Error requesting vulnerability kinds data"; failExit(); } else { INFO_LOG(m_logger) << "Amount of vulnerability kinds = " << map.size(); m_id = map.firstKey(); for(auto it = map.begin(); it != map.end(); ++it) { const ProjectDataManagement::VulnerabilityClass &vc = it.value().vulnerabilityClassId; INFO_LOG(m_logger) << "VulnerabilityKind(" << it.key() << ") : " << it.value().name << ", translation " << m_dtc->trVulnerabilityKindName(it.key(), vc); } } QTimer::singleShot(10, this, &PdmTests::tryGetVulnerabilityKind); } //--------------------------------------------------------------------------------- void PdmTests::tryGetVulnerabilityKind() { INFO_LOG(m_logger) << "trying get itemData for Vulnerability kind " << m_id; ProjectDataManagement::VulnerabilityKind data = m_dtc->vulnerabilityKind(m_id); if (data.taVulnerabilityKind <= 0) { ERROR_LOG(m_logger) << "Error receiving data for id " << m_id; failExit(); } else { const ProjectDataManagement::VulnerabilityClass &vc = data.vulnerabilityClassId; INFO_LOG(m_logger) << "## VulnerabilityKind: (" << data.taVulnerabilityKind << "), name: " << data.name << ", translation " << m_dtc->trVulnerabilityKindName(m_id, vc); QTimer::singleShot(0, qApp, &QCoreApplication::quit); } } //--------------------------------------------------------------------------------- void PdmTests::tryGetAllBiteComponentTexts() { INFO_LOG(m_logger) << "trying to get all Bite Component Texts"; const QMap map = m_dtc->biteComponentTexts(); if (map.isEmpty()) { ERROR_LOG(m_logger) << "Error requesting bite components text data"; failExit(); } else { INFO_LOG(m_logger) << "Amount of bite component texts = " << map.size(); m_id = map.firstKey(); for(auto it = map.begin(); it != map.end(); ++it) INFO_LOG(m_logger) << "BiteComponent(" << it.key() << ") : " << it.value().name << ", translation " << m_dtc->trBiteComponentTextName(it.key()); } } // ------------------------------------------------------------------------------ void PdmTests::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") }); } int testId() const { return isSet(QLatin1String("t")) ? value(QLatin1String("t")).toInt() : 0; } }; // ------------------------------------------------------------------ int main(int argc, char **argv) { NGLCoreApplication app(argc, argv); app.createLogger("PDM", "log4cxx_pdm.props"); int iRet = -1; CmdLineParser options; if (!options.init()) return -1; std::unique_ptr pdmTests(new ProjectDataManagement::PdmTests); if(!pdmTests->init(options.domainId(), options.testId())) return iRet; QTimer::singleShot(0, pdmTests.get(), &ProjectDataManagement::PdmTests::startTest); STARTUP_LOG(app.baseLogger()); app.exec(); iRet = pdmTests->testsSuccessful() ? 0 : 1; fprintf(stderr, "%d\n", iRet); DEBUG_LOG(app.baseLogger()) << "** TEST result = " << iRet; SHUTDOWN_LOG(app.baseLogger()); return iRet; }