@@ -0,0 +1,72 | |||
|
1 | #include <QObject> | |
|
2 | #include <QtTest> | |
|
3 | ||
|
4 | #include <Data/IDataProvider.h> | |
|
5 | #include <Time/TimeController.h> | |
|
6 | #include <Variable/Variable.h> | |
|
7 | #include <Variable/VariableController.h> | |
|
8 | ||
|
9 | #include <memory> | |
|
10 | ||
|
11 | namespace { | |
|
12 | ||
|
13 | /// Provider used for the tests | |
|
14 | class TestProvider : public IDataProvider { | |
|
15 | void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters ¶meters) override | |
|
16 | { | |
|
17 | // Does nothing | |
|
18 | } | |
|
19 | ||
|
20 | void requestDataAborting(QUuid acqIdentifier) override | |
|
21 | { | |
|
22 | // Does nothing | |
|
23 | } | |
|
24 | }; | |
|
25 | ||
|
26 | /// Generates a time controller for the tests | |
|
27 | std::unique_ptr<TimeController> defaultTimeController() | |
|
28 | { | |
|
29 | auto timeController = std::make_unique<TimeController>(); | |
|
30 | ||
|
31 | QDateTime start{QDate{2017, 01, 01}, QTime{0, 0, 0, 0}}; | |
|
32 | QDateTime end{QDate{2017, 01, 02}, QTime{0, 0, 0, 0}}; | |
|
33 | timeController->onTimeToUpdate( | |
|
34 | SqpRange{DateUtils::secondsSinceEpoch(start), DateUtils::secondsSinceEpoch(end)}); | |
|
35 | ||
|
36 | return timeController; | |
|
37 | } | |
|
38 | ||
|
39 | } // namespace | |
|
40 | ||
|
41 | class TestVariableController : public QObject { | |
|
42 | Q_OBJECT | |
|
43 | ||
|
44 | private slots: | |
|
45 | /// Test removes variable from controller | |
|
46 | void testDeleteVariable(); | |
|
47 | }; | |
|
48 | ||
|
49 | void TestVariableController::testDeleteVariable() | |
|
50 | { | |
|
51 | // Creates variable controller | |
|
52 | auto timeController = defaultTimeController(); | |
|
53 | VariableController variableController{}; | |
|
54 | variableController.setTimeController(timeController.get()); | |
|
55 | ||
|
56 | // Creates a variable from the controller | |
|
57 | auto variable | |
|
58 | = variableController.createVariable("variable", {}, std::make_shared<TestProvider>()); | |
|
59 | ||
|
60 | qDebug() << QString::number(variable.use_count()); | |
|
61 | ||
|
62 | // Removes the variable from the controller | |
|
63 | variableController.deleteVariable(variable); | |
|
64 | ||
|
65 | // Verifies that the variable has been deleted: this implies that the number of shared_ptr | |
|
66 | // objects referring to the variable is 1 (the reference of this scope). Otherwise, the deletion | |
|
67 | // is considered invalid since the variable is still referenced in the controller | |
|
68 | QVERIFY(variable.use_count() == 1); | |
|
69 | } | |
|
70 | ||
|
71 | QTEST_MAIN(TestVariableController) | |
|
72 | #include "TestVariableController.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now