##// END OF EJS Templates
Add test for one variable acquisition in TestVariableSync
perrinel -
r837:650754855dfd feature/FixAcquis...
parent child
Show More
@@ -37,6 +37,36 std::vector<double> values(const SqpRange &range)
37 return result;
37 return result;
38 }
38 }
39
39
40 void validateRanges(VariableController &variableController,
41 const std::map<int, SqpRange> &expectedRanges)
42 {
43 for (const auto &expectedRangeEntry : expectedRanges) {
44 auto variableIndex = expectedRangeEntry.first;
45 auto expectedRange = expectedRangeEntry.second;
46
47 // Gets the variable in the controller
48 auto variable = variableController.variableModel()->variable(variableIndex);
49
50 // Compares variable's range to the expected range
51 QVERIFY(variable != nullptr);
52 auto range = variable->range();
53 qInfo() << "range vs expected range" << range << expectedRange;
54 QCOMPARE(range, expectedRange);
55
56 // Compares variable's data with values expected for its range
57 auto dataSeries = variable->dataSeries();
58 QVERIFY(dataSeries != nullptr);
59
60 auto it = dataSeries->xAxisRange(range.m_TStart, range.m_TEnd);
61 auto expectedValues = values(range);
62 qInfo() << std::distance(it.first, it.second) << expectedValues.size();
63 QVERIFY(std::equal(it.first, it.second, expectedValues.cbegin(), expectedValues.cend(),
64 [](const auto &dataSeriesIt, const auto &expectedValue) {
65 return dataSeriesIt.value() == expectedValue;
66 }));
67 }
68 }
69
40 /// Provider used for the tests
70 /// Provider used for the tests
41 class TestProvider : public IDataProvider {
71 class TestProvider : public IDataProvider {
42 std::shared_ptr<IDataProvider> clone() const { return std::make_shared<TestProvider>(); }
72 std::shared_ptr<IDataProvider> clone() const { return std::make_shared<TestProvider>(); }
@@ -97,8 +127,8 struct Create : public IOperation {
97 * Variable move/shift operation in the controller
127 * Variable move/shift operation in the controller
98 */
128 */
99 struct Move : public IOperation {
129 struct Move : public IOperation {
100 explicit Move(int index, const SqpRange &newRange, bool shift = false)
130 explicit Move(int index, const SqpRange &newRange, bool shift = false, int delayMS = 10)
101 : m_Index{index}, m_NewRange{newRange}, m_Shift{shift}
131 : m_Index{index}, m_NewRange{newRange}, m_Shift{shift}, m_DelayMs{delayMS}
102 {
132 {
103 }
133 }
104
134
@@ -106,12 +136,14 struct Move : public IOperation {
106 {
136 {
107 if (auto variable = variableController.variableModel()->variable(m_Index)) {
137 if (auto variable = variableController.variableModel()->variable(m_Index)) {
108 variableController.onRequestDataLoading({variable}, m_NewRange, !m_Shift);
138 variableController.onRequestDataLoading({variable}, m_NewRange, !m_Shift);
139 QTest::qWait(m_DelayMs);
109 }
140 }
110 }
141 }
111
142
112 int m_Index; ///< The index of the variable to move
143 int m_Index; ///< The index of the variable to move
113 SqpRange m_NewRange; ///< The new range of the variable
144 SqpRange m_NewRange; ///< The new range of the variable
114 bool m_Shift; ///< Performs a shift (
145 bool m_Shift; ///< Performs a shift (
146 int m_DelayMs; ///< wait the delay after running the request (
115 };
147 };
116
148
117 /**
149 /**
@@ -169,11 +201,17 private slots:
169 /// Input data for @sa testSyncWithAborting()
201 /// Input data for @sa testSyncWithAborting()
170 void testSyncWithAborting_data();
202 void testSyncWithAborting_data();
171
203
172 /// Tests synchronization between variables through several operations with aborting
204 /// Input data for @sa testSyncOneVar()
205 void testSyncOneVar_data();
206
207 /// Tests synchronization between variables through several operations with automatic aborting
173 void testSyncWithAborting();
208 void testSyncWithAborting();
174
209
175 /// Tests synchronization between variables through several operations
210 /// Tests synchronization between variables through several operations
176 void testSync();
211 void testSync();
212
213 /// Tests synchronization between variables through several operations
214 void testSyncOneVar();
177 };
215 };
178
216
179 namespace {
217 namespace {
@@ -312,12 +350,6 void testSyncCase1WithAborting()
312 {std::make_shared<Move>(0, var0NewRange), {{0, var0NewRange}, {1, var1ExpectedRange}}});
350 {std::make_shared<Move>(0, var0NewRange), {{0, var0NewRange}, {1, var1ExpectedRange}}});
313 };
351 };
314
352
315 // auto oldRange = newRange;
316 // newRange = range({14, 30}, {15, 30});
317 // auto expectedRange = oldRange;
318 // iterations.push_back(
319 // {std::make_shared<Move>(0, newRange), {{0, oldRange}, {1, expectedRange}}});
320
321 // Pan left
353 // Pan left
322 moveVar0(range({14, 30}, {15, 30}), range({14, 30}, {15, 30}));
354 moveVar0(range({14, 30}, {15, 30}), range({14, 30}, {15, 30}));
323 // Pan right
355 // Pan right
@@ -389,6 +421,64 void testSyncCase2()
389 QTest::newRow("sync2") << syncId << initialRange << iterations << 4000;
421 QTest::newRow("sync2") << syncId << initialRange << iterations << 4000;
390 // QTest::newRow("sync3") << syncId << initialRange << iterations << 5000;
422 // QTest::newRow("sync3") << syncId << initialRange << iterations << 5000;
391 }
423 }
424
425 void testSyncOnVarCase1()
426 {
427 // Id used to synchronize variables in the controller
428 auto syncId = QUuid::createUuid();
429
430 /// Generates a range according to a start time and a end time (the date is the same)
431 auto range = [](const QTime &startTime, const QTime &endTime) {
432 return SqpRange{DateUtils::secondsSinceEpoch(QDateTime{{2017, 1, 1}, startTime, Qt::UTC}),
433 DateUtils::secondsSinceEpoch(QDateTime{{2017, 1, 1}, endTime, Qt::UTC})};
434 };
435
436 auto initialRange = range({12, 0}, {13, 0});
437
438 Iterations creations{};
439 // Creates variables var0, var1 and var2
440 creations.push_back({std::make_shared<Create>(0), {{0, initialRange}}});
441
442 Iterations synchronization{};
443 // Adds variables into the sync group (ranges don't need to be tested here)
444 synchronization.push_back({std::make_shared<Synchronize>(0, syncId)});
445
446 Iterations iterations{};
447
448 // Moves var0 through several operations
449 auto moveOp = [&iterations](const auto &requestedRange, const auto &expectedRange, auto delay) {
450 iterations.push_back(
451 {std::make_shared<Move>(0, requestedRange, true, delay), {{0, expectedRange}}});
452 };
453
454 // we assume here 300 ms is enough to finsh a operation
455 int delayToFinish = 300;
456 // jump to right, let's the operation time to finish
457 moveOp(range({14, 30}, {15, 30}), range({14, 30}, {15, 30}), delayToFinish);
458 // pan to right, let's the operation time to finish
459 moveOp(range({14, 45}, {15, 45}), range({14, 45}, {15, 45}), delayToFinish);
460 // jump to left, let's the operation time to finish
461 moveOp(range({03, 30}, {04, 30}), range({03, 30}, {04, 30}), delayToFinish);
462 // Pan to left, let's the operation time to finish
463 moveOp(range({03, 10}, {04, 10}), range({03, 10}, {04, 10}), delayToFinish);
464 // Zoom in, let's the operation time to finish
465 moveOp(range({03, 30}, {04, 00}), range({03, 30}, {04, 00}), delayToFinish);
466 // Zoom out left, let's the operation time to finish
467 moveOp(range({01, 10}, {18, 10}), range({01, 10}, {18, 10}), delayToFinish);
468 // Go back to initial range
469 moveOp(initialRange, initialRange, delayToFinish);
470
471
472 // jump to right, let's the operation time to finish
473 // moveOp(range({14, 30}, {15, 30}), initialRange, delayToFinish);
474 // Zoom out left, let's the operation time to finish
475 moveOp(range({01, 10}, {18, 10}), initialRange, delayToFinish);
476 // Go back to initial range
477 moveOp(initialRange, initialRange, 300);
478
479 QTest::newRow("syncOnVarCase1") << syncId << initialRange << std::move(creations)
480 << std::move(iterations);
481 }
392 }
482 }
393
483
394 void TestVariableSync::testSync_data()
484 void TestVariableSync::testSync_data()
@@ -429,10 +519,26 void TestVariableSync::testSyncWithAborting_data()
429 testSyncCase1WithAborting();
519 testSyncCase1WithAborting();
430 }
520 }
431
521
432 void TestVariableSync::testSync()
522 void TestVariableSync::testSyncOneVar_data()
433 {
523 {
434 return;
524 // ////////////// //
525 // Test structure //
526 // ////////////// //
527
528 QTest::addColumn<QUuid>("syncId");
529 QTest::addColumn<SqpRange>("initialRange");
530 QTest::addColumn<Iterations>("creations");
531 QTest::addColumn<Iterations>("iterations");
435
532
533 // ////////// //
534 // Test cases //
535 // ////////// //
536
537 testSyncOnVarCase1();
538 }
539
540 void TestVariableSync::testSync()
541 {
436 // Inits controllers
542 // Inits controllers
437 TimeController timeController{};
543 TimeController timeController{};
438 VariableController variableController{};
544 VariableController variableController{};
@@ -445,33 +551,6 void TestVariableSync::testSync()
445 // Synchronization group used
551 // Synchronization group used
446 variableController.onAddSynchronizationGroupId(syncId);
552 variableController.onAddSynchronizationGroupId(syncId);
447
553
448 auto validateRanges = [&variableController](const auto &expectedRanges) {
449 for (const auto &expectedRangeEntry : expectedRanges) {
450 auto variableIndex = expectedRangeEntry.first;
451 auto expectedRange = expectedRangeEntry.second;
452
453 // Gets the variable in the controller
454 auto variable = variableController.variableModel()->variable(variableIndex);
455
456 // Compares variable's range to the expected range
457 QVERIFY(variable != nullptr);
458 auto range = variable->range();
459 QCOMPARE(range, expectedRange);
460
461 // Compares variable's data with values expected for its range
462 auto dataSeries = variable->dataSeries();
463 QVERIFY(dataSeries != nullptr);
464
465 auto it = dataSeries->xAxisRange(range.m_TStart, range.m_TEnd);
466 auto expectedValues = values(range);
467 qInfo() << std::distance(it.first, it.second) << expectedValues.size();
468 QVERIFY(std::equal(it.first, it.second, expectedValues.cbegin(), expectedValues.cend(),
469 [](const auto &dataSeriesIt, const auto &expectedValue) {
470 return dataSeriesIt.value() == expectedValue;
471 }));
472 }
473 };
474
475 // For each iteration:
554 // For each iteration:
476 // - execute operation
555 // - execute operation
477 // - compare the variables' state to the expected states
556 // - compare the variables' state to the expected states
@@ -481,7 +560,7 void TestVariableSync::testSync()
481 iteration.m_Operation->exec(variableController);
560 iteration.m_Operation->exec(variableController);
482 QTest::qWait(operationDelay);
561 QTest::qWait(operationDelay);
483
562
484 validateRanges(iteration.m_ExpectedRanges);
563 validateRanges(variableController, iteration.m_ExpectedRanges);
485 }
564 }
486 }
565 }
487
566
@@ -499,54 +578,59 void TestVariableSync::testSyncWithAborting()
499 // Synchronization group used
578 // Synchronization group used
500 variableController.onAddSynchronizationGroupId(syncId);
579 variableController.onAddSynchronizationGroupId(syncId);
501
580
502 auto validateRanges = [&variableController](const auto &expectedRanges) {
581 // For each iteration:
503 for (const auto &expectedRangeEntry : expectedRanges) {
582 // - execute operation
504 auto variableIndex = expectedRangeEntry.first;
583 // - compare the variables' state to the expected states
505 auto expectedRange = expectedRangeEntry.second;
584 QFETCH(Iterations, iterations);
506
585 QFETCH(Iterations, creations);
507 // Gets the variable in the controller
586 QFETCH(int, operationDelay);
508 auto variable = variableController.variableModel()->variable(variableIndex);
509
587
510 // Compares variable's range to the expected range
588 for (const auto &creation : creations) {
511 QVERIFY(variable != nullptr);
589 creation.m_Operation->exec(variableController);
512 auto range = variable->range();
590 QTest::qWait(operationDelay);
513 qInfo() << "range vs expected range" << range << variable->range();
591 }
514 QCOMPARE(range, expectedRange);
515
592
516 // Compares variable's data with values expected for its range
593 for (const auto &iteration : iterations) {
517 auto dataSeries = variable->dataSeries();
594 iteration.m_Operation->exec(variableController);
518 QVERIFY(dataSeries != nullptr);
595 }
519
596
520 auto it = dataSeries->xAxisRange(range.m_TStart, range.m_TEnd);
597 QTest::qWait(operationDelay);
521 auto expectedValues = values(range);
598 validateRanges(variableController, iterations.back().m_ExpectedRanges);
522 qInfo() << std::distance(it.first, it.second) << expectedValues.size();
523 QVERIFY(std::equal(it.first, it.second, expectedValues.cbegin(), expectedValues.cend(),
524 [](const auto &dataSeriesIt, const auto &expectedValue) {
525 return dataSeriesIt.value() == expectedValue;
526 }));
527 }
599 }
528 };
600
601 void TestVariableSync::testSyncOneVar()
602 {
603 // Inits controllers
604 TimeController timeController{};
605 VariableController variableController{};
606 variableController.setTimeController(&timeController);
607
608 QFETCH(QUuid, syncId);
609 QFETCH(SqpRange, initialRange);
610 timeController.onTimeToUpdate(initialRange);
611
612 // Synchronization group used
613 variableController.onAddSynchronizationGroupId(syncId);
529
614
530 // For each iteration:
615 // For each iteration:
531 // - execute operation
616 // - execute operation
532 // - compare the variables' state to the expected states
617 // - compare the variables' state to the expected states
533 QFETCH(Iterations, iterations);
618 QFETCH(Iterations, iterations);
534 QFETCH(Iterations, creations);
619 QFETCH(Iterations, creations);
535 QFETCH(int, operationDelay);
536
620
537 for (const auto &creation : creations) {
621 for (const auto &creation : creations) {
538 creation.m_Operation->exec(variableController);
622 creation.m_Operation->exec(variableController);
539 QTest::qWait(operationDelay);
623 QTest::qWait(300);
540 }
624 }
541
625
542 for (const auto &iteration : iterations) {
626 for (const auto &iteration : iterations) {
543 iteration.m_Operation->exec(variableController);
627 iteration.m_Operation->exec(variableController);
544 }
628 }
545
629
546 QTest::qWait(operationDelay);
630 if (!iterations.empty()) {
547 validateRanges(iterations.back().m_ExpectedRanges);
631 validateRanges(variableController, iterations.back().m_ExpectedRanges);
632 }
548 }
633 }
549
550
634
551 QTEST_MAIN(TestVariableSync)
635 QTEST_MAIN(TestVariableSync)
552
636
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

Merge lasted acquisition developpement on main Sciqlop branch

You need to be logged in to leave comments. Login now