Auto status change to "Under Review"
@@ -1,390 +1,551 | |||
|
1 | 1 | #include <QObject> |
|
2 | 2 | #include <QtTest> |
|
3 | 3 | |
|
4 | 4 | #include <memory> |
|
5 | 5 | |
|
6 | 6 | #include <Data/DataProviderParameters.h> |
|
7 | 7 | #include <Data/IDataProvider.h> |
|
8 | 8 | #include <Data/ScalarSeries.h> |
|
9 | 9 | #include <Time/TimeController.h> |
|
10 | 10 | #include <Variable/Variable.h> |
|
11 | 11 | #include <Variable/VariableController.h> |
|
12 | 12 | #include <Variable/VariableModel.h> |
|
13 | 13 | |
|
14 | 14 | namespace { |
|
15 | 15 | |
|
16 | 16 | /// Delay after each operation on the variable before validating it (in ms) |
|
17 | 17 | const auto OPERATION_DELAY = 100; |
|
18 | 18 | |
|
19 | 19 | /** |
|
20 | 20 | * Generates values according to a range. The value generated for a time t is the number of seconds |
|
21 | 21 | * of difference between t and a reference value (which is midnight -> 00:00:00) |
|
22 | 22 | * |
|
23 | 23 | * Example: For a range between 00:00:10 and 00:00:20, the generated values are |
|
24 | 24 | * {10,11,12,13,14,15,16,17,18,19,20} |
|
25 | 25 | */ |
|
26 | 26 | std::vector<double> values(const SqpRange &range) |
|
27 | 27 | { |
|
28 | 28 | QTime referenceTime{0, 0}; |
|
29 | 29 | |
|
30 | 30 | std::vector<double> result{}; |
|
31 | 31 | |
|
32 | 32 | for (auto i = range.m_TStart; i <= range.m_TEnd; ++i) { |
|
33 | 33 | auto time = DateUtils::dateTime(i).time(); |
|
34 | 34 | result.push_back(referenceTime.secsTo(time)); |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | return result; |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | 40 | /// Provider used for the tests |
|
41 | 41 | class TestProvider : public IDataProvider { |
|
42 | 42 | std::shared_ptr<IDataProvider> clone() const { return std::make_shared<TestProvider>(); } |
|
43 | 43 | |
|
44 | 44 | void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters ¶meters) override |
|
45 | 45 | { |
|
46 | 46 | const auto &ranges = parameters.m_Times; |
|
47 | 47 | |
|
48 | 48 | for (const auto &range : ranges) { |
|
49 | 49 | // Generates data series |
|
50 | 50 | auto valuesData = values(range); |
|
51 | 51 | |
|
52 | 52 | std::vector<double> xAxisData{}; |
|
53 | 53 | for (auto i = range.m_TStart; i <= range.m_TEnd; ++i) { |
|
54 | 54 | xAxisData.push_back(i); |
|
55 | 55 | } |
|
56 | 56 | |
|
57 | 57 | auto dataSeries = std::make_shared<ScalarSeries>( |
|
58 | 58 | std::move(xAxisData), std::move(valuesData), Unit{"t", true}, Unit{}); |
|
59 | 59 | |
|
60 | 60 | emit dataProvided(acqIdentifier, dataSeries, range); |
|
61 | 61 | } |
|
62 | 62 | } |
|
63 | 63 | |
|
64 | 64 | void requestDataAborting(QUuid acqIdentifier) override |
|
65 | 65 | { |
|
66 | 66 | // Does nothing |
|
67 | 67 | } |
|
68 | 68 | }; |
|
69 | 69 | |
|
70 | 70 | /** |
|
71 | 71 | * Interface representing an operation performed on a variable controller. |
|
72 | 72 | * This interface is used in tests to apply a set of operations and check the status of the |
|
73 | 73 | * controller after each operation |
|
74 | 74 | */ |
|
75 | 75 | struct IOperation { |
|
76 | 76 | virtual ~IOperation() = default; |
|
77 | 77 | /// Executes the operation on the variable controller |
|
78 | 78 | virtual void exec(VariableController &variableController) const = 0; |
|
79 | 79 | }; |
|
80 | 80 | |
|
81 | 81 | /** |
|
82 | 82 | *Variable creation operation in the controller |
|
83 | 83 | */ |
|
84 | 84 | struct Create : public IOperation { |
|
85 | 85 | explicit Create(int index) : m_Index{index} {} |
|
86 | 86 | |
|
87 | 87 | void exec(VariableController &variableController) const override |
|
88 | 88 | { |
|
89 | 89 | auto variable = variableController.createVariable(QString::number(m_Index), {}, |
|
90 | 90 | std::make_unique<TestProvider>()); |
|
91 | 91 | } |
|
92 | 92 | |
|
93 | 93 | int m_Index; ///< The index of the variable to create in the controller |
|
94 | 94 | }; |
|
95 | 95 | |
|
96 | 96 | /** |
|
97 | 97 | * Variable move/shift operation in the controller |
|
98 | 98 | */ |
|
99 | 99 | struct Move : public IOperation { |
|
100 | 100 | explicit Move(int index, const SqpRange &newRange, bool shift = false) |
|
101 | 101 | : m_Index{index}, m_NewRange{newRange}, m_Shift{shift} |
|
102 | 102 | { |
|
103 | 103 | } |
|
104 | 104 | |
|
105 | 105 | void exec(VariableController &variableController) const override |
|
106 | 106 | { |
|
107 | 107 | if (auto variable = variableController.variableModel()->variable(m_Index)) { |
|
108 | 108 | variableController.onRequestDataLoading({variable}, m_NewRange, !m_Shift); |
|
109 | 109 | } |
|
110 | 110 | } |
|
111 | 111 | |
|
112 | 112 | int m_Index; ///< The index of the variable to move |
|
113 | 113 | SqpRange m_NewRange; ///< The new range of the variable |
|
114 | 114 | bool m_Shift; ///< Performs a shift ( |
|
115 | 115 | }; |
|
116 | 116 | |
|
117 | 117 | /** |
|
118 | 118 | * Variable synchronization/desynchronization operation in the controller |
|
119 | 119 | */ |
|
120 | 120 | struct Synchronize : public IOperation { |
|
121 | 121 | explicit Synchronize(int index, QUuid syncId, bool synchronize = true) |
|
122 | 122 | : m_Index{index}, m_SyncId{syncId}, m_Synchronize{synchronize} |
|
123 | 123 | { |
|
124 | 124 | } |
|
125 | 125 | |
|
126 | 126 | void exec(VariableController &variableController) const override |
|
127 | 127 | { |
|
128 | 128 | if (auto variable = variableController.variableModel()->variable(m_Index)) { |
|
129 | 129 | if (m_Synchronize) { |
|
130 | 130 | variableController.onAddSynchronized(variable, m_SyncId); |
|
131 | 131 | } |
|
132 | 132 | else { |
|
133 | 133 | variableController.desynchronize(variable, m_SyncId); |
|
134 | 134 | } |
|
135 | 135 | } |
|
136 | 136 | } |
|
137 | 137 | |
|
138 | 138 | int m_Index; ///< The index of the variable to sync/desync |
|
139 | 139 | QUuid m_SyncId; ///< The synchronization group of the variable |
|
140 | 140 | bool m_Synchronize; ///< Performs sync or desync operation |
|
141 | 141 | }; |
|
142 | 142 | |
|
143 | 143 | /** |
|
144 | 144 | * Test Iteration |
|
145 | 145 | * |
|
146 | 146 | * A test iteration includes an operation to be performed, and a set of expected ranges after each |
|
147 | 147 | * operation. Each range is tested after the operation to ensure that: |
|
148 | 148 | * - the range of the variable is the expected range |
|
149 | 149 | * - the data of the variable are those generated for the expected range |
|
150 | 150 | */ |
|
151 | 151 | struct Iteration { |
|
152 | 152 | std::shared_ptr<IOperation> m_Operation; ///< Operation to perform |
|
153 | 153 | std::map<int, SqpRange> m_ExpectedRanges; ///< Expected ranges (by variable index) |
|
154 | 154 | }; |
|
155 | 155 | |
|
156 | 156 | using Iterations = std::vector<Iteration>; |
|
157 | 157 | |
|
158 | 158 | } // namespace |
|
159 | 159 | |
|
160 | 160 | Q_DECLARE_METATYPE(Iterations) |
|
161 | 161 | |
|
162 | 162 | class TestVariableSync : public QObject { |
|
163 | 163 | Q_OBJECT |
|
164 | 164 | |
|
165 | 165 | private slots: |
|
166 | 166 | /// Input data for @sa testSync() |
|
167 | 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 | 175 | /// Tests synchronization between variables through several operations |
|
170 | 176 | void testSync(); |
|
171 | 177 | }; |
|
172 | 178 | |
|
173 | 179 | namespace { |
|
174 | 180 | |
|
175 | 181 | void testSyncCase1() |
|
176 | 182 | { |
|
177 | 183 | // Id used to synchronize variables in the controller |
|
178 | 184 | auto syncId = QUuid::createUuid(); |
|
179 | 185 | |
|
180 | 186 | /// Generates a range according to a start time and a end time (the date is the same) |
|
181 | 187 | auto range = [](const QTime &startTime, const QTime &endTime) { |
|
182 | 188 | return SqpRange{DateUtils::secondsSinceEpoch(QDateTime{{2017, 1, 1}, startTime, Qt::UTC}), |
|
183 | 189 | DateUtils::secondsSinceEpoch(QDateTime{{2017, 1, 1}, endTime, Qt::UTC})}; |
|
184 | 190 | }; |
|
185 | 191 | |
|
186 | 192 | auto initialRange = range({12, 0}, {13, 0}); |
|
187 | 193 | |
|
188 | 194 | Iterations iterations{}; |
|
189 | 195 | // Creates variables var0, var1 and var2 |
|
190 | 196 | iterations.push_back({std::make_shared<Create>(0), {{0, initialRange}}}); |
|
191 | 197 | iterations.push_back({std::make_shared<Create>(1), {{0, initialRange}, {1, initialRange}}}); |
|
192 | 198 | iterations.push_back( |
|
193 | 199 | {std::make_shared<Create>(2), {{0, initialRange}, {1, initialRange}, {2, initialRange}}}); |
|
194 | 200 | |
|
195 | 201 | // Adds variables into the sync group (ranges don't need to be tested here) |
|
196 | 202 | iterations.push_back({std::make_shared<Synchronize>(0, syncId)}); |
|
197 | 203 | iterations.push_back({std::make_shared<Synchronize>(1, syncId)}); |
|
198 | 204 | iterations.push_back({std::make_shared<Synchronize>(2, syncId)}); |
|
199 | 205 | |
|
200 | 206 | // Moves var0: ranges of var0, var1 and var2 change |
|
201 | 207 | auto newRange = range({12, 30}, {13, 30}); |
|
202 | 208 | iterations.push_back( |
|
203 | 209 | {std::make_shared<Move>(0, newRange), {{0, newRange}, {1, newRange}, {2, newRange}}}); |
|
204 | 210 | |
|
205 | 211 | // Moves var1: ranges of var0, var1 and var2 change |
|
206 | 212 | newRange = range({13, 0}, {14, 0}); |
|
207 | 213 | iterations.push_back( |
|
208 | 214 | {std::make_shared<Move>(0, newRange), {{0, newRange}, {1, newRange}, {2, newRange}}}); |
|
209 | 215 | |
|
210 | 216 | // Moves var2: ranges of var0, var1 and var2 change |
|
211 | 217 | newRange = range({13, 30}, {14, 30}); |
|
212 | 218 | iterations.push_back( |
|
213 | 219 | {std::make_shared<Move>(0, newRange), {{0, newRange}, {1, newRange}, {2, newRange}}}); |
|
214 | 220 | |
|
215 | 221 | // Desyncs var2 and moves var0: |
|
216 | 222 | // - ranges of var0 and var1 change |
|
217 | 223 | // - range of var2 doesn't change anymore |
|
218 | 224 | auto var2Range = newRange; |
|
219 | 225 | newRange = range({13, 45}, {14, 45}); |
|
220 | 226 | iterations.push_back({std::make_shared<Synchronize>(2, syncId, false)}); |
|
221 | 227 | iterations.push_back( |
|
222 | 228 | {std::make_shared<Move>(0, newRange), {{0, newRange}, {1, newRange}, {2, var2Range}}}); |
|
223 | 229 | |
|
224 | 230 | // Shifts var0: although var1 is synchronized with var0, its range doesn't change |
|
225 | 231 | auto var1Range = newRange; |
|
226 | 232 | newRange = range({14, 45}, {15, 45}); |
|
227 | 233 | iterations.push_back({std::make_shared<Move>(0, newRange, true), |
|
228 | 234 | {{0, newRange}, {1, var1Range}, {2, var2Range}}}); |
|
229 | 235 | |
|
230 | 236 | // Moves var0 through several operations: |
|
231 | 237 | // - range of var0 changes |
|
232 | 238 | // - range or var1 changes according to the previous shift (one hour) |
|
233 | 239 | auto moveVar0 = [&iterations](const auto &var0NewRange, const auto &var1ExpectedRange) { |
|
234 | 240 | iterations.push_back( |
|
235 | 241 | {std::make_shared<Move>(0, var0NewRange), {{0, var0NewRange}, {1, var1ExpectedRange}}}); |
|
236 | 242 | }; |
|
243 | ||
|
237 | 244 | // Pan left |
|
238 | 245 | moveVar0(range({14, 30}, {15, 30}), range({13, 30}, {14, 30})); |
|
239 | 246 | // Pan right |
|
240 | 247 | moveVar0(range({16, 0}, {17, 0}), range({15, 0}, {16, 0})); |
|
241 | 248 | // Zoom in |
|
242 | 249 | moveVar0(range({16, 30}, {16, 45}), range({15, 30}, {15, 45})); |
|
243 | 250 | // Zoom out |
|
244 | 251 | moveVar0(range({16, 15}, {17, 0}), range({15, 15}, {16, 0})); |
|
245 | 252 | |
|
246 | 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 | 333 | void testSyncCase2() |
|
250 | 334 | { |
|
251 | 335 | // Id used to synchronize variables in the controller |
|
252 | 336 | auto syncId = QUuid::createUuid(); |
|
253 | 337 | |
|
254 | 338 | /// Generates a range according to a start time and a end time (the date is the same) |
|
255 | 339 | auto dateTime = [](int year, int month, int day, int hours, int minutes, int seconds) { |
|
256 | 340 | return DateUtils::secondsSinceEpoch( |
|
257 | 341 | QDateTime{{year, month, day}, QTime{hours, minutes, seconds}, Qt::UTC}); |
|
258 | 342 | }; |
|
259 | 343 | |
|
260 | 344 | auto initialRange = SqpRange{dateTime(2017, 1, 1, 12, 0, 0), dateTime(2017, 1, 1, 13, 0, 0)}; |
|
261 | 345 | |
|
262 | 346 | Iterations iterations{}; |
|
263 | 347 | // Creates variables var0 and var1 |
|
264 | 348 | iterations.push_back({std::make_shared<Create>(0), {{0, initialRange}}}); |
|
265 | 349 | iterations.push_back({std::make_shared<Create>(1), {{0, initialRange}, {1, initialRange}}}); |
|
266 | 350 | |
|
267 | 351 | // Adds variables into the sync group (ranges don't need to be tested here) |
|
268 | 352 | iterations.push_back({std::make_shared<Synchronize>(0, syncId)}); |
|
269 | 353 | iterations.push_back({std::make_shared<Synchronize>(1, syncId)}); |
|
270 | 354 | |
|
271 | 355 | |
|
272 | 356 | // Moves var0 through several operations: |
|
273 | 357 | // - range of var0 changes |
|
274 | 358 | // - range or var1 changes according to the previous shift (one hour) |
|
275 | 359 | auto moveVar0 = [&iterations](const auto &var0NewRange) { |
|
276 | 360 | iterations.push_back( |
|
277 | 361 | {std::make_shared<Move>(0, var0NewRange), {{0, var0NewRange}, {1, var0NewRange}}}); |
|
278 | 362 | }; |
|
279 | 363 | moveVar0(SqpRange{dateTime(2017, 1, 1, 12, 0, 0), dateTime(2017, 1, 1, 13, 0, 0)}); |
|
280 | 364 | moveVar0(SqpRange{dateTime(2017, 1, 1, 14, 0, 0), dateTime(2017, 1, 1, 15, 0, 0)}); |
|
281 | 365 | moveVar0(SqpRange{dateTime(2017, 1, 1, 8, 0, 0), dateTime(2017, 1, 1, 9, 0, 0)}); |
|
282 | 366 | // moveVar0(SqpRange{dateTime(2017, 1, 1, 7, 30, 0), dateTime(2017, 1, 1, 9, 30, 0)}); |
|
283 | 367 | moveVar0(SqpRange{dateTime(2017, 1, 1, 2, 0, 0), dateTime(2017, 1, 1, 4, 0, 0)}); |
|
284 | 368 | moveVar0(SqpRange{dateTime(2017, 1, 1, 6, 0, 0), dateTime(2017, 1, 1, 8, 0, 0)}); |
|
285 | 369 | |
|
286 | 370 | moveVar0(SqpRange{dateTime(2017, 1, 10, 6, 0, 0), dateTime(2017, 1, 15, 8, 0, 0)}); |
|
287 | 371 | moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 1, 25, 8, 0, 0)}); |
|
288 | 372 | moveVar0(SqpRange{dateTime(2017, 1, 2, 6, 0, 0), dateTime(2017, 1, 8, 8, 0, 0)}); |
|
289 | 373 | |
|
290 | 374 | moveVar0(SqpRange{dateTime(2017, 4, 10, 6, 0, 0), dateTime(2017, 6, 15, 8, 0, 0)}); |
|
291 | 375 | moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 2, 25, 8, 0, 0)}); |
|
292 | 376 | moveVar0(SqpRange{dateTime(2017, 7, 2, 6, 0, 0), dateTime(2017, 10, 8, 8, 0, 0)}); |
|
293 | 377 | moveVar0(SqpRange{dateTime(2017, 4, 10, 6, 0, 0), dateTime(2017, 6, 15, 8, 0, 0)}); |
|
294 | 378 | moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 2, 25, 8, 0, 0)}); |
|
295 | 379 | moveVar0(SqpRange{dateTime(2017, 7, 2, 6, 0, 0), dateTime(2017, 10, 8, 8, 0, 0)}); |
|
296 | 380 | moveVar0(SqpRange{dateTime(2017, 4, 10, 6, 0, 0), dateTime(2017, 6, 15, 8, 0, 0)}); |
|
297 | 381 | moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 2, 25, 8, 0, 0)}); |
|
298 | 382 | moveVar0(SqpRange{dateTime(2017, 7, 2, 6, 0, 0), dateTime(2017, 10, 8, 8, 0, 0)}); |
|
299 | 383 | moveVar0(SqpRange{dateTime(2017, 4, 10, 6, 0, 0), dateTime(2017, 6, 15, 8, 0, 0)}); |
|
300 | 384 | moveVar0(SqpRange{dateTime(2017, 1, 17, 6, 0, 0), dateTime(2017, 2, 25, 8, 0, 0)}); |
|
301 | 385 | moveVar0(SqpRange{dateTime(2017, 7, 2, 6, 0, 0), dateTime(2017, 10, 8, 8, 0, 0)}); |
|
302 | 386 | |
|
303 | 387 | |
|
304 | 388 | QTest::newRow("sync2") << syncId << initialRange << iterations << 4000; |
|
305 | 389 | // QTest::newRow("sync3") << syncId << initialRange << iterations << 5000; |
|
306 | 390 | } |
|
307 | 391 | } |
|
308 | 392 | |
|
309 | 393 | void TestVariableSync::testSync_data() |
|
310 | 394 | { |
|
311 | 395 | // ////////////// // |
|
312 | 396 | // Test structure // |
|
313 | 397 | // ////////////// // |
|
314 | 398 | |
|
315 | 399 | QTest::addColumn<QUuid>("syncId"); |
|
316 | 400 | QTest::addColumn<SqpRange>("initialRange"); |
|
317 | 401 | QTest::addColumn<Iterations>("iterations"); |
|
318 | 402 | QTest::addColumn<int>("operationDelay"); |
|
319 | 403 | |
|
320 | 404 | // ////////// // |
|
321 | 405 | // Test cases // |
|
322 | 406 | // ////////// // |
|
323 | 407 | |
|
324 | 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 | 431 | void TestVariableSync::testSync() |
|
329 | 432 | { |
|
433 | return; | |
|
434 | ||
|
330 | 435 | // Inits controllers |
|
331 | 436 | TimeController timeController{}; |
|
332 | 437 | VariableController variableController{}; |
|
333 | 438 | variableController.setTimeController(&timeController); |
|
334 | 439 | |
|
335 | 440 | QFETCH(QUuid, syncId); |
|
336 | 441 | QFETCH(SqpRange, initialRange); |
|
337 | 442 | timeController.onTimeToUpdate(initialRange); |
|
338 | 443 | |
|
339 | 444 | // Synchronization group used |
|
340 | 445 | variableController.onAddSynchronizationGroupId(syncId); |
|
341 | 446 | |
|
342 | 447 | auto validateRanges = [&variableController](const auto &expectedRanges) { |
|
343 | 448 | for (const auto &expectedRangeEntry : expectedRanges) { |
|
344 | 449 | auto variableIndex = expectedRangeEntry.first; |
|
345 | 450 | auto expectedRange = expectedRangeEntry.second; |
|
346 | 451 | |
|
347 | 452 | // Gets the variable in the controller |
|
348 | 453 | auto variable = variableController.variableModel()->variable(variableIndex); |
|
349 | 454 | |
|
350 | 455 | // Compares variable's range to the expected range |
|
351 | 456 | QVERIFY(variable != nullptr); |
|
352 | 457 | auto range = variable->range(); |
|
353 | 458 | QCOMPARE(range, expectedRange); |
|
354 | 459 | |
|
355 | 460 | // Compares variable's data with values expected for its range |
|
356 | 461 | auto dataSeries = variable->dataSeries(); |
|
357 | 462 | QVERIFY(dataSeries != nullptr); |
|
358 | 463 | |
|
359 | 464 | auto it = dataSeries->xAxisRange(range.m_TStart, range.m_TEnd); |
|
360 | 465 | auto expectedValues = values(range); |
|
361 | 466 | qInfo() << std::distance(it.first, it.second) << expectedValues.size(); |
|
362 | 467 | QVERIFY(std::equal(it.first, it.second, expectedValues.cbegin(), expectedValues.cend(), |
|
363 | 468 | [](const auto &dataSeriesIt, const auto &expectedValue) { |
|
364 | 469 | return dataSeriesIt.value() == expectedValue; |
|
365 | 470 | })); |
|
366 | 471 | } |
|
367 | 472 | }; |
|
368 | 473 | |
|
369 | 474 | // For each iteration: |
|
370 | 475 | // - execute operation |
|
371 | 476 | // - compare the variables' state to the expected states |
|
372 | 477 | QFETCH(Iterations, iterations); |
|
373 | 478 | QFETCH(int, operationDelay); |
|
374 | 479 | for (const auto &iteration : iterations) { |
|
375 | 480 | iteration.m_Operation->exec(variableController); |
|
376 | 481 | QTest::qWait(operationDelay); |
|
377 | 482 | |
|
378 | 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 | 540 | for (const auto &iteration : iterations) { |
|
382 | 541 | iteration.m_Operation->exec(variableController); |
|
383 | 542 | } |
|
543 | ||
|
384 | 544 | QTest::qWait(operationDelay); |
|
385 | 545 | validateRanges(iterations.back().m_ExpectedRanges); |
|
386 | 546 | } |
|
387 | 547 | |
|
548 | ||
|
388 | 549 | QTEST_MAIN(TestVariableSync) |
|
389 | 550 | |
|
390 | 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