TestCosinusAcquisition.cpp
123 lines
| 3.8 KiB
| text/x-c
|
CppLexer
|
r742 | #include "CosinusProvider.h" | ||
|
r744 | #include <Data/DataProviderParameters.h> | ||
|
r743 | #include <Data/ScalarSeries.h> | ||
|
r742 | #include <SqpApplication.h> | ||
|
r744 | #include <Time/TimeController.h> | ||
#include <Variable/Variable.h> | ||||
#include <Variable/VariableController.h> | ||||
|
r742 | |||
#include <QObject> | ||||
#include <QtTest> | ||||
|
r743 | #include <cmath> | ||
#include <memory> | ||||
|
r742 | namespace { | ||
/// Path for the tests | ||||
const auto TESTS_RESOURCES_PATH = QFileInfo{ | ||||
QString{MOCKPLUGIN_TESTS_RESOURCES_DIR}, | ||||
"TestCosinusAcquisition"}.absoluteFilePath(); | ||||
|
r743 | /// Format of dates in data files | ||
const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss:zzz"); | ||||
|
r744 | /// Delay after each operation on the variable before validating it (in ms) | ||
const auto OPERATION_DELAY = 250; | ||||
|
r743 | /// 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{}); | ||||
} | ||||
|
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() | ||||
{ | ||||
|
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 | ||||
|
r742 | } | ||
void TestCosinusAcquisition::testAcquisition() | ||||
{ | ||||
|
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); | ||||
|
r744 | // Creates variable | ||
QFETCH(SqpRange, initialRange); | ||||
sqpApp->timeController().onTimeToUpdate(initialRange); | ||||
auto provider = std::make_shared<CosinusProvider>(); | ||||
auto variable = sqpApp->variableController().createVariable("MMS", {}, provider); | ||||
QTest::qWait(OPERATION_DELAY); | ||||
// Makes operations on the variable | ||||
QFETCH(std::vector<SqpRange>, operations); | ||||
for (const auto &operation : operations) { | ||||
// Asks request on the variable and waits during its execution | ||||
sqpApp->variableController().onRequestDataLoading({variable}, operation, | ||||
variable->range(), true); | ||||
QTest::qWait(OPERATION_DELAY); | ||||
} | ||||
|
r743 | } | ||
else { | ||||
QFAIL("Can't read input data file"); | ||||
} | ||||
|
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" | ||||