@@ -1,50 +1,100 | |||||
1 | #include "CosinusProvider.h" |
|
1 | #include "CosinusProvider.h" | |
2 |
|
2 | |||
|
3 | #include <Data/ScalarSeries.h> | |||
3 | #include <SqpApplication.h> |
|
4 | #include <SqpApplication.h> | |
4 |
|
5 | |||
5 | #include <QObject> |
|
6 | #include <QObject> | |
6 | #include <QtTest> |
|
7 | #include <QtTest> | |
7 |
|
8 | |||
|
9 | #include <cmath> | |||
|
10 | #include <memory> | |||
|
11 | ||||
8 | namespace { |
|
12 | namespace { | |
9 |
|
13 | |||
10 | /// Path for the tests |
|
14 | /// Path for the tests | |
11 | const auto TESTS_RESOURCES_PATH = QFileInfo{ |
|
15 | const auto TESTS_RESOURCES_PATH = QFileInfo{ | |
12 | QString{MOCKPLUGIN_TESTS_RESOURCES_DIR}, |
|
16 | QString{MOCKPLUGIN_TESTS_RESOURCES_DIR}, | |
13 | "TestCosinusAcquisition"}.absoluteFilePath(); |
|
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 | } // namespace |
|
45 | } // namespace | |
16 |
|
46 | |||
17 | /** |
|
47 | /** | |
18 | * @brief The TestCosinusAcquisition class tests acquisition in SciQlop (operations like zooms in, |
|
48 | * @brief The TestCosinusAcquisition class tests acquisition in SciQlop (operations like zooms in, | |
19 | * zooms out, pans) of data from CosinusProvider |
|
49 | * zooms out, pans) of data from CosinusProvider | |
20 | * @sa CosinusProvider |
|
50 | * @sa CosinusProvider | |
21 | */ |
|
51 | */ | |
22 | class TestCosinusAcquisition : public QObject { |
|
52 | class TestCosinusAcquisition : public QObject { | |
23 | Q_OBJECT |
|
53 | Q_OBJECT | |
24 |
|
54 | |||
25 | private slots: |
|
55 | private slots: | |
26 | /// Input data for @sa testAcquisition() |
|
56 | /// Input data for @sa testAcquisition() | |
27 | void testAcquisition_data(); |
|
57 | void testAcquisition_data(); | |
28 | void testAcquisition(); |
|
58 | void testAcquisition(); | |
29 | }; |
|
59 | }; | |
30 |
|
60 | |||
31 | void TestCosinusAcquisition::testAcquisition_data() |
|
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 | void TestCosinusAcquisition::testAcquisition() |
|
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 | int main(int argc, char *argv[]) |
|
91 | int main(int argc, char *argv[]) | |
42 | { |
|
92 | { | |
43 | SqpApplication app{argc, argv}; |
|
93 | SqpApplication app{argc, argv}; | |
44 | app.setAttribute(Qt::AA_Use96Dpi, true); |
|
94 | app.setAttribute(Qt::AA_Use96Dpi, true); | |
45 | TestCosinusAcquisition testObject{}; |
|
95 | TestCosinusAcquisition testObject{}; | |
46 | QTEST_SET_MAIN_SOURCE_PATH |
|
96 | QTEST_SET_MAIN_SOURCE_PATH | |
47 | return QTest::qExec(&testObject, argc, argv); |
|
97 | return QTest::qExec(&testObject, argc, argv); | |
48 | } |
|
98 | } | |
49 |
|
99 | |||
50 | #include "TestCosinusAcquisition.moc" |
|
100 | #include "TestCosinusAcquisition.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now