Skip to content

Commit 37a87d2

Browse files
committed
Simplified TestClass test cases
1 parent dd6a806 commit 37a87d2

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

test/testclass.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,7 +2423,7 @@ class TestClass : public TestFixture {
24232423
"[test.cpp:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\n", errout.str());
24242424
}
24252425

2426-
void checkConst(const char code[], const Settings *s = 0, bool inconclusive = true) {
2426+
void checkConst(const char code[], const Settings *s = 0, bool inconclusive = true, bool verify = true) {
24272427
// Clear the error log
24282428
errout.str("");
24292429

@@ -2439,7 +2439,12 @@ class TestClass : public TestFixture {
24392439
Tokenizer tokenizer(&settings, this);
24402440
std::istringstream istr(code);
24412441
tokenizer.tokenize(istr, "test.cpp");
2442+
2443+
const std::string str1(tokenizer.tokens()->stringifyList(0,true));
24422444
tokenizer.simplifyTokenList();
2445+
const std::string str2(tokenizer.tokens()->stringifyList(0,true));
2446+
if (verify && str1 != str2)
2447+
warn(("Unsimplified code in test case\nstr1="+str1+"\nstr2="+str2).c_str());
24432448

24442449
CheckClass checkClass(&tokenizer, &settings, this);
24452450
checkClass.checkConst();
@@ -2557,7 +2562,7 @@ class TestClass : public TestFixture {
25572562
// assignment to variable, can't be const
25582563
checkConst("class Fred {\n"
25592564
" std::string s;\n"
2560-
" void foo(std::string & a, std::string & b) { s = a; b = s; }\n"
2565+
" void foo(std::string & a, std::string & b) { s = a; b = a; }\n"
25612566
"};");
25622567
ASSERT_EQUALS("", errout.str());
25632568

@@ -2625,7 +2630,7 @@ class TestClass : public TestFixture {
26252630
" std::string s;\n"
26262631
" const std::string & foo();\n"
26272632
"};\n"
2628-
"const std::string & Fred::foo() { return \"\"; }");
2633+
"const std::string & Fred::foo() { return \"\"; }", 0, false, false);
26292634
TODO_ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static.\n", "", errout.str());
26302635

26312636
// functions with a function call to a non-const member can't be const.. (#1305)
@@ -2693,7 +2698,7 @@ class TestClass : public TestFixture {
26932698
" std::string s;\n"
26942699
" void foo(std::string & a, std::string & b);\n"
26952700
"};\n"
2696-
"void Fred::foo(std::string & a, std::string & b) { s = a; b = s; }");
2701+
"void Fred::foo(std::string & a, std::string & b) { s = a; b = a; }");
26972702
ASSERT_EQUALS("", errout.str());
26982703

26992704
// assignment to variable, can't be const
@@ -2877,7 +2882,7 @@ class TestClass : public TestFixture {
28772882
void constoperator1() {
28782883
checkConst("struct Fred {\n"
28792884
" int a;\n"
2880-
" bool operator<(const Fred &f) { return (a < f.a); }\n"
2885+
" bool operator<(const Fred &f) { return a < f.a; }\n"
28812886
"};");
28822887
ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'Fred::operator<' can be const.\n", errout.str());
28832888
}
@@ -3054,15 +3059,15 @@ class TestClass : public TestFixture {
30543059

30553060
checkConst("class A {\n"
30563061
"public:\n"
3057-
" int foo() { return (x ? x : x = 0); }\n"
3062+
" int foo() { return x ? x : x = 0; }\n"
30583063
"private:\n"
30593064
" int x;\n"
30603065
"};");
30613066
ASSERT_EQUALS("", errout.str());
30623067

30633068
checkConst("class A {\n"
30643069
"public:\n"
3065-
" int foo() { return (x ? x = 0 : x); }\n"
3070+
" int foo() { return x ? x = 0 : x; }\n"
30663071
"private:\n"
30673072
" int x;\n"
30683073
"};");
@@ -3355,7 +3360,7 @@ class TestClass : public TestFixture {
33553360

33563361
checkConst("class A {\n"
33573362
"public:\n"
3358-
" int * const * foo() { return &x; }\n"
3363+
" int * * foo() { return &x; }\n"
33593364
"private:\n"
33603365
" const int * x;\n"
33613366
"};");
@@ -3615,7 +3620,7 @@ class TestClass : public TestFixture {
36153620

36163621
checkConst("struct DelayBase {\n"
36173622
" float swapSpecificDelays(int index1) {\n"
3618-
" return static_cast<float>(delays_[index1]);\n"
3623+
" return delays_[index1];\n"
36193624
" }\n"
36203625
" float delays_[4];\n"
36213626
"};");
@@ -3634,7 +3639,7 @@ class TestClass : public TestFixture {
36343639
"double A::dGetValue() {\n"
36353640
" double dRet = m_iRealVal;\n"
36363641
" if( m_d != 0 )\n"
3637-
" return dRet / m_d;\n"
3642+
" return m_iRealVal / m_d;\n"
36383643
" return dRet;\n"
36393644
"};\n"
36403645
);
@@ -4235,7 +4240,7 @@ class TestClass : public TestFixture {
42354240
" bool bOn;\n"
42364241
" bool foo()\n"
42374242
" {\n"
4238-
" return 0 != (bOn = bOn && true);\n"
4243+
" return 0 != (bOn = bOn);\n"
42394244
" }\n"
42404245
"};");
42414246

@@ -4449,17 +4454,14 @@ class TestClass : public TestFixture {
44494454
" case FLOAT_TYPE:\n"
44504455
" {\n"
44514456
" return RET_OK;\n"
4452-
" break;\n"
44534457
" }\n"
44544458
" case INT_TYPE:\n"
44554459
" {\n"
44564460
" return RET_OK;\n"
4457-
" break;\n"
44584461
" }\n"
44594462
" default:\n"
44604463
" {\n"
44614464
" return RET_NOK;\n"
4462-
" break;\n"
44634465
" }\n"
44644466
" }\n"
44654467
" }\n"

0 commit comments

Comments
 (0)