Skip to content

Commit

Permalink
Log error when default profiles xml loads with error + unittest [5596] (
Browse files Browse the repository at this point in the history
#556)

* Log error when default profiles xml loads with error + unittest

* More verbose error

* log opening error also when the file is DEFAULT_FASTRTPS_PROFILES

* combine xml loading and error checking
  • Loading branch information
EduPonz authored and raquelalvarezbanos committed Jun 18, 2019
1 parent 4f331c8 commit cccb13f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ Session.vim
.netrwhist
*~

### VisualStudio Code ###
*.vscode

### VisualStudio ###
## Ignore Visual Studio temporary files, build results, and
Expand Down
4 changes: 1 addition & 3 deletions src/cpp/xmlparser/XMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2542,9 +2542,7 @@ XMLP_ret XMLParser::loadXML(const std::string& filename, up_base_node_t& root)
tinyxml2::XMLDocument xmlDoc;
if (tinyxml2::XMLError::XML_SUCCESS != xmlDoc.LoadFile(filename.c_str()))
{
if (filename != std::string(DEFAULT_FASTRTPS_PROFILES))
logError(XMLPARSER, "Error opening '" << filename << "'");

logError(XMLPARSER, "Error opening '" << filename << "'");
return XMLP_ret::XML_ERROR;
}

Expand Down
8 changes: 8 additions & 0 deletions test/unittest/xmlparser/XMLParserTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ TEST_F(XMLParserTests, NoFIle)
ASSERT_EQ(XMLParser::loadXML("missing_file.xml", root), XMLP_ret::XML_ERROR);
}

TEST_F(XMLParserTests, EmptyDefaultFile)
{
std::ifstream inFile;
inFile.open("DEFAULT_FASTRTPS_PROFILES.xml");
std::unique_ptr<BaseNode> root;
ASSERT_EQ(XMLParser::loadDefaultXMLFile(root), XMLP_ret::XML_ERROR);
}

TEST_F(XMLParserTests, EmptyString)
{
std::ifstream inFile;
Expand Down

0 comments on commit cccb13f

Please sign in to comment.