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