diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 399eb6d3d6e..c5308ca8c6b 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -825,7 +825,7 @@ unsigned int CppCheck::check(const FileSettings &fs) else if (!fs.standard.empty()) tempSettings.standards.setC(fs.standard); if (fs.platformType != Platform::Type::Unspecified) - tempSettings.platform.set(fs.platformType); + tempSettings.platform.set(fs.platformType); // TODO: properly handle files if (mSettings.clang) { tempSettings.includePaths.insert(tempSettings.includePaths.end(), fs.systemIncludePaths.cbegin(), fs.systemIncludePaths.cend()); // need to pass the externally provided ErrorLogger instead of our internal wrapper diff --git a/lib/platform.cpp b/lib/platform.cpp index 833c012ab8e..2cc8111e203 100644 --- a/lib/platform.cpp +++ b/lib/platform.cpp @@ -40,6 +40,7 @@ bool Platform::set(Type t) case Type::Unspecified: // unknown type sizes (sizes etc are set but are not known) case Type::Native: // same as system this code was compile on type = t; + windows = false; sizeof_bool = sizeof(bool); sizeof_short = sizeof(short); sizeof_int = sizeof(int); @@ -61,75 +62,17 @@ bool Platform::set(Type t) return true; case Type::Win32W: case Type::Win32A: - type = t; - sizeof_bool = 1; // 4 in Visual C++ 4.2 - sizeof_short = 2; - sizeof_int = 4; - sizeof_long = 4; - sizeof_long_long = 8; - sizeof_float = 4; - sizeof_double = 8; - sizeof_long_double = 8; - sizeof_wchar_t = 2; - sizeof_size_t = 4; - sizeof_pointer = 4; - defaultSign = '\0'; - char_bit = 8; - calculateBitMembers(); - return true; case Type::Win64: - type = t; - sizeof_bool = 1; - sizeof_short = 2; - sizeof_int = 4; - sizeof_long = 4; - sizeof_long_long = 8; - sizeof_float = 4; - sizeof_double = 8; - sizeof_long_double = 8; - sizeof_wchar_t = 2; - sizeof_size_t = 8; - sizeof_pointer = 8; - defaultSign = '\0'; - char_bit = 8; - calculateBitMembers(); - return true; case Type::Unix32: - type = t; - sizeof_bool = 1; - sizeof_short = 2; - sizeof_int = 4; - sizeof_long = 4; - sizeof_long_long = 8; - sizeof_float = 4; - sizeof_double = 8; - sizeof_long_double = 12; - sizeof_wchar_t = 4; - sizeof_size_t = 4; - sizeof_pointer = 4; - defaultSign = '\0'; - char_bit = 8; - calculateBitMembers(); - return true; case Type::Unix64: type = t; - sizeof_bool = 1; - sizeof_short = 2; - sizeof_int = 4; - sizeof_long = 8; - sizeof_long_long = 8; - sizeof_float = 4; - sizeof_double = 8; - sizeof_long_double = 16; - sizeof_wchar_t = 4; - sizeof_size_t = 8; - sizeof_pointer = 8; - defaultSign = '\0'; - char_bit = 8; + // read from platform file calculateBitMembers(); return true; case Type::File: + type = t; // sizes are not set. + calculateBitMembers(); return false; } // unsupported platform @@ -138,29 +81,69 @@ bool Platform::set(Type t) bool Platform::set(const std::string& platformstr, std::string& errstr, const std::vector& paths, bool debug) { - if (platformstr == "win32A") - set(Type::Win32A); - else if (platformstr == "win32W") - set(Type::Win32W); - else if (platformstr == "win64") - set(Type::Win64); - else if (platformstr == "unix32") - set(Type::Unix32); - else if (platformstr == "unix64") - set(Type::Unix64); - else if (platformstr == "native") - set(Type::Native); - else if (platformstr == "unspecified") - set(Type::Unspecified); + // TODO: needs to be invalidated in case it was already set + Type t; + std::string platformFile; + + if (platformstr == "win32A") { + // TODO: deprecate + //std::cout << "Platform 'win32A' is deprecated and will be removed in a future version. Please use 'win32a' instead." << std::endl; + t = Type::Win32A; + platformFile = "win32"; + } + else if (platformstr == "win32a") { + // TODO: deprecate if we have proper UNICODE support in win32.cfg + t = Type::Win32A; + platformFile = "win32"; + } + else if (platformstr == "win32W") { + // TODO: deprecate + //std::cout << "Platform 'win32W' is deprecated and will be removed in a future version. Please use 'win32w' instead." << std::endl; + t = Type::Win32W; + platformFile = "win32"; + } + else if (platformstr == "win32w") { + // TODO: deprecate if we have proper UNICODE support in win32.cfg + t = Type::Win32W; + platformFile = "win32"; + } + else if (platformstr == "win32") { + t = Type::Win32A; + platformFile = platformstr; + } + else if (platformstr == "win64") { + t = Type::Win64; + platformFile = platformstr; + } + else if (platformstr == "unix32") { + t = Type::Unix32; + platformFile = platformstr; + } + else if (platformstr == "unix64") { + t = Type::Unix64; + platformFile = platformstr; + } + else if (platformstr == "native") { + t = Type::Native; + } + else if (platformstr == "unspecified") { + t = Type::Unspecified; + } else if (paths.empty()) { errstr = "unrecognized platform: '" + platformstr + "' (no lookup)."; return false; } - else if (!loadFromFile(paths, platformstr, debug)) { - errstr = "unrecognized platform: '" + platformstr + "'."; + else { + t = Type::File; + platformFile = platformstr; + } + + if (!platformFile.empty() && !loadFromFile(paths, platformFile, debug)) { + errstr = "unrecognized platform: '" + platformFile + "'."; return false; } + set(t); return true; } @@ -231,6 +214,14 @@ bool Platform::loadFromFile(const std::vector& paths, const std::st return loadFromXmlDocument(&doc); } +static const char* xmlText(const tinyxml2::XMLElement* node, bool& error) +{ + const char* const str = node->GetText(); + if (!str) + error = true; + return str; +} + static unsigned int xmlTextAsUInt(const tinyxml2::XMLElement* node, bool& error) { unsigned int retval = 0; @@ -239,6 +230,14 @@ static unsigned int xmlTextAsUInt(const tinyxml2::XMLElement* node, bool& error) return retval; } +static unsigned int xmlTextAsBool(const tinyxml2::XMLElement* node, bool& error) +{ + bool retval = false; + if (node->QueryBoolText(&retval) != tinyxml2::XML_SUCCESS) + error = true; + return retval; +} + bool Platform::loadFromXmlDocument(const tinyxml2::XMLDocument *doc) { const tinyxml2::XMLElement * const rootnode = doc->FirstChildElement(); @@ -246,15 +245,14 @@ bool Platform::loadFromXmlDocument(const tinyxml2::XMLDocument *doc) if (!rootnode || std::strcmp(rootnode->Name(), "platform") != 0) return false; + // TODO: warn about missing fields bool error = false; for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) { const char* name = node->Name(); if (std::strcmp(name, "default-sign") == 0) { - const char* str = node->GetText(); - if (str) + const char * const str = xmlText(node, error); + if (!error) defaultSign = *str; - else - error = true; } else if (std::strcmp(name, "char_bit") == 0) char_bit = xmlTextAsUInt(node, error); else if (std::strcmp(name, "sizeof") == 0) { @@ -284,6 +282,9 @@ bool Platform::loadFromXmlDocument(const tinyxml2::XMLDocument *doc) sizeof_wchar_t = xmlTextAsUInt(sz, error); } } + else if (std::strcmp(node->Name(), "windows") == 0) { + windows = xmlTextAsBool(node, error); + } } calculateBitMembers(); type = Type::File; diff --git a/lib/platform.h b/lib/platform.h index 4673c4859e6..c117edf5856 100644 --- a/lib/platform.h +++ b/lib/platform.h @@ -132,6 +132,8 @@ class CPPCHECKLIB Platform { char defaultSign; // unsigned:'u', signed:'s', unknown:'\0' + bool windows{false}; // indicates if the platform is Windows + enum Type : std::uint8_t { Unspecified, // No platform specified Native, // whatever system this code was compiled on @@ -167,9 +169,7 @@ class CPPCHECKLIB Platform { * @return true if Windows platform type. */ bool isWindows() const { - return type == Type::Win32A || - type == Type::Win32W || - type == Type::Win64; + return windows; } const char *toString() const { diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index b6528d9a9e6..6aabd1606b5 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -7851,6 +7851,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to else if (Token::simpleMatch(tok->previous(), "sizeof (")) { ValueType valuetype(ValueType::Sign::UNSIGNED, ValueType::Type::LONG, 0U); + // TODO: handle via sizeof_size_t instead if (mSettings.platform.type == Platform::Type::Win64) valuetype.type = ValueType::Type::LONGLONG; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 96c69bb4dd9..cb6697487ab 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -10385,7 +10385,7 @@ void Tokenizer::simplifyMicrosoftStringFunctions() if (!mSettings.platform.isWindows()) return; - const bool ansi = mSettings.platform.type == Platform::Type::Win32A; + const bool ansi = (mSettings.platform.type == Platform::Type::Win32A); // TODO: check for UNICODE define instead for (Token *tok = list.front(); tok; tok = tok->next()) { if (tok->strAt(1) != "(") continue; diff --git a/platforms/unix32.xml b/platforms/unix32.xml new file mode 100644 index 00000000000..409d1abc55d --- /dev/null +++ b/platforms/unix32.xml @@ -0,0 +1,18 @@ + + + 8 + signed + + 1 + 2 + 4 + 4 + 8 + 4 + 8 + 12 + 4 + 4 + 4 + + diff --git a/platforms/unix64.xml b/platforms/unix64.xml new file mode 100644 index 00000000000..6d43afdd330 --- /dev/null +++ b/platforms/unix64.xml @@ -0,0 +1,18 @@ + + + 8 + signed + + 1 + 2 + 4 + 8 + 8 + 4 + 8 + 16 + 8 + 8 + 4 + + diff --git a/platforms/win32.xml b/platforms/win32.xml new file mode 100644 index 00000000000..1fd15b4af83 --- /dev/null +++ b/platforms/win32.xml @@ -0,0 +1,19 @@ + + + 8 + signed + true + + 1 + 2 + 4 + 4 + 8 + 4 + 8 + 8 + 4 + 4 + 2 + + diff --git a/platforms/win64.xml b/platforms/win64.xml new file mode 100644 index 00000000000..a716978f0fc --- /dev/null +++ b/platforms/win64.xml @@ -0,0 +1,19 @@ + + + 8 + signed + true + + 1 + 2 + 4 + 4 + 8 + 4 + 8 + 8 + 8 + 8 + 2 + + diff --git a/releasenotes.txt b/releasenotes.txt index f130e957aec..031163137e4 100644 --- a/releasenotes.txt +++ b/releasenotes.txt @@ -19,3 +19,8 @@ Changed interface: Infrastructure & dependencies: - + +Other: +- The built-in "win*" and "unix*" platforms will now default to signed char type instead of unknown signedness. If you require unsigned chars please specify "--funsigned-char" +- The `win32a` and `win32w` aliases have been added for the platforms `win32A` and `win32W` respectively. +- diff --git a/test/cli/other_test.py b/test/cli/other_test.py index c4ae2fab5cf..b8235bb3e54 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -4119,3 +4119,43 @@ def test_active_unusedfunction_only_misra_builddir(tmp_path): 'CheckUnusedFunctions::check' ] __test_active_checkers(tmp_path, 1, 1175, use_unusedfunction_only=True, use_misra=True, checkers_exp=checkers_exp) + + +def test_custom_platform(tmpdir): + test_cfg = os.path.join(tmpdir, 'test.cfg') + with open(test_cfg, 'wt') as f: + f.write(""" + + + 8 + unsigned + + 1 + 2 + 2 + 4 + 8 + 4 + 4 + 4 + 2 + 2 + 2 + + + """) + + # TODO: use a sample to make sure the file is actually used + test_file = os.path.join(tmpdir, 'test.cpp') + with open(test_file, 'wt') as f: + f.write(""" + """) + args = ['--platform={}'.format(test_cfg), test_file] + + exitcode, stdout, stderr = cppcheck(args) + assert exitcode == 0, stdout + lines = stdout.splitlines() + assert lines == [ + 'Checking {} ...'.format(test_file) + ] + assert stderr == '' diff --git a/test/fixture.h b/test/fixture.h index 5983ae66a3a..331090389eb 100644 --- a/test/fixture.h +++ b/test/fixture.h @@ -344,6 +344,6 @@ class TestInstance { #define REGISTER_TEST( CLASSNAME ) namespace { class CLASSNAME ## Instance : public TestInstance { public: CLASSNAME ## Instance() : TestInstance(#CLASSNAME) {} TestFixture* create() override { impl.reset(new CLASSNAME); return impl.get(); } }; CLASSNAME ## Instance instance_ ## CLASSNAME; } // *INDENT-ON* -#define PLATFORM( P, T ) do { std::string errstr; assertEquals(__FILE__, __LINE__, true, P.set(Platform::toString(T), errstr, {exename}), errstr); } while (false) +#define PLATFORM( P, T ) do { std::string errstr; assertEquals(__FILE__, __LINE__, true, P.set(Platform::toString(T), errstr, {Path::getPathFromFilename(exename)}), errstr); } while (false) #endif // fixtureH diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index 7b5c646e4bf..6f915688d6f 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -282,8 +282,11 @@ class TestCmdlineParser : public TestFixture { TEST_CASE(stdmulti1); TEST_CASE(stdmulti2); TEST_CASE(platformWin64); + TEST_CASE(platformWin32); TEST_CASE(platformWin32A); + TEST_CASE(platformWin32a); TEST_CASE(platformWin32W); + TEST_CASE(platformWin32w); TEST_CASE(platformUnix32); TEST_CASE(platformUnix32Unsigned); TEST_CASE(platformUnix64); @@ -1799,15 +1802,28 @@ class TestCmdlineParser : public TestFixture { void platformWin64() { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=win64", "file.cpp"}; - ASSERT(settings->platform.set(Platform::Type::Unspecified)); ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv)); ASSERT_EQUALS(Platform::Type::Win64, settings->platform.type); } + void platformWin32() { + REDIRECT; + const char * const argv[] = {"cppcheck", "--platform=win32", "file.cpp"}; + ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv)); + ASSERT_EQUALS(Platform::Type::Win32A, settings->platform.type); + ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); + } + void platformWin32A() { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=win32A", "file.cpp"}; - ASSERT(settings->platform.set(Platform::Type::Unspecified)); + ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv)); + ASSERT_EQUALS(Platform::Type::Win32A, settings->platform.type); + } + + void platformWin32a() { + REDIRECT; + const char * const argv[] = {"cppcheck", "--platform=win32a", "file.cpp"}; ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv)); ASSERT_EQUALS(Platform::Type::Win32A, settings->platform.type); } @@ -1815,7 +1831,13 @@ class TestCmdlineParser : public TestFixture { void platformWin32W() { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=win32W", "file.cpp"}; - ASSERT(settings->platform.set(Platform::Type::Unspecified)); + ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv)); + ASSERT_EQUALS(Platform::Type::Win32W, settings->platform.type); + } + + void platformWin32w() { + REDIRECT; + const char * const argv[] = {"cppcheck", "--platform=win32w", "file.cpp"}; ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv)); ASSERT_EQUALS(Platform::Type::Win32W, settings->platform.type); } @@ -1823,7 +1845,6 @@ class TestCmdlineParser : public TestFixture { void platformUnix32() { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=unix32", "file.cpp"}; - ASSERT(settings->platform.set(Platform::Type::Unspecified)); ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv)); ASSERT_EQUALS(Platform::Type::Unix32, settings->platform.type); } @@ -1831,7 +1852,6 @@ class TestCmdlineParser : public TestFixture { void platformUnix32Unsigned() { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=unix32-unsigned", "file.cpp"}; - ASSERT(settings->platform.set(Platform::Type::Unspecified)); ASSERT_EQUALS_ENUM(CmdLineParser::Result::Fail, parseFromArgs(argv)); ASSERT_EQUALS("cppcheck: error: unrecognized platform: 'unix32-unsigned'.\n", logger->str()); } @@ -1839,7 +1859,6 @@ class TestCmdlineParser : public TestFixture { void platformUnix64() { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=unix64", "file.cpp"}; - ASSERT(settings->platform.set(Platform::Type::Unspecified)); ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv)); ASSERT_EQUALS(Platform::Type::Unix64, settings->platform.type); } @@ -1847,7 +1866,6 @@ class TestCmdlineParser : public TestFixture { void platformUnix64Unsigned() { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=unix64-unsigned", "file.cpp"}; - ASSERT(settings->platform.set(Platform::Type::Unspecified)); ASSERT_EQUALS_ENUM(CmdLineParser::Result::Fail, parseFromArgs(argv)); ASSERT_EQUALS("cppcheck: error: unrecognized platform: 'unix64-unsigned'.\n", logger->str()); } @@ -1855,7 +1873,6 @@ class TestCmdlineParser : public TestFixture { void platformNative() { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=native", "file.cpp"}; - ASSERT(settings->platform.set(Platform::Type::Unspecified)); ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv)); ASSERT_EQUALS(Platform::Type::Native, settings->platform.type); } @@ -1863,7 +1880,6 @@ class TestCmdlineParser : public TestFixture { void platformUnspecified() { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=unspecified", "file.cpp"}; - ASSERT(settings->platform.set(Platform::Type::Native)); ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv)); ASSERT_EQUALS(Platform::Type::Unspecified, settings->platform.type); } @@ -1871,7 +1887,6 @@ class TestCmdlineParser : public TestFixture { void platformPlatformFile() { REDIRECT; const char * const argv[] = {"cppcheck", "--platform=avr8", "file.cpp"}; - ASSERT(settings->platform.set(Platform::Type::Unspecified)); ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv)); ASSERT_EQUALS(Platform::Type::File, settings->platform.type); } diff --git a/test/testplatform.cpp b/test/testplatform.cpp index c0f7bb2c017..da8a6e681b5 100644 --- a/test/testplatform.cpp +++ b/test/testplatform.cpp @@ -37,11 +37,12 @@ class TestPlatform : public TestFixture { TEST_CASE(valid_config_win32w); TEST_CASE(valid_config_unix32); TEST_CASE(valid_config_win64); + // TODO: test native and unspecified TEST_CASE(valid_config_file_1); TEST_CASE(valid_config_file_2); - TEST_CASE(valid_config_file_3); TEST_CASE(valid_config_file_4); TEST_CASE(invalid_config_file_1); + TEST_CASE(invalid_config_file_2); TEST_CASE(empty_elements); TEST_CASE(default_platform); TEST_CASE(limitsDefines); @@ -85,7 +86,7 @@ class TestPlatform : public TestFixture { ASSERT_EQUALS(2, platform.sizeof_wchar_t); ASSERT_EQUALS(4, platform.sizeof_size_t); ASSERT_EQUALS(4, platform.sizeof_pointer); - ASSERT_EQUALS('\0', platform.defaultSign); + ASSERT_EQUALS('s', platform.defaultSign); ASSERT_EQUALS(8, platform.char_bit); ASSERT_EQUALS(16, platform.short_bit); ASSERT_EQUALS(32, platform.int_bit); @@ -110,7 +111,7 @@ class TestPlatform : public TestFixture { ASSERT_EQUALS(4, platform.sizeof_wchar_t); ASSERT_EQUALS(8, platform.sizeof_size_t); ASSERT_EQUALS(8, platform.sizeof_pointer); - ASSERT_EQUALS('\0', platform.defaultSign); + ASSERT_EQUALS('s', platform.defaultSign); ASSERT_EQUALS(8, platform.char_bit); ASSERT_EQUALS(16, platform.short_bit); ASSERT_EQUALS(32, platform.int_bit); @@ -138,7 +139,7 @@ class TestPlatform : public TestFixture { ASSERT_EQUALS(2, platform.sizeof_wchar_t); ASSERT_EQUALS(4, platform.sizeof_size_t); ASSERT_EQUALS(4, platform.sizeof_pointer); - ASSERT_EQUALS('\0', platform.defaultSign); + ASSERT_EQUALS('s', platform.defaultSign); ASSERT_EQUALS(8, platform.char_bit); ASSERT_EQUALS(16, platform.short_bit); ASSERT_EQUALS(32, platform.int_bit); @@ -166,7 +167,7 @@ class TestPlatform : public TestFixture { ASSERT_EQUALS(4, platform.sizeof_wchar_t); ASSERT_EQUALS(4, platform.sizeof_size_t); ASSERT_EQUALS(4, platform.sizeof_pointer); - ASSERT_EQUALS('\0', platform.defaultSign); + ASSERT_EQUALS('s', platform.defaultSign); ASSERT_EQUALS(8, platform.char_bit); ASSERT_EQUALS(16, platform.short_bit); ASSERT_EQUALS(32, platform.int_bit); @@ -194,7 +195,7 @@ class TestPlatform : public TestFixture { ASSERT_EQUALS(2, platform.sizeof_wchar_t); ASSERT_EQUALS(8, platform.sizeof_size_t); ASSERT_EQUALS(8, platform.sizeof_pointer); - ASSERT_EQUALS('\0', platform.defaultSign); + ASSERT_EQUALS('s', platform.defaultSign); ASSERT_EQUALS(8, platform.char_bit); ASSERT_EQUALS(16, platform.short_bit); ASSERT_EQUALS(32, platform.int_bit); @@ -210,6 +211,7 @@ class TestPlatform : public TestFixture { // Similar to the avr8 platform file. constexpr char xmldata[] = "\n" "\n" + " false\n" " 8\n" " unsigned\n" " \n" @@ -228,8 +230,9 @@ class TestPlatform : public TestFixture { " "; PlatformTest platform; ASSERT(readPlatform(platform, xmldata)); - ASSERT_EQUALS(Platform::Type::File, platform.type); - ASSERT(!platform.isWindows()); + // not set by code + // ASSERT_EQUALS(Platform::Type::File, platform.type); + // ASSERT(!platform.isWindows()); ASSERT_EQUALS(8, platform.char_bit); ASSERT_EQUALS('u', platform.defaultSign); ASSERT_EQUALS(1, platform.sizeof_bool); @@ -254,6 +257,7 @@ class TestPlatform : public TestFixture { // char_bit > 8. constexpr char xmldata[] = "\n" "\n" + " true\n" " 20\n" " signed\n" " \n" @@ -272,8 +276,9 @@ class TestPlatform : public TestFixture { " "; PlatformTest platform; ASSERT(readPlatform(platform, xmldata)); - ASSERT_EQUALS(Platform::Type::File, platform.type); - ASSERT(!platform.isWindows()); + // not set by code + // ASSERT_EQUALS(Platform::Type::File, platform.type); + // ASSERT(platform.isWindows()); ASSERT_EQUALS(20, platform.char_bit); ASSERT_EQUALS('s', platform.defaultSign); ASSERT_EQUALS(1, platform.sizeof_bool); @@ -293,11 +298,12 @@ class TestPlatform : public TestFixture { ASSERT_EQUALS(100, platform.long_long_bit); } - void valid_config_file_3() const { - // Valid platform configuration without any usable information. + void invalid_config_file_2() const { + // Invalid platform configuration without any usable information. // Similar like an empty file. constexpr char xmldata[] = "\n" "\n" + " true\n" " 8\n" " unsigned\n" " \n" @@ -324,6 +330,7 @@ class TestPlatform : public TestFixture { // set to 0. constexpr char xmldata[] = "\n" "\n" + " true\n" " 0\n" " z\n" " \n" @@ -342,8 +349,9 @@ class TestPlatform : public TestFixture { " "; PlatformTest platform; ASSERT(readPlatform(platform, xmldata)); - ASSERT_EQUALS(Platform::Type::File, platform.type); - ASSERT(!platform.isWindows()); + // not set by the code + // ASSERT_EQUALS(Platform::Type::File, platform.type); + // ASSERT(platform.isWindows()); ASSERT_EQUALS(0, platform.char_bit); ASSERT_EQUALS('z', platform.defaultSign); ASSERT_EQUALS(0, platform.sizeof_bool); @@ -367,6 +375,7 @@ class TestPlatform : public TestFixture { // Invalid XML file: mismatching elements "boolt" vs "bool". constexpr char xmldata[] = "\n" "\n" + " false\n" " 8\n" " unsigned\n" " \n" @@ -392,6 +401,7 @@ class TestPlatform : public TestFixture { // Similar like an empty file. constexpr char xmldata[] = "\n" "\n" + " \n" " \n" " \n" " \n" @@ -410,6 +420,9 @@ class TestPlatform : public TestFixture { " "; PlatformTest platform; ASSERT(!readPlatform(platform, xmldata)); + // not set by code + //ASSERT_EQUALS(cppcheck::Platform::Win64, platform.platformType); + //ASSERT(platform.isWindowsPlatform()); } void default_platform() const {