From deca59aa865e31c932ddd0773f3ed1c68026dfc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 1 Sep 2008 06:38:41 +0000 Subject: [PATCH] testmemleak: added checks for class members --- testmemleak.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/testmemleak.cpp b/testmemleak.cpp index 0ce861814..c9b2e10a6 100644 --- a/testmemleak.cpp +++ b/testmemleak.cpp @@ -57,6 +57,8 @@ public: TEST_CASE( func1 ); TEST_CASE( func2 ); + TEST_CASE( class1 ); + } void simple1() @@ -452,6 +454,65 @@ public: + + + + + void class1() + { + check( "class Fred\n" + "{\n" + "private:\n" + " char *str1;\n" + " char *str2;\n" + "public:\n" + " Fred();\n" + " ~Fred();\n" + "};\n" + "\n" + "Fred::Fred()\n" + "{\n" + " str1 = new char[10];\n" + " str2 = new char[10];\n" + "}\n" + "\n" + "Fred::~Fred()\n" + "{\n" + " delete [] str2;\n" + "}\n" ); + + ASSERT_EQUALS( std::string("[test.cpp:1]: Memory leak: Fred::str1\n"), errout.str() ); + } + + + void class2() + { + check( "class Fred\n" + "{\n" + "private:\n" + " char *str1;\n" + "public:\n" + " Fred();\n" + " ~Fred();\n" + "};\n" + "\n" + "Fred::Fred()\n" + "{\n" + " str1 = new char[10];\n" + "}\n" + "\n" + "Fred::~Fred()\n" + "{\n" + " free(str1);\n" + "}\n" ); + + ASSERT_EQUALS( std::string("[test.cpp:17]: Mismatching allocation and deallocation: Fred::str1\n"), errout.str() ); + } + + + + + }; REGISTER_FIXTURE( TestMemleak )