improved setting of platform in tests / also improved platform tests (#4787)
* fixture.h: added TODO * TestPlatform: improved tests for built-in platforms * TestPlatform: changed tests to TODO asserts * testfilelister.cpp: added TODO * fixture.h: added `PLATFORM` macro to load platform / use `PLATFORM` in tests * platform.h: corrected capitalization in `Platform::platformString(PlatformType)` and bail on unknown type * fixture.h: fixed `readability-redundant-string-cstr` clang-tidy warning * testplatform.cpp: fixed `functionConst` selfcheck warnings
This commit is contained in:
parent
2be1e36603
commit
132a5a31cf
|
@ -24,6 +24,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <climits>
|
#include <climits>
|
||||||
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -149,9 +150,9 @@ namespace cppcheck {
|
||||||
static const char *platformString(PlatformType pt) {
|
static const char *platformString(PlatformType pt) {
|
||||||
switch (pt) {
|
switch (pt) {
|
||||||
case Unspecified:
|
case Unspecified:
|
||||||
return "Unspecified";
|
return "unspecified";
|
||||||
case Native:
|
case Native:
|
||||||
return "Native";
|
return "native";
|
||||||
case Win32A:
|
case Win32A:
|
||||||
return "win32A";
|
return "win32A";
|
||||||
case Win32W:
|
case Win32W:
|
||||||
|
@ -165,7 +166,7 @@ namespace cppcheck {
|
||||||
case PlatformFile:
|
case PlatformFile:
|
||||||
return "platformFile";
|
return "platformFile";
|
||||||
default:
|
default:
|
||||||
return "unknown";
|
throw std::runtime_error("unknown platform");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -141,6 +141,7 @@ extern std::ostringstream errout;
|
||||||
// NOLINTNEXTLINE(readability-redundant-declaration)
|
// NOLINTNEXTLINE(readability-redundant-declaration)
|
||||||
extern std::ostringstream output;
|
extern std::ostringstream output;
|
||||||
|
|
||||||
|
// TODO: most asserts do not actually assert i.e. do not return
|
||||||
#define TEST_CASE( NAME ) do { if (prepareTest(#NAME)) { setVerbose(false); NAME(); } } while (false)
|
#define TEST_CASE( NAME ) do { if (prepareTest(#NAME)) { setVerbose(false); NAME(); } } while (false)
|
||||||
#define ASSERT( CONDITION ) if (!assert_(__FILE__, __LINE__, (CONDITION))) return
|
#define ASSERT( CONDITION ) if (!assert_(__FILE__, __LINE__, (CONDITION))) return
|
||||||
#define ASSERT_LOC( CONDITION, FILE_, LINE_ ) assert_(FILE_, LINE_, (CONDITION))
|
#define ASSERT_LOC( CONDITION, FILE_, LINE_ ) assert_(FILE_, LINE_, (CONDITION))
|
||||||
|
@ -165,4 +166,6 @@ extern std::ostringstream output;
|
||||||
} \
|
} \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
|
#define PLATFORM( S, P ) do { std::string errstr; assertEquals(__FILE__, __LINE__, true, S.platform(cppcheck::Platform::platformString(P), errstr, {exename}), errstr); } while (false)
|
||||||
|
|
||||||
#endif // fixtureH
|
#endif // fixtureH
|
||||||
|
|
|
@ -34,7 +34,7 @@ private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
|
||||||
void run() override {
|
void run() override {
|
||||||
settings.platform(Settings::Unspecified);
|
PLATFORM(settings, Settings::Unspecified);
|
||||||
settings.severity.enable(Severity::warning);
|
settings.severity.enable(Severity::warning);
|
||||||
settings.severity.enable(Severity::portability);
|
settings.severity.enable(Severity::portability);
|
||||||
|
|
||||||
|
|
|
@ -1052,10 +1052,15 @@ private:
|
||||||
#define GET_SYMBOL_DB(AST) \
|
#define GET_SYMBOL_DB(AST) \
|
||||||
Settings settings; \
|
Settings settings; \
|
||||||
settings.clang = true; \
|
settings.clang = true; \
|
||||||
settings.platform(cppcheck::Platform::PlatformType::Unix64); \
|
{ \
|
||||||
|
std::string errstr; \
|
||||||
|
ASSERT_EQUALS_MSG(true, settings.platform("unix64", errstr, {exename.c_str()}), errstr); \
|
||||||
|
} \
|
||||||
Tokenizer tokenizer(&settings, this); \
|
Tokenizer tokenizer(&settings, this); \
|
||||||
|
{ \
|
||||||
std::istringstream istr(AST); \
|
std::istringstream istr(AST); \
|
||||||
clangimport::parseClangAstDump(&tokenizer, istr); \
|
clangimport::parseClangAstDump(&tokenizer, istr); \
|
||||||
|
} \
|
||||||
const SymbolDatabase *db = tokenizer.getSymbolDatabase(); \
|
const SymbolDatabase *db = tokenizer.getSymbolDatabase(); \
|
||||||
ASSERT(db)
|
ASSERT(db)
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,8 @@ private:
|
||||||
|
|
||||||
void run() override {
|
void run() override {
|
||||||
// known platform..
|
// known platform..
|
||||||
settings0.platform(cppcheck::Platform::PlatformType::Native);
|
PLATFORM(settings0, cppcheck::Platform::Native);
|
||||||
settings1.platform(cppcheck::Platform::PlatformType::Native);
|
PLATFORM(settings1, cppcheck::Platform::Native);
|
||||||
|
|
||||||
LOAD_LIB_2(settings0.library, "qt.cfg");
|
LOAD_LIB_2(settings0.library, "qt.cfg");
|
||||||
LOAD_LIB_2(settings0.library, "std.cfg");
|
LOAD_LIB_2(settings0.library, "std.cfg");
|
||||||
|
@ -5580,7 +5580,7 @@ private:
|
||||||
void compareOutOfTypeRange() {
|
void compareOutOfTypeRange() {
|
||||||
Settings settingsUnix64;
|
Settings settingsUnix64;
|
||||||
settingsUnix64.severity.enable(Severity::style);
|
settingsUnix64.severity.enable(Severity::style);
|
||||||
settingsUnix64.platform(cppcheck::Platform::PlatformType::Unix64);
|
PLATFORM(settingsUnix64, cppcheck::Platform::PlatformType::Unix64);
|
||||||
|
|
||||||
check("void f(unsigned char c) {\n"
|
check("void f(unsigned char c) {\n"
|
||||||
" if (c == 256) {}\n"
|
" if (c == 256) {}\n"
|
||||||
|
|
|
@ -37,9 +37,11 @@ private:
|
||||||
// bail out if the tests are not executed from the base folder
|
// bail out if the tests are not executed from the base folder
|
||||||
{
|
{
|
||||||
std::ifstream fin("test/testfilelister.cpp");
|
std::ifstream fin("test/testfilelister.cpp");
|
||||||
if (!fin.is_open())
|
if (!fin.is_open()) {
|
||||||
|
// TODO: log
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE(isDirectory);
|
TEST_CASE(isDirectory);
|
||||||
TEST_CASE(recursiveAddFiles);
|
TEST_CASE(recursiveAddFiles);
|
||||||
|
|
|
@ -94,7 +94,7 @@ private:
|
||||||
if (portability)
|
if (portability)
|
||||||
settings.severity.enable(Severity::portability);
|
settings.severity.enable(Severity::portability);
|
||||||
settings.certainty.setEnabled(Certainty::inconclusive, inconclusive);
|
settings.certainty.setEnabled(Certainty::inconclusive, inconclusive);
|
||||||
settings.platform(platform);
|
PLATFORM(settings, platform);
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
|
|
|
@ -1991,7 +1991,7 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
Settings settings1;
|
Settings settings1;
|
||||||
settings1.platform(Settings::Win64);
|
PLATFORM(settings1, cppcheck::Platform::Win64);
|
||||||
check("using ui64 = unsigned __int64;\n"
|
check("using ui64 = unsigned __int64;\n"
|
||||||
"ui64 Test(ui64 one, ui64 two) { return one + two; }\n",
|
"ui64 Test(ui64 one, ui64 two) { return one + two; }\n",
|
||||||
/*filename*/ nullptr, /*experimental*/ false, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);
|
/*filename*/ nullptr, /*experimental*/ false, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1);
|
||||||
|
@ -2137,12 +2137,12 @@ private:
|
||||||
"void f(X x) {}";
|
"void f(X x) {}";
|
||||||
|
|
||||||
Settings s32(_settings);
|
Settings s32(_settings);
|
||||||
s32.platform(cppcheck::Platform::Unix32);
|
PLATFORM(s32, cppcheck::Platform::Unix32);
|
||||||
check(code, &s32);
|
check(code, &s32);
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (performance) Function parameter 'x' should be passed by const reference.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (performance) Function parameter 'x' should be passed by const reference.\n", errout.str());
|
||||||
|
|
||||||
Settings s64(_settings);
|
Settings s64(_settings);
|
||||||
s64.platform(cppcheck::Platform::Unix64);
|
PLATFORM(s64, cppcheck::Platform::Unix64);
|
||||||
check(code, &s64);
|
check(code, &s64);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -7421,7 +7421,7 @@ private:
|
||||||
|
|
||||||
// #9040
|
// #9040
|
||||||
Settings settings1;
|
Settings settings1;
|
||||||
settings1.platform(Settings::Win64);
|
PLATFORM(settings1, cppcheck::Platform::Win64);
|
||||||
check("using BOOL = unsigned;\n"
|
check("using BOOL = unsigned;\n"
|
||||||
"int i;\n"
|
"int i;\n"
|
||||||
"bool f() {\n"
|
"bool f() {\n"
|
||||||
|
|
|
@ -29,8 +29,11 @@ public:
|
||||||
private:
|
private:
|
||||||
void run() override {
|
void run() override {
|
||||||
TEST_CASE(empty);
|
TEST_CASE(empty);
|
||||||
TEST_CASE(valid_config_native_1);
|
TEST_CASE(valid_config_win32a);
|
||||||
TEST_CASE(valid_config_native_2);
|
TEST_CASE(valid_config_unix64);
|
||||||
|
TEST_CASE(valid_config_win32w);
|
||||||
|
TEST_CASE(valid_config_unix32);
|
||||||
|
TEST_CASE(valid_config_win64);
|
||||||
TEST_CASE(valid_config_file_1);
|
TEST_CASE(valid_config_file_1);
|
||||||
TEST_CASE(valid_config_file_2);
|
TEST_CASE(valid_config_file_2);
|
||||||
TEST_CASE(valid_config_file_3);
|
TEST_CASE(valid_config_file_3);
|
||||||
|
@ -50,50 +53,133 @@ private:
|
||||||
// An empty platform file does not change values, only the type.
|
// An empty platform file does not change values, only the type.
|
||||||
const char xmldata[] = "<?xml version=\"1.0\"?>\n<platform/>";
|
const char xmldata[] = "<?xml version=\"1.0\"?>\n<platform/>";
|
||||||
cppcheck::Platform platform;
|
cppcheck::Platform platform;
|
||||||
ASSERT(platform.platform(cppcheck::Platform::Win64));
|
// TODO: this should fail - platform files need to be complete
|
||||||
ASSERT(readPlatform(platform, xmldata));
|
TODO_ASSERT(!readPlatform(platform, xmldata));
|
||||||
ASSERT_EQUALS(cppcheck::Platform::PlatformFile, platform.platformType);
|
|
||||||
ASSERT(!platform.isWindowsPlatform());
|
|
||||||
ASSERT_EQUALS(8, platform.char_bit);
|
|
||||||
ASSERT_EQUALS('\0', platform.defaultSign);
|
|
||||||
ASSERT_EQUALS(1, platform.sizeof_bool);
|
|
||||||
ASSERT_EQUALS(2, platform.sizeof_short);
|
|
||||||
ASSERT_EQUALS(4, platform.sizeof_int);
|
|
||||||
ASSERT_EQUALS(4, platform.sizeof_long);
|
|
||||||
ASSERT_EQUALS(8, platform.sizeof_long_long);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void valid_config_native_1() const {
|
void valid_config_win32a() const {
|
||||||
// Verify if native Win32A platform is loaded correctly
|
// Verify if native Win32A platform is loaded correctly
|
||||||
cppcheck::Platform platform;
|
cppcheck::Platform platform;
|
||||||
ASSERT(platform.platform(cppcheck::Platform::Win32A));
|
PLATFORM(platform, cppcheck::Platform::Win32A);
|
||||||
ASSERT_EQUALS(cppcheck::Platform::Win32A, platform.platformType);
|
ASSERT_EQUALS(cppcheck::Platform::Win32A, platform.platformType);
|
||||||
ASSERT(platform.isWindowsPlatform());
|
ASSERT(platform.isWindowsPlatform());
|
||||||
ASSERT_EQUALS('\0', platform.defaultSign);
|
|
||||||
ASSERT_EQUALS(8, platform.char_bit);
|
|
||||||
ASSERT_EQUALS(1, platform.sizeof_bool);
|
ASSERT_EQUALS(1, platform.sizeof_bool);
|
||||||
ASSERT_EQUALS(2, platform.sizeof_short);
|
ASSERT_EQUALS(2, platform.sizeof_short);
|
||||||
ASSERT_EQUALS(4, platform.sizeof_int);
|
ASSERT_EQUALS(4, platform.sizeof_int);
|
||||||
ASSERT_EQUALS(4, platform.sizeof_long);
|
ASSERT_EQUALS(4, platform.sizeof_long);
|
||||||
ASSERT_EQUALS(8, platform.sizeof_long_long);
|
ASSERT_EQUALS(8, platform.sizeof_long_long);
|
||||||
|
ASSERT_EQUALS(4, platform.sizeof_float);
|
||||||
|
ASSERT_EQUALS(8, platform.sizeof_double);
|
||||||
|
ASSERT_EQUALS(8, platform.sizeof_long_double);
|
||||||
|
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(8, platform.char_bit);
|
||||||
ASSERT_EQUALS(16, platform.short_bit);
|
ASSERT_EQUALS(16, platform.short_bit);
|
||||||
ASSERT_EQUALS(32, platform.int_bit);
|
ASSERT_EQUALS(32, platform.int_bit);
|
||||||
ASSERT_EQUALS(32, platform.long_bit);
|
ASSERT_EQUALS(32, platform.long_bit);
|
||||||
ASSERT_EQUALS(64, platform.long_long_bit);
|
ASSERT_EQUALS(64, platform.long_long_bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void valid_config_native_2() const {
|
void valid_config_unix64() const {
|
||||||
// Verify if native Unix64 platform is loaded correctly
|
// Verify if native Unix64 platform is loaded correctly
|
||||||
cppcheck::Platform platform;
|
cppcheck::Platform platform;
|
||||||
ASSERT(platform.platform(cppcheck::Platform::Unix64));
|
PLATFORM(platform, cppcheck::Platform::Unix64);
|
||||||
ASSERT_EQUALS(cppcheck::Platform::Unix64, platform.platformType);
|
ASSERT_EQUALS(cppcheck::Platform::Unix64, platform.platformType);
|
||||||
ASSERT(!platform.isWindowsPlatform());
|
ASSERT(!platform.isWindowsPlatform());
|
||||||
|
ASSERT_EQUALS(1, platform.sizeof_bool);
|
||||||
|
ASSERT_EQUALS(2, platform.sizeof_short);
|
||||||
|
ASSERT_EQUALS(4, platform.sizeof_int);
|
||||||
|
ASSERT_EQUALS(8, platform.sizeof_long);
|
||||||
|
ASSERT_EQUALS(8, platform.sizeof_long_long);
|
||||||
|
ASSERT_EQUALS(4, platform.sizeof_float);
|
||||||
|
ASSERT_EQUALS(8, platform.sizeof_double);
|
||||||
|
ASSERT_EQUALS(16, platform.sizeof_long_double);
|
||||||
|
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('\0', platform.defaultSign);
|
||||||
ASSERT_EQUALS(8, platform.char_bit);
|
ASSERT_EQUALS(8, platform.char_bit);
|
||||||
ASSERT_EQUALS(4, platform.sizeof_int);
|
ASSERT_EQUALS(16, platform.short_bit);
|
||||||
ASSERT_EQUALS(32, platform.int_bit);
|
ASSERT_EQUALS(32, platform.int_bit);
|
||||||
ASSERT_EQUALS(8, platform.sizeof_long);
|
|
||||||
ASSERT_EQUALS(64, platform.long_bit);
|
ASSERT_EQUALS(64, platform.long_bit);
|
||||||
|
ASSERT_EQUALS(64, platform.long_long_bit);
|
||||||
|
}
|
||||||
|
|
||||||
|
void valid_config_win32w() const {
|
||||||
|
// Verify if native Win32W platform is loaded correctly
|
||||||
|
cppcheck::Platform platform;
|
||||||
|
PLATFORM(platform, cppcheck::Platform::Win32W);
|
||||||
|
ASSERT_EQUALS(cppcheck::Platform::Win32W, platform.platformType);
|
||||||
|
ASSERT(platform.isWindowsPlatform());
|
||||||
|
ASSERT_EQUALS(1, platform.sizeof_bool);
|
||||||
|
ASSERT_EQUALS(2, platform.sizeof_short);
|
||||||
|
ASSERT_EQUALS(4, platform.sizeof_int);
|
||||||
|
ASSERT_EQUALS(4, platform.sizeof_long);
|
||||||
|
ASSERT_EQUALS(8, platform.sizeof_long_long);
|
||||||
|
ASSERT_EQUALS(4, platform.sizeof_float);
|
||||||
|
ASSERT_EQUALS(8, platform.sizeof_double);
|
||||||
|
ASSERT_EQUALS(8, platform.sizeof_long_double);
|
||||||
|
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(8, platform.char_bit);
|
||||||
|
ASSERT_EQUALS(16, platform.short_bit);
|
||||||
|
ASSERT_EQUALS(32, platform.int_bit);
|
||||||
|
ASSERT_EQUALS(32, platform.long_bit);
|
||||||
|
ASSERT_EQUALS(64, platform.long_long_bit);
|
||||||
|
}
|
||||||
|
|
||||||
|
void valid_config_unix32() const {
|
||||||
|
// Verify if native Unix32 platform is loaded correctly
|
||||||
|
cppcheck::Platform platform;
|
||||||
|
PLATFORM(platform, cppcheck::Platform::Unix32);
|
||||||
|
ASSERT_EQUALS(cppcheck::Platform::Unix32, platform.platformType);
|
||||||
|
ASSERT(!platform.isWindowsPlatform());
|
||||||
|
ASSERT_EQUALS(1, platform.sizeof_bool);
|
||||||
|
ASSERT_EQUALS(2, platform.sizeof_short);
|
||||||
|
ASSERT_EQUALS(4, platform.sizeof_int);
|
||||||
|
ASSERT_EQUALS(4, platform.sizeof_long);
|
||||||
|
ASSERT_EQUALS(8, platform.sizeof_long_long);
|
||||||
|
ASSERT_EQUALS(4, platform.sizeof_float);
|
||||||
|
ASSERT_EQUALS(8, platform.sizeof_double);
|
||||||
|
ASSERT_EQUALS(12, platform.sizeof_long_double);
|
||||||
|
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(8, platform.char_bit);
|
||||||
|
ASSERT_EQUALS(16, platform.short_bit);
|
||||||
|
ASSERT_EQUALS(32, platform.int_bit);
|
||||||
|
ASSERT_EQUALS(32, platform.long_bit);
|
||||||
|
ASSERT_EQUALS(64, platform.long_long_bit);
|
||||||
|
}
|
||||||
|
|
||||||
|
void valid_config_win64() const {
|
||||||
|
// Verify if native Win64 platform is loaded correctly
|
||||||
|
cppcheck::Platform platform;
|
||||||
|
PLATFORM(platform, cppcheck::Platform::Win64);
|
||||||
|
ASSERT_EQUALS(cppcheck::Platform::Win64, platform.platformType);
|
||||||
|
ASSERT(platform.isWindowsPlatform());
|
||||||
|
ASSERT_EQUALS(1, platform.sizeof_bool);
|
||||||
|
ASSERT_EQUALS(2, platform.sizeof_short);
|
||||||
|
ASSERT_EQUALS(4, platform.sizeof_int);
|
||||||
|
ASSERT_EQUALS(4, platform.sizeof_long);
|
||||||
|
ASSERT_EQUALS(8, platform.sizeof_long_long);
|
||||||
|
ASSERT_EQUALS(4, platform.sizeof_float);
|
||||||
|
ASSERT_EQUALS(8, platform.sizeof_double);
|
||||||
|
ASSERT_EQUALS(8, platform.sizeof_long_double);
|
||||||
|
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(8, platform.char_bit);
|
||||||
|
ASSERT_EQUALS(16, platform.short_bit);
|
||||||
|
ASSERT_EQUALS(32, platform.int_bit);
|
||||||
|
ASSERT_EQUALS(32, platform.long_bit);
|
||||||
|
ASSERT_EQUALS(64, platform.long_long_bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void valid_config_file_1() {
|
void valid_config_file_1() {
|
||||||
|
@ -184,7 +270,7 @@ private:
|
||||||
ASSERT_EQUALS(100, platform.long_long_bit);
|
ASSERT_EQUALS(100, platform.long_long_bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void valid_config_file_3() {
|
void valid_config_file_3() const {
|
||||||
// Valid platform configuration without any usable information.
|
// Valid platform configuration without any usable information.
|
||||||
// Similar like an empty file.
|
// Similar like an empty file.
|
||||||
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
|
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
|
||||||
|
@ -206,17 +292,8 @@ private:
|
||||||
" </sizeof1>\n"
|
" </sizeof1>\n"
|
||||||
" </platform>";
|
" </platform>";
|
||||||
cppcheck::Platform platform;
|
cppcheck::Platform platform;
|
||||||
ASSERT(platform.platform(cppcheck::Platform::Win64));
|
// TODO: needs to fail - files need to be complete
|
||||||
ASSERT(readPlatform(platform, xmldata));
|
TODO_ASSERT(!readPlatform(platform, xmldata));
|
||||||
ASSERT_EQUALS(platform.PlatformFile, platform.platformType);
|
|
||||||
ASSERT(!platform.isWindowsPlatform());
|
|
||||||
ASSERT_EQUALS(8, platform.char_bit);
|
|
||||||
ASSERT_EQUALS('\0', platform.defaultSign);
|
|
||||||
ASSERT_EQUALS(1, platform.sizeof_bool);
|
|
||||||
ASSERT_EQUALS(2, platform.sizeof_short);
|
|
||||||
ASSERT_EQUALS(4, platform.sizeof_int);
|
|
||||||
ASSERT_EQUALS(4, platform.sizeof_long);
|
|
||||||
ASSERT_EQUALS(8, platform.sizeof_long_long);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void valid_config_file_4() {
|
void valid_config_file_4() {
|
||||||
|
@ -287,7 +364,7 @@ private:
|
||||||
ASSERT(!readPlatform(platform, xmldata));
|
ASSERT(!readPlatform(platform, xmldata));
|
||||||
}
|
}
|
||||||
|
|
||||||
void empty_elements() {
|
void empty_elements() const {
|
||||||
// Valid platform configuration without any usable information.
|
// Valid platform configuration without any usable information.
|
||||||
// Similar like an empty file.
|
// Similar like an empty file.
|
||||||
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
|
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
|
||||||
|
@ -309,10 +386,7 @@ private:
|
||||||
" </sizeof>\n"
|
" </sizeof>\n"
|
||||||
" </platform>";
|
" </platform>";
|
||||||
cppcheck::Platform platform;
|
cppcheck::Platform platform;
|
||||||
ASSERT(platform.platform(cppcheck::Platform::Win64));
|
|
||||||
ASSERT(!readPlatform(platform, xmldata));
|
ASSERT(!readPlatform(platform, xmldata));
|
||||||
ASSERT_EQUALS(platform.PlatformFile, platform.platformType);
|
|
||||||
ASSERT(!platform.isWindowsPlatform());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void default_platform() {
|
void default_platform() {
|
||||||
|
|
|
@ -480,12 +480,12 @@ private:
|
||||||
simplecpp::TokenList tokens(istr, files, "test.c");
|
simplecpp::TokenList tokens(istr, files, "test.c");
|
||||||
|
|
||||||
// preprocess code with unix32 platform..
|
// preprocess code with unix32 platform..
|
||||||
settings.platform(Settings::PlatformType::Unix32);
|
PLATFORM(settings, Settings::PlatformType::Unix32);
|
||||||
preprocessor.setPlatformInfo(&tokens);
|
preprocessor.setPlatformInfo(&tokens);
|
||||||
ASSERT_EQUALS("\n1", preprocessor.getcode(tokens, "", files, false));
|
ASSERT_EQUALS("\n1", preprocessor.getcode(tokens, "", files, false));
|
||||||
|
|
||||||
// preprocess code with unix64 platform..
|
// preprocess code with unix64 platform..
|
||||||
settings.platform(Settings::PlatformType::Unix64);
|
PLATFORM(settings, Settings::PlatformType::Unix64);
|
||||||
preprocessor.setPlatformInfo(&tokens);
|
preprocessor.setPlatformInfo(&tokens);
|
||||||
ASSERT_EQUALS("\n\n\n2", preprocessor.getcode(tokens, "", files, false));
|
ASSERT_EQUALS("\n\n\n2", preprocessor.getcode(tokens, "", files, false));
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,7 +313,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
settings.debugwarnings = debugwarnings;
|
settings.debugwarnings = debugwarnings;
|
||||||
settings.platform(type);
|
PLATFORM(settings, type);
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
|
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
|
|
|
@ -178,7 +178,7 @@ private:
|
||||||
std::string tok_(const char* file, int line, const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native) {
|
std::string tok_(const char* file, int line, const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
settings0.platform(type);
|
PLATFORM(settings0, type);
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
|
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
|
@ -207,7 +207,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
settings1.debugwarnings = true;
|
settings1.debugwarnings = true;
|
||||||
settings1.platform(platform);
|
PLATFORM(settings1, platform);
|
||||||
settings1.standards.cpp = cpp11 ? Standards::CPP11 : Standards::CPP03;
|
settings1.standards.cpp = cpp11 ? Standards::CPP11 : Standards::CPP03;
|
||||||
|
|
||||||
// tokenize..
|
// tokenize..
|
||||||
|
|
|
@ -214,7 +214,7 @@ private:
|
||||||
|
|
||||||
settings0.certainty.enable(Certainty::inconclusive);
|
settings0.certainty.enable(Certainty::inconclusive);
|
||||||
settings0.debugwarnings = debugwarnings; // show warnings about unhandled typedef
|
settings0.debugwarnings = debugwarnings; // show warnings about unhandled typedef
|
||||||
settings0.platform(type);
|
PLATFORM(settings0, type);
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
|
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
|
|
|
@ -103,7 +103,7 @@ private:
|
||||||
|
|
||||||
settings0.certainty.enable(Certainty::inconclusive);
|
settings0.certainty.enable(Certainty::inconclusive);
|
||||||
settings0.debugwarnings = debugwarnings;
|
settings0.debugwarnings = debugwarnings;
|
||||||
settings0.platform(type);
|
PLATFORM(settings0, type);
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
|
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
|
|
|
@ -120,7 +120,7 @@ private:
|
||||||
|
|
||||||
void run() override {
|
void run() override {
|
||||||
LOAD_LIB_2(settings1.library, "std.cfg");
|
LOAD_LIB_2(settings1.library, "std.cfg");
|
||||||
settings2.platform(Settings::Unspecified);
|
PLATFORM(settings2, cppcheck::Platform::Unspecified);
|
||||||
|
|
||||||
// If there are unused templates, keep those
|
// If there are unused templates, keep those
|
||||||
settings1.checkUnusedTemplates = true;
|
settings1.checkUnusedTemplates = true;
|
||||||
|
|
|
@ -472,7 +472,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
settings1.debugwarnings = true;
|
settings1.debugwarnings = true;
|
||||||
settings1.platform(platform);
|
PLATFORM(settings1, platform);
|
||||||
settings1.standards.cpp = std;
|
settings1.standards.cpp = std;
|
||||||
|
|
||||||
// tokenize..
|
// tokenize..
|
||||||
|
@ -501,7 +501,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
settings_windows.debugwarnings = true;
|
settings_windows.debugwarnings = true;
|
||||||
settings_windows.platform(platform);
|
PLATFORM(settings_windows, platform);
|
||||||
settings_windows.standards.cpp = cpp11 ? Standards::CPP11 : Standards::CPP03;
|
settings_windows.standards.cpp = cpp11 ? Standards::CPP11 : Standards::CPP03;
|
||||||
|
|
||||||
// tokenize..
|
// tokenize..
|
||||||
|
|
|
@ -67,7 +67,7 @@ private:
|
||||||
|
|
||||||
void checkTooBigShift_Unix32() {
|
void checkTooBigShift_Unix32() {
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.platform(Settings::Unix32);
|
PLATFORM(settings, Settings::Unix32);
|
||||||
|
|
||||||
// unsigned types getting promoted to int sizeof(int) = 4 bytes
|
// unsigned types getting promoted to int sizeof(int) = 4 bytes
|
||||||
// and unsigned types having already a size of 4 bytes
|
// and unsigned types having already a size of 4 bytes
|
||||||
|
@ -241,7 +241,7 @@ private:
|
||||||
|
|
||||||
void checkIntegerOverflow() {
|
void checkIntegerOverflow() {
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.platform(Settings::Unix32);
|
PLATFORM(settings, Settings::Unix32);
|
||||||
settings.severity.enable(Severity::warning);
|
settings.severity.enable(Severity::warning);
|
||||||
|
|
||||||
check("x = (int)0x10000 * (int)0x10000;", &settings);
|
check("x = (int)0x10000 * (int)0x10000;", &settings);
|
||||||
|
@ -283,7 +283,7 @@ private:
|
||||||
|
|
||||||
void signConversion() {
|
void signConversion() {
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.platform(Settings::Unix64);
|
PLATFORM(settings, Settings::Unix64);
|
||||||
check("x = -4 * (unsigned)y;");
|
check("x = -4 * (unsigned)y;");
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (warning) Expression '-4' has a negative value. That is converted to an unsigned value and used in an unsigned calculation.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:1]: (warning) Expression '-4' has a negative value. That is converted to an unsigned value and used in an unsigned calculation.\n", errout.str());
|
||||||
|
|
||||||
|
@ -334,7 +334,7 @@ private:
|
||||||
void longCastAssign() {
|
void longCastAssign() {
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.severity.enable(Severity::style);
|
settings.severity.enable(Severity::style);
|
||||||
settings.platform(Settings::Unix64);
|
PLATFORM(settings, Settings::Unix64);
|
||||||
|
|
||||||
check("long f(int x, int y) {\n"
|
check("long f(int x, int y) {\n"
|
||||||
" const long ret = x * y;\n"
|
" const long ret = x * y;\n"
|
||||||
|
|
|
@ -83,7 +83,7 @@ private:
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
settings.platform(platform);
|
PLATFORM(settings, platform);
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
|
|
|
@ -96,7 +96,7 @@ private:
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
settings.platform(platform);
|
PLATFORM(settings, platform);
|
||||||
|
|
||||||
// Raw tokens..
|
// Raw tokens..
|
||||||
std::vector<std::string> files(1, "test.cpp");
|
std::vector<std::string> files(1, "test.cpp");
|
||||||
|
|
|
@ -989,7 +989,7 @@ private:
|
||||||
|
|
||||||
// ~
|
// ~
|
||||||
code = "x = ~0U;";
|
code = "x = ~0U;";
|
||||||
settings.platform(cppcheck::Platform::Native); // ensure platform is native
|
PLATFORM(settings, cppcheck::Platform::Native); // ensure platform is native
|
||||||
values = tokenValues(code,"~");
|
values = tokenValues(code,"~");
|
||||||
ASSERT_EQUALS(1U, values.size());
|
ASSERT_EQUALS(1U, values.size());
|
||||||
ASSERT_EQUALS(~0U, values.back().intvalue);
|
ASSERT_EQUALS(~0U, values.back().intvalue);
|
||||||
|
|
|
@ -33,7 +33,7 @@ struct InternalError;
|
||||||
class TestVarID : public TestFixture {
|
class TestVarID : public TestFixture {
|
||||||
public:
|
public:
|
||||||
TestVarID() : TestFixture("TestVarID") {
|
TestVarID() : TestFixture("TestVarID") {
|
||||||
settings.platform(Settings::Unix64);
|
PLATFORM(settings, cppcheck::Platform::Unix64);
|
||||||
settings.standards.c = Standards::C89;
|
settings.standards.c = Standards::C89;
|
||||||
settings.standards.cpp = Standards::CPPLatest;
|
settings.standards.cpp = Standards::CPPLatest;
|
||||||
settings.checkUnusedTemplates = true;
|
settings.checkUnusedTemplates = true;
|
||||||
|
|
Loading…
Reference in New Issue