#include <stdio.h>
#include <stdlib.h>
#include "test_support.h"
extern void foo();
static bool calledMainNew = false;
static bool calledMainDelete = false;
static bool enableTracking = false;
void* operator new(size_t size)
{
if (enableTracking)
calledMainNew = true;
void* ptr = malloc(size);
return ptr;
}
void operator delete(void* ptr)
{
if (enableTracking)
calledMainDelete = true;
free(ptr);
}
int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
enableTracking = true;
int* v = new int(1);
if (!calledMainNew) {
FAIL("Didn't call executable operator new");
}
delete v;
if (!calledMainDelete) {
FAIL("Didn't call executable operator delete");
}
calledMainNew = false;
calledMainDelete = false;
foo();
if (calledMainNew) {
FAIL("Didn't call bar operator new");
}
if (calledMainDelete) {
FAIL("Didn't call bar operator delete");
}
PASS("Success");
}