diff --git a/core/tests/Variable/TestVariableSync.cpp b/core/tests/Variable/TestVariableSync.cpp index 539574d..120e416 100644 --- a/core/tests/Variable/TestVariableSync.cpp +++ b/core/tests/Variable/TestVariableSync.cpp @@ -1,8 +1,12 @@ #include #include +#include + #include #include +#include + namespace { /** @@ -17,6 +21,69 @@ struct IOperation { }; /** + *Variable creation operation in the controller + */ +struct Create : public IOperation { + explicit Create(int index) : m_Index{index} {} + + void exec(VariableController &variableController) const override + { + auto variable = variableController.createVariable(QString::number(m_Index), {}, + std::make_unique()); + } + + int m_Index; ///< The index of the variable to create in the controller +}; + +/** + * Variable move/shift operation in the controller + */ +struct Move : public IOperation { + explicit Move(int index, const SqpRange &newRange, bool shift = false) + : m_Index{index}, m_NewRange{newRange}, m_Shift{shift} + { + } + + void exec(VariableController &variableController) const override + { + if (auto variable = variableController.variableModel()->variable(m_Index)) { + variableController.onRequestDataLoading({variable}, m_NewRange, variable->range(), + !m_Shift); + } + } + + int m_Index; ///< The index of the variable to move + SqpRange m_NewRange; ///< The new range of the variable + bool m_Shift; ///< Performs a shift ( +}; + +/** + * Variable synchronization/desynchronization operation in the controller + */ +struct Synchronize : public IOperation { + explicit Synchronize(int index, QUuid syncId, bool synchronize = true) + : m_Index{index}, m_SyncId{syncId}, m_Synchronize{synchronize} + { + } + + void exec(VariableController &variableController) const override + { + if (auto variable = variableController.variableModel()->variable(m_Index)) { + if (m_Synchronize) { + variableController.onAddSynchronized(variable, m_SyncId); + } + else { + variableController.desynchronize(variable, m_SyncId); + } + } + } + + int m_Index; ///< The index of the variable to sync/desync + QUuid m_SyncId; ///< The synchronization group of the variable + bool m_Synchronize; ///< Performs sync or desync operation +}; + +/** * Test Iteration * * A test iteration includes an operation to be performed, and a set of expected ranges after each