From ddad2d45cf8f363082b956989958427110112e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 29 Nov 2012 09:58:55 +0100 Subject: [PATCH] CheckAssignIf: Add more testcases --- test/testassignif.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/testassignif.cpp b/test/testassignif.cpp index f0a85e064..9018e9e02 100644 --- a/test/testassignif.cpp +++ b/test/testassignif.cpp @@ -173,6 +173,27 @@ private: " if ((x | 4) != 3);\n" "}\n"); 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() {