1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/test/runtime/src/exc_interwork.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,102 @@
1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Name : exc_interwork.cpp
1.18 +// Part of : standard c++ tests.
1.19 +//
1.20 +//
1.21 +
1.22 +#include <stdcpp_support.h>
1.23 +#include <stdexcept>
1.24 +#include <new>
1.25 +#include "test_decls.h"
1.26 +
1.27 +// Test that the Symbian error codes are converted into propoer
1.28 +// Cpp exceptions.
1.29 +void foo()
1.30 +{
1.31 + int aPass = 0;
1.32 + int TotalCases = 0;
1.33 +
1.34 + try{
1.35 + TotalCases++;
1.36 + TranslateSymErrorToCppException(KErrNoMemory);
1.37 + }
1.38 + catch(std::bad_alloc a) {
1.39 + aPass++;
1.40 + }
1.41 + catch(...){
1.42 + CPP_TESTS_ASSERT_ALLWAYS(0);
1.43 + }
1.44 + try{
1.45 + TotalCases++;
1.46 + TranslateSymErrorToCppException(KErrArgument);
1.47 + }
1.48 + catch(std::invalid_argument ia) {
1.49 + aPass++;
1.50 + }
1.51 + catch(...){
1.52 + CPP_TESTS_ASSERT_ALLWAYS(0);
1.53 + }
1.54 +
1.55 + try {
1.56 + TotalCases++;
1.57 + TranslateSymErrorToCppException(KErrOverflow);
1.58 + }
1.59 + catch(std::overflow_error oe) {
1.60 + aPass++;
1.61 + }
1.62 + catch(...){
1.63 + CPP_TESTS_ASSERT_ALLWAYS(0);
1.64 + }
1.65 +
1.66 + try {
1.67 + TotalCases++;
1.68 + TranslateSymErrorToCppException(KErrUnderflow);
1.69 + }
1.70 + catch(std::underflow_error ue) {
1.71 + aPass++;
1.72 + }
1.73 + catch(...){
1.74 + CPP_TESTS_ASSERT_ALLWAYS(0);
1.75 + }
1.76 +
1.77 + try{
1.78 + TotalCases++;
1.79 + TranslateSymErrorToCppException(1);
1.80 + }
1.81 + catch(Symbian_error e) {
1.82 + aPass++;
1.83 + }
1.84 + catch(...){
1.85 + CPP_TESTS_ASSERT_ALLWAYS(0);
1.86 + }
1.87 +
1.88 + CPP_TESTS_ASSERT_ALLWAYS(TotalCases == aPass);
1.89 +}
1.90 +
1.91 +// Test that the exception is converted to proper Symbian error code
1.92 +void bar()
1.93 +{
1.94 + std::bad_alloc a;
1.95 + int x = TranslateCppExceptionToSymError(a);
1.96 + CPP_TESTS_ASSERT_ALLWAYS(x == KErrNoMemory);
1.97 +}
1.98 +
1.99 +int E32Main()
1.100 +{
1.101 + int *ptr = new int(1);
1.102 + foo();
1.103 + bar();
1.104 + return 0;
1.105 +}