@@ -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 | 1 | ## amda - CMakeLists.txt |
|
2 | 2 | STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX) |
|
3 | 3 | SET(SQPAMDA_LIBRARY_NAME "${LIBRARY_PREFFIX}_amda${DEBUG_SUFFIX}") |
|
4 | 4 | SET(SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src") |
|
5 | 5 | SET(INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") |
|
6 | 6 | SET(RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources") |
|
7 | SET(TESTS_RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests-resources") | |
|
7 | 8 | |
|
8 | 9 | # Include amda directory |
|
9 | 10 | INCLUDE_DIRECTORIES(${INCLUDES_DIR}) |
|
10 | 11 | INCLUDE_DIRECTORIES(${RESOURCES_DIR}) |
|
11 | 12 | |
|
12 | 13 | # |
|
13 | 14 | # Find Qt modules |
|
14 | 15 | # |
|
15 | 16 | SCIQLOP_FIND_QT(Core Widgets) |
|
16 | 17 | |
|
17 | 18 | # |
|
18 | 19 | # Find dependent libraries |
|
19 | 20 | # ======================== |
|
20 | 21 | |
|
21 | 22 | # sciqlop plugin |
|
22 | 23 | find_package(sciqlop-plugin) |
|
23 | 24 | INCLUDE_DIRECTORIES(${SCIQLOP-PLUGIN_INCLUDE_DIR}) |
|
24 | 25 | |
|
25 | 26 | # sciqlop core |
|
26 | 27 | find_package(sciqlop-core) |
|
27 | 28 | INCLUDE_DIRECTORIES(${SCIQLOP-CORE_INCLUDE_DIR}) |
|
28 | 29 | list(APPEND LIBRARIES ${SCIQLOP-CORE_LIBRARIES}) |
|
29 | 30 | |
|
30 | 31 | # sciqlop gui |
|
31 | 32 | find_package(sciqlop-gui) |
|
32 | 33 | INCLUDE_DIRECTORIES(${SCIQLOP-GUI_INCLUDE_DIR}) |
|
33 | 34 | list(APPEND LIBRARIES ${SCIQLOP-GUI_LIBRARIES}) |
|
34 | 35 | |
|
35 | 36 | # Description file |
|
36 | 37 | FILE (GLOB_RECURSE PLUGIN_FILE ${RESOURCES_DIR}/amda.json) |
|
37 | 38 | |
|
38 | 39 | # Resources files |
|
39 | 40 | FILE (GLOB_RECURSE PROJECT_RESOURCES ${RESOURCES_DIR}/*.qrc) |
|
40 | 41 | |
|
41 | 42 | # |
|
42 | 43 | # Compile the library |
|
43 | 44 | # |
|
44 | 45 | |
|
45 | 46 | ADD_DEFINITIONS(-DAMDA_LIB) |
|
46 | 47 | |
|
47 | 48 | FILE (GLOB_RECURSE MODULE_SOURCES |
|
48 | 49 | ${INCLUDES_DIR}/*.h |
|
49 | 50 | ${SOURCES_DIR}/*.c |
|
50 | 51 | ${SOURCES_DIR}/*.cpp |
|
51 | 52 | ${SOURCES_DIR}/*.h |
|
52 | 53 | ${PLUGIN_FILE}) |
|
53 | 54 | |
|
54 | 55 | QT5_ADD_RESOURCES(RCC_AMDA |
|
55 | 56 | ${PROJECT_RESOURCES} |
|
56 | 57 | ) |
|
57 | 58 | |
|
58 | 59 | ADD_LIBRARY(${SQPAMDA_LIBRARY_NAME} ${MODULE_SOURCES} ${RCC_AMDA}) |
|
59 | 60 | set_property(TARGET ${SQPAMDA_LIBRARY_NAME} PROPERTY CXX_STANDARD 14) |
|
60 | 61 | set_property(TARGET ${SQPAMDA_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) |
|
61 | 62 | |
|
62 | 63 | INSTALL(TARGETS ${SQPAMDA_LIBRARY_NAME} |
|
63 | 64 | RUNTIME DESTINATION ${INSTALL_BINARY_DIR} |
|
64 | 65 | LIBRARY DESTINATION ${INSTALL_PLUGINS_LIBRARY_DIR} |
|
65 | 66 | ARCHIVE DESTINATION ${INSTALL_PLUGINS_LIBRARY_DIR} |
|
66 | 67 | ) |
|
67 | 68 | |
|
68 | 69 | |
|
69 | 70 | TARGET_LINK_LIBRARIES(${SQPAMDA_LIBRARY_NAME} ${LIBRARIES}) |
|
70 | 71 | qt5_use_modules(${SQPAMDA_LIBRARY_NAME} Core Widgets) |
|
71 | 72 | |
|
72 | 73 | add_dependencies(${SQPAMDA_LIBRARY_NAME} ${SQPPLUGIN_LIBRARY_NAME} ${SQPGUI_LIBRARY_NAME} ${SQPCORE_LIBRARY_NAME}) |
|
73 | 74 | |
|
74 | 75 | # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html |
|
75 | 76 | # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order. |
|
76 | 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 | 78 | IF(BUILD_SHARED_LIBS) |
|
78 | 79 | SET_TARGET_PROPERTIES(${SQPAMDA_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT") |
|
79 | 80 | ELSE() |
|
80 | 81 | TARGET_COMPILE_DEFINITIONS(${SQPAMDA_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES") |
|
81 | 82 | ENDIF() |
|
82 | 83 | |
|
83 | 84 | # Set the variable to parent scope so that the other projects can copy the |
|
84 | 85 | # dependent shared libraries |
|
85 | 86 | SCIQLOP_SET_TO_PARENT_SCOPE(SQPAMDA_LIBRARY_NAME) |
|
86 | 87 | |
|
87 | 88 | # Copy extern shared libraries to the lib folder |
|
88 | 89 | SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPAMDA_LIBRARY_NAME} ${EXTERN_SHARED_LIBRARIES}) |
|
89 | 90 | |
|
90 | 91 | # Add the files to the list of files to be analyzed |
|
91 | 92 | LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES}) |
|
92 | 93 | SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES) |
|
93 | 94 | # Vera++ exclusion files |
|
94 | 95 | #LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt) |
|
95 | 96 | SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES) |
|
96 | 97 | |
|
97 | 98 | # |
|
98 | 99 | # Compile the tests |
|
99 | 100 | # |
|
100 | 101 | IF(BUILD_TESTS) |
|
101 | 102 | INCLUDE_DIRECTORIES(${SOURCES_DIR}) |
|
102 | 103 | FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp) |
|
103 | 104 | FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h) |
|
104 | 105 | SET( TEST_LIBRARIES ${SQPAMDA_LIBRARY_NAME}) |
|
105 | 106 | |
|
106 | 107 | FOREACH( testFile ${TESTS_SOURCES} ) |
|
107 | 108 | GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY ) |
|
108 | 109 | GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE ) |
|
109 | 110 | |
|
110 | 111 | # Add to the list of sources files all the sources in the same |
|
111 | 112 | # directory that aren't another test |
|
112 | 113 | FILE (GLOB currentTestSources |
|
113 | 114 | ${testDirectory}/*.c |
|
114 | 115 | ${testDirectory}/*.cpp |
|
115 | 116 | ${testDirectory}/*.h) |
|
116 | 117 | LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES}) |
|
117 | 118 | # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS}) |
|
118 | 119 | |
|
119 | 120 | ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources}) |
|
120 | 121 | set_property(TARGET ${testName} PROPERTY CXX_STANDARD 14) |
|
121 | 122 | set_property(TARGET ${testName} PROPERTY CXX_STANDARD_REQUIRED ON) |
|
122 | 123 | TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} ) |
|
123 | 124 | qt5_use_modules(${testName} Test) |
|
124 | 125 | |
|
125 | 126 | ADD_TEST( NAME ${testName} COMMAND ${testName} ) |
|
126 | 127 | |
|
127 | 128 | SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES}) |
|
128 | 129 | ENDFOREACH( testFile ) |
|
129 | 130 | |
|
130 | 131 | LIST(APPEND testFilesToFormat ${TESTS_SOURCES}) |
|
131 | 132 | LIST(APPEND testFilesToFormat ${TESTS_HEADERS}) |
|
132 | 133 | LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat}) |
|
133 | 134 | SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES) |
|
135 | ||
|
136 | ADD_DEFINITIONS(-DAMDA_TESTS_RESOURCES_DIR="${TESTS_RESOURCES_DIR}") | |
|
134 | 137 | ENDIF(BUILD_TESTS) |
|
135 | 138 | |
|
136 | 139 | # |
|
137 | 140 | # Set the files that must be formatted by clang-format. |
|
138 | 141 | # |
|
139 | 142 | LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES}) |
|
140 | 143 | SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES) |
|
141 | 144 | |
|
142 | 145 | # |
|
143 | 146 | # Set the directories that doxygen must browse to generate the |
|
144 | 147 | # documentation. |
|
145 | 148 | # |
|
146 | 149 | # Source directories: |
|
147 | 150 | LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs") |
|
148 | 151 | LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src") |
|
149 | 152 | SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS) |
|
150 | 153 | # Source directories to exclude from the documentation generation |
|
151 | 154 | #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*") |
|
152 | 155 | SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS) |
|
153 | 156 | |
|
154 | 157 | # |
|
155 | 158 | # Set the directories with the sources to analyze and propagate the |
|
156 | 159 | # modification to the parent scope |
|
157 | 160 | # |
|
158 | 161 | # Source directories to analyze: |
|
159 | 162 | LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src") |
|
160 | 163 | LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests") |
|
161 | 164 | SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS) |
|
162 | 165 | # Source directories to exclude from the analysis |
|
163 | 166 | #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir") |
|
164 | 167 | SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS) |
General Comments 0
You need to be logged in to leave comments.
Login now