From d51953af4db36642af180669dec7a5196b9d3f89 2018-08-07 14:49:18 From: Alexis Jeandet Date: 2018-08-07 14:49:18 Subject: [PATCH] Added SynchronizationGroup2 tests and documentation Signed-off-by: Alexis Jeandet --- diff --git a/include/Variable/VariableSynchronizationGroup2.h b/include/Variable/VariableSynchronizationGroup2.h index 131e869..41dcbde 100644 --- a/include/Variable/VariableSynchronizationGroup2.h +++ b/include/Variable/VariableSynchronizationGroup2.h @@ -8,25 +8,61 @@ #include #include +/** + * @brief The VariableSynchronizationGroup2 class holds a list of Variables uuid which are synchronized + * @note This class is part of SciQLop internals, as a normal user you shouldn't have to care about it + */ class SCIQLOP_CORE_EXPORT VariableSynchronizationGroup2 { public: explicit VariableSynchronizationGroup2()=default; - // Convenience ctor to build a group with a default variable + /** + * @brief VariableSynchronizationGroup2 is a convenience ctor to build a group with a default variable + * @param variable + */ explicit VariableSynchronizationGroup2(QUuid variable) :_variables{{variable}} {} - void addVariable(QUuid variable); - void removeVariable(QUuid variable); + /** + * @brief addVariable adds the given variable to the group, does nothing if the varaible is alredy in the group + * @param variable + * @sa removeVariable + */ + void addVariable(QUuid variable) noexcept + { + this->_variables.insert(variable); + } - bool contains(QUuid variable) + /** + * @brief removeVariable removes the given variable from the group, does nothing if the varaible is not in the group + * @param variable + * @sa addVariable + */ + void removeVariable(QUuid variable) noexcept + { + this->_variables.extract(variable); + } + + /** + * @brief contains checks if the given variable is in the group + * @param variable + * @return true if the variable is in the group + */ + bool contains(QUuid variable) const noexcept { return SciQLop::containers::contains(this->_variables,variable); } - const std::set &variables() const noexcept; + /** + * @brief variables + * @return the list of synchronized variables in this group as a std::set + */ + const std::set &variables() const noexcept + { + return this->_variables; + } private: std::set _variables; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 81498a4..6ea4ff1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,6 +4,7 @@ add_definitions(-DCORE_TESTS_RESOURCES_DIR="${CMAKE_CURRENT_LIST_DIR}/../tests-r declare_test(TestStringUtils TestStringUtils Common/TestStringUtils.cpp "sciqlopcore;Qt5::Test") declare_test(TestContainers TestContainers Common/TestContainers.cpp "sciqlopcore;Qt5::Test") +declare_test(TestSyncGroup TestSyncGroup Variable/TestSyncGroup.cpp "sciqlopcore;Qt5::Test") declare_test(TestDataSeriesUtils TestDataSeriesUtils Data/TestDataSeriesUtils.cpp "sciqlopcore;Qt5::Test") diff --git a/tests/Variable/TestSyncGroup.cpp b/tests/Variable/TestSyncGroup.cpp new file mode 100644 index 0000000..97e9d9b --- /dev/null +++ b/tests/Variable/TestSyncGroup.cpp @@ -0,0 +1,51 @@ +#include +#include +#include + +#include + +class TestSyncGroup: public QObject { + Q_OBJECT + +private slots: + void testAddVariables() + { + auto v = QUuid::createUuid(); + VariableSynchronizationGroup2 group{v}; + QVERIFY(group.contains(v)); + auto vars = {QUuid::createUuid(), QUuid::createUuid(), QUuid::createUuid(), QUuid::createUuid()}; + for(auto var:vars) + { + group.addVariable(var); + } + for(auto var:vars) + { + QVERIFY(group.contains(var)); + } + } + + void testRemoveVariables() + { + auto v = QUuid::createUuid(); + VariableSynchronizationGroup2 group{v}; + QVERIFY(group.contains(v)); + group.removeVariable(v); + QVERIFY(!group.contains(v)); + auto vars = {QUuid::createUuid(), QUuid::createUuid(), QUuid::createUuid(), QUuid::createUuid()}; + for(auto var:vars) + { + group.addVariable(var); + } + for(auto var:vars) + { + QVERIFY(group.contains(var)); + group.removeVariable(var); + QVERIFY(!group.contains(var)); + } + //shouldn't crash + group.removeVariable(v); + } +}; +QTEST_MAIN(TestSyncGroup) + +#include "TestSyncGroup.moc"