Auto status change to "Under Review"
@@ -1,195 +1,195 | |||||
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, 10 |
|
138 | referenceRange, {{COSINUS_TYPE_KEY, "scalar"}, {COSINUS_FREQUENCY_KEY, 10.}}); | |
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 | qInfo() << "range vs expected range" << variable->range() << range; |
|
147 | qInfo() << "range vs expected range" << variable->range() << range; | |
148 | QCOMPARE(variable->range(), range); |
|
148 | QCOMPARE(variable->range(), range); | |
149 |
|
149 | |||
150 | // Checks the variable's data series |
|
150 | // Checks the variable's data series | |
151 | QVERIFY(checkDataSeries(variable->dataSeries(), variable->cacheRange(), dataSeries)); |
|
151 | QVERIFY(checkDataSeries(variable->dataSeries(), variable->cacheRange(), dataSeries)); | |
152 | }; |
|
152 | }; | |
153 |
|
153 | |||
154 | // Creates variable |
|
154 | // Creates variable | |
155 | QFETCH(SqpRange, initialRange); |
|
155 | QFETCH(SqpRange, initialRange); | |
156 | sqpApp->timeController().onTimeToUpdate(initialRange); |
|
156 | sqpApp->timeController().onTimeToUpdate(initialRange); | |
157 | auto provider = std::make_shared<CosinusProvider>(); |
|
157 | auto provider = std::make_shared<CosinusProvider>(); | |
158 | auto variable = sqpApp->variableController().createVariable( |
|
158 | auto variable = sqpApp->variableController().createVariable( | |
159 |
"MMS", {{COSINUS_TYPE_KEY, "scalar"}, {COSINUS_FREQUENCY_KEY, 10 |
|
159 | "MMS", {{COSINUS_TYPE_KEY, "scalar"}, {COSINUS_FREQUENCY_KEY, 10.}}, provider); | |
160 |
|
160 | |||
161 |
|
161 | |||
162 | QFETCH(int, operationDelay); |
|
162 | QFETCH(int, operationDelay); | |
163 | QTest::qWait(operationDelay); |
|
163 | QTest::qWait(operationDelay); | |
164 | validateVariable(variable, initialRange); |
|
164 | validateVariable(variable, initialRange); | |
165 |
|
165 | |||
166 | QTest::qWait(operationDelay); |
|
166 | QTest::qWait(operationDelay); | |
167 | // Makes operations on the variable |
|
167 | // Makes operations on the variable | |
168 | QFETCH(std::vector<SqpRange>, operations); |
|
168 | QFETCH(std::vector<SqpRange>, operations); | |
169 | for (const auto &operation : operations) { |
|
169 | for (const auto &operation : operations) { | |
170 | // Asks request on the variable and waits during its execution |
|
170 | // Asks request on the variable and waits during its execution | |
171 | sqpApp->variableController().onRequestDataLoading({variable}, operation, false); |
|
171 | sqpApp->variableController().onRequestDataLoading({variable}, operation, false); | |
172 |
|
172 | |||
173 | QTest::qWait(operationDelay); |
|
173 | QTest::qWait(operationDelay); | |
174 | validateVariable(variable, operation); |
|
174 | validateVariable(variable, operation); | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 |
|
177 | |||
178 | for (const auto &operation : operations) { |
|
178 | for (const auto &operation : operations) { | |
179 | // Asks request on the variable and waits during its execution |
|
179 | // Asks request on the variable and waits during its execution | |
180 | sqpApp->variableController().onRequestDataLoading({variable}, operation, false); |
|
180 | sqpApp->variableController().onRequestDataLoading({variable}, operation, false); | |
181 | } |
|
181 | } | |
182 | QTest::qWait(operationDelay); |
|
182 | QTest::qWait(operationDelay); | |
183 | validateVariable(variable, operations.back()); |
|
183 | validateVariable(variable, operations.back()); | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | int main(int argc, char *argv[]) |
|
186 | int main(int argc, char *argv[]) | |
187 | { |
|
187 | { | |
188 | SqpApplication app{argc, argv}; |
|
188 | SqpApplication app{argc, argv}; | |
189 | app.setAttribute(Qt::AA_Use96Dpi, true); |
|
189 | app.setAttribute(Qt::AA_Use96Dpi, true); | |
190 | TestCosinusAcquisition testObject{}; |
|
190 | TestCosinusAcquisition testObject{}; | |
191 | QTEST_SET_MAIN_SOURCE_PATH |
|
191 | QTEST_SET_MAIN_SOURCE_PATH | |
192 | return QTest::qExec(&testObject, argc, argv); |
|
192 | return QTest::qExec(&testObject, argc, argv); | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | #include "TestCosinusAcquisition.moc" |
|
195 | #include "TestCosinusAcquisition.moc" |
General Comments 3
Status change > Approved
You need to be logged in to leave comments.
Login now