@@ -1,138 +1,192 | |||||
1 | #include <QObject> |
|
1 | #include <QObject> | |
2 | #include <QtTest> |
|
2 | #include <QtTest> | |
3 |
|
3 | |||
4 | #include <memory> |
|
4 | #include <memory> | |
5 |
|
5 | |||
|
6 | #include <Data/DataProviderParameters.h> | |||
|
7 | #include <Data/IDataProvider.h> | |||
|
8 | #include <Data/ScalarSeries.h> | |||
6 | #include <Variable/Variable.h> |
|
9 | #include <Variable/Variable.h> | |
7 | #include <Variable/VariableController.h> |
|
10 | #include <Variable/VariableController.h> | |
8 | #include <Variable/VariableModel.h> |
|
11 | #include <Variable/VariableModel.h> | |
9 |
|
12 | |||
10 | namespace { |
|
13 | namespace { | |
11 |
|
14 | |||
12 | /** |
|
15 | /** | |
|
16 | * Generates values according to a range. The value generated for a time t is the number of seconds | |||
|
17 | * of difference between t and a reference value (which is midnight -> 00:00:00) | |||
|
18 | * | |||
|
19 | * Example: For a range between 00:00:10 and 00:00:20, the generated values are | |||
|
20 | * {10,11,12,13,14,15,16,17,18,19,20} | |||
|
21 | */ | |||
|
22 | std::vector<double> values(const SqpRange &range) | |||
|
23 | { | |||
|
24 | QTime referenceTime{0, 0}; | |||
|
25 | ||||
|
26 | std::vector<double> result{}; | |||
|
27 | ||||
|
28 | for (auto i = range.m_TStart; i <= range.m_TEnd; ++i) { | |||
|
29 | auto time = DateUtils::dateTime(i).time(); | |||
|
30 | result.push_back(referenceTime.secsTo(time)); | |||
|
31 | } | |||
|
32 | ||||
|
33 | return result; | |||
|
34 | } | |||
|
35 | ||||
|
36 | /// Provider used for the tests | |||
|
37 | class TestProvider : public IDataProvider { | |||
|
38 | std::shared_ptr<IDataProvider> clone() const { return std::make_shared<TestProvider>(); } | |||
|
39 | ||||
|
40 | void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters ¶meters) override | |||
|
41 | { | |||
|
42 | const auto &ranges = parameters.m_Times; | |||
|
43 | ||||
|
44 | for (const auto &range : ranges) { | |||
|
45 | // Generates data series | |||
|
46 | auto valuesData = values(range); | |||
|
47 | ||||
|
48 | std::vector<double> xAxisData{}; | |||
|
49 | for (auto i = range.m_TStart; i <= range.m_TEnd; ++i) { | |||
|
50 | xAxisData.push_back(i); | |||
|
51 | } | |||
|
52 | ||||
|
53 | auto dataSeries = std::make_shared<ScalarSeries>( | |||
|
54 | std::move(xAxisData), std::move(valuesData), Unit{"t", true}, Unit{}); | |||
|
55 | ||||
|
56 | emit dataProvided(acqIdentifier, dataSeries, range); | |||
|
57 | } | |||
|
58 | } | |||
|
59 | ||||
|
60 | void requestDataAborting(QUuid acqIdentifier) override | |||
|
61 | { | |||
|
62 | // Does nothing | |||
|
63 | } | |||
|
64 | }; | |||
|
65 | ||||
|
66 | /** | |||
13 | * Interface representing an operation performed on a variable controller. |
|
67 | * Interface representing an operation performed on a variable controller. | |
14 | * This interface is used in tests to apply a set of operations and check the status of the |
|
68 | * This interface is used in tests to apply a set of operations and check the status of the | |
15 | * controller after each operation |
|
69 | * controller after each operation | |
16 | */ |
|
70 | */ | |
17 | struct IOperation { |
|
71 | struct IOperation { | |
18 | virtual ~IOperation() = default; |
|
72 | virtual ~IOperation() = default; | |
19 | /// Executes the operation on the variable controller |
|
73 | /// Executes the operation on the variable controller | |
20 | virtual void exec(VariableController &variableController) const = 0; |
|
74 | virtual void exec(VariableController &variableController) const = 0; | |
21 | }; |
|
75 | }; | |
22 |
|
76 | |||
23 | /** |
|
77 | /** | |
24 | *Variable creation operation in the controller |
|
78 | *Variable creation operation in the controller | |
25 | */ |
|
79 | */ | |
26 | struct Create : public IOperation { |
|
80 | struct Create : public IOperation { | |
27 | explicit Create(int index) : m_Index{index} {} |
|
81 | explicit Create(int index) : m_Index{index} {} | |
28 |
|
82 | |||
29 | void exec(VariableController &variableController) const override |
|
83 | void exec(VariableController &variableController) const override | |
30 | { |
|
84 | { | |
31 | auto variable = variableController.createVariable(QString::number(m_Index), {}, |
|
85 | auto variable = variableController.createVariable(QString::number(m_Index), {}, | |
32 | std::make_unique<TestProvider>()); |
|
86 | std::make_unique<TestProvider>()); | |
33 | } |
|
87 | } | |
34 |
|
88 | |||
35 | int m_Index; ///< The index of the variable to create in the controller |
|
89 | int m_Index; ///< The index of the variable to create in the controller | |
36 | }; |
|
90 | }; | |
37 |
|
91 | |||
38 | /** |
|
92 | /** | |
39 | * Variable move/shift operation in the controller |
|
93 | * Variable move/shift operation in the controller | |
40 | */ |
|
94 | */ | |
41 | struct Move : public IOperation { |
|
95 | struct Move : public IOperation { | |
42 | explicit Move(int index, const SqpRange &newRange, bool shift = false) |
|
96 | explicit Move(int index, const SqpRange &newRange, bool shift = false) | |
43 | : m_Index{index}, m_NewRange{newRange}, m_Shift{shift} |
|
97 | : m_Index{index}, m_NewRange{newRange}, m_Shift{shift} | |
44 | { |
|
98 | { | |
45 | } |
|
99 | } | |
46 |
|
100 | |||
47 | void exec(VariableController &variableController) const override |
|
101 | void exec(VariableController &variableController) const override | |
48 | { |
|
102 | { | |
49 | if (auto variable = variableController.variableModel()->variable(m_Index)) { |
|
103 | if (auto variable = variableController.variableModel()->variable(m_Index)) { | |
50 | variableController.onRequestDataLoading({variable}, m_NewRange, variable->range(), |
|
104 | variableController.onRequestDataLoading({variable}, m_NewRange, variable->range(), | |
51 | !m_Shift); |
|
105 | !m_Shift); | |
52 | } |
|
106 | } | |
53 | } |
|
107 | } | |
54 |
|
108 | |||
55 | int m_Index; ///< The index of the variable to move |
|
109 | int m_Index; ///< The index of the variable to move | |
56 | SqpRange m_NewRange; ///< The new range of the variable |
|
110 | SqpRange m_NewRange; ///< The new range of the variable | |
57 | bool m_Shift; ///< Performs a shift ( |
|
111 | bool m_Shift; ///< Performs a shift ( | |
58 | }; |
|
112 | }; | |
59 |
|
113 | |||
60 | /** |
|
114 | /** | |
61 | * Variable synchronization/desynchronization operation in the controller |
|
115 | * Variable synchronization/desynchronization operation in the controller | |
62 | */ |
|
116 | */ | |
63 | struct Synchronize : public IOperation { |
|
117 | struct Synchronize : public IOperation { | |
64 | explicit Synchronize(int index, QUuid syncId, bool synchronize = true) |
|
118 | explicit Synchronize(int index, QUuid syncId, bool synchronize = true) | |
65 | : m_Index{index}, m_SyncId{syncId}, m_Synchronize{synchronize} |
|
119 | : m_Index{index}, m_SyncId{syncId}, m_Synchronize{synchronize} | |
66 | { |
|
120 | { | |
67 | } |
|
121 | } | |
68 |
|
122 | |||
69 | void exec(VariableController &variableController) const override |
|
123 | void exec(VariableController &variableController) const override | |
70 | { |
|
124 | { | |
71 | if (auto variable = variableController.variableModel()->variable(m_Index)) { |
|
125 | if (auto variable = variableController.variableModel()->variable(m_Index)) { | |
72 | if (m_Synchronize) { |
|
126 | if (m_Synchronize) { | |
73 | variableController.onAddSynchronized(variable, m_SyncId); |
|
127 | variableController.onAddSynchronized(variable, m_SyncId); | |
74 | } |
|
128 | } | |
75 | else { |
|
129 | else { | |
76 | variableController.desynchronize(variable, m_SyncId); |
|
130 | variableController.desynchronize(variable, m_SyncId); | |
77 | } |
|
131 | } | |
78 | } |
|
132 | } | |
79 | } |
|
133 | } | |
80 |
|
134 | |||
81 | int m_Index; ///< The index of the variable to sync/desync |
|
135 | int m_Index; ///< The index of the variable to sync/desync | |
82 | QUuid m_SyncId; ///< The synchronization group of the variable |
|
136 | QUuid m_SyncId; ///< The synchronization group of the variable | |
83 | bool m_Synchronize; ///< Performs sync or desync operation |
|
137 | bool m_Synchronize; ///< Performs sync or desync operation | |
84 | }; |
|
138 | }; | |
85 |
|
139 | |||
86 | /** |
|
140 | /** | |
87 | * Test Iteration |
|
141 | * Test Iteration | |
88 | * |
|
142 | * | |
89 | * A test iteration includes an operation to be performed, and a set of expected ranges after each |
|
143 | * A test iteration includes an operation to be performed, and a set of expected ranges after each | |
90 | * operation. Each range is tested after the operation to ensure that: |
|
144 | * operation. Each range is tested after the operation to ensure that: | |
91 | * - the range of the variable is the expected range |
|
145 | * - the range of the variable is the expected range | |
92 | * - the data of the variable are those generated for the expected range |
|
146 | * - the data of the variable are those generated for the expected range | |
93 | */ |
|
147 | */ | |
94 | struct Iteration { |
|
148 | struct Iteration { | |
95 | std::shared_ptr<IOperation> m_Operation; ///< Operation to perform |
|
149 | std::shared_ptr<IOperation> m_Operation; ///< Operation to perform | |
96 | std::map<int, SqpRange> m_ExpectedRanges; ///< Expected ranges (by variable index) |
|
150 | std::map<int, SqpRange> m_ExpectedRanges; ///< Expected ranges (by variable index) | |
97 | }; |
|
151 | }; | |
98 |
|
152 | |||
99 | using Iterations = std::vector<Iteration>; |
|
153 | using Iterations = std::vector<Iteration>; | |
100 |
|
154 | |||
101 | } // namespace |
|
155 | } // namespace | |
102 |
|
156 | |||
103 | Q_DECLARE_METATYPE(Iterations) |
|
157 | Q_DECLARE_METATYPE(Iterations) | |
104 |
|
158 | |||
105 | class TestVariableSync : public QObject { |
|
159 | class TestVariableSync : public QObject { | |
106 | Q_OBJECT |
|
160 | Q_OBJECT | |
107 |
|
161 | |||
108 | private slots: |
|
162 | private slots: | |
109 | /// Input data for @sa testSync() |
|
163 | /// Input data for @sa testSync() | |
110 | void testSync_data(); |
|
164 | void testSync_data(); | |
111 |
|
165 | |||
112 | /// Tests synchronization between variables through several operations |
|
166 | /// Tests synchronization between variables through several operations | |
113 | void testSync(); |
|
167 | void testSync(); | |
114 | }; |
|
168 | }; | |
115 |
|
169 | |||
116 | void TestVariableSync::testSync_data() |
|
170 | void TestVariableSync::testSync_data() | |
117 | { |
|
171 | { | |
118 | // ////////////// // |
|
172 | // ////////////// // | |
119 | // Test structure // |
|
173 | // Test structure // | |
120 | // ////////////// // |
|
174 | // ////////////// // | |
121 |
|
175 | |||
122 | /// @todo |
|
176 | /// @todo | |
123 |
|
177 | |||
124 | // ////////// // |
|
178 | // ////////// // | |
125 | // Test cases // |
|
179 | // Test cases // | |
126 | // ////////// // |
|
180 | // ////////// // | |
127 |
|
181 | |||
128 | /// @todo |
|
182 | /// @todo | |
129 | } |
|
183 | } | |
130 |
|
184 | |||
131 | void TestVariableSync::testSync() |
|
185 | void TestVariableSync::testSync() | |
132 | { |
|
186 | { | |
133 | /// @todo |
|
187 | /// @todo | |
134 | } |
|
188 | } | |
135 |
|
189 | |||
136 | QTEST_MAIN(TestVariableSync) |
|
190 | QTEST_MAIN(TestVariableSync) | |
137 |
|
191 | |||
138 | #include "TestVariableSync.moc" |
|
192 | #include "TestVariableSync.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now