28 #ifndef D_MemoryLeakWarningPlugin_h 29 #define D_MemoryLeakWarningPlugin_h 31 #include "TestPlugin.h" 32 #include "MemoryLeakDetectorNewMacros.h" 34 #define IGNORE_ALL_LEAKS_IN_TEST() MemoryLeakWarningPlugin::getFirstPlugin()->ignoreAllLeaksInTest(); 35 #define EXPECT_N_LEAKS(n) MemoryLeakWarningPlugin::getFirstPlugin()->expectLeaksInTest(n); 37 extern void crash_on_allocation_number(
unsigned alloc_number);
39 class MemoryLeakDetector;
40 class MemoryLeakFailure;
42 class MemoryLeakWarningPlugin:
public TestPlugin
45 MemoryLeakWarningPlugin(
const SimpleString& name, MemoryLeakDetector* localDetector = 0);
46 virtual ~MemoryLeakWarningPlugin();
48 virtual void preTestAction(UtestShell& test, TestResult& result) _override;
49 virtual void postTestAction(UtestShell& test, TestResult& result) _override;
51 virtual const char* FinalReport(
int toBeDeletedLeaks = 0);
53 void ignoreAllLeaksInTest();
54 void expectLeaksInTest(
int n);
56 void destroyGlobalDetectorAndTurnOffMemoryLeakDetectionInDestructor(
bool des);
58 MemoryLeakDetector* getMemoryLeakDetector();
60 static MemoryLeakWarningPlugin* getFirstPlugin();
62 static MemoryLeakDetector* getGlobalDetector();
63 static MemoryLeakFailure* getGlobalFailureReporter();
64 static void setGlobalDetector(MemoryLeakDetector* detector, MemoryLeakFailure* reporter);
65 static void destroyGlobalDetector();
67 static void turnOffNewDeleteOverloads();
68 static void turnOnNewDeleteOverloads();
69 static void turnOnThreadSafeNewDeleteOverloads();
70 static bool areNewDeleteOverloaded();
72 MemoryLeakDetector* memLeakDetector_;
73 bool ignoreAllWarnings_;
74 bool destroyGlobalDetectorAndTurnOfMemoryLeakDetectionInDestructor_;
78 static MemoryLeakWarningPlugin* firstPlugin_;
81 extern void* cpputest_malloc_location_with_leak_detection(
size_t size,
const char* file,
int line);
82 extern void* cpputest_realloc_location_with_leak_detection(
void* memory,
size_t size,
const char* file,
int line);
83 extern void cpputest_free_location_with_leak_detection(
void* buffer,
const char* file,
int line);