##// END OF EJS Templates
Implements unit test (2)...
Implements unit test (2) Handles variable init and operations (zooms/pans)

File last commit:

r744:a0932f2ad0d7
r744:a0932f2ad0d7
Show More
TestCosinusAcquisition.cpp
123 lines | 3.8 KiB | text/x-c | CppLexer
/ plugins / mockplugin / tests / TestCosinusAcquisition.cpp
#include "CosinusProvider.h"
#include <Data/DataProviderParameters.h>
#include <Data/ScalarSeries.h>
#include <SqpApplication.h>
#include <Time/TimeController.h>
#include <Variable/Variable.h>
#include <Variable/VariableController.h>
#include <QObject>
#include <QtTest>
#include <cmath>
#include <memory>
namespace {
/// Path for the tests
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");
/// Delay after each operation on the variable before validating it (in ms)
const auto OPERATION_DELAY = 250;
/// 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{});
}
} // 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()
{
// ////////////// //
// 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
}
void TestCosinusAcquisition::testAcquisition()
{
// 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);
// 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);
}
}
else {
QFAIL("Can't read input data file");
}
}
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"