Refactoring tests

This commit is contained in:
Daniel Marjamäki 2017-06-06 08:59:18 +02:00
parent ff38cc5c13
commit 0967700f4b
1 changed files with 20 additions and 19 deletions

View File

@ -232,6 +232,10 @@ private:
} }
} }
void check(const char code[], Settings *s) {
check(code,"test.cpp",false,true,true,s);
}
void checkP(const char code[], const char *filename = "test.cpp") { void checkP(const char code[], const char *filename = "test.cpp") {
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
@ -1573,27 +1577,24 @@ private:
"}"); "}");
ASSERT_EQUALS("[test.cpp:10]: (performance) Function parameter 'y' should be passed by reference.\n", errout.str()); ASSERT_EQUALS("[test.cpp:10]: (performance) Function parameter 'y' should be passed by reference.\n", errout.str());
const auto originalPlatform = _settings.platformType; {
// 8-byte data should be passed by reference on 32-bit platform but not on 64-bit platform
_settings.platform(cppcheck::Platform::Unix32); const char code[] = "class X {\n"
check("class X {\n"
" uint64_t a;\n" " uint64_t a;\n"
" uint64_t b;\n" " uint64_t b;\n"
"};\n" "};\n"
"void f(X x) {\n" "void f(X x) {}";
"}");
Settings s32(_settings);
s32.platform(cppcheck::Platform::Unix32);
check(code, &s32);
ASSERT_EQUALS("[test.cpp:5]: (performance) Function parameter 'x' should be passed by reference.\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (performance) Function parameter 'x' should be passed by reference.\n", errout.str());
_settings.platform(cppcheck::Platform::Unix64); Settings s64(_settings);
check("class X {\n" s64.platform(cppcheck::Platform::Unix64);
" uint64_t a;\n" check(code, &s64);
" uint64_t b;\n"
"};\n"
"void f(X x) {\n"
"}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
}
_settings.platform(originalPlatform);
} }
void switchRedundantAssignmentTest() { void switchRedundantAssignmentTest() {