sl@0: //#include sl@0: #include sl@0: #include sl@0: sl@0: using namespace std; sl@0: sl@0: struct BigStruct sl@0: { sl@0: char _data[4096]; sl@0: }; sl@0: sl@0: void bad_alloc_test() sl@0: { sl@0: typedef allocator BigStructAllocType; sl@0: BigStructAllocType bigStructAlloc; sl@0: sl@0: try { sl@0: //Lets try to allocate almost 4096 Go (on most of the platforms) of memory: sl@0: BigStructAllocType::pointer pbigStruct = bigStructAlloc.allocate(1024 * 1024 * 1024); sl@0: sl@0: // CPPUNIT_ASSERT( pbigStruct != 0 && "Allocation failed but no exception thrown" ); sl@0: } sl@0: catch (bad_alloc const&) { sl@0: printf( "Ok\n" ); sl@0: } sl@0: catch (...) { sl@0: //We shouldn't be there: sl@0: // CPPUNIT_ASSERT( false && "Not bad_alloc exception thrown." ); sl@0: } sl@0: } sl@0: sl@0: void bad_alloc_test1() sl@0: { sl@0: try { sl@0: allocator all; sl@0: BigStruct *bs = all.allocate(1024*1024*1024); sl@0: sl@0: // throw bad_alloc(); sl@0: } sl@0: catch ( bad_alloc const & ) { sl@0: printf( "I am here\n" ); sl@0: } sl@0: catch ( ... ) { sl@0: } sl@0: } sl@0: sl@0: int main() sl@0: { sl@0: bad_alloc_test(); sl@0: #if 0 sl@0: try { sl@0: throw bad_alloc(); sl@0: } sl@0: catch ( bad_alloc& ) { sl@0: } sl@0: catch ( ... ) { sl@0: } sl@0: #endif sl@0: return 0; sl@0: }