From 751f52f38d58b4bc8b7492bdff5697ab76578eac 2017-07-05 09:39:09 From: Alexandre Leroux Date: 2017-07-05 09:39:09 Subject: [PATCH] Makes test cases --- diff --git a/plugins/amda/tests-resources/TestAmdaParser/TwoRootsFile.json b/plugins/amda/tests-resources/TestAmdaParser/TwoRootsFile.json new file mode 100644 index 0000000..1bb3d62 --- /dev/null +++ b/plugins/amda/tests-resources/TestAmdaParser/TwoRootsFile.json @@ -0,0 +1,4 @@ +"data": [ + "root1": "root", + "root2": "root" +] \ No newline at end of file diff --git a/plugins/amda/tests-resources/TestAmdaParser/ValidFile1.json b/plugins/amda/tests-resources/TestAmdaParser/ValidFile1.json new file mode 100644 index 0000000..c682403 --- /dev/null +++ b/plugins/amda/tests-resources/TestAmdaParser/ValidFile1.json @@ -0,0 +1,63 @@ +{ + "dataCenter": { + "name": "AMDA", + "desc": "AMDA_Internal_Data_Base", + "xml:id": "myLocalData-treeRootNode", + "mission": { + "att": "", + "name": "ICE@Giacobini-Zinner", + "rank": "93", + "xml:id": "ICE@Giacobini-Zinner", + "desc": "International Cometary Explorer", + "target": "Comet", + "available": "1", + "instrument": { + "att": "", + "name": "MAG", + "xml:id": "ICE@Giacobini-Zinner:MAG", + "desc": "Vector Helium Magnetometer", + "restricted": "", + "dataset": { + "att": "", + "restricted": "", + "name": "Magnetic Field", + "xml:id": "ice:mag:p21", + "sampling": "0.3s", + "maxSampling": "", + "dataStart": "1985/09/10", + "dataStop": "1985/09/14", + "dataSource": "PDS", + "target": "", + "parameter": [ + { + "name": "B_cse", + "units": "nT", + "display_type": "", + "xml:id": "ice_b_cse", + "component": [ + { + "name": "Bx", + "xml:id": "ice_b_cse(0)" + }, + { + "name": "By", + "xml:id": "ice_b_cse(1)" + }, + { + "name": "Bz", + "xml:id": "ice_b_cse(2)" + } + ] + }, + { + "name": "|B|", + "display_type": "", + "units": "nT", + "xml:id": "ice_b_tot" + } + ] + } + } + } + } +} \ No newline at end of file diff --git a/plugins/amda/tests-resources/TestAmdaParser/WrongRootKey.json b/plugins/amda/tests-resources/TestAmdaParser/WrongRootKey.json new file mode 100644 index 0000000..a141f29 --- /dev/null +++ b/plugins/amda/tests-resources/TestAmdaParser/WrongRootKey.json @@ -0,0 +1,5 @@ +{ + "wrongRoot": { + "name": "AMDA" + } +} \ No newline at end of file diff --git a/plugins/amda/tests-resources/TestAmdaParser/WrongRootType.json b/plugins/amda/tests-resources/TestAmdaParser/WrongRootType.json new file mode 100644 index 0000000..716d74a --- /dev/null +++ b/plugins/amda/tests-resources/TestAmdaParser/WrongRootType.json @@ -0,0 +1,3 @@ +{ + "dataCenter": "invalidType" +} \ No newline at end of file diff --git a/plugins/amda/tests/TestAmdaParser.cpp b/plugins/amda/tests/TestAmdaParser.cpp index b1c37a1..e2023f9 100644 --- a/plugins/amda/tests/TestAmdaParser.cpp +++ b/plugins/amda/tests/TestAmdaParser.cpp @@ -31,6 +31,83 @@ struct ExpectedResults { std::shared_ptr m_Item{nullptr}; }; +// ///////////////////////////////// // +// Set of expected results for tests // +// ///////////////////////////////// // + +ExpectedResults validResults1() +{ + auto component1 = std::make_unique( + DataSourceItemType::COMPONENT, + QHash{{"name", "Bx"}, {"xml:id", "ice_b_cse(0)"}}); + auto component2 = std::make_unique( + DataSourceItemType::COMPONENT, + QHash{{"name", "By"}, {"xml:id", "ice_b_cse(1)"}}); + auto component3 = std::make_unique( + DataSourceItemType::COMPONENT, + QHash{{"name", "Bz"}, {"xml:id", "ice_b_cse(2)"}}); + auto parameter1 = std::make_unique( + DataSourceItemType::PRODUCT, + QHash{ + {"name", "B_cse"}, {"units", "nT"}, {"display_type", ""}, {"xml:id", "ice_b_cse"}}); + parameter1->appendChild(std::move(component1)); + parameter1->appendChild(std::move(component2)); + parameter1->appendChild(std::move(component3)); + + auto parameter2 = std::make_unique( + DataSourceItemType::PRODUCT, + QHash{ + {"name", "|B|"}, {"units", "nT"}, {"display_type", ""}, {"xml:id", "ice_b_tot"}}); + + auto dataset = std::make_unique( + DataSourceItemType::NODE, QHash{{"att", ""}, + {"restricted", ""}, + {"name", "Magnetic Field"}, + {"xml:id", "ice:mag:p21"}, + {"sampling", "0.3s"}, + {"maxSampling", ""}, + {"dataStart", "1985/09/10"}, + {"dataStop", "1985/09/14"}, + {"dataSource", "PDS"}, + {"target", ""}}); + dataset->appendChild(std::move(parameter1)); + dataset->appendChild(std::move(parameter2)); + + auto instrument = std::make_unique( + DataSourceItemType::NODE, QHash{{"att", ""}, + {"name", "MAG"}, + {"xml:id", "ICE@Giacobini-Zinner:MAG"}, + {"desc", "Vector Helium Magnetometer"}, + {"restricted", ""}}); + instrument->appendChild(std::move(dataset)); + + auto mission = std::make_unique( + DataSourceItemType::NODE, + QHash{{"att", ""}, + {"name", "ICE@Giacobini-Zinner"}, + {"rank", "93"}, + {"xml:id", "ICE@Giacobini-Zinner"}, + {"desc", "International Cometary Explorer"}, + {"target", "Comet"}, + {"available", "1"}}); + mission->appendChild(std::move(instrument)); + + auto item = std::make_shared(DataSourceItemType::NODE, + QHash{ + {"name", "AMDA"}, + {"desc", "AMDA_Internal_Data_Base"}, + {"xml:id", "myLocalData-treeRootNode"}, + }); + item->appendChild(std::move(mission)); + + return ExpectedResults{item}; +} + +ExpectedResults invalidResults() +{ + return ExpectedResults{}; +} + } // namespace Q_DECLARE_METATYPE(ExpectedResults) @@ -56,6 +133,23 @@ void TestAmdaParser::testReadJson_data() QTest::addColumn("inputFileName"); // Expected results QTest::addColumn("expectedResults"); + + // ////////// // + // Test cases // + // ////////// // + + // Valid file + QTest::newRow("Valid file") << QStringLiteral("ValidFile1.json") << validResults1(); + + // Invalid files + QTest::newRow("Invalid file (unexisting file)") + << QStringLiteral("UnexistingFile.json") << invalidResults(); + QTest::newRow("Invalid file (two root objects)") + << QStringLiteral("TwoRootsFile.json") << invalidResults(); + QTest::newRow("Invalid file (wrong root key)") + << QStringLiteral("WrongRootKey.json") << invalidResults(); + QTest::newRow("Invalid file (wrong root type)") + << QStringLiteral("WrongRootType.json") << invalidResults(); } void TestAmdaParser::testReadJson()