Update contrib.
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Name : new_handler_test.cpp
15 // Part of : standard c++ tests.
20 #include "test_decls.h"
22 int one_huge_chunk = 0xa000;
23 int *last_huge_chunk=NULL;
29 * This is the new handler and it frees the last successful alloc so
30 * that the allocation in operator new has some free memory.
33 delete [] last_huge_chunk;
39 last_huge_chunk = new int[one_huge_chunk];
44 std::new_handler h_old, h_new;
48 // Keep allocating until we reach OOM condition. At OOM
49 // the default new handler throws std::bad_alloc
52 }catch(std::bad_alloc ba)
57 * Once the handler is set, failure of 'new' will call the handler to
58 * get some free memory...
60 h_new = (std::new_handler)&foo;
62 h_old = std::set_new_handler(h_new);
66 * Try once more to see if our handler actually freed up some memory
73 CPP_TESTS_ASSERT_ALLWAYS(glob_val != 0);
75 h_new = std::set_new_handler(h_old);