##// END OF EJS Templates
Update TestAmdaAcquisition for TDD
perrinel -
r833:e86994cc952a
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,115 +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
76
113 QEventLoop loop;
77 QTest::addColumn<QString>("dataFilename"); // File containing expected data of acquisitions
114 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
78 QTest::addColumn<SqpRange>("initialRange"); // First acquisition
115 loop.exec();
79 QTest::addColumn<std::vector<SqpRange> >("operations"); // Acquisitions to make
116
80
117 // Tests on acquisition operation
81 // ////////// //
118
82 // Test cases //
119 int count = 1;
83 // ////////// //
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, true);
127
128 QEventLoop loop;
129 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
130 loop.exec();
131
132 qInfo() << count << "RANGE " << var->range();
133 qInfo() << count << "CACHERANGE" << var->cacheRange();
134
135 QCOMPARE(var->range().m_TStart, nextSqpR.m_TStart);
136 QCOMPARE(var->range().m_TEnd, nextSqpR.m_TEnd);
137
138 // Verify dataserie
139 QVERIFY(compareDataSeries<ScalarSeries>(var->dataSeries(), var->cacheRange(), results));
140
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});
141 };
88 };
142
89
143 // 2 : pan (jump) left for one hour
144 auto nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 1, 0, 0}};
145 auto nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 2, 0, 0}};
146 // requestDataLoading(nextVarRS, nextVarRE);
147
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 two min
96 SqpRange{dateTime(2012, 1, 2, 2, 1, 0), dateTime(2012, 1, 2, 2, 2, 0)},
97 // 3 : pan (jump) right for four min
98 SqpRange{dateTime(2012, 1, 2, 2, 5, 0), dateTime(2012, 1, 2, 2, 6, 0)},
99 // 4 : pan (overlay) right for 30 sec
100 /*SqpRange{dateTime(2012, 1, 2, 2, 5, 30), dateTime(2012, 1, 2, 2, 6, 30)},
101 // 5 : pan (overlay) left for 30 sec
102 SqpRange{dateTime(2012, 1, 2, 2, 5, 0), dateTime(2012, 1, 2, 2, 6, 0)},
103 // 6 : pan (overlay) left for 30 sec - BIS
104 SqpRange{dateTime(2012, 1, 2, 2, 4, 30), dateTime(2012, 1, 2, 2, 5, 30)},
105 // 7 : Zoom in Inside 20 sec range
106 SqpRange{dateTime(2012, 1, 2, 2, 4, 50), dateTime(2012, 1, 2, 2, 5, 10)},
107 // 8 : Zoom out Inside 20 sec range
108 SqpRange{dateTime(2012, 1, 2, 2, 4, 30), dateTime(2012, 1, 2, 2, 5, 30)}*/};
109 }
148
110
149 // 3 : pan (jump) right for one hour
111 void TestAmdaAcquisition::testAcquisition()
150 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 0, 0}};
112 {
151 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
113 /// @todo: update test to be compatible with AMDA v2
152 // requestDataLoading(nextVarRS, nextVarRE);
153
114
154 // 4 : pan (overlay) right for 30 min
115 // Retrieves data file
155 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 30, 0}};
116 QFETCH(QString, dataFilename);
156 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 30, 0}};
117 auto filePath = QFileInfo{TESTS_RESOURCES_PATH, dataFilename}.absoluteFilePath();
157 // requestDataLoading(nextVarRS, nextVarRE);
118 auto results = AmdaResultParser::readTxt(filePath, AmdaResultParser::ValueType::SCALAR);
158
119
159 // 5 : pan (overlay) left for 30 min
120 /// Lambda used to validate a variable at each step
160 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 0, 0}};
121 auto validateVariable = [results](std::shared_ptr<Variable> variable, const SqpRange &range) {
161 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
122 // Checks that the variable's range has changed
162 // requestDataLoading(nextVarRS, nextVarRE);
123 qInfo() << tr("Compare var range vs range") << variable->range() << range;
124 QCOMPARE(variable->range(), range);
163
125
164 // 6 : pan (overlay) left for 30 min - BIS
126 // Checks the variable's data series
165 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 30, 0}};
127 QVERIFY(compareDataSeries<ScalarSeries>(variable->dataSeries(), variable->cacheRange(),
166 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 30, 0}};
128 results));
167 // requestDataLoading(nextVarRS, nextVarRE);
129 qInfo() << "\n";
130 };
168
131
169 // 7 : Zoom in Inside 20 min range
132 // Creates variable
170 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 50, 0}};
133 QFETCH(SqpRange, initialRange);
171 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 10, 0}};
134 sqpApp->timeController().onTimeToUpdate(initialRange);
172 // requestDataLoading(nextVarRS, nextVarRE);
135 auto provider = std::make_shared<AmdaProvider>();
136 auto variable = sqpApp->variableController().createVariable(
137 "bx_gse", {{"dataType", "scalar"}, {"xml:id", "imf(0)"}}, provider);
173
138
174 // 8 : Zoom out Inside 2 hours range
139 QTest::qWait(OPERATION_DELAY);
175 nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 0, 0}};
140 validateVariable(variable, initialRange);
176 nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}};
177 // requestDataLoading(nextVarRS, nextVarRE);
178
141
142 // Makes operations on the variable
143 QFETCH(std::vector<SqpRange>, operations);
144 for (const auto &operation : operations) {
145 // Asks request on the variable and waits during its execution
146 sqpApp->variableController().onRequestDataLoading({variable}, operation, false);
179
147
180 // Close the app after 10 sec
148 QTest::qWait(OPERATION_DELAY);
181 QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit);
149 validateVariable(variable, operation);
182 loop.exec();
150 }
183 }
151 }
184
152
185 int main(int argc, char *argv[])
153 int main(int argc, char *argv[])
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

Merge lasted acquisition developpement on main Sciqlop branch

You need to be logged in to leave comments. Login now