diff -r 000000000000 -r e4d67989cc36 genericopenlibs/cppstdlib/stl/test/compiler/eh.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/genericopenlibs/cppstdlib/stl/test/compiler/eh.cc Tue Feb 02 02:01:42 2010 +0200 @@ -0,0 +1,60 @@ +//#include +#include +#include + +using namespace std; + +struct BigStruct +{ + char _data[4096]; +}; + +void bad_alloc_test() +{ + typedef allocator BigStructAllocType; + BigStructAllocType bigStructAlloc; + + try { + //Lets try to allocate almost 4096 Go (on most of the platforms) of memory: + BigStructAllocType::pointer pbigStruct = bigStructAlloc.allocate(1024 * 1024 * 1024); + + // CPPUNIT_ASSERT( pbigStruct != 0 && "Allocation failed but no exception thrown" ); + } + catch (bad_alloc const&) { + printf( "Ok\n" ); + } + catch (...) { + //We shouldn't be there: + // CPPUNIT_ASSERT( false && "Not bad_alloc exception thrown." ); + } +} + +void bad_alloc_test1() +{ + try { + allocator all; + BigStruct *bs = all.allocate(1024*1024*1024); + + // throw bad_alloc(); + } + catch ( bad_alloc const & ) { + printf( "I am here\n" ); + } + catch ( ... ) { + } +} + +int main() +{ + bad_alloc_test(); +#if 0 + try { + throw bad_alloc(); + } + catch ( bad_alloc& ) { + } + catch ( ... ) { + } +#endif + return 0; +}