TestCosinusAcquisition.cpp
100 lines
| 2.8 KiB
| text/x-c
|
CppLexer
Alexandre Leroux
|
r742 | #include "CosinusProvider.h" | ||
Alexandre Leroux
|
r743 | #include <Data/ScalarSeries.h> | ||
Alexandre Leroux
|
r742 | #include <SqpApplication.h> | ||
#include <QObject> | ||||
#include <QtTest> | ||||
Alexandre Leroux
|
r743 | #include <cmath> | ||
#include <memory> | ||||
Alexandre Leroux
|
r742 | namespace { | ||
/// Path for the tests | ||||
const auto TESTS_RESOURCES_PATH = QFileInfo{ | ||||
QString{MOCKPLUGIN_TESTS_RESOURCES_DIR}, | ||||
"TestCosinusAcquisition"}.absoluteFilePath(); | ||||
Alexandre Leroux
|
r743 | /// 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<IDataSeries> readDataStream(QTextStream &stream) | ||||
{ | ||||
std::vector<double> 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<ScalarSeries>(std::move(xAxisData), std::move(valuesData), | ||||
Unit{{}, true}, Unit{}); | ||||
} | ||||
Alexandre Leroux
|
r742 | } // namespace | ||
/** | ||||
* @brief The TestCosinusAcquisition class tests acquisition in SciQlop (operations like zooms in, | ||||
* zooms out, pans) of data from CosinusProvider | ||||
* @sa CosinusProvider | ||||
*/ | ||||
class TestCosinusAcquisition : public QObject { | ||||
Q_OBJECT | ||||
private slots: | ||||
/// Input data for @sa testAcquisition() | ||||
void testAcquisition_data(); | ||||
void testAcquisition(); | ||||
}; | ||||
void TestCosinusAcquisition::testAcquisition_data() | ||||
{ | ||||
Alexandre Leroux
|
r743 | // ////////////// // | ||
// Test structure // | ||||
// ////////////// // | ||||
QTest::addColumn<QString>("dataFilename"); // File containing expected data of acquisitions | ||||
QTest::addColumn<SqpRange>("initialRange"); // First acquisition | ||||
QTest::addColumn<std::vector<SqpRange> >("operations"); // Acquisitions to make | ||||
Alexandre Leroux
|
r742 | } | ||
void TestCosinusAcquisition::testAcquisition() | ||||
{ | ||||
Alexandre Leroux
|
r743 | // 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"); | ||||
} | ||||
Alexandre Leroux
|
r742 | } | ||
int main(int argc, char *argv[]) | ||||
{ | ||||
SqpApplication app{argc, argv}; | ||||
app.setAttribute(Qt::AA_Use96Dpi, true); | ||||
TestCosinusAcquisition testObject{}; | ||||
QTEST_SET_MAIN_SOURCE_PATH | ||||
return QTest::qExec(&testObject, argc, argv); | ||||
} | ||||
#include "TestCosinusAcquisition.moc" | ||||