##// END OF EJS Templates
Update TestCosinusAcquisition to the new onRequestDataLoading API
perrinel -
r812:bec204429a95
parent child
Show More
@@ -1,194 +1,192
1 #include "CosinusProvider.h"
1 #include "CosinusProvider.h"
2 #include "MockDefs.h"
2 #include "MockDefs.h"
3
3
4 #include <Data/DataProviderParameters.h>
4 #include <Data/DataProviderParameters.h>
5 #include <Data/ScalarSeries.h>
5 #include <Data/ScalarSeries.h>
6 #include <SqpApplication.h>
6 #include <SqpApplication.h>
7 #include <Time/TimeController.h>
7 #include <Time/TimeController.h>
8 #include <Variable/Variable.h>
8 #include <Variable/Variable.h>
9 #include <Variable/VariableController.h>
9 #include <Variable/VariableController.h>
10
10
11 #include <QObject>
11 #include <QObject>
12 #include <QtTest>
12 #include <QtTest>
13
13
14 #include <cmath>
14 #include <cmath>
15 #include <memory>
15 #include <memory>
16
16
17 namespace {
17 namespace {
18
18
19 /// Path for the tests
19 /// Path for the tests
20 const auto TESTS_RESOURCES_PATH = QFileInfo{
20 const auto TESTS_RESOURCES_PATH = QFileInfo{
21 QString{MOCKPLUGIN_TESTS_RESOURCES_DIR},
21 QString{MOCKPLUGIN_TESTS_RESOURCES_DIR},
22 "TestCosinusAcquisition"}.absoluteFilePath();
22 "TestCosinusAcquisition"}.absoluteFilePath();
23
23
24 /// Format of dates in data files
24 /// Format of dates in data files
25 const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss:zzz");
25 const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss:zzz");
26
26
27 /**
27 /**
28 * Verifies that the data in the candidate series are identical to the data in the reference series
28 * Verifies that the data in the candidate series are identical to the data in the reference series
29 * in a specific range
29 * in a specific range
30 * @param candidate the candidate data series
30 * @param candidate the candidate data series
31 * @param range the range to check
31 * @param range the range to check
32 * @param reference the reference data series
32 * @param reference the reference data series
33 * @return true if the data of the candidate series and the reference series are identical in the
33 * @return true if the data of the candidate series and the reference series are identical in the
34 * range, false otherwise
34 * range, false otherwise
35 */
35 */
36 bool checkDataSeries(std::shared_ptr<IDataSeries> candidate, const SqpRange &range,
36 bool checkDataSeries(std::shared_ptr<IDataSeries> candidate, const SqpRange &range,
37 std::shared_ptr<IDataSeries> reference)
37 std::shared_ptr<IDataSeries> reference)
38 {
38 {
39 if (candidate == nullptr || reference == nullptr) {
39 if (candidate == nullptr || reference == nullptr) {
40 return candidate == reference;
40 return candidate == reference;
41 }
41 }
42
42
43 auto referenceIt = reference->xAxisRange(range.m_TStart, range.m_TEnd);
43 auto referenceIt = reference->xAxisRange(range.m_TStart, range.m_TEnd);
44
44
45 qInfo() << "candidateSize" << std::distance(candidate->cbegin(), candidate->cend());
45 qInfo() << "candidateSize" << std::distance(candidate->cbegin(), candidate->cend());
46 qInfo() << "refSize" << std::distance(referenceIt.first, referenceIt.second);
46 qInfo() << "refSize" << std::distance(referenceIt.first, referenceIt.second);
47
47
48 return std::equal(candidate->cbegin(), candidate->cend(), referenceIt.first, referenceIt.second,
48 return std::equal(candidate->cbegin(), candidate->cend(), referenceIt.first, referenceIt.second,
49 [](const auto &it1, const auto &it2) {
49 [](const auto &it1, const auto &it2) {
50 // - milliseconds precision for time
50 // - milliseconds precision for time
51 // - 1e-6 precision for value
51 // - 1e-6 precision for value
52 return std::abs(it1.x() - it2.x()) < 1e-3
52 return std::abs(it1.x() - it2.x()) < 1e-3
53 && std::abs(it1.value() - it2.value()) < 1e-6;
53 && std::abs(it1.value() - it2.value()) < 1e-6;
54 });
54 });
55 }
55 }
56
56
57 } // namespace
57 } // namespace
58
58
59 /**
59 /**
60 * @brief The TestCosinusAcquisition class tests acquisition in SciQlop (operations like zooms in,
60 * @brief The TestCosinusAcquisition class tests acquisition in SciQlop (operations like zooms in,
61 * zooms out, pans) of data from CosinusProvider
61 * zooms out, pans) of data from CosinusProvider
62 * @sa CosinusProvider
62 * @sa CosinusProvider
63 */
63 */
64 class TestCosinusAcquisition : public QObject {
64 class TestCosinusAcquisition : public QObject {
65 Q_OBJECT
65 Q_OBJECT
66
66
67 private slots:
67 private slots:
68 /// Input data for @sa testAcquisition()
68 /// Input data for @sa testAcquisition()
69 void testAcquisition_data();
69 void testAcquisition_data();
70 void testAcquisition();
70 void testAcquisition();
71 };
71 };
72
72
73 void TestCosinusAcquisition::testAcquisition_data()
73 void TestCosinusAcquisition::testAcquisition_data()
74 {
74 {
75 // ////////////// //
75 // ////////////// //
76 // Test structure //
76 // Test structure //
77 // ////////////// //
77 // ////////////// //
78
78
79 QTest::addColumn<SqpRange>("referenceRange"); // Range for generating reference series
79 QTest::addColumn<SqpRange>("referenceRange"); // Range for generating reference series
80 QTest::addColumn<SqpRange>("initialRange"); // First acquisition
80 QTest::addColumn<SqpRange>("initialRange"); // First acquisition
81 QTest::addColumn<int>("operationDelay"); // Acquisitions to make
81 QTest::addColumn<int>("operationDelay"); // Acquisitions to make
82 QTest::addColumn<std::vector<SqpRange> >("operations"); // Acquisitions to make
82 QTest::addColumn<std::vector<SqpRange> >("operations"); // Acquisitions to make
83
83
84 // ////////// //
84 // ////////// //
85 // Test cases //
85 // Test cases //
86 // ////////// //
86 // ////////// //
87
87
88 auto dateTime = [](int year, int month, int day, int hours, int minutes, int seconds) {
88 auto dateTime = [](int year, int month, int day, int hours, int minutes, int seconds) {
89 return DateUtils::secondsSinceEpoch(
89 return DateUtils::secondsSinceEpoch(
90 QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC});
90 QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC});
91 };
91 };
92
92
93 QTest::newRow("cosinus")
93 QTest::newRow("cosinus")
94 << SqpRange{dateTime(2017, 1, 1, 12, 0, 0), dateTime(2017, 1, 1, 13, 0, 0)}
94 << SqpRange{dateTime(2017, 1, 1, 12, 0, 0), dateTime(2017, 1, 1, 13, 0, 0)}
95 << SqpRange{dateTime(2017, 1, 1, 12, 30, 0), dateTime(2017, 1, 1, 12, 35, 1)} << 250
95 << SqpRange{dateTime(2017, 1, 1, 12, 30, 0), dateTime(2017, 1, 1, 12, 35, 1)} << 250
96 << std::vector<SqpRange>{
96 << std::vector<SqpRange>{
97 // Pan (jump) left
97 // Pan (jump) left
98 SqpRange{dateTime(2017, 1, 1, 12, 45, 0), dateTime(2017, 1, 1, 12, 50, 0)},
98 SqpRange{dateTime(2017, 1, 1, 12, 45, 0), dateTime(2017, 1, 1, 12, 50, 0)},
99 // Pan (jump) right
99 // Pan (jump) right
100 SqpRange{dateTime(2017, 1, 1, 12, 15, 0), dateTime(2017, 1, 1, 12, 20, 0)},
100 SqpRange{dateTime(2017, 1, 1, 12, 15, 0), dateTime(2017, 1, 1, 12, 20, 0)},
101 // Pan (overlay) right
101 // Pan (overlay) right
102 SqpRange{dateTime(2017, 1, 1, 12, 14, 0), dateTime(2017, 1, 1, 12, 19, 0)},
102 SqpRange{dateTime(2017, 1, 1, 12, 14, 0), dateTime(2017, 1, 1, 12, 19, 0)},
103 // Pan (overlay) left
103 // Pan (overlay) left
104 SqpRange{dateTime(2017, 1, 1, 12, 15, 0), dateTime(2017, 1, 1, 12, 20, 0)},
104 SqpRange{dateTime(2017, 1, 1, 12, 15, 0), dateTime(2017, 1, 1, 12, 20, 0)},
105 // Pan (overlay) left
105 // Pan (overlay) left
106 SqpRange{dateTime(2017, 1, 1, 12, 16, 0), dateTime(2017, 1, 1, 12, 21, 0)},
106 SqpRange{dateTime(2017, 1, 1, 12, 16, 0), dateTime(2017, 1, 1, 12, 21, 0)},
107 // Zoom in
107 // Zoom in
108 SqpRange{dateTime(2017, 1, 1, 12, 17, 30), dateTime(2017, 1, 1, 12, 19, 30)},
108 SqpRange{dateTime(2017, 1, 1, 12, 17, 30), dateTime(2017, 1, 1, 12, 19, 30)},
109 // Zoom out
109 // Zoom out
110 SqpRange{dateTime(2017, 1, 1, 12, 12, 30), dateTime(2017, 1, 1, 12, 24, 30)}};
110 SqpRange{dateTime(2017, 1, 1, 12, 12, 30), dateTime(2017, 1, 1, 12, 24, 30)}};
111
111
112 QTest::newRow("cosinus_big")
112 QTest::newRow("cosinus_big")
113 << SqpRange{dateTime(2017, 1, 1, 1, 0, 0), dateTime(2017, 1, 5, 13, 0, 0)}
113 << SqpRange{dateTime(2017, 1, 1, 1, 0, 0), dateTime(2017, 1, 5, 13, 0, 0)}
114 << SqpRange{dateTime(2017, 1, 2, 6, 30, 0), dateTime(2017, 1, 2, 18, 30, 0)} << 5000
114 << SqpRange{dateTime(2017, 1, 2, 6, 30, 0), dateTime(2017, 1, 2, 18, 30, 0)} << 5000
115 << std::vector<SqpRange>{
115 << std::vector<SqpRange>{
116 // Pan (jump) left
116 // Pan (jump) left
117 SqpRange{dateTime(2017, 1, 1, 13, 30, 0), dateTime(2017, 1, 1, 18, 30, 0)},
117 SqpRange{dateTime(2017, 1, 1, 13, 30, 0), dateTime(2017, 1, 1, 18, 30, 0)},
118 // Pan (jump) right
118 // Pan (jump) right
119 SqpRange{dateTime(2017, 1, 3, 4, 30, 0), dateTime(2017, 1, 3, 10, 30, 0)},
119 SqpRange{dateTime(2017, 1, 3, 4, 30, 0), dateTime(2017, 1, 3, 10, 30, 0)},
120 // Pan (overlay) right
120 // Pan (overlay) right
121 SqpRange{dateTime(2017, 1, 3, 8, 30, 0), dateTime(2017, 1, 3, 12, 30, 0)},
121 SqpRange{dateTime(2017, 1, 3, 8, 30, 0), dateTime(2017, 1, 3, 12, 30, 0)},
122 // Pan (overlay) left
122 // Pan (overlay) left
123 SqpRange{dateTime(2017, 1, 2, 8, 30, 0), dateTime(2017, 1, 3, 10, 30, 0)},
123 SqpRange{dateTime(2017, 1, 2, 8, 30, 0), dateTime(2017, 1, 3, 10, 30, 0)},
124 // Pan (overlay) left
124 // Pan (overlay) left
125 SqpRange{dateTime(2017, 1, 1, 12, 30, 0), dateTime(2017, 1, 3, 5, 30, 0)},
125 SqpRange{dateTime(2017, 1, 1, 12, 30, 0), dateTime(2017, 1, 3, 5, 30, 0)},
126 // Zoom in
126 // Zoom in
127 SqpRange{dateTime(2017, 1, 2, 2, 30, 0), dateTime(2017, 1, 2, 8, 30, 0)},
127 SqpRange{dateTime(2017, 1, 2, 2, 30, 0), dateTime(2017, 1, 2, 8, 30, 0)},
128 // Zoom out
128 // Zoom out
129 SqpRange{dateTime(2017, 1, 1, 14, 30, 0), dateTime(2017, 1, 3, 12, 30, 0)}};
129 SqpRange{dateTime(2017, 1, 1, 14, 30, 0), dateTime(2017, 1, 3, 12, 30, 0)}};
130 }
130 }
131
131
132 void TestCosinusAcquisition::testAcquisition()
132 void TestCosinusAcquisition::testAcquisition()
133 {
133 {
134 // Retrieves reference range
134 // Retrieves reference range
135 QFETCH(SqpRange, referenceRange);
135 QFETCH(SqpRange, referenceRange);
136 CosinusProvider referenceProvider{};
136 CosinusProvider referenceProvider{};
137 auto dataSeries = referenceProvider.provideDataSeries(
137 auto dataSeries = referenceProvider.provideDataSeries(
138 referenceRange, {{COSINUS_TYPE_KEY, "scalar"}, {COSINUS_FREQUENCY_KEY, 100.}});
138 referenceRange, {{COSINUS_TYPE_KEY, "scalar"}, {COSINUS_FREQUENCY_KEY, 100.}});
139
139
140 auto end = dataSeries->cend() - 1;
140 auto end = dataSeries->cend() - 1;
141 qInfo() << dataSeries->nbPoints() << dataSeries->cbegin()->x() << end->x();
141 qInfo() << dataSeries->nbPoints() << dataSeries->cbegin()->x() << end->x();
142
142
143 /// Lambda used to validate a variable at each step
143 /// Lambda used to validate a variable at each step
144 auto validateVariable
144 auto validateVariable
145 = [dataSeries](std::shared_ptr<Variable> variable, const SqpRange &range) {
145 = [dataSeries](std::shared_ptr<Variable> variable, const SqpRange &range) {
146 // Checks that the variable's range has changed
146 // Checks that the variable's range has changed
147 QCOMPARE(variable->range(), range);
147 QCOMPARE(variable->range(), range);
148
148
149 // Checks the variable's data series
149 // Checks the variable's data series
150 QVERIFY(checkDataSeries(variable->dataSeries(), variable->cacheRange(), dataSeries));
150 QVERIFY(checkDataSeries(variable->dataSeries(), variable->cacheRange(), dataSeries));
151 };
151 };
152
152
153 // Creates variable
153 // Creates variable
154 QFETCH(SqpRange, initialRange);
154 QFETCH(SqpRange, initialRange);
155 sqpApp->timeController().onTimeToUpdate(initialRange);
155 sqpApp->timeController().onTimeToUpdate(initialRange);
156 auto provider = std::make_shared<CosinusProvider>();
156 auto provider = std::make_shared<CosinusProvider>();
157 auto variable = sqpApp->variableController().createVariable(
157 auto variable = sqpApp->variableController().createVariable(
158 "MMS", {{COSINUS_TYPE_KEY, "scalar"}, {COSINUS_FREQUENCY_KEY, 100.}}, provider);
158 "MMS", {{COSINUS_TYPE_KEY, "scalar"}, {COSINUS_FREQUENCY_KEY, 100.}}, provider);
159
159
160 QFETCH(int, operationDelay);
160 QFETCH(int, operationDelay);
161 QTest::qWait(operationDelay);
161 QTest::qWait(operationDelay);
162 validateVariable(variable, initialRange);
162 validateVariable(variable, initialRange);
163
163
164 // Makes operations on the variable
164 // Makes operations on the variable
165 QFETCH(std::vector<SqpRange>, operations);
165 QFETCH(std::vector<SqpRange>, operations);
166 for (const auto &operation : operations) {
166 for (const auto &operation : operations) {
167 // Asks request on the variable and waits during its execution
167 // Asks request on the variable and waits during its execution
168 sqpApp->variableController().onRequestDataLoading({variable}, operation, variable->range(),
168 sqpApp->variableController().onRequestDataLoading({variable}, operation, true);
169 true);
170
169
171 QTest::qWait(operationDelay);
170 QTest::qWait(operationDelay);
172 validateVariable(variable, operation);
171 validateVariable(variable, operation);
173 }
172 }
174
173
175
174
176 for (const auto &operation : operations) {
175 for (const auto &operation : operations) {
177 // Asks request on the variable and waits during its execution
176 // Asks request on the variable and waits during its execution
178 sqpApp->variableController().onRequestDataLoading({variable}, operation, variable->range(),
177 sqpApp->variableController().onRequestDataLoading({variable}, operation, true);
179 true);
180 }
178 }
181 QTest::qWait(operationDelay);
179 QTest::qWait(operationDelay);
182 validateVariable(variable, operations.back());
180 validateVariable(variable, operations.back());
183 }
181 }
184
182
185 int main(int argc, char *argv[])
183 int main(int argc, char *argv[])
186 {
184 {
187 SqpApplication app{argc, argv};
185 SqpApplication app{argc, argv};
188 app.setAttribute(Qt::AA_Use96Dpi, true);
186 app.setAttribute(Qt::AA_Use96Dpi, true);
189 TestCosinusAcquisition testObject{};
187 TestCosinusAcquisition testObject{};
190 QTEST_SET_MAIN_SOURCE_PATH
188 QTEST_SET_MAIN_SOURCE_PATH
191 return QTest::qExec(&testObject, argc, argv);
189 return QTest::qExec(&testObject, argc, argv);
192 }
190 }
193
191
194 #include "TestCosinusAcquisition.moc"
192 #include "TestCosinusAcquisition.moc"
General Comments 0
You need to be logged in to leave comments. Login now