Skip to content

Commit e04019c

Browse files
authored
removed need for friend declaration of test class in Platform (danmar#7945)
1 parent 04dc663 commit e04019c

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

lib/platform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ namespace tinyxml2 {
4444
* @brief Platform settings
4545
*/
4646
class CPPCHECKLIB Platform {
47-
friend class TestPlatform;
4847
private:
4948
static long long min_value(std::uint8_t bit) {
5049
assert(bit > 0);
@@ -80,6 +79,7 @@ class CPPCHECKLIB Platform {
8079
/** provides list of defines specified by the limit.h/climits includes */
8180
std::string getLimitsDefines(bool c99) const;
8281

82+
protected:
8383
/** load platform from xml document, primarily for testing */
8484
bool loadFromXmlDocument(const tinyxml2::XMLDocument *doc);
8585
public:

test/testplatform.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,20 @@ class TestPlatform : public TestFixture {
5050
TEST_CASE(wrong_root_node);
5151
}
5252

53-
static bool readPlatform(Platform& platform, const char* xmldata) {
53+
class PlatformTest : public Platform
54+
{
55+
friend class TestPlatform;
56+
};
57+
58+
static bool readPlatform(PlatformTest& platform, const char* xmldata) {
5459
tinyxml2::XMLDocument doc;
5560
return (doc.Parse(xmldata) == tinyxml2::XML_SUCCESS) && platform.loadFromXmlDocument(&doc);
5661
}
5762

5863
void empty() const {
5964
// An empty platform file does not change values, only the type.
6065
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n<platform/>";
61-
Platform platform;
66+
PlatformTest platform;
6267
// TODO: this should fail - platform files need to be complete
6368
TODO_ASSERT(!readPlatform(platform, xmldata));
6469
}
@@ -221,7 +226,7 @@ class TestPlatform : public TestFixture {
221226
" <wchar_t>2</wchar_t>\n"
222227
" </sizeof>\n"
223228
" </platform>";
224-
Platform platform;
229+
PlatformTest platform;
225230
ASSERT(readPlatform(platform, xmldata));
226231
ASSERT_EQUALS(Platform::Type::File, platform.type);
227232
ASSERT(!platform.isWindows());
@@ -265,7 +270,7 @@ class TestPlatform : public TestFixture {
265270
" <wchar_t>11</wchar_t>\n"
266271
" </sizeof>\n"
267272
" </platform>";
268-
Platform platform;
273+
PlatformTest platform;
269274
ASSERT(readPlatform(platform, xmldata));
270275
ASSERT_EQUALS(Platform::Type::File, platform.type);
271276
ASSERT(!platform.isWindows());
@@ -309,7 +314,7 @@ class TestPlatform : public TestFixture {
309314
" <wchar_t1>11</wchar_t1>\n"
310315
" </sizeof1>\n"
311316
" </platform>";
312-
Platform platform;
317+
PlatformTest platform;
313318
// TODO: needs to fail - files need to be complete
314319
TODO_ASSERT(!readPlatform(platform, xmldata));
315320
}
@@ -335,7 +340,7 @@ class TestPlatform : public TestFixture {
335340
" <wchar_t>0</wchar_t>\n"
336341
" </sizeof>\n"
337342
" </platform>";
338-
Platform platform;
343+
PlatformTest platform;
339344
ASSERT(readPlatform(platform, xmldata));
340345
ASSERT_EQUALS(Platform::Type::File, platform.type);
341346
ASSERT(!platform.isWindows());
@@ -378,7 +383,7 @@ class TestPlatform : public TestFixture {
378383
" <wchar_t>2</wchar_t>\n"
379384
" </sizeof>\n"
380385
" </platform>";
381-
Platform platform;
386+
PlatformTest platform;
382387
ASSERT(!readPlatform(platform, xmldata));
383388
}
384389

@@ -403,7 +408,7 @@ class TestPlatform : public TestFixture {
403408
" <wchar_t></wchar_t>\n"
404409
" </sizeof>\n"
405410
" </platform>";
406-
Platform platform;
411+
PlatformTest platform;
407412
ASSERT(!readPlatform(platform, xmldata));
408413
}
409414

@@ -434,14 +439,14 @@ class TestPlatform : public TestFixture {
434439

435440
void no_root_node() const {
436441
constexpr char xmldata[] = "<?xml version=\"1.0\"?>";
437-
Platform platform;
442+
PlatformTest platform;
438443
ASSERT(!readPlatform(platform, xmldata));
439444
}
440445

441446
void wrong_root_node() const {
442447
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
443448
"<platforms/>";
444-
Platform platform;
449+
PlatformTest platform;
445450
ASSERT(!readPlatform(platform, xmldata));
446451
}
447452
};

0 commit comments

Comments
 (0)