os/ossrv/genericopenlibs/cppstdlib/stl/test/compiler/eh.cc
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/compiler/eh.cc	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,60 @@
     1.4 +//#include <list>
     1.5 +#include <stdexcept>
     1.6 +#include <stdio.h>
     1.7 +
     1.8 +using namespace std;
     1.9 +
    1.10 +struct BigStruct
    1.11 +{
    1.12 +  char _data[4096];
    1.13 +};
    1.14 +
    1.15 +void bad_alloc_test()
    1.16 +{
    1.17 +  typedef allocator<BigStruct> BigStructAllocType;
    1.18 +  BigStructAllocType bigStructAlloc;
    1.19 +
    1.20 +  try {
    1.21 +    //Lets try to allocate almost 4096 Go (on most of the platforms) of memory:
    1.22 +    BigStructAllocType::pointer pbigStruct = bigStructAlloc.allocate(1024 * 1024 * 1024);
    1.23 +
    1.24 +    // CPPUNIT_ASSERT( pbigStruct != 0 && "Allocation failed but no exception thrown" );
    1.25 +  }
    1.26 +  catch (bad_alloc const&) {
    1.27 +    printf( "Ok\n" );
    1.28 +  }
    1.29 +  catch (...) {
    1.30 +    //We shouldn't be there:
    1.31 +    // CPPUNIT_ASSERT( false && "Not bad_alloc exception thrown." );
    1.32 +  }
    1.33 +}
    1.34 +
    1.35 +void bad_alloc_test1()
    1.36 +{
    1.37 +  try {
    1.38 +    allocator<BigStruct> all;
    1.39 +    BigStruct *bs = all.allocate(1024*1024*1024);
    1.40 +
    1.41 +    // throw bad_alloc();
    1.42 +  }
    1.43 +  catch ( bad_alloc const & ) {
    1.44 +    printf( "I am here\n" );
    1.45 +  }
    1.46 +  catch ( ... ) {
    1.47 +  }
    1.48 +}
    1.49 +
    1.50 +int main()
    1.51 +{
    1.52 +  bad_alloc_test();
    1.53 +#if 0
    1.54 +  try {
    1.55 +    throw bad_alloc();
    1.56 +  }
    1.57 +  catch ( bad_alloc& ) {
    1.58 +  }
    1.59 +  catch ( ... ) {
    1.60 +  }
    1.61 +#endif
    1.62 +  return 0;
    1.63 +}