##// END OF EJS Templates
Setups test (2)...
Alexandre Leroux -
r714:6790f5fb3952
parent child
Show More
@@ -1,71 +1,138
1 #include <QObject>
1 #include <QObject>
2 #include <QtTest>
2 #include <QtTest>
3
3
4 #include <memory>
5
4 #include <Variable/Variable.h>
6 #include <Variable/Variable.h>
5 #include <Variable/VariableController.h>
7 #include <Variable/VariableController.h>
8 #include <Variable/VariableModel.h>
9
6 namespace {
10 namespace {
7
11
8 /**
12 /**
9 * Interface representing an operation performed on a variable controller.
13 * Interface representing an operation performed on a variable controller.
10 * This interface is used in tests to apply a set of operations and check the status of the
14 * This interface is used in tests to apply a set of operations and check the status of the
11 * controller after each operation
15 * controller after each operation
12 */
16 */
13 struct IOperation {
17 struct IOperation {
14 virtual ~IOperation() = default;
18 virtual ~IOperation() = default;
15 /// Executes the operation on the variable controller
19 /// Executes the operation on the variable controller
16 virtual void exec(VariableController &variableController) const = 0;
20 virtual void exec(VariableController &variableController) const = 0;
17 };
21 };
18
22
19 /**
23 /**
24 *Variable creation operation in the controller
25 */
26 struct Create : public IOperation {
27 explicit Create(int index) : m_Index{index} {}
28
29 void exec(VariableController &variableController) const override
30 {
31 auto variable = variableController.createVariable(QString::number(m_Index), {},
32 std::make_unique<TestProvider>());
33 }
34
35 int m_Index; ///< The index of the variable to create in the controller
36 };
37
38 /**
39 * Variable move/shift operation in the controller
40 */
41 struct Move : public IOperation {
42 explicit Move(int index, const SqpRange &newRange, bool shift = false)
43 : m_Index{index}, m_NewRange{newRange}, m_Shift{shift}
44 {
45 }
46
47 void exec(VariableController &variableController) const override
48 {
49 if (auto variable = variableController.variableModel()->variable(m_Index)) {
50 variableController.onRequestDataLoading({variable}, m_NewRange, variable->range(),
51 !m_Shift);
52 }
53 }
54
55 int m_Index; ///< The index of the variable to move
56 SqpRange m_NewRange; ///< The new range of the variable
57 bool m_Shift; ///< Performs a shift (
58 };
59
60 /**
61 * Variable synchronization/desynchronization operation in the controller
62 */
63 struct Synchronize : public IOperation {
64 explicit Synchronize(int index, QUuid syncId, bool synchronize = true)
65 : m_Index{index}, m_SyncId{syncId}, m_Synchronize{synchronize}
66 {
67 }
68
69 void exec(VariableController &variableController) const override
70 {
71 if (auto variable = variableController.variableModel()->variable(m_Index)) {
72 if (m_Synchronize) {
73 variableController.onAddSynchronized(variable, m_SyncId);
74 }
75 else {
76 variableController.desynchronize(variable, m_SyncId);
77 }
78 }
79 }
80
81 int m_Index; ///< The index of the variable to sync/desync
82 QUuid m_SyncId; ///< The synchronization group of the variable
83 bool m_Synchronize; ///< Performs sync or desync operation
84 };
85
86 /**
20 * Test Iteration
87 * Test Iteration
21 *
88 *
22 * A test iteration includes an operation to be performed, and a set of expected ranges after each
89 * A test iteration includes an operation to be performed, and a set of expected ranges after each
23 * operation. Each range is tested after the operation to ensure that:
90 * operation. Each range is tested after the operation to ensure that:
24 * - the range of the variable is the expected range
91 * - the range of the variable is the expected range
25 * - the data of the variable are those generated for the expected range
92 * - the data of the variable are those generated for the expected range
26 */
93 */
27 struct Iteration {
94 struct Iteration {
28 std::shared_ptr<IOperation> m_Operation; ///< Operation to perform
95 std::shared_ptr<IOperation> m_Operation; ///< Operation to perform
29 std::map<int, SqpRange> m_ExpectedRanges; ///< Expected ranges (by variable index)
96 std::map<int, SqpRange> m_ExpectedRanges; ///< Expected ranges (by variable index)
30 };
97 };
31
98
32 using Iterations = std::vector<Iteration>;
99 using Iterations = std::vector<Iteration>;
33
100
34 } // namespace
101 } // namespace
35
102
36 Q_DECLARE_METATYPE(Iterations)
103 Q_DECLARE_METATYPE(Iterations)
37
104
38 class TestVariableSync : public QObject {
105 class TestVariableSync : public QObject {
39 Q_OBJECT
106 Q_OBJECT
40
107
41 private slots:
108 private slots:
42 /// Input data for @sa testSync()
109 /// Input data for @sa testSync()
43 void testSync_data();
110 void testSync_data();
44
111
45 /// Tests synchronization between variables through several operations
112 /// Tests synchronization between variables through several operations
46 void testSync();
113 void testSync();
47 };
114 };
48
115
49 void TestVariableSync::testSync_data()
116 void TestVariableSync::testSync_data()
50 {
117 {
51 // ////////////// //
118 // ////////////// //
52 // Test structure //
119 // Test structure //
53 // ////////////// //
120 // ////////////// //
54
121
55 /// @todo
122 /// @todo
56
123
57 // ////////// //
124 // ////////// //
58 // Test cases //
125 // Test cases //
59 // ////////// //
126 // ////////// //
60
127
61 /// @todo
128 /// @todo
62 }
129 }
63
130
64 void TestVariableSync::testSync()
131 void TestVariableSync::testSync()
65 {
132 {
66 /// @todo
133 /// @todo
67 }
134 }
68
135
69 QTEST_MAIN(TestVariableSync)
136 QTEST_MAIN(TestVariableSync)
70
137
71 #include "TestVariableSync.moc"
138 #include "TestVariableSync.moc"
General Comments 0
You need to be logged in to leave comments. Login now