Auto status change to "Under Review"
@@ -166,6 +166,12 private slots: | |||||
166 | /// Input data for @sa testSync() |
|
166 | /// Input data for @sa testSync() | |
167 | void testSync_data(); |
|
167 | void testSync_data(); | |
168 |
|
168 | |||
|
169 | /// Input data for @sa testSyncWithAborting() | |||
|
170 | void testSyncWithAborting_data(); | |||
|
171 | ||||
|
172 | /// Tests synchronization between variables through several operations with aborting | |||
|
173 | void testSyncWithAborting(); | |||
|
174 | ||||
169 | /// Tests synchronization between variables through several operations |
|
175 | /// Tests synchronization between variables through several operations | |
170 | void testSync(); |
|
176 | void testSync(); | |
171 | }; |
|
177 | }; | |
@@ -234,6 +240,7 void testSyncCase1() | |||||
234 | iterations.push_back( |
|
240 | iterations.push_back( | |
235 | {std::make_shared<Move>(0, var0NewRange), {{0, var0NewRange}, {1, var1ExpectedRange}}}); |
|
241 | {std::make_shared<Move>(0, var0NewRange), {{0, var0NewRange}, {1, var1ExpectedRange}}}); | |
236 | }; |
|
242 | }; | |
|
243 | ||||
237 | // Pan left |
|
244 | // Pan left | |
238 | moveVar0(range({14, 30}, {15, 30}), range({13, 30}, {14, 30})); |
|
245 | moveVar0(range({14, 30}, {15, 30}), range({13, 30}, {14, 30})); | |
239 | // Pan right |
|
246 | // Pan right | |
@@ -246,6 +253,83 void testSyncCase1() | |||||
246 | QTest::newRow("sync1") << syncId << initialRange << std::move(iterations) << 200; |
|
253 | QTest::newRow("sync1") << syncId << initialRange << std::move(iterations) << 200; | |
247 | } |
|
254 | } | |
248 |
|
255 | |||
|
256 | void testSyncCase1WithAborting() | |||
|
257 | { | |||
|
258 | // Id used to synchronize variables in the controller | |||
|
259 | auto syncId = QUuid::createUuid(); | |||
|
260 | ||||
|
261 | /// Generates a range according to a start time and a end time (the date is the same) | |||
|
262 | auto range = [](const QTime &startTime, const QTime &endTime) { | |||
|
263 | return SqpRange{DateUtils::secondsSinceEpoch(QDateTime{{2017, 1, 1}, startTime, Qt::UTC}), | |||
|
264 | DateUtils::secondsSinceEpoch(QDateTime{{2017, 1, 1}, endTime, Qt::UTC})}; | |||
|
265 | }; | |||
|
266 | ||||
|
267 | auto initialRange = range({12, 0}, {13, 0}); | |||
|
268 | ||||
|
269 | Iterations creations{}; | |||
|
270 | // Creates variables var0, var1 and var2 | |||
|
271 | creations.push_back({std::make_shared<Create>(0), {{0, initialRange}}}); | |||
|
272 | creations.push_back({std::make_shared<Create>(1), {{0, initialRange}, {1, initialRange}}}); | |||
|
273 | ||||
|
274 | // Adds variables into the sync group (ranges don't need to be tested here) | |||
|
275 | Iterations iterations{}; | |||
|
276 | iterations.push_back({std::make_shared<Synchronize>(0, syncId)}); | |||
|
277 | iterations.push_back({std::make_shared<Synchronize>(1, syncId)}); | |||
|
278 | ||||
|
279 | // Moves var0: ranges of var0, var1 and var2 change | |||
|
280 | auto newRange = range({12, 30}, {13, 30}); | |||
|
281 | iterations.push_back({std::make_shared<Move>(0, newRange), {{0, newRange}, {1, newRange}}}); | |||
|
282 | ||||
|
283 | // Moves var1: ranges of var0, var1 and var2 change | |||
|
284 | newRange = range({13, 0}, {14, 0}); | |||
|
285 | iterations.push_back({std::make_shared<Move>(0, newRange), {{0, newRange}, {1, newRange}}}); | |||
|
286 | ||||
|
287 | // Moves var2: ranges of var0, var1 and var2 change | |||
|
288 | newRange = range({13, 30}, {14, 30}); | |||
|
289 | iterations.push_back( | |||
|
290 | {std::make_shared<Move>(0, newRange), {{0, newRange}, {1, newRange}, {2, newRange}}}); | |||
|
291 | ||||
|
292 | // Desyncs var2 and moves var0: | |||
|
293 | // - ranges of var0 and var1 change | |||
|
294 | // - range of var2 doesn't change anymore | |||
|
295 | auto var2Range = newRange; | |||
|
296 | newRange = range({13, 45}, {14, 45}); | |||
|
297 | iterations.push_back({std::make_shared<Synchronize>(2, syncId, false)}); | |||
|
298 | iterations.push_back({std::make_shared<Move>(0, newRange), {{0, newRange}, {1, newRange}}}); | |||
|
299 | ||||
|
300 | // Shifts var0: although var1 is synchronized with var0, its range doesn't change | |||
|
301 | auto var1Range = newRange; | |||
|
302 | newRange = range({14, 45}, {15, 45}); | |||
|
303 | iterations.push_back( | |||
|
304 | {std::make_shared<Move>(0, newRange, true), {{0, newRange}, {1, var1Range}}}); | |||
|
305 | ||||
|
306 | // Moves var0 through several operations: | |||
|
307 | // - range of var0 changes | |||
|
308 | // - range or var1 changes according to the previous shift (one hour) | |||
|
309 | auto moveVar0 = [&iterations](const auto &var0NewRange, const auto &var1ExpectedRange) { | |||
|
310 | iterations.push_back( | |||
|
311 | {std::make_shared<Move>(0, var0NewRange), {{0, var0NewRange}, {1, var1ExpectedRange}}}); | |||
|
312 | }; | |||
|
313 | ||||
|
314 | // auto oldRange = newRange; | |||
|
315 | // newRange = range({14, 30}, {15, 30}); | |||
|
316 | // auto expectedRange = oldRange; | |||
|
317 | // iterations.push_back( | |||
|
318 | // {std::make_shared<Move>(0, newRange), {{0, oldRange}, {1, expectedRange}}}); | |||
|
319 | ||||
|
320 | // Pan left | |||
|
321 | moveVar0(range({14, 30}, {15, 30}), range({13, 30}, {14, 30})); | |||
|
322 | // Pan right | |||
|
323 | moveVar0(range({16, 0}, {17, 0}), range({15, 0}, {16, 0})); | |||
|
324 | // Zoom in | |||
|
325 | moveVar0(range({16, 30}, {16, 45}), range({15, 30}, {15, 45})); | |||
|
326 | // Zoom out | |||
|
327 | moveVar0(range({16, 15}, {17, 0}), range({15, 15}, {16, 0})); | |||
|
328 | ||||
|
329 | QTest::newRow("syncWithAborting1") << syncId << initialRange << std::move(creations) | |||
|
330 | << std::move(iterations) << 200; | |||
|
331 | } | |||
|
332 | ||||
249 | void testSyncCase2() |
|
333 | void testSyncCase2() | |
250 | { |
|
334 | { | |
251 | // Id used to synchronize variables in the controller |
|
335 | // Id used to synchronize variables in the controller | |
@@ -322,11 +406,32 void TestVariableSync::testSync_data() | |||||
322 | // ////////// // |
|
406 | // ////////// // | |
323 |
|
407 | |||
324 | testSyncCase1(); |
|
408 | testSyncCase1(); | |
325 |
|
|
409 | testSyncCase2(); | |
|
410 | } | |||
|
411 | ||||
|
412 | void TestVariableSync::testSyncWithAborting_data() | |||
|
413 | { | |||
|
414 | // ////////////// // | |||
|
415 | // Test structure // | |||
|
416 | // ////////////// // | |||
|
417 | ||||
|
418 | QTest::addColumn<QUuid>("syncId"); | |||
|
419 | QTest::addColumn<SqpRange>("initialRange"); | |||
|
420 | QTest::addColumn<Iterations>("creations"); | |||
|
421 | QTest::addColumn<Iterations>("iterations"); | |||
|
422 | QTest::addColumn<int>("operationDelay"); | |||
|
423 | ||||
|
424 | // ////////// // | |||
|
425 | // Test cases // | |||
|
426 | // ////////// // | |||
|
427 | ||||
|
428 | testSyncCase1WithAborting(); | |||
326 | } |
|
429 | } | |
327 |
|
430 | |||
328 | void TestVariableSync::testSync() |
|
431 | void TestVariableSync::testSync() | |
329 | { |
|
432 | { | |
|
433 | return; | |||
|
434 | ||||
330 | // Inits controllers |
|
435 | // Inits controllers | |
331 | TimeController timeController{}; |
|
436 | TimeController timeController{}; | |
332 | VariableController variableController{}; |
|
437 | VariableController variableController{}; | |
@@ -377,14 +482,70 void TestVariableSync::testSync() | |||||
377 |
|
482 | |||
378 | validateRanges(iteration.m_ExpectedRanges); |
|
483 | validateRanges(iteration.m_ExpectedRanges); | |
379 | } |
|
484 | } | |
|
485 | } | |||
|
486 | ||||
|
487 | void TestVariableSync::testSyncWithAborting() | |||
|
488 | { | |||
|
489 | // Inits controllers | |||
|
490 | TimeController timeController{}; | |||
|
491 | VariableController variableController{}; | |||
|
492 | variableController.setTimeController(&timeController); | |||
|
493 | ||||
|
494 | QFETCH(QUuid, syncId); | |||
|
495 | QFETCH(SqpRange, initialRange); | |||
|
496 | timeController.onTimeToUpdate(initialRange); | |||
|
497 | ||||
|
498 | // Synchronization group used | |||
|
499 | variableController.onAddSynchronizationGroupId(syncId); | |||
|
500 | ||||
|
501 | auto validateRanges = [&variableController](const auto &expectedRanges) { | |||
|
502 | for (const auto &expectedRangeEntry : expectedRanges) { | |||
|
503 | auto variableIndex = expectedRangeEntry.first; | |||
|
504 | auto expectedRange = expectedRangeEntry.second; | |||
|
505 | ||||
|
506 | // Gets the variable in the controller | |||
|
507 | auto variable = variableController.variableModel()->variable(variableIndex); | |||
|
508 | ||||
|
509 | // Compares variable's range to the expected range | |||
|
510 | QVERIFY(variable != nullptr); | |||
|
511 | auto range = variable->range(); | |||
|
512 | QCOMPARE(range, expectedRange); | |||
|
513 | ||||
|
514 | // Compares variable's data with values expected for its range | |||
|
515 | auto dataSeries = variable->dataSeries(); | |||
|
516 | QVERIFY(dataSeries != nullptr); | |||
|
517 | ||||
|
518 | auto it = dataSeries->xAxisRange(range.m_TStart, range.m_TEnd); | |||
|
519 | auto expectedValues = values(range); | |||
|
520 | qInfo() << std::distance(it.first, it.second) << expectedValues.size(); | |||
|
521 | QVERIFY(std::equal(it.first, it.second, expectedValues.cbegin(), expectedValues.cend(), | |||
|
522 | [](const auto &dataSeriesIt, const auto &expectedValue) { | |||
|
523 | return dataSeriesIt.value() == expectedValue; | |||
|
524 | })); | |||
|
525 | } | |||
|
526 | }; | |||
|
527 | ||||
|
528 | // For each iteration: | |||
|
529 | // - execute operation | |||
|
530 | // - compare the variables' state to the expected states | |||
|
531 | QFETCH(Iterations, iterations); | |||
|
532 | QFETCH(Iterations, creations); | |||
|
533 | QFETCH(int, operationDelay); | |||
|
534 | ||||
|
535 | for (const auto &creation : creations) { | |||
|
536 | creation.m_Operation->exec(variableController); | |||
|
537 | QTest::qWait(operationDelay); | |||
|
538 | } | |||
380 |
|
539 | |||
381 | for (const auto &iteration : iterations) { |
|
540 | for (const auto &iteration : iterations) { | |
382 | iteration.m_Operation->exec(variableController); |
|
541 | iteration.m_Operation->exec(variableController); | |
383 | } |
|
542 | } | |
|
543 | ||||
384 | QTest::qWait(operationDelay); |
|
544 | QTest::qWait(operationDelay); | |
385 | validateRanges(iterations.back().m_ExpectedRanges); |
|
545 | validateRanges(iterations.back().m_ExpectedRanges); | |
386 | } |
|
546 | } | |
387 |
|
547 | |||
|
548 | ||||
388 | QTEST_MAIN(TestVariableSync) |
|
549 | QTEST_MAIN(TestVariableSync) | |
389 |
|
550 | |||
390 | #include "TestVariableSync.moc" |
|
551 | #include "TestVariableSync.moc" |
General Comments 3
Merge lasted acquisition developpement on main Sciqlop branch
You need to be logged in to leave comments.
Login now