From 3edf24abad7348add4c6d81f162acbb2c8b68d23 2017-10-02 09:12:59 From: mperrinel Date: 2017-10-02 09:12:59 Subject: [PATCH] Merge branch 'feature/AcqBasedOnPreviousRequest' into develop --- diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index 7b231da..fa6e0c1 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -48,15 +48,17 @@ SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange & break; } case AcquisitionZoomType::PanRight: { + auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; - varRangeRequested.m_TStart += deltaRight; + varRangeRequested.m_TStart += deltaLeft; varRangeRequested.m_TEnd += deltaRight; break; } case AcquisitionZoomType::PanLeft: { auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; + auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; varRangeRequested.m_TStart -= deltaLeft; - varRangeRequested.m_TEnd -= deltaLeft; + varRangeRequested.m_TEnd -= deltaRight; break; } case AcquisitionZoomType::Unknown: { @@ -117,6 +119,8 @@ struct VariableController::VariableControllerPrivate { void updateVariableRequest(QUuid varRequestId); void cancelVariableRequest(QUuid varRequestId); + SqpRange getLastRequestedRange(QUuid varId); + QMutex m_WorkingMutex; /// Variable model. The VariableController has the ownership VariableModel *m_VariableModel; @@ -549,15 +553,19 @@ AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd auto zoomType = AcquisitionZoomType::Unknown; if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) { + qCCritical(LOG_VariableController()) << "zoomtype: ZoomOut"; zoomType = AcquisitionZoomType::ZoomOut; } else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) { + qCCritical(LOG_VariableController()) << "zoomtype: PanRight"; zoomType = AcquisitionZoomType::PanRight; } else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) { + qCCritical(LOG_VariableController()) << "zoomtype: PanLeft"; zoomType = AcquisitionZoomType::PanLeft; } else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) { + qCCritical(LOG_VariableController()) << "zoomtype: ZoomIn"; zoomType = AcquisitionZoomType::ZoomIn; } else { @@ -570,59 +578,70 @@ void VariableController::VariableControllerPrivate::processRequest(std::shared_p const SqpRange &rangeRequested, QUuid varRequestId) { - - // TODO: protect at auto varRequest = VariableRequest{}; - auto varId = m_VariableToIdentifierMap.at(var); - auto varStrategyRangesRequested - = m_VariableCacheStrategy->computeRange(var->range(), rangeRequested); + auto it = m_VariableToIdentifierMap.find(var); + if (it != m_VariableToIdentifierMap.cend()) { - auto notInCacheRangeList = QVector{varStrategyRangesRequested.second}; - auto inCacheRangeList = QVector{}; - if (m_VarIdToVarRequestIdQueueMap.find(varId) == m_VarIdToVarRequestIdQueueMap.cend()) { - notInCacheRangeList = var->provideNotInCacheRangeList(varStrategyRangesRequested.second); - inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second); - } + auto varId = it->second; + + auto oldRange = getLastRequestedRange(varId); + + // check for update oldRange to the last request range. + if (oldRange == INVALID_RANGE) { + oldRange = var->range(); + } - if (!notInCacheRangeList.empty()) { - varRequest.m_RangeRequested = varStrategyRangesRequested.first; - varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; + auto varStrategyRangesRequested + = m_VariableCacheStrategy->computeRange(oldRange, rangeRequested); - // store VarRequest - storeVariableRequest(varId, varRequestId, varRequest); + auto notInCacheRangeList = QVector{varStrategyRangesRequested.second}; + auto inCacheRangeList = QVector{}; + if (m_VarIdToVarRequestIdQueueMap.find(varId) == m_VarIdToVarRequestIdQueueMap.cend()) { + notInCacheRangeList + = var->provideNotInCacheRangeList(varStrategyRangesRequested.second); + inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second); + } - auto varProvider = m_VariableToProviderMap.at(var); - if (varProvider != nullptr) { - auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest( - varRequestId, varId, varStrategyRangesRequested.first, - varStrategyRangesRequested.second, - DataProviderParameters{std::move(notInCacheRangeList), var->metadata()}, - varProvider); + if (!notInCacheRangeList.empty()) { + varRequest.m_RangeRequested = varStrategyRangesRequested.first; + varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; + + // store VarRequest + storeVariableRequest(varId, varRequestId, varRequest); + + auto varProvider = m_VariableToProviderMap.at(var); + if (varProvider != nullptr) { + auto varRequestIdCanceled = m_VariableAcquisitionWorker->pushVariableRequest( + varRequestId, varId, varStrategyRangesRequested.first, + varStrategyRangesRequested.second, + DataProviderParameters{std::move(notInCacheRangeList), var->metadata()}, + varProvider); + + if (!varRequestIdCanceled.isNull()) { + qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ") + << varRequestIdCanceled; + cancelVariableRequest(varRequestIdCanceled); + } + } + else { + qCCritical(LOG_VariableController()) + << "Impossible to provide data with a null provider"; + } - if (!varRequestIdCanceled.isNull()) { - qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ") - << varRequestIdCanceled; - cancelVariableRequest(varRequestIdCanceled); + if (!inCacheRangeList.empty()) { + emit q->updateVarDisplaying(var, inCacheRangeList.first()); } } else { - qCCritical(LOG_VariableController()) - << "Impossible to provide data with a null provider"; - } - - if (!inCacheRangeList.empty()) { - emit q->updateVarDisplaying(var, inCacheRangeList.first()); + varRequest.m_RangeRequested = varStrategyRangesRequested.first; + varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; + // store VarRequest + storeVariableRequest(varId, varRequestId, varRequest); + acceptVariableRequest( + varId, var->dataSeries()->subDataSeries(varStrategyRangesRequested.second)); } } - else { - varRequest.m_RangeRequested = varStrategyRangesRequested.first; - varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; - // store VarRequest - storeVariableRequest(varId, varRequestId, varRequest); - acceptVariableRequest(varId, - var->dataSeries()->subDataSeries(varStrategyRangesRequested.second)); - } } std::shared_ptr @@ -838,3 +857,40 @@ void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid } } } + +SqpRange VariableController::VariableControllerPrivate::getLastRequestedRange(QUuid varId) +{ + auto lastRangeRequested = SqpRange{INVALID_RANGE}; + auto varIdToVarRequestIdQueueMapIt = m_VarIdToVarRequestIdQueueMap.find(varId); + if (varIdToVarRequestIdQueueMapIt != m_VarIdToVarRequestIdQueueMap.cend()) { + auto &varRequestIdQueue = varIdToVarRequestIdQueueMapIt->second; + auto varRequestId = varRequestIdQueue.back(); + auto varRequestIdToVarIdVarRequestMapIt + = m_VarRequestIdToVarIdVarRequestMap.find(varRequestId); + if (varRequestIdToVarIdVarRequestMapIt != m_VarRequestIdToVarIdVarRequestMap.cend()) { + auto &varIdToVarRequestMap = varRequestIdToVarIdVarRequestMapIt->second; + auto varIdToVarRequestMapIt = varIdToVarRequestMap.find(varId); + if (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) { + auto &varRequest = varIdToVarRequestMapIt->second; + lastRangeRequested = varRequest.m_RangeRequested; + } + else { + qCDebug(LOG_VariableController()) + << tr("Impossible to getLastRequestedRange of a unknown variable id attached " + "to a variableRequestId") + << varRequestId << varId; + } + } + else { + qCCritical(LOG_VariableController()) + << tr("Impossible to getLastRequestedRange of a unknown variableRequestId") + << varRequestId; + } + } + else { + qDebug(LOG_VariableController()) + << tr("Impossible to getLastRequestedRange of a unknown variable id") << varId; + } + + return lastRangeRequested; +} diff --git a/core/tests/Variable/TestVariableSync.cpp b/core/tests/Variable/TestVariableSync.cpp index 61daa00..21a8907 100644 --- a/core/tests/Variable/TestVariableSync.cpp +++ b/core/tests/Variable/TestVariableSync.cpp @@ -171,20 +171,10 @@ private slots: void testSync(); }; -void TestVariableSync::testSync_data() -{ - // ////////////// // - // Test structure // - // ////////////// // - - QTest::addColumn("syncId"); - QTest::addColumn("initialRange"); - QTest::addColumn("iterations"); - - // ////////// // - // Test cases // - // ////////// // +namespace { +void testSyncCase1() +{ // Id used to synchronize variables in the controller auto syncId = QUuid::createUuid(); @@ -254,7 +244,86 @@ void TestVariableSync::testSync_data() // Zoom out moveVar0(range({12, 0}, {18, 0}), range({11, 0}, {17, 0})); - QTest::newRow("sync1") << syncId << initialRange << std::move(iterations); + QTest::newRow("sync1") << syncId << initialRange << std::move(iterations) << 200; +} + +void testSyncCase2() +{ + // Id used to synchronize variables in the controller + auto syncId = QUuid::createUuid(); + + /// Generates a range according to a start time and a end time (the date is the same) + auto dateTime = [](int year, int month, int day, int hours, int minutes, int seconds) { + return DateUtils::secondsSinceEpoch( + QDateTime{{year, month, day}, QTime{hours, minutes, seconds}, Qt::UTC}); + }; + + auto initialRange = SqpRange{dateTime(2017, 1, 1, 12, 0, 0), dateTime(2017, 1, 1, 13, 0, 0)}; + + Iterations iterations{}; + // Creates variables var0 and var1 + iterations.push_back({std::make_shared(0), {{0, initialRange}}}); + iterations.push_back({std::make_shared(1), {{0, initialRange}, {1, initialRange}}}); + + // Adds variables into the sync group (ranges don't need to be tested here) + iterations.push_back({std::make_shared(0, syncId)}); + iterations.push_back({std::make_shared(1, syncId)}); + + + // Moves var0 through several operations: + // - range of var0 changes + // - range or var1 changes according to the previous shift (one hour) + auto moveVar0 = [&iterations](const auto &var0NewRange) { + iterations.push_back( + {std::make_shared(0, var0NewRange), {{0, var0NewRange}, {1, var0NewRange}}}); + }; + moveVar0(SqpRange{dateTime(2017, 1, 1, 12, 0, 0), dateTime(2017, 1, 1, 13, 0, 0)}); + moveVar0(SqpRange{dateTime(2017, 1, 1, 14, 0, 0), dateTime(2017, 1, 1, 15, 0, 0)}); + moveVar0(SqpRange{dateTime(2017, 1, 1, 8, 0, 0), dateTime(2017, 1, 1, 9, 0, 0)}); + // moveVar0(SqpRange{dateTime(2017, 1, 1, 7, 30, 0), dateTime(2017, 1, 1, 9, 30, 0)}); + moveVar0(SqpRange{dateTime(2017, 1, 1, 2, 0, 0), dateTime(2017, 1, 1, 4, 0, 0)}); + moveVar0(SqpRange{dateTime(2017, 1, 1, 6, 0, 0), dateTime(2017, 1, 1, 8, 0, 0)}); + + moveVar0(SqpRange{dateTime(2017, 1, 10, 6, 0, 0), dateTime(2017, 1, 15, 8, 0, 0)}); + moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 1, 25, 8, 0, 0)}); + moveVar0(SqpRange{dateTime(2017, 1, 2, 6, 0, 0), dateTime(2017, 1, 8, 8, 0, 0)}); + + moveVar0(SqpRange{dateTime(2017, 4, 10, 6, 0, 0), dateTime(2017, 6, 15, 8, 0, 0)}); + moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 2, 25, 8, 0, 0)}); + moveVar0(SqpRange{dateTime(2017, 7, 2, 6, 0, 0), dateTime(2017, 10, 8, 8, 0, 0)}); + moveVar0(SqpRange{dateTime(2017, 4, 10, 6, 0, 0), dateTime(2017, 6, 15, 8, 0, 0)}); + moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 2, 25, 8, 0, 0)}); + moveVar0(SqpRange{dateTime(2017, 7, 2, 6, 0, 0), dateTime(2017, 10, 8, 8, 0, 0)}); + moveVar0(SqpRange{dateTime(2017, 4, 10, 6, 0, 0), dateTime(2017, 6, 15, 8, 0, 0)}); + moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 2, 25, 8, 0, 0)}); + moveVar0(SqpRange{dateTime(2017, 7, 2, 6, 0, 0), dateTime(2017, 10, 8, 8, 0, 0)}); + moveVar0(SqpRange{dateTime(2017, 4, 10, 6, 0, 0), dateTime(2017, 6, 15, 8, 0, 0)}); + moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 2, 25, 8, 0, 0)}); + moveVar0(SqpRange{dateTime(2017, 7, 2, 6, 0, 0), dateTime(2017, 10, 8, 8, 0, 0)}); + + + QTest::newRow("sync2") << syncId << initialRange << iterations << 4000; + // QTest::newRow("sync3") << syncId << initialRange << iterations << 5000; +} +} + +void TestVariableSync::testSync_data() +{ + // ////////////// // + // Test structure // + // ////////////// // + + QTest::addColumn("syncId"); + QTest::addColumn("initialRange"); + QTest::addColumn("iterations"); + QTest::addColumn("operationDelay"); + + // ////////// // + // Test cases // + // ////////// // + + testSyncCase1(); + testSyncCase2(); } void TestVariableSync::testSync() @@ -271,15 +340,8 @@ void TestVariableSync::testSync() // Synchronization group used variableController.onAddSynchronizationGroupId(syncId); - // For each iteration: - // - execute operation - // - compare the variables' state to the expected states - QFETCH(Iterations, iterations); - for (const auto &iteration : iterations) { - iteration.m_Operation->exec(variableController); - QTest::qWait(OPERATION_DELAY); - - for (const auto &expectedRangeEntry : iteration.m_ExpectedRanges) { + auto validateRanges = [&variableController](const auto &expectedRanges) { + for (const auto &expectedRangeEntry : expectedRanges) { auto variableIndex = expectedRangeEntry.first; auto expectedRange = expectedRangeEntry.second; @@ -297,12 +359,31 @@ void TestVariableSync::testSync() auto it = dataSeries->xAxisRange(range.m_TStart, range.m_TEnd); auto expectedValues = values(range); + qInfo() << std::distance(it.first, it.second) << expectedValues.size(); QVERIFY(std::equal(it.first, it.second, expectedValues.cbegin(), expectedValues.cend(), [](const auto &dataSeriesIt, const auto &expectedValue) { return dataSeriesIt.value() == expectedValue; })); } + }; + + // For each iteration: + // - execute operation + // - compare the variables' state to the expected states + QFETCH(Iterations, iterations); + QFETCH(int, operationDelay); + for (const auto &iteration : iterations) { + iteration.m_Operation->exec(variableController); + QTest::qWait(operationDelay); + + validateRanges(iteration.m_ExpectedRanges); + } + + for (const auto &iteration : iterations) { + iteration.m_Operation->exec(variableController); } + QTest::qWait(operationDelay); + validateRanges(iterations.back().m_ExpectedRanges); } QTEST_MAIN(TestVariableSync) diff --git a/gui/src/Visualization/VisualizationZoneWidget.cpp b/gui/src/Visualization/VisualizationZoneWidget.cpp index aacba29..7d1998a 100644 --- a/gui/src/Visualization/VisualizationZoneWidget.cpp +++ b/gui/src/Visualization/VisualizationZoneWidget.cpp @@ -153,8 +153,9 @@ VisualizationGraphWidget *VisualizationZoneWidget::createGraph(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[])