From 03a222e9266380b6ef4d5297591609971e0989a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 15 Feb 2018 21:01:34 +0100 Subject: [PATCH] Platform: Improve testability of platform file loading --- lib/platform.cpp | 7 ++++++- lib/platform.h | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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.