Unit Testing: Moving memleak checks
This commit is contained in:
parent
2dace08aae
commit
c66846353c
|
@ -1 +0,0 @@
|
|||
Memory leak for 'clKalle::str'
|
|
@ -1,23 +0,0 @@
|
|||
|
||||
class clKalle
|
||||
{
|
||||
private:
|
||||
char *str;
|
||||
char *str2;
|
||||
public:
|
||||
clKalle();
|
||||
~clKalle();
|
||||
};
|
||||
|
||||
clKalle::clKalle()
|
||||
{
|
||||
str = new char[10];
|
||||
str2 = new char[10];
|
||||
}
|
||||
|
||||
clKalle::~clKalle()
|
||||
{
|
||||
delete [] str2;
|
||||
}
|
||||
|
||||
|
|
@ -1 +0,0 @@
|
|||
[testmemleak2\testmemleak2.cpp:8]: Memory leak:str
|
|
@ -1,12 +0,0 @@
|
|||
|
||||
|
||||
bool f()
|
||||
{
|
||||
char *str = strdup("hello");
|
||||
if (a==b)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
free(str);
|
||||
return true;
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
[testmemleak3\testmemleak3.cpp:11]: Memory leak:str
|
|
@ -1,12 +0,0 @@
|
|||
|
||||
|
||||
bool f()
|
||||
{
|
||||
char *str = strdup("hello");
|
||||
if (a==b)
|
||||
{
|
||||
free(str);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
|
||||
bool f()
|
||||
{
|
||||
TStringList *StringList = new TStringList;
|
||||
|
||||
if (asd)
|
||||
{
|
||||
delete StringList;
|
||||
return false;
|
||||
}
|
||||
|
||||
delete StringList;
|
||||
return true;
|
||||
}
|
||||
|
79
tests.cpp
79
tests.cpp
|
@ -25,6 +25,7 @@ static void constructors();
|
|||
static void operator_eq();
|
||||
static void mismatching_allocation_deallocation();
|
||||
static void memleak_in_function();
|
||||
static void memleak_in_class();
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
int main()
|
||||
|
@ -35,6 +36,7 @@ int main()
|
|||
operator_eq();
|
||||
memleak_in_function();
|
||||
mismatching_allocation_deallocation();
|
||||
memleak_in_class();
|
||||
std::cout << "Success Rate: "
|
||||
<< SuccessCount
|
||||
<< " / "
|
||||
|
@ -268,6 +270,7 @@ static void memleak_in_function()
|
|||
// test3: check all execution paths
|
||||
// test4: check all execution paths
|
||||
// test5: check all execution paths
|
||||
// test6: check all execution paths
|
||||
|
||||
const char test1[] = "void f()\n"
|
||||
"{\n"
|
||||
|
@ -334,6 +337,82 @@ static void memleak_in_function()
|
|||
"}\n";
|
||||
check( CheckMemoryLeak, __LINE__, test5, "" );
|
||||
|
||||
|
||||
|
||||
|
||||
const char test6[] = "void f()\n"
|
||||
"{\n"
|
||||
" char *str = strdup(\"hello\");\n"
|
||||
" if (a==b)\n"
|
||||
" {\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
" free(str);\n"
|
||||
"}\n";
|
||||
check( CheckMemoryLeak, __LINE__, test6, "[test.cpp:6]: Memory leak:str\n" );
|
||||
|
||||
|
||||
|
||||
|
||||
const char test7[] = "void f()\n"
|
||||
"{\n"
|
||||
" char *str = strdup(\"hello\");\n"
|
||||
" if (a==b)\n"
|
||||
" {\n"
|
||||
" free(str);\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
check( CheckMemoryLeak, __LINE__, test7, "[test.cpp:9]: Memory leak:str\n" );
|
||||
|
||||
|
||||
|
||||
|
||||
const char test8[] = "void f()\n"
|
||||
"{\n"
|
||||
" char *str = new char[10];\n"
|
||||
" if (a==b)\n"
|
||||
" {\n"
|
||||
" delete [] str;\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
" delete [] str;\n"
|
||||
"}\n";
|
||||
check( CheckMemoryLeak, __LINE__, test8, "" );
|
||||
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
static void memleak_in_class()
|
||||
{
|
||||
|
||||
|
||||
const char test1[] = "class clKalle\n"
|
||||
"{\n"
|
||||
"private:\n"
|
||||
" char *str1;\n"
|
||||
" char *str2;\n"
|
||||
"public:\n"
|
||||
" clKalle();\n"
|
||||
" ~clKalle();\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"clKalle::clKalle()\n"
|
||||
"{\n"
|
||||
" str1 = new char[10];\n"
|
||||
" str2 = new char[10];\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"clKalle::~clKalle()\n"
|
||||
"{\n"
|
||||
" delete [] str2;\n"
|
||||
"}\n";
|
||||
|
||||
check( CheckMemoryLeak, __LINE__, test1, "Memory leak for 'clKalle::str1'\n" );
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
|
Loading…
Reference in New Issue