Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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: 1 addition & 1 deletion lib/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down
25 changes: 15 additions & 10 deletions test/testplatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,20 @@ 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);
}

void empty() const {
// An empty platform file does not change values, only the type.
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n<platform/>";
Platform platform;
PlatformTest platform;
// TODO: this should fail - platform files need to be complete
TODO_ASSERT(!readPlatform(platform, xmldata));
}
Expand Down Expand Up @@ -221,7 +226,7 @@ class TestPlatform : public TestFixture {
" <wchar_t>2</wchar_t>\n"
" </sizeof>\n"
" </platform>";
Platform platform;
PlatformTest platform;
ASSERT(readPlatform(platform, xmldata));
ASSERT_EQUALS(Platform::Type::File, platform.type);
ASSERT(!platform.isWindows());
Expand Down Expand Up @@ -265,7 +270,7 @@ class TestPlatform : public TestFixture {
" <wchar_t>11</wchar_t>\n"
" </sizeof>\n"
" </platform>";
Platform platform;
PlatformTest platform;
ASSERT(readPlatform(platform, xmldata));
ASSERT_EQUALS(Platform::Type::File, platform.type);
ASSERT(!platform.isWindows());
Expand Down Expand Up @@ -309,7 +314,7 @@ class TestPlatform : public TestFixture {
" <wchar_t1>11</wchar_t1>\n"
" </sizeof1>\n"
" </platform>";
Platform platform;
PlatformTest platform;
// TODO: needs to fail - files need to be complete
TODO_ASSERT(!readPlatform(platform, xmldata));
}
Expand All @@ -335,7 +340,7 @@ class TestPlatform : public TestFixture {
" <wchar_t>0</wchar_t>\n"
" </sizeof>\n"
" </platform>";
Platform platform;
PlatformTest platform;
ASSERT(readPlatform(platform, xmldata));
ASSERT_EQUALS(Platform::Type::File, platform.type);
ASSERT(!platform.isWindows());
Expand Down Expand Up @@ -378,7 +383,7 @@ class TestPlatform : public TestFixture {
" <wchar_t>2</wchar_t>\n"
" </sizeof>\n"
" </platform>";
Platform platform;
PlatformTest platform;
ASSERT(!readPlatform(platform, xmldata));
}

Expand All @@ -403,7 +408,7 @@ class TestPlatform : public TestFixture {
" <wchar_t></wchar_t>\n"
" </sizeof>\n"
" </platform>";
Platform platform;
PlatformTest platform;
ASSERT(!readPlatform(platform, xmldata));
}

Expand Down Expand Up @@ -434,14 +439,14 @@ class TestPlatform : public TestFixture {

void no_root_node() const {
constexpr char xmldata[] = "<?xml version=\"1.0\"?>";
Platform platform;
PlatformTest platform;
ASSERT(!readPlatform(platform, xmldata));
}

void wrong_root_node() const {
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<platforms/>";
Platform platform;
PlatformTest platform;
ASSERT(!readPlatform(platform, xmldata));
}
};
Expand Down