##// END OF EJS Templates
Update AmdaTestAcquisition
perrinel -
r790:bec987f6862b feature/AmdaAcqDDD
parent child
Show More
@@ -1,164 +1,165
1 #include "AmdaProvider.h"
1 #include "AmdaProvider.h"
2 #include "AmdaResultParser.h"
2 #include "AmdaResultParser.h"
3
3
4 #include "SqpApplication.h"
4 #include "SqpApplication.h"
5 #include <Data/DataSeries.h>
5 #include <Data/DataSeries.h>
6 #include <Data/IDataSeries.h>
6 #include <Data/IDataSeries.h>
7 #include <Data/ScalarSeries.h>
7 #include <Data/ScalarSeries.h>
8 #include <Time/TimeController.h>
8 #include <Time/TimeController.h>
9 #include <Variable/Variable.h>
9 #include <Variable/Variable.h>
10 #include <Variable/VariableController.h>
10 #include <Variable/VariableController.h>
11
11
12 #include <QObject>
12 #include <QObject>
13 #include <QtTest>
13 #include <QtTest>
14
14
15 #include <memory>
15 #include <memory>
16
16
17 // TEST with REF:
17 // TEST with REF:
18 // AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00
18 // AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00
19 // imf(0) - Type : Local Parameter @ CDPP/AMDA -
19 // imf(0) - Type : Local Parameter @ CDPP/AMDA -
20 // Name : bx_gse - Units : nT - Size : 1 -
20 // Name : bx_gse - Units : nT - Size : 1 -
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://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
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
28 /// Path for the tests
28 /// Path for the tests
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 /// Delay after each operation on the variable before validating it (in ms)
32 /// Delay after each operation on the variable before validating it (in ms)
33 const auto OPERATION_DELAY = 10000;
33 const auto OPERATION_DELAY = 10000;
34
34
35 template <typename T>
35 template <typename T>
36 bool compareDataSeries(std::shared_ptr<IDataSeries> candidate, SqpRange candidateCacheRange,
36 bool compareDataSeries(std::shared_ptr<IDataSeries> candidate, SqpRange candidateCacheRange,
37 std::shared_ptr<IDataSeries> reference)
37 std::shared_ptr<IDataSeries> reference)
38 {
38 {
39 auto compareLambda = [](const auto &it1, const auto &it2) {
39 auto compareLambda = [](const auto &it1, const auto &it2) {
40 return (it1.x() == it2.x()) && (it1.value() == it2.value());
40 return (it1.x() == it2.x()) && (it1.value() == it2.value());
41 };
41 };
42
42
43 auto candidateDS = std::dynamic_pointer_cast<T>(candidate);
43 auto candidateDS = std::dynamic_pointer_cast<T>(candidate);
44 auto referenceDS = std::dynamic_pointer_cast<T>(reference);
44 auto referenceDS = std::dynamic_pointer_cast<T>(reference);
45
45
46 if (candidateDS && referenceDS) {
46 if (candidateDS && referenceDS) {
47
47
48 auto itRefs
48 auto itRefs
49 = referenceDS->xAxisRange(candidateCacheRange.m_TStart, candidateCacheRange.m_TEnd);
49 = referenceDS->xAxisRange(candidateCacheRange.m_TStart, candidateCacheRange.m_TEnd);
50 qDebug() << " DISTANCE" << std::distance(candidateDS->cbegin(), candidateDS->cend())
50 qDebug() << " DISTANCE" << std::distance(candidateDS->cbegin(), candidateDS->cend())
51 << std::distance(itRefs.first, itRefs.second);
51 << std::distance(itRefs.first, itRefs.second);
52
52
53 return std::equal(candidateDS->cbegin(), candidateDS->cend(), itRefs.first, itRefs.second,
53 return std::equal(candidateDS->cbegin(), candidateDS->cend(), itRefs.first, itRefs.second,
54 compareLambda);
54 compareLambda);
55 }
55 }
56 else {
56 else {
57 return false;
57 return false;
58 }
58 }
59 }
59 }
60 }
60 }
61
61
62 class TestAmdaAcquisition : public QObject {
62 class TestAmdaAcquisition : public QObject {
63 Q_OBJECT
63 Q_OBJECT
64
64
65 private slots:
65 private slots:
66 /// Input data for @sa testAcquisition()
66 /// Input data for @sa testAcquisition()
67 void testAcquisition_data();
67 void testAcquisition_data();
68 void testAcquisition();
68 void testAcquisition();
69 };
69 };
70
70
71 void TestAmdaAcquisition::testAcquisition_data()
71 void TestAmdaAcquisition::testAcquisition_data()
72 {
72 {
73 // ////////////// //
73 // ////////////// //
74 // Test structure //
74 // Test structure //
75 // ////////////// //
75 // ////////////// //
76
76
77 QTest::addColumn<QString>("dataFilename"); // File containing expected data of acquisitions
77 QTest::addColumn<QString>("dataFilename"); // File containing expected data of acquisitions
78 QTest::addColumn<SqpRange>("initialRange"); // First acquisition
78 QTest::addColumn<SqpRange>("initialRange"); // First acquisition
79 QTest::addColumn<std::vector<SqpRange> >("operations"); // Acquisitions to make
79 QTest::addColumn<std::vector<SqpRange> >("operations"); // Acquisitions to make
80
80
81 // ////////// //
81 // ////////// //
82 // Test cases //
82 // Test cases //
83 // ////////// //
83 // ////////// //
84
84
85 auto dateTime = [](int year, int month, int day, int hours, int minutes, int seconds) {
85 auto dateTime = [](int year, int month, int day, int hours, int minutes, int seconds) {
86 return DateUtils::secondsSinceEpoch(
86 return DateUtils::secondsSinceEpoch(
87 QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC});
87 QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC});
88 };
88 };
89
89
90
90
91 QTest::newRow("amda")
91 QTest::newRow("amda")
92 << "AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00.txt"
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)}
93 << SqpRange{dateTime(2012, 1, 2, 2, 3, 0), dateTime(2012, 1, 2, 2, 4, 0)}
94 << std::vector<SqpRange>{
94 << std::vector<SqpRange>{
95 // 2 : pan (jump) left for one hour
95 // 2 : pan (jump) left for two min
96 // SqpRange{dateTime(2012, 1, 2, 2, 1, 0), dateTime(2012, 1, 2, 2, 2, 0)},
96 SqpRange{dateTime(2012, 1, 2, 2, 1, 0), dateTime(2012, 1, 2, 2, 2, 0)},
97 // 3 : pan (jump) right for one hour
97 // 3 : pan (jump) right for four min
98 // SqpRange{dateTime(2012, 1, 2, 2, 5, 0), dateTime(2012, 1, 2, 2, 6, 0)},
98 SqpRange{dateTime(2012, 1, 2, 2, 5, 0), dateTime(2012, 1, 2, 2, 6, 0)},
99 // 4 : pan (overlay) right for 30 min
99 // 4 : pan (overlay) right for 30 sec
100 // SqpRange{dateTime(2012, 1, 2, 2, 5, 30), dateTime(2012, 1, 2, 2, 6, 30)},
100 SqpRange{dateTime(2012, 1, 2, 2, 5, 30), dateTime(2012, 1, 2, 2, 6, 30)},
101 // 5 : pan (overlay) left for 30 min
101 // 5 : pan (overlay) left for 30 sec
102 // SqpRange{dateTime(2012, 1, 2, 2, 5, 0), dateTime(2012, 1, 2, 2, 6, 0)},
102 SqpRange{dateTime(2012, 1, 2, 2, 5, 0), dateTime(2012, 1, 2, 2, 6, 0)},
103 // 6 : pan (overlay) left for 30 min - BIS
103 // 6 : pan (overlay) left for 30 sec - BIS
104 // SqpRange{dateTime(2012, 1, 2, 4, 30, 0), dateTime(2012, 1, 2, 2, 5, 30)},
104 SqpRange{dateTime(2012, 1, 2, 2, 4, 30), dateTime(2012, 1, 2, 2, 5, 30)},
105 // 7 : Zoom in Inside 20 min range
105 // 7 : Zoom in Inside 20 sec range
106 // SqpRange{dateTime(2012, 1, 2, 2, 4, 50), dateTime(2012, 1, 2, 2, 5, 10)},
106 SqpRange{dateTime(2012, 1, 2, 2, 4, 50), dateTime(2012, 1, 2, 2, 5, 10)},
107 // 8 : Zoom out Inside 2 hours range
107 // 8 : Zoom out Inside 20 sec range
108 // SqpRange{dateTime(2012, 1, 2, 2, 4, 0), dateTime(2012, 1, 2, 2, 6, 0)}
108 SqpRange{dateTime(2012, 1, 2, 2, 4, 30), dateTime(2012, 1, 2, 2, 5, 30)}};
109 };
110 }
109 }
111
110
112 void TestAmdaAcquisition::testAcquisition()
111 void TestAmdaAcquisition::testAcquisition()
113 {
112 {
114 /// @todo: update test to be compatible with AMDA v2
113 /// @todo: update test to be compatible with AMDA v2
115
114
116 // Retrieves data file
115 // Retrieves data file
117 QFETCH(QString, dataFilename);
116 QFETCH(QString, dataFilename);
118 auto filePath = QFileInfo{TESTS_RESOURCES_PATH, dataFilename}.absoluteFilePath();
117 auto filePath = QFileInfo{TESTS_RESOURCES_PATH, dataFilename}.absoluteFilePath();
119 auto results = AmdaResultParser::readTxt(filePath, AmdaResultParser::ValueType::SCALAR);
118 auto results = AmdaResultParser::readTxt(filePath, AmdaResultParser::ValueType::SCALAR);
120
119
121 /// Lambda used to validate a variable at each step
120 /// Lambda used to validate a variable at each step
122 auto validateVariable = [results](std::shared_ptr<Variable> variable, const SqpRange &range) {
121 auto validateVariable = [results](std::shared_ptr<Variable> variable, const SqpRange &range) {
123 // Checks that the variable's range has changed
122 // Checks that the variable's range has changed
123 qInfo() << tr("Compare var range vs range") << variable->range() << range;
124 QCOMPARE(variable->range(), range);
124 QCOMPARE(variable->range(), range);
125
125
126 // Checks the variable's data series
126 // Checks the variable's data series
127 QVERIFY(compareDataSeries<ScalarSeries>(variable->dataSeries(), variable->cacheRange(),
127 QVERIFY(compareDataSeries<ScalarSeries>(variable->dataSeries(), variable->cacheRange(),
128 results));
128 results));
129 qInfo() << "\n";
129 };
130 };
130
131
131 // Creates variable
132 // Creates variable
132 QFETCH(SqpRange, initialRange);
133 QFETCH(SqpRange, initialRange);
133 sqpApp->timeController().onTimeToUpdate(initialRange);
134 sqpApp->timeController().onTimeToUpdate(initialRange);
134 auto provider = std::make_shared<AmdaProvider>();
135 auto provider = std::make_shared<AmdaProvider>();
135 auto variable = sqpApp->variableController().createVariable(
136 auto variable = sqpApp->variableController().createVariable(
136 "bx_gse", {{"dataType", "scalar"}, {"xml:id", "imf(0)"}}, provider);
137 "bx_gse", {{"dataType", "scalar"}, {"xml:id", "imf(0)"}}, provider);
137
138
138 QTest::qWait(OPERATION_DELAY);
139 QTest::qWait(OPERATION_DELAY);
139 validateVariable(variable, initialRange);
140 validateVariable(variable, initialRange);
140
141
141 // Makes operations on the variable
142 // Makes operations on the variable
142 QFETCH(std::vector<SqpRange>, operations);
143 QFETCH(std::vector<SqpRange>, operations);
143 for (const auto &operation : operations) {
144 for (const auto &operation : operations) {
144 // Asks request on the variable and waits during its execution
145 // Asks request on the variable and waits during its execution
145 sqpApp->variableController().onRequestDataLoading({variable}, operation, variable->range(),
146 sqpApp->variableController().onRequestDataLoading({variable}, operation, variable->range(),
146 true);
147 true);
147
148
148 QTest::qWait(OPERATION_DELAY);
149 QTest::qWait(OPERATION_DELAY);
149 validateVariable(variable, operation);
150 validateVariable(variable, operation);
150 }
151 }
151 }
152 }
152
153
153 int main(int argc, char *argv[])
154 int main(int argc, char *argv[])
154 {
155 {
155 SqpApplication app(argc, argv);
156 SqpApplication app(argc, argv);
156 app.setAttribute(Qt::AA_Use96Dpi, true);
157 app.setAttribute(Qt::AA_Use96Dpi, true);
157 TestAmdaAcquisition tc;
158 TestAmdaAcquisition tc;
158 QTEST_SET_MAIN_SOURCE_PATH
159 QTEST_SET_MAIN_SOURCE_PATH
159 return QTest::qExec(&tc, argc, argv);
160 return QTest::qExec(&tc, argc, argv);
160 }
161 }
161
162
162 // QTEST_MAIN(TestAmdaAcquisition)
163 // QTEST_MAIN(TestAmdaAcquisition)
163
164
164 #include "TestAmdaAcquisition.moc"
165 #include "TestAmdaAcquisition.moc"
General Comments 0
You need to be logged in to leave comments. Login now