]>
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
8 #import "test_support.h"
11 // This test case verifies that calling operator new[] in libstdc++.dylib
12 // will turn around and call operator new in this main exectuable
15 static void* myLastNewAllocation
;
16 static void* myLastDelete
;
18 // Note: this is not weak. That is specifically suppported
19 void* operator new(size_t s
) throw (std::bad_alloc
)
21 myLastNewAllocation
= malloc(s
);
22 return myLastNewAllocation
;
29 // Note: this is weak and because it is in main executable should override OS
31 void operator delete(void* p
) throw()
37 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
38 // test that OS's operator new[] redirects to my operator new
39 myLastNewAllocation
= NULL
;
40 char* stuff
= new char[24];
41 if ( (void*)stuff
!= myLastNewAllocation
) {
42 FAIL("system array allocator not redirected through my operator new");
45 // test that program uses my operator new
46 myLastNewAllocation
= NULL
;
48 if ( (void*)foo
!= myLastNewAllocation
) {
49 FAIL("allocation not redirected though my operator new");
54 if ( (void*)foo
!= myLastDelete
) {
55 FAIL("deallocation not redirected though my operator delete");