diff --git a/src/VariableMapper.cc b/src/VariableMapper.cc index ee03b4f6076b110823e834c4d51a7bce32436772..e145b239c7edadff0d45e1129e924dd986e19f0d 100644 --- a/src/VariableMapper.cc +++ b/src/VariableMapper.cc @@ -108,20 +108,19 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0) void VariableMapper::processLocation(xmlpp::Node const * locationNode){ const xmlpp::Element* location = dynamic_cast<const xmlpp::Element*>(locationNode); - std::string name = location->get_attribute("name")->get_value(); + std::string locationName = location->get_attribute("name")->get_value(); - std::cout << "Found location: " << name << std::endl; + std::cout << "Found location: " << locationName << std::endl; for (auto const & node : location->get_children()){ if (nodeIsWhitespace(node)) continue; if (node->get_name() == "property"){ - processProperty(node, name); + processProperty(node, locationName); }else if (node->get_name() == "import"){ - processLocationImport(node, name); + processLocationImport(node, locationName); }else{ - std::cout << "FIXME: Implement location node '" << node->get_name() - << "'! Current implementation does nothing" << std::endl; + throw std::invalid_argument(std::string("Error parsing xml file in location ") + locationName + ": Unknown node '"+node->get_name()+"'"); } } } @@ -253,8 +252,7 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0) }else if (mainNode->get_name() == "import"){ processGlobalImport(mainNode); }else{ - std::cout << "FIXME: Implement main node '" << mainNode->get_name() - << "'! Current implementation does nothing" << std::endl; + throw std::invalid_argument(std::string("Error parsing xml file ") + xmlFile + ": Unknown node '"+mainNode->get_name()+"'"); } } diff --git a/tests/src/testVariableMapper.cpp b/tests/src/testVariableMapper.cpp index ffa395e9876d2f8aefec3fba0e28e9de3475db6f..55c66defe8c8bbee9513a403ac78ede6accd91a0 100644 --- a/tests/src/testVariableMapper.cpp +++ b/tests/src/testVariableMapper.cpp @@ -65,8 +65,8 @@ template <typename Map> bool mapCompare (Map const &lhs, Map const &rhs) { // No predicate needed because there is operator== for pairs already. if ( lhs.size() != rhs.size() ){ - std::cout << "Map size comparison failed: lhs.size() " << lhs.size() << ", rhs.size() " << rhs.size() << std::endl; - return false; + std::cout << "Map size comparison failed: lhs.size() " << lhs.size() << ", rhs.size() " << rhs.size() << std::endl;// LCOV_EXCL_LINE + return false;// LCOV_EXCL_LINE } return std::equal(lhs.begin(), lhs.end(), rhs.begin()); } @@ -116,8 +116,13 @@ BOOST_AUTO_TEST_CASE( testImportAll ){ } BOOST_AUTO_TEST_CASE( testImportTooShort ){ - BOOST_CHECK_THROW(testXmlParsing("variableTreeXml/globalImportPartTooShort.xml", {}), - std::logic_error); + try{ + testXmlParsing("variableTreeXml/globalImportPartTooShort.xml", {}); + BOOST_ERROR("testImportTooShort did not throw as expected.");// LCOV_EXCL_LINE + }catch(std::logic_error & e){ + std::cout << "For manually checking the exception message for too short tree depth:\n" + << e.what() << std::endl; + } } BOOST_AUTO_TEST_CASE( testGlobalImportPart ){ @@ -140,3 +145,33 @@ BOOST_AUTO_TEST_CASE( testCherryPicking ){ {"/DIRECT/INT", {"DIRECT","INT"}} }); } + +BOOST_AUTO_TEST_CASE( testDuplicateSource ){ + try{ + testXmlParsing("variableTreeXml/duplicateSource.xml", {}); + BOOST_ERROR("testDuplicateSource did not throw as expected"); // LCOV_EXCL_LINE + }catch(std::logic_error & e){ + std::cout << "For manually checking the exception message for duplicate sources:\n" + << e.what() << std::endl; + } +} + +BOOST_AUTO_TEST_CASE( testUnknownMainNode ){ + try{ + testXmlParsing("variableTreeXml/unknownMainNode.xml", {}); + BOOST_ERROR("testUnknownMainNode did not throw as expected"); // LCOV_EXCL_LINE + }catch(std::logic_error & e){ + std::cout << "For manually checking the exception message for unknown main node:\n" + << e.what() << std::endl; + } +} + +BOOST_AUTO_TEST_CASE( testUnkownLocationNode ){ + try{ + testXmlParsing("variableTreeXml/unknownLocationNode.xml", {}); + BOOST_ERROR("testUnknownLocationNode did not throw as expected"); // LCOV_EXCL_LINE + }catch(std::logic_error & e){ + std::cout << "For manually checking the exception message for unknown location node:\n" + << e.what() << std::endl; + } +} diff --git a/tests/variableTreeXml/duplicateSource.xml b/tests/variableTreeXml/duplicateSource.xml new file mode 100644 index 0000000000000000000000000000000000000000..662adce8ed2b06dc8c12bc889050cc2e18dff6c4 --- /dev/null +++ b/tests/variableTreeXml/duplicateSource.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<device_server xmlns="https://github.com/ChimeraTK/ControlSystemAdapter-DoocsAdapter"> + <location name="DIRECT"> + <property source="/A/b/do" name="LOLO"/> + </location> + <location name="GRR"> + <property source="/A/b/do" name="JOHO"/> + </location> +</device_server> diff --git a/tests/variableTreeXml/unknownLocationNode.xml b/tests/variableTreeXml/unknownLocationNode.xml new file mode 100644 index 0000000000000000000000000000000000000000..51f1b52973fb31a8e7f2e8362743d90f738c2c99 --- /dev/null +++ b/tests/variableTreeXml/unknownLocationNode.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<device_server xmlns="https://github.com/ChimeraTK/ControlSystemAdapter-DoocsAdapter"> + <location name="DIRECT"> + <unknownNode/> + </location> +</device_server> diff --git a/tests/variableTreeXml/unknownMainNode.xml b/tests/variableTreeXml/unknownMainNode.xml new file mode 100644 index 0000000000000000000000000000000000000000..2ad157afeaf7699491895e20c85535838442547e --- /dev/null +++ b/tests/variableTreeXml/unknownMainNode.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<device_server xmlns="https://github.com/ChimeraTK/ControlSystemAdapter-DoocsAdapter"> + <unknownNode/> +</device_server>