From c61ec1e07c4f14d178dc9034dfd098867f0c6ddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 14 Oct 2024 13:28:02 +0200 Subject: [PATCH] move tests --- test/testclass.cpp | 51 --------------------------------------- test/testconstructors.cpp | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 51 deletions(-) diff --git a/test/testclass.cpp b/test/testclass.cpp index a837e3af3fe..64913601b65 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -80,8 +80,6 @@ class TestClass : public TestFixture { TEST_CASE(operatorEqToSelf8); // ticket #2179 TEST_CASE(operatorEqToSelf9); // ticket #2592 - TEST_CASE(operatorEqPtrAssign); // ticket #13203 - TEST_CASE(memsetOnStruct); TEST_CASE(memsetVector); TEST_CASE(memsetOnClass); @@ -2591,55 +2589,6 @@ class TestClass : public TestFixture { ASSERT_EQUALS("", errout_str()); } -#define checkConstructors(code) checkConstructors_(code, __FILE__, __LINE__) - template - void checkConstructors_(const char (&code)[size], const char* file, int line) { - const Settings settings = settingsBuilder().severity(Severity::warning).build(); - - // Tokenize.. - SimpleTokenizer tokenizer(settings, *this); - ASSERT_LOC(tokenizer.tokenize(code), file, line); - - // Check.. - CheckClass checkClass(&tokenizer, &settings, this); - (checkClass.constructors)(); - } - - void operatorEqPtrAssign() { // ticket #13203 - checkConstructors("struct S {\n" - " int* m_data;\n" - " S() : m_data(new int()) {}\n" - " S& operator=(const S& s) {\n" - " if (&s != this) {\n" - " *(m_data) = *(s.m_data);\n" - " }\n" - " return *this;\n" - " }\n" - "};\n"); - ASSERT_EQUALS("", errout_str()); - - checkConstructors("struct S {\n" - " int* m_data;\n" - " S() : m_data(new int()) {}\n" - " S& operator=(const S& s) {\n" - " if (&s != this) {\n" - " (*m_data) = *(s.m_data);\n" - " }\n" - " return *this;\n" - " }\n" - "};\n"); - ASSERT_EQUALS("", errout_str()); - - checkConstructors("struct S {\n" - " int* m_data;\n" - " S() : m_data(new int()) {}\n" - " S& operator=(const S& s) {\n" - " return *this;\n" - " }\n" - "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'S::m_data' is not assigned a value in 'S::operator='.\n", errout_str()); - } - // Check that base classes have virtual destructors #define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__) template diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index a7bac11432b..62bd960da0a 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -104,6 +104,9 @@ class TestConstructors : public TestFixture { TEST_CASE(initvar_operator_eq6); TEST_CASE(initvar_operator_eq7); TEST_CASE(initvar_operator_eq8); + TEST_CASE(initvar_operator_eq9); + TEST_CASE(initvar_operator_eq10); + TEST_CASE(initvar_operator_eq11); TEST_CASE(initvar_same_classname); // BUG 2208157 TEST_CASE(initvar_chained_assign); // BUG 2270433 TEST_CASE(initvar_2constructors); // BUG 2270353 @@ -997,6 +1000,46 @@ class TestConstructors : public TestFixture { "[test.cpp:13]: (warning) Member variable 'D3::d2' is not assigned a value in 'D3::operator='.\n", errout_str()); } + void initvar_operator_eq9() { // ticket #13203 + check("struct S {\n" + " int* m_data;\n" + " S() : m_data(new int()) {}\n" + " S& operator=(const S& s) {\n" + " if (&s != this) {\n" + " *(m_data) = *(s.m_data);\n" + " }\n" + " return *this;\n" + " }\n" + "};\n"); + ASSERT_EQUALS("", errout_str()); + } + + void initvar_operator_eq10() { + check("struct S {\n" + " int* m_data;\n" + " S() : m_data(new int()) {}\n" + " S& operator=(const S& s) {\n" + " if (&s != this) {\n" + " (*m_data) = *(s.m_data);\n" + " }\n" + " return *this;\n" + " }\n" + "};\n"); + ASSERT_EQUALS("", errout_str()); + } + + void initvar_operator_eq11() { + check("struct S {\n" + " int* m_data;\n" + " S() : m_data(new int()) {}\n" + " S& operator=(const S& s) {\n" + " return *this;\n" + " }\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'S::m_data' is not assigned a value in 'S::operator='.\n", errout_str()); + } + + void initvar_same_classname() { // Bug 2208157 - False positive: Uninitialized variable, same class name