]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/weak-coalesce-inserted-dylibs.dtest/main.cpp
2 // BUILD: $CXX foo.cpp -dynamiclib -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib -fno-exceptions
3 // BUILD: $CXX bar.cpp -dynamiclib -install_name $RUN_DIR/libbar.dylib -o $BUILD_DIR/libbar.dylib -fno-exceptions
4 // BUILD: $CXX main.cpp $BUILD_DIR/libfoo.dylib -o $BUILD_DIR/weak-coalesce-inserted-dylibs.exe -fno-exceptions
5 // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/weak-coalesce-inserted-dylibs.exe
7 // RUN: DYLD_INSERT_LIBRARIES=libbar.dylib ./weak-coalesce-inserted-dylibs.exe
15 // We have our own copy of operator new. Make sure that we call our version, but that foo calls the one from the inserted bar dylib
16 static bool calledMainNew
= false;
17 static bool calledMainDelete
= false;
18 static bool enableTracking
= false;
20 void* operator new(size_t size
)
24 void* ptr
= malloc(size
);
28 void operator delete(void* ptr
)
31 calledMainDelete
= true;
37 printf("[BEGIN] weak-coalesce-inserted-dylibs\n");
39 // First make sure we do use our versions of new and delete.
40 enableTracking
= true;
44 printf("[FAIL] weak-coalesce-inserted-dylibs, didn't call executable operator new\n");
49 if (!calledMainDelete
) {
50 printf("[FAIL] weak-coalesce-inserted-dylibs, didn't call executable operator delete\n");
54 // Now make foo do the same and make sure we got the new/delete from bar
55 calledMainNew
= false;
56 calledMainDelete
= false;
60 printf("[FAIL] weak-coalesce-inserted-dylibs, didn't call bar operator new\n");
64 if (calledMainDelete
) {
65 printf("[FAIL] weak-coalesce-inserted-dylibs, didn't call bar operator delete\n");
69 printf("[PASS] weak-coalesce-inserted-dylibs\n");