From f01ab43eedd65b679cd150dd7c432da5abd4fe08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 8 Oct 2008 07:01:25 +0000 Subject: [PATCH] testmemleak: preparing to add checks of function calls --- testmemleak.cpp | 69 ++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/testmemleak.cpp b/testmemleak.cpp index c9b2e10a6..e24a26870 100644 --- a/testmemleak.cpp +++ b/testmemleak.cpp @@ -416,40 +416,49 @@ public: /* - code = "static char *dmalloc()\n" - "{\n" - " char *p = new char[100];\n" - " return p;\n" - "}\n" - "static void f()\n" - "{\n" - " char *p = dmalloc();\n" - "}\n"; - check( CheckMemoryLeak, __LINE__, code, "[test.cpp:9]: Memory leak: p\n" ); + void func3() + { + check( "static char *dmalloc()\n" + "{\n" + " char *p = new char[100];\n" + " return p;\n" + "}\n" + "static void f()\n" + "{\n" + " char *p = dmalloc();\n" + "}\n" ); + ASSERT_EQUALS( std::string("[test.cpp:9]: Memory leak: p\n"), errout.str() ); + } - code = "static char *dmalloc()\n" - "{\n" - " char *p = new char[100];\n" - " return p;\n" - "}\n" - "static void f()\n" - "{\n" - " char *p = dmalloc();\n" - " delete p;\n" - "}\n"; - check( CheckMemoryLeak, __LINE__, code, "[test.cpp:9]: Mismatching allocation and deallocation: p\n" ); + void func4() + { + check( "static char *dmalloc()\n" + "{\n" + " char *p = new char[100];\n" + " return p;\n" + "}\n" + "static void f()\n" + "{\n" + " char *p = dmalloc();\n" + " delete p;\n" + "}\n" ); + ASSERT_EQUALS( std::string("[test.cpp:9]: Mismatching allocation and deallocation: p\n"), errout.str() ); + } - code = "static void foo(const char *str)\n" - "{ }\n" - "\n" - "static void f()\n" - "{\n" - " char *p = new char[100];\n" - " foo(p);\n" - "}\n"; - check( CheckMemoryLeak, __LINE__, code, "[test.cpp:8]: Memory leak: p\n" ); + void func5() + { + check( "static void foo(const char *str)\n" + "{ }\n" + "\n" + "static void f()\n" + "{\n" + " char *p = new char[100];\n" + " foo(p);\n" + "}\n" ); + ASSERT_EQUALS( std::string("[test.cpp:8]: Memory leak: p\n"), errout.str() ); + } */