TestCosinusAcquisition.cpp
100 lines
| 2.8 KiB
| text/x-c
|
CppLexer
|
r686 | #include "CosinusProvider.h" | ||
|
r687 | #include <Data/ScalarSeries.h> | ||
|
r686 | #include <SqpApplication.h> | ||
#include <QObject> | ||||
#include <QtTest> | ||||
|
r687 | #include <cmath> | ||
#include <memory> | ||||
|
r686 | namespace { | ||
/// Path for the tests | ||||
const auto TESTS_RESOURCES_PATH = QFileInfo{ | ||||
QString{MOCKPLUGIN_TESTS_RESOURCES_DIR}, | ||||
"TestCosinusAcquisition"}.absoluteFilePath(); | ||||
|
r687 | /// 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{}); | ||||
} | ||||
|
r686 | } // 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() | ||||
{ | ||||
|
r687 | // ////////////// // | ||
// 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 | ||||
|
r686 | } | ||
void TestCosinusAcquisition::testAcquisition() | ||||
{ | ||||
|
r687 | // 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"); | ||||
} | ||||
|
r686 | } | ||
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" | ||||