@@ -0,0 +1,49 | |||||
|
1 | #include <DataSource/DataSourceController.h> | |||
|
2 | #include <DataSource/DataSourceItem.h> | |||
|
3 | ||||
|
4 | #include <QObject> | |||
|
5 | #include <QtTest> | |||
|
6 | ||||
|
7 | #include <memory> | |||
|
8 | ||||
|
9 | class TestDataSourceController : public QObject { | |||
|
10 | Q_OBJECT | |||
|
11 | private slots: | |||
|
12 | void testRegisterDataSource(); | |||
|
13 | void testSetDataSourceItem(); | |||
|
14 | }; | |||
|
15 | ||||
|
16 | void TestDataSourceController::testRegisterDataSource() | |||
|
17 | { | |||
|
18 | DataSourceController dataSourceController{}; | |||
|
19 | ||||
|
20 | auto uid = dataSourceController.registerDataSource(QStringLiteral("Source1")); | |||
|
21 | QVERIFY(!uid.isNull()); | |||
|
22 | } | |||
|
23 | ||||
|
24 | void TestDataSourceController::testSetDataSourceItem() | |||
|
25 | { | |||
|
26 | DataSourceController dataSourceController{}; | |||
|
27 | ||||
|
28 | // Spy to test controllers' signals | |||
|
29 | QSignalSpy signalSpy{&dataSourceController, SIGNAL(dataSourceItemSet(const DataSourceItem &))}; | |||
|
30 | ||||
|
31 | // Create a data source item | |||
|
32 | auto source1Name = QStringLiteral("Source1"); | |||
|
33 | auto source1Values = QVector<QVariant>{source1Name}; | |||
|
34 | auto source1Item = std::make_unique<DataSourceItem>(std::move(source1Values)); | |||
|
35 | ||||
|
36 | // Add data source item to the controller and check that a signal has been emitted after setting | |||
|
37 | // data source item in the controller | |||
|
38 | auto source1Uid = dataSourceController.registerDataSource(source1Name); | |||
|
39 | dataSourceController.setDataSourceItem(source1Uid, std::move(source1Item)); | |||
|
40 | QCOMPARE(signalSpy.count(), 1); | |||
|
41 | ||||
|
42 | // Try to a data source item with an unregistered uid and check that no signal has been emitted | |||
|
43 | auto unregisteredUid = QUuid::createUuid(); | |||
|
44 | dataSourceController.setDataSourceItem(unregisteredUid, std::make_unique<DataSourceItem>()); | |||
|
45 | QCOMPARE(signalSpy.count(), 1); | |||
|
46 | } | |||
|
47 | ||||
|
48 | QTEST_MAIN(TestDataSourceController) | |||
|
49 | #include "TestDataSourceController.moc" |
@@ -79,10 +79,12 IF(BUILD_TESTS) | |||||
79 | ${testDirectory}/*.c |
|
79 | ${testDirectory}/*.c | |
80 | ${testDirectory}/*.cpp |
|
80 | ${testDirectory}/*.cpp | |
81 | ${testDirectory}/*.h) |
|
81 | ${testDirectory}/*.h) | |
82 |
|
|
82 | LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES}) | |
83 |
|
|
83 | # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS}) | |
84 |
|
84 | |||
85 | ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources}) |
|
85 | ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources}) | |
|
86 | set_property(TARGET ${testName} PROPERTY CXX_STANDARD 14) | |||
|
87 | set_property(TARGET ${testName} PROPERTY CXX_STANDARD_REQUIRED ON) | |||
86 | TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} ) |
|
88 | TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} ) | |
87 | qt5_use_modules(${testName} Test) |
|
89 | qt5_use_modules(${testName} Test) | |
88 |
|
90 |
@@ -110,9 +110,11 IF(BUILD_TESTS) | |||||
110 | ${testDirectory}/*.cpp |
|
110 | ${testDirectory}/*.cpp | |
111 | ${testDirectory}/*.h) |
|
111 | ${testDirectory}/*.h) | |
112 | LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES}) |
|
112 | LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES}) | |
113 | LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS}) |
|
113 | # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS}) | |
114 |
|
114 | |||
115 | ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources}) |
|
115 | ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources}) | |
|
116 | set_property(TARGET ${testName} PROPERTY CXX_STANDARD 14) | |||
|
117 | set_property(TARGET ${testName} PROPERTY CXX_STANDARD_REQUIRED ON) | |||
116 | TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} ) |
|
118 | TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} ) | |
117 | qt5_use_modules(${testName} Test) |
|
119 | qt5_use_modules(${testName} Test) | |
118 |
|
120 |
General Comments 0
You need to be logged in to leave comments.
Login now