os/ossrv/genericopenlibs/cppstdlib/test/runtime/src/unexpected_handler_test.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Name        : unexpected_handler_test.cpp
    15 // Part of     : standard c++ tests.
    16 // 
    17 //
    18 
    19 #include <exception>
    20 #include "test_decls.h"
    21 #include <cstddef>
    22 #include <cstdlib>
    23 
    24 void foo()
    25 {
    26 /*
    27  * The handler is invoked so terminate
    28  **/
    29 	CPP_TESTS_ASSERT_ALLWAYS(1);
    30 	abort();
    31 }
    32 
    33 void bar() throw()
    34 {
    35 	throw int(0);
    36 }
    37 
    38 int main()
    39 {
    40 	std::unexpected_handler hu_old,hu_new;
    41 //	std::terminate_handler ht_old,ht_new;
    42 	
    43 	hu_new = (std::unexpected_handler)&foo;
    44 	hu_old = std::set_unexpected(hu_new);
    45 	hu_old = hu_old;//get rid of the warning
    46 	
    47 //	ht_new = (std::terminate_handler)&foo;
    48 //	ht_old = std::set_terminate(ht_new);
    49 	try {
    50 	bar();
    51 	}catch(...){}
    52 	/*
    53 	 * Failure case. If we reach here, the unexpected_handler wasn't 
    54 	 * invoked.
    55 	 **/
    56 	CPP_TESTS_ASSERT_ALLWAYS(0);
    57 	return 0;
    58 }