]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/operator-new.dtest/main.cxx
2 // BUILD: $CXX main.cxx -o $BUILD_DIR/operator-new.exe
4 // RUN: ./operator-new.exe
12 // This test case verifies that calling operator new[] in libstdc++.dylib
13 // will turn around and call operator new in this main exectuable
16 static void* myLastNewAllocation
;
17 static void* myLastDelete
;
19 // Note: this is not weak. That is specifically suppported
20 void* operator new(size_t s
) throw (std::bad_alloc
)
22 myLastNewAllocation
= malloc(s
);
23 return myLastNewAllocation
;
30 // Note: this is weak and because it is in main executable should override OS
32 void operator delete(void* p
) throw()
40 printf("[BEGIN] operator-new\n");
42 // test that OS's operator new[] redirects to my operator new
43 myLastNewAllocation
= NULL
;
44 char* stuff
= new char[24];
45 if ( (void*)stuff
!= myLastNewAllocation
) {
46 printf("[FAIL] operator-new system array allocator not redirected through my operator new\n");
50 // test that program uses my operator new
51 myLastNewAllocation
= NULL
;
53 if ( (void*)foo
!= myLastNewAllocation
) {
54 printf("[FAIL] operator-new allocation not redirected though my operator new\n");
60 if ( (void*)foo
!= myLastDelete
) {
61 printf("[FAIL] operator-new deallocation not redirected though my operator delete\n");
65 printf("[PASS] operator-new\n");