##// END OF EJS Templates
Added SynchronizationGroup2 tests and documentation...
jeandet -
r1:d51953af4db3
parent child
Show More
@@ -0,0 +1,51
1 #include <QObject>
2 #include <QtTest>
3 #include <QUuid>
4
5 #include <Variable/VariableSynchronizationGroup2.h>
6
7 class TestSyncGroup: public QObject {
8 Q_OBJECT
9
10 private slots:
11 void testAddVariables()
12 {
13 auto v = QUuid::createUuid();
14 VariableSynchronizationGroup2 group{v};
15 QVERIFY(group.contains(v));
16 auto vars = {QUuid::createUuid(), QUuid::createUuid(), QUuid::createUuid(), QUuid::createUuid()};
17 for(auto var:vars)
18 {
19 group.addVariable(var);
20 }
21 for(auto var:vars)
22 {
23 QVERIFY(group.contains(var));
24 }
25 }
26
27 void testRemoveVariables()
28 {
29 auto v = QUuid::createUuid();
30 VariableSynchronizationGroup2 group{v};
31 QVERIFY(group.contains(v));
32 group.removeVariable(v);
33 QVERIFY(!group.contains(v));
34 auto vars = {QUuid::createUuid(), QUuid::createUuid(), QUuid::createUuid(), QUuid::createUuid()};
35 for(auto var:vars)
36 {
37 group.addVariable(var);
38 }
39 for(auto var:vars)
40 {
41 QVERIFY(group.contains(var));
42 group.removeVariable(var);
43 QVERIFY(!group.contains(var));
44 }
45 //shouldn't crash
46 group.removeVariable(v);
47 }
48 };
49 QTEST_MAIN(TestSyncGroup)
50
51 #include "TestSyncGroup.moc"
@@ -8,25 +8,61
8 8 #include <Common/spimpl.h>
9 9 #include <Common/containers.h>
10 10
11 /**
12 * @brief The VariableSynchronizationGroup2 class holds a list of Variables uuid which are synchronized
13 * @note This class is part of SciQLop internals, as a normal user you shouldn't have to care about it
14 */
11 15 class SCIQLOP_CORE_EXPORT VariableSynchronizationGroup2
12 16 {
13 17
14 18 public:
15 19 explicit VariableSynchronizationGroup2()=default;
16 // Convenience ctor to build a group with a default variable
20 /**
21 * @brief VariableSynchronizationGroup2 is a convenience ctor to build a group with a default variable
22 * @param variable
23 */
17 24 explicit VariableSynchronizationGroup2(QUuid variable)
18 25 :_variables{{variable}}
19 26 {}
20 27
21 void addVariable(QUuid variable);
22 void removeVariable(QUuid variable);
28 /**
29 * @brief addVariable adds the given variable to the group, does nothing if the varaible is alredy in the group
30 * @param variable
31 * @sa removeVariable
32 */
33 void addVariable(QUuid variable) noexcept
34 {
35 this->_variables.insert(variable);
36 }
23 37
24 bool contains(QUuid variable)
38 /**
39 * @brief removeVariable removes the given variable from the group, does nothing if the varaible is not in the group
40 * @param variable
41 * @sa addVariable
42 */
43 void removeVariable(QUuid variable) noexcept
44 {
45 this->_variables.extract(variable);
46 }
47
48 /**
49 * @brief contains checks if the given variable is in the group
50 * @param variable
51 * @return true if the variable is in the group
52 */
53 bool contains(QUuid variable) const noexcept
25 54 {
26 55 return SciQLop::containers::contains(this->_variables,variable);
27 56 }
28 57
29 const std::set<QUuid> &variables() const noexcept;
58 /**
59 * @brief variables
60 * @return the list of synchronized variables in this group as a std::set
61 */
62 const std::set<QUuid> &variables() const noexcept
63 {
64 return this->_variables;
65 }
30 66
31 67 private:
32 68 std::set<QUuid> _variables;
@@ -4,6 +4,7 add_definitions(-DCORE_TESTS_RESOURCES_DIR="${CMAKE_CURRENT_LIST_DIR}/../tests-r
4 4 declare_test(TestStringUtils TestStringUtils Common/TestStringUtils.cpp "sciqlopcore;Qt5::Test")
5 5
6 6 declare_test(TestContainers TestContainers Common/TestContainers.cpp "sciqlopcore;Qt5::Test")
7 declare_test(TestSyncGroup TestSyncGroup Variable/TestSyncGroup.cpp "sciqlopcore;Qt5::Test")
7 8
8 9
9 10 declare_test(TestDataSeriesUtils TestDataSeriesUtils Data/TestDataSeriesUtils.cpp "sciqlopcore;Qt5::Test")
General Comments 0
You need to be logged in to leave comments. Login now