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