TestOther: refactoring library testing
This commit is contained in:
parent
0a6babea74
commit
e9663873e5
|
@ -33,11 +33,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Settings settings_std;
|
|
||||||
|
|
||||||
void run() {
|
void run() {
|
||||||
LOAD_LIB_2(settings_std.library, "std.cfg");
|
|
||||||
|
|
||||||
TEST_CASE(emptyBrackets);
|
TEST_CASE(emptyBrackets);
|
||||||
|
|
||||||
TEST_CASE(zeroDiv1);
|
TEST_CASE(zeroDiv1);
|
||||||
|
@ -167,7 +163,7 @@ private:
|
||||||
|
|
||||||
TEST_CASE(integerOverflow); // #5895
|
TEST_CASE(integerOverflow); // #5895
|
||||||
|
|
||||||
TEST_CASE(testReturnIgnoredReturnValue);
|
TEST_CASE(checkIgnoredReturnValue);
|
||||||
|
|
||||||
TEST_CASE(redundantPointerOp);
|
TEST_CASE(redundantPointerOp);
|
||||||
}
|
}
|
||||||
|
@ -4200,6 +4196,19 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void duplicateExpression3() {
|
void duplicateExpression3() {
|
||||||
|
Settings settings;
|
||||||
|
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
|
||||||
|
"<def>\n"
|
||||||
|
" <function name=\"mystrcmp\">\n"
|
||||||
|
" <pure/>\n"
|
||||||
|
" <arg nr=\"1\"/>\n"
|
||||||
|
" <arg nr=\"2\"/>\n"
|
||||||
|
" </function>\n"
|
||||||
|
"</def>";
|
||||||
|
tinyxml2::XMLDocument doc;
|
||||||
|
doc.Parse(xmldata, sizeof(xmldata));
|
||||||
|
settings.library.load(doc);
|
||||||
|
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" if (x() || x()) {}\n"
|
" if (x() || x()) {}\n"
|
||||||
"}");
|
"}");
|
||||||
|
@ -4246,8 +4255,8 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" if ((strcmp(a, b) == 0) || (strcmp(a, b) == 0)) {}\n"
|
" if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\n"
|
||||||
"}", "test.cpp", false, false, true, &settings_std, false);
|
"}", "test.cpp", false, false, true, &settings, false);
|
||||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '||'.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '||'.\n", errout.str());
|
||||||
|
|
||||||
check("void GetValue() { return rand(); }\n"
|
check("void GetValue() { return rand(); }\n"
|
||||||
|
@ -5914,54 +5923,67 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testReturnIgnoredReturnValue() {
|
void checkIgnoredReturnValue() {
|
||||||
check("void foo() {\n"
|
Settings settings;
|
||||||
" strcmp(a, b);\n"
|
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
|
||||||
"}", "test.cpp", false, false, true, &settings_std);
|
"<def>\n"
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Return value of function strcmp() is not used.\n", errout.str());
|
" <function name=\"mystrcmp\">\n"
|
||||||
|
" <use-retval/>\n"
|
||||||
|
" <arg nr=\"1\"/>\n"
|
||||||
|
" <arg nr=\"2\"/>\n"
|
||||||
|
" </function>\n"
|
||||||
|
"</def>";
|
||||||
|
tinyxml2::XMLDocument doc;
|
||||||
|
doc.Parse(xmldata, sizeof(xmldata));
|
||||||
|
settings.library.load(doc);
|
||||||
|
|
||||||
check("bool strcmp(char* a, char* b);\n" // cppcheck sees a custom strcmp definition, but it returns a value. Assume it is the one specified in the library.
|
check("void foo() {\n"
|
||||||
|
" mystrcmp(a, b);\n"
|
||||||
|
"}", "test.cpp", false, false, true, &settings);
|
||||||
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Return value of function mystrcmp() is not used.\n", errout.str());
|
||||||
|
|
||||||
|
check("bool mystrcmp(char* a, char* b);\n" // cppcheck sees a custom strcmp definition, but it returns a value. Assume it is the one specified in the library.
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" strcmp(a, b);\n"
|
" mystrcmp(a, b);\n"
|
||||||
"}", "test.cpp", false, false, true, &settings_std);
|
"}", "test.cpp", false, false, true, &settings);
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Return value of function strcmp() is not used.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (warning) Return value of function mystrcmp() is not used.\n", errout.str());
|
||||||
|
|
||||||
check("void strcmp(char* a, char* b);\n" // cppcheck sees a custom strcmp definition which returns void!
|
check("void mystrcmp(char* a, char* b);\n" // cppcheck sees a custom strcmp definition which returns void!
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" strcmp(a, b);\n"
|
" mystrcmp(a, b);\n"
|
||||||
"}", "test.cpp", false, false, true, &settings_std);
|
"}", "test.cpp", false, false, true, &settings);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" class strcmp { strcmp() {} };\n" // strcmp is a constructor definition here
|
" class mystrcmp { mystrcmp() {} };\n" // strcmp is a constructor definition here
|
||||||
"}", "test.cpp", false, false, true, &settings_std);
|
"}", "test.cpp", false, false, true, &settings);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" return strcmp(a, b);\n"
|
" return mystrcmp(a, b);\n"
|
||||||
"}", "test.cpp", false, false, true, &settings_std);
|
"}", "test.cpp", false, false, true, &settings);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" if(strcmp(a, b));\n"
|
" if(mystrcmp(a, b));\n"
|
||||||
"}", "test.cpp", false, false, true, &settings_std);
|
"}", "test.cpp", false, false, true, &settings);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" bool b = strcmp(a, b);\n"
|
" bool b = mystrcmp(a, b);\n"
|
||||||
"}", "test.cpp", false, false, true, &settings_std);
|
"}", "test.cpp", false, false, true, &settings);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// #6194
|
// #6194
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" std::ofstream log(logfile.c_str(), std::ios::out);\n"
|
" MyStrCmp mystrcmp(x, y);\n"
|
||||||
"}", "test.cpp", false, false, true, &settings_std);
|
"}", "test.cpp", false, false, true, &settings);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// #6197
|
// #6197
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" DebugLog::getInstance().log(systemInfo.getSystemInfo());\n"
|
" abc::def.mystrcmp(a,b);\n"
|
||||||
"}", "test.cpp", false, false, true, &settings_std);
|
"}", "test.cpp", false, false, true, &settings);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// #6233
|
// #6233
|
||||||
|
|
Loading…
Reference in New Issue