##// END OF EJS Templates
correction clang format
perrinel -
r342:df6a5b97d490
parent child
Show More
@@ -1,176 +1,176
1 1 #include "AmdaParser.h"
2 2
3 3 #include <DataSource/DataSourceItem.h>
4 4
5 5 #include <QObject>
6 6 #include <QtTest>
7 7
8 8 #include <QString>
9 9
10 10 namespace {
11 11
12 12 /// Path for the tests
13 13 const auto TESTS_RESOURCES_PATH
14 14 = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaParser"}.absoluteFilePath();
15 15
16 16 QString inputFilePath(const QString &inputFileName)
17 17 {
18 18 return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath();
19 19 }
20 20
21 21 struct ExpectedResults {
22 22 explicit ExpectedResults() = default;
23 23 explicit ExpectedResults(std::shared_ptr<DataSourceItem> item)
24 24 : m_ParsingOK{true}, m_Item{std::move(item)}
25 25 {
26 26 }
27 27
28 28 // Parsing was successfully completed
29 29 bool m_ParsingOK{false};
30 30 // Expected item after parsing
31 31 std::shared_ptr<DataSourceItem> m_Item{nullptr};
32 32 };
33 33
34 34 // ///////////////////////////////// //
35 35 // Set of expected results for tests //
36 36 // ///////////////////////////////// //
37 37
38 38 ExpectedResults validResults1()
39 39 {
40 40 auto component1 = std::make_unique<DataSourceItem>(
41 41 DataSourceItemType::COMPONENT,
42 42 QHash<QString, QVariant>{{"name", "Bx"}, {"xml:id", "ice_b_cse(0)"}});
43 43 auto component2 = std::make_unique<DataSourceItem>(
44 44 DataSourceItemType::COMPONENT,
45 45 QHash<QString, QVariant>{{"name", "By"}, {"xml:id", "ice_b_cse(1)"}});
46 46 auto component3 = std::make_unique<DataSourceItem>(
47 47 DataSourceItemType::COMPONENT,
48 48 QHash<QString, QVariant>{{"name", "Bz"}, {"xml:id", "ice_b_cse(2)"}});
49 49 auto parameter1 = std::make_unique<DataSourceItem>(
50 50 DataSourceItemType::PRODUCT,
51 51 QHash<QString, QVariant>{
52 52 {"name", "B_cse"}, {"units", "nT"}, {"display_type", ""}, {"xml:id", "ice_b_cse"}});
53 53 parameter1->appendChild(std::move(component1));
54 54 parameter1->appendChild(std::move(component2));
55 55 parameter1->appendChild(std::move(component3));
56 56
57 57 auto parameter2 = std::make_unique<DataSourceItem>(
58 58 DataSourceItemType::PRODUCT,
59 59 QHash<QString, QVariant>{
60 60 {"name", "|B|"}, {"units", "nT"}, {"display_type", ""}, {"xml:id", "ice_b_tot"}});
61 61
62 62 auto dataset = std::make_unique<DataSourceItem>(
63 63 DataSourceItemType::NODE, QHash<QString, QVariant>{{"att", ""},
64 64 {"restricted", ""},
65 65 {"name", "Magnetic Field"},
66 66 {"xml:id", "ice:mag:p21"},
67 67 {"sampling", "0.3s"},
68 68 {"maxSampling", ""},
69 69 {"dataStart", "1985/09/10"},
70 70 {"dataStop", "1985/09/14"},
71 71 {"dataSource", "PDS"},
72 72 {"target", ""}});
73 73 dataset->appendChild(std::move(parameter1));
74 74 dataset->appendChild(std::move(parameter2));
75 75
76 76 auto instrument = std::make_unique<DataSourceItem>(
77 77 DataSourceItemType::NODE, QHash<QString, QVariant>{{"att", ""},
78 78 {"name", "MAG"},
79 79 {"xml:id", "ICE@Giacobini-Zinner:MAG"},
80 80 {"desc", "Vector Helium Magnetometer"},
81 81 {"restricted", ""}});
82 82 instrument->appendChild(std::move(dataset));
83 83
84 84 auto mission = std::make_unique<DataSourceItem>(
85 85 DataSourceItemType::NODE,
86 86 QHash<QString, QVariant>{{"att", ""},
87 87 {"name", "ICE@Giacobini-Zinner"},
88 88 {"rank", "93"},
89 89 {"xml:id", "ICE@Giacobini-Zinner"},
90 90 {"desc", "International Cometary Explorer"},
91 91 {"target", "Comet"},
92 92 {"available", "1"}});
93 93 mission->appendChild(std::move(instrument));
94 94
95 95 auto item = std::make_shared<DataSourceItem>(DataSourceItemType::NODE,
96 96 QHash<QString, QVariant>{
97 97 {"name", "AMDA"},
98 98 {"desc", "AMDA_Internal_Data_Base"},
99 99 {"xml:id", "myLocalData-treeRootNode"},
100 100 });
101 101 item->appendChild(std::move(mission));
102 102
103 103 return ExpectedResults{item};
104 104 }
105 105
106 106 ExpectedResults invalidResults()
107 107 {
108 108 return ExpectedResults{};
109 109 }
110 110
111 111 } // namespace
112 112
113 113 Q_DECLARE_METATYPE(ExpectedResults)
114 114
115 115 class TestAmdaParser : public QObject {
116 116 Q_OBJECT
117 117 private slots:
118 118 /// Input test data
119 119 /// @sa testReadJson()
120 120 void testReadJson_data();
121 121
122 122 /// Tests parsing of a JSON file
123 123 void testReadJson();
124 124 };
125 125
126 126 void TestAmdaParser::testReadJson_data()
127 127 {
128 128 // ////////////// //
129 129 // Test structure //
130 130 // ////////////// //
131 131
132 132 // Name of JSON file to read
133 133 QTest::addColumn<QString>("inputFileName");
134 134 // Expected results
135 135 QTest::addColumn<ExpectedResults>("expectedResults");
136 136
137 137 // ////////// //
138 138 // Test cases //
139 139 // ////////// //
140 140
141 141 // Valid file
142 142 QTest::newRow("Valid file") << QStringLiteral("ValidFile1.json") << validResults1();
143 143
144 144 // Invalid files
145 QTest::newRow("Invalid file (unexisting file)")
146 << QStringLiteral("UnexistingFile.json") << invalidResults();
147 QTest::newRow("Invalid file (two root objects)")
148 << QStringLiteral("TwoRootsFile.json") << invalidResults();
149 QTest::newRow("Invalid file (wrong root key)")
150 << QStringLiteral("WrongRootKey.json") << invalidResults();
151 QTest::newRow("Invalid file (wrong root type)")
152 << QStringLiteral("WrongRootType.json") << invalidResults();
145 QTest::newRow("Invalid file (unexisting file)") << QStringLiteral("UnexistingFile.json")
146 << invalidResults();
147 QTest::newRow("Invalid file (two root objects)") << QStringLiteral("TwoRootsFile.json")
148 << invalidResults();
149 QTest::newRow("Invalid file (wrong root key)") << QStringLiteral("WrongRootKey.json")
150 << invalidResults();
151 QTest::newRow("Invalid file (wrong root type)") << QStringLiteral("WrongRootType.json")
152 << invalidResults();
153 153 }
154 154
155 155 void TestAmdaParser::testReadJson()
156 156 {
157 157 QFETCH(QString, inputFileName);
158 158 QFETCH(ExpectedResults, expectedResults);
159 159
160 160 // Parses file
161 161 auto filePath = inputFilePath(inputFileName);
162 162 auto item = AmdaParser::readJson(filePath);
163 163
164 164 // Validates results
165 165 if (expectedResults.m_ParsingOK) {
166 166 QVERIFY(item != nullptr);
167 167 QVERIFY(expectedResults.m_Item != nullptr);
168 168 QVERIFY(*item == *expectedResults.m_Item);
169 169 }
170 170 else {
171 171 QVERIFY(item == nullptr);
172 172 }
173 173 }
174 174
175 175 QTEST_MAIN(TestAmdaParser)
176 176 #include "TestAmdaParser.moc"
General Comments 0
You need to be logged in to leave comments. Login now