##// END OF EJS Templates
Implements unit test (2)...
Alexandre Leroux -
r744:a0932f2ad0d7
parent child
Show More
@@ -1,100 +1,123
1 #include "CosinusProvider.h"
1 #include "CosinusProvider.h"
2
2
3 #include <Data/DataProviderParameters.h>
3 #include <Data/ScalarSeries.h>
4 #include <Data/ScalarSeries.h>
4 #include <SqpApplication.h>
5 #include <SqpApplication.h>
6 #include <Time/TimeController.h>
7 #include <Variable/Variable.h>
8 #include <Variable/VariableController.h>
5
9
6 #include <QObject>
10 #include <QObject>
7 #include <QtTest>
11 #include <QtTest>
8
12
9 #include <cmath>
13 #include <cmath>
10 #include <memory>
14 #include <memory>
11
15
12 namespace {
16 namespace {
13
17
14 /// Path for the tests
18 /// Path for the tests
15 const auto TESTS_RESOURCES_PATH = QFileInfo{
19 const auto TESTS_RESOURCES_PATH = QFileInfo{
16 QString{MOCKPLUGIN_TESTS_RESOURCES_DIR},
20 QString{MOCKPLUGIN_TESTS_RESOURCES_DIR},
17 "TestCosinusAcquisition"}.absoluteFilePath();
21 "TestCosinusAcquisition"}.absoluteFilePath();
18
22
19 /// Format of dates in data files
23 /// Format of dates in data files
20 const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss:zzz");
24 const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss:zzz");
21
25
26 /// Delay after each operation on the variable before validating it (in ms)
27 const auto OPERATION_DELAY = 250;
28
22 /// Generates the data series from the reading of a data stream
29 /// Generates the data series from the reading of a data stream
23 std::shared_ptr<IDataSeries> readDataStream(QTextStream &stream)
30 std::shared_ptr<IDataSeries> readDataStream(QTextStream &stream)
24 {
31 {
25 std::vector<double> xAxisData, valuesData;
32 std::vector<double> xAxisData, valuesData;
26
33
27 QString line{};
34 QString line{};
28 while (stream.readLineInto(&line)) {
35 while (stream.readLineInto(&line)) {
29 // Separates date (x-axis data) to value data
36 // Separates date (x-axis data) to value data
30 auto splitLine = line.split('\t');
37 auto splitLine = line.split('\t');
31 if (splitLine.size() == 2) {
38 if (splitLine.size() == 2) {
32 // Converts datetime to double
39 // Converts datetime to double
33 auto dateTime = QDateTime::fromString(splitLine[0], DATETIME_FORMAT);
40 auto dateTime = QDateTime::fromString(splitLine[0], DATETIME_FORMAT);
34 dateTime.setTimeSpec(Qt::UTC);
41 dateTime.setTimeSpec(Qt::UTC);
35 xAxisData.push_back(DateUtils::secondsSinceEpoch(dateTime));
42 xAxisData.push_back(DateUtils::secondsSinceEpoch(dateTime));
36
43
37 valuesData.push_back(splitLine[1].toDouble());
44 valuesData.push_back(splitLine[1].toDouble());
38 }
45 }
39 }
46 }
40
47
41 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
48 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
42 Unit{{}, true}, Unit{});
49 Unit{{}, true}, Unit{});
43 }
50 }
44
51
45 } // namespace
52 } // namespace
46
53
47 /**
54 /**
48 * @brief The TestCosinusAcquisition class tests acquisition in SciQlop (operations like zooms in,
55 * @brief The TestCosinusAcquisition class tests acquisition in SciQlop (operations like zooms in,
49 * zooms out, pans) of data from CosinusProvider
56 * zooms out, pans) of data from CosinusProvider
50 * @sa CosinusProvider
57 * @sa CosinusProvider
51 */
58 */
52 class TestCosinusAcquisition : public QObject {
59 class TestCosinusAcquisition : public QObject {
53 Q_OBJECT
60 Q_OBJECT
54
61
55 private slots:
62 private slots:
56 /// Input data for @sa testAcquisition()
63 /// Input data for @sa testAcquisition()
57 void testAcquisition_data();
64 void testAcquisition_data();
58 void testAcquisition();
65 void testAcquisition();
59 };
66 };
60
67
61 void TestCosinusAcquisition::testAcquisition_data()
68 void TestCosinusAcquisition::testAcquisition_data()
62 {
69 {
63 // ////////////// //
70 // ////////////// //
64 // Test structure //
71 // Test structure //
65 // ////////////// //
72 // ////////////// //
66
73
67 QTest::addColumn<QString>("dataFilename"); // File containing expected data of acquisitions
74 QTest::addColumn<QString>("dataFilename"); // File containing expected data of acquisitions
68 QTest::addColumn<SqpRange>("initialRange"); // First acquisition
75 QTest::addColumn<SqpRange>("initialRange"); // First acquisition
69 QTest::addColumn<std::vector<SqpRange> >("operations"); // Acquisitions to make
76 QTest::addColumn<std::vector<SqpRange> >("operations"); // Acquisitions to make
70 }
77 }
71
78
72 void TestCosinusAcquisition::testAcquisition()
79 void TestCosinusAcquisition::testAcquisition()
73 {
80 {
74 // Retrieves data file
81 // Retrieves data file
75 QFETCH(QString, dataFilename);
82 QFETCH(QString, dataFilename);
76
83
77 auto dataFilePath = QFileInfo{TESTS_RESOURCES_PATH, dataFilename}.absoluteFilePath();
84 auto dataFilePath = QFileInfo{TESTS_RESOURCES_PATH, dataFilename}.absoluteFilePath();
78 QFile dataFile{dataFilePath};
85 QFile dataFile{dataFilePath};
79
86
80 if (dataFile.open(QFile::ReadOnly)) {
87 if (dataFile.open(QFile::ReadOnly)) {
81 // Generates data series to compare with
88 // Generates data series to compare with
82 QTextStream dataStream{&dataFile};
89 QTextStream dataStream{&dataFile};
83 auto dataSeries = readDataStream(dataStream);
90 auto dataSeries = readDataStream(dataStream);
84
91
92 // Creates variable
93 QFETCH(SqpRange, initialRange);
94 sqpApp->timeController().onTimeToUpdate(initialRange);
95 auto provider = std::make_shared<CosinusProvider>();
96 auto variable = sqpApp->variableController().createVariable("MMS", {}, provider);
97
98 QTest::qWait(OPERATION_DELAY);
99 // Makes operations on the variable
100 QFETCH(std::vector<SqpRange>, operations);
101 for (const auto &operation : operations) {
102 // Asks request on the variable and waits during its execution
103 sqpApp->variableController().onRequestDataLoading({variable}, operation,
104 variable->range(), true);
105
106 QTest::qWait(OPERATION_DELAY);
107 }
85 }
108 }
86 else {
109 else {
87 QFAIL("Can't read input data file");
110 QFAIL("Can't read input data file");
88 }
111 }
89 }
112 }
90
113
91 int main(int argc, char *argv[])
114 int main(int argc, char *argv[])
92 {
115 {
93 SqpApplication app{argc, argv};
116 SqpApplication app{argc, argv};
94 app.setAttribute(Qt::AA_Use96Dpi, true);
117 app.setAttribute(Qt::AA_Use96Dpi, true);
95 TestCosinusAcquisition testObject{};
118 TestCosinusAcquisition testObject{};
96 QTEST_SET_MAIN_SOURCE_PATH
119 QTEST_SET_MAIN_SOURCE_PATH
97 return QTest::qExec(&testObject, argc, argv);
120 return QTest::qExec(&testObject, argc, argv);
98 }
121 }
99
122
100 #include "TestCosinusAcquisition.moc"
123 #include "TestCosinusAcquisition.moc"
General Comments 0
You need to be logged in to leave comments. Login now