##// END OF EJS Templates
Implements unit test (1)...
Alexandre Leroux -
r743:06afcb0c4476
parent child
Show More
@@ -1,50 +1,100
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
11 15 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 /**
18 48 * @brief The TestCosinusAcquisition class tests acquisition in SciQlop (operations like zooms in,
19 49 * zooms out, pans) of data from CosinusProvider
20 50 * @sa CosinusProvider
21 51 */
22 52 class TestCosinusAcquisition : public QObject {
23 53 Q_OBJECT
24 54
25 55 private slots:
26 56 /// Input data for @sa testAcquisition()
27 57 void testAcquisition_data();
28 58 void testAcquisition();
29 59 };
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[])
42 92 {
43 93 SqpApplication app{argc, argv};
44 94 app.setAttribute(Qt::AA_Use96Dpi, true);
45 95 TestCosinusAcquisition testObject{};
46 96 QTEST_SET_MAIN_SOURCE_PATH
47 97 return QTest::qExec(&testObject, argc, argv);
48 98 }
49 99
50 100 #include "TestCosinusAcquisition.moc"
General Comments 0
You need to be logged in to leave comments. Login now