@@ -1,10 +1,14 | |||
|
1 | 1 | #include "CosinusProvider.h" |
|
2 | 2 | |
|
3 | #include <Data/ScalarSeries.h> | |
|
3 | 4 | #include <SqpApplication.h> |
|
4 | 5 | |
|
5 | 6 | #include <QObject> |
|
6 | 7 | #include <QtTest> |
|
7 | 8 | |
|
9 | #include <cmath> | |
|
10 | #include <memory> | |
|
11 | ||
|
8 | 12 | namespace { |
|
9 | 13 | |
|
10 | 14 | /// Path for the tests |
@@ -12,6 +16,32 const auto TESTS_RESOURCES_PATH = QFileInfo{ | |||
|
12 | 16 | QString{MOCKPLUGIN_TESTS_RESOURCES_DIR}, |
|
13 | 17 | "TestCosinusAcquisition"}.absoluteFilePath(); |
|
14 | 18 | |
|
19 | /// Format of dates in data files | |
|
20 | const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss:zzz"); | |
|
21 | ||
|
22 | /// Generates the data series from the reading of a data stream | |
|
23 | std::shared_ptr<IDataSeries> readDataStream(QTextStream &stream) | |
|
24 | { | |
|
25 | std::vector<double> xAxisData, valuesData; | |
|
26 | ||
|
27 | QString line{}; | |
|
28 | while (stream.readLineInto(&line)) { | |
|
29 | // Separates date (x-axis data) to value data | |
|
30 | auto splitLine = line.split('\t'); | |
|
31 | if (splitLine.size() == 2) { | |
|
32 | // Converts datetime to double | |
|
33 | auto dateTime = QDateTime::fromString(splitLine[0], DATETIME_FORMAT); | |
|
34 | dateTime.setTimeSpec(Qt::UTC); | |
|
35 | xAxisData.push_back(DateUtils::secondsSinceEpoch(dateTime)); | |
|
36 | ||
|
37 | valuesData.push_back(splitLine[1].toDouble()); | |
|
38 | } | |
|
39 | } | |
|
40 | ||
|
41 | return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), | |
|
42 | Unit{{}, true}, Unit{}); | |
|
43 | } | |
|
44 | ||
|
15 | 45 | } // namespace |
|
16 | 46 | |
|
17 | 47 | /** |
@@ -30,12 +60,32 private slots: | |||
|
30 | 60 | |
|
31 | 61 | void TestCosinusAcquisition::testAcquisition_data() |
|
32 | 62 | { |
|
33 | /// @todo | |
|
63 | // ////////////// // | |
|
64 | // Test structure // | |
|
65 | // ////////////// // | |
|
66 | ||
|
67 | QTest::addColumn<QString>("dataFilename"); // File containing expected data of acquisitions | |
|
68 | QTest::addColumn<SqpRange>("initialRange"); // First acquisition | |
|
69 | QTest::addColumn<std::vector<SqpRange> >("operations"); // Acquisitions to make | |
|
34 | 70 | } |
|
35 | 71 | |
|
36 | 72 | void TestCosinusAcquisition::testAcquisition() |
|
37 | 73 | { |
|
38 | /// @todo | |
|
74 | // Retrieves data file | |
|
75 | QFETCH(QString, dataFilename); | |
|
76 | ||
|
77 | auto dataFilePath = QFileInfo{TESTS_RESOURCES_PATH, dataFilename}.absoluteFilePath(); | |
|
78 | QFile dataFile{dataFilePath}; | |
|
79 | ||
|
80 | if (dataFile.open(QFile::ReadOnly)) { | |
|
81 | // Generates data series to compare with | |
|
82 | QTextStream dataStream{&dataFile}; | |
|
83 | auto dataSeries = readDataStream(dataStream); | |
|
84 | ||
|
85 | } | |
|
86 | else { | |
|
87 | QFAIL("Can't read input data file"); | |
|
88 | } | |
|
39 | 89 | } |
|
40 | 90 | |
|
41 | 91 | int main(int argc, char *argv[]) |
General Comments 0
You need to be logged in to leave comments.
Login now