Moved several tests from testclass.cpp to testconstructors.cpp, fixes test failure introduced recently.

This commit is contained in:
PKEuS 2014-08-05 12:19:52 +02:00
parent 4207b3cb66
commit d3501e77a8
2 changed files with 125 additions and 141 deletions

View File

@ -48,17 +48,6 @@ private:
TEST_CASE(copyConstructor1);
TEST_CASE(copyConstructor2); // ticket #4458
TEST_CASE(noConstructor1);
TEST_CASE(noConstructor2);
TEST_CASE(noConstructor3);
TEST_CASE(noConstructor4);
TEST_CASE(noConstructor5);
TEST_CASE(noConstructor6); // ticket #4386
TEST_CASE(noConstructor7); // ticket #4391
TEST_CASE(noConstructor8); // ticket #4404
TEST_CASE(noConstructor9); // ticket #4419
TEST_CASE(forwardDeclaration); // ticket #4290/#3190
TEST_CASE(operatorEq1);
TEST_CASE(operatorEq2);
TEST_CASE(operatorEq3); // ticket #3051
@ -187,7 +176,6 @@ private:
TEST_CASE(pureVirtualFunctionCallPrevented);
TEST_CASE(duplInheritedMembers);
TEST_CASE(invalidInitializerList);
}
void checkDuplInheritedMembers(const char code[]) {
@ -2019,127 +2007,6 @@ private:
ASSERT_EQUALS("[test.cpp:3]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
}
void checkNoConstructor(const char code[]) {
// Clear the error log
errout.str("");
Settings settings;
settings.addEnabled("style");
// Tokenize..
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList2();
// Check..
CheckClass checkClass(&tokenizer, &settings, this);
checkClass.constructors();
}
void noConstructor1() {
// There are nonstatic member variables - constructor is needed
checkNoConstructor("class Fred\n"
"{\n"
" int i;\n"
"};");
ASSERT_EQUALS("[test.cpp:1]: (style) The class 'Fred' does not have a constructor.\n", errout.str());
}
void noConstructor2() {
checkNoConstructor("class Fred\n"
"{\n"
"public:\n"
" static void foobar();\n"
"};\n"
"\n"
"void Fred::foobar()\n"
"{ }");
ASSERT_EQUALS("", errout.str());
}
void noConstructor3() {
checkNoConstructor("class Fred\n"
"{\n"
"private:\n"
" static int foobar;\n"
"};");
ASSERT_EQUALS("", errout.str());
}
void noConstructor4() {
checkNoConstructor("class Fred\n"
"{\n"
"public:\n"
" int foobar;\n"
"};");
ASSERT_EQUALS("", errout.str());
}
void noConstructor5() {
checkNoConstructor("namespace Foo\n"
"{\n"
" int i;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void noConstructor6() {
// ticket #4386
checkNoConstructor("class Ccpucycles {\n"
" friend class foo::bar;\n"
" Ccpucycles() :\n"
" m_v(0), m_b(true)\n"
" {}\n"
"private:\n"
" cpucyclesT m_v;\n"
" bool m_b;\n"
"};");
ASSERT_EQUALS("", errout.str());
}
void noConstructor7() {
// ticket #4391
checkNoConstructor("short bar;\n"
"class foo;\n");
ASSERT_EQUALS("", errout.str());
}
void noConstructor8() {
// ticket #4404
checkNoConstructor("class LineSegment;\n"
"class PointArray { };\n"
"void* tech_ = NULL;\n");
ASSERT_EQUALS("", errout.str());
}
void noConstructor9() {
// ticket #4419
checkNoConstructor("class CGreeting : public CGreetingBase<char> {\n"
"public:\n"
" CGreeting() : CGreetingBase<char>(), MessageSet(false) {}\n"
"private:\n"
" bool MessageSet;\n"
"};");
ASSERT_EQUALS("", errout.str());
}
// ticket #4290 "False Positive: style (noConstructor): The class 'foo' does not have a constructor."
// ticket #3190 "SymbolDatabase: Parse of sub class constructor fails"
void forwardDeclaration() {
checkNoConstructor("class foo;\n"
"int bar;\n");
ASSERT_EQUALS("", errout.str());
checkNoConstructor("class foo;\n"
"class foo;\n");
ASSERT_EQUALS("", errout.str());
checkNoConstructor("class foo{};\n"
"class foo;\n");
ASSERT_EQUALS("", errout.str());
}
void checkNoMemset(const char code[], bool load_std_cfg = false) {
// Clear the error log
errout.str("");
@ -6096,13 +5963,6 @@ private:
"{nonpure(false);}\n");
ASSERT_EQUALS("", errout.str());
}
void invalidInitializerList() {
ASSERT_THROW(checkNoConstructor("struct R1 {\n"
" int a;\n"
" R1 () : a { }\n"
"};\n"), InternalError);
}
};
REGISTER_TEST(TestClass)

View File

@ -68,6 +68,18 @@ private:
TEST_CASE(simple12); // ticket #4620
TEST_CASE(simple13); // #5498 - no constructor, c++11 assignments
TEST_CASE(noConstructor1);
TEST_CASE(noConstructor2);
TEST_CASE(noConstructor3);
TEST_CASE(noConstructor4);
TEST_CASE(noConstructor5);
TEST_CASE(noConstructor6); // ticket #4386
TEST_CASE(noConstructor7); // ticket #4391
TEST_CASE(noConstructor8); // ticket #4404
TEST_CASE(noConstructor9); // ticket #4419
TEST_CASE(forwardDeclaration); // ticket #4290/#3190
TEST_CASE(initvar_with_this); // BUG 2190300
TEST_CASE(initvar_if); // BUG 2190290
TEST_CASE(initvar_operator_eq1); // BUG 2190376
@ -163,6 +175,7 @@ private:
TEST_CASE(uninitVarPointer); // ticket #3801
TEST_CASE(uninitConstVar);
TEST_CASE(constructors_crash1); // ticket #5641
TEST_CASE(invalidInitializerList); // ticket #5702
}
@ -403,6 +416,109 @@ private:
ASSERT_EQUALS("", errout.str());
}
void noConstructor1() {
// There are nonstatic member variables - constructor is needed
check("class Fred\n"
"{\n"
" int i;\n"
"};");
ASSERT_EQUALS("[test.cpp:1]: (style) The class 'Fred' does not have a constructor.\n", errout.str());
}
void noConstructor2() {
check("class Fred\n"
"{\n"
"public:\n"
" static void foobar();\n"
"};\n"
"\n"
"void Fred::foobar()\n"
"{ }");
ASSERT_EQUALS("", errout.str());
}
void noConstructor3() {
check("class Fred\n"
"{\n"
"private:\n"
" static int foobar;\n"
"};");
ASSERT_EQUALS("", errout.str());
}
void noConstructor4() {
check("class Fred\n"
"{\n"
"public:\n"
" int foobar;\n"
"};");
ASSERT_EQUALS("", errout.str());
}
void noConstructor5() {
check("namespace Foo\n"
"{\n"
" int i;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void noConstructor6() {
// ticket #4386
check("class Ccpucycles {\n"
" friend class foo::bar;\n"
" Ccpucycles() :\n"
" m_v(0), m_b(true)\n"
" {}\n"
"private:\n"
" cpucyclesT m_v;\n"
" bool m_b;\n"
"};");
ASSERT_EQUALS("", errout.str());
}
void noConstructor7() {
// ticket #4391
check("short bar;\n"
"class foo;\n");
ASSERT_EQUALS("", errout.str());
}
void noConstructor8() {
// ticket #4404
check("class LineSegment;\n"
"class PointArray { };\n"
"void* tech_ = NULL;\n");
ASSERT_EQUALS("", errout.str());
}
void noConstructor9() {
// ticket #4419
check("class CGreeting : public CGreetingBase<char> {\n"
"public:\n"
" CGreeting() : CGreetingBase<char>(), MessageSet(false) {}\n"
"private:\n"
" bool MessageSet;\n"
"};");
ASSERT_EQUALS("", errout.str());
}
// ticket #4290 "False Positive: style (noConstructor): The class 'foo' does not have a constructor."
// ticket #3190 "SymbolDatabase: Parse of sub class constructor fails"
void forwardDeclaration() {
check("class foo;\n"
"int bar;\n");
ASSERT_EQUALS("", errout.str());
check("class foo;\n"
"class foo;\n");
ASSERT_EQUALS("", errout.str());
check("class foo{};\n"
"class foo;\n");
ASSERT_EQUALS("", errout.str());
}
void initvar_with_this() {
check("struct Fred\n"
"{\n"
@ -2912,6 +3028,14 @@ private:
"};\n");
ASSERT_EQUALS("", errout.str());
}
void invalidInitializerList() {
// 5702
ASSERT_THROW(check("struct R1 {\n"
" int a;\n"
" R1 () : a { }\n"
"};\n"), InternalError);
}
};
REGISTER_TEST(TestConstructors)