##// 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"
@@ -4,6 +4,7 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})
@@ -131,6 +132,8 IF(BUILD_TESTS)
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 #
General Comments 0
You need to be logged in to leave comments. Login now