sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Name : unexpected_handler_test.cpp sl@0: // Part of : standard c++ tests. sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include "test_decls.h" sl@0: #include sl@0: #include sl@0: sl@0: void foo() sl@0: { sl@0: /* sl@0: * The handler is invoked so terminate sl@0: **/ sl@0: CPP_TESTS_ASSERT_ALLWAYS(1); sl@0: abort(); sl@0: } sl@0: sl@0: void bar() throw() sl@0: { sl@0: throw int(0); sl@0: } sl@0: sl@0: int main() sl@0: { sl@0: std::unexpected_handler hu_old,hu_new; sl@0: // std::terminate_handler ht_old,ht_new; sl@0: sl@0: hu_new = (std::unexpected_handler)&foo; sl@0: hu_old = std::set_unexpected(hu_new); sl@0: hu_old = hu_old;//get rid of the warning sl@0: sl@0: // ht_new = (std::terminate_handler)&foo; sl@0: // ht_old = std::set_terminate(ht_new); sl@0: try { sl@0: bar(); sl@0: }catch(...){} sl@0: /* sl@0: * Failure case. If we reach here, the unexpected_handler wasn't sl@0: * invoked. sl@0: **/ sl@0: CPP_TESTS_ASSERT_ALLWAYS(0); sl@0: return 0; sl@0: }