Platform: Improve testability of platform file loading

This commit is contained in:
Daniel Marjamäki 2018-02-15 21:01:34 +01:00
parent 0f00259a96
commit 03a222e926
2 changed files with 13 additions and 1 deletions

View File

@ -183,7 +183,12 @@ bool cppcheck::Platform::platformFile(const char exename[], const std::string &f
return false;
}
const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement();
return loadFromXmlDocument(&doc);
}
bool cppcheck::Platform::loadFromXmlDocument(const tinyxml2::XMLDocument *doc)
{
const tinyxml2::XMLElement * const rootnode = doc->FirstChildElement();
if (!rootnode || std::strcmp(rootnode->Name(), "platform") != 0)
return false;

View File

@ -28,6 +28,10 @@
/// @addtogroup Core
/// @{
namespace tinyxml2 {
class XMLDocument;
}
namespace cppcheck {
/**
@ -99,6 +103,9 @@ namespace cppcheck {
/** set the platform type for user specified platforms */
bool platformFile(const char exename[], const std::string &filename);
/** load platform from xml document, primarily for testing */
bool loadFromXmlDocument(const tinyxml2::XMLDocument *doc);
/**
* @brief Returns true if platform type is Windows
* @return true if Windows platform type.