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