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