diff --git a/lib/platform.cpp b/lib/platform.cpp index 13f58a916..33dc1a38e 100644 --- a/lib/platform.cpp +++ b/lib/platform.cpp @@ -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; diff --git a/lib/platform.h b/lib/platform.h index 42707cf37..b84422552 100644 --- a/lib/platform.h +++ b/lib/platform.h @@ -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.