Detecting memory leaks in BOOST test cases.
-
Hi All, I have a BOOST test case as below BOOST_AUTO_TEST_CASE( BoostUnitTestSample ) { // seven ways to detect and report the same error: BOOST_CHECK( add( 2,2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2,2 ) == 4 ); // #2 throws on error somefunction_whichleaksmemory();----------->memory leak function. if( add( 2,2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error } I want to programmatically detect the memory leak in function somefunction_whichleaks() and get information like line number and filename where the leaked occurred. And most importantly I should know in which test case this leaked occured.May be I would like to have a dump of all this information in some file. Does anybody knows a solution to this?
-
Hi All, I have a BOOST test case as below BOOST_AUTO_TEST_CASE( BoostUnitTestSample ) { // seven ways to detect and report the same error: BOOST_CHECK( add( 2,2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2,2 ) == 4 ); // #2 throws on error somefunction_whichleaksmemory();----------->memory leak function. if( add( 2,2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error } I want to programmatically detect the memory leak in function somefunction_whichleaks() and get information like line number and filename where the leaked occurred. And most importantly I should know in which test case this leaked occured.May be I would like to have a dump of all this information in some file. Does anybody knows a solution to this?
If you're using MFC, add this snippet above your code:
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endifYour memory leaks will then appear in the output window. Note that it doesn't work correctly with overloaded new constructors, so for those you may need some $ifdef guards.