Skip to content

Commit 693c6e8

Browse files
committed
Removed more duplicate unit tests
1 parent 8e4f998 commit 693c6e8

3 files changed

Lines changed: 15 additions & 96 deletions

File tree

test/testnullpointer.cpp

Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,12 +1124,6 @@ class TestNullPointer : public TestFixture {
11241124
}
11251125

11261126
void nullpointer8() {
1127-
check("void foo()\n"
1128-
"{\n"
1129-
" const char * x = 0;\n"
1130-
" strdup(x);\n"
1131-
"}");
1132-
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str());
11331127
check("void foo()\n"
11341128
"{\n"
11351129
" char const * x = 0;\n"
@@ -1154,39 +1148,9 @@ class TestNullPointer : public TestFixture {
11541148
" p->x = 0;\n"
11551149
"}");
11561150
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
1157-
1158-
check("void foo()\n"
1159-
"{\n"
1160-
" struct my_type* p;\n"
1161-
" p = 0;\n"
1162-
" p->x = 0;\n"
1163-
"}");
1164-
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());
11651151
}
11661152

11671153
void nullpointer11() { // ticket #2812
1168-
check("int foo()\n"
1169-
"{\n"
1170-
" my_type* p = 0;\n"
1171-
" return p->x;\n"
1172-
"}");
1173-
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
1174-
1175-
check("int foo()\n"
1176-
"{\n"
1177-
" struct my_type* p = 0;\n"
1178-
" return p->x;\n"
1179-
"}");
1180-
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
1181-
1182-
check("int foo()\n"
1183-
"{\n"
1184-
" my_type* p;\n"
1185-
" p = 0;\n"
1186-
" return p->x;\n"
1187-
"}");
1188-
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());
1189-
11901154
check("int foo()\n"
11911155
"{\n"
11921156
" struct my_type* p;\n"
@@ -1429,21 +1393,20 @@ class TestNullPointer : public TestFixture {
14291393
"}");
14301394
ASSERT_EQUALS("", errout.str());
14311395

1432-
check("void foo(char *p) {\n"
1433-
" if (!p) {\n"
1434-
" abort();\n"
1435-
" }\n"
1436-
" *p = 0;\n"
1437-
"}");
1438-
ASSERT_EQUALS("", errout.str());
1396+
{
1397+
static const char code[] =
1398+
"void foo(char *p) {\n"
1399+
" if (!p) {\n"
1400+
" abort();\n"
1401+
" }\n"
1402+
" *p = 0;\n"
1403+
"}";
1404+
check(code, false);
1405+
ASSERT_EQUALS("", errout.str());
14391406

1440-
check("void foo(char *p) {\n"
1441-
" if (!p) {\n"
1442-
" abort();\n"
1443-
" }\n"
1444-
" *p = 0;\n"
1445-
"}\n", true);
1446-
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:2]: (warning, inconclusive) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
1407+
check(code, true);
1408+
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:2]: (warning, inconclusive) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
1409+
}
14471410

14481411
check("void foo(char *p) {\n"
14491412
" if (!p) {\n"

test/testother.cpp

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,13 +2844,6 @@ class TestOther : public TestFixture {
28442844
}
28452845

28462846
void suspiciousEqualityComparison() {
2847-
check("void foo(int c) {\n"
2848-
" if (c == 1) {\n"
2849-
" c == 0;\n"
2850-
" }\n"
2851-
"}");
2852-
ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Found suspicious equality comparison. Did you intend to assign a value instead?\n", errout.str());
2853-
28542847
check("void foo(int c) {\n"
28552848
" if (c == 1) c == 0;\n"
28562849
"}");
@@ -2916,13 +2909,6 @@ class TestOther : public TestFixture {
29162909
"}");
29172910
ASSERT_EQUALS("", errout.str());
29182911

2919-
check("void foo(int c) {\n"
2920-
" for (; running == 1;) {\n"
2921-
" c ++;\n"
2922-
" }\n"
2923-
"}");
2924-
ASSERT_EQUALS("", errout.str());
2925-
29262912
check("void foo(int c) {\n"
29272913
" printf(\"%i\n\", ({x==0;}));\n"
29282914
"}");
@@ -3446,14 +3432,6 @@ class TestOther : public TestFixture {
34463432
);
34473433
ASSERT_EQUALS("[test.cpp:4]: (warning) Logical disjunction always evaluates to true: x != 5 || x != 6.\n", errout.str());
34483434

3449-
check("void f(int x, int y) {\n"
3450-
" const int ERR1 = 5;\n"
3451-
" if ((x != ERR1) || (y != ERR1))\n"
3452-
" a++;\n"
3453-
"}\n"
3454-
);
3455-
ASSERT_EQUALS("", errout.str());
3456-
34573435
check("void f(unsigned int a, unsigned int b, unsigned int c) {\n"
34583436
" if((a != b) || (c != b) || (c != a))\n"
34593437
" {\n"
@@ -3849,8 +3827,6 @@ class TestOther : public TestFixture {
38493827
check("setegid(getegid());\n", NULL, false , false, true);
38503828
ASSERT_EQUALS("[test.cpp:1]: (warning) Redundant get and set of user id.\n", errout.str());
38513829

3852-
check("seteuid(getuid());\n", NULL, false , false, true);
3853-
ASSERT_EQUALS("", errout.str());
38543830
check("seteuid(getuid());\n", NULL, false , false, true);
38553831
ASSERT_EQUALS("", errout.str());
38563832
check("seteuid(foo());\n", NULL, false , false, true);
@@ -4089,12 +4065,12 @@ class TestOther : public TestFixture {
40894065
ASSERT_EQUALS("[test.cpp:2]: (warning) Conversion of string literal \"Hello\" to bool always evaluates to true.\n", errout.str());
40904066

40914067
check("int f() {\n"
4092-
" if (\"Hello\" && 1) { }\n"
4068+
" if (\"Hello\" && test) { }\n"
40934069
"}");
40944070
ASSERT_EQUALS("[test.cpp:2]: (warning) Conversion of string literal \"Hello\" to bool always evaluates to true.\n", errout.str());
40954071

40964072
check("int f() {\n"
4097-
" if (1 && \"Hello\") { }\n"
4073+
" if (test && \"Hello\") { }\n"
40984074
"}");
40994075
ASSERT_EQUALS("[test.cpp:2]: (warning) Conversion of string literal \"Hello\" to bool always evaluates to true.\n", errout.str());
41004076

@@ -4286,15 +4262,6 @@ class TestOther : public TestFixture {
42864262
"}");
42874263
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str());
42884264

4289-
check("void f()\n"
4290-
"{\n"
4291-
" if (front < 0)\n"
4292-
" { frac = (front)/(front-back);}\n"
4293-
" else\n"
4294-
" frac = (front)/(front-back);\n"
4295-
"}");
4296-
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str());
4297-
42984265
check("void f()\n"
42994266
"{\n"
43004267
" if (front < 0)\n"
@@ -5017,16 +4984,6 @@ class TestOther : public TestFixture {
50174984
"}");
50184985
ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Suspicious use of ; at the end of 'for' statement.\n", errout.str());
50194986

5020-
// Block with some tokens to make sure the tokenizer output
5021-
// stays the same for "for(); {}"
5022-
check(
5023-
"void foo() {\n"
5024-
" for(int i = 0; i < 10; ++i); {\n"
5025-
" int j = 123;\n"
5026-
" }\n"
5027-
"}");
5028-
ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Suspicious use of ; at the end of 'for' statement.\n", errout.str());
5029-
50304987
check(
50314988
"void foo() {\n"
50324989
" while (!quit); {\n"

test/testsimplifytokens.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2584,7 +2584,6 @@ class TestSimplifyTokens : public TestFixture {
25842584
ASSERT_EQUALS("if ( ! x ) { ; }", tok("if(0==x);", false));
25852585
ASSERT_EQUALS("if ( ! x ) { ; }", tok("if(x==0);", false));
25862586
ASSERT_EQUALS("if ( ! ( a = b ) ) { ; }", tok("if(0==(a=b));", false));
2587-
ASSERT_EQUALS("if ( ! x ) { ; }", tok("if(x==0);", false));
25882587
ASSERT_EQUALS("if ( ! a && b ( ) ) { ; }", tok("if( 0 == a && b() );", false));
25892588
ASSERT_EQUALS("if ( b ( ) && ! a ) { ; }", tok("if( b() && 0 == a );", false));
25902589
ASSERT_EQUALS("if ( ! ( a = b ) ) { ; }", tok("if((a=b)==0);", false));

0 commit comments

Comments
 (0)