From 06afcb0c44763f8df12c226a1ad00b373ee36558 2017-09-20 08:19:49 From: Alexandre Leroux Date: 2017-09-20 08:19:49 Subject: [PATCH] Implements unit test (1) Creates test structure and reads result file --- diff --git a/plugins/mockplugin/tests/TestCosinusAcquisition.cpp b/plugins/mockplugin/tests/TestCosinusAcquisition.cpp index 62cbc31..3149800 100644 --- a/plugins/mockplugin/tests/TestCosinusAcquisition.cpp +++ b/plugins/mockplugin/tests/TestCosinusAcquisition.cpp @@ -1,10 +1,14 @@ #include "CosinusProvider.h" +#include #include #include #include +#include +#include + namespace { /// Path for the tests @@ -12,6 +16,32 @@ const auto TESTS_RESOURCES_PATH = QFileInfo{ QString{MOCKPLUGIN_TESTS_RESOURCES_DIR}, "TestCosinusAcquisition"}.absoluteFilePath(); +/// Format of dates in data files +const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss:zzz"); + +/// Generates the data series from the reading of a data stream +std::shared_ptr readDataStream(QTextStream &stream) +{ + std::vector xAxisData, valuesData; + + QString line{}; + while (stream.readLineInto(&line)) { + // Separates date (x-axis data) to value data + auto splitLine = line.split('\t'); + if (splitLine.size() == 2) { + // Converts datetime to double + auto dateTime = QDateTime::fromString(splitLine[0], DATETIME_FORMAT); + dateTime.setTimeSpec(Qt::UTC); + xAxisData.push_back(DateUtils::secondsSinceEpoch(dateTime)); + + valuesData.push_back(splitLine[1].toDouble()); + } + } + + return std::make_shared(std::move(xAxisData), std::move(valuesData), + Unit{{}, true}, Unit{}); +} + } // namespace /** @@ -30,12 +60,32 @@ private slots: void TestCosinusAcquisition::testAcquisition_data() { - /// @todo + // ////////////// // + // Test structure // + // ////////////// // + + QTest::addColumn("dataFilename"); // File containing expected data of acquisitions + QTest::addColumn("initialRange"); // First acquisition + QTest::addColumn >("operations"); // Acquisitions to make } void TestCosinusAcquisition::testAcquisition() { - /// @todo + // Retrieves data file + QFETCH(QString, dataFilename); + + auto dataFilePath = QFileInfo{TESTS_RESOURCES_PATH, dataFilename}.absoluteFilePath(); + QFile dataFile{dataFilePath}; + + if (dataFile.open(QFile::ReadOnly)) { + // Generates data series to compare with + QTextStream dataStream{&dataFile}; + auto dataSeries = readDataStream(dataStream); + + } + else { + QFAIL("Can't read input data file"); + } } int main(int argc, char *argv[])