##// END OF EJS Templates
Makes test cases
Alexandre Leroux -
r359:751f52f38d58
parent child
Show More
@@ -0,0 +1,4
1 "data": [
2 "root1": "root",
3 "root2": "root"
4 ] No newline at end of file
@@ -0,0 +1,63
1 {
2 "dataCenter": {
3 "name": "AMDA",
4 "desc": "AMDA_Internal_Data_Base",
5 "xml:id": "myLocalData-treeRootNode",
6 "mission": {
7 "att": "",
8 "name": "ICE@Giacobini-Zinner",
9 "rank": "93",
10 "xml:id": "ICE@Giacobini-Zinner",
11 "desc": "International Cometary Explorer",
12 "target": "Comet",
13 "available": "1",
14 "instrument": {
15 "att": "",
16 "name": "MAG",
17 "xml:id": "ICE@Giacobini-Zinner:MAG",
18 "desc": "Vector Helium Magnetometer",
19 "restricted": "",
20 "dataset": {
21 "att": "",
22 "restricted": "",
23 "name": "Magnetic Field",
24 "xml:id": "ice:mag:p21",
25 "sampling": "0.3s",
26 "maxSampling": "",
27 "dataStart": "1985/09/10",
28 "dataStop": "1985/09/14",
29 "dataSource": "PDS",
30 "target": "",
31 "parameter": [
32 {
33 "name": "B_cse",
34 "units": "nT",
35 "display_type": "",
36 "xml:id": "ice_b_cse",
37 "component": [
38 {
39 "name": "Bx",
40 "xml:id": "ice_b_cse(0)"
41 },
42 {
43 "name": "By",
44 "xml:id": "ice_b_cse(1)"
45 },
46 {
47 "name": "Bz",
48 "xml:id": "ice_b_cse(2)"
49 }
50 ]
51 },
52 {
53 "name": "|B|",
54 "display_type": "",
55 "units": "nT",
56 "xml:id": "ice_b_tot"
57 }
58 ]
59 }
60 }
61 }
62 }
63 } No newline at end of file
@@ -0,0 +1,5
1 {
2 "wrongRoot": {
3 "name": "AMDA"
4 }
5 } No newline at end of file
@@ -0,0 +1,3
1 {
2 "dataCenter": "invalidType"
3 } No newline at end of file
@@ -31,6 +31,83 struct ExpectedResults {
31 std::shared_ptr<DataSourceItem> m_Item{nullptr};
31 std::shared_ptr<DataSourceItem> m_Item{nullptr};
32 };
32 };
33
33
34 // ///////////////////////////////// //
35 // Set of expected results for tests //
36 // ///////////////////////////////// //
37
38 ExpectedResults validResults1()
39 {
40 auto component1 = std::make_unique<DataSourceItem>(
41 DataSourceItemType::COMPONENT,
42 QHash<QString, QVariant>{{"name", "Bx"}, {"xml:id", "ice_b_cse(0)"}});
43 auto component2 = std::make_unique<DataSourceItem>(
44 DataSourceItemType::COMPONENT,
45 QHash<QString, QVariant>{{"name", "By"}, {"xml:id", "ice_b_cse(1)"}});
46 auto component3 = std::make_unique<DataSourceItem>(
47 DataSourceItemType::COMPONENT,
48 QHash<QString, QVariant>{{"name", "Bz"}, {"xml:id", "ice_b_cse(2)"}});
49 auto parameter1 = std::make_unique<DataSourceItem>(
50 DataSourceItemType::PRODUCT,
51 QHash<QString, QVariant>{
52 {"name", "B_cse"}, {"units", "nT"}, {"display_type", ""}, {"xml:id", "ice_b_cse"}});
53 parameter1->appendChild(std::move(component1));
54 parameter1->appendChild(std::move(component2));
55 parameter1->appendChild(std::move(component3));
56
57 auto parameter2 = std::make_unique<DataSourceItem>(
58 DataSourceItemType::PRODUCT,
59 QHash<QString, QVariant>{
60 {"name", "|B|"}, {"units", "nT"}, {"display_type", ""}, {"xml:id", "ice_b_tot"}});
61
62 auto dataset = std::make_unique<DataSourceItem>(
63 DataSourceItemType::NODE, QHash<QString, QVariant>{{"att", ""},
64 {"restricted", ""},
65 {"name", "Magnetic Field"},
66 {"xml:id", "ice:mag:p21"},
67 {"sampling", "0.3s"},
68 {"maxSampling", ""},
69 {"dataStart", "1985/09/10"},
70 {"dataStop", "1985/09/14"},
71 {"dataSource", "PDS"},
72 {"target", ""}});
73 dataset->appendChild(std::move(parameter1));
74 dataset->appendChild(std::move(parameter2));
75
76 auto instrument = std::make_unique<DataSourceItem>(
77 DataSourceItemType::NODE, QHash<QString, QVariant>{{"att", ""},
78 {"name", "MAG"},
79 {"xml:id", "ICE@Giacobini-Zinner:MAG"},
80 {"desc", "Vector Helium Magnetometer"},
81 {"restricted", ""}});
82 instrument->appendChild(std::move(dataset));
83
84 auto mission = std::make_unique<DataSourceItem>(
85 DataSourceItemType::NODE,
86 QHash<QString, QVariant>{{"att", ""},
87 {"name", "ICE@Giacobini-Zinner"},
88 {"rank", "93"},
89 {"xml:id", "ICE@Giacobini-Zinner"},
90 {"desc", "International Cometary Explorer"},
91 {"target", "Comet"},
92 {"available", "1"}});
93 mission->appendChild(std::move(instrument));
94
95 auto item = std::make_shared<DataSourceItem>(DataSourceItemType::NODE,
96 QHash<QString, QVariant>{
97 {"name", "AMDA"},
98 {"desc", "AMDA_Internal_Data_Base"},
99 {"xml:id", "myLocalData-treeRootNode"},
100 });
101 item->appendChild(std::move(mission));
102
103 return ExpectedResults{item};
104 }
105
106 ExpectedResults invalidResults()
107 {
108 return ExpectedResults{};
109 }
110
34 } // namespace
111 } // namespace
35
112
36 Q_DECLARE_METATYPE(ExpectedResults)
113 Q_DECLARE_METATYPE(ExpectedResults)
@@ -56,6 +133,23 void TestAmdaParser::testReadJson_data()
56 QTest::addColumn<QString>("inputFileName");
133 QTest::addColumn<QString>("inputFileName");
57 // Expected results
134 // Expected results
58 QTest::addColumn<ExpectedResults>("expectedResults");
135 QTest::addColumn<ExpectedResults>("expectedResults");
136
137 // ////////// //
138 // Test cases //
139 // ////////// //
140
141 // Valid file
142 QTest::newRow("Valid file") << QStringLiteral("ValidFile1.json") << validResults1();
143
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();
59 }
153 }
60
154
61 void TestAmdaParser::testReadJson()
155 void TestAmdaParser::testReadJson()
General Comments 0
You need to be logged in to leave comments. Login now