diff --git a/plugins/mockplugin/include/CosinusProvider.h b/plugins/mockplugin/include/CosinusProvider.h index 2260032..584d9b0 100644 --- a/plugins/mockplugin/include/CosinusProvider.h +++ b/plugins/mockplugin/include/CosinusProvider.h @@ -26,6 +26,11 @@ public: void requestDataAborting(QUuid acqIdentifier) override; + /// Provide data + std::shared_ptr provideDataSeries(const SqpRange &dataRangeRequested, + const QVariantHash &data); + + private: std::shared_ptr retrieveData(QUuid acqIdentifier, const SqpRange &dataRangeRequested, const QVariantHash &data); diff --git a/plugins/mockplugin/src/CosinusProvider.cpp b/plugins/mockplugin/src/CosinusProvider.cpp index ed23a60..fb09008 100644 --- a/plugins/mockplugin/src/CosinusProvider.cpp +++ b/plugins/mockplugin/src/CosinusProvider.cpp @@ -145,8 +145,9 @@ std::shared_ptr CosinusProvider::retrieveData(QUuid acqIdentifier, progress = currentProgress; emit dataProvidedProgress(acqIdentifier, progress); - qCInfo(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData" - << QThread::currentThread()->objectName() << progress; + qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData" + << QThread::currentThread()->objectName() + << progress; // NOTE: Try to use multithread if possible } } @@ -199,3 +200,14 @@ void CosinusProvider::requestDataAborting(QUuid acqIdentifier) << tr("Aborting progression of inexistant identifier detected !!!"); } } + +std::shared_ptr CosinusProvider::provideDataSeries(const SqpRange &dataRangeRequested, + const QVariantHash &data) +{ + auto uid = QUuid::createUuid(); + m_VariableToEnableProvider[uid] = true; + auto dataSeries = this->retrieveData(uid, dataRangeRequested, data); + + m_VariableToEnableProvider.remove(uid); + return dataSeries; +} diff --git a/plugins/mockplugin/tests/TestCosinusAcquisition.cpp b/plugins/mockplugin/tests/TestCosinusAcquisition.cpp index 472a671..b1decbc 100644 --- a/plugins/mockplugin/tests/TestCosinusAcquisition.cpp +++ b/plugins/mockplugin/tests/TestCosinusAcquisition.cpp @@ -24,9 +24,6 @@ const auto TESTS_RESOURCES_PATH = QFileInfo{ /// Format of dates in data files const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss:zzz"); -/// Delay after each operation on the variable before validating it (in ms) -const auto OPERATION_DELAY = 250; - /** * Verifies that the data in the candidate series are identical to the data in the reference series * in a specific range @@ -45,6 +42,9 @@ bool checkDataSeries(std::shared_ptr candidate, const SqpRange &ran auto referenceIt = reference->xAxisRange(range.m_TStart, range.m_TEnd); + qInfo() << "candidateSize" << std::distance(candidate->cbegin(), candidate->cend()); + qInfo() << "refSize" << std::distance(referenceIt.first, referenceIt.second); + return std::equal(candidate->cbegin(), candidate->cend(), referenceIt.first, referenceIt.second, [](const auto &it1, const auto &it2) { // - milliseconds precision for time @@ -54,29 +54,6 @@ bool checkDataSeries(std::shared_ptr candidate, const SqpRange &ran }); } -/// Generates the data series from the reading of a data stream -std::shared_ptr readDataStream(QTextStream &stream) -{ - std::vector xAxisData, valuesData; - - QString line{}; - while (stream.readLineInto(&line)) { - // Separates date (x-axis data) to value data - auto splitLine = line.split('\t'); - if (splitLine.size() == 2) { - // Converts datetime to double - auto dateTime = QDateTime::fromString(splitLine[0], DATETIME_FORMAT); - dateTime.setTimeSpec(Qt::UTC); - xAxisData.push_back(DateUtils::secondsSinceEpoch(dateTime)); - - valuesData.push_back(splitLine[1].toDouble()); - } - } - - return std::make_shared(std::move(xAxisData), std::move(valuesData), - Unit{{}, true}, Unit{}); -} - } // namespace /** @@ -99,8 +76,9 @@ void TestCosinusAcquisition::testAcquisition_data() // Test structure // // ////////////// // - QTest::addColumn("dataFilename"); // File containing expected data of acquisitions - QTest::addColumn("initialRange"); // First acquisition + QTest::addColumn("referenceRange"); // Range for generating reference series + QTest::addColumn("initialRange"); // First acquisition + QTest::addColumn("operationDelay"); // Acquisitions to make QTest::addColumn >("operations"); // Acquisitions to make // ////////// // @@ -113,8 +91,8 @@ void TestCosinusAcquisition::testAcquisition_data() }; QTest::newRow("cosinus") - << "Cosinus_100Hz_20170101_1200_20170101_1300.txt" - << SqpRange{dateTime(2017, 1, 1, 12, 30, 0), dateTime(2017, 1, 1, 12, 35, 1)} + << SqpRange{dateTime(2017, 1, 1, 12, 0, 0), dateTime(2017, 1, 1, 13, 0, 0)} + << SqpRange{dateTime(2017, 1, 1, 12, 30, 0), dateTime(2017, 1, 1, 12, 35, 1)} << 250 << std::vector{ // Pan (jump) left SqpRange{dateTime(2017, 1, 1, 12, 45, 0), dateTime(2017, 1, 1, 12, 50, 0)}, @@ -130,55 +108,78 @@ void TestCosinusAcquisition::testAcquisition_data() SqpRange{dateTime(2017, 1, 1, 12, 17, 30), dateTime(2017, 1, 1, 12, 19, 30)}, // Zoom out SqpRange{dateTime(2017, 1, 1, 12, 12, 30), dateTime(2017, 1, 1, 12, 24, 30)}}; + + QTest::newRow("cosinus_big") + << SqpRange{dateTime(2017, 1, 1, 1, 0, 0), dateTime(2017, 1, 5, 13, 0, 0)} + << SqpRange{dateTime(2017, 1, 2, 6, 30, 0), dateTime(2017, 1, 2, 18, 30, 0)} << 5000 + << std::vector{ + // Pan (jump) left + SqpRange{dateTime(2017, 1, 1, 13, 30, 0), dateTime(2017, 1, 1, 18, 30, 0)}, + // Pan (jump) right + SqpRange{dateTime(2017, 1, 3, 4, 30, 0), dateTime(2017, 1, 3, 10, 30, 0)}, + // Pan (overlay) right + SqpRange{dateTime(2017, 1, 3, 8, 30, 0), dateTime(2017, 1, 3, 12, 30, 0)}, + // Pan (overlay) left + SqpRange{dateTime(2017, 1, 2, 8, 30, 0), dateTime(2017, 1, 3, 10, 30, 0)}, + // Pan (overlay) left + SqpRange{dateTime(2017, 1, 1, 12, 30, 0), dateTime(2017, 1, 3, 5, 30, 0)}, + // Zoom in + SqpRange{dateTime(2017, 1, 2, 2, 30, 0), dateTime(2017, 1, 2, 8, 30, 0)}, + // Zoom out + SqpRange{dateTime(2017, 1, 1, 14, 30, 0), dateTime(2017, 1, 3, 12, 30, 0)}}; } void TestCosinusAcquisition::testAcquisition() { - // Retrieves data file - QFETCH(QString, dataFilename); - - auto dataFilePath = QFileInfo{TESTS_RESOURCES_PATH, dataFilename}.absoluteFilePath(); - QFile dataFile{dataFilePath}; - - if (dataFile.open(QFile::ReadOnly)) { - // Generates data series to compare with - QTextStream dataStream{&dataFile}; - auto dataSeries = readDataStream(dataStream); - - /// Lambda used to validate a variable at each step - auto validateVariable = [dataSeries](std::shared_ptr variable, - const SqpRange &range) { - // Checks that the variable's range has changed - QCOMPARE(variable->range(), range); - - // Checks the variable's data series - QVERIFY(checkDataSeries(variable->dataSeries(), variable->cacheRange(), dataSeries)); - }; - - // Creates variable - QFETCH(SqpRange, initialRange); - sqpApp->timeController().onTimeToUpdate(initialRange); - auto provider = std::make_shared(); - auto variable = sqpApp->variableController().createVariable( - "MMS", {{COSINUS_TYPE_KEY, "scalar"}, {COSINUS_FREQUENCY_KEY, 100.}}, provider); - - QTest::qWait(OPERATION_DELAY); - validateVariable(variable, initialRange); - - // Makes operations on the variable - QFETCH(std::vector, operations); - for (const auto &operation : operations) { - // Asks request on the variable and waits during its execution - sqpApp->variableController().onRequestDataLoading({variable}, operation, - variable->range(), true); - - QTest::qWait(OPERATION_DELAY); - validateVariable(variable, operation); - } + // Retrieves reference range + QFETCH(SqpRange, referenceRange); + CosinusProvider referenceProvider{}; + auto dataSeries = referenceProvider.provideDataSeries( + referenceRange, {{COSINUS_TYPE_KEY, "scalar"}, {COSINUS_FREQUENCY_KEY, 100.}}); + + auto end = dataSeries->cend() - 1; + qInfo() << dataSeries->nbPoints() << dataSeries->cbegin()->x() << end->x(); + + /// Lambda used to validate a variable at each step + auto validateVariable + = [dataSeries](std::shared_ptr variable, const SqpRange &range) { + // Checks that the variable's range has changed + QCOMPARE(variable->range(), range); + + // Checks the variable's data series + QVERIFY(checkDataSeries(variable->dataSeries(), variable->cacheRange(), dataSeries)); + }; + + // Creates variable + QFETCH(SqpRange, initialRange); + sqpApp->timeController().onTimeToUpdate(initialRange); + auto provider = std::make_shared(); + auto variable = sqpApp->variableController().createVariable( + "MMS", {{COSINUS_TYPE_KEY, "scalar"}, {COSINUS_FREQUENCY_KEY, 100.}}, provider); + + QFETCH(int, operationDelay); + QTest::qWait(operationDelay); + validateVariable(variable, initialRange); + + // Makes operations on the variable + QFETCH(std::vector, operations); + for (const auto &operation : operations) { + // Asks request on the variable and waits during its execution + sqpApp->variableController().onRequestDataLoading({variable}, operation, variable->range(), + true); + + QTest::qWait(operationDelay); + validateVariable(variable, operation); } - else { - QFAIL("Can't read input data file"); + + + for (const auto &operation : operations) { + // Asks request on the variable and waits during its execution + sqpApp->variableController().onRequestDataLoading({variable}, operation, variable->range(), + true); } + QTest::qWait(operationDelay); + validateVariable(variable, operations.back()); } int main(int argc, char *argv[])