Skip to content
Snippets Groups Projects
Commit d8d8a8e0 authored by Martin Killenberg's avatar Martin Killenberg
Browse files

testing some error handling (do we need it if we validate?)

parent 99e8f557
No related branches found
No related tags found
No related merge requests found
......@@ -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()+"'");
}
}
......
......@@ -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;
}
}
<?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>
<?xml version="1.0" encoding="UTF-8"?>
<device_server xmlns="https://github.com/ChimeraTK/ControlSystemAdapter-DoocsAdapter">
<location name="DIRECT">
<unknownNode/>
</location>
</device_server>
<?xml version="1.0" encoding="UTF-8"?>
<device_server xmlns="https://github.com/ChimeraTK/ControlSystemAdapter-DoocsAdapter">
<unknownNode/>
</device_server>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment