##// END OF EJS Templates
Updates Amda acquisition test to be DDD
Alexandre Leroux -
r788:357a617c7e23
parent child
Show More
@@ -21,7 +21,7
21 // Frame : GSE - Mission : ACE -
21 // Frame : GSE - Mission : ACE -
22 // Instrument : MFI - Dataset : mfi_final-prelim
22 // Instrument : MFI - Dataset : mfi_final-prelim
23 // REFERENCE DOWNLOAD FILE =
23 // REFERENCE DOWNLOAD FILE =
24 // http://amda.irap.omp.eu/php/rest/getParameter.php?startTime=2012-01-01T12:00:00&stopTime=2012-01-03T12:00:00&parameterID=imf(0)&outputFormat=ASCII&timeFormat=ISO8601&gzip=0
24 // http://amdatest.irap.omp.eu/php/rest/getParameter.php?startTime=2012-01-01T12:00:00&stopTime=2012-01-03T12:00:00&parameterID=imf(0)&outputFormat=ASCII&timeFormat=ISO8601&gzip=0
25
25
26 namespace {
26 namespace {
27
27
@@ -29,7 +29,8 namespace {
29 const auto TESTS_RESOURCES_PATH
29 const auto TESTS_RESOURCES_PATH
30 = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaAcquisition"}.absoluteFilePath();
30 = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaAcquisition"}.absoluteFilePath();
31
31
32 const auto TESTS_AMDA_REF_FILE = QString{"AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00.txt"};
32 /// Delay after each operation on the variable before validating it (in ms)
33 const auto OPERATION_DELAY = 10000;
33
34
34 template <typename T>
35 template <typename T>
35 bool compareDataSeries(std::shared_ptr<IDataSeries> candidate, SqpRange candidateCacheRange,
36 bool compareDataSeries(std::shared_ptr<IDataSeries> candidate, SqpRange candidateCacheRange,
@@ -49,15 +50,6 bool compareDataSeries(std::shared_ptr<IDataSeries> candidate, SqpRange candidat
49 qDebug() << " DISTANCE" << std::distance(candidateDS->cbegin(), candidateDS->cend())
50 qDebug() << " DISTANCE" << std::distance(candidateDS->cbegin(), candidateDS->cend())
50 << std::distance(itRefs.first, itRefs.second);
51 << std::distance(itRefs.first, itRefs.second);
51
52
52 // auto xcValue = candidateDS->valuesData()->data();
53 // auto dist = std::distance(itRefs.first, itRefs.second);
54 // auto it = itRefs.first;
55 // for (auto i = 0; i < dist - 1; ++i) {
56 // ++it;
57 // qInfo() << "END:" << it->value();
58 // }
59 // qDebug() << "END:" << it->value() << xcValue.last();
60
61 return std::equal(candidateDS->cbegin(), candidateDS->cend(), itRefs.first, itRefs.second,
53 return std::equal(candidateDS->cbegin(), candidateDS->cend(), itRefs.first, itRefs.second,
62 compareLambda);
54 compareLambda);
63 }
55 }
@@ -71,116 +63,91 class TestAmdaAcquisition : public QObject {
71 Q_OBJECT
63 Q_OBJECT
72
64
73 private slots:
65 private slots:
66 /// Input data for @sa testAcquisition()
67 void testAcquisition_data();
74 void testAcquisition();
68 void testAcquisition();
75 };
69 };
76
70
77 void TestAmdaAcquisition::testAcquisition()
71 void TestAmdaAcquisition::testAcquisition_data()
78 {
72 {
79 /// @todo: update test to be compatible with AMDA v2
73 // ////////////// //
80
74 // Test structure //
81 // READ the ref file:
75 // ////////////// //
82 auto filePath = QFileInfo{TESTS_RESOURCES_PATH, TESTS_AMDA_REF_FILE}.absoluteFilePath();
83 auto results = AmdaResultParser::readTxt(filePath, AmdaResultParser::ValueType::SCALAR);
84
85 auto provider = std::make_shared<AmdaProvider>();
86 auto timeController = std::make_unique<TimeController>();
87
88 auto varRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 3, 0, 0}};
89 auto varRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 0, 0}};
90
91 auto sqpR = SqpRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)};
92
93 timeController->onTimeToUpdate(sqpR);
94
95 QVariantHash metaData;
96 metaData.insert("dataType", "scalar");
97 metaData.insert("xml:id", "imf(0)");
98
99 VariableController vc;
100 vc.setTimeController(timeController.get());
101
102 auto var = vc.createVariable("bx_gse", metaData, provider);
103
104 // 1 : Variable creation
105
106 qDebug() << " 1: TIMECONTROLLER" << timeController->dateTime();
107 qDebug() << " 1: RANGE " << var->range();
108 qDebug() << " 1: CACHERANGE" << var->cacheRange();
109
110 // wait for 10 sec before asking next request toi permit asynchrone process to finish.
111 auto timeToWaitMs = 10000;
112
113 QEventLoop loop;
114 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
115 loop.exec();
116
117 // Tests on acquisition operation
118
119 int count = 1;
120
121 auto requestDataLoading = [&vc, var, timeToWaitMs, results, &count](auto tStart, auto tEnd) {
122 ++count;
123
124 auto nextSqpR
125 = SqpRange{DateUtils::secondsSinceEpoch(tStart), DateUtils::secondsSinceEpoch(tEnd)};
126 vc.onRequestDataLoading(QVector<std::shared_ptr<Variable> >{} << var, nextSqpR,
127 var->range(), true);
128
129 QEventLoop loop;
130 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
131 loop.exec();
132
133 qInfo() << count << "RANGE " << var->range();
134 qInfo() << count << "CACHERANGE" << var->cacheRange();
135
76
136 QCOMPARE(var->range().m_TStart, nextSqpR.m_TStart);
77 QTest::addColumn<QString>("dataFilename"); // File containing expected data of acquisitions
137 QCOMPARE(var->range().m_TEnd, nextSqpR.m_TEnd);
78 QTest::addColumn<SqpRange>("initialRange"); // First acquisition
79 QTest::addColumn<std::vector<SqpRange> >("operations"); // Acquisitions to make
138
80
139 // Verify dataserie
81 // ////////// //
140 QVERIFY(compareDataSeries<ScalarSeries>(var->dataSeries(), var->cacheRange(), results));
82 // Test cases //
83 // ////////// //
141
84
85 auto dateTime = [](int year, int month, int day, int hours, int minutes, int seconds) {
86 return DateUtils::secondsSinceEpoch(
87 QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC});
142 };
88 };
143
89
144 // 2 : pan (jump) left for one hour
145 auto nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 1, 0, 0}};
146 auto nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 2, 0, 0}};
147 // requestDataLoading(nextVarRS, nextVarRE);
148
149
90
91 QTest::newRow("amda")
92 << "AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00.txt"
93 << SqpRange{dateTime(2012, 1, 2, 2, 3, 0), dateTime(2012, 1, 2, 2, 4, 0)}
94 << std::vector<SqpRange>{
95 // 2 : pan (jump) left for one hour
96 // SqpRange{dateTime(2012, 1, 2, 2, 1, 0), dateTime(2012, 1, 2, 2, 2, 0)},
150 // 3 : pan (jump) right for one hour
97 // 3 : pan (jump) right for one hour
151 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 0, 0}};
98 // SqpRange{dateTime(2012, 1, 2, 2, 5, 0), dateTime(2012, 1, 2, 2, 6, 0)},
152 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
153 // requestDataLoading(nextVarRS, nextVarRE);
154
155 // 4 : pan (overlay) right for 30 min
99 // 4 : pan (overlay) right for 30 min
156 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 30, 0}};
100 // SqpRange{dateTime(2012, 1, 2, 2, 5, 30), dateTime(2012, 1, 2, 2, 6, 30)},
157 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 30, 0}};
158 // requestDataLoading(nextVarRS, nextVarRE);
159
160 // 5 : pan (overlay) left for 30 min
101 // 5 : pan (overlay) left for 30 min
161 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 0, 0}};
102 // SqpRange{dateTime(2012, 1, 2, 2, 5, 0), dateTime(2012, 1, 2, 2, 6, 0)},
162 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
163 // requestDataLoading(nextVarRS, nextVarRE);
164
165 // 6 : pan (overlay) left for 30 min - BIS
103 // 6 : pan (overlay) left for 30 min - BIS
166 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 30, 0}};
104 // SqpRange{dateTime(2012, 1, 2, 4, 30, 0), dateTime(2012, 1, 2, 2, 5, 30)},
167 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 30, 0}};
168 // requestDataLoading(nextVarRS, nextVarRE);
169
170 // 7 : Zoom in Inside 20 min range
105 // 7 : Zoom in Inside 20 min range
171 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 50, 0}};
106 // SqpRange{dateTime(2012, 1, 2, 2, 4, 50), dateTime(2012, 1, 2, 2, 5, 10)},
172 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 10, 0}};
173 // requestDataLoading(nextVarRS, nextVarRE);
174
175 // 8 : Zoom out Inside 2 hours range
107 // 8 : Zoom out Inside 2 hours range
176 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 0, 0}};
108 // SqpRange{dateTime(2012, 1, 2, 2, 4, 0), dateTime(2012, 1, 2, 2, 6, 0)}
177 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
109 };
178 // requestDataLoading(nextVarRS, nextVarRE);
110 }
179
111
112 void TestAmdaAcquisition::testAcquisition()
113 {
114 /// @todo: update test to be compatible with AMDA v2
115
116 // Retrieves data file
117 QFETCH(QString, dataFilename);
118 auto filePath = QFileInfo{TESTS_RESOURCES_PATH, dataFilename}.absoluteFilePath();
119 auto results = AmdaResultParser::readTxt(filePath, AmdaResultParser::ValueType::SCALAR);
120
121 /// Lambda used to validate a variable at each step
122 auto validateVariable = [results](std::shared_ptr<Variable> variable, const SqpRange &range) {
123 // Checks that the variable's range has changed
124 QCOMPARE(variable->range(), range);
125
126 // Checks the variable's data series
127 QVERIFY(compareDataSeries<ScalarSeries>(variable->dataSeries(), variable->cacheRange(),
128 results));
129 };
180
130
181 // Close the app after 10 sec
131 // Creates variable
182 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
132 QFETCH(SqpRange, initialRange);
183 loop.exec();
133 sqpApp->timeController().onTimeToUpdate(initialRange);
134 auto provider = std::make_shared<AmdaProvider>();
135 auto variable = sqpApp->variableController().createVariable(
136 "bx_gse", {{"dataType", "scalar"}, {"xml:id", "imf(0)"}}, provider);
137
138 QTest::qWait(OPERATION_DELAY);
139 validateVariable(variable, initialRange);
140
141 // Makes operations on the variable
142 QFETCH(std::vector<SqpRange>, operations);
143 for (const auto &operation : operations) {
144 // Asks request on the variable and waits during its execution
145 sqpApp->variableController().onRequestDataLoading({variable}, operation, variable->range(),
146 true);
147
148 QTest::qWait(OPERATION_DELAY);
149 validateVariable(variable, operation);
150 }
184 }
151 }
185
152
186 int main(int argc, char *argv[])
153 int main(int argc, char *argv[])
General Comments 0
You need to be logged in to leave comments. Login now