##// END OF EJS Templates
Inits unit tests
Alexandre Leroux -
r358:20e67488223e
parent child
Show More
@@ -0,0 +1,82
1 #include "AmdaParser.h"
2
3 #include <DataSource/DataSourceItem.h>
4
5 #include <QObject>
6 #include <QtTest>
7
8 #include <QString>
9
10 namespace {
11
12 /// Path for the tests
13 const auto TESTS_RESOURCES_PATH
14 = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaParser"}.absoluteFilePath();
15
16 QString inputFilePath(const QString &inputFileName)
17 {
18 return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath();
19 }
20
21 struct ExpectedResults {
22 explicit ExpectedResults() = default;
23 explicit ExpectedResults(std::shared_ptr<DataSourceItem> item)
24 : m_ParsingOK{true}, m_Item{std::move(item)}
25 {
26 }
27
28 // Parsing was successfully completed
29 bool m_ParsingOK{false};
30 // Expected item after parsing
31 std::shared_ptr<DataSourceItem> m_Item{nullptr};
32 };
33
34 } // namespace
35
36 Q_DECLARE_METATYPE(ExpectedResults)
37
38 class TestAmdaParser : public QObject {
39 Q_OBJECT
40 private slots:
41 /// Input test data
42 /// @sa testReadJson()
43 void testReadJson_data();
44
45 /// Tests parsing of a JSON file
46 void testReadJson();
47 };
48
49 void TestAmdaParser::testReadJson_data()
50 {
51 // ////////////// //
52 // Test structure //
53 // ////////////// //
54
55 // Name of JSON file to read
56 QTest::addColumn<QString>("inputFileName");
57 // Expected results
58 QTest::addColumn<ExpectedResults>("expectedResults");
59 }
60
61 void TestAmdaParser::testReadJson()
62 {
63 QFETCH(QString, inputFileName);
64 QFETCH(ExpectedResults, expectedResults);
65
66 // Parses file
67 auto filePath = inputFilePath(inputFileName);
68 auto item = AmdaParser::readJson(filePath);
69
70 // Validates results
71 if (expectedResults.m_ParsingOK) {
72 QVERIFY(item != nullptr);
73 QVERIFY(expectedResults.m_Item != nullptr);
74 QVERIFY(*item == *expectedResults.m_Item);
75 }
76 else {
77 QVERIFY(item == nullptr);
78 }
79 }
80
81 QTEST_MAIN(TestAmdaParser)
82 #include "TestAmdaParser.moc"
@@ -1,164 +1,167
1 ## amda - CMakeLists.txt
1 ## amda - CMakeLists.txt
2 STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX)
2 STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX)
3 SET(SQPAMDA_LIBRARY_NAME "${LIBRARY_PREFFIX}_amda${DEBUG_SUFFIX}")
3 SET(SQPAMDA_LIBRARY_NAME "${LIBRARY_PREFFIX}_amda${DEBUG_SUFFIX}")
4 SET(SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
4 SET(SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
5 SET(INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
5 SET(INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
6 SET(RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources")
6 SET(RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources")
7 SET(TESTS_RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests-resources")
7
8
8 # Include amda directory
9 # Include amda directory
9 INCLUDE_DIRECTORIES(${INCLUDES_DIR})
10 INCLUDE_DIRECTORIES(${INCLUDES_DIR})
10 INCLUDE_DIRECTORIES(${RESOURCES_DIR})
11 INCLUDE_DIRECTORIES(${RESOURCES_DIR})
11
12
12 #
13 #
13 # Find Qt modules
14 # Find Qt modules
14 #
15 #
15 SCIQLOP_FIND_QT(Core Widgets)
16 SCIQLOP_FIND_QT(Core Widgets)
16
17
17 #
18 #
18 # Find dependent libraries
19 # Find dependent libraries
19 # ========================
20 # ========================
20
21
21 # sciqlop plugin
22 # sciqlop plugin
22 find_package(sciqlop-plugin)
23 find_package(sciqlop-plugin)
23 INCLUDE_DIRECTORIES(${SCIQLOP-PLUGIN_INCLUDE_DIR})
24 INCLUDE_DIRECTORIES(${SCIQLOP-PLUGIN_INCLUDE_DIR})
24
25
25 # sciqlop core
26 # sciqlop core
26 find_package(sciqlop-core)
27 find_package(sciqlop-core)
27 INCLUDE_DIRECTORIES(${SCIQLOP-CORE_INCLUDE_DIR})
28 INCLUDE_DIRECTORIES(${SCIQLOP-CORE_INCLUDE_DIR})
28 list(APPEND LIBRARIES ${SCIQLOP-CORE_LIBRARIES})
29 list(APPEND LIBRARIES ${SCIQLOP-CORE_LIBRARIES})
29
30
30 # sciqlop gui
31 # sciqlop gui
31 find_package(sciqlop-gui)
32 find_package(sciqlop-gui)
32 INCLUDE_DIRECTORIES(${SCIQLOP-GUI_INCLUDE_DIR})
33 INCLUDE_DIRECTORIES(${SCIQLOP-GUI_INCLUDE_DIR})
33 list(APPEND LIBRARIES ${SCIQLOP-GUI_LIBRARIES})
34 list(APPEND LIBRARIES ${SCIQLOP-GUI_LIBRARIES})
34
35
35 # Description file
36 # Description file
36 FILE (GLOB_RECURSE PLUGIN_FILE ${RESOURCES_DIR}/amda.json)
37 FILE (GLOB_RECURSE PLUGIN_FILE ${RESOURCES_DIR}/amda.json)
37
38
38 # Resources files
39 # Resources files
39 FILE (GLOB_RECURSE PROJECT_RESOURCES ${RESOURCES_DIR}/*.qrc)
40 FILE (GLOB_RECURSE PROJECT_RESOURCES ${RESOURCES_DIR}/*.qrc)
40
41
41 #
42 #
42 # Compile the library
43 # Compile the library
43 #
44 #
44
45
45 ADD_DEFINITIONS(-DAMDA_LIB)
46 ADD_DEFINITIONS(-DAMDA_LIB)
46
47
47 FILE (GLOB_RECURSE MODULE_SOURCES
48 FILE (GLOB_RECURSE MODULE_SOURCES
48 ${INCLUDES_DIR}/*.h
49 ${INCLUDES_DIR}/*.h
49 ${SOURCES_DIR}/*.c
50 ${SOURCES_DIR}/*.c
50 ${SOURCES_DIR}/*.cpp
51 ${SOURCES_DIR}/*.cpp
51 ${SOURCES_DIR}/*.h
52 ${SOURCES_DIR}/*.h
52 ${PLUGIN_FILE})
53 ${PLUGIN_FILE})
53
54
54 QT5_ADD_RESOURCES(RCC_AMDA
55 QT5_ADD_RESOURCES(RCC_AMDA
55 ${PROJECT_RESOURCES}
56 ${PROJECT_RESOURCES}
56 )
57 )
57
58
58 ADD_LIBRARY(${SQPAMDA_LIBRARY_NAME} ${MODULE_SOURCES} ${RCC_AMDA})
59 ADD_LIBRARY(${SQPAMDA_LIBRARY_NAME} ${MODULE_SOURCES} ${RCC_AMDA})
59 set_property(TARGET ${SQPAMDA_LIBRARY_NAME} PROPERTY CXX_STANDARD 14)
60 set_property(TARGET ${SQPAMDA_LIBRARY_NAME} PROPERTY CXX_STANDARD 14)
60 set_property(TARGET ${SQPAMDA_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
61 set_property(TARGET ${SQPAMDA_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
61
62
62 INSTALL(TARGETS ${SQPAMDA_LIBRARY_NAME}
63 INSTALL(TARGETS ${SQPAMDA_LIBRARY_NAME}
63 RUNTIME DESTINATION ${INSTALL_BINARY_DIR}
64 RUNTIME DESTINATION ${INSTALL_BINARY_DIR}
64 LIBRARY DESTINATION ${INSTALL_PLUGINS_LIBRARY_DIR}
65 LIBRARY DESTINATION ${INSTALL_PLUGINS_LIBRARY_DIR}
65 ARCHIVE DESTINATION ${INSTALL_PLUGINS_LIBRARY_DIR}
66 ARCHIVE DESTINATION ${INSTALL_PLUGINS_LIBRARY_DIR}
66 )
67 )
67
68
68
69
69 TARGET_LINK_LIBRARIES(${SQPAMDA_LIBRARY_NAME} ${LIBRARIES})
70 TARGET_LINK_LIBRARIES(${SQPAMDA_LIBRARY_NAME} ${LIBRARIES})
70 qt5_use_modules(${SQPAMDA_LIBRARY_NAME} Core Widgets)
71 qt5_use_modules(${SQPAMDA_LIBRARY_NAME} Core Widgets)
71
72
72 add_dependencies(${SQPAMDA_LIBRARY_NAME} ${SQPPLUGIN_LIBRARY_NAME} ${SQPGUI_LIBRARY_NAME} ${SQPCORE_LIBRARY_NAME})
73 add_dependencies(${SQPAMDA_LIBRARY_NAME} ${SQPPLUGIN_LIBRARY_NAME} ${SQPGUI_LIBRARY_NAME} ${SQPCORE_LIBRARY_NAME})
73
74
74 # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html
75 # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html
75 # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order.
76 # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order.
76 # The DEFINE_SYMBOL target property is also added as a compile definition as a special convenience case for SHARED and MODULE library targets
77 # The DEFINE_SYMBOL target property is also added as a compile definition as a special convenience case for SHARED and MODULE library targets
77 IF(BUILD_SHARED_LIBS)
78 IF(BUILD_SHARED_LIBS)
78 SET_TARGET_PROPERTIES(${SQPAMDA_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT")
79 SET_TARGET_PROPERTIES(${SQPAMDA_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT")
79 ELSE()
80 ELSE()
80 TARGET_COMPILE_DEFINITIONS(${SQPAMDA_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES")
81 TARGET_COMPILE_DEFINITIONS(${SQPAMDA_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES")
81 ENDIF()
82 ENDIF()
82
83
83 # Set the variable to parent scope so that the other projects can copy the
84 # Set the variable to parent scope so that the other projects can copy the
84 # dependent shared libraries
85 # dependent shared libraries
85 SCIQLOP_SET_TO_PARENT_SCOPE(SQPAMDA_LIBRARY_NAME)
86 SCIQLOP_SET_TO_PARENT_SCOPE(SQPAMDA_LIBRARY_NAME)
86
87
87 # Copy extern shared libraries to the lib folder
88 # Copy extern shared libraries to the lib folder
88 SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPAMDA_LIBRARY_NAME} ${EXTERN_SHARED_LIBRARIES})
89 SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPAMDA_LIBRARY_NAME} ${EXTERN_SHARED_LIBRARIES})
89
90
90 # Add the files to the list of files to be analyzed
91 # Add the files to the list of files to be analyzed
91 LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES})
92 LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES})
92 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES)
93 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES)
93 # Vera++ exclusion files
94 # Vera++ exclusion files
94 #LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt)
95 #LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt)
95 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES)
96 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES)
96
97
97 #
98 #
98 # Compile the tests
99 # Compile the tests
99 #
100 #
100 IF(BUILD_TESTS)
101 IF(BUILD_TESTS)
101 INCLUDE_DIRECTORIES(${SOURCES_DIR})
102 INCLUDE_DIRECTORIES(${SOURCES_DIR})
102 FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp)
103 FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp)
103 FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h)
104 FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h)
104 SET( TEST_LIBRARIES ${SQPAMDA_LIBRARY_NAME})
105 SET( TEST_LIBRARIES ${SQPAMDA_LIBRARY_NAME})
105
106
106 FOREACH( testFile ${TESTS_SOURCES} )
107 FOREACH( testFile ${TESTS_SOURCES} )
107 GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY )
108 GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY )
108 GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE )
109 GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE )
109
110
110 # Add to the list of sources files all the sources in the same
111 # Add to the list of sources files all the sources in the same
111 # directory that aren't another test
112 # directory that aren't another test
112 FILE (GLOB currentTestSources
113 FILE (GLOB currentTestSources
113 ${testDirectory}/*.c
114 ${testDirectory}/*.c
114 ${testDirectory}/*.cpp
115 ${testDirectory}/*.cpp
115 ${testDirectory}/*.h)
116 ${testDirectory}/*.h)
116 LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES})
117 LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES})
117 # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS})
118 # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS})
118
119
119 ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources})
120 ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources})
120 set_property(TARGET ${testName} PROPERTY CXX_STANDARD 14)
121 set_property(TARGET ${testName} PROPERTY CXX_STANDARD 14)
121 set_property(TARGET ${testName} PROPERTY CXX_STANDARD_REQUIRED ON)
122 set_property(TARGET ${testName} PROPERTY CXX_STANDARD_REQUIRED ON)
122 TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} )
123 TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} )
123 qt5_use_modules(${testName} Test)
124 qt5_use_modules(${testName} Test)
124
125
125 ADD_TEST( NAME ${testName} COMMAND ${testName} )
126 ADD_TEST( NAME ${testName} COMMAND ${testName} )
126
127
127 SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES})
128 SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES})
128 ENDFOREACH( testFile )
129 ENDFOREACH( testFile )
129
130
130 LIST(APPEND testFilesToFormat ${TESTS_SOURCES})
131 LIST(APPEND testFilesToFormat ${TESTS_SOURCES})
131 LIST(APPEND testFilesToFormat ${TESTS_HEADERS})
132 LIST(APPEND testFilesToFormat ${TESTS_HEADERS})
132 LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat})
133 LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat})
133 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
134 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
135
136 ADD_DEFINITIONS(-DAMDA_TESTS_RESOURCES_DIR="${TESTS_RESOURCES_DIR}")
134 ENDIF(BUILD_TESTS)
137 ENDIF(BUILD_TESTS)
135
138
136 #
139 #
137 # Set the files that must be formatted by clang-format.
140 # Set the files that must be formatted by clang-format.
138 #
141 #
139 LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES})
142 LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES})
140 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
143 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
141
144
142 #
145 #
143 # Set the directories that doxygen must browse to generate the
146 # Set the directories that doxygen must browse to generate the
144 # documentation.
147 # documentation.
145 #
148 #
146 # Source directories:
149 # Source directories:
147 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs")
150 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs")
148 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
151 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
149 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS)
152 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS)
150 # Source directories to exclude from the documentation generation
153 # Source directories to exclude from the documentation generation
151 #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*")
154 #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*")
152 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS)
155 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS)
153
156
154 #
157 #
155 # Set the directories with the sources to analyze and propagate the
158 # Set the directories with the sources to analyze and propagate the
156 # modification to the parent scope
159 # modification to the parent scope
157 #
160 #
158 # Source directories to analyze:
161 # Source directories to analyze:
159 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
162 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
160 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
163 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
161 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS)
164 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS)
162 # Source directories to exclude from the analysis
165 # Source directories to exclude from the analysis
163 #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir")
166 #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir")
164 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS)
167 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS)
General Comments 0
You need to be logged in to leave comments. Login now