##// END OF EJS Templates
Some WIP refactoring, trying to remove TimeController object...
Some WIP refactoring, trying to remove TimeController object SciQLOP core should be usable OOTB without creating controllers objects. Time range should be given on variable creation not taken from a global object. Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r1345:ce477e992869
r1345:ce477e992869
Show More
TestVariableController.cpp
74 lines | 2.2 KiB | text/x-c | CppLexer
/ core / tests / Variable / TestVariableController.cpp
Alexandre Leroux
Add unit test of variable deletion in VariableController
r665 #include <QObject>
#include <QtTest>
#include <Data/IDataProvider.h>
#include <Time/TimeController.h>
#include <Variable/Variable.h>
#include <Variable/VariableController.h>
#include <memory>
namespace {
/// Provider used for the tests
class TestProvider : public IDataProvider {
Alexandre Leroux
Generates and registers clone provider
r712 std::shared_ptr<IDataProvider> clone() const { return std::make_shared<TestProvider>(); }
Alexandre Leroux
Add unit test of variable deletion in VariableController
r665 void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters) override
{
// Does nothing
}
void requestDataAborting(QUuid acqIdentifier) override
{
// Does nothing
}
};
/// Generates a time controller for the tests
std::unique_ptr<TimeController> defaultTimeController()
{
auto timeController = std::make_unique<TimeController>();
QDateTime start{QDate{2017, 01, 01}, QTime{0, 0, 0, 0}};
QDateTime end{QDate{2017, 01, 02}, QTime{0, 0, 0, 0}};
Some WIP refactoring, trying to remove TimeController object...
r1345 timeController->setDateTimeRange(
Alexandre Leroux
Add unit test of variable deletion in VariableController
r665 SqpRange{DateUtils::secondsSinceEpoch(start), DateUtils::secondsSinceEpoch(end)});
return timeController;
}
} // namespace
class TestVariableController : public QObject {
Q_OBJECT
private slots:
/// Test removes variable from controller
void testDeleteVariable();
};
void TestVariableController::testDeleteVariable()
{
// Creates variable controller
auto timeController = defaultTimeController();
VariableController variableController{};
Some WIP refactoring, trying to remove TimeController object...
r1345 //variableController.setTimeController(timeController.get());
Alexandre Leroux
Add unit test of variable deletion in VariableController
r665
// Creates a variable from the controller
auto variable
Some WIP refactoring, trying to remove TimeController object...
r1345 = variableController.createVariable("variable", {}, std::make_shared<TestProvider>(), timeController->dateTime());
Alexandre Leroux
Add unit test of variable deletion in VariableController
r665
qDebug() << QString::number(variable.use_count());
// Removes the variable from the controller
variableController.deleteVariable(variable);
// Verifies that the variable has been deleted: this implies that the number of shared_ptr
// objects referring to the variable is 1 (the reference of this scope). Otherwise, the deletion
// is considered invalid since the variable is still referenced in the controller
QVERIFY(variable.use_count() == 1);
}
QTEST_MAIN(TestVariableController)
#include "TestVariableController.moc"