Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log error when default profiles xml loads with error + unittest [5596] #556

Merged
merged 4 commits into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 3 additions & 1 deletion src/cpp/xmlparser/XMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2540,8 +2540,10 @@ 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()))
tinyxml2::XMLError load_error = xmlDoc.LoadFile(filename.c_str());
if (tinyxml2::XMLError::XML_SUCCESS != load_error)
EduPonz marked this conversation as resolved.
Show resolved Hide resolved
{
logError(XMLPARSER, "Error loading '" << filename << "'. Error code: " << load_error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you could add more info here and say that next we'll try to load the default profile

if (filename != std::string(DEFAULT_FASTRTPS_PROFILES))
logError(XMLPARSER, "Error opening '" << filename << "'");

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