diff --git a/lib/platform.h b/lib/platform.h index 94130f9cf24..4673c4859e6 100644 --- a/lib/platform.h +++ b/lib/platform.h @@ -44,7 +44,6 @@ namespace tinyxml2 { * @brief Platform settings */ class CPPCHECKLIB Platform { - friend class TestPlatform; private: static long long min_value(std::uint8_t bit) { assert(bit > 0); @@ -80,6 +79,7 @@ class CPPCHECKLIB Platform { /** provides list of defines specified by the limit.h/climits includes */ std::string getLimitsDefines(bool c99) const; +protected: /** load platform from xml document, primarily for testing */ bool loadFromXmlDocument(const tinyxml2::XMLDocument *doc); public: diff --git a/test/testplatform.cpp b/test/testplatform.cpp index f0c7f6fa596..96fa960a5c3 100644 --- a/test/testplatform.cpp +++ b/test/testplatform.cpp @@ -50,7 +50,12 @@ class TestPlatform : public TestFixture { TEST_CASE(wrong_root_node); } - static bool readPlatform(Platform& platform, const char* xmldata) { + class PlatformTest : public Platform + { + friend class TestPlatform; + }; + + static bool readPlatform(PlatformTest& platform, const char* xmldata) { tinyxml2::XMLDocument doc; return (doc.Parse(xmldata) == tinyxml2::XML_SUCCESS) && platform.loadFromXmlDocument(&doc); } @@ -58,7 +63,7 @@ class TestPlatform : public TestFixture { void empty() const { // An empty platform file does not change values, only the type. constexpr char xmldata[] = "\n"; - Platform platform; + PlatformTest platform; // TODO: this should fail - platform files need to be complete TODO_ASSERT(!readPlatform(platform, xmldata)); } @@ -221,7 +226,7 @@ class TestPlatform : public TestFixture { " 2\n" " \n" " "; - Platform platform; + PlatformTest platform; ASSERT(readPlatform(platform, xmldata)); ASSERT_EQUALS(Platform::Type::File, platform.type); ASSERT(!platform.isWindows()); @@ -265,7 +270,7 @@ class TestPlatform : public TestFixture { " 11\n" " \n" " "; - Platform platform; + PlatformTest platform; ASSERT(readPlatform(platform, xmldata)); ASSERT_EQUALS(Platform::Type::File, platform.type); ASSERT(!platform.isWindows()); @@ -309,7 +314,7 @@ class TestPlatform : public TestFixture { " 11\n" " \n" " "; - Platform platform; + PlatformTest platform; // TODO: needs to fail - files need to be complete TODO_ASSERT(!readPlatform(platform, xmldata)); } @@ -335,7 +340,7 @@ class TestPlatform : public TestFixture { " 0\n" " \n" " "; - Platform platform; + PlatformTest platform; ASSERT(readPlatform(platform, xmldata)); ASSERT_EQUALS(Platform::Type::File, platform.type); ASSERT(!platform.isWindows()); @@ -378,7 +383,7 @@ class TestPlatform : public TestFixture { " 2\n" " \n" " "; - Platform platform; + PlatformTest platform; ASSERT(!readPlatform(platform, xmldata)); } @@ -403,7 +408,7 @@ class TestPlatform : public TestFixture { " \n" " \n" " "; - Platform platform; + PlatformTest platform; ASSERT(!readPlatform(platform, xmldata)); } @@ -434,14 +439,14 @@ class TestPlatform : public TestFixture { void no_root_node() const { constexpr char xmldata[] = ""; - Platform platform; + PlatformTest platform; ASSERT(!readPlatform(platform, xmldata)); } void wrong_root_node() const { constexpr char xmldata[] = "\n" ""; - Platform platform; + PlatformTest platform; ASSERT(!readPlatform(platform, xmldata)); } };