CheckAssignIf: Add more testcases

This commit is contained in:
Daniel Marjamäki 2012-11-29 09:58:55 +01:00
parent 3372657a07
commit ddad2d45cf
1 changed files with 21 additions and 0 deletions

View File

@ -173,6 +173,27 @@ private:
" if ((x | 4) != 3);\n" " if ((x | 4) != 3);\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X | 0x4) != 0x3' is always true.\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X | 0x4) != 0x3' is always true.\n", errout.str());
// array
check("void foo(int *x)\n"
"{\n"
" if (x[0] & 4 == 3);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X & 0x4) == 0x3' is always false.\n", errout.str());
// struct member
check("void foo(struct X *x)\n"
"{\n"
" if (x->y & 4 == 3);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X & 0x4) == 0x3' is always false.\n", errout.str());
// expression
check("void foo(int x)\n"
"{\n"
" if ((x+2) & 4 == 3);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X & 0x4) == 0x3' is always false.\n", errout.str());
} }
void multicompare() { void multicompare() {