##// END OF EJS Templates
Inits unit tests for DataSource controller
Alexandre Leroux -
r38:ac9e67540b80
parent child
Show More
@@ -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"
@@ -1,128 +1,130
1 1
2 2 ## core - CMakeLists.txt
3 3 STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX)
4 4 SET(SQPCORE_LIBRARY_NAME "${LIBRARY_PREFFIX}_core${DEBUG_SUFFIX}")
5 5 SET(SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/")
6 6 SET(INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/")
7 7
8 8 # Include core directory
9 9 include_directories("${INCLUDES_DIR}")
10 10
11 11 # Set a variable to display a warning in the version files.
12 12 SET(SCIQLOP_CMAKE_GENERATION_WARNING "DON'T CHANGE THIS FILE. AUTOGENERATED BY CMAKE.")
13 13 # Generate the version file from the cmake version variables. The version
14 14 # variables are defined in the cmake/sciqlop_version.cmake file.
15 15 CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/resources/Version.h.in"
16 16 "${INCLUDES_DIR}/Version.h")
17 17 CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/resources/Version.cpp.in"
18 18 "${SOURCES_DIR}/Version.cpp")
19 19
20 20 #
21 21 # Find Qt modules
22 22 #
23 23 SCIQLOP_FIND_QT(Core)
24 24
25 25 #
26 26 # Compile the library library
27 27 #
28 28 FILE (GLOB_RECURSE MODULE_SOURCES
29 29 ${INCLUDES_DIR}/*.h
30 30 ${SOURCES_DIR}/*.c
31 31 ${SOURCES_DIR}/*.cpp
32 32 ${SOURCES_DIR}/*.h)
33 33
34 34 ADD_LIBRARY(${SQPCORE_LIBRARY_NAME} ${MODULE_SOURCES})
35 35 set_property(TARGET ${SQPCORE_LIBRARY_NAME} PROPERTY CXX_STANDARD 14)
36 36 set_property(TARGET ${SQPCORE_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
37 37 TARGET_LINK_LIBRARIES(${SQPCORE_LIBRARY_NAME})
38 38 qt5_use_modules(${SQPCORE_LIBRARY_NAME} Core)
39 39
40 40 # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html
41 41 # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order.
42 42 # The DEFINE_SYMBOL target property is also added as a compile definition as a special convenience case for SHARED and MODULE library targets
43 43 IF(BUILD_SHARED_LIBS)
44 44 SET_TARGET_PROPERTIES(${SQPCORE_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT")
45 45 ELSE()
46 46 TARGET_COMPILE_DEFINITIONS(${SQPCORE_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES")
47 47 ENDIF()
48 48
49 49 # Set the variable to parent scope so that the other projects can copy the
50 50 # dependent shared libraries
51 51 SCIQLOP_SET_TO_PARENT_SCOPE(SQPCORE_LIBRARY_NAME)
52 52
53 53 # Copy extern shared libraries to the lib folder
54 54 SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPCORE_LIBRARY_NAME} ${EXTERN_SHARED_LIBRARIES})
55 55
56 56 # Add the files to the list of files to be analyzed
57 57 LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES})
58 58 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES)
59 59 # Vera++ exclusion files
60 60 LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt)
61 61 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES)
62 62
63 63 #
64 64 # Compile the tests
65 65 #
66 66 IF(BUILD_TESTS)
67 67 INCLUDE_DIRECTORIES(${SOURCES_DIR})
68 68 FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp)
69 69 FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h)
70 70 SET( TEST_LIBRARIES ${SQPCORE_LIBRARY_NAME})
71 71
72 72 FOREACH( testFile ${TESTS_SOURCES} )
73 73 GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY )
74 74 GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE )
75 75
76 76 # Add to the list of sources files all the sources in the same
77 77 # directory that aren't another test
78 78 FILE (GLOB currentTestSources
79 79 ${testDirectory}/*.c
80 80 ${testDirectory}/*.cpp
81 81 ${testDirectory}/*.h)
82 LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES})
83 LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS})
82 LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES})
83 # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS})
84 84
85 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 88 TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} )
87 89 qt5_use_modules(${testName} Test)
88 90
89 91 ADD_TEST( NAME ${testName} COMMAND ${testName} )
90 92
91 93 SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES})
92 94 ENDFOREACH( testFile )
93 95
94 96 LIST(APPEND testFilesToFormat ${TESTS_SOURCES})
95 97 LIST(APPEND testFilesToFormat ${TESTS_HEADERS})
96 98 LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat})
97 99 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
98 100 ENDIF(BUILD_TESTS)
99 101
100 102 #
101 103 # Set the files that must be formatted by clang-format.
102 104 #
103 105 LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES})
104 106 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
105 107
106 108 #
107 109 # Set the directories that doxygen must browse to generate the
108 110 # documentation.
109 111 #
110 112 # Source directories:
111 113 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs")
112 114 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
113 115 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS)
114 116 # Source directories to exclude from the documentation generation
115 117 #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*")
116 118 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS)
117 119
118 120 #
119 121 # Set the directories with the sources to analyze and propagate the
120 122 # modification to the parent scope
121 123 #
122 124 # Source directories to analyze:
123 125 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
124 126 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
125 127 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS)
126 128 # Source directories to exclude from the analysis
127 129 #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir")
128 130 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS)
@@ -1,158 +1,160
1 1
2 2 ## gui - CMakeLists.txt
3 3 STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX)
4 4 SET(SQPGUI_LIBRARY_NAME "${LIBRARY_PREFFIX}_gui${DEBUG_SUFFIX}")
5 5 SET(SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
6 6 SET(INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
7 7 SET(UI_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/ui")
8 8 SET(RES_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/resources")
9 9
10 10 # Include gui directory
11 11 include_directories("${INCLUDES_DIR}")
12 12 include_directories("${CMAKE_CURRENT_BINARY_DIR}")
13 13
14 14 # Set a variable to display a warning in the version files.
15 15 SET(SCIQLOP_CMAKE_GENERATION_WARNING "DON'T CHANGE THIS FILE. AUTOGENERATED BY CMAKE.")
16 16
17 17 #
18 18 # Find Qt modules
19 19 #
20 20 SCIQLOP_FIND_QT(Core Widgets)
21 21
22 22 #
23 23 # Find dependent libraries
24 24 # ========================
25 25 find_package(sciqlop-core)
26 26
27 27 SET(LIBRARIES ${SCIQLOP-CORE_LIBRARIES})
28 28
29 29 INCLUDE_DIRECTORIES(${SCIQLOP-CORE_INCLUDE_DIR})
30 30
31 31 # Add sqpcore to the list of libraries to use
32 32 list(APPEND LIBRARIES ${SQPCORE_LIBRARY_NAME})
33 33
34 34 # Add dependent shared libraries
35 35 list(APPEND SHARED_LIBRARIES ${SQPCORE_SHARED_LIBRARIES})
36 36
37 37
38 38 # Ui files
39 39 FILE (GLOB_RECURSE PROJECT_FORMS ${UI_FOLDER}/*.ui)
40 40
41 41 # Resources files
42 42 FILE (GLOB_RECURSE PROJECT_RESOURCES ${RES_FOLDER}/*.qrc)
43 43
44 44 #
45 45 # Compile the library library
46 46 #
47 47 FILE (GLOB_RECURSE MODULE_SOURCES
48 48 ${INCLUDES_DIR}/*.h
49 49 ${SOURCES_DIR}/*.c
50 50 ${SOURCES_DIR}/*.cpp
51 51 ${SOURCES_DIR}/*.h
52 52 ${PROJECT_FORMS})
53 53
54 54 QT5_ADD_RESOURCES(RCC_HDRS
55 55 ${PROJECT_RESOURCES}
56 56 )
57 57
58 58 QT5_WRAP_UI(UIS_HDRS
59 59 ${PROJECT_FORMS}
60 60 )
61 61
62 62
63 63 ADD_LIBRARY(${SQPGUI_LIBRARY_NAME} ${MODULE_SOURCES} ${UIS_HDRS} ${RCC_HDRS})
64 64 set_property(TARGET ${SQPGUI_LIBRARY_NAME} PROPERTY CXX_STANDARD 14)
65 65 set_property(TARGET ${SQPGUI_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
66 66
67 67 TARGET_LINK_LIBRARIES(${SQPGUI_LIBRARY_NAME} ${LIBRARIES})
68 68 qt5_use_modules(${SQPGUI_LIBRARY_NAME} Core Widgets)
69 69
70 70 # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html
71 71 # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order.
72 72 # The DEFINE_SYMBOL target property is also added as a compile definition as a special convenience case for SHARED and MODULE library targets
73 73 IF(BUILD_SHARED_LIBS)
74 74 SET_TARGET_PROPERTIES(${SQPGUI_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT")
75 75 ELSE()
76 76 TARGET_COMPILE_DEFINITIONS(${SQPGUI_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES")
77 77 ENDIF()
78 78
79 79 # Set the variable to parent scope so that the other projects can copy the
80 80 # dependent shared libraries
81 81 SCIQLOP_SET_TO_PARENT_SCOPE(SQPGUI_LIBRARY_NAME)
82 82
83 83 # Copy extern shared libraries to the lib folder
84 84 SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPGUI_LIBRARY_NAME})
85 85
86 86 # Add the files to the list of files to be analyzed
87 87 LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES})
88 88 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES)
89 89 # Vera++ exclusion files
90 90 #LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/path/to/exclusionFiles.tcl)
91 91 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES)
92 92
93 93 #
94 94 # Compile the tests
95 95 #
96 96 IF(BUILD_TESTS)
97 97 INCLUDE_DIRECTORIES(${SOURCES_DIR})
98 98 FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp)
99 99 FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h)
100 100 SET( TEST_LIBRARIES ${SQPGUI_LIBRARY_NAME})
101 101
102 102 FOREACH( testFile ${TESTS_SOURCES} )
103 103 GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY )
104 104 GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE )
105 105
106 106 # Add to the list of sources files all the sources in the same
107 107 # directory that aren't another test
108 108 FILE (GLOB currentTestSources
109 109 ${testDirectory}/*.c
110 110 ${testDirectory}/*.cpp
111 111 ${testDirectory}/*.h)
112 112 LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES})
113 LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS})
113 # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS})
114 114
115 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 118 TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} )
117 119 qt5_use_modules(${testName} Test)
118 120
119 121 ADD_TEST( NAME ${testName} COMMAND ${testName} )
120 122
121 123 SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES})
122 124 ENDFOREACH( testFile )
123 125
124 126 LIST(APPEND testFilesToFormat ${TESTS_SOURCES})
125 127 LIST(APPEND testFilesToFormat ${TESTS_HEADERS})
126 128 LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat})
127 129 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
128 130 ENDIF(BUILD_TESTS)
129 131
130 132 #
131 133 # Set the files that must be formatted by clang-format.
132 134 #
133 135 LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES})
134 136 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
135 137
136 138 #
137 139 # Set the directories that doxygen must browse to generate the
138 140 # documentation.
139 141 #
140 142 # Source directories:
141 143 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs")
142 144 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
143 145 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS)
144 146 # Source directories to exclude from the documentation generation
145 147 #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*")
146 148 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS)
147 149
148 150 #
149 151 # Set the directories with the sources to analyze and propagate the
150 152 # modification to the parent scope
151 153 #
152 154 # Source directories to analyze:
153 155 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
154 156 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
155 157 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS)
156 158 # Source directories to exclude from the analysis
157 159 #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir")
158 160 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS)
General Comments 0
You need to be logged in to leave comments. Login now